Merge "add web portal framework for TestAPI"
[releng.git] / utils / test / testapi / 3rd_party / static / testapi-ui / shared / header / headerController.js
1 /*
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
5  *
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
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.
13  */
14
15 (function () {
16     'use strict';
17
18     angular
19         .module('testapiApp')
20         .controller('HeaderController', HeaderController);
21
22     HeaderController.$inject = ['$location'];
23
24     /**
25      * TestAPI Header Controller
26      * This controller is for the header template which contains the site
27      * navigation.
28      */
29     function HeaderController($location) {
30         var ctrl = this;
31
32         ctrl.isActive = isActive;
33         ctrl.isCatalogActive = isCatalogActive;
34
35         /** Whether the Navbar is collapsed for small displays. */
36         ctrl.navbarCollapsed = true;
37
38         /**
39          * This determines whether a button should be in the active state based
40          * on the URL.
41          */
42         function isActive(viewLocation) {
43             var path = $location.path().substr(0, viewLocation.length);
44             if (path === viewLocation) {
45                 // Make sure "/" only matches when viewLocation is "/".
46                 if (!($location.path().substr(0).length > 1 &&
47                     viewLocation.length === 1 )) {
48                     return true;
49                 }
50             }
51             return false;
52         }
53
54         /** This determines the active state for the catalog dropdown. Type
55          * parameter should be passed in to specify if the catalog is the
56          * public or user one.
57          */
58         function isCatalogActive(type) {
59             return ctrl.isActive('/' + type + '_vendors')
60                    || ctrl.isActive('/' + type + '_products');
61         }
62     }
63 })();