From d23adad7f655f7c5ba9ed634d44c126c829e5498 Mon Sep 17 00:00:00 2001 From: Paul Van Eck Date: Wed, 30 Sep 2015 12:31:32 -0700 Subject: [PATCH] Update eslint and update angular style to match With an updated eslint version and the addition of eslint-config-openstack and eslint-plugin-angular, there are several more stylistic guidelines to follow. However, this is what other OpenStack angular projects follow such as Horizon. Some notable changes are: * Wrapped javascript content in anonymous functions. This is a safeguard to keep the code from conflicting with other variables with the same name in other scripts on the same page. * Explicitly inject dependencies and have controllers, factories, etc as explicitly declared functions. * Use angular "controller as" syntax instead of assigning variables to $scope. * Added eslint rule that requires JSDoc for every function declaration. Note these are mainly stylistic changes and all the functionality of RefStack should remain the same. Change-Id: I044b1f473d589681a2ae9d2704700dd85687cbb6 --- .eslintrc | 17 +- package.json | 10 +- refstack-ui/app/app.js | 154 ++- .../auth-failure/authFailureController.js | 42 +- .../components/capabilities/capabilities.html | 26 +- .../capabilities/capabilitiesController.js | 333 +++--- .../partials/capabilityDetailsV1.2.html | 22 +- .../partials/capabilityDetailsV1.3.html | 22 +- .../components/profile/importPubKeyModal.html | 14 +- .../app/components/profile/profile.html | 14 +- .../components/profile/profileController.js | 318 +++-- .../components/profile/showPubKeyModal.html | 10 +- .../partials/fullTestListModal.html | 6 +- .../partials/reportDetails.html | 42 +- .../results-report/resultsReport.html | 76 +- .../results-report/resultsReportController.js | 1050 +++++++++-------- .../app/components/results/results.html | 50 +- .../components/results/resultsController.js | 231 ++-- refstack-ui/app/shared/alerts/alertModal.html | 8 +- .../app/shared/alerts/alertModalFactory.js | 69 +- refstack-ui/app/shared/filters.js | 74 +- refstack-ui/app/shared/header/header.html | 14 +- .../app/shared/header/headerController.js | 49 +- refstack-ui/tests/unit/ControllerSpec.js | 352 +++--- 24 files changed, 1666 insertions(+), 1337 deletions(-) diff --git a/.eslintrc b/.eslintrc index fea13b0f..6c08851d 100644 --- a/.eslintrc +++ b/.eslintrc @@ -32,6 +32,8 @@ "shelljs": false }, + "extends": "openstack", + "globals": { "require": false, "exports": false, @@ -43,16 +45,25 @@ "browser": false }, + "plugins": [ + "angular" + ], + "rules": { "quotes": [2, "single"], "eol-last": 2, "no-trailing-spaces": 2, "camelcase": 0, "no-extra-boolean-cast": 0, + "operator-linebreak": 0, + "require-jsdoc": 2, // Stylistic - "indent": [2, 4], + "indent": [2, 4, {SwitchCase: 1}], "max-len": [2, 80], - "no-undefined": 2 + "no-undefined": 2, + + // Angular Plugin + "angular/controller-as-vm": [1, "ctrl"] } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 1794822a..d2e9bb28 100644 --- a/package.json +++ b/package.json @@ -2,11 +2,13 @@ "version": "0.0.1", "private": true, "name": "refstack-ui", - "description": "A user interface for Refstack", + "description": "A user interface for RefStack", "license": "Apache2", "devDependencies": { "bower": "1.3.12", - "eslint": "^0.21.2", + "eslint": "1.5.1", + "eslint-config-openstack": "1.2.1", + "eslint-plugin-angular": "0.12.0", "http-server": "^0.6.1", "karma": "^0.12.23", "karma-chrome-launcher": "^0.1.5", @@ -15,9 +17,7 @@ "karma-jasmine": "^0.2.2", "karma-phantomjs-launcher": "0.2.0", "phantomjs": "1.9.17", - "protractor": "~1.0.0", - "shelljs": "^0.2.6", - "tmp": "0.0.23" + "protractor": "~1.0.0" }, "scripts": { "postinstall": "bower install --config.interactive=false", diff --git a/refstack-ui/app/app.js b/refstack-ui/app/app.js index 7824143d..471f4517 100644 --- a/refstack-ui/app/app.js +++ b/refstack-ui/app/app.js @@ -1,16 +1,38 @@ -/** Main app module where application dependencies are listed. */ -var refstackApp = angular.module('refstackApp', [ - 'ui.router', 'ui.bootstrap', 'cgBusy', 'ngResource', 'angular-confirm']); - -/** - * Handle application routing. Specific templates and controllers will be - * used based on the URL route. +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -refstackApp.config([ - '$stateProvider', '$urlRouterProvider', - function ($stateProvider, $urlRouterProvider) { - 'use strict'; +(function () { + 'use strict'; + + /** Main app module where application dependencies are listed. */ + angular + .module('refstackApp', [ + 'ui.router','ui.bootstrap', 'cgBusy', + 'ngResource', 'angular-confirm' + ]); + + angular + .module('refstackApp') + .config(configureRoutes); + + configureRoutes.$inject = ['$stateProvider', '$urlRouterProvider']; + + /** + * Handle application routing. Specific templates and controllers will be + * used based on the URL route. + */ + function configureRoutes($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise('/'); $stateProvider. state('home', { @@ -24,70 +46,80 @@ refstackApp.config([ state('capabilities', { url: '/capabilities', templateUrl: '/components/capabilities/capabilities.html', - controller: 'capabilitiesController' + controller: 'CapabilitiesController as ctrl' }). state('communityResults', { url: '/community_results', templateUrl: '/components/results/results.html', - controller: 'resultsController' + controller: 'ResultsController as ctrl' }). state('userResults', { url: '/user_results', templateUrl: '/components/results/results.html', - controller: 'resultsController' + controller: 'ResultsController as ctrl' }). state('resultsDetail', { url: '/results/:testID', - templateUrl: '/components/results-report/resultsReport.html', - controller: 'resultsReportController' + templateUrl: '/components/results-report' + + '/resultsReport.html', + controller: 'ResultsReportController as ctrl' }). state('profile', { url: '/profile', templateUrl: '/components/profile/profile.html', - controller: 'profileController' + controller: 'ProfileController as ctrl' }). state('authFailure', { url: '/auth_failure/:message', templateUrl: '/components/home/home.html', - controller: 'authFailureController' + controller: 'AuthFailureController as ctrl' }); } -]); -/** - * Injections in $rootscope - */ + angular + .module('refstackApp') + .run(setup); -refstackApp.run(['$http', '$rootScope', '$window', '$state', 'refstackApiUrl', - function($http, $rootScope, $window, $state, refstackApiUrl) { - 'use strict'; + setup.$inject = [ + '$http', '$rootScope', '$window', '$state', 'refstackApiUrl' + ]; + + /** + * Set up the app with injections into $rootscope. This is mainly for auth + * functions. + */ + function setup($http, $rootScope, $window, $state, refstackApiUrl) { /** * This function injects sign in function in all scopes */ $rootScope.auth = {}; + $rootScope.auth.doSignIn = doSignIn; + $rootScope.auth.doSignOut = doSignOut; + $rootScope.auth.doSignCheck = doSignCheck; var sign_in_url = refstackApiUrl + '/auth/signin'; - $rootScope.auth.doSignIn = function () { - $window.location.href = sign_in_url; - }; - - /** - * This function injects sign out function in all scopes - */ var sign_out_url = refstackApiUrl + '/auth/signout'; - $rootScope.auth.doSignOut = function () { + var profile_url = refstackApiUrl + '/profile'; + + /** This function initiates a sign in. */ + function doSignIn() { + $window.location.href = sign_in_url; + } + + /** This function will initate a sign out. */ + function doSignOut() { $rootScope.currentUser = null; $rootScope.isAuthenticated = false; $window.location.href = sign_out_url; - }; + } /** - * This block tries to authenticate user + * This function checks to see if a user is logged in and + * authenticated. */ - var profile_url = refstackApiUrl + '/profile'; - $rootScope.auth.doSignCheck = function () { + function doSignCheck() { return $http.get(profile_url, {withCredentials: true}). success(function (data) { $rootScope.auth.currentUser = data; @@ -97,30 +129,38 @@ refstackApp.run(['$http', '$rootScope', '$window', '$state', 'refstackApiUrl', $rootScope.auth.currentUser = null; $rootScope.auth.isAuthenticated = false; }); - }; + } + $rootScope.auth.doSignCheck(); } -]); -/** - * Load config and start up the angular application. - */ -angular.element(document).ready(function () { - 'use strict'; + angular + .element(document) + .ready(loadConfig); - var $http = angular.injector(['ng']).get('$http'); + /** + * Load config and start up the angular application. + */ + function loadConfig() { - function startApp(config) { - // Add config options as constants. - for (var key in config) { - angular.module('refstackApp').constant(key, config[key]); + var $http = angular.injector(['ng']).get('$http'); + + /** + * Store config variables as constants, and start the app. + */ + function startApp(config) { + // Add config options as constants. + angular.forEach(config, function(value, key) { + angular.module('refstackApp').constant(key, value); + }); + + angular.bootstrap(document, ['refstackApp']); } - angular.bootstrap(document, ['refstackApp']); - } - $http.get('config.json').success(function (data) { - startApp(data); - }).error(function () { - startApp({}); - }); -}); + $http.get('config.json').success(function (data) { + startApp(data); + }).error(function () { + startApp({}); + }); + } +})(); diff --git a/refstack-ui/app/components/auth-failure/authFailureController.js b/refstack-ui/app/components/auth-failure/authFailureController.js index 597f1578..51ea8f29 100644 --- a/refstack-ui/app/components/auth-failure/authFailureController.js +++ b/refstack-ui/app/components/auth-failure/authFailureController.js @@ -1,17 +1,31 @@ -/** - * Refstack Auth Failure Controller - * This controller handles messages from Refstack API if user auth fails. +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -var refstackApp = angular.module('refstackApp'); +(function () { + 'use strict'; -refstackApp.controller('authFailureController', - [ - '$stateParams', '$state', 'raiseAlert', - function($stateParams, $state, raiseAlert) { - 'use strict'; - raiseAlert('danger', 'Authentication Failure:', - $stateParams.message); - $state.go('home'); - } - ]); + angular + .module('refstackApp') + .controller('AuthFailureController', AuthFailureController); + + AuthFailureController.$inject = ['$stateParams', '$state', 'raiseAlert']; + /** + * Refstack Auth Failure Controller + * This controller handles messages from Refstack API if user auth fails. + */ + function AuthFailureController($stateParams, $state, raiseAlert) { + raiseAlert('danger', 'Authentication Failure:', $stateParams.message); + $state.go('home'); + } +})(); diff --git a/refstack-ui/app/components/capabilities/capabilities.html b/refstack-ui/app/components/capabilities/capabilities.html index 26b42d6e..e4cdeb7a 100644 --- a/refstack-ui/app/components/capabilities/capabilities.html +++ b/refstack-ui/app/components/capabilities/capabilities.html @@ -4,15 +4,15 @@
Version: - - +
Target Program: About - @@ -21,10 +21,10 @@

-
+
Corresponding OpenStack Releases:
    -
  • +
  • {{release | capitalize}}
@@ -33,19 +33,19 @@ Capability Status:
@@ -54,14 +54,14 @@

Tests marked with are tests flagged by DefCore.

-
-
+
+
-
+
diff --git a/refstack-ui/app/components/capabilities/capabilitiesController.js b/refstack-ui/app/components/capabilities/capabilitiesController.js index f955ba78..2068b83e 100644 --- a/refstack-ui/app/components/capabilities/capabilitiesController.js +++ b/refstack-ui/app/components/capabilities/capabilitiesController.js @@ -1,172 +1,191 @@ -var refstackApp = angular.module('refstackApp'); - -/** - * Refstack Capabilities Controller - * This controller is for the '/capabilities' page where a user can browse - * through tests belonging to DefCore-defined capabilities. +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -refstackApp.controller('capabilitiesController', - ['$scope', '$http', 'refstackApiUrl', - function ($scope, $http, refstackApiUrl) { - 'use strict'; - /** Whether to hide/collapse the achievements for each capability. */ - $scope.hideAchievements = true; +(function () { + 'use strict'; - /** Whether to hide/collapse the tests for each capability. */ - $scope.hideTests = true; + angular + .module('refstackApp') + .controller('CapabilitiesController', CapabilitiesController); - /** The target OpenStack marketing program to show capabilities for. */ - $scope.target = 'platform'; + CapabilitiesController.$inject = ['$http', 'refstackApiUrl']; - /** The various possible capability statuses. */ - $scope.status = { - required: true, - advisory: false, - deprecated: false, - removed: false - }; + /** + * RefStack Capabilities Controller + * This controller is for the '/capabilities' page where a user can browse + * through tests belonging to DefCore-defined capabilities. + */ + function CapabilitiesController($http, refstackApiUrl) { + var ctrl = this; - /** - * The template to load for displaying capability details. The value - * of this depends on the schema version of the capabilities file. - */ - $scope.detailsTemplate = null; + ctrl.getVersionList = getVersionList; + ctrl.update = update; + ctrl.updateTargetCapabilities = updateTargetCapabilities; + ctrl.filterStatus = filterStatus; + ctrl.getObjectLength = getObjectLength; - /** - * Retrieve an array of available capability files from the Refstack - * API server, sort this array reverse-alphabetically, and store it in - * a scoped variable. The scope's selected version is initialized to - * the latest (i.e. first) version here as well. After a successful API - * call, the function to update the capabilities is called. - * Sample API return array: ["2015.03.json", "2015.04.json"] - */ - $scope.getVersionList = function () { - var content_url = refstackApiUrl + '/capabilities'; - $scope.versionsRequest = - $http.get(content_url).success(function (data) { - $scope.versionList = data.sort().reverse(); - $scope.version = $scope.versionList[0]; - $scope.update(); - }).error(function (error) { - $scope.showError = true; - $scope.error = 'Error retrieving version list: ' + - JSON.stringify(error); - }); - }; + /** The target OpenStack marketing program to show capabilities for. */ + ctrl.target = 'platform'; - /** - * This will contact the Refstack API server to retrieve the JSON - * content of the capability file corresponding to the selected - * version. - */ - $scope.update = function () { - var content_url = refstackApiUrl + '/capabilities/' + - $scope.version; - $scope.capsRequest = - $http.get(content_url).success(function (data) { - $scope.capabilities = data; - $scope.detailsTemplate = 'components/capabilities/' + - 'partials/capabilityDetailsV' + - data.schema + '.html'; - $scope.updateTargetCapabilities(); - }).error(function (error) { - $scope.showError = true; - $scope.capabilities = null; - $scope.error = 'Error retrieving capabilities: ' + - JSON.stringify(error); - }); - }; + /** The various possible capability statuses. */ + ctrl.status = { + required: true, + advisory: false, + deprecated: false, + removed: false + }; - /** - * This will update the scope's 'targetCapabilities' object with - * capabilities belonging to the selected OpenStack marketing program - * (programs typically correspond to 'components' in the DefCore - * schema). Each capability will have its status mapped to it. - */ - $scope.updateTargetCapabilities = function () { - $scope.targetCapabilities = {}; - var components = $scope.capabilities.components; - var targetCaps = $scope.targetCapabilities; + /** + * The template to load for displaying capability details. The value + * of this depends on the schema version of the capabilities file. + */ + ctrl.detailsTemplate = null; - // The 'platform' target is comprised of multiple components, so - // we need to get the capabilities belonging to each of its - // components. - if ($scope.target === 'platform') { - var platform_components = - $scope.capabilities.platform.required; + /** + * Retrieve an array of available capability files from the Refstack + * API server, sort this array reverse-alphabetically, and store it in + * a scoped variable. The scope's selected version is initialized to + * the latest (i.e. first) version here as well. After a successful API + * call, the function to update the capabilities is called. + * Sample API return array: ["2015.03.json", "2015.04.json"] + */ + function getVersionList() { + var content_url = refstackApiUrl + '/capabilities'; + ctrl.versionsRequest = + $http.get(content_url).success(function (data) { + ctrl.versionList = data.sort().reverse(); + ctrl.version = ctrl.versionList[0]; + ctrl.update(); + }).error(function (error) { + ctrl.showError = true; + ctrl.error = 'Error retrieving version list: ' + + angular.toJson(error); + }); + } - // This will contain status priority values, where lower - // values mean higher priorities. - var statusMap = { - required: 1, - advisory: 2, - deprecated: 3, - removed: 4 - }; + /** + * This will contact the Refstack API server to retrieve the JSON + * content of the capability file corresponding to the selected + * version. + */ + function update() { + var content_url = refstackApiUrl + '/capabilities/' + + ctrl.version; + ctrl.capsRequest = + $http.get(content_url).success(function (data) { + ctrl.capabilities = data; + ctrl.detailsTemplate = 'components/capabilities/' + + 'partials/capabilityDetailsV' + + data.schema + '.html'; + ctrl.updateTargetCapabilities(); + }).error(function (error) { + ctrl.showError = true; + ctrl.capabilities = null; + ctrl.error = 'Error retrieving capabilities: ' + + angular.toJson(error); + }); + } - // For each component required for the platform program. - angular.forEach(platform_components, function (component) { - // Get each capability list belonging to each status. - angular.forEach(components[component], - function (caps, status) { - // For each capability. - angular.forEach(caps, function(cap) { - // If the capability has already been added. - if (cap in targetCaps) { - // If the status priority value is less - // than the saved priority value, update - // the value. - if (statusMap[status] < - statusMap[targetCaps[cap]]) { - targetCaps[cap] = status; - } - } - else { - targetCaps[cap] = status; - } - }); - }); - }); - } - else { - angular.forEach(components[$scope.target], - function (caps, status) { - angular.forEach(caps, function(cap) { - targetCaps[cap] = status; - }); - }); - } - }; + /** + * This will update the scope's 'targetCapabilities' object with + * capabilities belonging to the selected OpenStack marketing program + * (programs typically correspond to 'components' in the DefCore + * schema). Each capability will have its status mapped to it. + */ + function updateTargetCapabilities() { + ctrl.targetCapabilities = {}; + var components = ctrl.capabilities.components; + var targetCaps = ctrl.targetCapabilities; - $scope.getVersionList(); + // The 'platform' target is comprised of multiple components, so + // we need to get the capabilities belonging to each of its + // components. + if (ctrl.target === 'platform') { + var platform_components = ctrl.capabilities.platform.required; - /** - * This filter will check if a capability's status corresponds - * to a status that is checked/selected in the UI. This filter - * is meant to be used with the ng-repeat directive. - * @param {Object} capability - * @returns {Boolean} True if capability's status is selected - */ - $scope.filterStatus = function (capability) { - var caps = $scope.targetCapabilities; - return ($scope.status.required && - caps[capability.id] === 'required') || - ($scope.status.advisory && - caps[capability.id] === 'advisory') || - ($scope.status.deprecated && - caps[capability.id] === 'deprecated') || - ($scope.status.removed && - caps[capability.id] === 'removed'); - }; + // This will contain status priority values, where lower + // values mean higher priorities. + var statusMap = { + required: 1, + advisory: 2, + deprecated: 3, + removed: 4 + }; - /** - * This function will get the length of an Object/dict based on - * the number of keys it has. - * @param {Object} object - * @returns {Number} length of object - */ - $scope.getObjectLength = function (object) { - return Object.keys(object).length; - }; - }]); + // For each component required for the platform program. + angular.forEach(platform_components, function (component) { + // Get each capability list belonging to each status. + angular.forEach(components[component], + function (caps, status) { + // For each capability. + angular.forEach(caps, function(cap) { + // If the capability has already been added. + if (cap in targetCaps) { + // If the status priority value is less + // than the saved priority value, update + // the value. + if (statusMap[status] < + statusMap[targetCaps[cap]]) { + targetCaps[cap] = status; + } + } + else { + targetCaps[cap] = status; + } + }); + }); + }); + } + else { + angular.forEach(components[ctrl.target], + function (caps, status) { + angular.forEach(caps, function(cap) { + targetCaps[cap] = status; + }); + }); + } + } + + /** + * This filter will check if a capability's status corresponds + * to a status that is checked/selected in the UI. This filter + * is meant to be used with the ng-repeat directive. + * @param {Object} capability + * @returns {Boolean} True if capability's status is selected + */ + function filterStatus(capability) { + var caps = ctrl.targetCapabilities; + return (ctrl.status.required && + caps[capability.id] === 'required') || + (ctrl.status.advisory && + caps[capability.id] === 'advisory') || + (ctrl.status.deprecated && + caps[capability.id] === 'deprecated') || + (ctrl.status.removed && + caps[capability.id] === 'removed'); + } + + /** + * This function will get the length of an Object/dict based on + * the number of keys it has. + * @param {Object} object + * @returns {Number} length of object + */ + function getObjectLength(object) { + return Object.keys(object).length; + } + + ctrl.getVersionList(); + } +})(); diff --git a/refstack-ui/app/components/capabilities/partials/capabilityDetailsV1.2.html b/refstack-ui/app/components/capabilities/partials/capabilityDetailsV1.2.html index 0e24c804..22f33e41 100644 --- a/refstack-ui/app/components/capabilities/partials/capabilityDetailsV1.2.html +++ b/refstack-ui/app/components/capabilities/partials/capabilityDetailsV1.2.html @@ -4,20 +4,20 @@ This expects the JSON data of the capability file to be stored in scope variable 'capabilities'. --> -
    -
  1. +
      +
    1. {{capability.id}}
      {{capability.description}}
      - Status: {{targetCapabilities[capability.id]}}
      - Achievements ({{capability.achievements.length}})
      -
        + Status: {{ctrl.targetCapabilities[capability.id]}}
        + Achievements ({{capability.achievements.length}})
        +
        1. {{achievement}}
        - Tests ({{capability.tests.length}}) -
      -
      +

      -

      Criteria

      -
      +

      Criteria

      +
        -
      • +
      • {{criterion.name}}
        {{criterion.Description}}
        Weight: {{criterion.weight}} diff --git a/refstack-ui/app/components/capabilities/partials/capabilityDetailsV1.3.html b/refstack-ui/app/components/capabilities/partials/capabilityDetailsV1.3.html index db44813a..cb075632 100644 --- a/refstack-ui/app/components/capabilities/partials/capabilityDetailsV1.3.html +++ b/refstack-ui/app/components/capabilities/partials/capabilityDetailsV1.3.html @@ -4,21 +4,21 @@ This expects the JSON data of the capability file to be stored in scope variable 'capabilities'. --> -
          -
        1. +
            +
          1. {{capability.id}}
            {{capability.description}}
            - Status: {{targetCapabilities[capability.id]}}
            + Status: {{ctrl.targetCapabilities[capability.id]}}
            Project: {{capability.project | capitalize}}
            - Achievements ({{capability.achievements.length}})
            -
              + Achievements ({{capability.achievements.length}})
              +
              1. {{achievement}}
              - Tests ({{getObjectLength(capability.tests)}}) -
            -
            +

            -

            Criteria

            -
            +

            Criteria

            +
              -
            • +
            • {{criterion.name}}
              {{criterion.Description}}
              Weight: {{criterion.weight}} diff --git a/refstack-ui/app/components/profile/importPubKeyModal.html b/refstack-ui/app/components/profile/importPubKeyModal.html index d9b1107a..e86e3a5b 100644 --- a/refstack-ui/app/components/profile/importPubKeyModal.html +++ b/refstack-ui/app/components/profile/importPubKeyModal.html @@ -1,21 +1,21 @@ \ No newline at end of file +
            diff --git a/refstack-ui/app/components/profile/profile.html b/refstack-ui/app/components/profile/profile.html index 3d1e275f..dc97c41e 100644 --- a/refstack-ui/app/components/profile/profile.html +++ b/refstack-ui/app/components/profile/profile.html @@ -1,5 +1,5 @@

            User profile

            -
            +
            @@ -9,15 +9,15 @@
            -
            +
            -

            User public keys

            +

            User Public Keys

            -
            @@ -26,7 +26,7 @@
            - + @@ -34,4 +34,4 @@
            {{pubKey.format}} {{pubKey.shortKey}} {{pubKey.comment}}
            -
            \ No newline at end of file +
            diff --git a/refstack-ui/app/components/profile/profileController.js b/refstack-ui/app/components/profile/profileController.js index 8383e246..2a8bb69d 100644 --- a/refstack-ui/app/components/profile/profileController.js +++ b/refstack-ui/app/components/profile/profileController.js @@ -1,133 +1,217 @@ -/** - * Refstack User Profile Controller - * This controller handles user's profile page, where a user can view - * account-specific information. +/* + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -var refstackApp = angular.module('refstackApp'); +(function () { + 'use strict'; -refstackApp.factory('PubKeys', - ['$resource', 'refstackApiUrl', function($resource, refstackApiUrl) { - 'use strict'; + angular + .module('refstackApp') + .factory('PubKeys', PubKeys); + + PubKeys.$inject = ['$resource', 'refstackApiUrl']; + + /** + * This is a provider for the user's uploaded public keys. + */ + function PubKeys($resource, refstackApiUrl) { return $resource(refstackApiUrl + '/profile/pubkeys/:id', null, null); - }]); + } -refstackApp.controller('profileController', - [ + angular + .module('refstackApp') + .controller('ProfileController', ProfileController); + + ProfileController.$inject = [ '$scope', '$http', 'refstackApiUrl', 'PubKeys', - '$modal', 'raiseAlert', '$state', - function($scope, $http, refstackApiUrl, - PubKeys, $modal, raiseAlert, $state) { - 'use strict'; + '$modal', 'raiseAlert', '$state' + ]; - if (!$scope.auth.isAuthenticated) { - $state.go('home'); - } + /** + * RefStack Profile Controller + * This controller handles user's profile page, where a user can view + * account-specific information. + */ + function ProfileController($scope, $http, refstackApiUrl, + PubKeys, $modal, raiseAlert, $state) { - $scope.updatePubKeys = function (){ - var keys = PubKeys.query(function(){ - $scope.pubkeys = []; - angular.forEach(keys, function (key) { - $scope.pubkeys.push({ - 'resource': key, - 'format': key.format, - 'shortKey': [ - key.pubkey.slice(0, 10), - '.', - key.pubkey.slice(-10, -1) - ].join('.'), - 'pubkey': key.pubkey, - 'comment': key.comment - }); + var ctrl = this; + + ctrl.updatePubKeys = updatePubKeys; + ctrl.openImportPubKeyModal = openImportPubKeyModal; + ctrl.openShowPubKeyModal = openShowPubKeyModal; + + // Must be authenticated to view this page. + if (!$scope.auth.isAuthenticated) { + $state.go('home'); + } + + /** + * This function will fetch all the user's public keys from the + * server and store them in an array. + */ + function updatePubKeys() { + var keys = PubKeys.query(function() { + ctrl.pubkeys = []; + angular.forEach(keys, function (key) { + ctrl.pubkeys.push({ + 'resource': key, + 'format': key.format, + 'shortKey': [ + key.pubkey.slice(0, 10), + '.', + key.pubkey.slice(-10, -1) + ].join('.'), + 'pubkey': key.pubkey, + 'comment': key.comment }); }); - }; - $scope.openImportPubKeyModal = function () { - $modal.open({ - templateUrl: '/components/profile/importPubKeyModal.html', - backdrop: true, - windowClass: 'modal', - controller: 'importPubKeyModalController' - }).result.finally(function() { - $scope.updatePubKeys(); - }); - }; - - $scope.openShowPubKeyModal = function (pubKey) { - $modal.open({ - templateUrl: '/components/profile/showPubKeyModal.html', - backdrop: true, - windowClass: 'modal', - controller: 'showPubKeyModalController', - resolve: { - pubKey: function(){ - return pubKey; - } - } - }).result.finally(function() { - $scope.updatePubKeys(); - }); - }; - $scope.showRes = function(pubKey){ - raiseAlert('success', '', pubKey.pubkey); - }; - $scope.authRequest = $scope.auth.doSignCheck() - .then($scope.updatePubKeys); + }); } - ]); -refstackApp.controller('importPubKeyModalController', - ['$scope', '$modalInstance', 'PubKeys', 'raiseAlert', - function ($scope, $modalInstance, PubKeys, raiseAlert) { - 'use strict'; - $scope.importPubKey = function () { - var newPubKey = new PubKeys( - {raw_key: $scope.raw_key, - self_signature: $scope.self_signature} - ); - newPubKey.$save(function(newPubKey_){ - raiseAlert('success', - '', 'Public key saved successfully'); - $modalInstance.close(newPubKey_); - }, - function(httpResp){ - raiseAlert('danger', - httpResp.statusText, httpResp.data.title); - $scope.cancel(); - } - ); - }; - $scope.cancel = function () { - $modalInstance.dismiss('cancel'); - }; + /** + * This function will open the modal that will give the user a form + * for importing a public key. + */ + function openImportPubKeyModal() { + $modal.open({ + templateUrl: '/components/profile/importPubKeyModal.html', + backdrop: true, + windowClass: 'modal', + controller: 'ImportPubKeyModalController as modal' + }).result.finally(function() { + ctrl.updatePubKeys(); + }); } - ]); -refstackApp.controller('showPubKeyModalController', - ['$scope', '$modalInstance', 'raiseAlert', 'pubKey', - function ($scope, $modalInstance, raiseAlert, pubKey) { - 'use strict'; - $scope.pubKey = pubKey.resource; - $scope.rawKey = [pubKey.format, - pubKey.pubkey, pubKey.comment].join('\n'); - $scope.deletePubKey = function () { - $scope.pubKey.$remove( - {id: $scope.pubKey.id}, - function(){ - raiseAlert('success', - '', 'Public key deleted successfully'); - $modalInstance.close($scope.pubKey.id); - }, - function(httpResp){ - raiseAlert('danger', - httpResp.statusText, httpResp.data.title); - $scope.cancel(); + /** + * This function will open the modal that will give the full + * information regarding a specific public key. + * @param {Object} pubKey resource + */ + function openShowPubKeyModal(pubKey) { + $modal.open({ + templateUrl: '/components/profile/showPubKeyModal.html', + backdrop: true, + windowClass: 'modal', + controller: 'ShowPubKeyModalController as modal', + resolve: { + pubKey: function() { + return pubKey; } - ); - }; - $scope.cancel = function () { - $modalInstance.dismiss('cancel'); - }; + } + }).result.finally(function() { + ctrl.updatePubKeys(); + }); } - ] -); + + ctrl.authRequest = $scope.auth.doSignCheck().then(ctrl.updatePubKeys); + } + + angular + .module('refstackApp') + .controller('ImportPubKeyModalController', ImportPubKeyModalController); + + ImportPubKeyModalController.$inject = [ + '$modalInstance', 'PubKeys', 'raiseAlert' + ]; + + /** + * Import Pub Key Modal Controller + * This controller is for the modal that appears if a user wants to import + * a public key. + */ + function ImportPubKeyModalController($modalInstance, PubKeys, raiseAlert) { + var ctrl = this; + + ctrl.importPubKey = importPubKey; + ctrl.cancel = cancel; + + /** + * This function will save a new public key resource to the API server. + */ + function importPubKey() { + var newPubKey = new PubKeys( + {raw_key: ctrl.raw_key, self_signature: ctrl.self_signature} + ); + newPubKey.$save( + function(newPubKey_) { + raiseAlert('success', '', 'Public key saved successfully'); + $modalInstance.close(newPubKey_); + }, + function(httpResp) { + raiseAlert('danger', + httpResp.statusText, httpResp.data.title); + ctrl.cancel(); + } + ); + } + + /** + * This function will dismiss the modal. + */ + function cancel() { + $modalInstance.dismiss('cancel'); + } + } + + angular + .module('refstackApp') + .controller('ShowPubKeyModalController', ShowPubKeyModalController); + + ShowPubKeyModalController.$inject = [ + '$modalInstance', 'raiseAlert', 'pubKey' + ]; + + /** + * Show Pub Key Modal Controller + * This controller is for the modal that appears if a user wants to see the + * full details of one of their public keys. + */ + function ShowPubKeyModalController($modalInstance, raiseAlert, pubKey) { + var ctrl = this; + + ctrl.deletePubKey = deletePubKey; + ctrl.cancel = cancel; + + ctrl.pubKey = pubKey.resource; + ctrl.rawKey = [pubKey.format, pubKey.pubkey, pubKey.comment].join('\n'); + + /** + * This function will delete a public key resource. + */ + function deletePubKey() { + ctrl.pubKey.$remove( + {id: ctrl.pubKey.id}, + function() { + raiseAlert('success', + '', 'Public key deleted successfully'); + $modalInstance.close(ctrl.pubKey.id); + }, + function(httpResp) { + raiseAlert('danger', + httpResp.statusText, httpResp.data.title); + ctrl.cancel(); + } + ); + } + + /** + * This method will dismiss the modal. + */ + function cancel() { + $modalInstance.dismiss('cancel'); + } + } +})(); diff --git a/refstack-ui/app/components/profile/showPubKeyModal.html b/refstack-ui/app/components/profile/showPubKeyModal.html index d2dbf2f2..5f63a5ef 100644 --- a/refstack-ui/app/components/profile/showPubKeyModal.html +++ b/refstack-ui/app/components/profile/showPubKeyModal.html @@ -1,11 +1,11 @@ \ No newline at end of file +
            diff --git a/refstack-ui/app/components/results-report/partials/fullTestListModal.html b/refstack-ui/app/components/results-report/partials/fullTestListModal.html index 2ac7de77..6db198b0 100644 --- a/refstack-ui/app/components/results-report/partials/fullTestListModal.html +++ b/refstack-ui/app/components/results-report/partials/fullTestListModal.html @@ -1,13 +1,13 @@ diff --git a/refstack-ui/app/components/results-report/partials/reportDetails.html b/refstack-ui/app/components/results-report/partials/reportDetails.html index 3548660e..7f603a1f 100644 --- a/refstack-ui/app/components/results-report/partials/reportDetails.html +++ b/refstack-ui/app/components/results-report/partials/reportDetails.html @@ -3,13 +3,13 @@ HTML for each accordion group that separates the status types on the results report page. --> - + {{status | capitalize}} - (Total: {{caps[status].caps.length}} capabilities, {{caps[status].count}} tests) - - ({{testStatus | capitalize}}: {{getStatusTestCount(status)}} tests) + (Total: {{ctrl.caps[status].caps.length}} capabilities, {{ctrl.caps[status].count}} tests) + + ({{ctrl.testStatus | capitalize}}: {{ctrl.getStatusTestCount(status)}} tests)
              -
            1. +
            2. - + {{capability.id}} - - [{{getCapabilityTestCount(capability)}}] + + [{{ctrl.getCapabilityTestCount(capability)}}] + ng-if="ctrl.testStatus === 'total'"> [{{capability.passedTests.length}}/{{capability.passedTests.length + capability.notPassedTests.length}}] -
                +
                • + ng-if="ctrl.isTestShown(test, capability)"> + ctrl.isTestFlagged(test, ctrl.capabilityData.capabilities[capability.id])}" + title="{{ctrl.getFlaggedReason(test, ctrl.capabilityData.capabilities[capability.id])}}"> {{test}}
                • + ng-if="ctrl.isTestShown(test, capability)"> + ctrl.isTestFlagged(test, ctrl.capabilityData.capabilities[capability.id])}" + title="{{ctrl.getFlaggedReason(test, ctrl.capabilityData.capabilities[capability.id])}}"> {{test}}
                • diff --git a/refstack-ui/app/components/results-report/resultsReport.html b/refstack-ui/app/components/results-report/resultsReport.html index 166c9947..cdd42f6a 100644 --- a/refstack-ui/app/components/results-report/resultsReport.html +++ b/refstack-ui/app/components/results-report/resultsReport.html @@ -1,31 +1,31 @@

                  Test Run Results

                  -
                  +
                  - Test ID: {{testId}}
                  -
                  Cloud ID: {{resultsData.cpid}}
                  - Upload Date: {{resultsData.created_at}} UTC
                  - Duration: {{resultsData.duration_seconds}} seconds
                  + Test ID: {{ctrl.testId}}
                  +
                  Cloud ID: {{ctrl.resultsData.cpid}}
                  + Upload Date: {{ctrl.resultsData.created_at}} UTC
                  + Duration: {{ctrl.resultsData.duration_seconds}} seconds
                  Total Number of Passed Tests: - - {{resultsData.results.length}} + + {{ctrl.resultsData.results.length}}

                  -
                  - - - +
                  + + +
                  -
                  +

                  See how these results stack up against DefCore capabilities and OpenStack target marketing programs.

                  @@ -34,14 +34,14 @@
                  Capabilities Version: - - +
                  Target Program: - @@ -53,28 +53,28 @@
                  Corresponding OpenStack Releases:
                    -
                  • +
                  • {{release | capitalize}}

                  -
                  +
                  Status: -

                  This cloud passes {{requiredPassPercent | number:1}}% - ({{caps.required.passedCount}}/{{caps.required.count}}) - of the tests in the {{version.slice(0, -5)}} required capabilities for the - {{targetMappings[target]}} program.
                  +

                  This cloud passes {{ctrl.requiredPassPercent | number:1}}% + ({{ctrl.caps.required.passedCount}}/{{ctrl.caps.required.count}}) + of the tests in the {{ctrl.version.slice(0, -5)}} required capabilities for the + {{ctrl.targetMappings[target]}} program.
                  Excluding flagged tests, this cloud passes - {{nonFlagRequiredPassPercent | number:1}}% - ({{nonFlagPassCount}}/{{totalNonFlagCount}}) + {{ctrl.nonFlagRequiredPassPercent | number:1}}% + ({{ctrl.nonFlagPassCount}}/{{ctrl.totalNonFlagCount}}) of the required tests.

                  -

                  Compliance with {{version.slice(0, -5)}}: +

                  Compliance with {{ctrl.version.slice(0, -5)}}: - YES - NO + YES + NO

                  @@ -83,20 +83,20 @@ Test Filters:
                  -
                  @@ -105,23 +105,23 @@
                  + src="ctrl.detailsTemplate">
                  + src="ctrl.detailsTemplate">
                  + src="ctrl.detailsTemplate">
                  diff --git a/refstack-ui/app/components/results-report/resultsReportController.js b/refstack-ui/app/components/results-report/resultsReportController.js index 04514e4d..1166c110 100644 --- a/refstack-ui/app/components/results-report/resultsReportController.js +++ b/refstack-ui/app/components/results-report/resultsReportController.js @@ -1,538 +1,598 @@ -var refstackApp = angular.module('refstackApp'); - -/** - * Refstack Results Report Controller - * This controller is for the '/results/' page where a user can - * view details for a specific test run. +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -refstackApp.controller('resultsReportController', - ['$scope', '$http', '$stateParams', - '$window', '$modal', 'refstackApiUrl', 'raiseAlert', - function ($scope, $http, $stateParams, $window, $modal, - refstackApiUrl, raiseAlert) { - 'use strict'; - /** The testID extracted from the URL route. */ - $scope.testId = $stateParams.testID; +(function () { + 'use strict'; - /** Whether to hide tests on start.*/ - $scope.hideTests = true; + angular + .module('refstackApp') + .controller('ResultsReportController', ResultsReportController); - /** The target OpenStack marketing program to compare against. */ - $scope.target = 'platform'; + ResultsReportController.$inject = [ + '$http', '$stateParams', '$window', + '$modal', 'refstackApiUrl', 'raiseAlert' + ]; - /** Mappings of DefCore components to marketing program names. */ - $scope.targetMappings = { - 'platform': 'Openstack Powered Platform', - 'compute': 'OpenStack Powered Compute', - 'object': 'OpenStack Powered Object Storage' - }; + /** + * RefStack Results Report Controller + * This controller is for the '/results/' page where a user can + * view details for a specific test run. + */ + function ResultsReportController($http, $stateParams, $window, + $modal, refstackApiUrl, raiseAlert) { - /** The schema version of the currently selected capabilities data. */ - $scope.schemaVersion = null; + var ctrl = this; - /** The selected test status used for test filtering. */ - $scope.testStatus = 'total'; + ctrl.getVersionList = getVersionList; + ctrl.getResults = getResults; + ctrl.isEditingAllowed = isEditingAllowed; + ctrl.isShared = isShared; + ctrl.shareTestRun = shareTestRun; + ctrl.deleteTestRun = deleteTestRun; + ctrl.updateCapabilities = updateCapabilities; + ctrl.getTargetCapabilities = getTargetCapabilities; + ctrl.buildCapabilityV1_2 = buildCapabilityV1_2; + ctrl.buildCapabilityV1_3 = buildCapabilityV1_3; + ctrl.buildCapabilitiesObject = buildCapabilitiesObject; + ctrl.isTestFlagged = isTestFlagged; + ctrl.getFlaggedReason = getFlaggedReason; + ctrl.isCapabilityShown = isCapabilityShown; + ctrl.isTestShown = isTestShown; + ctrl.getCapabilityTestCount = getCapabilityTestCount; + ctrl.getStatusTestCount = getStatusTestCount; + ctrl.openFullTestListModal = openFullTestListModal; - /** The HTML template that all accordian groups will use. */ - $scope.detailsTemplate = 'components/results-report/partials/' + - 'reportDetails.html'; + /** The testID extracted from the URL route. */ + ctrl.testId = $stateParams.testID; - /** - * Retrieve an array of available capability files from the Refstack - * API server, sort this array reverse-alphabetically, and store it in - * a scoped variable. The scope's selected version is initialized to - * the latest (i.e. first) version here as well. After a successful API - * call, the function to update the capabilities is called. - * Sample API return array: ["2015.03.json", "2015.04.json"] - */ - var getVersionList = function () { - var content_url = refstackApiUrl + '/capabilities'; - $scope.versionsRequest = - $http.get(content_url).success(function (data) { - $scope.versionList = data.sort().reverse(); - $scope.version = $scope.versionList[0]; - $scope.updateCapabilities(); - }).error(function (error) { - $scope.showError = true; - $scope.error = 'Error retrieving version list: ' + - JSON.stringify(error); - }); - }; + /** Whether to hide tests on start.*/ + ctrl.hideTests = true; - /** - * Retrieve results from the Refstack API server based on the test - * run id in the URL. This function is the first function that will - * be called from the controller. Upon successful retrieval of results, - * the function that gets the version list will be called. - */ - var getResults = function () { - var content_url = refstackApiUrl + '/results/' + $scope.testId; - $scope.resultsRequest = - $http.get(content_url).success(function (data) { - $scope.resultsData = data; - getVersionList(); - }).error(function (error) { - $scope.showError = true; - $scope.resultsData = null; - $scope.error = 'Error retrieving results from server: ' + - JSON.stringify(error); + /** The target OpenStack marketing program to compare against. */ + ctrl.target = 'platform'; - }); - }; + /** Mappings of DefCore components to marketing program names. */ + ctrl.targetMappings = { + 'platform': 'Openstack Powered Platform', + 'compute': 'OpenStack Powered Compute', + 'object': 'OpenStack Powered Object Storage' + }; - $scope.isEditingAllowed = function () { - return Boolean($scope.resultsData && - $scope.resultsData.user_role === 'owner'); - }; + /** The schema version of the currently selected capabilities data. */ + ctrl.schemaVersion = null; - $scope.isShared = function () { - return Boolean($scope.resultsData && - 'shared' in $scope.resultsData.meta); - }; + /** The selected test status used for test filtering. */ + ctrl.testStatus = 'total'; - $scope.shareTestRun = function (shareState) { - var content_url = [ - refstackApiUrl, '/results/', $scope.testId, '/meta/shared' - ].join(''); - if (shareState) { - $scope.shareRequest = - $http.post(content_url, 'true').success(function () { - $scope.resultsData.meta.shared = 'true'; - raiseAlert('success', '', 'Test run shared!'); - }).error(function (error) { - raiseAlert('danger', - error.title, error.detail); - }); - } else { - $scope.shareRequest = - $http.delete(content_url).success(function () { - delete $scope.resultsData.meta.shared; - raiseAlert('success', '', 'Test run unshared!'); - }).error(function (error) { - raiseAlert('danger', - error.title, error.detail); - }); - } - }; + /** The HTML template that all accordian groups will use. */ + ctrl.detailsTemplate = 'components/results-report/partials/' + + 'reportDetails.html'; - $scope.deleteTestRun = function () { - var content_url = [ - refstackApiUrl, '/results/', $scope.testId - ].join(''); - $scope.deleteRequest = - $http.delete(content_url).success(function () { - $window.history.back(); - }).error(function (error) { - raiseAlert('danger', - error.title, error.detail); - }); - }; + /** + * Retrieve an array of available capability files from the Refstack + * API server, sort this array reverse-alphabetically, and store it in + * a scoped variable. The scope's selected version is initialized to + * the latest (i.e. first) version here as well. After a successful API + * call, the function to update the capabilities is called. + * Sample API return array: ["2015.03.json", "2015.04.json"] + */ + function getVersionList() { + var content_url = refstackApiUrl + '/capabilities'; + ctrl.versionsRequest = + $http.get(content_url).success(function (data) { + ctrl.versionList = data.sort().reverse(); + ctrl.version = ctrl.versionList[0]; + ctrl.updateCapabilities(); + }).error(function (error) { + ctrl.showError = true; + ctrl.error = 'Error retrieving version list: ' + + angular.toJson(error); + }); + } - /** - * This will contact the Refstack API server to retrieve the JSON - * content of the capability file corresponding to the selected - * version. A function to construct an object from the capability - * date will be called upon successful retrieval. - */ - $scope.updateCapabilities = function () { - $scope.capabilityData = null; - $scope.showError = false; - var content_url = refstackApiUrl + '/capabilities/' + - $scope.version; - $scope.capsRequest = - $http.get(content_url).success(function (data) { - $scope.capabilityData = data; - $scope.schemaVersion = data.schema; - $scope.buildCapabilitiesObject(); - }).error(function (error) { - $scope.showError = true; - $scope.capabilityData = null; - $scope.error = 'Error retrieving capabilities: ' + - JSON.stringify(error); - }); - }; + /** + * Retrieve results from the Refstack API server based on the test + * run id in the URL. This function is the first function that will + * be called from the controller. Upon successful retrieval of results, + * the function that gets the version list will be called. + */ + function getResults() { + var content_url = refstackApiUrl + '/results/' + ctrl.testId; + ctrl.resultsRequest = + $http.get(content_url).success(function (data) { + ctrl.resultsData = data; + getVersionList(); + }).error(function (error) { + ctrl.showError = true; + ctrl.resultsData = null; + ctrl.error = 'Error retrieving results from server: ' + + angular.toJson(error); + }); + } - /** - * This will get all the capabilities relevant to the target and - * their corresponding statuses. - * @returns {Object} Object containing each capability and their status - */ - $scope.getTargetCapabilities = function () { - var components = $scope.capabilityData.components; - var targetCaps = {}; + /** + * This tells you whether the current results can be edited/managed + * based on if the current user is the owner of the results set. + * @returns {Boolean} true if editing is allowed + */ + function isEditingAllowed() { + return Boolean(ctrl.resultsData && + ctrl.resultsData.user_role === 'owner'); + } + /** + * This tells you whether the current results are shared with the + * community or not. + * @returns {Boolean} true if the results are shared + */ + function isShared() { + return Boolean(ctrl.resultsData && + 'shared' in ctrl.resultsData.meta); + } - // The 'platform' target is comprised of multiple components, so - // we need to get the capabilities belonging to each of its - // components. - if ($scope.target === 'platform') { - var platform_components = - $scope.capabilityData.platform.required; + /** + * This will send an API request in order to share or unshare the + * current results based on the passed in shareState. + * @param {Boolean} shareState - Whether to share or unshare results. + */ + function shareTestRun(shareState) { + var content_url = [ + refstackApiUrl, '/results/', ctrl.testId, '/meta/shared' + ].join(''); + if (shareState) { + ctrl.shareRequest = + $http.post(content_url, 'true').success(function () { + ctrl.resultsData.meta.shared = 'true'; + raiseAlert('success', '', 'Test run shared!'); + }).error(function (error) { + raiseAlert('danger', error.title, error.detail); + }); + } else { + ctrl.shareRequest = + $http.delete(content_url).success(function () { + delete ctrl.resultsData.meta.shared; + raiseAlert('success', '', 'Test run unshared!'); + }).error(function (error) { + raiseAlert('danger', error.title, error.detail); + }); + } + } - // This will contain status priority values, where lower - // values mean higher priorities. - var statusMap = { - required: 1, - advisory: 2, - deprecated: 3, - removed: 4 - }; + /** + * This will send a request to the API to delete the current + * test results set. + */ + function deleteTestRun() { + var content_url = [ + refstackApiUrl, '/results/', ctrl.testId + ].join(''); + ctrl.deleteRequest = + $http.delete(content_url).success(function () { + $window.history.back(); + }).error(function (error) { + raiseAlert('danger', error.title, error.detail); + }); + } - // For each component required for the platform program. - angular.forEach(platform_components, function (component) { - // Get each capability list belonging to each status. - angular.forEach(components[component], - function (caps, status) { - // For each capability. - angular.forEach(caps, function(cap) { - // If the capability has already been added. - if (cap in targetCaps) { - // If the status priority value is less - // than the saved priority value, update - // the value. - if (statusMap[status] < - statusMap[targetCaps[cap]]) { - targetCaps[cap] = status; - } - } - else { - targetCaps[cap] = status; - } - }); - }); - }); - } - else { - angular.forEach(components[$scope.target], - function (caps, status) { - angular.forEach(caps, function(cap) { - targetCaps[cap] = status; - }); - }); - } - return targetCaps; - }; + /** + * This will contact the Refstack API server to retrieve the JSON + * content of the capability file corresponding to the selected + * version. A function to construct an object from the capability + * date will be called upon successful retrieval. + */ + function updateCapabilities() { + ctrl.capabilityData = null; + ctrl.showError = false; + var content_url = refstackApiUrl + '/capabilities/' + + ctrl.version; + ctrl.capsRequest = + $http.get(content_url).success(function (data) { + ctrl.capabilityData = data; + ctrl.schemaVersion = data.schema; + ctrl.buildCapabilitiesObject(); + }).error(function (error) { + ctrl.showError = true; + ctrl.capabilityData = null; + ctrl.error = 'Error retrieving capabilities: ' + + angular.toJson(error); + }); + } - /** - * This will build the a capability object for schema version 1.2. - * This object will contain the information needed to form a report in - * the HTML template. - * @param {String} capId capability ID - */ - $scope.buildCapabilityV1_2 = function (capId) { - var cap = { - 'id': capId, - 'passedTests': [], - 'notPassedTests': [], - 'passedFlagged': [], - 'notPassedFlagged': [] - }; - var capDetails = $scope.capabilityData.capabilities[capId]; - // Loop through each test belonging to the capability. - angular.forEach(capDetails.tests, - function (testId) { - // If the test ID is in the results' test list, add - // it to the passedTests array. - if ($scope.resultsData.results.indexOf(testId) > -1) { - cap.passedTests.push(testId); - if (capDetails.flagged.indexOf(testId) > -1) { - cap.passedFlagged.push(testId); - } - } - else { - cap.notPassedTests.push(testId); - if (capDetails.flagged.indexOf(testId) > -1) { - cap.notPassedFlagged.push(testId); - } - } - }); - return cap; - }; + /** + * This will get all the capabilities relevant to the target and + * their corresponding statuses. + * @returns {Object} Object containing each capability and their status + */ + function getTargetCapabilities() { + var components = ctrl.capabilityData.components; + var targetCaps = {}; - /** - * This will build the a capability object for schema version 1.3. - * This object will contain the information needed to form a report in - * the HTML template. - * @param {String} capId capability ID - */ - $scope.buildCapabilityV1_3 = function (capId) { - var cap = { - 'id': capId, - 'passedTests': [], - 'notPassedTests': [], - 'passedFlagged': [], - 'notPassedFlagged': [] - }; - // Loop through each test belonging to the capability. - angular.forEach($scope.capabilityData.capabilities[capId].tests, - function (details, testId) { - // If the test ID is in the results' test list, add - // it to the passedTests array. - if ($scope.resultsData.results.indexOf(testId) > -1) { - cap.passedTests.push(testId); - if ('flagged' in details) { - cap.passedFlagged.push(testId); - } - } - else { - cap.notPassedTests.push(testId); - if ('flagged' in details) { - cap.notPassedFlagged.push(testId); - } - } - }); - return cap; - }; + // The 'platform' target is comprised of multiple components, so + // we need to get the capabilities belonging to each of its + // components. + if (ctrl.target === 'platform') { + var platform_components = + ctrl.capabilityData.platform.required; - /** - * This will check the schema version of the current capabilities file, - * and will call the correct method to build an object based on the - * capability data retrieved from the Refstack API server. - */ - $scope.buildCapabilitiesObject = function () { - // This is the object template where 'count' is the number of - // total tests that fall under the given status, and 'passedCount' - // is the number of tests passed. The 'caps' array will contain - // objects with details regarding each capability. - $scope.caps = { - 'required': {'caps': [], 'count': 0, 'passedCount': 0, - 'flagFailCount': 0, 'flagPassCount': 0}, - 'advisory': {'caps': [], 'count': 0, 'passedCount': 0, - 'flagFailCount': 0, 'flagPassCount': 0}, - 'deprecated': {'caps': [], 'count': 0, 'passedCount': 0, - 'flagFailCount': 0, 'flagPassCount': 0}, - 'removed': {'caps': [], 'count': 0, 'passedCount': 0, - 'flagFailCount': 0, 'flagPassCount': 0} - }; + // This will contain status priority values, where lower + // values mean higher priorities. + var statusMap = { + required: 1, + advisory: 2, + deprecated: 3, + removed: 4 + }; - switch ($scope.schemaVersion) { - case '1.2': - var capMethod = 'buildCapabilityV1_2'; - break; - case '1.3': - capMethod = 'buildCapabilityV1_3'; - break; - default: - $scope.showError = true; - $scope.capabilityData = null; - $scope.error = 'The schema version for the capabilities ' + - 'file selected (' + $scope.schemaVersion + - ') is currently not supported.'; - return; - } + // For each component required for the platform program. + angular.forEach(platform_components, function (component) { + // Get each capability list belonging to each status. + angular.forEach(components[component], + function (caps, status) { + // For each capability. + angular.forEach(caps, function(cap) { + // If the capability has already been added. + if (cap in targetCaps) { + // If the status priority value is less + // than the saved priority value, update + // the value. + if (statusMap[status] < + statusMap[targetCaps[cap]]) { + targetCaps[cap] = status; + } + } + else { + targetCaps[cap] = status; + } + }); + }); + }); + } + else { + angular.forEach(components[ctrl.target], + function (caps, status) { + angular.forEach(caps, function(cap) { + targetCaps[cap] = status; + }); + }); + } + return targetCaps; + } - // Get test details for each relevant capability and store - // them in the scope's 'caps' object. - var targetCaps = $scope.getTargetCapabilities(); - angular.forEach(targetCaps, function(status, capId) { - var cap = $scope[capMethod](capId); - $scope.caps[status].count += - cap.passedTests.length + cap.notPassedTests.length; - $scope.caps[status].passedCount += cap.passedTests.length; - $scope.caps[status].flagPassCount += cap.passedFlagged.length; - $scope.caps[status].flagFailCount += - cap.notPassedFlagged.length; - $scope.caps[status].caps.push(cap); - }); + /** + * This will build the a capability object for schema version 1.2. + * This object will contain the information needed to form a report in + * the HTML template. + * @param {String} capId capability ID + */ + function buildCapabilityV1_2(capId) { + var cap = { + 'id': capId, + 'passedTests': [], + 'notPassedTests': [], + 'passedFlagged': [], + 'notPassedFlagged': [] + }; + var capDetails = ctrl.capabilityData.capabilities[capId]; + // Loop through each test belonging to the capability. + angular.forEach(capDetails.tests, + function (testId) { + // If the test ID is in the results' test list, add + // it to the passedTests array. + if (ctrl.resultsData.results.indexOf(testId) > -1) { + cap.passedTests.push(testId); + if (capDetails.flagged.indexOf(testId) > -1) { + cap.passedFlagged.push(testId); + } + } + else { + cap.notPassedTests.push(testId); + if (capDetails.flagged.indexOf(testId) > -1) { + cap.notPassedFlagged.push(testId); + } + } + }); + return cap; + } - $scope.requiredPassPercent = ($scope.caps.required.passedCount * - 100 / $scope.caps.required.count); + /** + * This will build the a capability object for schema version 1.3. + * This object will contain the information needed to form a report in + * the HTML template. + * @param {String} capId capability ID + */ + function buildCapabilityV1_3(capId) { + var cap = { + 'id': capId, + 'passedTests': [], + 'notPassedTests': [], + 'passedFlagged': [], + 'notPassedFlagged': [] + }; + // Loop through each test belonging to the capability. + angular.forEach(ctrl.capabilityData.capabilities[capId].tests, + function (details, testId) { + // If the test ID is in the results' test list, add + // it to the passedTests array. + if (ctrl.resultsData.results.indexOf(testId) > -1) { + cap.passedTests.push(testId); + if ('flagged' in details) { + cap.passedFlagged.push(testId); + } + } + else { + cap.notPassedTests.push(testId); + if ('flagged' in details) { + cap.notPassedFlagged.push(testId); + } + } + }); + return cap; + } - $scope.totalRequiredFailCount = $scope.caps.required.count - - $scope.caps.required.passedCount; - $scope.totalRequiredFlagCount = - $scope.caps.required.flagFailCount + - $scope.caps.required.flagPassCount; - $scope.totalNonFlagCount = $scope.caps.required.count - - $scope.totalRequiredFlagCount; - $scope.nonFlagPassCount = $scope.totalNonFlagCount - - ($scope.totalRequiredFailCount - - $scope.caps.required.flagFailCount); + /** + * This will check the schema version of the current capabilities file, + * and will call the correct method to build an object based on the + * capability data retrieved from the Refstack API server. + */ + function buildCapabilitiesObject() { + // This is the object template where 'count' is the number of + // total tests that fall under the given status, and 'passedCount' + // is the number of tests passed. The 'caps' array will contain + // objects with details regarding each capability. + ctrl.caps = { + 'required': {'caps': [], 'count': 0, 'passedCount': 0, + 'flagFailCount': 0, 'flagPassCount': 0}, + 'advisory': {'caps': [], 'count': 0, 'passedCount': 0, + 'flagFailCount': 0, 'flagPassCount': 0}, + 'deprecated': {'caps': [], 'count': 0, 'passedCount': 0, + 'flagFailCount': 0, 'flagPassCount': 0}, + 'removed': {'caps': [], 'count': 0, 'passedCount': 0, + 'flagFailCount': 0, 'flagPassCount': 0} + }; - $scope.nonFlagRequiredPassPercent = ($scope.nonFlagPassCount * - 100 / $scope.totalNonFlagCount); - }; + switch (ctrl.schemaVersion) { + case '1.2': + var capMethod = 'buildCapabilityV1_2'; + break; + case '1.3': + capMethod = 'buildCapabilityV1_3'; + break; + default: + ctrl.showError = true; + ctrl.capabilityData = null; + ctrl.error = 'The schema version for the capabilities ' + + 'file selected (' + ctrl.schemaVersion + + ') is currently not supported.'; + return; + } - /** - * This will check if a given test is flagged. - * @param {String} test ID of the test to check - * @param {Object} capObj capability that test is under - * @returns {Boolean} truthy value if test is flagged - */ - $scope.isTestFlagged = function (test, capObj) { - if (!capObj) { - return false; - } - return ((($scope.schemaVersion === '1.2') && - (capObj.flagged.indexOf(test) > -1)) || - (($scope.schemaVersion === '1.3') && - (capObj.tests[test].flagged))); - }; + // Get test details for each relevant capability and store + // them in the scope's 'caps' object. + var targetCaps = ctrl.getTargetCapabilities(); + angular.forEach(targetCaps, function(status, capId) { + var cap = ctrl[capMethod](capId); + ctrl.caps[status].count += + cap.passedTests.length + cap.notPassedTests.length; + ctrl.caps[status].passedCount += cap.passedTests.length; + ctrl.caps[status].flagPassCount += cap.passedFlagged.length; + ctrl.caps[status].flagFailCount += + cap.notPassedFlagged.length; + ctrl.caps[status].caps.push(cap); + }); - /** - * This will return the reason a test is flagged. An empty string - * will be returned if the passed in test is not flagged. - * @param {String} test ID of the test to check - * @param {String} capObj capability that test is under - * @returns {String} reason - */ - $scope.getFlaggedReason = function (test, capObj) { - if (($scope.schemaVersion === '1.2') && - ($scope.isTestFlagged(test, capObj))){ + ctrl.requiredPassPercent = (ctrl.caps.required.passedCount * + 100 / ctrl.caps.required.count); - // Return a generic message since schema 1.2 does not - // provide flag reasons. - return 'DefCore has flagged this test.'; - } - else if (($scope.schemaVersion === '1.3') && - ($scope.isTestFlagged(test, capObj))){ + ctrl.totalRequiredFailCount = ctrl.caps.required.count - + ctrl.caps.required.passedCount; + ctrl.totalRequiredFlagCount = + ctrl.caps.required.flagFailCount + + ctrl.caps.required.flagPassCount; + ctrl.totalNonFlagCount = ctrl.caps.required.count - + ctrl.totalRequiredFlagCount; + ctrl.nonFlagPassCount = ctrl.totalNonFlagCount - + (ctrl.totalRequiredFailCount - + ctrl.caps.required.flagFailCount); - return capObj.tests[test].flagged.reason; - } - else { - return ''; - } - }; + ctrl.nonFlagRequiredPassPercent = (ctrl.nonFlagPassCount * + 100 / ctrl.totalNonFlagCount); + } - /** - * This will check the if a capability should be shown based on the - * test filter selected. If a capability does not have any tests - * belonging under the given filter, it should not be shown. - * @param {Object} capability Built object for capability - * @returns {Boolean} true if capability should be shown - */ - $scope.isCapabilityShown = function (capability) { - return (($scope.testStatus === 'total') || - ($scope.testStatus === 'passed' && - capability.passedTests.length > 0) || - ($scope.testStatus === 'not passed' && - capability.notPassedTests.length > 0) || - ($scope.testStatus === 'flagged' && - (capability.passedFlagged.length + - capability.notPassedFlagged.length > 0))); - }; + /** + * This will check if a given test is flagged. + * @param {String} test ID of the test to check + * @param {Object} capObj capability that test is under + * @returns {Boolean} truthy value if test is flagged + */ + function isTestFlagged(test, capObj) { + if (!capObj) { + return false; + } + return (((ctrl.schemaVersion === '1.2') && + (capObj.flagged.indexOf(test) > -1)) || + ((ctrl.schemaVersion === '1.3') && + (capObj.tests[test].flagged))); + } - /** - * This will check the if a test should be shown based on the test - * filter selected. - * @param {String} test ID of the test - * @param {Object} capability Built object for capability - * @return {Boolean} true if test should be shown - */ - $scope.isTestShown = function (test, capability) { - return (($scope.testStatus === 'total') || - ($scope.testStatus === 'passed' && - capability.passedTests.indexOf(test) > -1) || - ($scope.testStatus === 'not passed' && - capability.notPassedTests.indexOf(test) > -1) || - ($scope.testStatus === 'flagged' && - (capability.passedFlagged.indexOf(test) > -1 || - capability.notPassedFlagged.indexOf(test) > -1))); - }; + /** + * This will return the reason a test is flagged. An empty string + * will be returned if the passed in test is not flagged. + * @param {String} test ID of the test to check + * @param {String} capObj capability that test is under + * @returns {String} reason + */ + function getFlaggedReason(test, capObj) { + if ((ctrl.schemaVersion === '1.2') && + (ctrl.isTestFlagged(test, capObj))) { - /** - * This will give the number of tests belonging under the selected - * test filter for a given capability. - * @param {Object} capability Built object for capability - * @returns {Number} number of tests under filter - */ - $scope.getCapabilityTestCount = function (capability) { - if ($scope.testStatus === 'total') { - return capability.passedTests.length + - capability.notPassedTests.length; - } - else if ($scope.testStatus === 'passed') { - return capability.passedTests.length; - } - else if ($scope.testStatus === 'not passed') { - return capability.notPassedTests.length; - } - else if ($scope.testStatus === 'flagged') { - return capability.passedFlagged.length + - capability.notPassedFlagged.length; - } - else { - return 0; - } - }; + // Return a generic message since schema 1.2 does not + // provide flag reasons. + return 'DefCore has flagged this test.'; + } + else if ((ctrl.schemaVersion === '1.3') && + (ctrl.isTestFlagged(test, capObj))) { - /** - * This will give the number of tests belonging under the selected - * test filter for a given status. - * @param {String} capability status - * @returns {Number} number of tests for status under filter - */ - $scope.getStatusTestCount = function (status) { - if (!$scope.caps) { - return -1; - } - else if ($scope.testStatus === 'total') { - return $scope.caps[status].count; - } - else if ($scope.testStatus === 'passed') { - return $scope.caps[status].passedCount; - } - else if ($scope.testStatus === 'not passed') { - return $scope.caps[status].count - - $scope.caps[status].passedCount; - } - else if ($scope.testStatus === 'flagged') { - return $scope.caps[status].flagFailCount + - $scope.caps[status].flagPassCount; - } - else { - return -1; - } - }; + return capObj.tests[test].flagged.reason; + } + else { + return ''; + } + } - $scope.openFullTestListModal = function () { - $modal.open({ - templateUrl: '/components/results-report/partials' + - '/fullTestListModal.html', - backdrop: true, - windowClass: 'modal', - animation: true, - controller: 'fullTestListModalController', - size: 'lg', - resolve: { - tests: function () { - return $scope.resultsData.results; - } - } - }); - }; + /** + * This will check the if a capability should be shown based on the + * test filter selected. If a capability does not have any tests + * belonging under the given filter, it should not be shown. + * @param {Object} capability Built object for capability + * @returns {Boolean} true if capability should be shown + */ + function isCapabilityShown(capability) { + return ((ctrl.testStatus === 'total') || + (ctrl.testStatus === 'passed' && + capability.passedTests.length > 0) || + (ctrl.testStatus === 'not passed' && + capability.notPassedTests.length > 0) || + (ctrl.testStatus === 'flagged' && + (capability.passedFlagged.length + + capability.notPassedFlagged.length > 0))); + } - getResults(); - } - ] -); + /** + * This will check the if a test should be shown based on the test + * filter selected. + * @param {String} test ID of the test + * @param {Object} capability Built object for capability + * @return {Boolean} true if test should be shown + */ + function isTestShown(test, capability) { + return ((ctrl.testStatus === 'total') || + (ctrl.testStatus === 'passed' && + capability.passedTests.indexOf(test) > -1) || + (ctrl.testStatus === 'not passed' && + capability.notPassedTests.indexOf(test) > -1) || + (ctrl.testStatus === 'flagged' && + (capability.passedFlagged.indexOf(test) > -1 || + capability.notPassedFlagged.indexOf(test) > -1))); + } + /** + * This will give the number of tests belonging under the selected + * test filter for a given capability. + * @param {Object} capability Built object for capability + * @returns {Number} number of tests under filter + */ + function getCapabilityTestCount(capability) { + if (ctrl.testStatus === 'total') { + return capability.passedTests.length + + capability.notPassedTests.length; + } + else if (ctrl.testStatus === 'passed') { + return capability.passedTests.length; + } + else if (ctrl.testStatus === 'not passed') { + return capability.notPassedTests.length; + } + else if (ctrl.testStatus === 'flagged') { + return capability.passedFlagged.length + + capability.notPassedFlagged.length; + } + else { + return 0; + } + } -/** - * Full Test List Modal Controller - * This controller is for the modal that appears if a user wants to see the - * full list of passed tests on a report page. - */ -refstackApp.controller('fullTestListModalController', - ['$scope', '$modalInstance', 'tests', - function ($scope, $modalInstance, tests) { - 'use strict'; + /** + * This will give the number of tests belonging under the selected + * test filter for a given status. + * @param {String} capability status + * @returns {Number} number of tests for status under filter + */ + function getStatusTestCount(status) { + if (!ctrl.caps) { + return -1; + } + else if (ctrl.testStatus === 'total') { + return ctrl.caps[status].count; + } + else if (ctrl.testStatus === 'passed') { + return ctrl.caps[status].passedCount; + } + else if (ctrl.testStatus === 'not passed') { + return ctrl.caps[status].count - + ctrl.caps[status].passedCount; + } + else if (ctrl.testStatus === 'flagged') { + return ctrl.caps[status].flagFailCount + + ctrl.caps[status].flagPassCount; + } + else { + return -1; + } + } - $scope.tests = tests; + /** + * This will open the modal that will show the full list of passed + * tests for the current results. + */ + function openFullTestListModal() { + $modal.open({ + templateUrl: '/components/results-report/partials' + + '/fullTestListModal.html', + backdrop: true, + windowClass: 'modal', + animation: true, + controller: 'FullTestListModalController as modal', + size: 'lg', + resolve: { + tests: function () { + return ctrl.resultsData.results; + } + } + }); + } - /** - * This function will close/dismiss the modal. - */ - $scope.close = function () { - $modalInstance.dismiss('exit'); - }; + getResults(); + } - /** - * This function will return a string representing the sorted - * tests list separated by newlines. - */ - $scope.getTestListString = function () { - return $scope.tests.sort().join('\n'); - }; - }] -); + angular + .module('refstackApp') + .controller('FullTestListModalController', FullTestListModalController); + + FullTestListModalController.$inject = ['$modalInstance', 'tests']; + + /** + * Full Test List Modal Controller + * This controller is for the modal that appears if a user wants to see the + * full list of passed tests on a report page. + */ + function FullTestListModalController($modalInstance, tests) { + var ctrl = this; + + ctrl.tests = tests; + + /** + * This function will close/dismiss the modal. + */ + ctrl.close = function () { + $modalInstance.dismiss('exit'); + }; + + /** + * This function will return a string representing the sorted + * tests list separated by newlines. + */ + ctrl.getTestListString = function () { + return ctrl.tests.sort().join('\n'); + }; + } +})(); diff --git a/refstack-ui/app/components/results/results.html b/refstack-ui/app/components/results/results.html index c4b98bd8..e04e13f2 100644 --- a/refstack-ui/app/components/results/results.html +++ b/refstack-ui/app/components/results/results.html @@ -1,4 +1,4 @@ -

                  {{pageHeader}}

                  +

                  {{ctrl.pageHeader}}

                  The most recently uploaded community test results are listed here.

                  @@ -8,12 +8,11 @@

                  - @@ -23,62 +22,61 @@

                  -

                  - - + +
                  -
                  -
                  -
                  - +
                  +
                  +
                  +
                  - + - + - +
                  Upload Date Test Run IDSharedShared
                  {{result.created_at}} {{result.id}}
                  + num-pages="ctrl.numPages" + ng-change="ctrl.update()">
                  - diff --git a/refstack-ui/app/shared/alerts/alertModalFactory.js b/refstack-ui/app/shared/alerts/alertModalFactory.js index abeff4ae..f2a6a6b1 100644 --- a/refstack-ui/app/shared/alerts/alertModalFactory.js +++ b/refstack-ui/app/shared/alerts/alertModalFactory.js @@ -1,12 +1,35 @@ -var refstackApp = angular.module('refstackApp'); +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ -refstackApp.factory('raiseAlert', - ['$modal', function($modal) { - 'use strict'; +(function () { + 'use strict'; + + angular + .module('refstackApp') + .factory('raiseAlert', raiseAlert); + + raiseAlert.$inject = ['$modal']; + + /** + * This allows alert pop-ups to be raised. Just inject it as a dependency + * in the calling controller. + */ + function raiseAlert($modal) { return function(mode, title, text) { $modal.open({ templateUrl: '/shared/alerts/alertModal.html', - controller: 'raiseAlertModalController', + controller: 'RaiseAlertModalController as alert', backdrop: true, keyboard: true, backdropClick: true, @@ -22,20 +45,30 @@ refstackApp.factory('raiseAlert', } }); }; - }] -); + } + angular + .module('refstackApp') + .controller('RaiseAlertModalController', RaiseAlertModalController); -refstackApp.controller('raiseAlertModalController', - ['$scope', '$modalInstance', 'data', - function ($scope, $modalInstance, data) { - 'use strict'; - $scope.data = data; + RaiseAlertModalController.$inject = ['$modalInstance', 'data']; - //wait for users click to close the pop up window. - $scope.close = function() { - $modalInstance.close(); - }; + /** + * This is the controller for the alert pop-up. + */ + function RaiseAlertModalController($modalInstance, data) { + var ctrl = this; + + ctrl.close = close; + ctrl.data = data; + + /** + * This method will close the alert modal. The modal will close + * when the user clicks the close button or clicks outside of the + * modal. + */ + function close() { + $modalInstance.close(); } - ] -); + } +})(); diff --git a/refstack-ui/app/shared/filters.js b/refstack-ui/app/shared/filters.js index 6b3cb9a5..84b171b6 100644 --- a/refstack-ui/app/shared/filters.js +++ b/refstack-ui/app/shared/filters.js @@ -1,31 +1,53 @@ -var refstackApp = angular.module('refstackApp'); - -/** Refstack AngularJS Filters */ - -/** - * Convert an object of objects to an array of objects to use with ng-repeat - * filters. +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ -refstackApp.filter('arrayConverter', function () { + +(function () { 'use strict'; - return function (objects) { - var array = []; - angular.forEach(objects, function (object, key) { - object.id = key; - array.push(object); - }); - return array; - }; -}); + /** + * Convert an object of objects to an array of objects to use with ng-repeat + * filters. + */ + angular + .module('refstackApp') + .filter('arrayConverter', arrayConverter); -/** - * Angular filter that will capitalize the first letter of a string. - */ -refstackApp.filter('capitalize', function() { - 'use strict'; + /** + * Convert an object of objects to an array of objects to use with ng-repeat + * filters. + */ + function arrayConverter() { + return function (objects) { + var array = []; + angular.forEach(objects, function (object, key) { + object.id = key; + array.push(object); + }); + return array; + }; + } - return function (string) { - return string.substring(0, 1).toUpperCase() + string.substring(1); - }; -}); + angular + .module('refstackApp') + .filter('capitalize', capitalize); + + /** + * Angular filter that will capitalize the first letter of a string. + */ + function capitalize() { + return function (string) { + return string.substring(0, 1).toUpperCase() + string.substring(1); + }; + } +})(); diff --git a/refstack-ui/app/shared/header/header.html b/refstack-ui/app/shared/header/header.html index 2809563c..16f67d99 100644 --- a/refstack-ui/app/shared/header/header.html +++ b/refstack-ui/app/shared/header/header.html @@ -1,11 +1,11 @@
                  RefStack RefStack
                  -