| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 # Copyright 2015 The LUCI Authors. All rights reserved. | |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | |
| 4 # that can be found in the LICENSE file. | |
| 5 | |
| 6 --> | |
| 7 | |
| 8 <!-- | |
| 9 @group Swarming Elements | |
| 10 | |
| 11 `stats-app' encapsulates the statistic front end. | |
| 12 | |
| 13 @element stats-app | |
| 14 --> | |
| 15 | |
| 16 <link rel="import" href="bower_components/polymer/polymer.html"> | |
| 17 <link rel="import" href="bower_components/core-ajax/core-ajax.html"> | |
| 18 <link rel="import" href="bower_components/core-label/core-label.html"> | |
| 19 <link rel="import" href="bower_components/paper-checkbox/paper-checkbox.html"> | |
| 20 <link rel="import" href="bower_components/paper-dialog/paper-dialog.html"> | |
| 21 <link rel="import" href="bower_components/paper-radio-button/paper-radio-button.
html"> | |
| 22 <link rel="import" href="bower_components/paper-radio-group/paper-radio-group.ht
ml"> | |
| 23 <link rel="import" href="bower_components/paper-spinner/paper-spinner.html"> | |
| 24 | |
| 25 <link rel="import" href="stats-dimension-filter.html"> | |
| 26 <link rel="import" href="stats-request-chart.html"> | |
| 27 <link rel="import" href="stats-work-chart.html"> | |
| 28 <link rel="import" href="stats-table-chart.html"> | |
| 29 <link rel="import" href="stats-time-chart.html"> | |
| 30 | |
| 31 | |
| 32 <polymer-element name="stats-app" attributes="dimensions"> | |
| 33 <template> | |
| 34 <style> | |
| 35 #loading { | |
| 36 position: fixed; | |
| 37 top: 0px; | |
| 38 right: 0px; | |
| 39 } | |
| 40 #radioGroup > paper-radio-button { | |
| 41 padding: 0px 0px 0px 12px; | |
| 42 } | |
| 43 #filterPanel { | |
| 44 width: 480px; | |
| 45 } | |
| 46 core-label { | |
| 47 margin-left: 12px; | |
| 48 display: inline; | |
| 49 } | |
| 50 </style> | |
| 51 | |
| 52 <core-ajax id="get_stats_summary" | |
| 53 headers='{"x-datasource-auth": "a"}' | |
| 54 url="/swarming/api/v1/stats/summary/{{resolution}}" | |
| 55 params='{"duration": "{{duration}}"}' | |
| 56 handleAs="json" | |
| 57 on-core-response="{{onGetStatsSummarySuccess}}" | |
| 58 loading="{{ajaxLoading}}"> | |
| 59 </core-ajax> | |
| 60 | |
| 61 <core-ajax id="get_stats_dimension" | |
| 62 headers='{"x-datasource-auth": "a"}' | |
| 63 url="/swarming/api/v1/stats/dimensions/{{dimension}}/{{resolution}}" | |
| 64 params='{"duration": "{{duration}}"}' | |
| 65 handleAs="json" | |
| 66 on-core-response="{{onGetStatsSummarySuccess}}" | |
| 67 loading="{{ajaxLoading}}"> | |
| 68 </core-ajax> | |
| 69 | |
| 70 <div layout horizontal> | |
| 71 <div layout vertical id="filterPanel"> | |
| 72 <div layout horizontal center> | |
| 73 <paper-radio-group id="radioGroup" selected="{{resolution}}"> | |
| 74 <paper-radio-button name="days" label="Days"></paper-radio-button> | |
| 75 <paper-radio-button name="hours" label="Hours"></paper-radio-button> | |
| 76 <paper-radio-button name="minutes" label="Minutes"></paper-radio-but
ton> | |
| 77 </paper-radio-group> | |
| 78 </div> | |
| 79 | |
| 80 <stats-dimension-filter dimensions="{{dimensions}}" value="{{dimension}}
"> | |
| 81 </stats-dimension-filter> | |
| 82 </div> | |
| 83 <div layout vertical flex> | |
| 84 <stats-work-chart | |
| 85 isDimension="{{dimension ? true : false}}" | |
| 86 data="{{dataTable}}" | |
| 87 resolution="{{resolution}}"> | |
| 88 </stats-work-chart> | |
| 89 | |
| 90 <stats-time-chart | |
| 91 isDimension="{{dimension ? true : false}}" | |
| 92 data="{{dataTable}}" | |
| 93 resolution="{{resolution}}"> | |
| 94 </stats-time-chart> | |
| 95 | |
| 96 <stats-request-chart | |
| 97 hidden?="{{dimension}}" | |
| 98 data="{{dataTable}}" | |
| 99 resolution="{{resolution}}"> | |
| 100 </stats-request-chart> | |
| 101 </div> | |
| 102 </div> | |
| 103 <stats-table-chart data="{{dataTable}}"></stats-table-chart> | |
| 104 | |
| 105 <paper-spinner id="loading"></paper-spinner> | |
| 106 </template> | |
| 107 | |
| 108 <script> | |
| 109 Polymer('stats-app', { | |
| 110 observe: { | |
| 111 'dimension': 'paramsChanged', | |
| 112 'duration': 'paramsChanged', | |
| 113 'resolution': 'paramsChanged' | |
| 114 }, | |
| 115 | |
| 116 ready: function() { | |
| 117 var self = this; | |
| 118 window.onpopstate = function(event) { | |
| 119 self.restoringState = true; | |
| 120 self.dimension = event.state.dimension; | |
| 121 self.duration = event.state.duration; | |
| 122 self.resolution = event.state.resolution; | |
| 123 }; | |
| 124 this.restoreState(); | |
| 125 }, | |
| 126 | |
| 127 restoreState: function() { | |
| 128 try { | |
| 129 var stateObj = JSON.parse( | |
| 130 decodeURIComponent(window.location.search.substr(1))); | |
| 131 this.dimension = stateObj.dimension; | |
| 132 this.duration = stateObj.duration || 120; | |
| 133 this.resolution = stateObj.resolution || 'hours'; | |
| 134 this.restoringState = true; | |
| 135 var stateObj = this.getState(); | |
| 136 var url = '/stats?' + JSON.stringify(stateObj); | |
| 137 window.history.replaceState(stateObj, '', url); | |
| 138 } catch (e) { | |
| 139 this.restoringState = false; | |
| 140 this.resolution = 'hours'; | |
| 141 this.duration = 120; | |
| 142 } | |
| 143 }, | |
| 144 | |
| 145 getState: function() { | |
| 146 return { | |
| 147 dimension: this.dimension, | |
| 148 duration: this.duration, | |
| 149 resolution: this.resolution, | |
| 150 }; | |
| 151 }, | |
| 152 | |
| 153 pushState: function() { | |
| 154 var stateObj = this.getState(); | |
| 155 var url = '/stats?' + JSON.stringify(stateObj); | |
| 156 window.history.pushState(stateObj, '', url); | |
| 157 }, | |
| 158 | |
| 159 paramsChanged: function(oldValue, newValue) { | |
| 160 if (this.dimension) { | |
| 161 this.$.get_stats_dimension.go(); | |
| 162 } else { | |
| 163 this.$.get_stats_summary.go(); | |
| 164 } | |
| 165 if (!this.restoringState) { | |
| 166 this.pushState(); | |
| 167 } else { | |
| 168 this.restoringState = false; | |
| 169 } | |
| 170 }, | |
| 171 | |
| 172 onGetStatsSummarySuccess: function(event, detail, sender) { | |
| 173 this.dataTable = detail.response.table; | |
| 174 }, | |
| 175 | |
| 176 ajaxLoadingChanged: function(oldValue, newValue) { | |
| 177 if (newValue) { | |
| 178 this.$.loading.active = true; | |
| 179 } else { | |
| 180 this.$.loading.active = false; | |
| 181 } | |
| 182 } | |
| 183 }); | |
| 184 </script> | |
| 185 </polymer-element> | |
| OLD | NEW |