2019-05-06 15:58:18 +00:00
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<h4 class="title is-4">Create Project</h4>
|
|
|
|
|
<div class="field">
|
|
|
|
|
<div class="control">
|
|
|
|
|
<input class="input" type="text" placeholder="Project name" v-model="projectName">
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2019-05-14 12:24:40 +00:00
|
|
|
<div class="field">
|
|
|
|
|
<div class="control">
|
|
|
|
|
<label class="checkbox">
|
|
|
|
|
<input type="checkbox" v-model="projectIsPrivate">
|
|
|
|
|
Private
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2019-05-06 15:58:18 +00:00
|
|
|
<h4 class="title is-4">Available remote repositories</h4>
|
|
|
|
|
<div v-for="remoteSource in remoteSources" v-bind:key="remoteSource.id">
|
|
|
|
|
<remoterepos
|
2019-05-13 14:25:43 +00:00
|
|
|
class="remoterepos"
|
|
|
|
|
:remotesource="remoteSource"
|
|
|
|
|
:selected="selectedRemoteSource && selectedRemoteSource.id == remoteSource.id"
|
2019-05-06 15:58:18 +00:00
|
|
|
v-on:reposelected="repoSelected(remoteSource, $event)"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="field is-grouped">
|
|
|
|
|
<div class="control">
|
2019-05-13 21:48:44 +00:00
|
|
|
<button
|
|
|
|
|
class="button is-primary"
|
|
|
|
|
v-bind:class="{ 'is-loading': createProjectLoading }"
|
|
|
|
|
:disabled="!createProjectButtonEnabled"
|
|
|
|
|
@click="createProject()"
|
|
|
|
|
>Create Project</button>
|
2019-05-06 15:58:18 +00:00
|
|
|
</div>
|
2019-05-13 14:29:47 +00:00
|
|
|
</div>
|
|
|
|
|
<div v-if="createProjectError" class="message is-danger">
|
|
|
|
|
<div class="message-body">{{ createProjectError }}</div>
|
2019-05-06 15:58:18 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import {
|
|
|
|
|
fetchCurrentUser,
|
|
|
|
|
fetchRemoteSources,
|
|
|
|
|
createProject
|
|
|
|
|
} from "@/util/data.js";
|
|
|
|
|
|
|
|
|
|
import { projectLink } from "@/util/link.js";
|
|
|
|
|
|
|
|
|
|
import remoterepos from "@/components/remoterepos.vue";
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
components: { remoterepos },
|
|
|
|
|
name: "createproject",
|
|
|
|
|
props: {
|
|
|
|
|
ownertype: String,
|
|
|
|
|
ownername: String,
|
|
|
|
|
projectgroupref: Array
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2019-05-13 14:29:47 +00:00
|
|
|
createProjectError: null,
|
2019-05-13 21:48:44 +00:00
|
|
|
createProjectLoading: false,
|
|
|
|
|
createProjectLoadingTimeout: null,
|
2019-05-06 15:58:18 +00:00
|
|
|
user: null,
|
|
|
|
|
remoteSources: null,
|
|
|
|
|
remoteRepos: [],
|
2019-05-13 21:48:44 +00:00
|
|
|
projectName: "",
|
2019-05-14 12:24:40 +00:00
|
|
|
projectIsPrivate: false,
|
2019-05-06 15:58:18 +00:00
|
|
|
remoteRepoPath: null,
|
|
|
|
|
selectedRemoteSource: null
|
|
|
|
|
};
|
|
|
|
|
},
|
2019-05-13 21:48:44 +00:00
|
|
|
computed: {
|
|
|
|
|
createProjectButtonEnabled: function() {
|
|
|
|
|
return this.projectName.length && this.selectedRemoteSource;
|
|
|
|
|
}
|
|
|
|
|
},
|
2019-05-06 15:58:18 +00:00
|
|
|
methods: {
|
2019-05-13 14:29:47 +00:00
|
|
|
resetErrors() {
|
|
|
|
|
this.createProjectError = null;
|
|
|
|
|
},
|
2019-05-13 21:48:44 +00:00
|
|
|
startProjectLoading() {
|
|
|
|
|
this.createProjectLoadingTimeout = setTimeout(() => {
|
|
|
|
|
this.createProjectLoading = true;
|
|
|
|
|
}, 300);
|
|
|
|
|
},
|
|
|
|
|
stopProjectLoading() {
|
|
|
|
|
clearTimeout(this.createProjectLoadingTimeout);
|
|
|
|
|
this.createProjectLoading = false;
|
|
|
|
|
},
|
2019-05-06 15:58:18 +00:00
|
|
|
repoSelected(remoteSource, repoPath) {
|
|
|
|
|
this.selectedRemoteSource = remoteSource;
|
|
|
|
|
this.remoteRepoPath = repoPath;
|
|
|
|
|
},
|
|
|
|
|
async createProject() {
|
2019-05-13 14:29:47 +00:00
|
|
|
this.resetErrors();
|
|
|
|
|
|
2019-05-06 15:58:18 +00:00
|
|
|
let refArray = [this.ownertype, this.ownername];
|
|
|
|
|
if (this.projectgroupref) {
|
|
|
|
|
refArray = [...refArray, ...this.projectgroupref];
|
|
|
|
|
}
|
|
|
|
|
let parentref = refArray.join("/");
|
|
|
|
|
|
2019-05-14 12:24:40 +00:00
|
|
|
let visibility = "public";
|
|
|
|
|
if (this.projectIsPrivate) {
|
|
|
|
|
visibility = "private";
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-13 21:48:44 +00:00
|
|
|
this.startProjectLoading();
|
2019-05-13 14:29:47 +00:00
|
|
|
let { error } = await createProject(
|
2019-05-06 15:58:18 +00:00
|
|
|
parentref,
|
|
|
|
|
this.projectName,
|
2019-05-14 12:24:40 +00:00
|
|
|
visibility,
|
2019-05-06 15:58:18 +00:00
|
|
|
this.selectedRemoteSource.name,
|
|
|
|
|
this.remoteRepoPath
|
|
|
|
|
);
|
2019-05-13 21:48:44 +00:00
|
|
|
this.stopProjectLoading();
|
2019-05-13 14:29:47 +00:00
|
|
|
if (error) {
|
|
|
|
|
this.createProjectError = error;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-05-06 15:58:18 +00:00
|
|
|
|
|
|
|
|
let projectref = [this.projectName];
|
|
|
|
|
if (this.projectgroupref) {
|
|
|
|
|
projectref = this.projectgroupref.concat(this.projectName);
|
|
|
|
|
}
|
|
|
|
|
this.$router.push(
|
|
|
|
|
projectLink(this.ownertype, this.ownername, projectref)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created: async function() {
|
2019-05-13 14:29:47 +00:00
|
|
|
let { data, error } = await fetchCurrentUser();
|
|
|
|
|
if (error) {
|
|
|
|
|
this.$store.dispatch("setError", error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.user = data;
|
|
|
|
|
|
2019-05-06 15:58:18 +00:00
|
|
|
// TODO(sgotti) filter only remote source where the user has a linked account
|
2019-05-13 14:29:47 +00:00
|
|
|
({ data, error } = await fetchRemoteSources());
|
|
|
|
|
if (error) {
|
|
|
|
|
this.$store.dispatch("setError", error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.remoteSources = data;
|
2019-05-06 15:58:18 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
@import "@/css/_variables.scss";
|
|
|
|
|
|
|
|
|
|
.item-list {
|
|
|
|
|
.item {
|
|
|
|
|
margin-bottom: 5px;
|
|
|
|
|
border: 1px solid $grey-lighter;
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
display: flex;
|
|
|
|
|
padding: 10px;
|
|
|
|
|
}
|
|
|
|
|
.name {
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-13 14:25:43 +00:00
|
|
|
.remoterepos {
|
|
|
|
|
margin-top: 1rem;
|
|
|
|
|
margin-bottom: 1rem;
|
|
|
|
|
}
|
2019-05-06 15:58:18 +00:00
|
|
|
</style>
|
|
|
|
|
|