blob: e4c1f7c6906f942e14f09e715df742a3aeec76d1 [file] [log] [blame]
Rizwan Haider8e5f4772016-08-17 18:04:35 -04001/**
2 * © OpenCORD
3 *
4 * Visit http://guide.xosproject.org/devguide/addview/ for more information
5 *
6 * Created by teone on 6/28/16.
7 */
8
9(function () {
10 'use strict';
11 angular.module('xos.ecordTopology')
12 .directive('elineDetails', function() {
13 return {
14 restrict: 'E',
15 scope: {
16 },
17 bindToController: true,
18 controllerAs: 'vm',
19 templateUrl: 'templates/eline-details.tpl.html',
20 controller: function ($scope, $stateParams, Eline) {
21
22 this.eline = null;
23
24 const Resource = Eline();
25
26 Eline.get({id: $stateParams.id}).$promise
27 .then((eline) => {
28 this.eline = eline;
29 });
30
31 this.slas = [
32 {
33 name: 'Latency',
34 unit: 'ms',
35 default: 300
36 },
37 {
38 name: 'Latency Variation',
39 unit: '%',
40 default: 5
41 },
42 {
43 name: 'Packet Loss',
44 unit: '%',
45 default: 2
46 }
47 ];
48
49 this.availableServices = {
50 performance: [
51 {id: 1, label: 'WAN Accelerator'},
52 {id: 2, label: 'Traffic Analytics'},
53 {id: 3, label: 'Policy Control'},
54 ],
55 security: [
56 {id: 4, label: 'Firewall'},
57 {id: 5, label: 'Anti-virus'},
58 {id: 6, label: 'IDS'},
59 {id: 7, label: 'Encryption'},
60 ],
61 enterprise: [
62 {id: 8, label: 'vRouter'},
63 {id: 9, label: 'NAT'},
64 {id: 10, label: 'VPN'},
65 ]
66 };
67
68 this.activeServices = [];
69 this.toggleService = (service) => {
70 let isSelected = this.activeServices.indexOf(service);
71 if(isSelected !== -1){
72 this.activeServices.splice(this.activeServices.indexOf(service), 1);
73 }
74 else {
75 this.activeServices.push(service);
76 }
77 };
78
79 this.isServiceActive = (service) => {
80 let isSelected = this.activeServices.indexOf(service);
81 return (isSelected !== -1) ? true : false;
82 };
83
84 $scope.$watch(() => this.el, (val, oldval) => {
85 if(val !== oldval && this.elineUpdate.$saved){
86 this.eline.$saved = false;
87 }
88 }, true);
89
90 this.saveEline = () => {
91
92 const resource = new Eline(this.eline);
93
94 resource.$save()
95 .then(() => {
96 $scope.saved = true;
97 })
98 .catch(e => {
99 console.error(e);
100 });
101 };
102 }
103 }
104 })
105 .directive('bToMb', function() {
106 // TODO improve with this:
107 // https://gist.github.com/thomseddon/3511330
108 return {
109 require: 'ngModel',
110 restrict: 'A',
111 link: function(scope, element, attrs, ngModelController) {
112 ngModelController.$parsers.push(function(data) {
113 //convert data from view format to model format
114 return data * 1000000000; //converted
115 });
116
117 ngModelController.$formatters.push(function(data) {
118 //convert data from model format to view format
119 return data / 1000000000; //converted
120 });
121 }
122 }
123 });
124})();
125