Skip to content

Commit

Permalink
✨ : add create credentials page
Browse files Browse the repository at this point in the history
  • Loading branch information
juwit committed Jul 12, 2020
1 parent 7e7fcdb commit 5b2ef99
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 129 deletions.
83 changes: 20 additions & 63 deletions src/main/client/app/pages/credentials/credentials-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,21 @@
v-for="credentials in credentialsList"
:key="credentials.id"
:title="credentials.name"
style="max-width: 20rem;"
:header-class="credentials.provider"
>
<template v-slot:header>
<b-img
:src="imageUrl(credentials)"
class="rounded-logo"
rounded="circle"
width="80px"
height="80px"
left
/>
<p class="providerName">
{{ providerName(credentials) }}
</p>
<app-provider-header :provider="credentials.provider" />
</template>

<b-button
:to="{ name: 'credentials', params: { credentialsId: credentials.id } }"
title="Edit this credentials"
variant="primary"
class="mr-1"
>
<font-awesome-icon icon="edit" />
</b-button>
<template v-slot:footer>
<b-button
:to="{ name: 'credentials', params: { credentialsId: credentials.id } }"
title="Edit this credentials"
variant="primary"
class="mr-1"
>
<font-awesome-icon icon="edit" />
</b-button>
</template>
</b-card>
</b-card-group>
</div>
Expand All @@ -47,9 +37,15 @@
<script>
import { getCredentialsList } from '@/shared/api/credentials-api';
import { AppProviderHeader } from '@/shared/components';
export default {
name: 'Credentials',
components: {
AppProviderHeader,
},
data: function data() {
return {
credentialsList: [],
Expand All @@ -59,54 +55,15 @@
async created() {
this.credentialsList = await getCredentialsList();
},
methods: {
imageUrl(credentials) {
// eslint-disable-next-line global-require, import/no-dynamic-require
return require(`@/assets/images/providers/logos/${credentials.provider}.png`);
},
providerName(credentials) {
return {
aws: 'AWS',
google: 'GCP',
azurerm: 'Azure',
}[credentials.provider];
},
},
};
</script>

<style scoped>
.card-header {
display: flex;
align-items: center;
}
.card-header img {
margin-right: 1rem;
}
.card-header.google {
background-color: #2f6fd8;
}
.card-header.aws {
background-color: #ea8c00;
}
.card-header.azurerm {
background-color: #007cc1;
}
.rounded-logo {
background-color: white;
padding: 0;
}
.providerName {
color: white;
font-weight: bold;
font-size: x-large;
.card-title {
margin: 0;
}
</style>
10 changes: 10 additions & 0 deletions src/main/client/app/pages/credentials/credentials-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ const credentialsRoutes = [
title: 'Gaia - Credentials',
},
},
{
path: '/credentials/new',
name: 'new_credentials',
component: () => import(/* webpackChunkName: "chunk-credentials" */ '@/pages/credentials/new-credentials'),
meta: {
authorities: ['ROLE_USER'],
breadcrumb: [{ text: 'Credentials', to: { name: 'credentialsList' } }, { text: 'New Credentials' }],
title: 'Gaia - New credentials edition',
},
},
{
path: '/credentials/:credentialsId',
name: 'credentials',
Expand Down
95 changes: 29 additions & 66 deletions src/main/client/app/pages/credentials/credentials.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,13 @@
<div>
<b-card
v-if="credentials"
:header-class="credentials.provider"
>
<b-card-title>
Credentials : {{ credentials.name }}
</b-card-title>

<template v-slot:header>
<b-img
:src="imageUrl"
class="rounded-logo"
rounded="circle"
width="80px"
height="80px"
left
/>
<p class="providerName">
{{ providerName(credentials) }}
</p>
<app-provider-header :provider="credentials.provider" />
</template>

<b-form-group
Expand Down Expand Up @@ -47,22 +36,24 @@
:credentials="credentials"
/>

<b-button
title="Save"
variant="success"
class="mb-4"
@click="save"
>
<font-awesome-icon icon="save" /> Save
</b-button>
<template v-slot:footer>
<b-button
title="Save"
variant="success"
@click="save"
>
<font-awesome-icon icon="save" /> Save
</b-button>
</template>
</b-card>
</div>
</template>

<script>
import { getCredentials, updateCredentials } from '@/shared/api/credentials-api';
import { getCredentials, createCredentials, updateCredentials } from '@/shared/api/credentials-api';
import { displayNotification } from '@/shared/services/modal-service';
import AppProviderHeader from '@/shared/components/providers/provider-header.vue';
import AppCredentialsAws from '@/pages/credentials/providers/credentials-aws.vue';
import AppCredentialsAzurerm from '@/pages/credentials/providers/credentials-azurerm.vue';
import AppCredentialsGoogle from '@/pages/credentials/providers/credentials-google.vue';
Expand All @@ -74,50 +65,43 @@
AppCredentialsAws,
AppCredentialsAzurerm,
AppCredentialsGoogle,
AppProviderHeader,
},
props: {
credentialsId: {
type: String,
required: true,
default: null,
},
},
data: function data() {
return {
credentials: null,
};
},
computed: {
imageUrl() {
// eslint-disable-next-line global-require, import/no-dynamic-require
return require(`@/assets/images/providers/logos/${this.credentials.provider}.png`);
credentials: {
type: Object,
default: () => null,
},
},
async created() {
this.credentials = await getCredentials(this.credentialsId);
if (this.credentialsId) {
this.credentials = await getCredentials(this.credentialsId);
}
},
methods: {
providerName(credentials) {
return {
aws: 'AWS',
google: 'GCP',
azurerm: 'Azure',
}[credentials.provider];
},
notEmpty(field) {
return typeof field !== 'undefined' && field !== null && field.trim() !== '';
},
async save() {
await updateCredentials(this.credentials)
await this.createOrUpdate()
.then(() => displayNotification(this, { message: 'Credentials saved', variant: 'success' }))
.catch(({ error, message }) => displayNotification(this, { title: error, message, variant: 'danger' }));
},
async createOrUpdate() {
if (!this.credentials.id) {
return createCredentials(this.credentials);
}
return updateCredentials(this.credentials);
},
},
};
Expand All @@ -127,31 +111,10 @@
.card-header {
display: flex;
align-items: center;
padding: 0;
}
.card-header img {
margin-right: 1rem;
}
.card-header.google {
background-color: #2f6fd8;
}
.card-header.aws {
background-color: #ea8c00;
}
.card-header.azurerm {
background-color: #007cc1;
}
.rounded-logo {
background-color: white;
}
.providerName {
color: white;
font-weight: bold;
font-size: x-large;
}
</style>
66 changes: 66 additions & 0 deletions src/main/client/app/pages/credentials/new-credentials.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<template>
<div>
<div v-if="credentials.provider == null">
<h1>Choose Terraform provider</h1>
<b-card-group columns>
<a
v-for="provider in providerList"
:key="provider"
@click="credentials.provider = provider"
>
<b-card
header-class="provider-card"
no-body
>
<template slot="header">
<app-provider-header
:provider="provider"
style="width: 100%;"
/>
</template>
</b-card>
</a>
</b-card-group>
</div>
<app-credentials
v-if="credentials.provider != null"
:credentials="credentials"
/>
</div>
</template>

<script>
import { AppProviderHeader } from '@/shared/components';
import AppCredentials from '@/pages/credentials/credentials.vue';
export default {
name: 'NewCredentials',
components: {
AppProviderHeader,
AppCredentials,
},
data: () => (
{
credentials: {
provider: null,
},
providerList: ['aws', 'azurerm', 'google'],
}
),
};
</script>

<style>
.card-header {
display: flex;
align-items: center;
}
a {
cursor: pointer;
}
.provider-card {
padding: 0;
}
</style>
1 change: 1 addition & 0 deletions src/main/client/app/shared/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export { default as AppFormTypeahead } from '@/shared/components/typeahead/form-
export { default as AppMarkdown } from '@/shared/components/markdown/markdown.vue';
export { default as AppConsole } from '@/shared/components/console/console.vue';
export { default as AppProviderLogo } from '@/shared/components/providers/provider-logo.vue';
export { default as AppProviderHeader } from '@/shared/components/providers/provider-header.vue';
Loading

0 comments on commit 5b2ef99

Please sign in to comment.