Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 1 | import {Component, OnInit} from '@angular/core'; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 2 | import {Router} from '@angular/router'; |
| 3 | |
| 4 | import {SessionsService} from './sessions.service'; |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 5 | import {Session} from './session'; |
Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 6 | |
| 7 | @Component({ |
Radek Krejci | b479496 | 2017-09-21 14:16:28 +0200 | [diff] [blame] | 8 | selector: 'netopeer-config', |
| 9 | templateUrl: './config.component.html', |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 10 | styleUrls: ['../netopeer.css', './config.component.css', './tree.component.css', '../inventory/inventory.component.css'] |
Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 11 | }) |
| 12 | |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 13 | export class ConfigComponent implements OnInit { |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 14 | title = 'Configuration'; |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 15 | activeSession: Session; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 16 | err_msg = ""; |
| 17 | |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 18 | objectKeys = Object.keys; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 19 | constructor(private sessionsService: SessionsService, private router: Router) {} |
| 20 | |
| 21 | addSession() { |
| 22 | this.router.navigateByUrl('/netopeer/inventory/devices'); |
| 23 | } |
| 24 | |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 25 | reloadData() { |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 26 | this.activeSession.data = null; |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 27 | if (this.activeSession.dataVisibility == 'all') { |
| 28 | this.rpcGet(true); |
| 29 | } else if(this.activeSession.dataVisibility == 'root') { |
| 30 | this.rpcGet(false); |
| 31 | } |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 32 | } |
| 33 | |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 34 | 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 Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 46 | 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 Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 61 | getCapabilities(key: string) { |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 62 | if (this.activeSession.cpblts) { |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 63 | this.activeSession.cpbltsVisibility = true; |
| 64 | this.sessionsService.storeData(); |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 65 | return; |
| 66 | } |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 67 | this.sessionsService.getCpblts(key).subscribe(result => { |
| 68 | if (result['success']) { |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 69 | this.activeSession.cpblts = result['capabilities']; |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 70 | this.activeSession.cpbltsVisibility = true; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 71 | } else { |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 72 | this.activeSession.cpbltsVisibility = false; |
| 73 | this.err_msg = result['error-msg']; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 74 | } |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 75 | this.sessionsService.storeData(); |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 76 | }); |
| 77 | } |
| 78 | |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 79 | 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 Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 132 | rpcGet(all: boolean) { |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 133 | if (this.activeSession.data) { |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 134 | if ((all && this.activeSession.dataVisibility == 'all') || |
| 135 | (!all && this.activeSession.dataVisibility == 'root')) { |
| 136 | return; |
| 137 | } |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 138 | } |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 139 | this.sessionsService.rpcGetSubtree(this.activeSession.key, all).subscribe(result => { |
Radek Krejci | 2e57856 | 2017-10-17 11:11:13 +0200 | [diff] [blame] | 140 | if (result['success']) { |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 141 | this.activeSession.data = result['data']; |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 142 | if (all) { |
| 143 | this.activeSession.dataVisibility = 'all'; |
| 144 | } else { |
| 145 | this.activeSession.dataVisibility = 'root'; |
| 146 | } |
Radek Krejci | 2e57856 | 2017-10-17 11:11:13 +0200 | [diff] [blame] | 147 | } else { |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 148 | 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 Krejci | 2e57856 | 2017-10-17 11:11:13 +0200 | [diff] [blame] | 154 | } |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 155 | this.sessionsService.storeData(); |
Radek Krejci | 2e57856 | 2017-10-17 11:11:13 +0200 | [diff] [blame] | 156 | }); |
| 157 | } |
| 158 | |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 159 | ngOnInit(): void { |
| 160 | this.sessionsService.checkSessions(); |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 161 | this.activeSession = this.sessionsService.getActiveSession(); |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 162 | } |
| 163 | |
Radek Krejci | b424acd | 2017-10-20 11:36:46 +0200 | [diff] [blame] | 164 | changeActiveSession(key: string) { |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 165 | this.activeSession = this.sessionsService.changeActiveSession(key); |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 166 | } |
Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 167 | } |