2020-07-14 15:03:14 +00:00
|
|
|
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
import CustomIcProcessor from "./ic-processor.mjs";
|
2020-07-23 06:37:37 +00:00
|
|
|
import {State} from './app-model.mjs';
|
2020-07-14 15:03:14 +00:00
|
|
|
import {MapProcessor} from './map-processor.mjs';
|
|
|
|
import './ic-panel.mjs';
|
|
|
|
import './timeline-panel.mjs';
|
|
|
|
import './map-panel.mjs';
|
|
|
|
import './log-file-reader.mjs';
|
2020-07-16 10:02:52 +00:00
|
|
|
class App {
|
2020-07-24 13:51:36 +00:00
|
|
|
#timeSelection = {start: 0, end: Infinity};
|
2020-07-23 08:41:38 +00:00
|
|
|
constructor(fileReaderId, mapPanelId, timelinePanelId, icPanelId) {
|
2020-07-16 10:02:52 +00:00
|
|
|
this.mapPanelId_ = mapPanelId;
|
|
|
|
this.timelinePanelId_ = timelinePanelId;
|
|
|
|
this.icPanelId_ = icPanelId;
|
|
|
|
this.icPanel_ = this.$(icPanelId);
|
2020-07-28 09:02:26 +00:00
|
|
|
this.fileLoaded = false;
|
2020-07-23 08:41:38 +00:00
|
|
|
this.logFileReader_ = this.$(fileReaderId);
|
|
|
|
this.logFileReader_.addEventListener('fileuploadstart',
|
|
|
|
e => this.handleFileUpload(e));
|
|
|
|
this.logFileReader_.addEventListener('fileuploadend',
|
|
|
|
e => this.handleDataUpload(e));
|
2020-07-16 10:02:52 +00:00
|
|
|
document.addEventListener('keydown', e => this.handleKeyDown(e));
|
2020-07-22 14:41:42 +00:00
|
|
|
this.icPanel_.addEventListener(
|
|
|
|
'ictimefilter', e => this.handleICTimeFilter(e));
|
|
|
|
this.icPanel_.addEventListener(
|
|
|
|
'mapclick', e => this.handleMapClick(e));
|
|
|
|
this.icPanel_.addEventListener(
|
|
|
|
'filepositionclick', e => this.handleFilePositionClick(e));
|
2020-07-28 09:02:26 +00:00
|
|
|
this.toggleSwitch = this.$('.theme-switch input[type="checkbox"]');
|
|
|
|
this.toggleSwitch.addEventListener('change', e => this.switchTheme(e));
|
2020-07-14 15:03:14 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 08:41:38 +00:00
|
|
|
handleFileUpload(e){
|
|
|
|
this.$('#container').style.display = 'none';
|
|
|
|
}
|
2020-07-22 14:41:42 +00:00
|
|
|
handleMapClick(e) {
|
|
|
|
//TODO(zcankara) Direct the event based on the key and value
|
|
|
|
console.log("map: ", e.detail.key);
|
|
|
|
}
|
|
|
|
handleFilePositionClick(e) {
|
|
|
|
//TODO(zcankara) Direct the event based on the key and value
|
|
|
|
console.log("filePosition: ", e.detail.key);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleICTimeFilter(event) {
|
2020-07-24 13:51:36 +00:00
|
|
|
this.#timeSelection.start = event.detail.startTime;
|
|
|
|
this.#timeSelection.end = event.detail.endTime;
|
|
|
|
document.state.icTimeline.selectTimeRange(this.#timeSelection.start,
|
|
|
|
this.#timeSelection.end);
|
|
|
|
this.icPanel_.filteredEntries = document.state.icTimeline.selection;
|
2020-07-22 14:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-16 10:02:52 +00:00
|
|
|
$(id) { return document.querySelector(id); }
|
|
|
|
|
2020-07-22 14:41:42 +00:00
|
|
|
handleKeyDown(event) {
|
2020-07-16 10:02:52 +00:00
|
|
|
let nav = document.state.navigation;
|
|
|
|
switch(event.key) {
|
|
|
|
case "ArrowUp":
|
|
|
|
event.preventDefault();
|
|
|
|
if (event.shiftKey) {
|
|
|
|
nav.selectPrevEdge();
|
|
|
|
} else {
|
|
|
|
nav.moveInChunk(-1);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
case "ArrowDown":
|
|
|
|
event.preventDefault();
|
|
|
|
if (event.shiftKey) {
|
|
|
|
nav.selectNextEdge();
|
|
|
|
} else {
|
|
|
|
nav.moveInChunk(1);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
case "ArrowLeft":
|
|
|
|
nav.moveInChunks(false);
|
|
|
|
break;
|
|
|
|
case "ArrowRight":
|
|
|
|
nav.moveInChunks(true);
|
|
|
|
break;
|
|
|
|
case "+":
|
|
|
|
nav.increaseTimelineResolution();
|
|
|
|
break;
|
|
|
|
case "-":
|
|
|
|
nav.decreaseTimelineResolution();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Map event log processing
|
|
|
|
handleLoadTextMapProcessor(text) {
|
2020-07-14 15:03:14 +00:00
|
|
|
let mapProcessor = new MapProcessor();
|
|
|
|
return mapProcessor.processString(text);
|
|
|
|
}
|
|
|
|
|
2020-07-16 10:02:52 +00:00
|
|
|
// IC event file reading and log processing
|
|
|
|
loadICLogFile(fileData) {
|
|
|
|
let reader = new FileReader();
|
|
|
|
reader.onload = (evt) => {
|
|
|
|
let icProcessor = new CustomIcProcessor();
|
2020-07-24 13:51:36 +00:00
|
|
|
//TODO(zcankara) Assign timeline directly to the ic panel
|
|
|
|
//TODO(zcankara) Exe: this.icPanel_.timeline = document.state.icTimeline
|
|
|
|
document.state.icTimeline = icProcessor.processString(fileData.chunk);
|
|
|
|
this.icPanel_.filteredEntries = document.state.icTimeline.all;
|
|
|
|
this.icPanel_.count.innerHTML = document.state.icTimeline.all.length;
|
2020-07-16 10:02:52 +00:00
|
|
|
}
|
|
|
|
reader.readAsText(fileData.file);
|
|
|
|
this.icPanel_.initGroupKeySelect();
|
|
|
|
}
|
2020-07-14 15:03:14 +00:00
|
|
|
|
2020-07-16 10:02:52 +00:00
|
|
|
// call when a new file uploaded
|
|
|
|
handleDataUpload(e) {
|
|
|
|
if(!e.detail) return;
|
|
|
|
this.$('#container').style.display = 'block';
|
|
|
|
// instantiate the app logic
|
|
|
|
let fileData = e.detail;
|
2020-07-16 19:38:43 +00:00
|
|
|
document.state = new State(this.mapPanelId_, this.timelinePanelId_);
|
|
|
|
try {
|
2020-07-24 13:51:36 +00:00
|
|
|
const timeline = this.handleLoadTextMapProcessor(fileData.chunk);
|
|
|
|
// Transitions must be set before timeline for stats panel.
|
|
|
|
document.state.transitions= timeline.transitions;
|
|
|
|
document.state.timeline = timeline;
|
2020-07-16 19:38:43 +00:00
|
|
|
} catch (error) {
|
|
|
|
console.log(error);
|
|
|
|
}
|
2020-07-16 10:02:52 +00:00
|
|
|
this.loadICLogFile(fileData);
|
2020-07-28 09:02:26 +00:00
|
|
|
this.fileLoaded = true;
|
2020-07-16 10:02:52 +00:00
|
|
|
}
|
2020-07-14 15:03:14 +00:00
|
|
|
|
2020-07-16 10:02:52 +00:00
|
|
|
handleMapAddressSearch(e) {
|
|
|
|
if(!e.detail.isValidMap) return;
|
|
|
|
document.state.map = e.detail.map;
|
|
|
|
}
|
2020-07-14 15:03:14 +00:00
|
|
|
|
2020-07-16 10:02:52 +00:00
|
|
|
handleShowMaps(e) {
|
2020-07-22 15:00:22 +00:00
|
|
|
document.state.mapPanel.mapEntries = e.detail;
|
2020-07-16 10:02:52 +00:00
|
|
|
}
|
2020-07-14 15:03:14 +00:00
|
|
|
|
2020-07-16 10:02:52 +00:00
|
|
|
handleSelectIc(e){
|
|
|
|
if(!e.detail) return;
|
2020-07-24 13:51:36 +00:00
|
|
|
//TODO(zcankara) Send filtered entries to State
|
|
|
|
console.log("filtered IC entried: ", e.detail)
|
2020-07-16 10:02:52 +00:00
|
|
|
}
|
2020-07-28 09:02:26 +00:00
|
|
|
|
|
|
|
switchTheme(event) {
|
|
|
|
if(this.fileLoaded) return;
|
|
|
|
document.documentElement.dataset.theme =
|
|
|
|
event.target.checked ? 'dark' : 'light';
|
|
|
|
}
|
2020-07-15 07:28:00 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 09:02:26 +00:00
|
|
|
|
2020-07-15 07:28:00 +00:00
|
|
|
export {App};
|