1616 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1717 */
1818
19- function buildDiffDiffPageUrl ( fromPlatform , toPlatform , fromPropertiesPath , toPropertiesPath , lookPast , date ) {
19+ function buildDiffPageUrl ( fromPlatform , toPlatform , fromPropertiesPath , toPropertiesPath , lookPast , timestamp ) {
2020 const urlParams = {
2121 application : fromPlatform . application_name ,
2222 platform : fromPlatform . platform ,
@@ -26,11 +26,19 @@ function buildDiffDiffPageUrl(fromPlatform, toPlatform, fromPropertiesPath, toPr
2626 compare_path : toPropertiesPath ,
2727 } ;
2828 if ( lookPast ) {
29- urlParams . timestamp = date ;
29+ urlParams . timestamp = timestamp ;
3030 }
3131 return `/#/diff?${ Object . keys ( urlParams ) . map ( ( key ) => `${ encodeURIComponent ( key ) } =${ encodeURIComponent ( urlParams [ key ] ) } ` ) . join ( '&' ) } ` ;
3232}
3333
34+ function dateToTimestamp ( lookPast , date ) {
35+ var timestamp = null ;
36+ if ( lookPast ) {
37+ timestamp = date ? Number ( moment ( date , 'YYYY-MM-DD HH:mm:ss Z' ) ) : new Date ( ) . getTime ( ) ;
38+ }
39+ return timestamp ;
40+ }
41+
3442angular . module ( 'hesperides.diff' , [ ] )
3543
3644 . controller ( 'DiffController' , function ( $filter , $scope , $routeParams , $timeout , $route , ApplicationService , ModuleService , $translate , HesperidesModalFactory , Platform , notify ) {
@@ -247,49 +255,49 @@ angular.module('hesperides.diff', [])
247255 if status == 3 : same behavior as status == 2
248256 */
249257 $scope . diff_containers . filter ( ( diff_container ) => diff_container . selected )
250- . forEach ( ( diff_container ) => {
251- switch ( diff_container . status ) {
252- case 0 :
253- break ;
254- case 1 :
258+ . forEach ( ( diff_container ) => {
259+ switch ( diff_container . status ) {
260+ case 0 :
261+ break ;
262+ case 1 :
255263 // Revert modifs
256- diff_container . property_to_modify . value = diff_container . property_to_modify . old_value ;
257- delete diff_container . property_to_modify . old_value ;
258-
259- // Change status and reset markers. Keep selected for user experience
260- // Status depends on old_value, if it was empty status is 3 otherwise it is 2
261- diff_container . status = diff_container . property_to_modify . value === '' ? 3 : 2 ;
262- diff_container . modified = false ;
263- break ;
264- case 2 :
264+ diff_container . property_to_modify . value = diff_container . property_to_modify . old_value ;
265+ delete diff_container . property_to_modify . old_value ;
266+
267+ // Change status and reset markers. Keep selected for user experience
268+ // Status depends on old_value, if it was empty status is 3 otherwise it is 2
269+ diff_container . status = diff_container . property_to_modify . value === '' ? 3 : 2 ;
270+ diff_container . modified = false ;
271+ break ;
272+ case 2 :
265273 // Store old value and apply modifs
266- diff_container . property_to_modify . old_value = diff_container . property_to_modify . value ;
267- diff_container . property_to_modify . value = diff_container . property_to_compare_to . value ;
268-
269- // Change status and reset markers. Keep selected for user experience
270- diff_container . modified = true ;
271- diff_container . status = 1 ;
272- break ;
273- case 3 :
274+ diff_container . property_to_modify . old_value = diff_container . property_to_modify . value ;
275+ diff_container . property_to_modify . value = diff_container . property_to_compare_to . value ;
276+
277+ // Change status and reset markers. Keep selected for user experience
278+ diff_container . modified = true ;
279+ diff_container . status = 1 ;
280+ break ;
281+ case 3 :
274282 // Same as 2, copy paste (bad :p )
275283 // Store old value and apply modifs
276- diff_container . property_to_modify . old_value = diff_container . property_to_modify . value ;
277- diff_container . property_to_modify . value = diff_container . property_to_compare_to . value ;
278-
279- // Change status and reset markers. Keep selected for user experience
280- diff_container . modified = true ;
281- diff_container . status = 1 ;
282- break ;
283- default :
284- throw new Error ( `Diff container with invalid status -> ${ diff_container . status } . It will be ignored` ) ;
285- }
286- } ) ;
284+ diff_container . property_to_modify . old_value = diff_container . property_to_modify . value ;
285+ diff_container . property_to_modify . value = diff_container . property_to_compare_to . value ;
286+
287+ // Change status and reset markers. Keep selected for user experience
288+ diff_container . modified = true ;
289+ diff_container . status = 1 ;
290+ break ;
291+ default :
292+ throw new Error ( `Diff container with invalid status -> ${ diff_container . status } . It will be ignored` ) ;
293+ }
294+ } ) ;
287295 } ;
288296
289297 $scope . save_diff = function ( ) {
290298 // Get all the properties modified
291299 var key_value_properties = $scope . diff_containers . filter ( ( diff_container ) => diff_container . property_to_modify )
292- . map ( ( diff_container ) => diff_container . property_to_modify ) ;
300+ . map ( ( diff_container ) => diff_container . property_to_modify ) ;
293301
294302 // Is some diff item selected ?
295303 var hasSomeDiffSelected = _ . some ( $scope . diff_containers , { selected : true } ) ;
@@ -347,7 +355,7 @@ angular.module('hesperides.diff', [])
347355 $scope . checkToPlatformExist = function ( ) {
348356 if ( $scope . diffForm ) {
349357 $scope . diffForm . $setValidity ( 'matchingModule' , true ) ; // reset to default value
350- let appHasPlatform = _ . some ( $scope . targetPlatforms , { name : $scope . toPlatform . platform } ) ;
358+ const appHasPlatform = _ . some ( $scope . targetPlatforms , { name : $scope . toPlatform . platform } ) ;
351359 $scope . diffForm . $setValidity ( 'toPlatformExist' , appHasPlatform ) ;
352360 }
353361 } ;
@@ -362,12 +370,8 @@ angular.module('hesperides.diff', [])
362370
363371 $scope . getModuleToCompare = function ( ) {
364372 $scope . loadingComparePlatform = true ;
365- if ( $scope . lookPast ) {
366- $scope . date = $scope . date ? Number ( moment ( $scope . date , 'YYYY-MM-DD HH:mm:ss Z' ) ) : new Date ( ) . getTime ( ) ;
367- } else {
368- $scope . date = null ;
369- }
370- ApplicationService . get_platform ( $scope . toPlatform . application_name , $scope . toPlatform . platform , $scope . date ) . then ( ( platformFetched ) => {
373+ const timestamp = dateToTimestamp ( $scope . lookPast , $scope . date ) ;
374+ ApplicationService . get_platform ( $scope . toPlatform . application_name , $scope . toPlatform . platform , timestamp ) . then ( ( platformFetched ) => {
371375 $scope . loadingComparePlatform = false ;
372376 $scope . toPlatform . modules = platformFetched . modules ;
373377 $scope . toModule = _ . find ( $scope . toPlatform . modules , { name : $scope . fromModule . name } ) ;
@@ -396,7 +400,8 @@ angular.module('hesperides.diff', [])
396400
397401 $scope . openDiffPage = function ( ) {
398402 $mdDialog . hide ( ) ;
399- $window . open ( buildDiffDiffPageUrl ( $scope . fromPlatform , $scope . toPlatform , $scope . fromModule . properties_path , $scope . toModule . properties_path , $scope . lookPast , $scope . date ) , '_blank' ) ;
403+ const timestamp = dateToTimestamp ( $scope . lookPast , $scope . date ) ;
404+ $window . open ( buildDiffPageUrl ( $scope . fromPlatform , $scope . toPlatform , $scope . fromModule . properties_path , $scope . toModule . properties_path , $scope . lookPast , timestamp ) , '_blank' ) ;
400405 } ;
401406
402407 // Construtor initialization:
@@ -432,7 +437,7 @@ angular.module('hesperides.diff', [])
432437
433438 $scope . checkToPlatformExist = function ( ) {
434439 if ( $scope . diffForm ) {
435- let appHasPlatform = _ . some ( $scope . targetPlatforms , { name : $scope . toPlatform . platform } ) ;
440+ const appHasPlatform = _ . some ( $scope . targetPlatforms , { name : $scope . toPlatform . platform } ) ;
436441 $scope . diffForm . $setValidity ( 'toPlatformExist' , appHasPlatform ) ;
437442 }
438443 } ;
@@ -451,7 +456,8 @@ angular.module('hesperides.diff', [])
451456
452457 $scope . openDiffPage = function ( ) {
453458 $mdDialog . hide ( ) ;
454- $window . open ( buildDiffDiffPageUrl ( $scope . fromPlatform , $scope . toPlatform , '#' , '#' , $scope . lookPast , $scope . date ) , '_blank' ) ;
459+ const timestamp = dateToTimestamp ( $scope . lookPast , $scope . date ) ;
460+ $window . open ( buildDiffPageUrl ( $scope . fromPlatform , $scope . toPlatform , '#' , '#' , $scope . lookPast , timestamp ) , '_blank' ) ;
455461 } ;
456462
457463 // Construtor initialization:
@@ -471,7 +477,7 @@ angular.module('hesperides.diff', [])
471477 if ( $scope . ngModel ) {
472478 angular . element ( $document [ 0 ] . querySelector ( $scope . target ) ) . focus ( ) ;
473479 }
474- } ) ;
480+ } , 100 ) ; // Nécessaire pour faire fonctionner le focus au premier essai
475481 } ) ;
476482 } ,
477483 } ;
0 commit comments