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-08-06 14:41:38 +00:00
|
|
|
import {Entry} from "./ic-processor.mjs";
|
2020-07-23 06:37:37 +00:00
|
|
|
import {State} from './app-model.mjs';
|
2020-08-04 08:51:59 +00:00
|
|
|
import {MapProcessor, V8Map} from './map-processor.mjs';
|
|
|
|
import {$} from './helper.mjs';
|
2020-07-14 15:03:14 +00:00
|
|
|
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-08-04 08:51:59 +00:00
|
|
|
#state
|
|
|
|
#view;
|
2020-07-28 12:46:10 +00:00
|
|
|
constructor(fileReaderId, mapPanelId, timelinePanelId,
|
|
|
|
icPanelId, mapTrackId, icTrackId) {
|
2020-08-04 08:51:59 +00:00
|
|
|
this.#view = {
|
|
|
|
logFileReader: $(fileReaderId),
|
|
|
|
icPanel: $(icPanelId),
|
|
|
|
mapPanel: $(mapPanelId),
|
|
|
|
timelinePanel: $(timelinePanelId),
|
|
|
|
mapTrack: $(mapTrackId),
|
|
|
|
icTrack: $(icTrackId),
|
|
|
|
}
|
|
|
|
this.#state = new State();
|
2020-08-06 14:41:38 +00:00
|
|
|
this.toggleSwitch = $('.theme-switch input[type="checkbox"]');
|
|
|
|
this.toggleSwitch.addEventListener('change', e => this.switchTheme(e));
|
2020-08-04 08:51:59 +00:00
|
|
|
this.#view.logFileReader.addEventListener('fileuploadstart',
|
2020-07-23 08:41:38 +00:00
|
|
|
e => this.handleFileUpload(e));
|
2020-08-04 08:51:59 +00:00
|
|
|
this.#view.logFileReader.addEventListener('fileuploadend',
|
2020-07-23 08:41:38 +00:00
|
|
|
e => this.handleDataUpload(e));
|
2020-08-06 14:41:38 +00:00
|
|
|
Object.entries(this.#view).forEach(([_, value]) => {
|
|
|
|
value.addEventListener('showentries',
|
|
|
|
e => this.handleShowEntries(e));
|
|
|
|
value.addEventListener('showentrydetail',
|
|
|
|
e => this.handleShowEntryDetail(e));
|
|
|
|
});
|
2020-08-04 08:51:59 +00:00
|
|
|
this.#view.icPanel.addEventListener(
|
2020-07-22 14:41:42 +00:00
|
|
|
'ictimefilter', e => this.handleICTimeFilter(e));
|
2020-07-23 08:41:38 +00:00
|
|
|
}
|
2020-08-06 14:41:38 +00:00
|
|
|
handleShowEntries(e){
|
|
|
|
if(e.entries[0] instanceof V8Map){
|
|
|
|
this.#view.mapPanel.mapEntries = e.entries;
|
|
|
|
}
|
2020-07-22 14:41:42 +00:00
|
|
|
}
|
2020-08-06 14:41:38 +00:00
|
|
|
handleShowEntryDetail(e){
|
|
|
|
if(e.entry instanceof V8Map){
|
|
|
|
this.selectMapLogEvent(e.entry);
|
|
|
|
}
|
|
|
|
else if(e.entry instanceof Entry){
|
|
|
|
this.selectICLogEvent(e.entry);
|
|
|
|
}
|
|
|
|
else if(typeof e.entry === 'string'){
|
|
|
|
this.selectSourcePositionEvent(e.entry);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
console.log("undefined");
|
|
|
|
}
|
2020-07-22 14:41:42 +00:00
|
|
|
}
|
2020-08-04 08:51:59 +00:00
|
|
|
handleClickSourcePositions(e){
|
|
|
|
//TODO(zcankara) Handle source position
|
2020-08-06 14:41:38 +00:00
|
|
|
console.log("Entry containing source position: ", e.entries);
|
2020-07-22 14:41:42 +00:00
|
|
|
}
|
2020-08-06 14:41:38 +00:00
|
|
|
selectMapLogEvent(entry){
|
|
|
|
this.#state.map = entry;
|
|
|
|
this.#view.mapTrack.selectedEntry = entry;
|
|
|
|
this.#view.mapPanel.map = entry;
|
2020-08-04 08:51:59 +00:00
|
|
|
}
|
2020-08-06 14:41:38 +00:00
|
|
|
selectICLogEvent(entry){
|
|
|
|
console.log("IC Entry selection");
|
2020-08-04 08:51:59 +00:00
|
|
|
}
|
2020-08-06 14:41:38 +00:00
|
|
|
selectSourcePositionEvent(sourcePositions){
|
|
|
|
console.log("source positions: ", sourcePositions);
|
2020-08-04 08:51:59 +00:00
|
|
|
}
|
|
|
|
handleICTimeFilter(event) {
|
|
|
|
this.#state.timeSelection.start = event.detail.startTime;
|
|
|
|
this.#state.timeSelection.end = event.detail.endTime;
|
|
|
|
this.#view.icTrack.data.selectTimeRange(this.#state.timeSelection.start,
|
|
|
|
this.#state.timeSelection.end);
|
|
|
|
this.#view.icPanel.filteredEntries = this.#view.icTrack.data.selection;
|
|
|
|
}
|
|
|
|
handleFileUpload(e){
|
|
|
|
//TODO(zcankara) Set a state on the document.body. Exe: .loading, .loaded
|
|
|
|
$('#container').style.display = 'none';
|
2020-07-16 10:02:52 +00:00
|
|
|
}
|
|
|
|
// 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
|
2020-07-28 12:46:10 +00:00
|
|
|
//TODO(zcankara) Exe: this.#icPanel.timeline = document.state.icTimeline
|
2020-08-04 08:51:59 +00:00
|
|
|
//TODO(zcankara) Set the data of the State object first
|
|
|
|
this.#state.icTimeline = icProcessor.processString(fileData.chunk);
|
|
|
|
this.#view.icTrack.data = this.#state.icTimeline;
|
|
|
|
this.#view.icPanel.filteredEntries = this.#view.icTrack.data.all;
|
|
|
|
this.#view.icPanel.count.innerHTML = this.#view.icTrack.data.all.length;
|
2020-07-16 10:02:52 +00:00
|
|
|
}
|
|
|
|
reader.readAsText(fileData.file);
|
2020-08-04 08:51:59 +00:00
|
|
|
this.#view.icPanel.initGroupKeySelect();
|
2020-07-16 10:02:52 +00:00
|
|
|
}
|
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;
|
2020-08-04 08:51:59 +00:00
|
|
|
$('#container').style.display = 'block';
|
2020-07-16 10:02:52 +00:00
|
|
|
// instantiate the app logic
|
|
|
|
let fileData = e.detail;
|
2020-07-16 19:38:43 +00:00
|
|
|
try {
|
2020-07-24 13:51:36 +00:00
|
|
|
const timeline = this.handleLoadTextMapProcessor(fileData.chunk);
|
|
|
|
// Transitions must be set before timeline for stats panel.
|
2020-08-04 08:51:59 +00:00
|
|
|
this.#state.mapTimeline = timeline;
|
|
|
|
this.#view.mapPanel.transitions = this.#state.mapTimeline.transitions;
|
|
|
|
this.#view.mapTrack.data = this.#state.mapTimeline;
|
|
|
|
this.#state.chunks = this.#view.mapTrack.chunks;
|
|
|
|
this.#view.mapPanel.timeline = this.#state.mapTimeline;
|
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-08-05 04:13:01 +00:00
|
|
|
refreshTimelineTrackView(){
|
|
|
|
this.#view.mapTrack.data = this.#state.mapTimeline;
|
|
|
|
this.#view.icTrack.data = this.#state.icTimeline;
|
|
|
|
}
|
|
|
|
|
2020-07-28 09:02:26 +00:00
|
|
|
switchTheme(event) {
|
|
|
|
document.documentElement.dataset.theme =
|
2020-08-05 04:13:01 +00:00
|
|
|
event.target.checked ? 'light' : 'dark';
|
|
|
|
if(this.fileLoaded) {
|
|
|
|
this.refreshTimelineTrackView();
|
|
|
|
}
|
2020-07-28 09:02:26 +00:00
|
|
|
}
|
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};
|