11cb0ef41Sopenharmony_ci// Copyright 2020 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ciimport './map-panel/map-details.mjs'; 51cb0ef41Sopenharmony_ciimport './map-panel/map-transitions.mjs'; 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciimport {MapLogEntry} from '../log/map.mjs'; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciimport {FocusEvent} from './events.mjs'; 101cb0ef41Sopenharmony_ciimport {CollapsableElement, DOM} from './helper.mjs'; 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciDOM.defineCustomElement('view/map-panel', 131cb0ef41Sopenharmony_ci (templateText) => 141cb0ef41Sopenharmony_ci class MapPanel extends CollapsableElement { 151cb0ef41Sopenharmony_ci _map; 161cb0ef41Sopenharmony_ci _timeline; 171cb0ef41Sopenharmony_ci _selectedLogEntries = []; 181cb0ef41Sopenharmony_ci _displayedLogEntries = []; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci constructor() { 211cb0ef41Sopenharmony_ci super(templateText); 221cb0ef41Sopenharmony_ci this.searchBarBtn.addEventListener('click', e => this._handleSearch(e)); 231cb0ef41Sopenharmony_ci this.showAllRadio.onclick = _ => this._showEntries(this._timeline); 241cb0ef41Sopenharmony_ci this.showTimerangeRadio.onclick = _ => 251cb0ef41Sopenharmony_ci this._showEntries(this._timeline.selectionOrSelf); 261cb0ef41Sopenharmony_ci this.showSelectionRadio.onclick = _ => 271cb0ef41Sopenharmony_ci this._showEntries(this._selectedLogEntries); 281cb0ef41Sopenharmony_ci } 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci get showAllRadio() { 311cb0ef41Sopenharmony_ci return this.$('#show-all'); 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci get showTimerangeRadio() { 351cb0ef41Sopenharmony_ci return this.$('#show-timerange'); 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci get showSelectionRadio() { 391cb0ef41Sopenharmony_ci return this.$('#show-selection'); 401cb0ef41Sopenharmony_ci } 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci get mapTransitionsPanel() { 431cb0ef41Sopenharmony_ci return this.$('#map-transitions'); 441cb0ef41Sopenharmony_ci } 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci get mapDetailsTransitionsPanel() { 471cb0ef41Sopenharmony_ci return this.$('#map-details-transitions'); 481cb0ef41Sopenharmony_ci } 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci get mapDetailsPanel() { 511cb0ef41Sopenharmony_ci return this.$('#map-details'); 521cb0ef41Sopenharmony_ci } 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci get searchBarBtn() { 551cb0ef41Sopenharmony_ci return this.$('#searchBarBtn'); 561cb0ef41Sopenharmony_ci } 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci get searchBar() { 591cb0ef41Sopenharmony_ci return this.$('#searchBar'); 601cb0ef41Sopenharmony_ci } 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci set timeline(timeline) { 631cb0ef41Sopenharmony_ci console.assert(timeline !== undefined, 'timeline undefined!'); 641cb0ef41Sopenharmony_ci this._timeline = timeline; 651cb0ef41Sopenharmony_ci this.$('.panel').style.display = timeline.isEmpty() ? 'none' : 'inherit'; 661cb0ef41Sopenharmony_ci this.mapTransitionsPanel.timeline = timeline; 671cb0ef41Sopenharmony_ci this.mapDetailsTransitionsPanel.timeline = timeline; 681cb0ef41Sopenharmony_ci } 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci set selectedLogEntries(entries) { 711cb0ef41Sopenharmony_ci if (entries === this._timeline.selection) { 721cb0ef41Sopenharmony_ci this.showTimerangeRadio.click(); 731cb0ef41Sopenharmony_ci } else if (entries == this._timeline) { 741cb0ef41Sopenharmony_ci this.showAllRadio.click(); 751cb0ef41Sopenharmony_ci } else { 761cb0ef41Sopenharmony_ci this._selectedLogEntries = entries; 771cb0ef41Sopenharmony_ci this.showSelectionRadio.click(); 781cb0ef41Sopenharmony_ci } 791cb0ef41Sopenharmony_ci } 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ci set map(map) { 821cb0ef41Sopenharmony_ci this._map = map; 831cb0ef41Sopenharmony_ci this.requestUpdate(); 841cb0ef41Sopenharmony_ci } 851cb0ef41Sopenharmony_ci 861cb0ef41Sopenharmony_ci _showEntries(entries) { 871cb0ef41Sopenharmony_ci this._displayedLogEntries = entries; 881cb0ef41Sopenharmony_ci this.requestUpdate(); 891cb0ef41Sopenharmony_ci } 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_ci _update() { 921cb0ef41Sopenharmony_ci this.mapDetailsTransitionsPanel.selectedLogEntries = [this._map]; 931cb0ef41Sopenharmony_ci this.mapDetailsPanel.map = this._map; 941cb0ef41Sopenharmony_ci this.mapTransitionsPanel.selectedLogEntries = this._displayedLogEntries; 951cb0ef41Sopenharmony_ci } 961cb0ef41Sopenharmony_ci 971cb0ef41Sopenharmony_ci _handleSearch(e) { 981cb0ef41Sopenharmony_ci const searchBar = this.$('#searchBarInput'); 991cb0ef41Sopenharmony_ci const searchBarInput = searchBar.value; 1001cb0ef41Sopenharmony_ci // access the map from model cache 1011cb0ef41Sopenharmony_ci const selectedMap = MapLogEntry.get(searchBarInput); 1021cb0ef41Sopenharmony_ci if (selectedMap) { 1031cb0ef41Sopenharmony_ci searchBar.className = 'success'; 1041cb0ef41Sopenharmony_ci this.dispatchEvent(new FocusEvent(selectedMap)); 1051cb0ef41Sopenharmony_ci } else { 1061cb0ef41Sopenharmony_ci searchBar.className = 'failure'; 1071cb0ef41Sopenharmony_ci } 1081cb0ef41Sopenharmony_ci } 1091cb0ef41Sopenharmony_ci}); 110