mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
199 lines
5.5 KiB
199 lines
5.5 KiB
4 years ago
|
<template>
|
||
|
<div>
|
||
|
<v-toolbar flat height="60" class="toolbar-border-bottom">
|
||
|
<v-text-field
|
||
|
v-model="search"
|
||
|
label="Search"
|
||
|
class="mx-4"
|
||
|
dense
|
||
|
outlined
|
||
|
hide-details
|
||
|
prepend-inner-icon="search"
|
||
3 years ago
|
/>
|
||
4 years ago
|
|
||
3 years ago
|
<v-spacer />
|
||
|
<x-btn
|
||
|
outlined
|
||
3 years ago
|
:tooltip="$t('tooltip.reloadList')"
|
||
3 years ago
|
small
|
||
|
color="primary"
|
||
|
icon="refresh"
|
||
|
btn.class="text-capitalize"
|
||
|
@click="loadRelations"
|
||
|
>
|
||
3 years ago
|
<!-- Reload -->
|
||
|
{{ $t('general.reload') }}
|
||
4 years ago
|
</x-btn>
|
||
3 years ago
|
<!-- <x-btn
|
||
3 years ago
|
outlined
|
||
|
tooltip="Toggle All"
|
||
|
small
|
||
|
color="primary"
|
||
|
btn.class="text-capitalize"
|
||
|
icon="mdi-check-bold"
|
||
|
@click="toggleAll(toggle)"
|
||
|
>
|
||
|
Toggle All {{ toggle ? 'ON' : 'OFF' }}
|
||
3 years ago
|
</x-btn>-->
|
||
3 years ago
|
<x-btn
|
||
|
outlined
|
||
3 years ago
|
:tooltip="$t('tooltip.saveChanges')"
|
||
3 years ago
|
small
|
||
|
:disabled="!edited"
|
||
|
:loading="updating"
|
||
|
btn.class="text-capitalize"
|
||
|
color="primary"
|
||
|
icon="save"
|
||
|
@click="save"
|
||
|
>
|
||
3 years ago
|
<!-- Save -->
|
||
|
{{ $t('general.save') }}
|
||
4 years ago
|
</x-btn>
|
||
|
</v-toolbar>
|
||
|
<div class="d-flex justify-center">
|
||
2 years ago
|
<v-skeleton-loader v-if="loading" type="table" class="flex-shrink-1" style="min-width: 75%" />
|
||
3 years ago
|
<v-data-table
|
||
|
v-else
|
||
|
dense
|
||
|
class="flex-shrink-1"
|
||
2 years ago
|
style="min-width: 75%"
|
||
|
:headers="[{}, {}, {}, { value: 'tn' }, { value: 'rtn' }, {}]"
|
||
3 years ago
|
hide-default-header
|
||
|
:items="relations"
|
||
|
:search="search"
|
||
4 years ago
|
>
|
||
3 years ago
|
<template #header>
|
||
4 years ago
|
<thead>
|
||
3 years ago
|
<tr class="text-left caption">
|
||
2 years ago
|
<th class="grey--text">#</th>
|
||
3 years ago
|
<th class="grey--text">
|
||
|
Table Name <span class="caption grey--text">({{ selectedCount }})</span>
|
||
|
</th>
|
||
2 years ago
|
<th class="grey--text">Relation</th>
|
||
|
<th class="grey--text">Parent</th>
|
||
|
<th class="grey--text">Child</th>
|
||
3 years ago
|
<!-- <th />-->
|
||
3 years ago
|
</tr>
|
||
4 years ago
|
</thead>
|
||
|
</template>
|
||
|
|
||
2 years ago
|
<template #item="{ item, index }">
|
||
4 years ago
|
<tr class="caption">
|
||
|
<td>{{ index + 1 }}</td>
|
||
3 years ago
|
<td>{{ item.relationType === 'hm' ? item.rtn : item.table_name }}</td>
|
||
4 years ago
|
<td>{{ item.relationType === 'hm' ? 'HasMany' : 'BelongsTo' }}</td>
|
||
|
<td>{{ item.rtn }}</td>
|
||
3 years ago
|
<td>{{ item.table_name }}</td>
|
||
3 years ago
|
<!-- <td>
|
||
3 years ago
|
<v-checkbox
|
||
|
v-model="item.enabled"
|
||
|
class=""
|
||
|
dense
|
||
|
hide-details
|
||
|
@change="$set(item,'edited',true)"
|
||
|
/>
|
||
3 years ago
|
</td>-->
|
||
4 years ago
|
</tr>
|
||
|
</template>
|
||
|
</v-data-table>
|
||
|
</div>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
export default {
|
||
3 years ago
|
name: 'DisableOrEnableRelations',
|
||
|
props: ['nodes', 'dbAlias'],
|
||
4 years ago
|
data: () => ({
|
||
|
loading: true,
|
||
|
toggle: true,
|
||
|
updating: false,
|
||
|
relations: [],
|
||
2 years ago
|
search: '',
|
||
4 years ago
|
}),
|
||
3 years ago
|
computed: {
|
||
3 years ago
|
selectedCount() {
|
||
2 years ago
|
return `${this.relations.filter(({ enabled }) => enabled).length}/${this.relations.length}`;
|
||
3 years ago
|
},
|
||
3 years ago
|
edited() {
|
||
2 years ago
|
return this.relations.some(({ edited }) => edited);
|
||
|
},
|
||
3 years ago
|
},
|
||
3 years ago
|
async created() {
|
||
2 years ago
|
await this.loadRelations();
|
||
3 years ago
|
},
|
||
4 years ago
|
methods: {
|
||
3 years ago
|
async loadRelations() {
|
||
2 years ago
|
this.loading = true;
|
||
4 years ago
|
try {
|
||
2 years ago
|
this.relations = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
dbAlias: this.dbAlias,
|
||
|
env: this.$store.getters['project/GtrEnv'],
|
||
|
},
|
||
|
'xcRelationsGet',
|
||
|
]);
|
||
4 years ago
|
} catch (e) {
|
||
2 years ago
|
console.log(e);
|
||
4 years ago
|
}
|
||
2 years ago
|
this.loading = false;
|
||
4 years ago
|
},
|
||
3 years ago
|
toggleAll(toggle) {
|
||
2 years ago
|
this.toggle = !toggle;
|
||
3 years ago
|
for (const rel of this.relations) {
|
||
2 years ago
|
this.$set(rel, 'edited', rel.edited || rel.enabled !== toggle);
|
||
|
this.$set(rel, 'enabled', toggle);
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async save() {
|
||
2 years ago
|
const editedRelations = this.relations.filter(({ edited }) => edited);
|
||
|
this.updating = true;
|
||
4 years ago
|
try {
|
||
2 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
dbAlias: this.dbAlias,
|
||
|
env: this.$store.getters['project/GtrEnv'],
|
||
|
},
|
||
|
'xcRelationsSet',
|
||
|
editedRelations,
|
||
|
]);
|
||
|
this.$toast.success('Relations enabled/disabled successfully').goAway(3000);
|
||
4 years ago
|
for (const rel of this.relations) {
|
||
2 years ago
|
this.$set(rel, 'edited', false);
|
||
4 years ago
|
}
|
||
|
} catch (e) {
|
||
2 years ago
|
this.$toast[e.response?.status === 402 ? 'info' : 'error'](e.message).goAway(3000);
|
||
|
console.log(e.message);
|
||
4 years ago
|
}
|
||
2 years ago
|
this.updating = false;
|
||
|
},
|
||
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
2 years ago
|
<style scoped></style>
|
||
4 years ago
|
<!--
|
||
|
/**
|
||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
|
||
|
*
|
||
|
* @author Naveen MR <oof1lab@gmail.com>
|
||
|
* @author Pranav C Balan <pranavxc@gmail.com>
|
||
|
*
|
||
|
* @license GNU AGPL version 3 or any later version
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|