summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-03-24 21:28:03 +0100
committerGitHub <noreply@github.com>2021-03-24 21:28:03 +0100
commite75b3fe8cc54f62d6c6dc6b3a0c98c2c7640017f (patch)
treea4d29f81306c519f21464c2d257a4e1f726db68a /src
parent7075b22bda0da70108f150208a8b8f0898854eb1 (diff)
parent298076829936818ad95e5a9de4b57c81158779d2 (diff)
Merge pull request #13 from gico-net/feat/add-repo
Add repository if does not exists
Diffstat (limited to 'src')
-rw-r--r--src/sass/_bootstrap.sass3
-rw-r--r--src/store.js15
-rw-r--r--src/views/Repository.vue55
-rw-r--r--src/views/Search.vue2
4 files changed, 72 insertions, 3 deletions
diff --git a/src/sass/_bootstrap.sass b/src/sass/_bootstrap.sass
index c83c1eb..4fbcb1c 100644
--- a/src/sass/_bootstrap.sass
+++ b/src/sass/_bootstrap.sass
@@ -26,3 +26,6 @@ h2
@media (max-width: 768px)
@content
+.toast-header
+ padding-bottom: 0
+ margin-bottom: 0
diff --git a/src/store.js b/src/store.js
index 1483402..51dfc91 100644
--- a/src/store.js
+++ b/src/store.js
@@ -134,6 +134,21 @@ export default new Vuex.Store({
async set_committer({commit}, avatar) {
commit('load_committer_avatar', avatar);
},
+ // Add new repository
+ async add_repo({commit}, payload) {
+ commit('loading_state', true)
+ let res
+ await fetch(`${this.state.api}/repo/`, {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(payload),
+ })
+ .then(async response => {
+ res = await response.json()
+ })
+ commit('loading_state', false)
+ return res
+ },
// Set loading state
async set_loading({commit}, status) {
commit('loading_state', status);
diff --git a/src/views/Repository.vue b/src/views/Repository.vue
index ade55d3..abb40a9 100644
--- a/src/views/Repository.vue
+++ b/src/views/Repository.vue
@@ -14,13 +14,27 @@
i.fab.fa-github
section(v-if="commits.length > 0")
.commit.no-hover
- h2 Commits found {{ (commits.length == 1000)?"1000+":commits.length }}
+ h2 Commits found: {{ (commits.length == 1000)?"1000+":commits.length }}
commit-card(
v-for="i in commits" :key="i.hash" :data="i"
:author="emails[i.author_email]"
:committer="emails[i.committer_email]"
:expand="true"
)
+ section(v-else)
+ b-modal#new-repo(
+ @ok="add_new_repo()"
+ ok-title="Add"
+ ok-variant="outline-success"
+ cancel-variant="outline-dark"
+ )
+ <template #modal-title>Add {{ user }}/{{ name }} on Gico!</template>
+ b-form-group(label="Insert the branch name")
+ b-form-input(v-model="form.branch" placeholder="main")
+ .commit.no-hover
+ b-button(variant="outline-success" v-b-modal.new-repo)
+ | Add this repository on Gico
+ i.fas.fa-plus
</template>
<script>
@@ -36,7 +50,9 @@ export default {
},
data() {
return {
- error404: false
+ form: {
+ branch: undefined
+ }
}
},
async mounted() {
@@ -55,5 +71,40 @@ export default {
return this.$store.getters.emails;
},
},
+ methods: {
+ add_new_repo() {
+ this.$store.dispatch('add_repo', {
+ url: `github.com/${this.user}/${this.name}`,
+ branch: this.form.branch || "main"
+ }).then(response => {
+ if(response.detail) {
+ this.$bvToast.toast(response.detail, {
+ title: 'Error!',
+ autoHideDelay: 5000,
+ variant: 'danger',
+ appendToast: true
+ })
+ } else if(response.id) {
+ this.$bvToast.toast(response.url, {
+ title: 'Repository created!',
+ autoHideDelay: 5000,
+ variant: 'success',
+ appendToast: true
+ })
+ window.setTimeout(() => {
+ window.location.href="/repo/"+response.url
+ }, 1000)
+ } else {
+ this.$bvToast.toast("", {
+ title: 'Error!',
+ autoHideDelay: 5000,
+ variant: 'danger',
+ appendToast: true
+ })
+ }
+ })
+
+ }
+ }
}
</script>
diff --git a/src/views/Search.vue b/src/views/Search.vue
index 5cbfe33..50f922c 100644
--- a/src/views/Search.vue
+++ b/src/views/Search.vue
@@ -5,7 +5,7 @@
b-overlay(:show="true" spinner-large)
b-container(v-else)
.commit.no-hover
- h2 Commits found {{ commits.length }}
+ h2 Commits found: {{ commits.length }}
.commit.no-hover(style="padding: 50px" v-if="loading")
b-overlay(:show="true" spinner-large)
commit-card(