blob: 3ea20cd8d19fcbd874ee3bc3b281f0b1860f0bc1 [file] [log] [blame]
Radek Krejciae758392017-10-20 10:53:26 +02001import {Component, OnInit, OnDestroy} 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 Krejci95bd14c2017-09-21 14:24:13 +02006import {Device} from '../inventory/device';
Radek Krejcid23f0df2017-08-31 16:34:49 +02007
8@Component({
Radek Krejcib4794962017-09-21 14:16:28 +02009 selector: 'netopeer-config',
10 templateUrl: './config.component.html',
Radek Krejciae758392017-10-20 10:53:26 +020011 styleUrls: ['../netopeer.css', './config.component.css', '../inventory/inventory.component.css']
Radek Krejcid23f0df2017-08-31 16:34:49 +020012})
13
Radek Krejciae758392017-10-20 10:53:26 +020014export class ConfigComponent implements OnInit, OnDestroy {
Radek Krejci95bd14c2017-09-21 14:24:13 +020015 title = 'Configuration';
Radek Krejciae758392017-10-20 10:53:26 +020016 activeSession: Session;
Radek Krejci95bd14c2017-09-21 14:24:13 +020017 err_msg = "";
18
19 constructor(private sessionsService: SessionsService, private router: Router) {}
20
21 addSession() {
22 this.router.navigateByUrl('/netopeer/inventory/devices');
23 }
24
Radek Krejciae758392017-10-20 10:53:26 +020025 reloadData(key: string) {
26 this.activeSession.data = null;
27 this.rpcGet(key);
28 }
29
Radek Krejci95bd14c2017-09-21 14:24:13 +020030 disconnect(key: string) {
31 this.sessionsService.close(key).subscribe(result => {
32 if (result['success']) {
33 if (!this.sessionsService.activeSession) {
34 this.router.navigateByUrl('/netopeer/inventory/devices');
35 }
36 } else {
37 this.err_msg = result['error-msg'];
38 }
39 });
40 }
41
42 getCapabilities(key: string) {
Radek Krejciae758392017-10-20 10:53:26 +020043 if (this.activeSession.cpblts) {
44 return;
45 }
Radek Krejci95bd14c2017-09-21 14:24:13 +020046 this.sessionsService.getCpblts(key).subscribe(result => {
47 if (result['success']) {
Radek Krejciae758392017-10-20 10:53:26 +020048 this.activeSession.cpblts = result['capabilities']
Radek Krejci95bd14c2017-09-21 14:24:13 +020049 } else {
50 this.err_msg = result['error-msg']
51 }
52 });
53 }
54
Radek Krejciae758392017-10-20 10:53:26 +020055 parseCapabilityName(cpblt: string): string {
56 let name = cpblt;
57 let pos = cpblt.search('module=');
58 if (pos != -1) {
59 /* schema */
60 pos += 7;
61 name = cpblt.slice(pos);
62 let end = name.search('&');
63 if (end != -1) {
64 name = name.slice(0, end);
65 }
66 } else {
67 /* capability */
68 pos = 0;
69 if (cpblt.match('urn:ietf:params:netconf:capability:*')) {
70 pos = 34;
71 } else if (cpblt.match('urn:ietf:params:netconf:*')) {
72 pos = 23;
73 }
74 name = cpblt.slice(pos);
75
76 let end = name.search('\\?');
77 if (end != -1) {
78 name = name.slice(0, end);
79 }
80 pos = name.lastIndexOf(':')
81 name = name.slice(0, pos);
82 }
83 return name;
84 }
85
86 parseCapabilityRevision(cpblt: string): string {
87 let version = "";
88 let pos = cpblt.search('revision=');
89 if (pos != -1) {
90 pos += 9;
91 version = cpblt.slice(pos);
92 let end = version.search('&');
93 if (end != -1) {
94 version = version.slice(0, end);
95 }
96 return version;
97 } else if (cpblt.match('urn:ietf:params:netconf:*')) {
98 let end = cpblt.search('\\?');
99 if (end != -1) {
100 cpblt = cpblt.slice(0, end);
101 }
102 pos = cpblt.lastIndexOf(':')
103 version = cpblt.slice(pos + 1);
104 }
105 return version;
106 }
107
Radek Krejci2e578562017-10-17 11:11:13 +0200108 rpcGet(key: string) {
Radek Krejciae758392017-10-20 10:53:26 +0200109 if (this.activeSession.data) {
110 return;
111 }
Radek Krejci2e578562017-10-17 11:11:13 +0200112 this.sessionsService.rpcGet(key).subscribe(result => {
113 if (result['success']) {
Radek Krejciae758392017-10-20 10:53:26 +0200114 this.activeSession.data = result['data']
Radek Krejci2e578562017-10-17 11:11:13 +0200115 } else if ('error-msg' in result) {
116 this.err_msg = result['error-msg']
117 } else {
118 this.err_msg = result['error'][0]['message']
119 }
120 });
121 }
122
Radek Krejci95bd14c2017-09-21 14:24:13 +0200123 ngOnInit(): void {
124 this.sessionsService.checkSessions();
Radek Krejciae758392017-10-20 10:53:26 +0200125 this.activeSession = this.sessionsService.getActiveSession(this.sessionsService.activeSession);
126 }
127
128 ngOnDestroy(): void {
129 this.sessionsService.changingView();
Radek Krejci95bd14c2017-09-21 14:24:13 +0200130 }
Radek Krejcid23f0df2017-08-31 16:34:49 +0200131}