blob: cba8c59c7b5f030c05f99ac4979dc40d958962cc [file] [log] [blame]
Bri Prebilic Colee0311892015-05-15 11:27:15 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Bri Prebilic Colee0311892015-05-15 11:27:15 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17(function () {
18 'use strict';
19
Bri Prebilic Coled189e282015-06-05 10:00:22 -070020 var urlSuffix = '/rs/bundle';
Bri Prebilic Cole10570eb2015-05-20 16:23:52 -070021
Bri Prebilic Colef3eba312015-05-21 16:35:06 -070022 var basic = 'basic',
Bri Prebilic Coled3d7a322015-05-28 14:15:14 -070023 family = 'family';
Bri Prebilic Coled050a4b2015-05-27 15:53:30 -070024
Bri Prebilic Cole8db16402015-05-18 13:50:31 -070025 angular.module('cordBundle', [])
Bri Prebilic Coled3d7a322015-05-28 14:15:14 -070026 .controller('CordBundleCtrl', ['$log', '$scope', '$resource',
27 function ($log, $scope, $resource) {
28 var BundleData, resource,
29 getData;
Bri Prebilic Cole60553c82015-06-05 08:50:17 -070030 $scope.page.curr = 'bundle';
Bri Prebilic Cole0e371dc2015-06-05 16:47:21 -070031 $scope.show = false;
Bri Prebilic Colef3eba312015-05-21 16:35:06 -070032
Bri Prebilic Coled3d7a322015-05-28 14:15:14 -070033 getData = function (id) {
34 if (!id) { id = ''; }
35
Bri Prebilic Coled189e282015-06-05 10:00:22 -070036 BundleData = $resource($scope.shared.url + urlSuffix + '/' + id);
Bri Prebilic Coled3d7a322015-05-28 14:15:14 -070037 resource = BundleData.get({},
38 // success
39 function () {
40 var current, availId;
41 current = resource.bundle.id;
42 $scope.name = resource.bundle.name;
43 $scope.desc = resource.bundle.desc;
44 $scope.funcs = resource.bundle.functions;
45
46 availId = (current === basic) ? family : basic;
47 resource.bundles.forEach(function (bundle) {
48 if (bundle.id === availId) {
49 $scope.available = bundle;
50 }
51 });
52 },
53 // error
54 function () {
55 $log.error('Problem with resource', resource);
56 });
Bri Prebilic Colef3eba312015-05-21 16:35:06 -070057 };
Bri Prebilic Cole10570eb2015-05-20 16:23:52 -070058
Bri Prebilic Coled3d7a322015-05-28 14:15:14 -070059 getData();
Bri Prebilic Coled050a4b2015-05-27 15:53:30 -070060
Bri Prebilic Coled3d7a322015-05-28 14:15:14 -070061 $scope.changeBundle = function (id) {
62 getData(id);
63 };
Bri Prebilic Coled050a4b2015-05-27 15:53:30 -070064
Bri Prebilic Cole0e371dc2015-06-05 16:47:21 -070065 $scope.showBundles = function () {
66 $scope.show = !$scope.show;
67 };
68
Bri Prebilic Coled050a4b2015-05-27 15:53:30 -070069 $log.debug('Cord Bundle Ctrl has been created.');
70 }])
71
Bri Prebilic Coled3d7a322015-05-28 14:15:14 -070072 .directive('bundleAvailable', [function () {
Bri Prebilic Coled050a4b2015-05-27 15:53:30 -070073 return {
Bri Prebilic Coled3d7a322015-05-28 14:15:14 -070074 templateUrl: 'app/view/bundle/available.html'
Bri Prebilic Coled050a4b2015-05-27 15:53:30 -070075 };
Bri Prebilic Colebdd6b3b2015-05-22 15:44:18 -070076 }]);
Bri Prebilic Colee0311892015-05-15 11:27:15 -070077}());