Matteo Scandolo | 6bc31bf | 2016-08-29 10:17:31 -0700 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | angular.module('xos.mcord-slicing', [ |
| 4 | 'ngResource', |
| 5 | 'ngCookies', |
| 6 | 'ui.router', |
| 7 | 'xos.helpers' |
| 8 | ]) |
| 9 | .config(($stateProvider) => { |
| 10 | $stateProvider |
| 11 | .state('slicing-topo', { |
| 12 | url: '/', |
| 13 | template: '<slicing-topo></slicing-topo>' |
| 14 | }) |
| 15 | .state('node-links', { |
| 16 | url: '/data', |
| 17 | template: '<node-links></node-links>' |
| 18 | }); |
| 19 | }) |
| 20 | .config(function($httpProvider){ |
| 21 | $httpProvider.interceptors.push('NoHyperlinks'); |
| 22 | }) |
| 23 | .service('McordSlicingTopo', function($http, $q){ |
| 24 | this.query = () => { |
| 25 | const d = $q.defer(); |
| 26 | |
| 27 | $http.get('api/service/mcord_slicing_ui/topology/') |
| 28 | .then((res) => { |
| 29 | let data; |
| 30 | if (res.data.hasOwnProperty('nodes')){ |
| 31 | data = res.data; |
| 32 | } |
| 33 | else { |
| 34 | // INVESTIGATE why proxy change resposne |
| 35 | data = { |
| 36 | nodes: res.data[0], |
| 37 | links: res.data[1] |
| 38 | }; |
| 39 | } |
| 40 | d.resolve(data); |
| 41 | }) |
| 42 | .catch((e) => { |
| 43 | d.reject(e); |
| 44 | }); |
| 45 | |
| 46 | return {$promise: d.promise}; |
| 47 | }; |
| 48 | }) |
| 49 | .directive('nodeLinks', function(){ |
| 50 | return { |
| 51 | restrict: 'E', |
| 52 | scope: {}, |
| 53 | bindToController: true, |
| 54 | controllerAs: 'vm', |
| 55 | templateUrl: 'templates/node-links.tpl.html', |
| 56 | controller: function(McordSlicingTopo){ |
| 57 | |
| 58 | this.tableConfig = { |
| 59 | columns: [ |
| 60 | { |
| 61 | label: 'Id', |
| 62 | prop: 'id' |
| 63 | }, |
| 64 | { |
| 65 | label: 'Name', |
| 66 | prop: 'name' |
| 67 | }, |
| 68 | { |
| 69 | label: 'Type', |
| 70 | prop: 'type' |
| 71 | }, |
| 72 | { |
| 73 | label: 'Plane', |
| 74 | prop: 'plane' |
| 75 | }, |
| 76 | { |
| 77 | label: 'Model Id', |
| 78 | prop: 'model_id' |
| 79 | } |
| 80 | ] |
| 81 | }; |
| 82 | |
| 83 | // retrieving user list |
| 84 | McordSlicingTopo.query().$promise |
| 85 | .then((users) => { |
| 86 | this.users = users.nodes; |
| 87 | }) |
| 88 | .catch((e) => { |
| 89 | throw new Error(e); |
| 90 | }); |
| 91 | } |
| 92 | }; |
| 93 | }); |