import {css, html, LitElement} from 'lit';
import {customElement, property} from 'lit/decorators.js';
@customElement('netsim-app')
export class NetsimApp extends LitElement {
/**
* The view of the netsim app: main (map view), trace (packet trace view)
*/
@property() viewMode: string = 'main';
/**
* The version of netsim.
*/
@property() version: string = '';
static styles = css`
.container {
display: flex;
width: 100%;
}
.contentA {
flex: 2;
}
.contentB {
flex: 2;
}
#bottom {
position: relative;
bottom: 0;
left: 0;
font-size: 20px;
}
`;
constructor() {
super();
this.invokeGetVersion();
}
invokeGetVersion() {
fetch('./version', {
method: 'GET',
})
.then(response => response.json())
.then(data => {
this.version = data.version;
})
.catch(error => {
// eslint-disable-next-line
console.log('Cannot connect to netsim web server', error);
});
}
connectedCallback() {
super.connectedCallback();
window.addEventListener('changeModeEvent', this.handleChangeModeEvent);
window.addEventListener('reset-button-clicked', this.handleReset);
window.addEventListener('bumble-button-clicked', this.handleBumbleHive);
}
disconnectedCallback() {
window.removeEventListener('bumble-button-clicked', this.handleBumbleHive);
window.removeEventListener('reset-button-clicked', this.handleReset);
window.removeEventListener('changeModeEvent', this.handleChangeModeEvent);
super.disconnectedCallback();
}
handleChangeModeEvent = (e: Event) => {
const {detail} = (e as CustomEvent);
this.viewMode = detail.mode;
};
handleReset() {
fetch('./v1/devices', {
method: 'PUT',
}).catch(error => {
console.log('Cannot connect to netsim web server:', error);
})
};
handleBumbleHive() {
window.open('https://google.github.io/bumble/hive/index.html', '_blank');
}
render() {
let page = html``;
if (this.viewMode === 'main') {
page = html`