first initial working link for ptp and joining back and drawing the edge, also making use of old core icons to provide a basic look and feel, updated coloring to dark mode instead of info, seems to fit better
This commit is contained in:
parent
b10c7fe502
commit
8e99af96a4
18 changed files with 1414 additions and 45 deletions
|
@ -1,9 +1,106 @@
|
|||
const SessionStates = {
|
||||
definition: 1,
|
||||
configuration: 2,
|
||||
instantiation: 3,
|
||||
runtime: 4,
|
||||
dataCollect: 5,
|
||||
shutdown: 6
|
||||
};
|
||||
|
||||
const SessionStateDisplay = {
|
||||
1: 'Definition',
|
||||
2: 'Configuration',
|
||||
3: 'Instantiation',
|
||||
4: 'Runtime',
|
||||
5: 'Data Collect',
|
||||
6: 'Shutdown'
|
||||
};
|
||||
|
||||
async function sendJson(url, data, type) {
|
||||
return await $.ajax({
|
||||
url,
|
||||
type,
|
||||
data: JSON.stringify(data),
|
||||
contentType: 'application/json',
|
||||
dataType: 'json'
|
||||
});
|
||||
}
|
||||
|
||||
async function postJson(url, data) {
|
||||
console.log('POST: ', url);
|
||||
return await sendJson(url, data, 'POST');
|
||||
}
|
||||
|
||||
async function putJson(url, data) {
|
||||
console.log('PUT: ', url);
|
||||
return await sendJson(url, data, 'PUT');
|
||||
}
|
||||
|
||||
class CoreRest {
|
||||
constructor() {
|
||||
this.currentSession = null;
|
||||
}
|
||||
|
||||
async sessions(callback) {
|
||||
const response = await $.getJSON('/sessions');
|
||||
callback(response);
|
||||
getStateName(state) {
|
||||
return SessionStateDisplay[state];
|
||||
}
|
||||
|
||||
async getSession() {
|
||||
return await $.getJSON(`/sessions/${this.currentSession}`);
|
||||
}
|
||||
|
||||
async getSessions() {
|
||||
return await $.getJSON('/sessions');
|
||||
}
|
||||
|
||||
async createSession() {
|
||||
return await postJson('/sessions');
|
||||
}
|
||||
|
||||
async shutdownSession() {
|
||||
return await this.setSessionState(SessionStates.shutdown);
|
||||
}
|
||||
|
||||
async setSessionState(state) {
|
||||
return await putJson(`/sessions/${this.currentSession}/state`, {state})
|
||||
}
|
||||
|
||||
async createNode(node) {
|
||||
return await postJson(`/sessions/${this.currentSession}/nodes`, node);
|
||||
}
|
||||
|
||||
async createLink(link) {
|
||||
return await postJson(`/sessions/${this.currentSession}/links`, link);
|
||||
}
|
||||
|
||||
async getLinks(nodeId) {
|
||||
return await $.getJSON(`/sessions/${this.currentSession}/nodes/${nodeId}/links`)
|
||||
}
|
||||
|
||||
async getNodeIps(nodeId, ip4Prefix, ip6Prefix) {
|
||||
return await postJson('/ips', {
|
||||
id: nodeId,
|
||||
ip4: ip4Prefix,
|
||||
ip6: ip6Prefix
|
||||
});
|
||||
}
|
||||
|
||||
async retrieveSession() {
|
||||
let response = await this.getSessions();
|
||||
const sessions = response.sessions;
|
||||
console.log('current sessions: ', sessions);
|
||||
const session = {id: 0, state: 0};
|
||||
|
||||
if (sessions.length) {
|
||||
this.currentSession = sessions[0].id;
|
||||
session.state = sessions[0].state;
|
||||
} else {
|
||||
response = await this.createSession();
|
||||
this.currentSession = response.id;
|
||||
session.state = response.state;
|
||||
}
|
||||
|
||||
session.id = this.currentSession;
|
||||
return session;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue