@@ -72,10 +72,16 @@ var wpStatelessApp = angular.module('wpStatelessApp', [])
7272 $scope . log = [ ] ;
7373
7474 /**
75- * Status text
76- * @type {boolean }
75+ * Status message
76+ * @type {String }
77+ */
78+ $scope . status = '' ;
79+
80+ /**
81+ * Status message
82+ * @type {String }
7783 */
78- $scope . status = false ;
84+ $scope . extraStatus = '' ;
7985
8086 /**
8187 * Init
@@ -84,6 +90,30 @@ var wpStatelessApp = angular.module('wpStatelessApp', [])
8490 jQuery ( "#regenthumbs-bar" ) . progressbar ( ) ;
8591 }
8692
93+ /**
94+ * Get error message
95+ */
96+ $scope . getError = function ( response , message ) {
97+ if ( response . data && typeof response . data . data !== 'undefined' ) {
98+ return response . data . data ;
99+ }
100+
101+ if ( response . data && typeof response . data == 'string' ) {
102+ $scope . extraStatus = response . data ;
103+ return message ;
104+ }
105+
106+ if ( ! response . data && response . statusText ) {
107+ return response . statusText + " (Response code: " + response . status + ")" ;
108+ }
109+
110+ if ( ! response . data && response . status == - 1 ) {
111+ return "Unable to connect to the server" ;
112+ }
113+
114+ return message ;
115+ }
116+
87117 /**
88118 *
89119 * @param callback
@@ -329,23 +359,23 @@ var wpStatelessApp = angular.module('wpStatelessApp', [])
329359 }
330360 }
331361 } else {
332- $scope . status = data . data || 'Unable to get Images Media ID' ;
362+ $scope . status = $scope . getError ( response , 'Unable to get Images Media ID' ) ;
333363 $scope . error = true ;
334364 }
335365
336366 $scope . isLoading = false ;
337367
338368 if ( WP_DEBUG ) {
339- console . log ( "WP-Stateless get Images Media ID:" , data ) ;
369+ console . log ( "WP-Stateless get Images Media ID:" , response ) ;
340370 }
341371
342372 } , function ( response ) {
343373 $scope . error = true ;
344- $scope . status = response . data || 'Get Images Media ID: Request failed' ;
374+ $scope . status = $scope . getError ( response , 'Get Images Media ID: Request failed' ) ;
345375 $scope . isLoading = false ;
346376
347377 if ( WP_DEBUG ) {
348- console . log ( "WP-Stateless get Images Media ID: Request failed" , response . data , response . headers ( ) ) ;
378+ console . log ( "WP-Stateless get Images Media ID: Request failed" , response , response . headers ( ) ) ;
349379 }
350380 } ) ;
351381
@@ -377,26 +407,26 @@ var wpStatelessApp = angular.module('wpStatelessApp', [])
377407 $scope . objectIDs = data . data ;
378408 callback ( ) ;
379409 } else {
380- $scope . status = data . data || 'IDs are malformed' ;
410+ $scope . status = $scope . getError ( response , 'IDs are malformed' ) ;
381411 $scope . error = true ;
382412 }
383413 }
384414 } else {
385- $scope . status = data . data || 'Unable to get non Images Media ID' ;
415+ $scope . status = $scope . getError ( response , 'Unable to get non Images Media ID' ) ;
386416 $scope . error = true ;
387417 }
388418
389419 $scope . isLoading = false ;
390420
391421 if ( WP_DEBUG ) {
392- console . log ( "WP-Stateless get non Images Media ID:" , response . data , response . headers ( ) ) ;
422+ console . log ( "WP-Stateless get non Images Media ID:" , response , response . headers ( ) ) ;
393423 }
394424 } , function ( response ) {
395425 $scope . error = true ;
396- $scope . status = response . data || 'Get non Images Media ID: Request failed' ;
426+ $scope . status = $scope . getError ( response , 'Get non Images Media ID: Request failed' ) ;
397427 $scope . isLoading = false ;
398428 if ( WP_DEBUG ) {
399- console . log ( "WP-Stateless get non Images Media ID: Request failed" , response . data , response . headers ( ) ) ;
429+ console . log ( "WP-Stateless get non Images Media ID: Request failed" , response , response . headers ( ) ) ;
400430 }
401431 } ) ;
402432
@@ -428,27 +458,27 @@ var wpStatelessApp = angular.module('wpStatelessApp', [])
428458 $scope . objectIDs = data . data ;
429459 callback ( ) ;
430460 } else {
431- $scope . status = data . data || "IDs are malformed" ;
461+ $scope . status = $scope . getError ( response , "IDs are malformed" ) ;
432462 $scope . error = true ;
433463 }
434464 }
435465 } else {
436466 $scope . error = true ;
437- $scope . status = data . data || 'Unable to get non library files' ;
467+ $scope . status = $scope . getError ( response , 'Non libraries files are not found' ) ;
438468 }
439469
440470 $scope . isLoading = false ;
441471
442472 if ( WP_DEBUG ) {
443- console . log ( "WP-Stateless get non library files:" , response . data , response . headers ( ) ) ;
473+ console . log ( "WP-Stateless get non library files:" , response , response . headers ( ) ) ;
444474 }
445475 } , function ( response ) {
446476 $scope . error = true ;
447- $scope . status = response . data || 'Get non library files: Request failed' ;
477+ $scope . status = $scope . getError ( response , 'Get non library files: Request failed' ) ;
448478 $scope . isLoading = false ;
449479
450480 if ( WP_DEBUG ) {
451- console . log ( "WP-Stateless get non library files: Request failed" , response . data , response . headers ( ) ) ;
481+ console . log ( "WP-Stateless get non library files: Request failed" , response , response . headers ( ) ) ;
452482 }
453483 } ) ;
454484
@@ -534,12 +564,17 @@ var wpStatelessApp = angular.module('wpStatelessApp', [])
534564 } ) . then (
535565 function ( response ) {
536566 var data = response . data || { } ;
537- $scope . log . push ( { message :data . data } ) ;
567+ $scope . log . push ( { message :data . data || "Regenerate single image: Failed" } ) ;
538568
539569 jQuery ( "#regenthumbs-bar" ) . progressbar ( "value" , ( ++ $scope . objectsCounter / $scope . objectsTotal ) * 100 ) ;
540570 jQuery ( "#regenthumbs-bar-percent" ) . html ( Math . round ( ( $scope . objectsCounter / $scope . objectsTotal ) * 1000 ) / 10 + "%" ) ;
541571
542- if ( 'undefined' !== typeof chunk_id ) {
572+ if ( typeof response . data . status == 'undefined' || response . data . status == false ) {
573+ $scope . error = true ;
574+ $scope . status = $scope . getError ( response , "Regenerate single image: Failed" ) ;
575+ $scope . isRunning = false ;
576+ }
577+ else if ( 'undefined' !== typeof chunk_id ) {
543578 if ( $scope . chunkIDs [ chunk_id ] . length && $scope . continue ) {
544579 $scope . regenerateSingle ( $scope . chunkIDs [ chunk_id ] . shift ( ) , chunk_id ) ;
545580 } else {
@@ -553,15 +588,15 @@ var wpStatelessApp = angular.module('wpStatelessApp', [])
553588 }
554589 }
555590 if ( WP_DEBUG ) {
556- console . log ( "WP-Stateless regenerate single image:" , response . data , response . headers ( ) ) ;
591+ console . log ( "WP-Stateless regenerate single image:" , response , response . headers ( ) ) ;
557592 }
558593 } ,
559594 function ( response ) {
560595 $scope . error = true ;
561- $scope . status = response . data || "Regenerate single image: Request failed" ;
596+ $scope . status = $scope . getError ( response , "Regenerate single image: Request failed" ) ;
562597 $scope . isRunning = false ;
563598 if ( WP_DEBUG ) {
564- console . log ( "WP-Stateless regenerate single image: Request failed" , response . data , response . headers ( ) ) ;
599+ console . log ( "WP-Stateless regenerate single image: Request failed" , response , response . headers ( ) ) ;
565600 }
566601 }
567602 ) ;
@@ -584,12 +619,17 @@ var wpStatelessApp = angular.module('wpStatelessApp', [])
584619 } ) . then (
585620 function ( response ) {
586621 var data = response . data || { } ;
587- $scope . log . push ( { message :data . data } ) ;
622+ $scope . log . push ( { message :data . data || "Sync single file: Failed" } ) ;
588623
589624 jQuery ( "#regenthumbs-bar" ) . progressbar ( "value" , ( ++ $scope . objectsCounter / $scope . objectsTotal ) * 100 ) ;
590625 jQuery ( "#regenthumbs-bar-percent" ) . html ( Math . round ( ( $scope . objectsCounter / $scope . objectsTotal ) * 1000 ) / 10 + "%" ) ;
591626
592- if ( 'undefined' !== typeof chunk_id ) {
627+ if ( typeof response . data . status == 'undefined' || response . data . status == false ) {
628+ $scope . error = true ;
629+ $scope . status = $scope . getError ( response , "Sync single file: Failed" ) ;
630+ $scope . isRunning = false ;
631+ }
632+ else if ( 'undefined' !== typeof chunk_id ) {
593633 if ( $scope . chunkIDs [ chunk_id ] . length && $scope . continue ) {
594634 $scope . syncSingleFile ( $scope . chunkIDs [ chunk_id ] . shift ( ) , chunk_id ) ;
595635 } else {
@@ -604,16 +644,16 @@ var wpStatelessApp = angular.module('wpStatelessApp', [])
604644 }
605645
606646 if ( WP_DEBUG ) {
607- console . log ( "WP-Stateless sync single file:" , response . data , response . headers ( ) ) ;
647+ console . log ( "WP-Stateless sync single file:" , response , response . headers ( ) ) ;
608648 }
609649 } ,
610650 function ( response ) {
611651 $scope . error = true ;
612- $scope . status = response . data || "Sync single file: Request failed" ;
652+ $scope . status = $scope . getError ( response , "Sync single file: Request failed" ) ;
613653 $scope . isRunning = false ;
614654
615655 if ( WP_DEBUG ) {
616- console . log ( "WP-Stateless sync single file: Request failed" , response . data , response . headers ( ) ) ;
656+ console . log ( "WP-Stateless sync single file: Request failed" , response , response . headers ( ) ) ;
617657 }
618658 }
619659 ) ;
@@ -636,12 +676,17 @@ var wpStatelessApp = angular.module('wpStatelessApp', [])
636676 } ) . then (
637677 function ( response ) {
638678 var data = response . data || { } ;
639- $scope . log . push ( { message :data . data } ) ;
679+ $scope . log . push ( { message :data . data || "Sync non library file: Failed" } ) ;
640680
641681 jQuery ( "#regenthumbs-bar" ) . progressbar ( "value" , ( ++ $scope . objectsCounter / $scope . objectsTotal ) * 100 ) ;
642682 jQuery ( "#regenthumbs-bar-percent" ) . html ( Math . round ( ( $scope . objectsCounter / $scope . objectsTotal ) * 1000 ) / 10 + "%" ) ;
643683
644- if ( 'undefined' !== typeof chunk_id ) {
684+ if ( typeof response . data . status == 'undefined' || response . data . status == false ) {
685+ $scope . error = true ;
686+ $scope . status = $scope . getError ( response , "Sync non library file: Failed" ) ;
687+ $scope . isRunning = false ;
688+ }
689+ else if ( 'undefined' !== typeof chunk_id ) {
645690 if ( $scope . chunkIDs [ chunk_id ] . length && $scope . continue ) {
646691 $scope . syncSingleNonLibraryFile ( $scope . chunkIDs [ chunk_id ] . shift ( ) , chunk_id ) ;
647692 } else {
@@ -656,16 +701,16 @@ var wpStatelessApp = angular.module('wpStatelessApp', [])
656701 }
657702
658703 if ( WP_DEBUG ) {
659- console . log ( "WP-Stateless sync non library file:" , response . data , response . headers ( ) ) ;
704+ console . log ( "WP-Stateless sync non library file:" , response , response . headers ( ) ) ;
660705 }
661706 } ,
662707 function ( response ) {
663708 $scope . error = true ;
664- $scope . status = response . data || "Sync non library file: Request failed" ;
709+ $scope . status = $scope . getError ( response , "Sync non library file: Request failed" ) ;
665710 $scope . isRunning = false ;
666711
667712 if ( WP_DEBUG ) {
668- console . log ( "WP-Stateless sync non library file: Request failed" , response . data , response . headers ( ) ) ;
713+ console . log ( "WP-Stateless sync non library file: Request failed" , response , response . headers ( ) ) ;
669714 }
670715 }
671716 ) ;
@@ -705,3 +750,9 @@ var wpStatelessApp = angular.module('wpStatelessApp', [])
705750. controller ( 'wpStatelessCompatibility' , function ( $scope , $filter ) {
706751 $scope . modules = wp_stateless_compatibility || { } ;
707752} ) ;
753+
754+ wpStatelessApp . filter ( "trust" , [ '$sce' , function ( $sce ) {
755+ return function ( htmlCode ) {
756+ return $sce . trustAsHtml ( htmlCode ) ;
757+ }
758+ } ] ) ;
0 commit comments