blob: 4b0f37da72997e77fb8c0307a3579434dc88890b [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandolo6bc31bf2016-08-29 10:17:31 -070019'use strict';
20
21angular.module('xos.mcord-slicing', [
22 'ngResource',
23 'ngCookies',
24 'ui.router',
25 'xos.helpers'
26])
27.config(($stateProvider) => {
28 $stateProvider
29 .state('slicing-topo', {
30 url: '/',
31 template: '<slicing-topo></slicing-topo>'
32 })
33 .state('node-links', {
34 url: '/data',
35 template: '<node-links></node-links>'
36 });
37})
38.config(function($httpProvider){
39 $httpProvider.interceptors.push('NoHyperlinks');
40})
41.service('McordSlicingTopo', function($http, $q){
42 this.query = () => {
43 const d = $q.defer();
44
45 $http.get('api/service/mcord_slicing_ui/topology/')
46 .then((res) => {
47 let data;
48 if (res.data.hasOwnProperty('nodes')){
49 data = res.data;
50 }
51 else {
52 // INVESTIGATE why proxy change resposne
53 data = {
54 nodes: res.data[0],
55 links: res.data[1]
56 };
57 }
58 d.resolve(data);
59 })
60 .catch((e) => {
61 d.reject(e);
62 });
63
64 return {$promise: d.promise};
65 };
66})
67.directive('nodeLinks', function(){
68 return {
69 restrict: 'E',
70 scope: {},
71 bindToController: true,
72 controllerAs: 'vm',
73 templateUrl: 'templates/node-links.tpl.html',
74 controller: function(McordSlicingTopo){
75
76 this.tableConfig = {
77 columns: [
78 {
79 label: 'Id',
80 prop: 'id'
81 },
82 {
83 label: 'Name',
84 prop: 'name'
85 },
86 {
87 label: 'Type',
88 prop: 'type'
89 },
90 {
91 label: 'Plane',
92 prop: 'plane'
93 },
94 {
95 label: 'Model Id',
96 prop: 'model_id'
97 }
98 ]
99 };
100
101 // retrieving user list
102 McordSlicingTopo.query().$promise
103 .then((users) => {
104 this.users = users.nodes;
105 })
106 .catch((e) => {
107 throw new Error(e);
108 });
109 }
110 };
111});