| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| |
| <link rel="import" href="/core/analysis/util.html"> |
| <link rel="import" href="/base/base.html"> |
| <link rel="import" href="/base/ui.html"> |
| <link rel="import" href="/base/ui/dom_helpers.html"> |
| <link rel="import" href="/core/analysis/analysis_sub_view.html"> |
| <link rel="import" href="/core/analysis/table_builder.html"> |
| |
| <polymer-element name="tv-c-a-alert-sub-view" |
| extends="tracing-analysis-sub-view"> |
| <template> |
| <style> |
| :host { |
| display: flex; |
| flex-direction: column; |
| } |
| #table { |
| flex: 1 1 auto; |
| align-self: stretch; |
| } |
| </style> |
| <tracing-analysis-nested-table id="table"> |
| </tracing-analysis-nested-table> |
| </template> |
| <script> |
| 'use strict'; |
| |
| Polymer({ |
| ready: function() { |
| this.currentSelection_ = undefined; |
| this.$.table.tableColumns = [ |
| { |
| title: 'Label', |
| value: function(row) { return row.name; }, |
| width: '150px' |
| }, |
| { |
| title: 'Value', |
| width: '100%', |
| value: function(row) { return row.value; } |
| } |
| ]; |
| this.$.table.showHeader = false; |
| }, |
| |
| get selection() { |
| return this.currentSelection_; |
| }, |
| |
| set selection(selection) { |
| this.currentSelection_ = selection; |
| this.updateContents_(); |
| }, |
| |
| getRowsForSingleAlert_: function(alert) { |
| var rows = []; |
| |
| // Arguments |
| for (var argName in alert.args) { |
| var argView = |
| document.createElement('tv-c-analysis-generic-object-view'); |
| argView.object = alert.args[argName]; |
| rows.push({ name: argName, value: argView }); |
| } |
| |
| // Associated events |
| if (alert.associatedEvents.length) { |
| alert.associatedEvents.forEach(function(event, i) { |
| var linkEl = document.createElement('tv-c-analysis-link'); |
| linkEl.setSelectionAndContent(function() { |
| return new tv.c.Selection(event); |
| }, event.title); |
| |
| var valueString = ''; |
| if (event instanceof tv.c.trace_model.TimedEvent) |
| valueString = 'took ' + event.duration.toFixed(2) + 'ms'; |
| |
| rows.push({ |
| name: linkEl, |
| value: valueString |
| }); |
| }); |
| } |
| |
| // Description |
| var descriptionEl = tv.b.ui.createDiv({ |
| textContent: alert.info.description, |
| maxWidth: '300px' |
| }); |
| rows.push({ |
| name: 'Description', |
| value: descriptionEl |
| }); |
| |
| if (alert.info.docUrl) { |
| var linkEl = document.createElement('a'); |
| linkEl.href = alert.info.docUrl; |
| linkEl.textContent = alert.info.docUrl; |
| linkEl.target = '_blank'; |
| rows.push({ |
| name: 'Additional reading', |
| value: linkEl |
| }); |
| } |
| return rows; |
| }, |
| |
| getRowsForAlerts_: function(alerts) { |
| if (alerts.length == 1) { |
| var rows = [{ |
| name: 'Alert', |
| value: alerts[0].title |
| }]; |
| var detailRows = this.getRowsForSingleAlert_(alerts[0]); |
| rows.push.apply(rows, detailRows); |
| return rows; |
| } else { |
| return alerts.map(function(alert) { |
| return { |
| name: 'Alert', |
| value: alert.title, |
| isExpanded: alerts.size < 10, // This is somewhat arbitrary for now. |
| subRows: this.getRowsForSingleAlert_(alert) |
| }; |
| }, this); |
| } |
| }, |
| |
| updateContents_: function() { |
| if (this.currentSelection_ === undefined) { |
| this.$.table.rows = []; |
| this.$.table.rebuild(); |
| return; |
| } |
| |
| var alerts = this.currentSelection_; |
| this.$.table.tableRows = this.getRowsForAlerts_(alerts); |
| this.$.table.rebuild(); |
| } |
| }); |
| </script> |
| </polymer-element> |