rundetails: move api functions to data.js

This commit is contained in:
Simone Gotti 2019-04-08 17:45:30 +02:00
parent 53e814f00e
commit c8effcc334
2 changed files with 31 additions and 29 deletions

View File

@ -32,12 +32,12 @@
<a <a
v-if="run.can_restart_from_scratch" v-if="run.can_restart_from_scratch"
class="dropdown-item" class="dropdown-item"
@click="restartRun(run, true)" @click="restartRun(run.id, true)"
>From start</a> >From start</a>
<a <a
v-if="run.can_restart_from_failed_tasks" v-if="run.can_restart_from_failed_tasks"
class="dropdown-item" class="dropdown-item"
@click="restartRun(run)" @click="restartRun(run.id)"
>From failed tasks</a> >From failed tasks</a>
</div> </div>
</div> </div>
@ -45,7 +45,7 @@
<button <button
class="button is-danger" class="button is-danger"
v-if="run.phase == 'running'" v-if="run.phase == 'running'"
@click="stopRun(run)" @click="stopRun(run.id)"
>Stop</button> >Stop</button>
</div> </div>
</div> </div>
@ -93,7 +93,7 @@
</template> </template>
<script> <script>
import { apiurl, fetch } from "@/util/auth"; import { stopRun, restartRun } from "@/util/data.js";
export default { export default {
name: "RunDetail", name: "RunDetail",
@ -133,31 +133,8 @@ export default {
if (task.status == "running") return "running"; if (task.status == "running") return "running";
return "unknown"; return "unknown";
}, },
async restartRun(run, fromStart) { stopRun: stopRun,
let res = await fetch(apiurl("/runs/" + run.id + "/actions"), { restartRun: restartRun
method: "PUT",
body: JSON.stringify({
action_type: "restart",
from_start: fromStart
})
});
if (res.status == 200) {
return res.json();
}
throw Error(res.statusText);
},
async stopRun(run) {
let res = fetch(apiurl("/runs/" + run.id + "/actions"), {
method: "PUT",
body: JSON.stringify({
action_type: "stop"
})
});
if (res.status == 200) {
return res.json();
}
throw Error(res.statusText);
}
} }
}; };
</script> </script>

View File

@ -72,6 +72,31 @@ export async function deleteUserToken(username, tokenname) {
return res.text(); return res.text();
} }
export async function restartRun(runid, fromStart) {
let path = "/runs/" + runid + "/actions"
let init = {
method: "PUT",
body: JSON.stringify({
action_type: "restart",
from_start: fromStart
})
}
let res = await fetch(apiurl(path), init)
return res.json();
}
export async function stopRun(runid) {
let path = "/runs/" + runid + "/actions"
let init = {
method: "PUT",
body: JSON.stringify({
action_type: "stop"
})
}
let res = await fetch(apiurl(path), init)
return res.json();
}
export async function approveTask(runid, taskid) { export async function approveTask(runid, taskid) {
let path = "/runs/" + runid + "/tasks/" + taskid + "/actions" let path = "/runs/" + runid + "/tasks/" + taskid + "/actions"
let init = { let init = {