Compare commits

...

1 Commits

Author SHA1 Message Date
Piotr Sarnacki
8240169016 Use V3 API for restarting and cancelling a build and a job 2016-02-08 11:41:46 +01:00
4 changed files with 35 additions and 13 deletions

View File

@ -22,6 +22,7 @@ if (Config.useV3API) {
Build.reopen({ Build.reopen({
ajax: Ember.inject.service(), ajax: Ember.inject.service(),
v3Ajax: Ember.inject.service(),
state: attr(), state: attr(),
number: attr('number'), number: attr('number'),
message: attr('string'), message: attr('string'),
@ -125,11 +126,11 @@ Build.reopen({
canRestart: Ember.computed.alias('isFinished'), canRestart: Ember.computed.alias('isFinished'),
cancel() { cancel() {
return this.get('ajax').post("/builds/" + (this.get('id')) + "/cancel"); return this.get('v3Ajax').post("/build/" + (this.get('id')) + "/cancel");
}, },
restart() { restart() {
return this.get('ajax').post("/builds/" + (this.get('id')) + "/restart"); return this.get('v3Ajax').post("/build/" + (this.get('id')) + "/restart");
}, },
formattedFinishedAt: function() { formattedFinishedAt: function() {

View File

@ -9,6 +9,7 @@ import { hasMany, belongsTo } from 'ember-data/relationships';
export default Model.extend(DurationCalculations, { export default Model.extend(DurationCalculations, {
ajax: Ember.inject.service(), ajax: Ember.inject.service(),
v3Ajax: Ember.inject.service(),
logId: attr(), logId: attr(),
queue: attr(), queue: attr(),
state: attr(), state: attr(),
@ -111,7 +112,7 @@ export default Model.extend(DurationCalculations, {
canRestart: Ember.computed.alias('isFinished'), canRestart: Ember.computed.alias('isFinished'),
cancel() { cancel() {
return this.get('ajax').post("/jobs/" + (this.get('id')) + "/cancel"); return this.get('v3Ajax').post("/job/" + (this.get('id')) + "/cancel");
}, },
removeLog() { removeLog() {
@ -126,7 +127,7 @@ export default Model.extend(DurationCalculations, {
}, },
restart() { restart() {
return this.get('ajax').post("/jobs/" + (this.get('id')) + "/restart"); return this.get('v3Ajax').post("/job/" + (this.get('id')) + "/restart");
}, },
appendLog(part) { appendLog(part) {

View File

@ -1,17 +1,16 @@
import Ember from 'ember'; import Ember from 'ember';
import config from 'travis/config/environment'; import config from 'travis/config/environment';
var default_options;
jQuery.support.cors = true; jQuery.support.cors = true;
default_options = { export default Ember.Service.extend({
auth: Ember.inject.service(),
default_options: {
accepts: { accepts: {
json: 'application/json; version=2' json: 'application/json; version=2'
} }
}; },
export default Ember.Service.extend({
auth: Ember.inject.service(),
get(url, callback, errorCallback) { get(url, callback, errorCallback) {
return this.ajax(url, 'get', { return this.ajax(url, 'get', {
@ -38,11 +37,15 @@ export default Ember.Service.extend({
return true; return true;
}, },
getEndpoint() {
return config.apiEndpoint || '';
},
ajax(url, method, options) { ajax(url, method, options) {
var accepts, base, data, delimeter, endpoint, error, key, name, params, promise, ref, ref1, ref2, reject, resolve, success, token, value, xhr; var accepts, base, data, delimeter, endpoint, error, key, name, params, promise, ref, ref1, ref2, reject, resolve, success, token, value, xhr;
method = method || "GET"; method = method || "GET";
method = method.toUpperCase(); method = method.toUpperCase();
endpoint = config.apiEndpoint || ''; endpoint = this.getEndpoint();
options = options || {}; options = options || {};
token = Ember.get(this, 'auth').token(); token = Ember.get(this, 'auth').token();
if (token && (this.needsAuth(method, url) || options.forceAuth)) { if (token && (this.needsAuth(method, url) || options.forceAuth)) {
@ -83,7 +86,7 @@ export default Ember.Service.extend({
return error.call(this, data, status, xhr); return error.call(this, data, status, xhr);
}; };
options = $.extend(options, default_options); options = $.extend(options, this.default_options);
if (options.data && (method === "GET" || method === "HEAD")) { if (options.data && (method === "GET" || method === "HEAD")) {
params = jQuery.param(options.data); params = jQuery.param(options.data);

17
app/services/v3-ajax.js Normal file
View File

@ -0,0 +1,17 @@
import Ember from 'ember';
import config from 'travis/config/environment';
import Ajax from 'travis/services/ajax';
jQuery.support.cors = true;
export default Ajax.extend({
default_options: {
accepts: {
json: 'application/json'
}
},
getEndpoint() {
return config.apiEndpoint + '/v3';
}
});