| <!DOCTYPE html> |
| <!-- |
| Copyright 2018 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| |
| <link rel="import" href="/components/app-route/app-location.html"> |
| <link rel="import" href="/components/iron-form/iron-form.html"> |
| <link rel="import" href="/components/paper-button/paper-button.html"> |
| <link rel="import" href="/components/paper-dialog/paper-dialog.html"> |
| <link rel="import" href="/components/paper-fab/paper-fab.html"> |
| <link rel="import" href="/components/paper-tooltip/paper-tooltip.html"> |
| |
| <link rel="import" href="/elements/base-style.html"> |
| |
| <dom-module id="rerun-job-fab"> |
| <template> |
| <style include="base-style"> |
| paper-fab { |
| color: var(--paper-grey-700); |
| --paper-fab-background: white; |
| } |
| |
| .error { |
| color: var(--paper-red-500); |
| } |
| </style> |
| |
| <app-location route="{{route}}"></app-location> |
| <paper-fab mini id="job-fab" icon="refresh" on-tap="openDialog"></paper-fab> |
| <paper-tooltip for="job-fab" position="left">Re-run this job</paper-tooltip> |
| <paper-dialog id="job_dialog" entry-animation="fade-in-animation" exit-animation="fade-out-animation"> |
| <h2>Re-run this job?</h2> |
| <div> |
| <template is="dom-if" if="[[error]]"> |
| <p class="error">[[error]] |
| </template> |
| <iron-form id="job_form" headers="[[authHeaders]]" on-iron-form-error="handleError" on-iron-form-response="handleResponse"> |
| <form action="/api/new" method="POST"> |
| <template is="dom-repeat" items="[[getArguments(job)]]"> |
| <input type="hidden" name="[[item.key]]" value="[[item.value]]"> |
| </template> |
| |
| </form> |
| </iron-form> |
| </div> |
| <div class="buttons"> |
| <paper-button on-tap="submit">Start</paper-button> |
| </div> |
| </paper-dialog> |
| </template> |
| |
| <script> |
| 'use strict'; |
| Polymer({ |
| is: 'rerun-job-fab', |
| |
| properties: { |
| error: Object, |
| job: Object, |
| }, |
| |
| openDialog() { |
| this.$.job_dialog.open(); |
| }, |
| |
| getArguments(job) { |
| const args = Object.assign({}, job.arguments); |
| delete args.name; |
| delete args.user; |
| |
| // TODO(dtu): Remove after there are no jobs we care about with |
| // comparison_magnitude == 'None' (a string containing 'None'). |
| if (args.comparison_magnitude == 'None') { |
| delete args.comparison_magnitude; |
| } |
| |
| const tuples = []; |
| for (const key in args) { |
| tuples.push({key, value: args[key]}); |
| } |
| return tuples; |
| }, |
| |
| submit() { |
| this.$.job_form.submit(); |
| }, |
| |
| handleError(event) { |
| this.error = event.detail.request.response.error; |
| }, |
| |
| handleResponse(event) { |
| this.set('route.path', '/job/' + event.detail.response.jobId); |
| this.$.job_dialog.close(); |
| }, |
| }); |
| </script> |
| </dom-module> |