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);
31 .directive('dynamicModel', ['$compile', '$parse', function ($compile, $parse) {
36 link: function (scope, elem) {
37 var name = $parse(elem.attr('dynamic-model'))(scope);
38 elem.removeAttr('dynamic-model');
39 elem.attr('ng-model', name);
40 $compile(elem)(scope);
45 configureRoutes.$inject = ['$stateProvider', '$urlRouterProvider'];
48 * Handle application routing. Specific templates and controllers will be
49 * used based on the URL route.
51 function configureRoutes($stateProvider, $urlRouterProvider) {
52 $urlRouterProvider.otherwise('/');
56 templateUrl: 'testapi-ui/components/home/home.html'
60 templateUrl: 'testapi-ui/components/about/about.html'
64 templateUrl: 'testapi-ui/components/pods/pods.html',
65 controller: 'PodsController as ctrl'
67 state('communityResults', {
68 url: '/community_results',
69 templateUrl: 'testapi-ui/components/results/results.html',
70 controller: 'ResultsController as ctrl'
72 state('userResults', {
74 templateUrl: 'testapi-ui/components/results/results.html',
75 controller: 'ResultsController as ctrl'
77 state('resultsDetail', {
78 url: '/results/:testID',
79 templateUrl: 'testapi-ui/components/results-report' +
80 '/resultsReport.html',
81 controller: 'ResultsReportController as ctrl'
85 templateUrl: 'testapi-ui/components/profile/profile.html',
86 controller: 'ProfileController as ctrl'
88 state('authFailure', {
90 templateUrl: 'testapi-ui/components/home/home.html',
91 controller: 'AuthFailureController as ctrl'
95 templateUrl: 'testapi-ui/components/logout/logout.html',
96 controller: 'LogoutController as ctrl'
98 state('userVendors', {
100 templateUrl: '/testapi-ui/components/vendors/vendors.html',
101 controller: 'VendorsController as ctrl'
103 state('publicVendors', {
104 url: '/public_vendors',
105 templateUrl: '/testapi-ui/components/vendors/vendors.html',
106 controller: 'VendorsController as ctrl'
109 url: '/vendor/:vendorID',
110 templateUrl: '/swagger/testapi-ui/components/vendors/vendor.html',
111 controller: 'VendorController as ctrl'
113 state('userProducts', {
114 url: '/user_products',
115 templateUrl: '/testapi-ui/components/products/products.html',
116 controller: 'ProductsController as ctrl'
118 state('publicProducts', {
119 url: '/public_products',
120 templateUrl: '/testapi-ui/components/products/products.html',
121 controller: 'ProductsController as ctrl'
125 templateUrl: '/testapi-ui/components/products/cloud.html',
126 controller: 'ProductController as ctrl'
130 templateUrl: '/testapi-ui/components/products/distro.html',
131 controller: 'ProductController as ctrl'
136 .module('testapiApp')
137 .config(disableHttpCache);
139 disableHttpCache.$inject = ['$httpProvider'];
142 * Disable caching in $http requests. This is primarily for IE, as it
143 * tends to cache Angular IE requests.
145 function disableHttpCache($httpProvider) {
146 if (!$httpProvider.defaults.headers.get) {
147 $httpProvider.defaults.headers.get = {};
149 $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
150 $httpProvider.defaults.headers.get.Pragma = 'no-cache';
154 .module('testapiApp')
158 '$http', '$rootScope', '$window', '$state', 'testapiApiUrl'
162 * Set up the app with injections into $rootscope. This is mainly for auth
165 function setup($http, $rootScope, $window, $state, testapiApiUrl) {
167 $rootScope.auth = {};
168 $rootScope.auth.doSignIn = doSignIn;
169 $rootScope.auth.doSignOut = doSignOut;
170 $rootScope.auth.doSignCheck = doSignCheck;
172 var sign_in_url = testapiApiUrl + '/auth/signin';
173 var sign_out_url = testapiApiUrl + '/auth/signout';
174 var profile_url = testapiApiUrl + '/profile';
176 /** This function initiates a sign in. */
177 function doSignIn() {
178 $window.location.href = sign_in_url;
181 /** This function will initate a sign out. */
182 function doSignOut() {
183 $rootScope.auth.currentUser = null;
184 $rootScope.auth.isAuthenticated = false;
185 $window.location.href = sign_out_url;
189 * This function checks to see if a user is logged in and
192 function doSignCheck() {
193 return $http.get(profile_url, {withCredentials: true}).
194 success(function (data) {
195 $rootScope.auth.currentUser = data;
196 $rootScope.auth.isAuthenticated = true;
199 $rootScope.auth.currentUser = null;
200 $rootScope.auth.isAuthenticated = false;
204 $rootScope.auth.doSignCheck();
212 * Load config and start up the angular application.
214 function loadConfig() {
216 var $http = angular.injector(['ng']).get('$http');
219 * Store config variables as constants, and start the app.
221 function startApp(config) {
222 // Add config options as constants.
223 angular.forEach(config, function(value, key) {
224 angular.module('testapiApp').constant(key, value);
227 angular.bootstrap(document, ['testapiApp']);
230 $http.get('testapi-ui/config.json').success(function (data) {
232 }).error(function () {