blob: 7b0a2ee06d02ed3a5ffef844e65b94787196eb88 [file] [log] [blame]
<!--
The <admin-task-runs-sk> custom element declaration. Displays a table with details about each
completed and pending admin task, and allows the user to delete pending tasks if applicable.
Attributes:
url: POST URI to request tasks, e.g. "/_/get_recreate_page_sets_tasks". Must be set.
deleteUrl: POST URI to delete a task, e.g. "/_/delete_recreate_page_sets_task". Must be set.
redoUrl: POST URI to redo a task, e.g. "/_/redo_recreate_page_sets_task". Must be set.
taskType: Type of task, e.g. "RecreatePageSets". Must be set.
defaultSize: The number of tasks to show per page, default 10.
constrainByUser: Whether to show only tasks created by the logged-in user initially, default
false.
myRunsConstrainText: Button text to constrain by user, default "View only my runs".
everyonesRunsConstrainText: Button text to disable constraining by user, default "View
everyone's runs".
constrainByTestRun: Whether to show only non-test tasks, default true. Test tasks are those that
use the "Dummy1k" page sets.
nonTestRunsConstrainText: Button text to constrain to non-test tasks, default "Exclude test
runs".
testRunsConstrainText: Button text to disable constraining by test tasks, default "Include test
runs".
Events:
None.
Methods:
reload: queries for updated information on tasks.
resetPagination: Moves to the first page of tasks.
constrainRunsByUser: Toggles constrainByUser and reloads the appropriate data.
constrainTestRuns: Toggles constrainByTestRun and reloads the appropriate data.
-->
<dom-module id="admin-task-runs-sk">
<style>
table.runshistory {
border-spacing: 0px;
}
tr.headers {
background-color: #CCCCFF;
text-align: center;
}
td.nowrap {
white-space: nowrap;
}
table.runshistory > tbody > tr > td {
padding: 10px;
border: solid black 1px;
}
.delete-button, .redo-button {
--paper-icon-button-disabled: {
display: none;
}
}
.oldruns {
margin-left: 20px;
}
</style>
<template>
<confirm-dialog-sk id="confirm_dialog"></confirm-dialog-sk>
<h2><template is="dom-if" if="{{constrainByUser}}">My </template><span>{{taskType}}</span> Task Runs</h2>
<paging-sk pagination="{{pagination}}" on-pagechange="pageChangedHandler"></paging-sk>
<br/>
<paper-button raised on-click="constrainRunsByUser">{{
constrainButtonText(constrainByUser, myRunsConstrainText, everyonesRunsConstrainText)
}}</paper-button>
<paper-button raised on-click="constrainTestRuns">{{
constrainButtonText(constrainByTestRun, nonTestRunsConstrainText, testRunsConstrainText)
}}</paper-button>
<br/>
<br/>
<table class="runshistory" id="runshistory" cellpadding="5" border="1">
<tr class="headers">
<td>Id</td>
<td>User</td>
<td>Timestamps</td>
<td>Task Config</td>
<td>Results</td>
<td>Task Repeats</td>
</tr>
<template is="dom-repeat" items="{{adminTasks}}" as="adminTask" index-as="index">
<tr style="border: 1px solid black;">
<!-- Id col -->
<td class="nowrap">
<span>{{adminTask.Id}}</span>
<paper-icon-button icon="delete" mini
class="delete-button"
disabled="{{!adminTask.canDelete}}"
alt="Delete"
data-index$="{{index}}"
data-type="delete">
</paper-icon-button>
<paper-icon-button icon="redo" mini
class="redo-button"
disabled="{{!adminTask.canRedo}}"
alt="Redo"
data-index$="{{index}}"
data-type="redo">
</paper-icon-button>
</td>
<!-- User col -->
<td>{{adminTask.Username}}</td>
<!-- Timestamps col -->
<td>
<table>
<tr>
<td>Added:</td>
<td class="nowrap">{{ formatTimestamp(adminTask.TsAdded) }}</td>
</tr>
<tr>
<td>Started:</td>
<td class="nowrap">{{ formatTimestamp(adminTask.TsStarted) }}</td>
</tr>
<tr>
<td>Completed:</td>
<td class="nowrap">{{ formatTimestamp(adminTask.TsCompleted) }}</td>
</tr>
</table>
</td>
<!-- Task Config col -->
<td>
<table>
<tr>
<td>PageSet:</td>
<td>{{adminTask.PageSets}}</td>
</tr>
<template is="dom-if" if="{{isRecreateWebpageArchivesTask()}}">
<tr>
<td>ChromiumBuild:</td>
<td class="nowrap">
<a href="{{chromiumCommitUrl(adminTask.ChromiumRev)}}">{{shortHash(adminTask.ChromiumRev)}}</a>-<a href="{{skiaCommitUrl(adminTask.SkiaRev)}}">{{shortHash(adminTask.SkiaRev)}}</a>
</td>
</tr>
</template>
</table>
</td>
<!-- Results col -->
<td class="nowrap">
<template is="dom-if" if="{{adminTask.Failure}}">
<div style="color:red;">Failed</div>
</template>
<template is="dom-if" if="{{!adminTask.TaskDone}}">
<div style="color:green;">Waiting</div>
</template>
<template is="dom-if" if="{{isDone(adminTask.Failure, adminTask.TaskDone)}}">
Done
</template>
<br/>
<template is="dom-if" if="{{adminTask.SwarmingLogs}}">
<a href="{{adminTask.SwarmingLogs}}" target="_blank">Swarming Logs</a>
</template>
</td>
<!-- Repeat Every -->
<td>{{ formatRepeatAfterDays(adminTask.RepeatAfterDays) }}</td>
</tr>
</template>
</table>
</template>
</dom-module>
<script>
Polymer({
is: "admin-task-runs-sk",
properties: {
url: String,
deleteUrl: String,
redoUrl: String,
taskType: String,
adminTasks: {
type: Array,
value: function() { return []; },
},
defaultSize: {
type: Number,
value: 10,
},
constrainByUser: {
type: Boolean,
value: false,
},
myRunsConstrainText: {
type: String,
value: "View only my runs",
},
everyonesRunsConstrainText: {
type: String,
value: "View everyone's runs",
},
constrainByTestRun: {
type: Boolean,
value: true,
},
nonTestRunsConstrainText: {
type: String,
value: "Exclude test runs",
},
testRunsConstrainText: {
type: String,
value: "Include test runs",
},
pagination: {
type: Object,
value: function() { return {}; },
},
pageChangedHandler: {
type: Object,
value: function() { return null; },
},
},
ready: function() {
this.pagination = {"offset": 0, "size": this.defaultSize};
this.pageChangedHandler = this.reload.bind(this);
var that = this;
this.$.runshistory.addEventListener('click', function(e) {
var button = sk.findParent(e.target, "PAPER-ICON-BUTTON");
if (button != null) {
if (button.dataset.type == "delete") {
var index = button.dataset.index;
that.$.confirm_dialog.open("Proceed with deleting task?")
.then(that.deleteTask.bind(that, index));
} else if (button.dataset.type == "redo") {
var index = button.dataset.index;
that.$.confirm_dialog.open("Reschedule this task?")
.then(that.redoTask.bind(that, index));
}
}
});
this.reload();
},
reload: function() {
var queryParams = {
"offset": this.pagination.offset,
"size": this.pagination.size,
}
if (this.constrainByUser) {
queryParams["filter_by_logged_in_user"] = true;
}
if (this.constrainByTestRun) {
queryParams["exclude_dummy_page_sets"] = true;
}
var queryStr = "?" + sk.query.fromObject(queryParams);
sk.post(this.url + queryStr).then(JSON.parse).then(function(json) {
this.pagination = json.pagination;
this.adminTasks = json.data;
for (var i = 0; i < this.adminTasks.length; i++) {
this.adminTasks[i].canDelete = json.permissions[i].DeleteAllowed;
this.adminTasks[i].canRedo = json.permissions[i].RedoAllowed;
this.adminTasks[i].Id = json.ids[i];
}
}.bind(this)).catch(sk.errorMessage);
},
resetPagination: function() {
this.pagination.offset = 0;
this.pagination.size = this.defaultSize;
},
constrainRunsByUser: function() {
this.constrainByUser = !this.constrainByUser;
this.resetPagination();
this.reload();
},
constrainTestRuns: function() {
this.constrainByTestRun = !this.constrainByTestRun;
this.resetPagination();
this.reload();
},
constrainButtonText: function(constrained, constrainText, unconstrainText) {
if (constrained) {
return unconstrainText;
} else {
return constrainText;
}
},
deleteTask: function(deleteIndex) {
var params = {};
params["id"] = this.adminTasks[deleteIndex].Id;
sk.post(this.deleteUrl, JSON.stringify(params)).then(function() {
$$$("#confirm_toast").text = "Deleted task " + params["id"];
$$$("#confirm_toast").show();
}.bind(this)).catch(sk.errorMessage).then(function() {
this.reload();
}.bind(this));
},
redoTask: function(redoIndex) {
var params = {};
params["id"] = this.adminTasks[redoIndex].Id;
sk.post(this.redoUrl, JSON.stringify(params)).then(function() {
$$$("#confirm_toast").text = "Resubmitted task " + params["id"];
$$$("#confirm_toast").show();
}.bind(this)).catch(sk.errorMessage).then(function() {
this.reload();
}.bind(this));
},
formatTimestamp: ctfe.getFormattedTimestamp,
chromiumCommitUrl: ctfe.chromiumBuild.chromiumCommitUrl,
skiaCommitUrl: ctfe.chromiumBuild.skiaCommitUrl,
shortHash: ctfe.chromiumBuild.shortHash,
formatRepeatAfterDays: ctfe.formatRepeatAfterDays,
isRecreateWebpageArchivesTask: function() {
return this.taskType == "RecreateWebpageArchives";
},
isDone: function(failure, taskDone) {
return !failure && taskDone;
},
});
</script>