debian-mirror-gitlab/app/assets/javascripts/deploy_keys/components/app.vue

111 lines
2.9 KiB
Vue
Raw Normal View History

2017-08-17 22:00:37 +05:30
<script>
2018-03-17 18:26:18 +05:30
import Flash from '../../flash';
2017-08-17 22:00:37 +05:30
import eventHub from '../eventhub';
import DeployKeysService from '../service';
import DeployKeysStore from '../store';
import keysPanel from './keys_panel.vue';
2017-09-10 17:25:29 +05:30
import loadingIcon from '../../vue_shared/components/loading_icon.vue';
2017-08-17 22:00:37 +05:30
export default {
2018-03-17 18:26:18 +05:30
components: {
keysPanel,
loadingIcon,
2017-08-17 22:00:37 +05:30
},
props: {
endpoint: {
type: String,
required: true,
},
},
2018-03-17 18:26:18 +05:30
data() {
return {
isLoading: false,
store: new DeployKeysStore(),
};
},
2017-08-17 22:00:37 +05:30
computed: {
hasKeys() {
return Object.keys(this.keys).length;
},
keys() {
return this.store.keys;
},
},
2018-03-17 18:26:18 +05:30
created() {
this.service = new DeployKeysService(this.endpoint);
eventHub.$on('enable.key', this.enableKey);
eventHub.$on('remove.key', this.disableKey);
eventHub.$on('disable.key', this.disableKey);
},
mounted() {
this.fetchKeys();
},
beforeDestroy() {
eventHub.$off('enable.key', this.enableKey);
eventHub.$off('remove.key', this.disableKey);
eventHub.$off('disable.key', this.disableKey);
2017-08-17 22:00:37 +05:30
},
methods: {
fetchKeys() {
this.isLoading = true;
this.service.getKeys()
.then((data) => {
this.isLoading = false;
this.store.keys = data;
})
.catch(() => new Flash('Error getting deploy keys'));
},
enableKey(deployKey) {
this.service.enableKey(deployKey.id)
.then(() => this.fetchKeys())
.catch(() => new Flash('Error enabling deploy key'));
},
2018-03-17 18:26:18 +05:30
disableKey(deployKey, callback) {
2017-08-17 22:00:37 +05:30
// eslint-disable-next-line no-alert
if (confirm('You are going to remove this deploy key. Are you sure?')) {
this.service.disableKey(deployKey.id)
.then(() => this.fetchKeys())
2018-03-17 18:26:18 +05:30
.then(callback)
2017-08-17 22:00:37 +05:30
.catch(() => new Flash('Error removing deploy key'));
2018-03-17 18:26:18 +05:30
} else {
callback();
2017-08-17 22:00:37 +05:30
}
},
},
};
</script>
<template>
2017-09-10 17:25:29 +05:30
<div class="append-bottom-default deploy-keys">
<loading-icon
v-if="isLoading && !hasKeys"
size="2"
label="Loading deploy keys"
/>
2017-08-17 22:00:37 +05:30
<div v-else-if="hasKeys">
<keys-panel
title="Enabled deploy keys for this project"
2018-03-17 18:26:18 +05:30
class="qa-project-deploy-keys"
2017-08-17 22:00:37 +05:30
:keys="keys.enabled_keys"
2017-09-10 17:25:29 +05:30
:store="store"
:endpoint="endpoint"
/>
2017-08-17 22:00:37 +05:30
<keys-panel
title="Deploy keys from projects you have access to"
:keys="keys.available_project_keys"
2017-09-10 17:25:29 +05:30
:store="store"
:endpoint="endpoint"
/>
2017-08-17 22:00:37 +05:30
<keys-panel
v-if="keys.public_keys.length"
title="Public deploy keys available to any project"
:keys="keys.public_keys"
2017-09-10 17:25:29 +05:30
:store="store"
:endpoint="endpoint"
/>
2017-08-17 22:00:37 +05:30
</div>
</div>
</template>