From 15773ba2429ee765781e0929a833436589530edb Mon Sep 17 00:00:00 2001 From: Jared Tabor Date: Thu, 21 May 2015 23:10:12 -0400 Subject: [PATCH] demodalizing the license modal the license modal is now its own standalone page. this commit includes demodalizing the license page, directing the user to this page if no license exists, redirects the user to hte home page when a license is entered, and adds the license type to the license page and the About Tower modal. It also includes a small change to the aw-feature directive to better handle a session that does not have a license yet. --- awx/ui/static/js/app.js | 18 +- awx/ui/static/js/controllers/License.js | 191 +++++++ awx/ui/static/js/forms/LicenseForm.js | 6 + awx/ui/static/js/helpers/AboutAnsible.js | 19 +- awx/ui/static/js/helpers/License.js | 532 ++++-------------- .../js/shared/features/features.controller.js | 6 +- awx/ui/static/less/ansible-ui.less | 6 +- awx/ui/static/partials/cowsay-about.html | 6 +- awx/ui/static/partials/license.html | 4 + awx/ui/templates/ui/index.html | 2 +- 10 files changed, 362 insertions(+), 428 deletions(-) create mode 100644 awx/ui/static/js/controllers/License.js create mode 100644 awx/ui/static/partials/license.html diff --git a/awx/ui/static/js/app.js b/awx/ui/static/js/app.js index d67b469e35..20fd1f1f66 100644 --- a/awx/ui/static/js/app.js +++ b/awx/ui/static/js/app.js @@ -42,6 +42,7 @@ import browserData from 'tower/browser-data/main'; import {JobDetailController} from 'tower/controllers/JobDetail'; import {JobStdoutController} from 'tower/controllers/JobStdout'; import {JobTemplatesList, JobTemplatesAdd, JobTemplatesEdit} from 'tower/controllers/JobTemplates'; +import {LicenseController} from 'tower/controllers/License'; import {ScheduleEditController} from 'tower/controllers/Schedules'; import {ProjectsList, ProjectsAdd, ProjectsEdit} from 'tower/controllers/Projects'; import {OrganizationsList, OrganizationsAdd, OrganizationsEdit} from 'tower/controllers/Organizations'; @@ -888,6 +889,17 @@ var tower = angular.module('Tower', [ } }). + when('/license', { + name: 'license', + templateUrl: urlPrefix + 'partials/license.html', + controller: LicenseController, + resolve: { + features: ['FeaturesService', function(FeaturesService) { + return FeaturesService.get(); + }] + } + }). + when('/sockets', { name: 'sockets', templateUrl: urlPrefix + 'partials/sockets.html', @@ -914,9 +926,9 @@ var tower = angular.module('Tower', [ }]) .run(['$compile', '$cookieStore', '$rootScope', '$log', 'CheckLicense', '$location', 'Authorization', 'LoadBasePaths', 'Timer', 'ClearScope', 'HideStream', 'Socket', - 'LoadConfig', 'Store', 'ShowSocketHelp', 'LicenseViewer', 'AboutAnsibleHelp', 'ConfigureTower', 'CreateCustomInventory', + 'LoadConfig', 'Store', 'ShowSocketHelp', 'AboutAnsibleHelp', 'ConfigureTower', 'CreateCustomInventory', function ($compile, $cookieStore, $rootScope, $log, CheckLicense, $location, Authorization, LoadBasePaths, Timer, ClearScope, HideStream, Socket, - LoadConfig, Store, ShowSocketHelp, LicenseViewer, AboutAnsibleHelp, ConfigureTower, CreateCustomInventory) { + LoadConfig, Store, ShowSocketHelp, AboutAnsibleHelp, ConfigureTower, CreateCustomInventory) { var e, html, sock; @@ -1107,7 +1119,7 @@ var tower = angular.module('Tower', [ }; $rootScope.viewLicense = function () { - LicenseViewer.showViewer(); + $location.path('/license'); }; $rootScope.toggleTab = function(e, tab, tabs) { e.preventDefault(); diff --git a/awx/ui/static/js/controllers/License.js b/awx/ui/static/js/controllers/License.js new file mode 100644 index 0000000000..b870026854 --- /dev/null +++ b/awx/ui/static/js/controllers/License.js @@ -0,0 +1,191 @@ +/************************************ + * Copyright (c) 2014 AnsibleWorks, Inc. + * + * + * Organizations.js + * + * Controller functions for Organization model. + * + */ +/** + * @ngdoc function + * @name controllers.function:Organizations + * @description This controller's for the Organizations page +*/ + + +export function LicenseController(ClearScope, $location, $rootScope, $compile, $filter, GenerateForm, Rest, Alert, + GetBasePath, ProcessErrors, FormatDate, Prompt, Empty, LicenseForm, IsAdmin, CreateDialog, CheckLicense, + TextareaResize, $scope) { + + ClearScope(); + + $scope.getDefaultHTML = function(license_info) { + var fld, html, + self = this, + generator = GenerateForm; + + self.form = angular.copy(LicenseForm); + + for (fld in self.form.fields) { + if (fld !== 'time_remaining' && fld !== 'license_status' && fld !== 'tower_version') { + if (Empty(license_info[fld])) { + delete self.form.fields[fld]; + } + } + } + + if (!IsAdmin()) { + delete self.form.fields.license_key; + } + + if (license_info.is_aws || Empty(license_info.license_date)) { + delete self.form.fields.license_date; + delete self.form.fields.time_remaining; + } + + html = generator.buildHTML(self.form, { mode: 'edit', showButtons: false, breadCrumbs: false }); + return html; + }; + + $scope.loadDefaultScope = function(license_info, version) { + var fld, dt, days, license, + self = this; + + for (fld in self.form.fields) { + if (!Empty(license_info[fld])) { + $scope[fld] = license_info[fld]; + } + } + + $scope.tower_version = version; + + if ($scope.license_date) { + dt = new Date(parseInt($scope.license_date, 10) * 1000); // expects license_date in seconds + $scope.license_date = FormatDate(dt); + $scope.time_remaining = parseInt($scope.time_remaining,10) * 1000; + if ($scope.time_remaining < 0) { + days = 0; + } else { + days = Math.floor($scope.time_remaining / 86400000); + } + $scope.time_remaining = (days!==1) ? $filter('number')(days, 0) + ' days' : $filter('number')(days, 0) + ' day'; // '1 day' and '0 days/2 days' or more + } + + if (parseInt($scope.free_instances) <= 0) { + $scope.free_instances_class = 'field-failure'; + } else { + $scope.free_instances_class = 'field-success'; + } + + license = license_info; + if (license.valid_key === undefined) { + $scope.license_status = 'Missing License Key'; + $scope.status_color = 'license-invalid'; + } else if (!license.valid_key) { + $scope.license_status = 'Invalid License Key'; + $scope.status_color = 'license-invalid'; + } else if (license.date_expired !== undefined && license.date_expired) { + $scope.license_status = 'License Expired'; + $scope.status_color = 'license-expired'; + } else if (license.date_warning !== undefined && license.date_warning) { + $scope.license_status = 'License Expiring Soon'; + $scope.status_color = 'license-warning'; + } else if (license.free_instances !== undefined && parseInt(license.free_instances) <= 0) { + $scope.license_status = 'No Available Managed Hosts'; + $scope.status_color = 'license-invalid'; + } else { + $scope.license_status = 'Valid License'; + $scope.status_color = 'license-valid'; + } + }; + + $scope.setLicense = function(license_info, version) { + this.license = license_info; + this.version = version; + }; + + $scope.getLicense = function(){ + return this.license; + }; + + $scope.submitLicenseKey = function() { + CheckLicense.postLicense($scope.license_json, $scope); + }; + + if ($scope.removeLicenseDataReady) { + $scope.removeLicenseDataReady(); + } + $scope.removeLicenseDataReady = $scope.$on('LicenseDataReady', function(e, data) { + var html, version, eula, h; + version = data.version.replace(/-.*$/,''); + $scope.setLicense(data.license_info, version); + html = $scope.getDefaultHTML(data.license_info); + $scope.loadDefaultScope(data.license_info, version); + eula = (data.eula) ? data.eula : "" ; + + e = angular.element(document.getElementById('license-modal-dialog')); + e.empty().html(html); + + $scope.parseType = 'json'; + $scope.license_json = JSON.stringify($scope.license, null, ' '); + $scope.eula = eula; + $scope.eula_agreement = false; + + + h = CheckLicense.getHTML($scope.getLicense(),true).body; + $('#license-modal-dialog #license_tabs').append("
  • Update License
  • "); + $('#license-modal-dialog .tab-content').append("
    "); + $('#license-modal-dialog #update_license').html(h); + + if ($scope.license_status === 'Invalid License Key' || $scope.license_status === 'Missing License Key') { + $('#license_tabs li:eq(1)').hide(); + $('#license_tabs li:eq(2) a').tab('show'); + } + + setTimeout(function() { + $('#license_license_json').attr('ng-required' , 'true' ); + $('#license_eula_agreement_chbox').attr('ng-required' , 'true' ); + $('#license_form_submit_btn').attr('ng-disabled' , "license_form.$invalid" ); + var e = angular.element(document.getElementById('license-modal-dialog')); + $compile(e)($scope); + // $('#license-modal-dialog').dialog('open'); + }, 300); + + if (IsAdmin()) { + setTimeout(function() { + TextareaResize({ + scope: $scope, + textareaId: 'license_license_json', + modalId: 'license-modal-dialog', + formId: 'license-notification-body', + fld: 'license_json', + parse: true, + bottom_margin: 90, + onChange: function() { $scope.license_json_api_error = ''; } + }); + }, 300); + } + $('#license-ok-button').focus(); + $('#update_license_link').on('shown.bs.tab', function() { + if (IsAdmin()) { + TextareaResize({ + scope: $scope, + textareaId: 'license_license_json', + modalId: 'license-modal-dialog', + formId: 'license-notification-body', + fld: 'license_json', + bottom_margin: 90, + parse: true, + onChange: function() { $scope.license_json_api_error = ''; } + }); + } + }); + }); + CheckLicense.GetLicense('LicenseDataReady', $scope); + + } + +LicenseController.$inject = ['ClearScope', '$location', '$rootScope', '$compile', '$filter', 'GenerateForm', 'Rest', 'Alert', +'GetBasePath', 'ProcessErrors', 'FormatDate', 'Prompt', 'Empty', 'LicenseForm', 'IsAdmin', 'CreateDialog', +'CheckLicense', 'TextareaResize', '$scope']; diff --git a/awx/ui/static/js/forms/LicenseForm.js b/awx/ui/static/js/forms/LicenseForm.js index 923873444e..5859dbe189 100644 --- a/awx/ui/static/js/forms/LicenseForm.js +++ b/awx/ui/static/js/forms/LicenseForm.js @@ -40,6 +40,12 @@ export default readonly: true, tab: 'license' }, + license_type: { + label: 'License Type', + type: 'text', + readonly: true, + tab: 'license' + }, license_key: { label: 'License Key', type: 'textarea', diff --git a/awx/ui/static/js/helpers/AboutAnsible.js b/awx/ui/static/js/helpers/AboutAnsible.js index 999e4063f8..d548bbdacd 100644 --- a/awx/ui/static/js/helpers/AboutAnsible.js +++ b/awx/ui/static/js/helpers/AboutAnsible.js @@ -52,19 +52,22 @@ export default scope.removeBuildAboutDialog(); } scope.removeBuildAboutDialog = scope.$on('BuildAboutDialog', function(e, data) { - var spaces, i, j, - paddedStr = "", - version = data.version.replace(/-.*$/,''); + var spaces, i, + paddedStr = "", l, + version = data.version.replace(/-.*$/,''), + license_type = data.license_info.license_type; - spaces = Math.floor((16-version.length)/2); + // get the length of the license type and the word license (7) plus the extra spaces (4) + l = license_type.length + 11; + + spaces = Math.floor(l-(version.length + 10)); // 8 comes from " Tower " for( i=0; i<=spaces; i++){ paddedStr = paddedStr +" "; } - paddedStr = paddedStr+version; - for( j = paddedStr.length; j<16; j++){ - paddedStr = paddedStr + " "; - } + paddedStr = version+paddedStr; $('#about-modal-version').html(paddedStr); + $('#about-modal-license-type').html(license_type); + scope.modalOK = function(){ $('#about-modal-dialog').dialog('close'); }; diff --git a/awx/ui/static/js/helpers/License.js b/awx/ui/static/js/helpers/License.js index ad0c36e127..92335a1791 100644 --- a/awx/ui/static/js/helpers/License.js +++ b/awx/ui/static/js/helpers/License.js @@ -21,11 +21,16 @@ import 'tower/forms'; export default - angular.module('LicenseHelper', ['RestServices', 'Utilities', 'LicenseUpdateFormDefinition', 'FormGenerator', 'ParseHelper', 'ModalDialog', 'VariablesHelper', 'LicenseFormDefinition', 'AccessHelper']) + angular.module('LicenseHelper', ['RestServices', 'Utilities', 'LicenseUpdateFormDefinition', + 'FormGenerator', 'ParseHelper', 'ModalDialog', 'VariablesHelper', 'LicenseFormDefinition', + 'AccessHelper']) - .factory('CheckLicense', ['$rootScope', '$compile', 'CreateDialog', 'Store', 'LicenseUpdateForm', 'GenerateForm', 'TextareaResize', 'ToJSON', 'GetBasePath', 'Rest', 'ProcessErrors', 'Alert', 'IsAdmin', - function($rootScope, $compile, CreateDialog, Store, LicenseUpdateForm, GenerateForm, TextareaResize, ToJSON, GetBasePath, Rest, ProcessErrors, Alert, IsAdmin) { + .factory('CheckLicense', ['$rootScope', '$compile', 'CreateDialog', 'Store', + 'LicenseUpdateForm', 'GenerateForm', 'TextareaResize', 'ToJSON', 'GetBasePath', + 'Rest', 'ProcessErrors', 'Alert', 'IsAdmin', '$location', + function($rootScope, $compile, CreateDialog, Store, LicenseUpdateForm, GenerateForm, + TextareaResize, ToJSON, GetBasePath, Rest, ProcessErrors, Alert, IsAdmin, $location) { return { getRemainingDays: function(time_remaining) { // assumes time_remaining will be in seconds @@ -170,6 +175,7 @@ export default // ignore } Alert('License Accepted', 'The Ansible Tower license was updated. To view or update license information in the future choose View License from the Account menu.','alert-info'); + $location.path('/home'); }) .error(function (data, status) { scope.license_json_api_error = "A valid license key in JSON format is required"; @@ -186,7 +192,7 @@ export default var license = Store('license'), notify = this.shouldNotify(license), self = this, - scope, height, html, buttons; + scope; self.scope = $rootScope.$new(); scope = self.scope; @@ -204,118 +210,119 @@ export default return true; // if the license is valid it would exit 'test' here, otherwise it moves on to making the modal for the license } - html = this.getHTML(license); - $('#license-modal-dialog').html(html.body); - - scope.flashMessage = null; - scope.parseType = 'json'; - - scope.removeLicenseDialogReady = scope.$on('LicenseDialogReady', function() { - $('#license_license_json').attr('ng-required' , 'true' ); - $('#license_eula_agreement_chbox').attr('ng-required' , 'true' ); - $('#license-submit-button').attr('ng-disabled' , "license_form.$invalid" ); - var e = angular.element(document.getElementById('license-modal-dialog')); - $compile(e)(scope); - e = angular.element(document.getElementById('license-submit-button')); - $compile(e)(scope); - $('#license-modal-dialog').dialog('open'); - }); - - scope.submitLicenseKey = function() { - self.postLicense(scope.license_json); - }; - - if (IsAdmin()) { - buttons = [{ - label: "Cancel", - onClick: function() { - $('#license-modal-dialog').dialog('close'); - }, - "class": "btn btn-default", - "id": "license-cancel-button" - }, { - label: "Submit", - onClick: function() { - scope.submitLicenseKey(); - }, - "class": "btn btn-primary", - "id": "license-submit-button" - }]; - } else { - buttons = [{ - label: "OK", - onClick: function() { - $('#license-modal-dialog').dialog('close'); - }, - "class": "btn btn-primary", - "id": "license-ok-button" - }]; - } - - height = (IsAdmin()) ? 675 : 350; - - if (scope.removeLicenseReady) { - scope.removeLicenseReady(); - } - scope.removeLicenseReady = scope.$on('LicenseReady', function(e, data) { - - scope.license_json = ""; - scope.eula = data.eula; - if (data.license_info && data.license_info.valid_key !== undefined) { - scope.license_json = JSON.stringify(data.license_info, null, ' '); - } - - CreateDialog({ - scope: scope, - buttons: buttons, - width: 675, - height: height, - minWidth: 400, - title: html.title, - id: 'license-modal-dialog', - clonseOnEscape: false, - onClose: function() { - if (scope.codeMirror) { - scope.codeMirror.destroy(); - } - $('#license-modal-dialog').empty(); - }, - onResizeStop: function() { - if (IsAdmin()) { - TextareaResize({ - scope: scope, - textareaId: 'license_license_json', - modalId: 'license-modal-dialog', - formId: 'license-notification-body', - fld: 'license_json', - parse: true, - onChange: function() { scope.license_json_api_error = ''; } - }); - } - }, - onOpen: function() { - if (IsAdmin()) { - setTimeout(function() { - TextareaResize({ - scope: scope, - textareaId: 'license_license_json', - modalId: 'license-modal-dialog', - formId: 'license-notification-body', - fld: 'license_json', - parse: true, - onChange: function() { scope.license_json_api_error = ''; } - }); - $('#cm-license_json-container .CodeMirror textarea').focus(); - }, 300); - } else { - $('#license-ok-button').focus(); - } - }, - callback: 'LicenseDialogReady' - }); - }); - - self.GetLicense('LicenseReady'); + $location.path('/license'); + // html = this.getHTML(license); + // $('#license-modal-dialog').html(html.body); + // + // scope.flashMessage = null; + // scope.parseType = 'json'; + // + // scope.removeLicenseDialogReady = scope.$on('LicenseDialogReady', function() { + // $('#license_license_json').attr('ng-required' , 'true' ); + // $('#license_eula_agreement_chbox').attr('ng-required' , 'true' ); + // $('#license-submit-button').attr('ng-disabled' , "license_form.$invalid" ); + // var e = angular.element(document.getElementById('license-modal-dialog')); + // $compile(e)(scope); + // e = angular.element(document.getElementById('license-submit-button')); + // $compile(e)(scope); + // $('#license-modal-dialog').dialog('open'); + // }); + // + // scope.submitLicenseKey = function() { + // self.postLicense(scope.license_json); + // }; + // + // if (IsAdmin()) { + // buttons = [{ + // label: "Cancel", + // onClick: function() { + // $('#license-modal-dialog').dialog('close'); + // }, + // "class": "btn btn-default", + // "id": "license-cancel-button" + // }, { + // label: "Submit", + // onClick: function() { + // scope.submitLicenseKey(); + // }, + // "class": "btn btn-primary", + // "id": "license-submit-button" + // }]; + // } else { + // buttons = [{ + // label: "OK", + // onClick: function() { + // $('#license-modal-dialog').dialog('close'); + // }, + // "class": "btn btn-primary", + // "id": "license-ok-button" + // }]; + // } + // + // height = (IsAdmin()) ? 675 : 350; + // + // if (scope.removeLicenseReady) { + // scope.removeLicenseReady(); + // } + // scope.removeLicenseReady = scope.$on('LicenseReady', function(e, data) { + // + // scope.license_json = ""; + // scope.eula = data.eula; + // if (data.license_info && data.license_info.valid_key !== undefined) { + // scope.license_json = JSON.stringify(data.license_info, null, ' '); + // } + // + // CreateDialog({ + // scope: scope, + // buttons: buttons, + // width: 675, + // height: height, + // minWidth: 400, + // title: html.title, + // id: 'license-modal-dialog', + // clonseOnEscape: false, + // onClose: function() { + // if (scope.codeMirror) { + // scope.codeMirror.destroy(); + // } + // $('#license-modal-dialog').empty(); + // }, + // onResizeStop: function() { + // if (IsAdmin()) { + // TextareaResize({ + // scope: scope, + // textareaId: 'license_license_json', + // modalId: 'license-modal-dialog', + // formId: 'license-notification-body', + // fld: 'license_json', + // parse: true, + // onChange: function() { scope.license_json_api_error = ''; } + // }); + // } + // }, + // onOpen: function() { + // if (IsAdmin()) { + // setTimeout(function() { + // TextareaResize({ + // scope: scope, + // textareaId: 'license_license_json', + // modalId: 'license-modal-dialog', + // formId: 'license-notification-body', + // fld: 'license_json', + // parse: true, + // onChange: function() { scope.license_json_api_error = ''; } + // }); + // $('#cm-license_json-container .CodeMirror textarea').focus(); + // }, 300); + // } else { + // $('#license-ok-button').focus(); + // } + // }, + // callback: 'LicenseDialogReady' + // }); + // }); + // + // self.GetLicense('LicenseReady'); }, @@ -341,297 +348,4 @@ export default }); } }; - }]) - - .factory('LicenseViewer', ['$location', '$rootScope', '$compile', '$filter', 'GenerateForm', 'Rest', 'Alert', 'GetBasePath', 'ProcessErrors', 'FormatDate', 'Prompt', 'Empty', 'LicenseForm', 'IsAdmin', 'CreateDialog', 'CheckLicense', 'TextareaResize', - function ($location, $rootScope, $compile, $filter, GenerateForm, Rest, Alert, GetBasePath, ProcessErrors, FormatDate, Prompt, Empty, LicenseForm, IsAdmin, CreateDialog, CheckLicense, TextareaResize) { - return { - - createDialog: function(html) { - var self = this, - scope = this.getScope(), - buttons; - - if (scope.removeLicenseDialogReady) { - scope.removeLicenseDialogReady(); - } - scope.removeLicenseDialogReady = scope.$on('LicenseDialogReady', function() { - var e, h; - - e = angular.element(document.getElementById('license-modal-dialog')); - e.empty().html(html); - - if (scope.license_status === 'Invalid License Key' || scope.license_status === 'Missing License Key') { - $('#license_tabs li:eq(1)').hide(); - } - - scope.parseType = 'json'; - scope.license_json = JSON.stringify(self.license, null, ' '); - scope.eula = self.eula; - scope.eula_agreement = false; - - - h = CheckLicense.getHTML(self.getLicense(),true).body; - $('#license-modal-dialog #license_tabs').append("
  • Update License
  • "); - $('#license-modal-dialog .tab-content').append("
    "); - $('#license-modal-dialog #update_license').html(h); - - setTimeout(function() { - $('#license_license_json').attr('ng-required' , 'true' ); - $('#license_eula_agreement_chbox').attr('ng-required' , 'true' ); - $('#license_form_submit_btn').attr('ng-disabled' , "license_form.$invalid" ); - var e = angular.element(document.getElementById('license-modal-dialog')); - $compile(e)(scope); - $('#license-modal-dialog').dialog('open'); - }, 300); - }); - - scope.submitLicenseKey = function() { - CheckLicense.postLicense(scope.license_json, scope); - }; - - buttons = [{ - label: "OK", - onClick: function() { - $('#license-modal-dialog').dialog('close'); - }, - "class": "btn btn-primary", - "id": "license-ok-button" - }]; - - CreateDialog({ - scope: scope, - buttons: buttons, - width: 675, - height: (IsAdmin()) ? 745 : 600, - minWidth: 400, - title: 'Ansible Tower License', - id: 'license-modal-dialog', - clonseOnEscape: false, - onClose: function() { - if (scope.codeMirror) { - scope.codeMirror.destroy(); - } - $('#license-modal-dialog').empty(); - }, - onResizeStop: function() { - if (IsAdmin()) { - TextareaResize({ - scope: scope, - textareaId: 'license_license_json', - modalId: 'license-modal-dialog', - formId: 'license-notification-body', - fld: 'license_json', - bottom_margin: 90, - parse: true, - onChange: function() { scope.license_json_api_error = ''; } - }); - } - }, - onOpen: function() { - if (IsAdmin()) { - setTimeout(function() { - TextareaResize({ - scope: scope, - textareaId: 'license_license_json', - modalId: 'license-modal-dialog', - formId: 'license-notification-body', - fld: 'license_json', - parse: true, - bottom_margin: 90, - onChange: function() { scope.license_json_api_error = ''; } - }); - }, 300); - } - $('#license-ok-button').focus(); - $('#update_license_link').on('click', function() { - if (IsAdmin()) { - TextareaResize({ - scope: scope, - textareaId: 'license_license_json', - modalId: 'license-modal-dialog', - formId: 'license-notification-body', - fld: 'license_json', - bottom_margin: 90, - parse: true, - onChange: function() { scope.license_json_api_error = ''; } - }); - } - }); - }, - callback: 'LicenseDialogReady' - }); - }, - - getDefaultHTML: function(license_info) { - var fld, html, - self = this, - generator = GenerateForm; - - self.form = angular.copy(LicenseForm); - - for (fld in self.form.fields) { - if (fld !== 'time_remaining' && fld !== 'license_status' && fld !== 'tower_version') { - if (Empty(license_info[fld])) { - delete self.form.fields[fld]; - } - } - } - - if (!IsAdmin()) { - delete self.form.fields.license_key; - } - - if (license_info.is_aws || Empty(license_info.license_date)) { - delete self.form.fields.license_date; - delete self.form.fields.time_remaining; - } - - html = generator.buildHTML(self.form, { mode: 'edit', showButtons: false, breadCrumbs: false }); - return html; - }, - - loadDefaultScope: function(license_info, version) { - var fld, dt, days, license, - self = this, - scope = this.getScope(); - - for (fld in self.form.fields) { - if (!Empty(license_info[fld])) { - scope[fld] = license_info[fld]; - } - } - - scope.tower_version = version; - - if (scope.license_date) { - dt = new Date(parseInt(scope.license_date, 10) * 1000); // expects license_date in seconds - scope.license_date = FormatDate(dt); - scope.time_remaining = parseInt(scope.time_remaining,10) * 1000; - if (scope.time_remaining < 0) { - days = 0; - } else { - days = Math.floor(scope.time_remaining / 86400000); - } - scope.time_remaining = (days!==1) ? $filter('number')(days, 0) + ' days' : $filter('number')(days, 0) + ' day'; // '1 day' and '0 days/2 days' or more - } - - if (parseInt(scope.free_instances) <= 0) { - scope.free_instances_class = 'field-failure'; - } else { - scope.free_instances_class = 'field-success'; - } - - license = license_info; - if (license.valid_key === undefined) { - scope.license_status = 'Missing License Key'; - scope.status_color = 'license-invalid'; - } else if (!license.valid_key) { - scope.license_status = 'Invalid License Key'; - scope.status_color = 'license-invalid'; - } else if (license.date_expired !== undefined && license.date_expired) { - scope.license_status = 'License Expired'; - scope.status_color = 'license-expired'; - } else if (license.date_warning !== undefined && license.date_warning) { - scope.license_status = 'License Expiring Soon'; - scope.status_color = 'license-warning'; - } else if (license.free_instances !== undefined && parseInt(license.free_instances) <= 0) { - scope.license_status = 'No Available Managed Hosts'; - scope.status_color = 'license-invalid'; - } else { - scope.license_status = 'Valid License'; - scope.status_color = 'license-valid'; - } - }, - - getScope: function() { - return this.scope; - }, - - setLicense: function(license_info, version) { - this.license = license_info; - this.version = version; - }, - - getLicense: function() { - return this.license; - }, - - showViewer: function() { - var self = this, - scope = self.scope = $rootScope.$new(); - - if (scope.removeLicenseDataReady) { - scope.removeLicenseDataReady(); - } - scope.removeLicenseDataReady = scope.$on('LicenseDataReady', function(e, data) { - var html, version; - version = data.version.replace(/-.*$/,''); - self.setLicense(data.license_info, version); - html = self.getDefaultHTML(data.license_info); - self.loadDefaultScope(data.license_info, version); - self.eula = (data.eula) ? data.eula : "" ; - self.createDialog(html); - }); - CheckLicense.GetLicense('LicenseDataReady', scope); - } - }; }]); - - /* - .factory('CheckLicense', ['$rootScope', 'Store', 'Alert', '$location', 'Authorization', - function ($rootScope, Store, Alert, $location, Authorization) { - return function () { - // Check license status and alert the user, if needed - var status = 'success', - hdr, msg, - license = Store('license'), - purchase_msg = '

    To purchase a license or extend an existing license ' + - 'visit the Ansible online store, ' + - 'or visit support.ansible.com for assistance.

    '; - if (license && !Authorization.licenseTested()) { - // This is our first time evaluating the license - license.tested = true; - Store('license',license); //update with tested flag - $rootScope.license_tested = true; - $rootScope.version = license.version; - if (license.valid_key !== undefined && license.valid_key === false) { - // The license is invalid. Stop the user from logging in. - status = 'alert-danger'; - hdr = 'License Error'; - msg = '

    There is a problem with the /etc/tower/license file on your Tower server. Check to make sure Tower can access ' + - 'the file.

    ' + purchase_msg; - Alert(hdr, msg, status, null, false, true); - } else if (license.demo !== undefined && license.demo === true) { - // demo - status = 'alert-info'; - hdr = 'Tower Demo'; - msg = '

    Thank you for trying Ansible Tower. You can use this edition to manage up to 10 hosts free.

    ' + - purchase_msg; - Alert(hdr, msg, status); - } - if (license.date_expired !== undefined && license.date_expired === true) { - // expired - status = 'alert-info'; - hdr = 'License Expired'; - msg = '

    Your Ansible Tower License has expired and is no longer compliant. You can continue, but you will be ' + - 'unable to add any additional hosts.

    ' + purchase_msg; - Alert(hdr, msg, status); - } else if (license.date_warning !== undefined && license.date_warning === true) { - status = 'alert-info'; - hdr = 'License Warning'; - msg = '

    Your Ansible Tower license is about to expire!

    ' + purchase_msg; - Alert(hdr, msg, status); - } - if (license.free_instances !== undefined && parseInt(license.free_instances) <= 0) { - status = 'alert-info'; - hdr = 'License Warning'; - msg = '

    Your Ansible Tower license has reached capacity for the number of managed ' + - 'hosts allowed. You will not be able to add any additional hosts.

    ' + purchase_msg; - Alert(hdr, msg, status, null, true); - } - } - }; - } - ]); - */ diff --git a/awx/ui/static/js/shared/features/features.controller.js b/awx/ui/static/js/shared/features/features.controller.js index 78ff9ec270..6f1a62ae54 100644 --- a/awx/ui/static/js/shared/features/features.controller.js +++ b/awx/ui/static/js/shared/features/features.controller.js @@ -1,6 +1,10 @@ export default ['$rootScope', function ($rootScope) { this.isFeatureEnabled = function(feature){ - return $rootScope.features[feature] || false; + if(_.isEmpty($rootScope.features)){ + return false; + } else{ + return $rootScope.features[feature] || false; + } }; }]; diff --git a/awx/ui/static/less/ansible-ui.less b/awx/ui/static/less/ansible-ui.less index fa246348dd..1685a6d3e0 100644 --- a/awx/ui/static/less/ansible-ui.less +++ b/awx/ui/static/less/ansible-ui.less @@ -377,9 +377,9 @@ textarea.allowresize { color: @grey-txt; } -#license_eula{ - white-space: nowrap; -} +// #license_eula{ +// white-space: nowrap; +// } .modal-dialog .ui-accordion .ui-accordion-content { overflow: hidden; diff --git a/awx/ui/static/partials/cowsay-about.html b/awx/ui/static/partials/cowsay-about.html index e4e3fc8a1f..8ec3906381 100644 --- a/awx/ui/static/partials/cowsay-about.html +++ b/awx/ui/static/partials/cowsay-about.html @@ -5,8 +5,8 @@
      ________________
    -/  Tower Version \
    -\/
    +/  Tower  \
    +\   license /
      ----------------
             \   ^__^
              \  (oo)\_______
    @@ -23,4 +23,4 @@
                 

    Visit Ansible.com for more information.

    - \ No newline at end of file + diff --git a/awx/ui/static/partials/license.html b/awx/ui/static/partials/license.html new file mode 100644 index 0000000000..4e616a112a --- /dev/null +++ b/awx/ui/static/partials/license.html @@ -0,0 +1,4 @@ +
    +
    +
    +
    diff --git a/awx/ui/templates/ui/index.html b/awx/ui/templates/ui/index.html index f14fd6b3ab..73659cfc38 100644 --- a/awx/ui/templates/ui/index.html +++ b/awx/ui/templates/ui/index.html @@ -238,7 +238,7 @@ - +