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 | |
Radek Krejci | 9b41f5b | 2018-01-31 14:17:50 +0100 | [diff] [blame^] | 4 | import {ModificationsService} from './modifications.service'; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 5 | import {SessionsService} from './sessions.service'; |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 6 | import {Session} from './session'; |
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 | cd1ebe1 | 2018-01-11 11:34:17 +0100 | [diff] [blame] | 11 | styleUrls: ['./config.component.scss'] |
Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 12 | }) |
| 13 | |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 14 | export class ConfigComponent implements OnInit { |
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 = ""; |
Radek Krejci | 4990494 | 2018-01-29 13:32:11 +0100 | [diff] [blame] | 18 | loading = false; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 19 | |
Radek Krejci | 9b41f5b | 2018-01-31 14:17:50 +0100 | [diff] [blame^] | 20 | constructor(private sessionsService: SessionsService, |
| 21 | private modsService: ModificationsService, |
| 22 | private router: Router) {} |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 23 | |
| 24 | addSession() { |
| 25 | this.router.navigateByUrl('/netopeer/inventory/devices'); |
| 26 | } |
| 27 | |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 28 | reloadData() { |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 29 | this.activeSession.data = null; |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 30 | if (this.activeSession.dataVisibility == 'all') { |
| 31 | this.rpcGet(true); |
| 32 | } else if(this.activeSession.dataVisibility == 'root') { |
| 33 | this.rpcGet(false); |
| 34 | } |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 35 | } |
| 36 | |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 37 | disconnect(key: string) { |
| 38 | this.sessionsService.close(key).subscribe(result => { |
| 39 | if (result['success']) { |
| 40 | if (!this.sessionsService.activeSession) { |
| 41 | this.router.navigateByUrl('/netopeer/inventory/devices'); |
| 42 | } |
Radek Krejci | fb0c046 | 2018-01-26 10:01:12 +0100 | [diff] [blame] | 43 | this.activeSession = this.sessionsService.getActiveSession(); |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 44 | } else { |
| 45 | this.err_msg = result['error-msg']; |
| 46 | } |
| 47 | }); |
| 48 | } |
| 49 | |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 50 | setCpbltsVisibility(value: boolean) { |
| 51 | this.activeSession.cpbltsVisibility = value; |
| 52 | this.sessionsService.storeData(); |
| 53 | } |
| 54 | |
| 55 | setDataVisibility(value: string) { |
| 56 | this.activeSession.dataVisibility = value; |
| 57 | this.sessionsService.storeData(); |
| 58 | } |
| 59 | |
| 60 | invertStatus() { |
| 61 | this.activeSession.statusVisibility = !this.activeSession.statusVisibility; |
| 62 | this.sessionsService.storeData(); |
| 63 | } |
| 64 | |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 65 | getCapabilities(key: string) { |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 66 | if (this.activeSession.cpblts) { |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 67 | this.activeSession.cpbltsVisibility = true; |
| 68 | this.sessionsService.storeData(); |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 69 | return; |
| 70 | } |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 71 | this.sessionsService.getCpblts(key).subscribe(result => { |
| 72 | if (result['success']) { |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 73 | this.activeSession.cpblts = result['capabilities']; |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 74 | this.activeSession.cpbltsVisibility = true; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 75 | } else { |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 76 | this.activeSession.cpbltsVisibility = false; |
| 77 | this.err_msg = result['error-msg']; |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 78 | } |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 79 | this.sessionsService.storeData(); |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 80 | }); |
| 81 | } |
| 82 | |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 83 | parseCapabilityName(cpblt: string): string { |
| 84 | let name = cpblt; |
| 85 | let pos = cpblt.search('module='); |
| 86 | if (pos != -1) { |
| 87 | /* schema */ |
| 88 | pos += 7; |
| 89 | name = cpblt.slice(pos); |
| 90 | let end = name.search('&'); |
| 91 | if (end != -1) { |
| 92 | name = name.slice(0, end); |
| 93 | } |
| 94 | } else { |
| 95 | /* capability */ |
| 96 | pos = 0; |
| 97 | if (cpblt.match('urn:ietf:params:netconf:capability:*')) { |
| 98 | pos = 34; |
| 99 | } else if (cpblt.match('urn:ietf:params:netconf:*')) { |
| 100 | pos = 23; |
| 101 | } |
| 102 | name = cpblt.slice(pos); |
| 103 | |
| 104 | let end = name.search('\\?'); |
| 105 | if (end != -1) { |
| 106 | name = name.slice(0, end); |
| 107 | } |
| 108 | pos = name.lastIndexOf(':') |
| 109 | name = name.slice(0, pos); |
| 110 | } |
| 111 | return name; |
| 112 | } |
| 113 | |
| 114 | parseCapabilityRevision(cpblt: string): string { |
| 115 | let version = ""; |
| 116 | let pos = cpblt.search('revision='); |
| 117 | if (pos != -1) { |
| 118 | pos += 9; |
| 119 | version = cpblt.slice(pos); |
| 120 | let end = version.search('&'); |
| 121 | if (end != -1) { |
| 122 | version = version.slice(0, end); |
| 123 | } |
| 124 | return version; |
| 125 | } else if (cpblt.match('urn:ietf:params:netconf:*')) { |
| 126 | let end = cpblt.search('\\?'); |
| 127 | if (end != -1) { |
| 128 | cpblt = cpblt.slice(0, end); |
| 129 | } |
| 130 | pos = cpblt.lastIndexOf(':') |
| 131 | version = cpblt.slice(pos + 1); |
| 132 | } |
| 133 | return version; |
| 134 | } |
| 135 | |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 136 | rpcGet(all: boolean) { |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 137 | if (this.activeSession.data) { |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 138 | if ((all && this.activeSession.dataVisibility == 'all') || |
| 139 | (!all && this.activeSession.dataVisibility == 'root')) { |
| 140 | return; |
| 141 | } |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 142 | } |
Radek Krejci | 4990494 | 2018-01-29 13:32:11 +0100 | [diff] [blame] | 143 | this.loading = true; |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 144 | this.sessionsService.rpcGetSubtree(this.activeSession.key, all).subscribe(result => { |
Radek Krejci | 2e57856 | 2017-10-17 11:11:13 +0200 | [diff] [blame] | 145 | if (result['success']) { |
Radek Krejci | 9b41f5b | 2018-01-31 14:17:50 +0100 | [diff] [blame^] | 146 | for (let iter of result['data']) { |
| 147 | this.modsService.setDirty(this.activeSession, iter); |
| 148 | } |
| 149 | this.activeSession.data = {}; |
| 150 | this.activeSession.data['path'] = '/'; |
| 151 | this.activeSession.data['info'] = {}; |
| 152 | this.activeSession.data['info']['path'] = '/'; |
| 153 | this.activeSession.data['children'] = result['data']; |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 154 | if (all) { |
| 155 | this.activeSession.dataVisibility = 'all'; |
| 156 | } else { |
| 157 | this.activeSession.dataVisibility = 'root'; |
| 158 | } |
Radek Krejci | 9b41f5b | 2018-01-31 14:17:50 +0100 | [diff] [blame^] | 159 | console.log(this.activeSession.data); |
Radek Krejci | 2e57856 | 2017-10-17 11:11:13 +0200 | [diff] [blame] | 160 | } else { |
Radek Krejci | a133960 | 2017-11-02 13:52:38 +0100 | [diff] [blame] | 161 | this.activeSession.dataVisibility = 'none'; |
| 162 | if ('error-msg' in result) { |
| 163 | this.err_msg = result['error-msg']; |
| 164 | } else { |
| 165 | this.err_msg = result['error'][0]['message']; |
| 166 | } |
Radek Krejci | 2e57856 | 2017-10-17 11:11:13 +0200 | [diff] [blame] | 167 | } |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 168 | this.sessionsService.storeData(); |
Radek Krejci | 4990494 | 2018-01-29 13:32:11 +0100 | [diff] [blame] | 169 | this.loading = false; |
Radek Krejci | 2e57856 | 2017-10-17 11:11:13 +0200 | [diff] [blame] | 170 | }); |
| 171 | } |
Radek Krejci | 6e772b2 | 2018-01-25 13:28:57 +0100 | [diff] [blame] | 172 | |
Radek Krejci | 26bf2bc | 2018-01-09 15:00:54 +0100 | [diff] [blame] | 173 | cancelChanges() { |
Radek Krejci | 2ca11ba | 2018-01-26 11:25:42 +0100 | [diff] [blame] | 174 | //console.log(JSON.stringify(this.activeSession.modifications)) |
Radek Krejci | 9b41f5b | 2018-01-31 14:17:50 +0100 | [diff] [blame^] | 175 | this.modsService.cancelModification(this.activeSession); |
Radek Krejci | 26bf2bc | 2018-01-09 15:00:54 +0100 | [diff] [blame] | 176 | this.sessionsService.storeData(); |
Radek Krejci | 2ca11ba | 2018-01-26 11:25:42 +0100 | [diff] [blame] | 177 | //console.log(JSON.stringify(this.activeSession.modifications)) |
Radek Krejci | 26bf2bc | 2018-01-09 15:00:54 +0100 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | applyChanges() { |
| 181 | /* TODO */ |
| 182 | this.cancelChanges(); |
| 183 | } |
Radek Krejci | 6e772b2 | 2018-01-25 13:28:57 +0100 | [diff] [blame] | 184 | |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 185 | ngOnInit(): void { |
| 186 | this.sessionsService.checkSessions(); |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 187 | this.activeSession = this.sessionsService.getActiveSession(); |
Radek Krejci | ae75839 | 2017-10-20 10:53:26 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Radek Krejci | b424acd | 2017-10-20 11:36:46 +0200 | [diff] [blame] | 190 | changeActiveSession(key: string) { |
Radek Krejci | 77f7720 | 2017-11-03 15:33:50 +0100 | [diff] [blame] | 191 | this.activeSession = this.sessionsService.changeActiveSession(key); |
Radek Krejci | 95bd14c | 2017-09-21 14:24:13 +0200 | [diff] [blame] | 192 | } |
Radek Krejci | d23f0df | 2017-08-31 16:34:49 +0200 | [diff] [blame] | 193 | } |