blob: a964952e19f24bff42bc5e6d6a234235759edf98 [file] [log] [blame]
Hector Dearmanef1a7ff2018-07-10 11:21:06 +01001// Copyright (C) 2018 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15import * as m from 'mithril';
Hector Dearman03f962c2018-08-09 17:00:32 +010016
Hector Dearman03f962c2018-08-09 17:00:32 +010017import {globals} from './globals';
Michail Schwab20bab202018-08-02 18:17:44 -040018import {Sidebar} from './sidebar';
Primiano Tucci21b91bf2018-08-06 16:42:07 +010019import {Topbar} from './topbar';
Hector Dearmanef1a7ff2018-07-10 11:21:06 +010020
Hector Dearman03f962c2018-08-09 17:00:32 +010021function renderPermalink(): m.Children {
Primiano Tuccie36ca632018-08-21 14:32:23 +020022 if (!globals.state.permalink.requestId) return null;
23 const hash = globals.state.permalink.hash;
24 const url = `${self.location.origin}#!/?s=${hash}`;
Hector Dearman03f962c2018-08-09 17:00:32 +010025 return m(
26 '.alert-permalink',
Primiano Tuccie36ca632018-08-21 14:32:23 +020027 hash ? ['Permalink: ', m(`a[href=${url}]`, url)] : 'Uploading...');
Hector Dearman03f962c2018-08-09 17:00:32 +010028}
29
Deepanjan Roy97f63242018-09-20 15:32:01 -040030class Alerts implements m.ClassComponent {
Hector Dearman03f962c2018-08-09 17:00:32 +010031 view() {
32 return m('.alerts', renderPermalink());
Deepanjan Roy97f63242018-09-20 15:32:01 -040033 }
34}
Hector Dearman03f962c2018-08-09 17:00:32 +010035
Deepanjan Roy9a906ed2018-09-20 11:06:00 -040036const TogglePerfDebugButton = {
37 view() {
38 return m(
39 '.perf-monitor-button',
40 m('button',
41 {
42 onclick: () => globals.frontendLocalState.togglePerfDebug(),
43 },
44 m('i.material-icons',
45 {
46 title: 'Toggle Perf Debug Mode',
47 },
48 'assessment')));
49 }
50};
51
52const PerfStats: m.Component = {
53 view() {
54 const perfDebug = globals.frontendLocalState.perfDebug;
55 const children = [m(TogglePerfDebugButton)];
56 if (perfDebug) {
57 children.unshift(m('.perf-stats-content'));
58 }
59 return m(`.perf-stats[expanded=${perfDebug}]`, children);
60 }
61};
62
Hector Dearmanef1a7ff2018-07-10 11:21:06 +010063/**
64 * Wrap component with common UI elements (nav bar etc).
65 */
66export function createPage(component: m.Component): m.Component {
Deepanjan Royf190cb22018-08-28 10:43:07 -040067 const pageComponent = {
Hector Dearmanef1a7ff2018-07-10 11:21:06 +010068 view() {
69 return [
Michail Schwab20bab202018-08-02 18:17:44 -040070 m(Sidebar),
Primiano Tucci21b91bf2018-08-06 16:42:07 +010071 m(Topbar),
72 m(component),
Hector Dearman03f962c2018-08-09 17:00:32 +010073 m(Alerts),
Deepanjan Roy9a906ed2018-09-20 11:06:00 -040074 m(PerfStats),
Hector Dearmanef1a7ff2018-07-10 11:21:06 +010075 ];
76 },
77 };
Deepanjan Royf190cb22018-08-28 10:43:07 -040078
79 return pageComponent;
Hector Dearmanef1a7ff2018-07-10 11:21:06 +010080}