projectsettings: implement update project

add option to update project name and visibility
This commit is contained in:
Simone Gotti 2019-05-13 17:17:02 +02:00
parent 7eb6c2c961
commit 98073502e2
2 changed files with 66 additions and 1 deletions

View File

@ -1,5 +1,30 @@
<template> <template>
<div> <div>
<nav class="panel">
<p class="panel-heading">Project Settings</p>
<div class="panel-block is-block">
<div class="field">
<label class="label">Project Name</label>
<div class="control">
<input class="input" type="text" placeholder="Text input" v-model="project.name">
</div>
</div>
<div class="field">
<div class="control">
<label class="checkbox">
<input type="checkbox" v-model="projectIsPrivate">
Private
</label>
</div>
</div>
<div class="field is-grouped">
<div class="control">
<button class="button is-primary" @click="updateProject()">Update</button>
</div>
</div>
</div>
</nav>
<nav class="panel"> <nav class="panel">
<p class="panel-heading">Variables</p> <p class="panel-heading">Variables</p>
<div class="panel-block is-block"> <div class="panel-block is-block">
@ -46,7 +71,12 @@
</template> </template>
<script> <script>
import { fetchVariables, deleteProject } from "@/util/data.js"; import {
fetchProject,
fetchVariables,
updateProject,
deleteProject
} from "@/util/data.js";
import { projectGroupLink } from "@/util/link.js"; import { projectGroupLink } from "@/util/link.js";
@ -62,6 +92,8 @@ export default {
}, },
data() { data() {
return { return {
project: null,
projectIsPrivate: false,
variables: [], variables: [],
allvariables: [], allvariables: [],
projectNameToDelete: "" projectNameToDelete: ""
@ -79,6 +111,19 @@ export default {
} }
}, },
methods: { methods: {
async updateProject() {
let projectref = [
this.ownertype,
this.ownername,
...this.projectref
].join("/");
let visibility = "public";
if (this.projectIsPrivate) {
visibility = "private";
}
let res = await updateProject(projectref, this.project.name, visibility);
},
async deleteProject() { async deleteProject() {
let projectref = [ let projectref = [
this.ownertype, this.ownertype,
@ -99,6 +144,13 @@ export default {
} }
}, },
created: async function() { created: async function() {
let projectref = [this.ownertype, this.ownername, ...this.projectref].join(
"/"
);
this.project = await fetchProject(projectref);
this.projectIsPrivate = this.project.visibility == "private";
this.variables = await fetchVariables( this.variables = await fetchVariables(
"project", "project",
[this.ownertype, this.ownername, ...this.projectref].join("/"), [this.ownertype, this.ownername, ...this.projectref].join("/"),

View File

@ -151,6 +151,19 @@ export async function createProject(parentref, name, remotesourcename, remoterep
return res.json(); return res.json();
} }
export async function updateProject(projectref, name, visibility) {
let path = "/projects/" + encodeURIComponent(projectref)
let init = {
method: "PUT",
body: JSON.stringify({
name: name,
visibility: visibility,
})
}
let res = await fetch(apiurl(path), init)
return res.json()
}
export async function deleteProject(projectref) { export async function deleteProject(projectref) {
let path = "/projects/" + encodeURIComponent(projectref) let path = "/projects/" + encodeURIComponent(projectref)
let init = { let init = {