2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
6 * http://www.apache.org/licenses/LICENSE-2.0
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
18 /** Main app module where application dependencies are listed. */
20 .module('testapiApp', [
21 'ui.router','ui.bootstrap', 'cgBusy',
22 'ngResource', 'angular-confirm'
27 .config(configureRoutes);
29 configureRoutes.$inject = ['$stateProvider', '$urlRouterProvider'];
32 * Handle application routing. Specific templates and controllers will be
33 * used based on the URL route.
35 function configureRoutes($stateProvider, $urlRouterProvider) {
36 $urlRouterProvider.otherwise('/');
40 templateUrl: 'testapi-ui/components/home/home.html'
44 templateUrl: 'testapi-ui/components/about/about.html'
48 templateUrl: 'testapi-ui/components/guidelines/guidelines.html',
49 controller: 'GuidelinesController as ctrl'
51 state('communityResults', {
52 url: '/community_results',
53 templateUrl: 'testapi-ui/components/results/results.html',
54 controller: 'ResultsController as ctrl'
56 state('userResults', {
58 templateUrl: 'testapi-ui/components/results/results.html',
59 controller: 'ResultsController as ctrl'
61 state('resultsDetail', {
62 url: '/results/:testID',
63 templateUrl: 'testapi-ui/components/results-report' +
64 '/resultsReport.html',
65 controller: 'ResultsReportController as ctrl'
69 templateUrl: 'testapi-ui/components/profile/profile.html',
70 controller: 'ProfileController as ctrl'
72 state('authFailure', {
74 templateUrl: 'testapi-ui/components/home/home.html',
75 controller: 'AuthFailureController as ctrl'
79 templateUrl: 'testapi-ui/components/logout/logout.html',
80 controller: 'LogoutController as ctrl'
82 state('userVendors', {
84 templateUrl: '/testapi-ui/components/vendors/vendors.html',
85 controller: 'VendorsController as ctrl'
87 state('publicVendors', {
88 url: '/public_vendors',
89 templateUrl: '/testapi-ui/components/vendors/vendors.html',
90 controller: 'VendorsController as ctrl'
93 url: '/vendor/:vendorID',
94 templateUrl: '/swagger/testapi-ui/components/vendors/vendor.html',
95 controller: 'VendorController as ctrl'
97 state('userProducts', {
98 url: '/user_products',
99 templateUrl: '/testapi-ui/components/products/products.html',
100 controller: 'ProductsController as ctrl'
102 state('publicProducts', {
103 url: '/public_products',
104 templateUrl: '/testapi-ui/components/products/products.html',
105 controller: 'ProductsController as ctrl'
109 templateUrl: '/testapi-ui/components/products/cloud.html',
110 controller: 'ProductController as ctrl'
114 templateUrl: '/testapi-ui/components/products/distro.html',
115 controller: 'ProductController as ctrl'
120 .module('testapiApp')
121 .config(disableHttpCache);
123 disableHttpCache.$inject = ['$httpProvider'];
126 * Disable caching in $http requests. This is primarily for IE, as it
127 * tends to cache Angular IE requests.
129 function disableHttpCache($httpProvider) {
130 if (!$httpProvider.defaults.headers.get) {
131 $httpProvider.defaults.headers.get = {};
133 $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
134 $httpProvider.defaults.headers.get.Pragma = 'no-cache';
138 .module('testapiApp')
142 '$http', '$rootScope', '$window', '$state', 'testapiApiUrl'
146 * Set up the app with injections into $rootscope. This is mainly for auth
149 function setup($http, $rootScope, $window, $state, testapiApiUrl) {
151 $rootScope.auth = {};
152 $rootScope.auth.doSignIn = doSignIn;
153 $rootScope.auth.doSignOut = doSignOut;
154 $rootScope.auth.doSignCheck = doSignCheck;
156 var sign_in_url = testapiApiUrl + '/auth/signin';
157 var sign_out_url = testapiApiUrl + '/auth/signout';
158 var profile_url = testapiApiUrl + '/profile';
160 /** This function initiates a sign in. */
161 function doSignIn() {
162 $window.location.href = sign_in_url;
165 /** This function will initate a sign out. */
166 function doSignOut() {
167 $rootScope.auth.currentUser = null;
168 $rootScope.auth.isAuthenticated = false;
169 $window.location.href = sign_out_url;
173 * This function checks to see if a user is logged in and
176 function doSignCheck() {
177 return $http.get(profile_url, {withCredentials: true}).
178 success(function (data) {
179 $rootScope.auth.currentUser = data;
180 $rootScope.auth.isAuthenticated = true;
183 $rootScope.auth.currentUser = null;
184 $rootScope.auth.isAuthenticated = false;
188 $rootScope.auth.doSignCheck();
196 * Load config and start up the angular application.
198 function loadConfig() {
200 var $http = angular.injector(['ng']).get('$http');
203 * Store config variables as constants, and start the app.
205 function startApp(config) {
206 // Add config options as constants.
207 angular.forEach(config, function(value, key) {
208 angular.module('testapiApp').constant(key, value);
211 angular.bootstrap(document, ['testapiApp']);
214 $http.get('testapi-ui/config.json').success(function (data) {
216 }).error(function () {