From 26d52478468b55fcd313bcd0fa5bccf22dba4e45 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Tue, 21 May 2019 17:43:15 +0200 Subject: [PATCH] createproject: improve remote repos selection Use a select to choose the remote source and fetch remote repos only for that remote source --- src/components/createproject.vue | 104 +++++++++++++++++++++++-------- src/components/remoterepos.vue | 25 +------- 2 files changed, 80 insertions(+), 49 deletions(-) diff --git a/src/components/createproject.vue b/src/components/createproject.vue index b4ac3b8..26e4c0c 100644 --- a/src/components/createproject.vue +++ b/src/components/createproject.vue @@ -15,27 +15,49 @@ -

Available remote repositories

-
- +
+
+ +
+ + + +
+
+
- - @@ -44,7 +66,8 @@ import { fetchCurrentUser, fetchRemoteSources, - createProject + createProject, + userRemoteRepos } from "@/util/data.js"; import { projectLink } from "@/util/link.js"; @@ -62,26 +85,38 @@ export default { data() { return { createProjectError: null, + fetchRemoteReposLoading: false, + fetchRemoteReposLoadingTimeout: false, createProjectLoading: false, createProjectLoadingTimeout: null, user: null, remoteSources: null, remoteRepos: [], + selectedRemoteSourceIndex: null, projectName: "", projectIsPrivate: false, - remoteRepoPath: null, - selectedRemoteSource: null + remoteRepoPath: null }; }, computed: { createProjectButtonEnabled: function() { - return this.projectName.length && this.selectedRemoteSource; + return this.projectName.length && this.remoteRepoPath; } }, + watch: {}, methods: { resetErrors() { this.createProjectError = null; }, + startFetchRemoteReposLoading() { + this.fetchRemoteReposLoadingTimeout = setTimeout(() => { + this.fetchRemoteReposLoading = true; + }, 300); + }, + stopFetchRemoteReposLoading() { + clearTimeout(this.fetchRemoteReposLoadingTimeout); + this.fetchRemoteReposLoading = false; + }, startProjectLoading() { this.createProjectLoadingTimeout = setTimeout(() => { this.createProjectLoading = true; @@ -91,10 +126,23 @@ export default { clearTimeout(this.createProjectLoadingTimeout); this.createProjectLoading = false; }, - repoSelected(remoteSource, repoPath) { - this.selectedRemoteSource = remoteSource; + repoSelected(repoPath) { this.remoteRepoPath = repoPath; }, + 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; + }, async createProject() { this.resetErrors(); @@ -109,12 +157,14 @@ export default { visibility = "private"; } + let remoteSource = this.remoteSources[this.selectedRemoteSourceIndex]; + this.startProjectLoading(); let { error } = await createProject( parentref, this.projectName, visibility, - this.selectedRemoteSource.name, + remoteSource.name, this.remoteRepoPath ); this.stopProjectLoading(); diff --git a/src/components/remoterepos.vue b/src/components/remoterepos.vue index 7f86208..5b85d45 100644 --- a/src/components/remoterepos.vue +++ b/src/components/remoterepos.vue @@ -1,9 +1,5 @@