2017-04-28 12:06:19 -04:00
|
|
|
<script>
|
2018-05-07 14:21:34 -04:00
|
|
|
import { s__ } from '~/locale';
|
|
|
|
import Flash from '~/flash';
|
|
|
|
import NavigationTabs from '~/vue_shared/components/navigation_tabs.vue';
|
|
|
|
import eventHub from '../eventhub';
|
|
|
|
import DeployKeysService from '../service';
|
|
|
|
import DeployKeysStore from '../store';
|
|
|
|
import KeysPanel from './keys_panel.vue';
|
2017-04-28 12:06:19 -04:00
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
KeysPanel,
|
|
|
|
NavigationTabs,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
endpoint: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
2017-04-28 12:06:19 -04:00
|
|
|
},
|
2018-05-07 14:21:34 -04:00
|
|
|
projectId: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
2017-04-28 12:06:19 -04:00
|
|
|
},
|
2018-05-07 14:21:34 -04:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
currentTab: 'enabled_keys',
|
|
|
|
isLoading: false,
|
|
|
|
store: new DeployKeysStore(),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
scopes: {
|
|
|
|
enabled_keys: s__('DeployKeys|Enabled deploy keys'),
|
|
|
|
available_project_keys: s__('DeployKeys|Privately accessible deploy keys'),
|
|
|
|
public_keys: s__('DeployKeys|Publicly accessible deploy keys'),
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
tabs() {
|
|
|
|
return Object.keys(this.$options.scopes).map(scope => {
|
|
|
|
const count = Array.isArray(this.keys[scope]) ? this.keys[scope].length : null;
|
|
|
|
|
|
|
|
return {
|
|
|
|
name: this.$options.scopes[scope],
|
|
|
|
scope,
|
|
|
|
isActive: scope === this.currentTab,
|
|
|
|
count,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
},
|
|
|
|
hasKeys() {
|
|
|
|
return Object.keys(this.keys).length;
|
2018-01-05 09:31:01 -05:00
|
|
|
},
|
2018-05-07 14:21:34 -04:00
|
|
|
keys() {
|
|
|
|
return this.store.keys;
|
2017-04-28 12:06:19 -04:00
|
|
|
},
|
2018-05-07 14:21:34 -04:00
|
|
|
},
|
|
|
|
created() {
|
|
|
|
this.service = new DeployKeysService(this.endpoint);
|
2018-01-05 09:31:01 -05:00
|
|
|
|
2018-05-07 14:21:34 -04:00
|
|
|
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);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onChangeTab(tab) {
|
|
|
|
this.currentTab = tab;
|
2018-01-05 09:31:01 -05:00
|
|
|
},
|
2018-05-07 14:21:34 -04:00
|
|
|
fetchKeys() {
|
|
|
|
this.isLoading = true;
|
|
|
|
|
|
|
|
return this.service
|
|
|
|
.getKeys()
|
|
|
|
.then(data => {
|
|
|
|
this.isLoading = false;
|
|
|
|
this.store.keys = data;
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.isLoading = false;
|
|
|
|
this.store.keys = {};
|
|
|
|
return new Flash(s__('DeployKeys|Error getting deploy keys'));
|
|
|
|
});
|
2018-01-05 09:31:01 -05:00
|
|
|
},
|
2018-05-07 14:21:34 -04:00
|
|
|
enableKey(deployKey) {
|
|
|
|
this.service
|
|
|
|
.enableKey(deployKey.id)
|
|
|
|
.then(this.fetchKeys)
|
|
|
|
.catch(() => new Flash(s__('DeployKeys|Error enabling deploy key')));
|
2017-04-28 12:06:19 -04:00
|
|
|
},
|
2018-05-07 14:21:34 -04:00
|
|
|
disableKey(deployKey, callback) {
|
|
|
|
// eslint-disable-next-line no-alert
|
2018-06-15 11:58:27 -04:00
|
|
|
if (window.confirm(s__('DeployKeys|You are going to remove this deploy key. Are you sure?'))) {
|
2018-05-07 14:21:34 -04:00
|
|
|
this.service
|
|
|
|
.disableKey(deployKey.id)
|
|
|
|
.then(this.fetchKeys)
|
|
|
|
.then(callback)
|
|
|
|
.catch(() => new Flash(s__('DeployKeys|Error removing deploy key')));
|
|
|
|
} else {
|
|
|
|
callback();
|
|
|
|
}
|
2017-04-28 12:06:19 -04:00
|
|
|
},
|
2018-05-07 14:21:34 -04:00
|
|
|
},
|
|
|
|
};
|
2017-04-28 12:06:19 -04:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2017-06-07 04:11:44 -04:00
|
|
|
<div class="append-bottom-default deploy-keys">
|
2018-09-11 18:19:21 -04:00
|
|
|
<gl-loading-icon
|
2017-05-10 11:52:09 -04:00
|
|
|
v-if="isLoading && !hasKeys"
|
2018-05-07 14:21:34 -04:00
|
|
|
:label="s__('DeployKeys|Loading deploy keys')"
|
2018-09-11 18:19:21 -04:00
|
|
|
:size="2"
|
2017-03-31 08:54:38 -04:00
|
|
|
/>
|
2018-05-07 14:21:34 -04:00
|
|
|
<template v-else-if="hasKeys">
|
|
|
|
<div class="top-area scrolling-tabs-container inner-page-scroll-tabs">
|
|
|
|
<div class="fade-left">
|
|
|
|
<i
|
|
|
|
class="fa fa-angle-left"
|
|
|
|
aria-hidden="true"
|
|
|
|
>
|
|
|
|
</i>
|
|
|
|
</div>
|
|
|
|
<div class="fade-right">
|
|
|
|
<i
|
|
|
|
class="fa fa-angle-right"
|
|
|
|
aria-hidden="true"
|
|
|
|
>
|
|
|
|
</i>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<navigation-tabs
|
|
|
|
:tabs="tabs"
|
|
|
|
scope="deployKeys"
|
2018-06-11 05:49:47 -04:00
|
|
|
@onChangeTab="onChangeTab"
|
2018-05-07 14:21:34 -04:00
|
|
|
/>
|
|
|
|
</div>
|
2017-04-28 12:06:19 -04:00
|
|
|
<keys-panel
|
2018-05-07 14:21:34 -04:00
|
|
|
:project-id="projectId"
|
|
|
|
:keys="keys[currentTab]"
|
2017-03-31 08:54:38 -04:00
|
|
|
:store="store"
|
|
|
|
:endpoint="endpoint"
|
2018-06-11 05:49:47 -04:00
|
|
|
class="qa-project-deploy-keys"
|
2017-03-31 08:54:38 -04:00
|
|
|
/>
|
2018-05-07 14:21:34 -04:00
|
|
|
</template>
|
2017-04-28 12:06:19 -04:00
|
|
|
</div>
|
|
|
|
</template>
|