Commit f028b6e7 authored by janis.streib's avatar janis.streib 🦉
Browse files

UPD: new macfinder logic

parent e45a8815
......@@ -149,8 +149,6 @@ components:
description: hostname of device
mac:
type: string
nd_p_port:
$ref: '#/components/schemas/nd_p_port'
port:
type: string
description: Port name
......@@ -166,63 +164,6 @@ components:
started:
type: string
description: ISO date
nd_p_port:
type: object
properties:
module:
$ref: '#/components/schemas/module'
name:
type: string
module:
type: object
properties:
building:
$ref: '#/components/schemas/building'
description:
type: string
floor:
$ref: '#/components/schemas/floor'
module_type:
$ref: '#/components/schemas/module_type'
name:
type: string
room:
$ref: '#/components/schemas/room'
root_module:
$ref: '#/components/schemas/module'
room:
type: object
properties:
name:
type: string
nr:
type: string
building:
type: object
properties:
name:
type: string
nr:
type: string
floor:
type: object
properties:
description:
type: string
nr:
type: string
module_type:
type: object
properties:
name:
type: string
type_class:
$ref: '#/components/schemas/module_type_class'
module_type_class:
type: object
properties:
name:
type: string
oui_result:
type: object
properties:
......
import Axios from 'axios'
export default {
getJobs() {
return Axios.get('/api/macfinder/jobs')
pollJob(config, job) {
return Axios.get('/api/macfinder/job/' + job, config)
},
createJob(bcd, mac) {
return Axios.post('/api/macfinder/create_job', { bcd: bcd, mac: mac })
createJob(config, bcd, mac) {
return Axios.post('/api/macfinder/job', { bcd: bcd, mac: mac }, config)
},
ouiLookup(mac) {
return Axios.get('/api/macfinder/oui_lookup?mac=' + mac)
......
......@@ -97,9 +97,14 @@ async function init() {
reload_count: 0,
db_editor_cache: JSON.parse(window.localStorage.getItem('db_editor_cache')) || {},
db_editor_data_type_cache: data_types,
expert: JSON.parse(window.localStorage.getItem('expert')) || false
expert: JSON.parse(window.localStorage.getItem('expert')) || false,
macfinder_jobs: JSON.parse(window.localStorage.getItem('macfinder_jobs')) || []
},
mutations: {
newMacfinderJob(state, payload) {
state.macfinder_jobs.push(payload)
window.localStorage.setItem('macfinder_jobs', JSON.stringify(state.macfinder_jobs))
},
toggle_expert(state) {
state.expert = !state.expert
window.localStorage.setItem('expert', JSON.stringify(state.expert))
......@@ -167,6 +172,7 @@ async function init() {
state.transaction_result = null
state.executing_transaction = false
state.show_sidebar_right = false
state.macfinder_jobs = []
window.localStorage.removeItem('done')
window.localStorage.removeItem('undone')
window.localStorage.removeItem('undo_redo_new_mutation')
......@@ -175,6 +181,7 @@ async function init() {
window.localStorage.removeItem('executing_transaction')
window.localStorage.removeItem('show_sidebar_right')
window.localStorage.removeItem('db_editor_cache')
window.localStorage.removeItem('macfinder_jobs')
state.netdb_axios_config = {
headers: {
Authorization: null,
......@@ -316,7 +323,9 @@ async function init() {
'setTransactionBusy',
'moveTaElements',
'replaceTransactionList',
'setTransactionResult'
'setTransactionResult',
'newMacfinderJob',
'toggle_expert'
]
}
)
......
......@@ -35,12 +35,6 @@
<ul>
<li v-for="res in data.item.status.result" v-bind:key="res.host + res.port">
Switch <code>{{ res.host }}</code>, Port <code>{{ res.port }}</code>
<p><a target="_blank" :href="'https://www.kit.edu/campusplan/index.php?id='+res.nd_p_port.module.root_module.building.nr">{{ res.nd_p_port.module.root_module.building.name }}
({{ res.nd_p_port.module.root_module.building.nr }})</a>,
{{ res.nd_p_port.module.root_module.floor.nr }},
{{ res.nd_p_port.module.root_module.room.name }} ({{ res.nd_p_port.module.root_module.room.nr }})
</p>
<p>Root-Modul: <code>{{ res.nd_p_port.module.root_module.name }}</code> ({{ res.nd_p_port.module.root_module.module_type.name }})</p>
</li>
</ul>
</template>
......@@ -54,18 +48,21 @@
</template>
</template>
<template v-slot:cell(actions)="data">
<b-button :id="'refire_'+data.item.job_id" variant="outline-primary" @click="refire(data.item.bcd, data.item.mac)"><font-awesome-icon icon="sync"></font-awesome-icon></b-button>
<b-button :id="'refire_'+data.item.job_id" variant="outline-primary"
@click="refire(data.item.bcd, data.item.mac)">
<font-awesome-icon icon="sync"></font-awesome-icon>
</b-button>
<b-tooltip :target="'refire_'+data.item.job_id" triggers="hover"
variant="primary" placement="left">
Erneut suchen
</b-tooltip>
</template>
<template v-slot:cell(started)="data">
{{ (new Date(data.item.started)).toLocaleDateString()}}
{{ (new Date(data.item.started)).toLocaleTimeString()}}
{{ (new Date(data.item.started)).toLocaleDateString() }}
{{ (new Date(data.item.started)).toLocaleTimeString() }}
</template>
<template v-slot:cell(bcd)="data">
<b-button variant="link" :to="'/dnsvs/bcds/'+data.item.bcd">{{data.item.bcd}}</b-button>
<b-button variant="link" :to="'/dnsvs/bcds/'+data.item.bcd">{{ data.item.bcd }}</b-button>
</template>
</b-table>
</div>
......@@ -121,28 +118,38 @@ export default {
},
async refresh() {
try {
const jobs = await MACfinderService.getJobs()
const jobs = this.$store.state.macfinder_jobs
const jq = []
for (const job of jobs) {
jq.push(MACfinderService.pollJob(this.$store.state.netdb_axios_config, job))
}
const res = await Promise.all(jq)
this.jobs = []
for (const job in jobs.data.jobs) {
this.jobs.push(jobs.data.jobs[job])
for (const r of res) {
this.jobs.push(r.data)
}
} catch (e) {
window.console.log('Error on poll. Ignore')
}
},
async fireJob(bcd, mac) {
const jobs = await MACfinderService.createJob(this.$store.state.netdb_axios_config, bcd, mac)
for (const j of jobs.data.job_ids) {
this.$store.commit('newMacfinderJob', j)
}
await this.refresh()
},
async createJob(ev) {
ev.preventDefault()
if (!this.search_bcd) {
return false
}
await MACfinderService.createJob(this.search_bcd.name, this.search_mac)
await this.refresh()
await this.fireJob(this.search_bcd.name, this.search_mac)
this.search_mac = this.bcd_query = ''
return true
},
async refire(bcd, mac) {
await MACfinderService.createJob(bcd, mac)
await this.refresh()
await this.fireJob(bcd, mac)
},
async getBCDs(bcd) {
const res = await SearchService.searchBCDRegex(this.$store.state.netdb_axios_config, bcd, null)
......@@ -151,7 +158,7 @@ export default {
pollData() {
this.poller = setInterval(() => {
this.refresh()
}, 3000)
}, 40000)
}
},
watch: {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment