blob: 00ce5427a9a3e10bdaac08ddaa880330222fcd3a [file] [log] [blame]
<!--
The <lua-scripts-sk> custom element declaration. Displays a form that allows the user to queue a
task to run a Lua script.
Attributes:
skpRepositories: List of all available SKP repositories, as accepted by
skp-repository-selector-sk property skpRepositories. Must be set.
Events:
None.
Methods:
None.
-->
<dom-module id="lua-scripts-sk">
<style>
paper-input {
width: 20em;
}
.triggering-spinner {
margin: auto;
vertical-align: middle;
}
.iron-selected {
background-color: #D6ECF2;
}
.long-field {
width: 40em;
}
table.options td {
padding: 1em 2em;
}
td.center {
text-align:center;
padding-top:2em;
}
.panel {
@apply(--shadow-elevation-2dp);
}
</style>
<template>
<confirm-dialog-sk id="confirm_dialog"></confirm-dialog-sk>
<table class="options panel">
<tr>
<td>SKP Repository</td>
<td>
<skp-repository-selector-sk id="skp_repository" skp-repositories="{{skpRepositories}}">
</skp-repository-selector-sk>
</td>
</tr>
<tr>
<td>Lua script</td>
<td>
<iron-autogrow-textarea class="long-field" rows=15 max-rows=30 id="lua_script">
</iron-autogrow-textarea>
</td>
</tr>
<tr>
<td>Lua aggregator script (optional)</td>
<td>
<iron-autogrow-textarea class="long-field" rows=15 max-rows=30 id="lua_aggregator_script">
</iron-autogrow-textarea>
</td>
</tr>
<tr>
<td>Repeat this task</td>
<td>
<repeat-after-days-sk id="repeat_after_days"></repeat-after-days-sk>
</td>
</tr>
<tr>
<td>Description</td>
<td>
<paper-input value="" id="desc" label="Description is required"></paper-input>
</td>
</tr>
<tr>
<td colspan="2" class="center">
<div class="triggering-spinner">
<paper-spinner active="[[ triggeringTask ]]" alt="Trigger task"></paper-spinner>
</div>
<paper-button raised id="submit_task" disabled="[[ triggeringTask ]]">Queue Task</paper-button>
</td>
</tr>
<tr>
<td colspan="2" class="center">
<paper-button raised id="view_history">View runs history</paper-button>
</td>
</tr>
</table>
<br/><br/>
</template>
</dom-module>
<script>
Polymer({
is: "lua-scripts-sk",
properties: {
skpRepositories: {
type: Array,
observer: "skpRepositoriesChanged",
},
triggeringTask: {
type: Boolean,
value: false,
},
},
ready: function() {
var that = this;
this.$.submit_task.addEventListener('click', function(e) {
that.validateTask();
});
this.$.view_history.addEventListener('click', function(e) {
that.gotoRunsHistory();
});
},
skpRepositoriesChanged: function(newValue, oldValue) {
// CT's lua scripts do not currently support PDF page sets.
for (var i=this.skpRepositories.length-1; i>=0; i--) {
if (this.skpRepositories[i].PageSets.startsWith("PDF")) {
this.skpRepositories.splice(i, 1);
}
}
if (!oldValue || oldValue.length == 0) {
this.$.skp_repository.selectFirst();
}
},
validateTask: function() {
if (!this.$.skp_repository.selected) {
sk.errorMessage("Please select an SKP repository");
this.$.skp_repository.focus();
return;
}
if (!this.$.lua_script.textarea.value) {
sk.errorMessage("Please provide a script to run");
this.$.lua_script.focus();
return;
}
if (!this.$.desc.value) {
sk.errorMessage("Please specify a description");
this.$.desc.focus();
return;
}
if (ctfe.moreThanThreeActiveTasks($$$("drawer-sk").sizeOfUserQueue)) {
return;
}
this.$.confirm_dialog.open("Proceed with queueing task?")
.then(this.queueTask.bind(this))
.catch(function() {
sk.errorMessage("Did not queue");
})
},
queueTask: function() {
this.triggeringTask = true;
var params = {};
params["skp_repository"] = this.$.skp_repository.selected;
params["lua_script"] = this.$.lua_script.textarea.value;
params["lua_aggregator_script"] = this.$.lua_aggregator_script.textarea.value;
params["desc"] = this.$.desc.value;
params["repeat_after_days"] = this.$.repeat_after_days.selected;
var that = this;
sk.post("/_/add_lua_script_task", JSON.stringify(params)).then(function(resp) {
that.gotoRunsHistory();
}).catch(function(e) {
that.triggeringTask = false;
sk.errorMessage(e);
});
},
gotoRunsHistory: function() {
window.location.href = "/lua_script_runs/";
},
});
</script>