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