@@ -10,41 +10,38 @@ if (typeof Joomla === 'undefined') {
1010}
1111
1212const defaultSettings = {
13- offset : 0 ,
14- progress : 0 ,
13+ progress : null ,
1514 lastPage : null ,
1615 baseURL : `${ Joomla . getOptions ( 'system.paths' ) . baseFull } index.php?option=com_patchtester&tmpl=component&format=json` ,
17- lastPage : null ,
1816} ;
1917
2018class PatchFetcher {
2119 constructor ( settings = defaultSettings ) {
2220 this . url = new URL ( settings . baseURL ) ;
23- this . offset = settings . offset ;
2421 this . progress = settings . progress ;
2522 this . lastPage = settings . lastPage ;
2623
2724 this . progressBar = document . getElementById ( 'progress-bar' ) ;
28-
29- this . url . searchParams . append ( document . querySelector ( '#patchtester-token' ) . getAttribute ( 'name' ) , 1 ) ;
30- this . url . searchParams . append ( 'task' , `${ task } .${ task } ` ) ;
25+ this . url . searchParams . append ( document . getElementById ( 'patchtester-token' ) . getAttribute ( 'name' ) , 1 ) ;
3126
3227 this . request ( 'startfetch' ) ;
3328 }
3429
35- request ( ) {
30+ request ( task ) {
31+ this . url . searchParams . append ( 'task' , `${ task } .${ task } ` ) ;
32+
3633 Joomla . request ( {
37- url : path . toString ( ) ,
34+ url : this . url . toString ( ) ,
3835 method : 'GET' ,
36+ headers : { 'Content-Type' : 'application/json' } ,
3937 perform : true ,
40- data : `task=${ task } .${ task } ` ,
41-
4238 onSuccess : ( response ) => {
39+ response = JSON . parse ( response )
4340 try {
4441 if ( response === null || response . error || response . success === false ) {
4542 throw response ;
4643 }
47-
44+ // {"success":true,"message":"Processing page 1 of GitHub data","messages":null,"data":{"complete":false,"header":"Processing data from GitHub"}}
4845 // Store the last page if it is part of this request and not a boolean false
4946 if ( typeof response . data . lastPage !== 'undefined' && response . data . lastPage !== false ) {
5047 this . lastPage = response . data . lastPage ;
@@ -54,17 +51,17 @@ class PatchFetcher {
5451 if ( typeof response . data . page !== 'undefined' ) {
5552 this . progress = ( response . data . page / this . lastPage ) * 100 ;
5653
57- if ( progress < 100 ) {
58- this . progressBar . style . width = `${ progress } %` ;
59- this . progressBar . setAttribute ( 'aria-valuenow' , progress ) ;
54+ if ( this . progress < 100 ) {
55+ this . progressBar . style . width = `${ this . progress } %` ;
56+ this . progressBar . setAttribute ( 'aria-valuenow' , this . progress ) ;
6057 } else {
6158 // Both BS2 and BS4 classes are targeted to keep this script simple
6259 this . progressBar . classList . remove ( [ 'bar-success' , 'bg-success' ] ) ;
6360 this . progressBar . classList . remove ( [ 'bar-warning' , 'bg-warning' ] ) ;
64- this . progressBar . style . width = `${ progress } %` ;
61+ this . progressBar . style . width = `${ this . progress } %` ;
6562 this . progressBar . setAttribute ( 'aria-valuemin' , 100 ) ;
6663 this . progressBar . setAttribute ( 'aria-valuemax' , 200 ) ;
67- this . progressBar . setAttribute ( 'aria-valuenow' , progress ) ;
64+ this . progressBar . setAttribute ( 'aria-valuenow' , this . progress ) ;
6865 }
6966 }
7067
@@ -75,11 +72,12 @@ class PatchFetcher {
7572 }
7673
7774 if ( ! response . data . complete ) {
78- // Send another request
75+ this . url . searchParams . append ( document . querySelector ( '#patchtester-token' ) . getAttribute ( 'name' ) , 1 ) ;
76+ this . url . searchParams . append ( 'task' , `${ task } .${ task } ` ) ;
7977 this . request ( 'fetch' ) ;
8078 } else {
8179 document . getElementById ( 'progress' ) . remove ( ) ;
82- document . getElementById ( ' modal-sync button.btn-close', window . parent . document ) . click ( ) ;
80+ window . parent . document . querySelector ( '# modal-sync button.btn-close') . click ( ) ;
8381 }
8482 } catch ( error ) {
8583 try {
0 commit comments