Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: Stop job button #4189

Merged
merged 11 commits into from
Apr 21, 2018
24 changes: 17 additions & 7 deletions ui/app/adapters/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,24 @@ export default Watchable.extend({

forcePeriodic(job) {
if (job.get('periodic')) {
const [path, params] = this.buildURL('job', job.get('id'), job, 'findRecord').split('?');
let url = `${path}/periodic/force`;

if (params) {
url += `?${params}`;
}

const url = addToPath(this.urlForFindRecord(job.get('id'), 'job'), '/periodic/force');
return this.ajax(url, 'POST');
}
},

stop(job) {
const url = this.urlForFindRecord(job.get('id'), 'job');
return this.ajax(url, 'DELETE');
},
});

function addToPath(url, extension = '') {
const [path, params] = url.split('?');
let newUrl = `${path}${extension}`;

if (params) {
newUrl += `?${params}`;
}

return newUrl;
}
26 changes: 26 additions & 0 deletions ui/app/components/two-step-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Component from '@ember/component';
import { equal } from '@ember/object/computed';

export default Component.extend({
classNames: ['two-step-button'],

idleText: '',
cancelText: '',
confirmText: '',
confirmationMessage: '',
onConfirm() {},
onCancel() {},

state: 'idle',
isIdle: equal('state', 'idle'),
isPendingConfirmation: equal('state', 'prompt'),

actions: {
setToIdle() {
this.set('state', 'idle');
},
promptForConfirmation() {
this.set('state', 'prompt');
},
},
});
4 changes: 4 additions & 0 deletions ui/app/models/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ export default Model.extend({
return this.store.adapterFor('job').forcePeriodic(this);
},

stop() {
return this.store.adapterFor('job').stop(this);
},

statusClass: computed('status', function() {
const classMap = {
pending: 'is-pending',
Expand Down
37 changes: 19 additions & 18 deletions ui/app/styles/components.scss
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
@import "./components/badge";
@import "./components/boxed-section";
@import "./components/cli-window";
@import "./components/ember-power-select";
@import "./components/empty-message";
@import "./components/error-container";
@import "./components/gutter";
@import "./components/inline-definitions";
@import "./components/job-diff";
@import "./components/json-viewer";
@import "./components/loading-spinner";
@import "./components/metrics";
@import "./components/node-status-light";
@import "./components/page-layout";
@import "./components/simple-list";
@import "./components/status-text";
@import "./components/timeline";
@import "./components/tooltip";
@import './components/badge';
@import './components/boxed-section';
@import './components/cli-window';
@import './components/ember-power-select';
@import './components/empty-message';
@import './components/error-container';
@import './components/gutter';
@import './components/inline-definitions';
@import './components/job-diff';
@import './components/json-viewer';
@import './components/loading-spinner';
@import './components/metrics';
@import './components/node-status-light';
@import './components/page-layout';
@import './components/simple-list';
@import './components/status-text';
@import './components/timeline';
@import './components/tooltip';
@import './components/two-step-button';
14 changes: 14 additions & 0 deletions ui/app/styles/components/two-step-button.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.two-step-button {
display: inline;
position: relative;

.confirmation-text {
position: absolute;
left: 0;
top: -1.2em;
font-size: $body-size;
font-weight: $weight-normal;
color: darken($grey-blue, 20%);
white-space: nowrap;
}
}
19 changes: 19 additions & 0 deletions ui/app/templates/components/two-step-button.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{#if isIdle}}
<button class="button is-warning is-small is-inline" onclick={{action "promptForConfirmation"}}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs type="button"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Updated it.

{{idleText}}
</button>
{{else if isPendingConfirmation}}
<span class="confirmation-text">{{confirmationMessage}}</span>
<button class="button is-dark is-outlined is-small is-inline" onclick={{action (queue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type here too please!

(action "setToIdle")
(action onCancel)
)}}>
{{cancelText}}
</button>
<button class="button is-danger is-small is-inline" onclick={{action (queue
(action "setToIdle")
(action onConfirm)
)}}>
{{confirmText}}
</button>
{{/if}}