2018-08-22 04:47:01 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div v-if="loading">
|
|
|
|
<div class="spinner spinner-xl blue"></div>
|
|
|
|
</div>
|
2018-08-26 21:03:43 +00:00
|
|
|
<div class="animate fadein" v-else>
|
2018-08-26 21:11:18 +00:00
|
|
|
<div class="content-box mb-6" v-if="!databases.length">
|
2018-08-26 21:03:43 +00:00
|
|
|
<div class="flex items-center">
|
|
|
|
<database-icon class="flex-none text-grey-darker"></database-icon>
|
|
|
|
<div class="flex-1 px-4 text-grey-darker">
|
|
|
|
<p>You have no databases.</p>
|
|
|
|
</div>
|
2018-08-22 04:47:01 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-08-26 21:03:43 +00:00
|
|
|
<div v-else>
|
|
|
|
<database-row v-for="database in databases" :database="database" :key="database.name"/>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<button class="btn btn-blue btn-lg" v-on:click="showCreateModal = true">Create new database</button>
|
|
|
|
</div>
|
|
|
|
<modal :show="showCreateModal" v-on:close="showCreateModal = false">
|
|
|
|
<create-database-modal
|
|
|
|
v-on:close="showCreateModal = false"
|
|
|
|
v-on:database="handleModalCallback"
|
|
|
|
v-if="showCreateModal"
|
|
|
|
/>
|
|
|
|
</modal>
|
2018-08-22 04:47:01 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2018-12-30 03:24:52 +00:00
|
|
|
<script>
|
2018-08-25 21:43:21 +00:00
|
|
|
import { DatabaseIcon, LockIcon, Trash2Icon } from 'vue-feather-icons';
|
2018-08-22 04:47:01 +00:00
|
|
|
import map from 'lodash/map';
|
2018-08-26 21:01:00 +00:00
|
|
|
import filter from 'lodash/filter';
|
2018-08-23 05:29:20 +00:00
|
|
|
import Modal from '../../core/Modal';
|
2018-08-26 21:01:00 +00:00
|
|
|
import CreateDatabaseModal from '../components/database/CreateDatabaseModal';
|
|
|
|
import DatabaseRow from '../components/database/DatabaseRow';
|
2018-08-22 04:47:01 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'databases-page',
|
2018-08-26 21:01:00 +00:00
|
|
|
components: {DatabaseRow, CreateDatabaseModal, Modal, DatabaseIcon, LockIcon, Trash2Icon },
|
2018-08-22 04:47:01 +00:00
|
|
|
|
|
|
|
data: function () {
|
|
|
|
return {
|
|
|
|
databases: [],
|
2018-08-23 05:29:20 +00:00
|
|
|
loading: true,
|
|
|
|
showCreateModal: false,
|
2018-08-22 04:47:01 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted: function () {
|
|
|
|
this.getDatabases();
|
2018-08-26 21:01:00 +00:00
|
|
|
|
|
|
|
window.events.$on('server:deleted-database', this.removeDatabase);
|
2018-08-22 04:47:01 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
/**
|
|
|
|
* Get all of the databases that exist for this server.
|
|
|
|
*/
|
|
|
|
getDatabases: function () {
|
|
|
|
this.clearFlashes();
|
|
|
|
this.loading = true;
|
|
|
|
|
|
|
|
window.axios.get(this.route('api.client.servers.databases', {
|
|
|
|
server: this.$route.params.id,
|
|
|
|
include: 'password'
|
|
|
|
}))
|
|
|
|
.then(response => {
|
|
|
|
this.databases = map(response.data.data, (object) => {
|
|
|
|
const data = object.attributes;
|
|
|
|
|
|
|
|
data.password = data.relationships.password.attributes.password;
|
|
|
|
data.showPassword = false;
|
|
|
|
delete data.relationships;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
this.error('There was an error encountered while attempting to fetch databases for this server.');
|
|
|
|
console.error(err);
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-08-23 05:29:20 +00:00
|
|
|
/**
|
|
|
|
* Add the database to the list of existing databases automatically when the modal
|
|
|
|
* is closed with a successful callback.
|
|
|
|
*/
|
|
|
|
handleModalCallback: function (object) {
|
|
|
|
const data = object;
|
|
|
|
data.password = data.relationships.password.attributes.password;
|
|
|
|
data.showPassword = false;
|
|
|
|
|
|
|
|
delete data.relationships;
|
|
|
|
|
|
|
|
this.databases.push(data);
|
|
|
|
},
|
|
|
|
|
2018-08-22 04:47:01 +00:00
|
|
|
/**
|
2018-08-26 21:01:00 +00:00
|
|
|
* Handle event that is removing a database.
|
2018-08-22 04:47:01 +00:00
|
|
|
*
|
2018-08-26 21:01:00 +00:00
|
|
|
* @param databaseId
|
2018-08-22 04:47:01 +00:00
|
|
|
*/
|
2018-08-26 21:01:00 +00:00
|
|
|
removeDatabase: function (databaseId) {
|
|
|
|
this.databases = filter(this.databases, (database) => {
|
|
|
|
return database.id !== databaseId;
|
2018-08-22 04:47:01 +00:00
|
|
|
});
|
2018-08-26 21:01:00 +00:00
|
|
|
}
|
2018-08-22 04:47:01 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|