Fix display on License Expiration resolves #1250 (#1860)

* API returns s, not ms! resolves #1250

* License - fix mixed tabs/spaces, move save successful message
This commit is contained in:
Leigh
2016-05-09 14:26:07 -04:00
parent 11e9792356
commit 268baa6b9b
2 changed files with 84 additions and 84 deletions

View File

@@ -5,91 +5,91 @@
*************************************************/ *************************************************/
export default export default
['Wait', '$state', '$scope', '$rootScope', '$location', 'GetBasePath', ['Wait', '$state', '$scope', '$rootScope', '$location', 'GetBasePath',
'Rest', 'ProcessErrors', 'CheckLicense', 'moment','$window', 'Rest', 'ProcessErrors', 'CheckLicense', 'moment','$window',
function( Wait, $state, $scope, $rootScope, $location, GetBasePath, Rest, function( Wait, $state, $scope, $rootScope, $location, GetBasePath, Rest,
ProcessErrors, CheckLicense, moment, $window){ ProcessErrors, CheckLicense, moment, $window){
$scope.getKey = function(event){ $scope.getKey = function(event){
// Mimic HTML5 spec, show filename // Mimic HTML5 spec, show filename
$scope.fileName = event.target.files[0].name; $scope.fileName = event.target.files[0].name;
// Grab the key from the raw license file // Grab the key from the raw license file
var raw = new FileReader(); var raw = new FileReader();
// readAsFoo runs async // readAsFoo runs async
raw.onload = function(){ raw.onload = function(){
try { try {
$scope.newLicense.file = JSON.parse(raw.result); $scope.newLicense.file = JSON.parse(raw.result);
} }
catch(err) { catch(err) {
ProcessErrors($rootScope, null, null, null, {msg: 'Invalid file format. Please upload valid JSON.'}); ProcessErrors($rootScope, null, null, null, {msg: 'Invalid file format. Please upload valid JSON.'});
} }
}; };
try { try {
raw.readAsText(event.target.files[0]); raw.readAsText(event.target.files[0]);
} }
catch(err) { catch(err) {
ProcessErrors($rootScope, null, null, null, {msg: 'Invalid file format. Please upload valid JSON.'}); ProcessErrors($rootScope, null, null, null, {msg: 'Invalid file format. Please upload valid JSON.'});
} }
}; };
// HTML5 spec doesn't provide a way to customize file input css // HTML5 spec doesn't provide a way to customize file input css
// So we hide the default input, show our own, and simulate clicks to the hidden input // So we hide the default input, show our own, and simulate clicks to the hidden input
$scope.fakeClick = function(){ $scope.fakeClick = function(){
$('#License-file').click(); $('#License-file').click();
}; };
$scope.downloadLicense = function(){ $scope.downloadLicense = function(){
$window.open('https://www.ansible.com/license', '_blank'); $window.open('https://www.ansible.com/license', '_blank');
}; };
$scope.newLicense = {}; $scope.newLicense = {};
$scope.submit = function(){ $scope.submit = function(){
Wait('start'); Wait('start');
CheckLicense.post($scope.newLicense.file, $scope.newLicense.eula) CheckLicense.post($scope.newLicense.file, $scope.newLicense.eula)
.success(function(){ .success(function(){
reset(); reset();
init(); init();
$scope.success = true; $scope.success = true;
// for animation purposes // for animation purposes
var successTimeout = setTimeout(function(){ var successTimeout = setTimeout(function(){
$scope.success = false; $scope.success = false;
clearTimeout(successTimeout); clearTimeout(successTimeout);
}, 4000); }, 4000);
if($rootScope.licenseMissing === true){ if($rootScope.licenseMissing === true){
$rootScope.licenseMissing = false; $rootScope.licenseMissing = false;
$state.go('dashboard'); $state.go('dashboard');
} }
else{ else{
$rootScope.licenseMissing = false; $rootScope.licenseMissing = false;
} }
}); });
}; };
var calcDaysRemaining = function(ms){ var calcDaysRemaining = function(seconds){
// calculate the number of days remaining on the license // calculate the number of days remaining on the license
var duration = moment.duration(ms); var duration = moment.duration(seconds, 'seconds');
return duration.days(); return duration.days();
}; };
var calcExpiresOn = function(days){ var calcExpiresOn = function(days){
// calculate the expiration date of the license // calculate the expiration date of the license
return moment().add(days, 'days').calendar(); return moment().add(days, 'days').calendar();
}; };
var init = function(){ var init = function(){
$scope.fileName = "No file selected."; $scope.fileName = "No file selected.";
$scope.title = $rootScope.licenseMissing ? "Tower License" : "License Management"; $scope.title = $rootScope.licenseMissing ? "Tower License" : "License Management";
Wait('start'); Wait('start');
CheckLicense.get() CheckLicense.get()
.then(function(res){ .then(function(res){
$scope.license = res.data; $scope.license = res.data;
$scope.license.version = res.data.version.split('-')[0]; $scope.license.version = res.data.version.split('-')[0];
$scope.time = {}; $scope.time = {};
$scope.time.remaining = calcDaysRemaining($scope.license.license_info.time_remaining); $scope.time.remaining = calcDaysRemaining($scope.license.license_info.time_remaining);
$scope.time.expiresOn = calcExpiresOn($scope.time.remaining); $scope.time.expiresOn = calcExpiresOn($scope.time.remaining);
$scope.valid = CheckLicense.valid($scope.license.license_info); $scope.valid = CheckLicense.valid($scope.license.license_info);
Wait('stop'); Wait('stop');
}); });
}; };
var reset = function(){ var reset = function(){
document.getElementById('License-form').reset(); document.getElementById('License-form').reset();
}; };
init(); init();
} }
]; ];

View File

@@ -118,8 +118,8 @@
</div> </div>
</div> </div>
<div class="License-submit--container"> <div class="License-submit--container">
<span ng-show="success == true" class="License-greenText License-submit--success pull-left">Save successful!</span>
<button ng-click="submit()" class="btn btn-success pull-right" ng-disabled="newLicense.file.license_key == null || newLicense.eula == null">Submit</button> <button ng-click="submit()" class="btn btn-success pull-right" ng-disabled="newLicense.file.license_key == null || newLicense.eula == null">Submit</button>
<span ng-show="success == true" class="License-greenText License-submit--success pull-right">Save successful!</span>
</div> </div>
</form> </form>
</div> </div>