blob: fb98e4c4eb5ab62c00aea7f0f709846187ed202e [file] [log] [blame]
Matteo Scandolo22f8e822017-09-28 16:35:20 -07001/*
2 * Copyright 2017-present Open Networking Foundation
3
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
17import * as _ from 'lodash';
18import './subscriber-dashboard.scss';
19
20class rcordSubscriberDashboardCtrl {
21
22 static $inject = [
23 'toastr',
24 'XosModelStore',
25 'XosModeldefsCache'
26 ];
27
28 public levelOptions = [];
29 public subscribers = [];
30 public statusFieldOptions = [];
31 public slider = {
32 floor: 0,
33 ceil: 1000000000,
34 translate: (value) => {
35 return Math.floor(value / 1000000);
36 }
37 };
38
39 private subscriberDef;
40
41 constructor (
42 private toastr: any,
43 private XosModelStore: any,
44 private XosModeldefsCache: any
45 ) {
46
47 }
48
49 $onInit() {
50 this.XosModelStore.query('CordSubscriberRoot', '/rcord/cordsubscriberroots')
51 .subscribe(
52 res => {
53 this.subscribers = this.parseSubscribers(res);
54 }
55 );
56
57 this.levelOptions = [
58 `G`,
59 `PG`,
60 `PG_13`,
61 `R`,
62 `X`
63 ];
64
65 this.subscriberDef = this.XosModeldefsCache.get('CordSubscriberRoot');
66 this.statusFieldOptions = _.find(this.subscriberDef.fields, {name: 'status'}).options;
67 }
68
69 public addDevice(subscriber) {
70 subscriber.service_specific_attribute.devices.push({
71 name: '',
72 mac: '',
73 level: 'PG_13'
74 })
75 }
76
77 public removeDevice(subscriber, device) {
78 _.remove(subscriber.service_specific_attribute.devices, {name:device.name})
79 }
80
81 public save(subscriber) {
82 console.log(subscriber);
83 const item: any = angular.copy(subscriber);
84 item.service_specific_attribute = JSON.stringify(item.service_specific_attribute);
85 item.$save()
86 .then(() => {
87 this.toastr.success(`Subscriber successfully saved`);
88 });
89 }
90
91 private parseSubscribers(subscribers) {
92 return _.map(subscribers, (s) => {
93 if (angular.isString(s.service_specific_attribute)) {
94 s.service_specific_attribute = JSON.parse(s.service_specific_attribute);
95 }
96 return s;
97 })
98 }
99}
100
101export const rcordSubscriberDashboard: angular.IComponentOptions = {
102 template: require('./subscriber-dashboard.html'),
103 controllerAs: 'vm',
104 controller: rcordSubscriberDashboardCtrl
105};