| <!-- |
| 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; |
| } |
| |
| .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> |
| |
| <paper-dialog heading="Confirmation" id="confirm_dialog"> |
| <div>Proceed with queueing task?</div> |
| <paper-button id="task_dismiss">Cancel</paper-button> |
| <paper-button id="task_confirm" autofocus>OK</paper-button> |
| </paper-dialog> |
| |
| <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"> |
| <paper-button raised id="submit_task">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", |
| }, |
| }, |
| |
| ready: function() { |
| var that = this; |
| this.$.submit_task.addEventListener('click', function(e) { |
| that.validateTask(); |
| }); |
| this.$.task_dismiss.addEventListener('click', function(e) { |
| that.dismissTask(); |
| }); |
| this.$.task_confirm.addEventListener('click', function(e) { |
| that.queueTask(); |
| }); |
| 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.moreThanOneActiveTask($$$("drawer-sk").sizeOfUserQueue)) { |
| return; |
| } |
| this.$.confirm_dialog.open() |
| }, |
| |
| dismissTask: function() { |
| sk.errorMessage("Did not queue"); |
| this.$.confirm_dialog.close() |
| }, |
| |
| queueTask: function() { |
| 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(sk.errorMessage); |
| }, |
| |
| gotoRunsHistory: function() { |
| window.location.href = "/lua_script_runs/"; |
| }, |
| }); |
| </script> |