Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 1 | import {Component, OnInit, OnDestroy} 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 | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 6 | import {Device} from '../inventory/device'; |
Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 7 | |
| 8 | @Component({ |
Radek Krejci | b479496 | 2017-09-21 14:16:28 +0200 | [diff] [blame] | 9 | selector: 'netopeer-config', |
| 10 | templateUrl: './config.component.html', |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 11 | styleUrls: ['../netopeer.css', './config.component.css', '../inventory/inventory.component.css'] |
Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 12 | }) |
| 13 | |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 14 | export class ConfigComponent implements OnInit, OnDestroy { |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 15 | title = 'Configuration'; |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 16 | activeSession: Session; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 17 | err_msg = ""; |
| 18 | |
| 19 | constructor(private sessionsService: SessionsService, private router: Router) {} |
| 20 | |
| 21 | addSession() { |
| 22 | this.router.navigateByUrl('/netopeer/inventory/devices'); |
| 23 | } |
| 24 | |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 25 | reloadData(key: string) { |
| 26 | this.activeSession.data = null; |
| 27 | this.rpcGet(key); |
| 28 | } |
| 29 | |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 30 | 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 Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 43 | if (this.activeSession.cpblts) { |
| 44 | return; |
| 45 | } |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 46 | this.sessionsService.getCpblts(key).subscribe(result => { |
| 47 | if (result['success']) { |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 48 | this.activeSession.cpblts = result['capabilities'] |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 49 | } else { |
| 50 | this.err_msg = result['error-msg'] |
| 51 | } |
| 52 | }); |
| 53 | } |
| 54 | |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 55 | 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 Krejci | 2e57856 | 2017-10-17 11:11:13 +0200 | [diff] [blame] | 108 | rpcGet(key: string) { |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 109 | if (this.activeSession.data) { |
| 110 | return; |
| 111 | } |
Radek Krejci | 2e57856 | 2017-10-17 11:11:13 +0200 | [diff] [blame] | 112 | this.sessionsService.rpcGet(key).subscribe(result => { |
| 113 | if (result['success']) { |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 114 | this.activeSession.data = result['data'] |
Radek Krejci | 2e57856 | 2017-10-17 11:11:13 +0200 | [diff] [blame] | 115 | } 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 Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 123 | ngOnInit(): void { |
| 124 | this.sessionsService.checkSessions(); |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 125 | this.activeSession = this.sessionsService.getActiveSession(this.sessionsService.activeSession); |
| 126 | } |
| 127 | |
| 128 | ngOnDestroy(): void { |
| 129 | this.sessionsService.changingView(); |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 130 | } |
Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 131 | } |