blob: d1c2fa108be52f66aaa3a3e6aaf5a80cd056a6bb [file] [log] [blame]
<!--
The <ct-runs-summary-sk> custom element declaration. Displays a summary of
recent CT runs.
Attributes:
tasks: The successful tasks run by non-admins in the last week/month/year/all-time.
findTasksBeforeDays: Find above tasks that completed before these many days.
uniqueUsers: The number of unique users who triggered the above tasks.
Events:
None.
Methods:
reload: Queries for updated information on tasks.
weeklySummary: Sets findTasksBeforeDays to 7.
monthlySummary: Sets findTasksBeforeDays to 30.
yearlySummary: Sets findTasksBeforeDays to 365.
allTimeSummary: Sets findTasksBeforeDays to 0.
-->
<dom-module id="ct-runs-summary-sk">
<style>
tr.headers {
background-color: #CCCCFF;
text-align: center;
}
td.nowrap {
white-space: nowrap;
}
</style>
<template>
<h4>CT Runs Summary</h3>
<paper-button raised on-click="weeklySummary">Last Week</paper-button>
<paper-button raised on-click="monthlySummary">Last Month</paper-button>
<paper-button raised on-click="yearlySummary">Last Year</paper-button>
<paper-button raised on-click="allTimeSummary">All Time</paper-button>
<br/><br/>
<span>[[tasks.length]] runs by [[uniqueUsers]] users [[ getDaysText(findTasksBeforeDays) ]]</span>
<br/>
<template is="dom-if" if="{{tasks}}">
<table class="runssummary" id="runssummary" cellpadding="5" border="1">
<tr class="headers">
<td>Type</td>
<td>User</td>
<td>Description</td>
<td>Completed</td>
</tr>
<template is="dom-repeat" items="{{tasks}}" as="task" index-as="index">
<tr style="border: 1px solid black;">
<!-- Type col -->
<td>{{task.Type}}</td>
<!-- User col -->
<td>{{task.Username}}</td>
<!-- Description col -->
<td>{{task.Description}}</td>
<!-- Timestamps col -->
<td class="nowrap">{{task.TsCompleted}}</td>
</tr>
</template>
</table>
</template>
</template>
</dom-module>
<script>
Polymer({
is: "ct-runs-summary-sk",
properties: {
tasks: {
type: Array,
value: function() { return []; },
},
findTasksBeforeDays: {
type: Number,
value: 7,
},
uniqueUsers: {
type: Number,
value: 0,
},
},
ready: function() {
this.reload();
},
reload: function() {
if (this.findTasksBeforeDays > 0) {
var d = new Date();
d.setDate(d.getDate() - this.findTasksBeforeDays);
var completedAfter = this.getCtDbTimestamp(d);
} else {
var completedAfter = this.getCtDbTimestamp(new Date(0));
}
var queryParams = {
'completed_after': completedAfter,
'exclude_ctadmin_tasks': true,
}
var queryStr = "?" + sk.query.fromObject(queryParams);
sk.post('/_/completed_tasks' + queryStr).then(JSON.parse).then(function(json) {
this.tasks = json.CompletedTasks;
this.uniqueUsers = json.UniqueUsers;
}.bind(this)).catch(sk.errorMessage);
},
weeklySummary: function() {
this.findTasksBeforeDays = 7;
this.reload();
},
monthlySummary: function() {
this.findTasksBeforeDays = 30;
this.reload();
},
yearlySummary: function() {
this.findTasksBeforeDays = 365;
this.reload();
},
allTimeSummary: function() {
this.findTasksBeforeDays = 0;
this.reload();
},
getDaysText: function(days) {
if (days > 0) {
return "last " + days + " days";
} else {
return "all time";
}
},
getCtDbTimestamp: ctfe.getCtDbTimestamp,
});
</script>