convert fetch usage to async/await
This commit is contained in:
parent
ef5a9c4994
commit
219b2d2e2f
|
@ -36,7 +36,7 @@ export default {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetch: function() {
|
fetch() {
|
||||||
if (this.fetching) {
|
if (this.fetching) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ export default {
|
||||||
this.getLogs();
|
this.getLogs();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
streamLogs: function() {
|
streamLogs() {
|
||||||
let path = "/logs?runID=" + this.runid + "&taskID=" + this.taskid;
|
let path = "/logs?runID=" + this.runid + "&taskID=" + this.taskid;
|
||||||
if (this.setup) {
|
if (this.setup) {
|
||||||
path += "&setup";
|
path += "&setup";
|
||||||
|
@ -69,14 +69,14 @@ export default {
|
||||||
this.es.close();
|
this.es.close();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
getLogs: function() {
|
async getLogs() {
|
||||||
let path = "/logs?runID=" + this.runid + "&taskID=" + this.taskid;
|
let path = "/logs?runID=" + this.runid + "&taskID=" + this.taskid;
|
||||||
if (this.setup) {
|
if (this.setup) {
|
||||||
path += "&setup";
|
path += "&setup";
|
||||||
} else {
|
} else {
|
||||||
path += "&step=" + this.step;
|
path += "&step=" + this.step;
|
||||||
}
|
}
|
||||||
fetch(apiurl(path))
|
let res = await fetch(apiurl(path))
|
||||||
.then(r => {
|
.then(r => {
|
||||||
if (r.status == 200) {
|
if (r.status == 200) {
|
||||||
return r.text();
|
return r.text();
|
||||||
|
|
|
@ -38,17 +38,14 @@ export default {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fetchProjects(ownertype, ownername) {
|
async fetchProjects(ownertype, ownername) {
|
||||||
let path =
|
let path =
|
||||||
"/projectgroups/" + encodeURIComponent(ownertype + "/" + ownername);
|
"/projectgroups/" + encodeURIComponent(ownertype + "/" + ownername);
|
||||||
path += "/projects";
|
path += "/projects";
|
||||||
fetch(apiurl(path))
|
let res = await (await fetch(apiurl(path))).json();
|
||||||
.then(res => res.json())
|
console.log(res);
|
||||||
.then(res => {
|
this.projects = res;
|
||||||
console.log(res);
|
console.log("projects", this.projects);
|
||||||
this.projects = res;
|
|
||||||
console.log("projects", this.projects);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created: function() {
|
created: function() {
|
||||||
|
|
|
@ -134,34 +134,32 @@ export default {
|
||||||
if (task.status == "running") return "running";
|
if (task.status == "running") return "running";
|
||||||
return "unknown";
|
return "unknown";
|
||||||
},
|
},
|
||||||
restartRun(run, fromStart) {
|
async restartRun(run, fromStart) {
|
||||||
fetch(apiurl("/run/" + run.id + "/actions"), {
|
let res = await fetch(apiurl("/run/" + run.id + "/actions"), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
action_type: "restart",
|
action_type: "restart",
|
||||||
from_start: fromStart
|
from_start: fromStart
|
||||||
})
|
})
|
||||||
}).then(r => {
|
|
||||||
console.log("r: " + r);
|
|
||||||
if (r.status == 200) {
|
|
||||||
return r.json();
|
|
||||||
}
|
|
||||||
throw Error(r.statusText);
|
|
||||||
});
|
});
|
||||||
|
console.log("r: " + r);
|
||||||
|
if (r.status == 200) {
|
||||||
|
return r.json();
|
||||||
|
}
|
||||||
|
throw Error(r.statusText);
|
||||||
},
|
},
|
||||||
stopRun(run) {
|
async stopRun(run) {
|
||||||
fetch(apiurl("/run/" + run.id + "/actions"), {
|
let res = fetch(apiurl("/run/" + run.id + "/actions"), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
action_type: "stop"
|
action_type: "stop"
|
||||||
})
|
})
|
||||||
}).then(r => {
|
|
||||||
console.log("r: " + r);
|
|
||||||
if (r.status == 200) {
|
|
||||||
return r.json();
|
|
||||||
}
|
|
||||||
throw Error(r.statusText);
|
|
||||||
});
|
});
|
||||||
|
console.log("r: " + r);
|
||||||
|
if (r.status == 200) {
|
||||||
|
return r.json();
|
||||||
|
}
|
||||||
|
throw Error(r.statusText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -119,32 +119,26 @@ export default {
|
||||||
}
|
}
|
||||||
this.pollData();
|
this.pollData();
|
||||||
},
|
},
|
||||||
fetchProject() {
|
async fetchProject() {
|
||||||
let path =
|
let path =
|
||||||
"/projects/" +
|
"/projects/" +
|
||||||
encodeURIComponent(
|
encodeURIComponent(
|
||||||
this.ownertype + "/" + this.ownername + "/" + this.projectname
|
this.ownertype + "/" + this.ownername + "/" + this.projectname
|
||||||
);
|
);
|
||||||
fetch(apiurl(path))
|
let res = await (await fetch(apiurl(path))).json();
|
||||||
.then(res => res.json())
|
console.log(res);
|
||||||
.then(res => {
|
this.project = res;
|
||||||
console.log(res);
|
console.log("project", this.project);
|
||||||
this.project = res;
|
|
||||||
console.log("project", this.project);
|
|
||||||
|
|
||||||
this.fetchRuns();
|
this.fetchRuns();
|
||||||
});
|
|
||||||
},
|
},
|
||||||
fetchUser() {
|
async fetchUser() {
|
||||||
fetch(apiurl("/users/" + this.username))
|
let res = await (await fetch(apiurl("/users/" + this.username))).json();
|
||||||
.then(res => res.json())
|
console.log(res);
|
||||||
.then(res => {
|
this.user = res;
|
||||||
console.log(res);
|
console.log("user", this.user);
|
||||||
this.user = res;
|
|
||||||
console.log("user", this.user);
|
|
||||||
|
|
||||||
this.fetchRuns();
|
this.fetchRuns();
|
||||||
});
|
|
||||||
},
|
},
|
||||||
async fetchRuns() {
|
async fetchRuns() {
|
||||||
let group;
|
let group;
|
||||||
|
|
Loading…
Reference in New Issue