From 1d65f8f056733402c671878b0804583d9e7a1e1c Mon Sep 17 00:00:00 2001 From: Janis Streib <me@janis-streib.de> Date: Wed, 11 Nov 2020 17:10:19 +0100 Subject: [PATCH] ADD: search by vlan (closes #157) --- frontend/src/api-services/search.service.js | 12 ++++++ frontend/src/components/GlobalSearch.vue | 42 ++++++++++++++++++++- frontend/src/icons.js | 6 ++- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/frontend/src/api-services/search.service.js b/frontend/src/api-services/search.service.js index 309de93ee..a336db593 100644 --- a/frontend/src/api-services/search.service.js +++ b/frontend/src/api-services/search.service.js @@ -65,6 +65,18 @@ export default { ] return TransactionService.execute(config, ta) }, + searchVlan(config, term) { + const ta = [ + { + name: 'nd.vlan.list', + old: apiutil.denullify_dict({ + id: term, + fetch_limit: 20 + }) + } + ] + return TransactionService.execute(config, ta) + }, searchBCDSubnet(config, term, own) { const ta = [ { diff --git a/frontend/src/components/GlobalSearch.vue b/frontend/src/components/GlobalSearch.vue index 50e68ff45..5fade8ef2 100644 --- a/frontend/src/components/GlobalSearch.vue +++ b/frontend/src/components/GlobalSearch.vue @@ -148,6 +148,7 @@ export default { this.search_res.forEach(item => { let index = -1 let record_composit = null + let compiled_term = null switch (item.type.toLowerCase()) { case 'dns.record': record_composit = item.term.fqdn + ' IN ' + item.term.type + ' ' + item.term.data @@ -231,6 +232,35 @@ export default { } } break + case 'nd.vlan': + compiled_term = item.term.name + ' (' + item.term.id + '@' + item.term.net_instnc + ')' + if (isRegex) { + suggestions.push({ + name: + ['', + compiled_term, + '' + ], + type: item.type, + url: '/dnsvs/bcds/' + item.term.bcd + }) + } else { + index = compiled_term.toLowerCase().indexOf(search.toLowerCase()) + if (index !== -1) { + suggestions.push({ + name: + [compiled_term.substring(0, index), + compiled_term + .substring(index, index + search.length), + compiled_term + .substring(index + search.length) + ], + type: item.type, + url: '/dnsvs/bcds/' + item.term.bcd + }) + } + } + break } }) return suggestions @@ -244,6 +274,9 @@ export default { if (type.startsWith('dns.')) { return 'map-signs' } + if (type === 'nd.vlan') { + return 'ethernet' + } if (type.startsWith('nd.')) { return 'network-wired' } @@ -313,8 +346,11 @@ export default { this.descriminator = this.getSearchDiscriminator() const term = this.cutDescriminator().trim() const termIsIP = ipaddress.isValid(term.split('/')[0]) + const termIsNumeric = !isNaN(parseInt(term)) if (this.descriminator == null) { // Nur is_own, ohne regex - if (termIsIP) { + if (termIsNumeric) { + this.dispatch_search(SearchService.searchVlan(this.$store.state.netdb_axios_config, parseInt(term)), 'nd.vlan') + } else if (termIsIP) { this.dispatch_search(SearchService.searchRRByIP(this.$store.state.netdb_axios_config, term, true), 'dns.record') this.dispatch_search(SearchService.searchBCDSubnet(this.$store.state.netdb_axios_config, term, true), 'nd.ip_subnet') } else { @@ -322,7 +358,9 @@ export default { this.dispatch_search(SearchService.searchRecordRegex(this.$store.state.netdb_axios_config, term, true), 'dns.record') } } else if (this.descriminator === 'dnsvs') { - if (termIsIP) { + if (termIsNumeric) { + this.dispatch_search(SearchService.searchVlan(this.$store.state.netdb_axios_config, parseInt(term)), 'nd.vlan') + } else if (termIsIP) { this.dispatch_search(SearchService.searchRRByIP(this.$store.state.netdb_axios_config, term, null), 'dns.record') this.dispatch_search(SearchService.searchBCDSubnet(this.$store.state.netdb_axios_config, term, null), 'nd.ip_subnet') } else { diff --git a/frontend/src/icons.js b/frontend/src/icons.js index 514c65601..09dde85a9 100644 --- a/frontend/src/icons.js +++ b/frontend/src/icons.js @@ -46,7 +46,8 @@ import { faRadiation, faMapSigns, faNetworkWired, - faHistory + faHistory, + faEthernet } from '@fortawesome/free-solid-svg-icons' import { @@ -113,5 +114,6 @@ library.add( faRadiation, faMapSigns, faNetworkWired, - faHistory + faHistory, + faEthernet ) -- GitLab