rsanchez
2014-10-30 e2aa9b0177cdfeb9e3f26c511f541c37a03134aa
#2021 feature - Added menu color based on element status in packs and
licenses listings
4 files modified
changed files
securis/src/main/resources/static/js/admin.js patch | view | blame | history
securis/src/main/resources/static/js/licenses.js patch | view | blame | history
securis/src/main/resources/static/js/main.js patch | view | blame | history
securis/src/main/resources/static/licenses.html patch | view | blame | history
securis/src/main/resources/static/js/admin.js
....@@ -105,7 +105,7 @@
105105 toaster.pop('success', Catalogs.getName(), $L.get("Element deleted successfully"));
106106 },function(error) {
107107 console.log(error);
108
- toaster.pop('error', Catalogs.getName(), $L.get("Error deleting element, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR')), 10000);
108
+ toaster.pop('error', Catalogs.getName(), $L.get("Error deleting element, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR-MSG')), 10000);
109109 });
110110 }
111111 });
....@@ -180,7 +180,7 @@
180180 toaster.pop('success', Catalogs.getName(), $L.get("Element saved successfully"));
181181 }, function(error) {
182182 console.log(error);
183
- toaster.pop('error', Catalogs.getName(), $L.get("Error saving element, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR')), 10000);
183
+ toaster.pop('error', Catalogs.getName(), $L.get("Error saving element, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR-MSG')), 10000);
184184 });
185185 }
186186 }
securis/src/main/resources/static/js/licenses.js
....@@ -28,7 +28,8 @@
2828 'CA': $L.get('Cancelled')
2929 };
3030 /**
31
- * These transitions could be get from server, class Pack.Status, but we copy them for simplicity, this info won't change easily
31
+ * These transitions could be get from server, class Pack.Status, but we
32
+ * copy them for simplicity, this info won't change easily
3233 */
3334 var PACK_ACTIONS_BY_STATUS = {
3435 activate: [PACK_STATUS.CREATED, PACK_STATUS.EXPIRED, PACK_STATUS.ONHOLD],
....@@ -57,6 +58,21 @@
5758 }
5859 }
5960 );
61
+ this.getStatusColor = function(status) {
62
+ var COLORS_BY_STATUS = {
63
+ 'CR': '#808080',
64
+ 'AC': '#329e5a',
65
+ 'OH': '#9047c7',
66
+ 'EX': '#ea7824',
67
+ 'CA': '#a21717'
68
+ };
69
+
70
+ return COLORS_BY_STATUS[status];
71
+ },
72
+ this.getStatusName = function(status) {
73
+ return PACK_STATUSES[status];
74
+ }
75
+
6076 this.savePackData = function(pack, isNew, _onsuccess) {
6177 var _success = function() {
6278 _onsuccess();
....@@ -64,7 +80,7 @@
6480 }
6581 var _error = function(error) {
6682 console.log(error);
67
- toaster.pop('error', 'Packs', $L.get("Error {0} pack '{1}'. Reason: {2}", isNew ? $L.get("creating") : $L.get("updating"), pack.code, $L.get(error.headers('X-SECURIS-ERROR'))));
83
+ toaster.pop('error', 'Packs', $L.get("Error {0} pack '{1}'. Reason: {2}", isNew ? $L.get("creating") : $L.get("updating"), pack.code, $L.get(error.headers('X-SECURIS-ERROR-MSG'))));
6884 }
6985 packResource.save(pack, _success, _error);
7086 }
....@@ -73,10 +89,6 @@
7389 var validStatuses = PACK_ACTIONS_BY_STATUS[action];
7490 return pack && validStatuses && validStatuses.indexOf(pack.status) !== -1;
7591 }
76
- this.getStatusName = function(status) {
77
- return PACK_STATUSES[status];
78
- }
79
-
8092 var _createSuccessCallback = function(actionName, message, _innerCallback) {
8193 return function() {
8294 _innerCallback && _innerCallback();
....@@ -87,10 +99,10 @@
8799 return function(error) {
88100 console.log(error);
89101 _innerCallback && _innerCallback();
90
- toaster.pop('error', actionName, $L.get("Error on action '{0}', pack '{1}'. Reason: {2}", actionName, pack.code, $L.get(error.headers('X-SECURIS-ERROR'))));
102
+ toaster.pop('error', actionName, $L.get("Error on action '{0}', pack '{1}'. Reason: {2}", actionName, pack.code, $L.get(error.headers('X-SECURIS-ERROR-MSG'))));
91103 }
92104 }
93
- this.getPacksList = function(pack, _onsuccess, _onerror) {
105
+ this.getPacksList = function(_onsuccess, _onerror) {
94106 return packResource.query(_onsuccess, _onerror);
95107 }
96108 this.activate = function(pack, _onsuccess, _onerror) {
....@@ -141,24 +153,81 @@
141153 };
142154
143155 /**
144
- * These transitions could be get from server, class License.Status, but we copy them for simplicity, this info won't change easily
156
+ * These transitions could be get from server, class License.Status, but
157
+ * we copy them for simplicity, this info won't change easily
145158 */
146159 var LIC_ACTIONS_BY_STATUS = {
147160 activate: [LIC_STATUS.CREATED, LIC_STATUS.REQUESTED, LIC_STATUS.PREACTIVE],
148161 send: [LIC_STATUS.ACTIVE, LIC_STATUS.PREACTIVE],
149162 download: [LIC_STATUS.ACTIVE, LIC_STATUS.PREACTIVE],
163
+ block: [LIC_STATUS.CANCELLED],
164
+ unblock: [LIC_STATUS.CANCELLED],
150165 cancel: [LIC_STATUS.REQUESTED, LIC_STATUS.EXPIRED, LIC_STATUS.PREACTIVE, LIC_STATUS.ACTIVE],
151166 'delete': [LIC_STATUS.CREATED, LIC_STATUS.CANCELLED]
152167 }
168
+
169
+ var licenseResource = $resource('/license/:licenseId/:action', {
170
+ licenseId : '@id',
171
+ action : '@action'
172
+ },
173
+ {
174
+ activate: {
175
+ method: "POST",
176
+ params: {action: "activate"}
177
+ },
178
+ cancel: {
179
+ method: "POST",
180
+ params: {action: "cancel"}
181
+ },
182
+ download: {
183
+ method: "GET",
184
+ params: {action: "download"}
185
+ },
186
+ block: {
187
+ method: "POST",
188
+ params: {action: "block"}
189
+ },
190
+ send: {
191
+ method: "POST",
192
+ params: {action: "send"}
193
+ },
194
+ unblock: {
195
+ method: "POST",
196
+ params: {action: "unblock"}
197
+ }
198
+ });
199
+
153200
154201 this.isActionAvailable = function(action, lic) {
155202 var validStatuses = LIC_ACTIONS_BY_STATUS[action];
156203 return lic && validStatuses && validStatuses.indexOf(lic.status) !== -1;
157204 }
158
-
205
+ this.getStatusColor = function(status) {
206
+ var COLORS_BY_STATUS = {
207
+ 'CR': '#808080',
208
+ 'AC': '#329e5a',
209
+ 'RE': '#2981d4',
210
+ 'EX': '#ea7824',
211
+ 'CA': '#a21717'
212
+ };
213
+
214
+ return COLORS_BY_STATUS[status];
215
+ },
159216 this.getStatusName = function(status) {
160217 return LIC_STATUSES[status];
161218 }
219
+
220
+ this.saveLicenseData = function(license, isNew, _onsuccess) {
221
+ var _success = function() {
222
+ _onsuccess();
223
+ toaster.pop('success', 'Licenses', $L.get("License '{0}' {1} successfully", license.code, isNew ? $L.get("created") : $L.get("updated")));
224
+ }
225
+ var _error = function(error) {
226
+ console.log(error);
227
+ toaster.pop('error', 'Licenses', $L.get("Error {0} license '{1}'. Reason: {2}", isNew ? $L.get("creating") : $L.get("updating"), license.code, $L.get(error.headers('X-SECURIS-ERROR-MSG'))));
228
+ }
229
+ licenseResource.save(license, _success, _error);
230
+ }
162231
163232 var _createSuccessCallback = function(actionName, message, _innerCallback) {
164233 return function() {
....@@ -166,15 +235,16 @@
166235 toaster.pop('success', actionName, message);
167236 }
168237 }
169
- var _createErrorCallback = function(pack, actionName, _innerCallback) {
238
+ var _createErrorCallback = function(license, actionName, _innerCallback) {
170239 return function(error) {
171240 console.log(error);
172241 _innerCallback && _innerCallback();
173
- toaster.pop('error', actionName, $L.get("Error on action '{0}', pack '{1}'. Reason: {2}", actionName, pack.code, $L.get(error.headers('X-SECURIS-ERROR'))));
242
+ toaster.pop('error', actionName, $L.get("Error on action '{0}', license '{1}'. Reason: {2}", actionName, license.code, $L.get(error.headers('X-SECURIS-ERROR-MSG'))));
174243 }
175244 }
176
- this.getPacksList = function(pack, _onsuccess, _onerror) {
177
- return packResource.query(_onsuccess, _onerror);
245
+
246
+ this.getLicensesList = function(pack, _onsuccess, _onerror) {
247
+ return licenseResource.query({packId: pack.id}, _onsuccess, _onerror);
178248 }
179249 this.activate = function(license, _onsuccess, _onerror) {
180250 console.log('Activation on license: ' + license.id);
....@@ -218,14 +288,16 @@
218288 console.log('scope.license: ' + scope.$parent.license);
219289 var setter = $parse(attrs.fileLoader).assign;
220290 element.bind('change', function(evt) {
221
- if (!window.FileReader) { // Browser is not compatible
291
+ if (!window.FileReader) { // Browser is not
292
+ // compatible
222293 BootstrapDialog.alert($L.get("Open your .req file with a text editor and copy&paste the content in the form text field?"));
223294 return;
224295 }
225296 console.log('File selected');
226
- //console.log('scope.license: ' + scope.$parent.license);
297
+ // console.log('scope.license: ' +
298
+ // scope.$parent.license);
227299 var field = $parse(attrs.fileLoader);
228
- //console.log('field: ' + field);
300
+ // console.log('field: ' + field);
229301 var fileList = evt.target.files;
230302 if (fileList != null && fileList[0]) {
231303 var reader = new FileReader();
....@@ -314,7 +386,8 @@
314386 $scope.isNew = undefined;
315387
316388 // Selected pack from listing
317
- // pack is the edited pack, in creation contains the data for the new pack
389
+ // pack is the edited pack, in creation contains the data for
390
+ // the new pack
318391 $scope.pack = null;
319392
320393 $scope.packs = Packs.getPacksList();
....@@ -331,7 +404,8 @@
331404 }
332405
333406 /**
334
- * Execute an action over the pack, activation, onhold, cancellation
407
+ * Execute an action over the pack, activation, onhold,
408
+ * cancellation
335409 */
336410 $scope.execute = function(action, pack) {
337411 var _execute = function(extra_data) {
....@@ -348,7 +422,7 @@
348422 }
349423 }
350424 if (action === 'delete') {
351
- BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure ?", $scope.pack.code), function(answer) {
425
+ BootstrapDialog.confirm($L.get("The pack '{0}' will be deleted, are you sure ?", pack.code), function(answer) {
352426 if (answer) {
353427 _execute();
354428 }
....@@ -361,14 +435,13 @@
361435 message: function(dialog) {
362436 var $content = $('<div></div>');
363437 var $message = $('<div></div>');
364
- var pageToLoad = dialog.getData('pageToLoad');
365
- $message.append($('<label/>').text($L.get("The pack '{0}' and all its licenses will be cancelled, this action cannot be undone", $scope.pack.code)));
438
+ $message.append($('<label/>').text($L.get("The pack '{0}' and all its licenses will be cancelled, this action cannot be undone", pack.code)));
366439 $content.append($message);
367440
368441 var $message = $('<div style="margin-top:10pt;"/>');
369442 var pageToLoad = dialog.getData('pageToLoad');
370443 $message.append($('<label style="margin-right:5pt;"/>').text($L.get("Cancellation reason:") + " "));
371
- $message.append($('<input type="text" style="width:100%;" maxlength="512" id="_cancellation_reason"/>'));
444
+ $message.append($('<input type="text" style="width:100%;" maxlength="512" id="_pack_cancellation_reason"/>'));
372445 $content.append($message);
373446 return $content;
374447 },
....@@ -385,10 +458,10 @@
385458 label: $L.get('Cancel pack'),
386459 cssClass: 'btn-primary',
387460 action: function(dialogRef){
388
- var reason = $('#_cancellation_reason').val();
461
+ var reason = $('#_pack_cancellation_reason').val();
389462 console.log('Ready to cancel pack, by reason: ' + reason);
390463 if (!reason) {
391
- $('#_cancellation_reason').focus();
464
+ $('#_pack_cancellation_reason').focus();
392465 } else {
393466 _execute({reason: reason});
394467 dialogRef.close();
....@@ -413,7 +486,11 @@
413486 init_valid_date: new Date(),
414487 default_valid_period: 30,
415488 license_type_id: null,
416
- organization_id: null //!$scope.refs.organization_id || !$scope.refs.organization_id.length ? null : $scope.refs.organization_id[0].id
489
+ organization_id: null // !$scope.refs.organization_id
490
+ // ||
491
+ // !$scope.refs.organization_id.length
492
+ // ? null :
493
+ // $scope.refs.organization_id[0].id
417494 }
418495 setTimeout(function() {
419496 $('#code').focus();
....@@ -432,7 +509,9 @@
432509
433510 $scope.pack = selectedPack;
434511
435
- //$scope.pack.organization_name = $scope.getLabelFromId('organization_id', $scope.pack.organization_id);
512
+ // $scope.pack.organization_name =
513
+ // $scope.getLabelFromId('organization_id',
514
+ // $scope.pack.organization_id);
436515 $scope.pack.license_type_name = $scope.getLabelFromId('license_type_id', $scope.pack.license_type_id);
437516 $scope.pack.status_name = Packs.getStatusName($scope.pack.status);
438517
....@@ -452,7 +531,7 @@
452531 toaster.pop('success', Catalogs.getName(), $L.get("Pack '{0}' deleted successfully", selectedPack.code));
453532 },function(error) {
454533 console.log(error);
455
- toaster.pop('error', Catalogs.getName(), $L.get("Error deleting pack, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR')), 10000);
534
+ toaster.pop('error', Catalogs.getName(), $L.get("Error deleting pack, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR-MSG')), 10000);
456535 });
457536 }
458537 });
....@@ -493,7 +572,8 @@
493572 // Called when Application ID change in current field
494573 var newLTId = $scope.pack['license_type_id'];
495574 if (newLTId) {
496
- // Only if there is a "valid" value selected we should update the metadata
575
+ // Only if there is a "valid" value selected we should
576
+ // update the metadata
497577 Catalogs.getResource('licensetype').get({licenseTypeId: newLTId}).$promise.then(function(lt) {
498578 $scope.pack.metadata = [];
499579 lt.metadata.forEach(function(md) {
....@@ -520,7 +600,7 @@
520600 function($scope, $http, $resource, toaster, Licenses, $store, $L) {
521601 $scope.Licenses = Licenses;
522602 $scope.$on('pack_changed', function(evt, message) {
523
- $scope.licenses = licenseResource.query({packId: $scope.currentPack.id});
603
+ $scope.licenses = Licenses.getLicensesList($scope.currentPack);
524604 $scope.creationAvailable = $scope.currentPack.status == 'AC';
525605 if ($scope.showForm) {
526606 if ($scope.isNew) {
....@@ -531,28 +611,6 @@
531611 }
532612 })
533613
534
- var licenseResource = $resource('/license/:licenseId', {
535
- licenseId : '@id'
536
- }, {
537
- save_w_upload: {
538
- method: "POST",
539
- transformRequest: function(data, headersGetter) {
540
- // To use an object without FormData, follow: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest?redirectlocale=en-US&redirectslug=DOM%2FXMLHttpRequest%2FUsing_XMLHttpRequest#Submitting_forms_and_uploading_files
541
- var formData = new FormData();
542
- angular.forEach(data, function(value, key) {
543
- if (key !== 'request_data')
544
- formData.append(key, value)
545
- else
546
- formData.append(key, $('input#request_data_file').get(0).files[0]);
547
- })
548
-
549
- return formData;
550
- },
551
- headers: {
552
- 'Content-Type': undefined
553
- }
554
- }
555
- });
556614 $scope.mandatory = {
557615 code: true,
558616 email: true
....@@ -564,41 +622,29 @@
564622 }
565623 $scope.refs = {};
566624
567
- // Used to create the form with the appropriate data
625
+ // Used to create the form with the
626
+ // appropriate data
568627 $scope.isNew = undefined;
569628
570629 // Selected license from listing
571
- // license is the edited license, in creation contains the data for the new license
630
+ // license is the edited license, in
631
+ // creation contains the data for
632
+ // the new license
572633 $scope.license = null;
573
- if ($scope.currentPack)
574
- $scope.licenses = licenseResource.query({packId: $scope.currentPack.id});
575
-
576
-// $(document).on('change', '#request_data_file', function(newValue, oldValue) {
577
-// console.log('File changed!!!!');
578
-// var reader = new FileReader();
579
-// reader.onload = function(data) {
580
-// console.log('LOAD complete: ' + data);
581
-// console.log('LOAD reader.result: ' + reader.result);
582
-// $('input#request_data').val(reader.result)
583
-// }
584
-// console.log('file: ' + $('input#request_data_file').get(0).files[0]);
585
-// console.log('file2: ' + $scope.request_data_file);
586
-// reader.readAsText($('input#request_data_file').get(0).files[0]);
587
-// });
588
-
589
- $scope.save = function() {
590
- //$( "form#licenseForm" ).attr( "enctype", "multipart/form-data" ).attr( "encoding", "multipart/form-data" );
591
- var _success = function() {
592
- if (!$scope.isNew) $scope.showForm = false;
593
- $scope.licenses = licenseResource.query({packId: $scope.currentPack.id});
594
- toaster.pop('success', Catalogs.getName(), $L.get("License '{0}' {1} successfully", $scope.license.code, $scope.isNew ? $L.get("created") : $L.get("updated")));
595
- }
596
- var _error = function(error) {
597
- console.log(error);
598
- toaster.pop('error', Catalogs.getName(), $L.get("Error {0} license '{1}'. Reason: {2}", $scope.isNew ? $L.get("creating") : $L.get("updating"), $scope.pack.code, $L.get(error.headers('X-SECURIS-ERROR'))));
599
- }
600
- licenseResource.save($scope.license, _success, _error)
634
+ if ($scope.currentPack) {
635
+ $scope.licenses = Licenses.getLicensesList($scope.currentPack);
601636 }
637
+
638
+ $scope.save = function() {
639
+ Licenses.saveLicenseData($scope.license, $scope.isNew, function() {
640
+ if (!$scope.isNew) {
641
+ $scope.showForm = false;
642
+ } else {
643
+ $scope.newLicense();
644
+ }
645
+ $scope.licenses = Licenses.getLicensesList($scope.currentPack);
646
+ });
647
+ }
602648
603649 $scope.newLicense = function() {
604650 if (!$scope.currentPack) {
....@@ -658,17 +704,88 @@
658704 var promise = licenseResource.remove({}, {id: selectedlicense.id}).$promise;
659705 promise.then(function(data) {
660706 $scope.selectlicense(null);
661
- $scope.licenses = licenseResource.query({packId: $scope.currentPack.id});
707
+ $scope.licenses = Licenses.getLicensesList($scope.currentPack);
662708 toaster.pop('success', Catalogs.getName(), $L.get("License '{0}' deleted successfully", selectedlicense.code));
663709 },function(error) {
664710 console.log(error);
665
- toaster.pop('error', Catalogs.getName(), $L.get("Error deleting license, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR')), 10000);
711
+ toaster.pop('error', Catalogs.getName(), $L.get("Error deleting license, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR-MSG')), 10000);
666712 });
667713 }
668714 });
669715 $scope.isNew = false;
670716 }
671717
718
+ $scope.execute = function(action, license) {
719
+ if (!license) {
720
+ license = $scope.license;
721
+ }
722
+ var _execute = function(extra_data) {
723
+ if (extra_data) {
724
+ Licenses[action](license, extra_data, function() {
725
+ if (!$scope.isNew) $scope.showForm = false;
726
+ $scope.licenses = Licenses.getLicensesList($scope.currentPack);
727
+ });
728
+ } else {
729
+ Licenses[action](license, function() {
730
+ if (!$scope.isNew) $scope.showForm = false;
731
+ $scope.licenses = Licenses.getLicensesList($scope.currentPack);
732
+ });
733
+ }
734
+ }
735
+ if (action === 'delete') {
736
+ BootstrapDialog.confirm($L.get("The license '{0}' will be deleted, are you sure?", license.code), function(result){
737
+ if(result) {
738
+ _execute();
739
+ }
740
+ });
741
+ } else {
742
+ if (action === 'cancel') {
743
+ BootstrapDialog.show({
744
+ title: $L.get("License cancellation"),
745
+ type: BootstrapDialog.TYPE_DANGER,
746
+ message: function(dialog) {
747
+ var $content = $('<div></div>');
748
+ var $message = $('<div></div>');
749
+ var pageToLoad = dialog.getData('pageToLoad');
750
+ $message.append($('<label/>').text($L.get("This action cannot be undone.", $scope.pack.code)));
751
+ $content.append($message);
752
+
753
+ var $message = $('<div style="margin-top:10pt;"/>');
754
+ $message.append($('<label style="margin-right:5pt;"/>').text($L.get("Cancellation reason:") + " "));
755
+ $message.append($('<input type="text" style="width:100%;" maxlength="512" id="_lic_cancellation_reason"/>'));
756
+ $content.append($message);
757
+ return $content;
758
+ },
759
+ closable: true,
760
+ buttons: [{
761
+ id: 'btn-cancel',
762
+ label: $L.get('Close'),
763
+ cssClass: 'btn-default',
764
+ action: function(dialogRef) {
765
+ dialogRef.close();
766
+ }
767
+ }, {
768
+ id: 'btn-ok',
769
+ label: $L.get('Cancel license'),
770
+ cssClass: 'btn-primary',
771
+ action: function(dialogRef){
772
+ var reason = $('#_lic_cancellation_reason').val();
773
+ console.log('Ready to cancel license, by reason: ' + reason);
774
+ if (!reason) {
775
+ $('#_lic_cancellation_reason').focus();
776
+ } else {
777
+ _execute({reason: reason});
778
+ dialogRef.close();
779
+ }
780
+ }
781
+ }]
782
+ });
783
+ } else {
784
+ _execute();
785
+ }
786
+ }
787
+ }
788
+
672789
673790 $scope.cancel = function() {
674791 $scope.showForm = false;
securis/src/main/resources/static/js/main.js
....@@ -1,6 +1,6 @@
11 (function() {
22 'use strict';
3
-
3
+
44 var m = angular.module('securis', [ 'ngRoute', 'ngResource', 'toaster', 'localytics.directives', 'catalogs', 'i18n' ]);
55
66 m.service('$store', function() {
....@@ -20,75 +20,76 @@
2020 return store.getAll();
2121 }
2222 });
23
-
23
+
2424 m.factory('securisHttpInterceptor', function($q, $location, $store, toaster) {
2525 var isUnauthorizedAccess = function(rejection) {
2626 return rejection.status === 401 /* Unauthorized */;
2727 }
28
- return {
29
- 'request': function(config) {
30
- var token = $store.get('token');
31
- if (token) {
32
- var la = $store.get('last_access');
33
- var now = new Date().getTime();
34
- if (la !== null) {
35
- if (now > (la + 1800000)) { // Session timeout is 1/2 hour
36
- $store.clear();
37
- $location.path('/login');
38
- toaster.pop('warning', 'Session has expired', null, 4000);
39
- } else {
40
- console.debug('Last access recent');
41
- }
42
- }
43
- $store.set('last_access', now);
44
- }
45
- return config || $q.when(config);
46
- },
47
- 'responseError': function(rejection) {
48
- // do something on error
49
- if (isUnauthorizedAccess(rejection)) {
50
- if ($location.path() !== '/login') {
51
- $store.clear();
52
- $location.path('/login');
53
- console.error('There was an unathorized access to url {0}, method: {1}'.$i18n(rejection.config.url, rejection.config.method));
54
- } else {
55
- // console.log('Error on login ...')
56
- }
57
- }
58
- return $q.reject(rejection);
59
- }
60
- };
61
- });
28
+ return {
29
+ 'request': function(config) {
30
+ var token = $store.get('token');
31
+ if (token) {
32
+ var la = $store.get('last_access');
33
+ var now = new Date().getTime();
34
+ if (la !== null) {
35
+ if (now > (la + 1800000)) { // Session timeout is 1/2
36
+ // hour
37
+ $store.clear();
38
+ $location.path('/login');
39
+ toaster.pop('warning', 'Session has expired', null, 4000);
40
+ } else {
41
+ console.debug('Last access recent');
42
+ }
43
+ }
44
+ $store.set('last_access', now);
45
+ }
46
+ return config || $q.when(config);
47
+ },
48
+ 'responseError': function(rejection) {
49
+ // do something on error
50
+ if (isUnauthorizedAccess(rejection)) {
51
+ if ($location.path() !== '/login') {
52
+ $store.clear();
53
+ $location.path('/login');
54
+ console.error('There was an unathorized access to url {0}, method: {1}'.$i18n(rejection.config.url, rejection.config.method));
55
+ } else {
56
+ // console.log('Error on login ...')
57
+ }
58
+ }
59
+ return $q.reject(rejection);
60
+ }
61
+ };
62
+ });
6263
6364 m.config(function($routeProvider, $locationProvider, $httpProvider) {
6465 console.debug('Configuring routes...');
65
- $routeProvider.when('/login', {
66
- templateUrl: 'login.html',
67
- controller: 'LoginCtrl'
68
- });
69
- $routeProvider.when('/licenses', {
70
- templateUrl: 'licenses.html',
71
- controller: 'PackAndLicensesCtrl'
72
- });
73
- $routeProvider.when('/admin', {
74
- templateUrl: 'admin.html',
75
- controller: 'AdminCtrl'
76
- });
77
-
78
- // configure html5 to get links working on jsfiddle
79
- $locationProvider.html5Mode(true);
80
- $httpProvider.interceptors.push('securisHttpInterceptor');
66
+ $routeProvider.when('/login', {
67
+ templateUrl: 'login.html',
68
+ controller: 'LoginCtrl'
8169 });
82
-
70
+ $routeProvider.when('/licenses', {
71
+ templateUrl: 'licenses.html',
72
+ controller: 'PackAndLicensesCtrl'
73
+ });
74
+ $routeProvider.when('/admin', {
75
+ templateUrl: 'admin.html',
76
+ controller: 'AdminCtrl'
77
+ });
78
+
79
+ // configure html5 to get links working on jsfiddle
80
+ $locationProvider.html5Mode(true);
81
+ $httpProvider.interceptors.push('securisHttpInterceptor');
82
+ });
83
+
8384 m.controller('MainCtrl', ['$scope', '$http', '$location', '$L', '$store',
84
- function($scope, $http, $location, $L, $store) {
85
-
85
+ function($scope, $http, $location, $L, $store) {
86
+
8687 $scope.currentRoute = null;
8788 console.log('Current location: ' + $location);
8889 console.log($location);
8990 $location.path('/login');
9091 if ($store.get('token') != null) {
91
-
92
+
9293 $http.get('/check', {
9394 headers: {
9495 'X-SECURIS-TOKEN': $store.get('token')
....@@ -98,18 +99,18 @@
9899 $http.defaults.headers.common['X-SECURIS-TOKEN'] = $store.get('token');
99100 var location = $store.get('location') || '/licenses';
100101
101
- $location.path(location);
102
+ $location.path(location);
102103 $store.set('user', data.user);
103104 }
104105 });
105106 }
106
-
107
+
107108 $scope.logout = function() {
108109 $store.remove('user');
109110 $store.remove('token');
110111 $location.path('/login');
111112 }
112
-
113
- }]);
114
-
113
+
114
+ }]);
115
+
115116 })();
securis/src/main/resources/static/licenses.html
....@@ -294,8 +294,29 @@
294294 title="Total: {{p.num_licenses}}, available: {{p.num_available}}">{{p.num_licenses}}
295295 ({{p.num_available}})</td>
296296 <td>
297
- <span ng-click="editPack(p)" class="glyphicon glyphicon-pencil"></span>
298
- <span ng-if="Packs.isActionAvailable('delete', p)" ng-click="execute('delete', p)" class="glyphicon glyphicon-remove"></span>
297
+ <div class="dropdown">
298
+ <a class="dropdown-toggle" data-toggle="dropdown"> <span
299
+ class="glyphicon glyphicon-align-justify" style="color: {{Packs.getStatusColor(p.status)}}"></span>
300
+ <span style="color: {{Packs.getStatusColor(p.status)}}" class="caret"></span>
301
+ </a>
302
+ <ul class="dropdown-menu">
303
+ <li ng-if="Packs.isActionAvailable('edit', p)"><a
304
+ ng-click="editPack(p)"><span
305
+ class="glyphicon glyphicon-pencil"></span> <span i18n>Edit</span></a></li>
306
+ <li ng-if="Packs.isActionAvailable('activate', p)"><a
307
+ ng-click="execute('activate', p)"><span
308
+ class="glyphicon glyphicon-check"></span> <span i18n>Activate</span></a></li>
309
+ <li ng-if="Packs.isActionAvailable('putonhold', p)"><a
310
+ ng-click="execute('putonhold', p)"><span
311
+ class="glyphicon glyphicon-pause"></span> <span i18n>Put on hold</span></a></li>
312
+ <li ng-if="Packs.isActionAvailable('cancel', p)"><a
313
+ ng-click="execute('cancel', p)"><span
314
+ class="glyphicon glyphicon-ban-circle"></span> <span i18n>Cancel</span></a></li>
315
+ <li ng-if="Packs.isActionAvailable('delete', p)"><a
316
+ ng-click="execute('delete', p)"><span
317
+ class="glyphicon glyphicon-trash"></span> <span i18n>Delete</span></a></li>
318
+ </ul>
319
+ </div>
299320 </td>
300321 </tr>
301322 </tbody>
....@@ -566,11 +587,11 @@
566587 <span class="caret"></span>
567588 </button>
568589 <ul class="dropdown-menu" role="menu">
569
- <li ng-if="Licenses.isActionAvailable('activate', license)"><a ng-click="activateLicense(license)" href="#">Activate</a></li>
570
- <li ng-if="Licenses.isActionAvailable('download', license)"><a ng-click="downloadLicense(license)" href="#">Download</a></li>
571
- <li ng-if="Licenses.isActionAvailable('send', license)"><a ng-click="sendLicense(license)" href="#">Send by email</a></li>
572
- <li ng-if="Licenses.isActionAvailable('cancel', license)"><a ng-click="cancelLicense(license)" href="#">Invalidate</a></li>
573
- <li ng-if="Licenses.isActionAvailable('delete', license)"><a ng-click="removeLicense(license)" href="#">Delete</a></li>
590
+ <li ng-if="Licenses.isActionAvailable('activate', license)"><a ng-click="execute('activate', license)" href="#">Activate</a></li>
591
+ <li ng-if="Licenses.isActionAvailable('download', license)"><a ng-click="execute('download', license)" href="#">Download</a></li>
592
+ <li ng-if="Licenses.isActionAvailable('send', license)"><a ng-click="execute('send', license)" href="#">Send by email</a></li>
593
+ <li ng-if="Licenses.isActionAvailable('cancel', license)"><a ng-click="execute('cancel', license)" href="#">Cancel</a></li>
594
+ <li ng-if="Licenses.isActionAvailable('delete', license)"><a ng-click="execute('delete', license)" href="#">Delete</a></li>
574595 </ul>
575596
576597 </div>
....@@ -608,28 +629,33 @@
608629 <td>
609630 <div class="dropdown">
610631 <a class="dropdown-toggle" data-toggle="dropdown"> <span
611
- class="glyphicon glyphicon-align-justify"></span> <span
612
- class="caret"></span>
632
+ class="glyphicon glyphicon-align-justify" style="color: {{Licenses.getStatusColor(lic.status)}}"></span>
633
+ <span style="color: {{Licenses.getStatusColor(lic.status)}}" class="caret"></span>
613634 </a>
614635 <ul class="dropdown-menu">
615636 <li ng-if="Licenses.isActionAvailable('download', lic)"><a
616
- ng-click="downloadLicense(lic)"><span
637
+ ng-click="execute('download', lic)"><span
617638 class="glyphicon glyphicon-download"></span> <span i18n>Download</span></a></li>
618639 <li ng-if="Licenses.isActionAvailable('edit', lic)"><a
619640 ng-click="editLicense(lic)"><span
620641 class="glyphicon glyphicon-pencil"></span> <span i18n>Edit</span></a></li>
621642 <li ng-if="Licenses.isActionAvailable('activate', lic)"><a
622
- ng-click="activateLicense(lic)"><span
643
+ ng-click="execute('activate', lic)"><span
623644 class="glyphicon glyphicon-check"></span> <span i18n>Activate</span></a></li>
624645 <li ng-if="Licenses.isActionAvailable('send', lic)"><a
625
- ng-click="sendEmail(lic)"><span
626
- class="glyphicon glyphicon-send"></span> <span i18n>Send
627
- email</span></a></li>
646
+ ng-click="execute('send', lic)"><span
647
+ class="glyphicon glyphicon-send"></span> <span i18n>Send email</span></a></li>
648
+ <li ng-if="Licenses.isActionAvailable('block', lic)"><a
649
+ ng-click="execute('block', lic)"><span
650
+ class="glyphicon glyphicon-exclamation-sign"></span> <span i18n>Block</span></a></li>
651
+ <li ng-if="Licenses.isActionAvailable('unblock', lic)"><a
652
+ ng-click="execute('unblock', lic)"><span
653
+ class="glyphicon glyphicon-ok-sign"></span> <span i18n>Unblock</span></a></li>
628654 <li ng-if="Licenses.isActionAvailable('cancel', lic)"><a
629
- ng-click="deleteLicense(lic)"><span
655
+ ng-click="execute('cancel', lic)"><span
630656 class="glyphicon glyphicon-ban-circle"></span> <span i18n>Cancel</span></a></li>
631657 <li ng-if="Licenses.isActionAvailable('delete', lic)"><a
632
- ng-click="deleteLicense(lic)"><span
658
+ ng-click="execute('delete', lic)"><span
633659 class="glyphicon glyphicon-trash"></span> <span i18n>Delete</span></a></li>
634660 </ul>
635661 </div>