xtr-improved-frontend/src/StatusBox.vue

351 lines
9.0 KiB
Vue
Raw Normal View History

2019-11-20 22:45:03 +01:00
<template>
<div id="statusBox">
<div class="row">
<div class="col-4">
2019-12-05 23:48:29 +01:00
<select :ref="'serverSelectBox' + 1" v-if="pending === false" v-model="selectedServerData" id="serverSelectList">
2019-11-20 22:45:03 +01:00
<option v-for="(serverItem, index) in serverlist"
v-bind:value="serverItem"
>
2019-12-05 23:48:29 +01:00
{{serverItem.getLabelInfoString()}}
2019-11-20 22:45:03 +01:00
</option>
</select>
<input v-model="target" placeholder="Enter Ip or Domain">
<button v-on:click="handleClick()">
</button>
<RingLoader :size="10" :loading="isLoading" color="black"></RingLoader>
<br>
2019-12-06 20:02:01 +01:00
2019-12-05 23:48:29 +01:00
<span class="small">{{infoString}}</span>
2019-11-20 22:45:03 +01:00
<div>
<table :id="'tableId_'+boxNumber" class="table table-striped">
<thead>
<tr>
<td>IP</td>
<td>HOSTNAME</td>
<td>PING</td>
<td>AS</td>
</tr>
2019-12-05 23:48:29 +01:00
<tr :class="isOdd(index)" v-for="(tData, index) in tableData">
2019-11-20 22:45:03 +01:00
<td>{{ tData[0] }}</td>
<td>{{ tData[1] }}</td>
<td>{{ tData[2] }}</td>
<td :title="tData[4]">{{ tData[3] }}</td>
</tr>
</thead>
</table>
2019-12-05 23:48:29 +01:00
<input class="range" v-model="tick" type="range" v-if="tableDataHistory.length > 1" :max="tableDataHistory.length -1" min="0" :list="'tickmarks'+_uid">
<datalist :id="'tickmarks'+_uid">
<option v-for="(historyItem, index) in tableDataHistory"
:value="index"
>
</option>
</datalist>
2019-11-20 22:45:03 +01:00
</div>
</div>
</div>
</div>
</template>
<script>
import axios from 'axios';
2019-12-05 23:48:29 +01:00
import XtrServer from './ModelObjects/XtrServer.js';
import XtrData from './ModelObjects/XtrData.js';
import { RingLoader } from 'vue-spinners-css';
2019-11-20 22:45:03 +01:00
export default {
2019-12-06 20:02:01 +01:00
components: {
RingLoader
2019-12-06 20:02:01 +01:00
},
2019-11-20 22:45:03 +01:00
props: {
serverlist: Array,
2019-12-05 23:48:29 +01:00
pending: Boolean,
boxNumber: Number,
initData: XtrServer
},
data : function () {
return {
2019-12-06 20:02:01 +01:00
isLoading: false,
2019-12-05 23:48:29 +01:00
executionTime: 'Not execute yet',
selectedServerData: this.initData,
tick: '',
target: 'luan.xicon.eu',
tableData : [ ],
tableDataHistory: [],
2019-12-06 20:02:01 +01:00
tableDataHistoryObject: [],
jobCount: 0,
jobList: []
2019-12-05 23:48:29 +01:00
}
2019-11-20 22:45:03 +01:00
},
watch: {
2019-12-05 23:48:29 +01:00
pending : {
handler() {
if(this.pending === false
&& this.serverlist.length > 0
&& !(JSON.parse(sessionStorage.getItem(this.selectedServerDataIndex)))
) {
this.selectedServerData = this.serverlist[0];
}
}
},
tableDataHistory : {
2019-11-20 22:45:03 +01:00
handler() {
sessionStorage.setItem('tableDataHistory' + this.boxNumber, JSON.stringify(this.tableDataHistory));
2019-12-05 23:48:29 +01:00
// Restore history data and set the marker to the last range item
this.tick = this.tableDataHistory.length -1;
2019-11-20 22:45:03 +01:00
}
},
2019-12-05 23:48:29 +01:00
tableDataHistoryObject : {
handler() {
sessionStorage.setItem('tableDataHistoryObject' + this.boxNumber, JSON.stringify(this.tableDataHistoryObject));
// Restore history data and set the marker to the last range item
this.tick = this.tableDataHistoryObject.length -1;
},
deep: true
},
executionTime : {
2019-11-20 22:45:03 +01:00
handler() {
sessionStorage.setItem('executionTime' + this.boxNumber, JSON.stringify(this.executionTime));
},
deep: true
},
2019-12-05 23:48:29 +01:00
selectedServerData : {
2019-11-20 22:45:03 +01:00
handler() {
2019-12-05 23:48:29 +01:00
sessionStorage.setItem('selectedServerData' + this.boxNumber, JSON.stringify(this.selectedServerData));
2019-11-20 22:45:03 +01:00
},
deep: true
},
2019-12-05 23:48:29 +01:00
2019-11-20 22:45:03 +01:00
target : {
handler() {
sessionStorage.setItem('target' + this.boxNumber, JSON.stringify(this.target));
},
deep: true
},
2019-12-05 23:48:29 +01:00
2019-11-20 22:49:28 +01:00
tableData : {
2019-11-20 22:45:03 +01:00
handler() {
2019-12-05 23:48:29 +01:00
sessionStorage.setItem(this.tableDataIndex, JSON.stringify(this.tableData));
2019-11-20 22:45:03 +01:00
},
deep: true
2019-12-05 23:48:29 +01:00
},
tick : {
handler() {
sessionStorage.setItem(this.tickIndex, JSON.stringify(this.tick));
if(this.tableDataHistory.length > 0) {
this.tableData = this.tableDataHistory[this.tick];
}
}
}
},
computed : {
selectedServerDataIndex : function selectedServerDataIndex() {
return 'selectedServerData' + this.boxNumber;
},
tickIndex: function tickIndex() {
return 'tick' + this.boxNumber;
},
tableDataIndex : function tableDataIndex() {
return 'tableData' + this.boxNumber;
},
infoString : function infoString() {
var obData = this.tableDataHistoryObject[this.tick];
if(typeof(obData) !== "undefined" && obData !== null){
return obData.displayInfo();
} else {
return '';
}
},
tryHard : function tryHard() {
if (this.selectedServerData) {
} else {
this.selectedServerData = this.initData;
}
2019-11-20 22:45:03 +01:00
}
},
2019-12-05 23:48:29 +01:00
methods : {
isOdd : function isOdd(index) {
if(index % 2 === 0) {
return 'odd';
} else {
return 'even';
}
},
2019-12-06 20:02:01 +01:00
handleClick: function handleClick() {
this.traceRoute();
},
2019-12-05 23:48:29 +01:00
setLastExecutionTime : function setLastExecutionTime() {
2019-11-20 22:45:03 +01:00
var day = new Date();
2019-12-06 00:48:41 +01:00
this.executionTime = day.toISOString()
2019-11-20 22:45:03 +01:00
},
2019-12-05 23:48:29 +01:00
traceRoute : function traceRoute() {
2019-12-06 20:02:01 +01:00
this.isLoading = true;
let jobId = this.getJobCount;
this.jobList.push(jobId);
2019-11-20 22:45:03 +01:00
// e.g. http://199.247.22.146:12111/v3/client/request/8.8.8.8
2019-12-05 23:48:29 +01:00
axios.get("http://" + this.selectedServerData.getIpPortAsString() + "/v3/client/request/" + this.target)
2019-11-20 22:45:03 +01:00
.then(response => {
// JSON responses are automatically parsed.
2019-11-20 22:49:28 +01:00
this.tableData = response.data;
2019-11-20 22:45:03 +01:00
this.setLastExecutionTime();
2019-11-20 22:49:28 +01:00
this.tableDataHistory.push(this.tableData);
2019-12-05 23:48:29 +01:00
this.tick = this.tableDataHistory.length -1;
var xtrData = new XtrData();
xtrData.initObjectByElements(this.selectedServerData, this.executionTime , this.tableData ,this.target);
this.tableDataHistoryObject.push(xtrData);
2019-11-20 22:45:03 +01:00
})
.catch(e => {
if(e.response !== undefined) {
// JSON responses are automatically parsed.
this.tableData = {0 : {
0: "Status-Code: HTTP/" + e.response.status,
1: "Message: " + e.response.statusText,
2: "",
3: "",
4: ""
}};
this.setLastExecutionTime();
this.tableDataHistory.push(this.tableData);
this.tick = this.tableDataHistory.length -1;
var xtrData = new XtrData();
xtrData.initObjectByElements(this.selectedServerData, this.executionTime , this.tableData ,this.target);
this.tableDataHistoryObject.push(xtrData);
}
2019-12-06 20:02:01 +01:00
}).finally(ee => {
var position = this.jobList.indexOf(jobId);
if(~position) {
this.jobList.splice(position, 1);
}
if(this.jobList.length < 1) {
this.jobCount = 0;
this.isLoading = false;
}
});
2019-11-20 22:45:03 +01:00
},
2019-12-05 23:48:29 +01:00
2019-12-06 20:02:01 +01:00
getJobCount : function getJobCount() {
this.jobCount += 1;
return this.jobCount;
},
2019-12-05 23:48:29 +01:00
resetData : function resetData() {
this.executionTime = 'Not execute yet';
this.target = 'luan.xicon.eu';
this.tableData = [ ];
this.tableDataHistory = [ ];
this.tableDataHistoryObject = [ ];
this.selectedServerData = this.serverlist[0];
this.tick = '';
2019-11-20 22:45:03 +01:00
}
},
mounted() {
2019-12-05 23:48:29 +01:00
if (sessionStorage.getItem('tableDataHistory'+ this.boxNumber)) this.tableDataHistory = JSON.parse(sessionStorage.getItem('tableDataHistory'+ this.boxNumber));
if (sessionStorage.getItem('tick'+ this.boxNumber)) this.tick = parseInt(sessionStorage.getItem('tick'+ this.boxNumber));
2019-11-20 22:45:03 +01:00
if (sessionStorage.getItem('executionTime'+ this.boxNumber)) this.executionTime = JSON.parse(sessionStorage.getItem('executionTime'+ this.boxNumber));
2019-12-05 23:48:29 +01:00
if (sessionStorage.getItem('tableDataHistoryObject'+ this.boxNumber)) {
var manA = JSON.parse(sessionStorage.getItem('tableDataHistoryObject'+ this.boxNumber));
manA.forEach(element => {
var restoreData = new XtrData();
var restoreServer = new XtrServer();
restoreServer.initObjectByJson(element._requestServer);
restoreData.initObjectByElements(restoreServer, element._requestSendTime, element._responseData, element._targetUrl);
this.tableDataHistoryObject.push(restoreData);
});
}
if (sessionStorage.getItem('selectedServerData'+ this.boxNumber)) {
var restoreData = new XtrServer();
var man = JSON.parse(sessionStorage.getItem('selectedServerData'+ this.boxNumber))
restoreData.initObjectByJson(man);
this.selectedServerData = restoreData;
2019-11-20 22:45:03 +01:00
}
if (sessionStorage.getItem('target'+ this.boxNumber)) this.target = JSON.parse(sessionStorage.getItem('target'+ this.boxNumber));
2019-11-20 22:49:28 +01:00
if (sessionStorage.getItem('tableData'+ this.boxNumber)) this.tableData = JSON.parse(sessionStorage.getItem('tableData'+ this.boxNumber));
2019-11-20 22:45:03 +01:00
}
}
</script>
<style scoped>
2019-12-05 23:48:29 +01:00
input[type=range] {
width: 90%;
display: flex;
flex-direction: column;
align-items: stretch;
}
2019-11-20 22:45:03 +01:00
span.small {
font-size: 75%;
}
table.active {
border: 3px solid #9ac5e3;
}
table {
border-collapse: collapse;
width: 90%;
}
2019-12-05 23:48:29 +01:00
td {
2019-11-20 22:45:03 +01:00
border:1px solid grey;
font-size: 9pt;
}
2019-12-05 23:48:29 +01:00
.traceroutes {
2019-11-20 22:45:03 +01:00
text-decoration: none;
display: inline-block;
}
2019-12-05 23:48:29 +01:00
.traceroutes:visited {
2019-11-20 22:45:03 +01:00
color: #000000;
}
2019-12-05 23:48:29 +01:00
.traceroutes:hover {
2019-11-20 22:45:03 +01:00
color: #880000;
transform: rotate(-30deg);
}
2019-12-05 23:48:29 +01:00
.traceroutes:active {
2019-11-20 22:45:03 +01:00
color: #bb0000;
}
2019-12-05 23:48:29 +01:00
.traceroutes_rotating {
2019-11-20 22:45:03 +01:00
display: inline-block;
text-decoration: none;
color: #bb0000;
animation: spin 2s linear infinite;
}
2019-12-05 23:48:29 +01:00
.odd {
background-color: #EEE;
}
@keyframes spin {
2019-11-20 22:45:03 +01:00
0% { transform: rotate(-30deg); }
25% { transform: rotate(0deg); }
50% { transform: rotate(30deg); }
75% { transform: rotate(0deg); }
100% { transform: rotate(-30deg); }
}
2019-11-20 22:45:03 +01:00
</style>