Radek Krejci | 30ce159 | 2018-03-01 14:44:14 +0100 | [diff] [blame] | 1 | import {Component, OnInit} from '@angular/core'; |
Jakub Man | 59c4ea1 | 2018-06-13 15:21:32 +0200 | [diff] [blame] | 2 | import { Router } from '@angular/router'; |
| 3 | import { Observable } from 'rxjs/Observable'; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 4 | |
Radek Krejci | 30ce159 | 2018-03-01 14:44:14 +0100 | [diff] [blame] | 5 | import {TreeService} from './tree.service'; |
Radek Krejci | 9b41f5b | 2018-01-31 14:17:50 +0100 | [diff] [blame] | 6 | import {ModificationsService} from './modifications.service'; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 7 | import {SessionsService} from './sessions.service'; |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 8 | import {Session} from './session'; |
Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 9 | |
| 10 | @Component({ |
Radek Krejci | b479496 | 2017-09-21 14:16:28 +0200 | [diff] [blame] | 11 | selector: 'netopeer-config', |
| 12 | templateUrl: './config.component.html', |
Radek Krejci | 5a69fa3 | 2018-02-01 11:03:04 +0100 | [diff] [blame] | 13 | styleUrls: ['./config.component.scss'], |
Radek Krejci | 30ce159 | 2018-03-01 14:44:14 +0100 | [diff] [blame] | 14 | providers: [ModificationsService] |
Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 15 | }) |
| 16 | |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 17 | export class ConfigComponent implements OnInit { |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 18 | title = 'Configuration'; |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 19 | activeSession: Session; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 20 | err_msg = ""; |
Radek Krejci | fc908f3 | 2018-02-08 14:53:31 +0100 | [diff] [blame] | 21 | commit_error = []; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 22 | |
Radek Krejci | 4a4c9ed | 2018-03-21 13:22:04 +0100 | [diff] [blame] | 23 | constructor(public sessionsService: SessionsService, |
| 24 | public modsService: ModificationsService, |
| 25 | public treeService: TreeService, |
Radek Krejci | 9b41f5b | 2018-01-31 14:17:50 +0100 | [diff] [blame] | 26 | private router: Router) {} |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 27 | |
| 28 | addSession() { |
| 29 | this.router.navigateByUrl('/netopeer/inventory/devices'); |
| 30 | } |
| 31 | |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 32 | reloadData() { |
Radek Krejci | d0fac3b | 2018-03-13 16:55:47 +0100 | [diff] [blame] | 33 | switch (this.activeSession.dataPresence) { |
| 34 | case 'root': |
| 35 | this.activeSession.data = null; |
Radek Krejci | 30ce159 | 2018-03-01 14:44:14 +0100 | [diff] [blame] | 36 | this.sessionsService.rpcGet(this.activeSession, false); |
Radek Krejci | d0fac3b | 2018-03-13 16:55:47 +0100 | [diff] [blame] | 37 | break; |
| 38 | case 'all': |
| 39 | this.activeSession.data = null; |
Radek Krejci | 30ce159 | 2018-03-01 14:44:14 +0100 | [diff] [blame] | 40 | this.sessionsService.rpcGet(this.activeSession, true); |
Radek Krejci | d0fac3b | 2018-03-13 16:55:47 +0100 | [diff] [blame] | 41 | break; |
| 42 | case 'mixed': |
| 43 | this.sessionsService.rpcGetSubtree(this.activeSession.key, false).subscribe(result => { |
| 44 | let root = this.activeSession.data; |
| 45 | if (result['success']) { |
| 46 | for (let newRoot of result['data']) { |
| 47 | let matchIndex = -1; |
| 48 | for (let i in root['children']) { |
| 49 | if (newRoot['path'] == root['children'][i]['path']) { |
| 50 | matchIndex = Number(i); |
| 51 | break; |
| 52 | } |
| 53 | } |
| 54 | if (matchIndex == -1) { |
| 55 | /* add new subtree */ |
| 56 | root['children'].push(newRoot); |
| 57 | } else { |
| 58 | let subtree = root['children'][matchIndex]; |
| 59 | let filterIndex = this.activeSession.treeFilters.indexOf(subtree['path']); |
| 60 | if (filterIndex != -1) { |
| 61 | /* reloading currently present but not visible subtrees is postponed to the point they are displayed */ |
| 62 | subtree['subtreeRoot'] = true; |
| 63 | delete subtree['children']; |
| 64 | this.activeSession.treeFilters.splice(filterIndex, 1); |
| 65 | this.activeSession.dataPresence = 'root'; |
| 66 | for (let root of this.activeSession.data['children']) { |
| 67 | if (!('subtreeRoot' in root)) { |
| 68 | this.activeSession.dataPresence = 'mixed'; |
| 69 | break; |
| 70 | } |
| 71 | } |
| 72 | } else if (!('subtreeRoot' in subtree)) { |
| 73 | /* reload currently present and visible subtrees */ |
| 74 | subtree['loading'] = true; |
| 75 | this.sessionsService.rpcGetSubtree(this.activeSession.key, true, subtree['path']).subscribe(result => { |
| 76 | subtree['loading'] = false; |
| 77 | if (result['success']) { |
| 78 | for (let iter of result['data']['children']) { |
| 79 | this.treeService.setDirty(this.activeSession, iter); |
| 80 | } |
| 81 | subtree['children'] = result['data']['children']; |
| 82 | this.treeService.updateHiddenFlags(this.activeSession); |
| 83 | this.sessionsService.storeSessions(); |
| 84 | } |
| 85 | }); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | this.sessionsService.storeSessions(); |
| 91 | }); |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 92 | } |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 93 | } |
| 94 | |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 95 | disconnect(key: string) { |
| 96 | this.sessionsService.close(key).subscribe(result => { |
| 97 | if (result['success']) { |
| 98 | if (!this.sessionsService.activeSession) { |
| 99 | this.router.navigateByUrl('/netopeer/inventory/devices'); |
| 100 | } |
Radek Krejci | 482629d | 2018-03-13 14:56:00 +0100 | [diff] [blame] | 101 | this.activeSession = this.sessionsService.getSession(); |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 102 | } else { |
| 103 | this.err_msg = result['error-msg']; |
| 104 | } |
| 105 | }); |
| 106 | } |
| 107 | |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 108 | setCpbltsVisibility(value: boolean) { |
| 109 | this.activeSession.cpbltsVisibility = value; |
Radek Krejci | 482629d | 2018-03-13 14:56:00 +0100 | [diff] [blame] | 110 | this.sessionsService.storeSessions(); |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 113 | invertStatus() { |
| 114 | this.activeSession.statusVisibility = !this.activeSession.statusVisibility; |
Radek Krejci | 482629d | 2018-03-13 14:56:00 +0100 | [diff] [blame] | 115 | this.sessionsService.storeSessions(); |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 116 | } |
| 117 | |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 118 | getCapabilities(key: string) { |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 119 | if (this.activeSession.cpblts) { |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 120 | this.activeSession.cpbltsVisibility = true; |
Radek Krejci | 482629d | 2018-03-13 14:56:00 +0100 | [diff] [blame] | 121 | this.sessionsService.storeSessions(); |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 122 | return; |
| 123 | } |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 124 | this.sessionsService.getCpblts(key).subscribe(result => { |
| 125 | if (result['success']) { |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 126 | this.activeSession.cpblts = result['capabilities']; |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 127 | this.activeSession.cpbltsVisibility = true; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 128 | } else { |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 129 | this.activeSession.cpbltsVisibility = false; |
| 130 | this.err_msg = result['error-msg']; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 131 | } |
Radek Krejci | 482629d | 2018-03-13 14:56:00 +0100 | [diff] [blame] | 132 | this.sessionsService.storeSessions(); |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 133 | }); |
| 134 | } |
| 135 | |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 136 | parseCapabilityName(cpblt: string): string { |
| 137 | let name = cpblt; |
| 138 | let pos = cpblt.search('module='); |
| 139 | if (pos != -1) { |
| 140 | /* schema */ |
| 141 | pos += 7; |
| 142 | name = cpblt.slice(pos); |
| 143 | let end = name.search('&'); |
| 144 | if (end != -1) { |
| 145 | name = name.slice(0, end); |
| 146 | } |
| 147 | } else { |
| 148 | /* capability */ |
| 149 | pos = 0; |
| 150 | if (cpblt.match('urn:ietf:params:netconf:capability:*')) { |
| 151 | pos = 34; |
| 152 | } else if (cpblt.match('urn:ietf:params:netconf:*')) { |
| 153 | pos = 23; |
| 154 | } |
| 155 | name = cpblt.slice(pos); |
| 156 | |
| 157 | let end = name.search('\\?'); |
| 158 | if (end != -1) { |
| 159 | name = name.slice(0, end); |
| 160 | } |
| 161 | pos = name.lastIndexOf(':') |
| 162 | name = name.slice(0, pos); |
| 163 | } |
| 164 | return name; |
| 165 | } |
| 166 | |
| 167 | parseCapabilityRevision(cpblt: string): string { |
| 168 | let version = ""; |
| 169 | let pos = cpblt.search('revision='); |
| 170 | if (pos != -1) { |
| 171 | pos += 9; |
| 172 | version = cpblt.slice(pos); |
| 173 | let end = version.search('&'); |
| 174 | if (end != -1) { |
| 175 | version = version.slice(0, end); |
| 176 | } |
| 177 | return version; |
| 178 | } else if (cpblt.match('urn:ietf:params:netconf:*')) { |
| 179 | let end = cpblt.search('\\?'); |
| 180 | if (end != -1) { |
| 181 | cpblt = cpblt.slice(0, end); |
| 182 | } |
| 183 | pos = cpblt.lastIndexOf(':') |
| 184 | version = cpblt.slice(pos + 1); |
| 185 | } |
| 186 | return version; |
| 187 | } |
| 188 | |
Radek Krejci | 26bf2bc | 2018-01-09 15:00:54 +0100 | [diff] [blame] | 189 | cancelChanges() { |
Radek Krejci | 2ca11ba | 2018-01-26 11:25:42 +0100 | [diff] [blame] | 190 | //console.log(JSON.stringify(this.activeSession.modifications)) |
Radek Krejci | 9b41f5b | 2018-01-31 14:17:50 +0100 | [diff] [blame] | 191 | this.modsService.cancelModification(this.activeSession); |
Radek Krejci | fc908f3 | 2018-02-08 14:53:31 +0100 | [diff] [blame] | 192 | this.commit_error = []; |
Radek Krejci | 482629d | 2018-03-13 14:56:00 +0100 | [diff] [blame] | 193 | this.sessionsService.storeSessions(); |
Radek Krejci | 2ca11ba | 2018-01-26 11:25:42 +0100 | [diff] [blame] | 194 | //console.log(JSON.stringify(this.activeSession.modifications)) |
Radek Krejci | 26bf2bc | 2018-01-09 15:00:54 +0100 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | applyChanges() { |
Radek Krejci | 30ce159 | 2018-03-01 14:44:14 +0100 | [diff] [blame] | 198 | //console.log(JSON.stringify(this.activeSession.modifications)) |
Jakub Man | 59c4ea1 | 2018-06-13 15:21:32 +0200 | [diff] [blame] | 199 | this.modsService.applyModification(this.activeSession).subscribe(result => { |
Radek Krejci | 62fec6a | 2018-02-06 10:24:09 +0100 | [diff] [blame] | 200 | if (result['success']) { |
| 201 | this.reloadData(); |
Radek Krejci | fc908f3 | 2018-02-08 14:53:31 +0100 | [diff] [blame] | 202 | this.commit_error = []; |
Jakub Man | 59c4ea1 | 2018-06-13 15:21:32 +0200 | [diff] [blame] | 203 | } |
| 204 | else { |
Radek Krejci | fc908f3 | 2018-02-08 14:53:31 +0100 | [diff] [blame] | 205 | this.commit_error = result['error']; |
Radek Krejci | 62fec6a | 2018-02-06 10:24:09 +0100 | [diff] [blame] | 206 | } |
Jakub Man | 59c4ea1 | 2018-06-13 15:21:32 +0200 | [diff] [blame] | 207 | }); |
Radek Krejci | 26bf2bc | 2018-01-09 15:00:54 +0100 | [diff] [blame] | 208 | } |
Radek Krejci | 6e772b2 | 2018-01-25 13:28:57 +0100 | [diff] [blame] | 209 | |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 210 | ngOnInit(): void { |
| 211 | this.sessionsService.checkSessions(); |
Radek Krejci | 482629d | 2018-03-13 14:56:00 +0100 | [diff] [blame] | 212 | this.activeSession = this.sessionsService.getSession(); |
Radek Krejci | 6be087d | 2018-02-14 08:53:20 +0100 | [diff] [blame] | 213 | if (this.activeSession && !this.activeSession.data) { |
Radek Krejci | 30ce159 | 2018-03-01 14:44:14 +0100 | [diff] [blame] | 214 | this.sessionsService.rpcGet(this.activeSession, false); |
Radek Krejci | d0fac3b | 2018-03-13 16:55:47 +0100 | [diff] [blame] | 215 | this.activeSession.dataPresence = 'root'; |
Radek Krejci | 5a69fa3 | 2018-02-01 11:03:04 +0100 | [diff] [blame] | 216 | } |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 217 | } |
Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 218 | } |