Hector Dearman | ef1a7ff | 2018-07-10 11:21:06 +0100 | [diff] [blame] | 1 | // 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 | |
| 15 | import * as m from 'mithril'; |
Hector Dearman | 03f962c | 2018-08-09 17:00:32 +0100 | [diff] [blame] | 16 | |
Hector Dearman | 03f962c | 2018-08-09 17:00:32 +0100 | [diff] [blame] | 17 | import {globals} from './globals'; |
Michail Schwab | 20bab20 | 2018-08-02 18:17:44 -0400 | [diff] [blame] | 18 | import {Sidebar} from './sidebar'; |
Primiano Tucci | 21b91bf | 2018-08-06 16:42:07 +0100 | [diff] [blame] | 19 | import {Topbar} from './topbar'; |
Hector Dearman | ef1a7ff | 2018-07-10 11:21:06 +0100 | [diff] [blame] | 20 | |
Hector Dearman | 03f962c | 2018-08-09 17:00:32 +0100 | [diff] [blame] | 21 | function renderPermalink(): m.Children { |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 22 | if (!globals.state.permalink.requestId) return null; |
| 23 | const hash = globals.state.permalink.hash; |
| 24 | const url = `${self.location.origin}#!/?s=${hash}`; |
Hector Dearman | 03f962c | 2018-08-09 17:00:32 +0100 | [diff] [blame] | 25 | return m( |
| 26 | '.alert-permalink', |
Primiano Tucci | e36ca63 | 2018-08-21 14:32:23 +0200 | [diff] [blame] | 27 | hash ? ['Permalink: ', m(`a[href=${url}]`, url)] : 'Uploading...'); |
Hector Dearman | 03f962c | 2018-08-09 17:00:32 +0100 | [diff] [blame] | 28 | } |
| 29 | |
Deepanjan Roy | 97f6324 | 2018-09-20 15:32:01 -0400 | [diff] [blame] | 30 | class Alerts implements m.ClassComponent { |
Hector Dearman | 03f962c | 2018-08-09 17:00:32 +0100 | [diff] [blame] | 31 | view() { |
| 32 | return m('.alerts', renderPermalink()); |
Deepanjan Roy | 97f6324 | 2018-09-20 15:32:01 -0400 | [diff] [blame] | 33 | } |
| 34 | } |
Hector Dearman | 03f962c | 2018-08-09 17:00:32 +0100 | [diff] [blame] | 35 | |
Deepanjan Roy | 9a906ed | 2018-09-20 11:06:00 -0400 | [diff] [blame] | 36 | const 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 | |
| 52 | const 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 Dearman | ef1a7ff | 2018-07-10 11:21:06 +0100 | [diff] [blame] | 63 | /** |
| 64 | * Wrap component with common UI elements (nav bar etc). |
| 65 | */ |
| 66 | export function createPage(component: m.Component): m.Component { |
Deepanjan Roy | f190cb2 | 2018-08-28 10:43:07 -0400 | [diff] [blame] | 67 | const pageComponent = { |
Hector Dearman | ef1a7ff | 2018-07-10 11:21:06 +0100 | [diff] [blame] | 68 | view() { |
| 69 | return [ |
Michail Schwab | 20bab20 | 2018-08-02 18:17:44 -0400 | [diff] [blame] | 70 | m(Sidebar), |
Primiano Tucci | 21b91bf | 2018-08-06 16:42:07 +0100 | [diff] [blame] | 71 | m(Topbar), |
| 72 | m(component), |
Hector Dearman | 03f962c | 2018-08-09 17:00:32 +0100 | [diff] [blame] | 73 | m(Alerts), |
Deepanjan Roy | 9a906ed | 2018-09-20 11:06:00 -0400 | [diff] [blame] | 74 | m(PerfStats), |
Hector Dearman | ef1a7ff | 2018-07-10 11:21:06 +0100 | [diff] [blame] | 75 | ]; |
| 76 | }, |
| 77 | }; |
Deepanjan Roy | f190cb2 | 2018-08-28 10:43:07 -0400 | [diff] [blame] | 78 | |
| 79 | return pageComponent; |
Hector Dearman | ef1a7ff | 2018-07-10 11:21:06 +0100 | [diff] [blame] | 80 | } |