2019-05-06 15:58:18 +00:00
|
|
|
<template>
|
|
|
|
|
<div>
|
2019-05-21 10:13:21 +00:00
|
|
|
<h4 class="mb-4 text-xl font-bold">Create Project</h4>
|
|
|
|
|
|
|
|
|
|
<input
|
|
|
|
|
class="mb-4 appearance-none border rounded py-2 px-3 leading-tight focus:outline-none focus:shadow-outline"
|
|
|
|
|
type="text"
|
|
|
|
|
placeholder="Project Name"
|
|
|
|
|
v-model="projectName"
|
|
|
|
|
>
|
|
|
|
|
<div class="mb-4">
|
|
|
|
|
<label>
|
|
|
|
|
<input type="checkbox" v-model="projectIsPrivate">
|
|
|
|
|
Private
|
|
|
|
|
</label>
|
2019-05-14 12:24:40 +00:00
|
|
|
</div>
|
|
|
|
|
|
2019-05-21 15:43:15 +00:00
|
|
|
<div class="mb-3 flex items-center">
|
|
|
|
|
<div class="flex relative w-64">
|
|
|
|
|
<select
|
|
|
|
|
class="block appearance-none w-full bg-white border border-gray-400 hover:border-gray-500 px-4 py-2 pr-8 rounded shadow leading-tight focus:outline-none focus:shadow-outline"
|
|
|
|
|
v-model="selectedRemoteSourceIndex"
|
|
|
|
|
>
|
|
|
|
|
<option :value="null" disabled>Select the remote source</option>
|
|
|
|
|
<option
|
|
|
|
|
v-for="(rs, index) in remoteSources"
|
|
|
|
|
v-bind:key="rs.id"
|
|
|
|
|
:value="index"
|
|
|
|
|
>{{ rs.name }}</option>
|
|
|
|
|
</select>
|
|
|
|
|
<div class="pointer-events-none absolute inset-y-0 right-0 flex items-center px-2">
|
|
|
|
|
<svg class="fill-current h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
|
|
|
|
|
<path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z"></path>
|
|
|
|
|
</svg>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
class="ml-3 btn btn-blue"
|
|
|
|
|
v-bind:class="{ 'spinner': fetchRemoteReposLoading }"
|
|
|
|
|
:disabled="selectedRemoteSourceIndex == null"
|
|
|
|
|
@click="fetchRemoteRepos()"
|
|
|
|
|
>Fetch remote repositories</button>
|
2019-05-06 15:58:18 +00:00
|
|
|
</div>
|
2019-05-21 15:43:15 +00:00
|
|
|
|
|
|
|
|
<div v-if="remoteRepos.length">
|
|
|
|
|
<h4 class="text-xl">Available remote repositories</h4>
|
|
|
|
|
<remoterepos :remoterepos="remoteRepos" v-on:reposelected="repoSelected($event)"/>
|
|
|
|
|
<button
|
|
|
|
|
class="btn btn-blue"
|
|
|
|
|
v-bind:class="{ 'spinner': createProjectLoading }"
|
|
|
|
|
:disabled="!createProjectButtonEnabled"
|
|
|
|
|
@click="createProject()"
|
|
|
|
|
>Create Project</button>
|
|
|
|
|
<div
|
|
|
|
|
v-if="createProjectError"
|
|
|
|
|
class="mb-10 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative"
|
|
|
|
|
role="alert"
|
|
|
|
|
>
|
|
|
|
|
<span class="block sm:inline">{{ createProjectError }}</span>
|
|
|
|
|
</div>
|
2019-05-06 15:58:18 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import {
|
|
|
|
|
fetchCurrentUser,
|
|
|
|
|
fetchRemoteSources,
|
2019-05-21 15:43:15 +00:00
|
|
|
createProject,
|
|
|
|
|
userRemoteRepos
|
2019-05-06 15:58:18 +00:00
|
|
|
} 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-21 15:43:15 +00:00
|
|
|
fetchRemoteReposLoading: false,
|
|
|
|
|
fetchRemoteReposLoadingTimeout: false,
|
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-21 15:43:15 +00:00
|
|
|
selectedRemoteSourceIndex: null,
|
2019-05-13 21:48:44 +00:00
|
|
|
projectName: "",
|
2019-05-14 12:24:40 +00:00
|
|
|
projectIsPrivate: false,
|
2019-05-21 15:43:15 +00:00
|
|
|
remoteRepoPath: null
|
2019-05-06 15:58:18 +00:00
|
|
|
};
|
|
|
|
|
},
|
2019-05-13 21:48:44 +00:00
|
|
|
computed: {
|
|
|
|
|
createProjectButtonEnabled: function() {
|
2019-05-21 15:43:15 +00:00
|
|
|
return this.projectName.length && this.remoteRepoPath;
|
2019-05-13 21:48:44 +00:00
|
|
|
}
|
|
|
|
|
},
|
2019-05-21 15:43:15 +00:00
|
|
|
watch: {},
|
2019-05-06 15:58:18 +00:00
|
|
|
methods: {
|
2019-05-13 14:29:47 +00:00
|
|
|
resetErrors() {
|
|
|
|
|
this.createProjectError = null;
|
|
|
|
|
},
|
2019-05-21 15:43:15 +00:00
|
|
|
startFetchRemoteReposLoading() {
|
|
|
|
|
this.fetchRemoteReposLoadingTimeout = setTimeout(() => {
|
|
|
|
|
this.fetchRemoteReposLoading = true;
|
|
|
|
|
}, 300);
|
|
|
|
|
},
|
|
|
|
|
stopFetchRemoteReposLoading() {
|
|
|
|
|
clearTimeout(this.fetchRemoteReposLoadingTimeout);
|
|
|
|
|
this.fetchRemoteReposLoading = false;
|
|
|
|
|
},
|
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-21 15:43:15 +00:00
|
|
|
repoSelected(repoPath) {
|
2019-05-06 15:58:18 +00:00
|
|
|
this.remoteRepoPath = repoPath;
|
|
|
|
|
},
|
2019-05-21 15:43:15 +00:00
|
|
|
async fetchRemoteRepos() {
|
|
|
|
|
this.remoteRepos = [];
|
|
|
|
|
this.remoteRepoPath = null;
|
|
|
|
|
|
|
|
|
|
this.startFetchRemoteReposLoading();
|
|
|
|
|
let remoteSource = this.remoteSources[this.selectedRemoteSourceIndex];
|
|
|
|
|
let { data, error } = await userRemoteRepos(remoteSource.id);
|
|
|
|
|
this.stopFetchRemoteReposLoading();
|
|
|
|
|
if (error) {
|
|
|
|
|
this.$store.dispatch("setError", error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this.remoteRepos = data;
|
|
|
|
|
},
|
2019-05-06 15:58:18 +00:00
|
|
|
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-21 15:43:15 +00:00
|
|
|
let remoteSource = this.remoteSources[this.selectedRemoteSourceIndex];
|
|
|
|
|
|
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-21 15:43:15 +00:00
|
|
|
remoteSource.name,
|
2019-05-06 15:58:18 +00:00
|
|
|
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;
|
|
|
|
|
}
|
2019-05-15 22:35:11 +00:00
|
|
|
|
|
|
|
|
let allRemoteSources = data;
|
|
|
|
|
let remoteSources = [];
|
|
|
|
|
for (var i = 0; i < allRemoteSources.length; i++) {
|
|
|
|
|
for (var j = 0; j < this.user.linked_accounts.length; j++) {
|
|
|
|
|
let remotesource = allRemoteSources[i];
|
|
|
|
|
let la = this.user.linked_accounts[j];
|
|
|
|
|
if (la.remote_source_id == remotesource.id) {
|
|
|
|
|
remoteSources.push(remotesource);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.remoteSources = remoteSources;
|
|
|
|
|
}
|
2019-05-06 15:58:18 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
</style>
|
|
|
|
|
|