blob: e1830f4e810f5f62b5c7e7007c84f6ff129e23a7 [file] [log] [blame]
Radek Krejci77f77202017-11-03 15:33:50 +01001import {Component, OnInit} from '@angular/core';
Radek Krejci95bd14c2017-09-21 14:24:13 +02002import {Router} from '@angular/router';
3
4import {SessionsService} from './sessions.service';
Radek Krejciae758392017-10-20 10:53:26 +02005import {Session} from './session';
Radek Krejcid23f0df2017-08-31 16:34:49 +02006
7@Component({
Radek Krejcib4794962017-09-21 14:16:28 +02008 selector: 'netopeer-config',
9 templateUrl: './config.component.html',
Radek Krejcia1339602017-11-02 13:52:38 +010010 styleUrls: ['../netopeer.css', './config.component.css', './tree.component.css', '../inventory/inventory.component.css']
Radek Krejcid23f0df2017-08-31 16:34:49 +020011})
12
Radek Krejci77f77202017-11-03 15:33:50 +010013export class ConfigComponent implements OnInit {
Radek Krejci95bd14c2017-09-21 14:24:13 +020014 title = 'Configuration';
Radek Krejciae758392017-10-20 10:53:26 +020015 activeSession: Session;
Radek Krejci95bd14c2017-09-21 14:24:13 +020016 err_msg = "";
17
Radek Krejcia1339602017-11-02 13:52:38 +010018 objectKeys = Object.keys;
Radek Krejci95bd14c2017-09-21 14:24:13 +020019 constructor(private sessionsService: SessionsService, private router: Router) {}
20
21 addSession() {
22 this.router.navigateByUrl('/netopeer/inventory/devices');
23 }
24
Radek Krejcia1339602017-11-02 13:52:38 +010025 reloadData() {
Radek Krejciae758392017-10-20 10:53:26 +020026 this.activeSession.data = null;
Radek Krejcia1339602017-11-02 13:52:38 +010027 if (this.activeSession.dataVisibility == 'all') {
28 this.rpcGet(true);
29 } else if(this.activeSession.dataVisibility == 'root') {
30 this.rpcGet(false);
31 }
Radek Krejciae758392017-10-20 10:53:26 +020032 }
33
Radek Krejci95bd14c2017-09-21 14:24:13 +020034 disconnect(key: string) {
35 this.sessionsService.close(key).subscribe(result => {
36 if (result['success']) {
37 if (!this.sessionsService.activeSession) {
38 this.router.navigateByUrl('/netopeer/inventory/devices');
39 }
40 } else {
41 this.err_msg = result['error-msg'];
42 }
43 });
44 }
45
Radek Krejci77f77202017-11-03 15:33:50 +010046 setCpbltsVisibility(value: boolean) {
47 this.activeSession.cpbltsVisibility = value;
48 this.sessionsService.storeData();
49 }
50
51 setDataVisibility(value: string) {
52 this.activeSession.dataVisibility = value;
53 this.sessionsService.storeData();
54 }
55
56 invertStatus() {
57 this.activeSession.statusVisibility = !this.activeSession.statusVisibility;
58 this.sessionsService.storeData();
59 }
60
Radek Krejci95bd14c2017-09-21 14:24:13 +020061 getCapabilities(key: string) {
Radek Krejciae758392017-10-20 10:53:26 +020062 if (this.activeSession.cpblts) {
Radek Krejci77f77202017-11-03 15:33:50 +010063 this.activeSession.cpbltsVisibility = true;
64 this.sessionsService.storeData();
Radek Krejciae758392017-10-20 10:53:26 +020065 return;
66 }
Radek Krejci95bd14c2017-09-21 14:24:13 +020067 this.sessionsService.getCpblts(key).subscribe(result => {
68 if (result['success']) {
Radek Krejcia1339602017-11-02 13:52:38 +010069 this.activeSession.cpblts = result['capabilities'];
Radek Krejci77f77202017-11-03 15:33:50 +010070 this.activeSession.cpbltsVisibility = true;
Radek Krejci95bd14c2017-09-21 14:24:13 +020071 } else {
Radek Krejcia1339602017-11-02 13:52:38 +010072 this.activeSession.cpbltsVisibility = false;
73 this.err_msg = result['error-msg'];
Radek Krejci95bd14c2017-09-21 14:24:13 +020074 }
Radek Krejci77f77202017-11-03 15:33:50 +010075 this.sessionsService.storeData();
Radek Krejci95bd14c2017-09-21 14:24:13 +020076 });
77 }
78
Radek Krejciae758392017-10-20 10:53:26 +020079 parseCapabilityName(cpblt: string): string {
80 let name = cpblt;
81 let pos = cpblt.search('module=');
82 if (pos != -1) {
83 /* schema */
84 pos += 7;
85 name = cpblt.slice(pos);
86 let end = name.search('&');
87 if (end != -1) {
88 name = name.slice(0, end);
89 }
90 } else {
91 /* capability */
92 pos = 0;
93 if (cpblt.match('urn:ietf:params:netconf:capability:*')) {
94 pos = 34;
95 } else if (cpblt.match('urn:ietf:params:netconf:*')) {
96 pos = 23;
97 }
98 name = cpblt.slice(pos);
99
100 let end = name.search('\\?');
101 if (end != -1) {
102 name = name.slice(0, end);
103 }
104 pos = name.lastIndexOf(':')
105 name = name.slice(0, pos);
106 }
107 return name;
108 }
109
110 parseCapabilityRevision(cpblt: string): string {
111 let version = "";
112 let pos = cpblt.search('revision=');
113 if (pos != -1) {
114 pos += 9;
115 version = cpblt.slice(pos);
116 let end = version.search('&');
117 if (end != -1) {
118 version = version.slice(0, end);
119 }
120 return version;
121 } else if (cpblt.match('urn:ietf:params:netconf:*')) {
122 let end = cpblt.search('\\?');
123 if (end != -1) {
124 cpblt = cpblt.slice(0, end);
125 }
126 pos = cpblt.lastIndexOf(':')
127 version = cpblt.slice(pos + 1);
128 }
129 return version;
130 }
131
Radek Krejcia1339602017-11-02 13:52:38 +0100132 rpcGet(all: boolean) {
Radek Krejciae758392017-10-20 10:53:26 +0200133 if (this.activeSession.data) {
Radek Krejcia1339602017-11-02 13:52:38 +0100134 if ((all && this.activeSession.dataVisibility == 'all') ||
135 (!all && this.activeSession.dataVisibility == 'root')) {
136 return;
137 }
Radek Krejciae758392017-10-20 10:53:26 +0200138 }
Radek Krejcia1339602017-11-02 13:52:38 +0100139 this.sessionsService.rpcGetSubtree(this.activeSession.key, all).subscribe(result => {
Radek Krejci2e578562017-10-17 11:11:13 +0200140 if (result['success']) {
Radek Krejcia1339602017-11-02 13:52:38 +0100141 this.activeSession.data = result['data'];
Radek Krejci77f77202017-11-03 15:33:50 +0100142 if (all) {
143 this.activeSession.dataVisibility = 'all';
144 } else {
145 this.activeSession.dataVisibility = 'root';
146 }
Radek Krejci2e578562017-10-17 11:11:13 +0200147 } else {
Radek Krejcia1339602017-11-02 13:52:38 +0100148 this.activeSession.dataVisibility = 'none';
149 if ('error-msg' in result) {
150 this.err_msg = result['error-msg'];
151 } else {
152 this.err_msg = result['error'][0]['message'];
153 }
Radek Krejci2e578562017-10-17 11:11:13 +0200154 }
Radek Krejci77f77202017-11-03 15:33:50 +0100155 this.sessionsService.storeData();
Radek Krejci2e578562017-10-17 11:11:13 +0200156 });
157 }
158
Radek Krejci95bd14c2017-09-21 14:24:13 +0200159 ngOnInit(): void {
160 this.sessionsService.checkSessions();
Radek Krejci77f77202017-11-03 15:33:50 +0100161 this.activeSession = this.sessionsService.getActiveSession();
Radek Krejciae758392017-10-20 10:53:26 +0200162 }
163
Radek Krejcib424acd2017-10-20 11:36:46 +0200164 changeActiveSession(key: string) {
Radek Krejci77f77202017-11-03 15:33:50 +0100165 this.activeSession = this.sessionsService.changeActiveSession(key);
Radek Krejci95bd14c2017-09-21 14:24:13 +0200166 }
Radek Krejcid23f0df2017-08-31 16:34:49 +0200167}