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.
385 lines
11 KiB
385 lines
11 KiB
4 years ago
|
<template>
|
||
|
<div class="graphql-logic">
|
||
|
<v-toolbar flat height="42" class="toolbar-border-bottom">
|
||
|
<v-toolbar-title>
|
||
3 years ago
|
<v-breadcrumbs
|
||
3 years ago
|
:items="[
|
||
|
{
|
||
|
text: nodes.env,
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
{
|
||
|
text: nodes.dbAlias,
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
{
|
||
|
text: (nodes.table_name || nodes.view_name) + ' (APIs)',
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
]"
|
||
3 years ago
|
divider=">"
|
||
|
small
|
||
|
>
|
||
|
<template #divider>
|
||
3 years ago
|
<v-icon small color="grey lighten-2"> forward </v-icon>
|
||
4 years ago
|
</template>
|
||
|
</v-breadcrumbs>
|
||
|
</v-toolbar-title>
|
||
3 years ago
|
<v-spacer />
|
||
|
<v-btn small outlined class="caption text-capitalize" color="primary" @click="showSwagger = !showSwagger">
|
||
|
<v-icon small color="primary">
|
||
3 years ago
|
{{ showSwagger ? 'mdi-eye-off-outline' : 'mdi-eye-outline' }}
|
||
|
</v-icon>
|
||
|
|
||
3 years ago
|
|
||
|
{{ showSwagger ? 'Hide Schema' : 'Show Schema' }}
|
||
|
</v-btn>
|
||
|
<x-btn
|
||
3 years ago
|
v-ge="['rows', 'reload']"
|
||
3 years ago
|
outlined
|
||
|
tooltip="Reload Rows"
|
||
|
color="primary"
|
||
|
small
|
||
3 years ago
|
@click="
|
||
|
loadSchema();
|
||
|
loadResolvers();
|
||
|
"
|
||
3 years ago
|
>
|
||
3 years ago
|
<v-icon small left> refresh </v-icon>
|
||
3 years ago
|
<!-- Reload -->
|
||
|
{{ $t('general.reload') }}
|
||
4 years ago
|
</x-btn>
|
||
|
</v-toolbar>
|
||
|
|
||
|
<v-row class="mx-0" align="stretch">
|
||
|
<v-col v-if="showSwagger">
|
||
|
<v-card class="flex-shrink-1">
|
||
|
<div class="text-center" style="padding: 3px">
|
||
|
<span class="title schema-card-title">Schema</span>
|
||
|
</div>
|
||
|
<div class="d-flex pa-3">
|
||
3 years ago
|
<v-spacer />
|
||
|
|
||
|
<x-btn
|
||
|
outlined
|
||
3 years ago
|
:tooltip="`Compare GQL schema history of ${nodes.table_name}`"
|
||
3 years ago
|
color="primary"
|
||
|
x-small
|
||
|
:disabled="loading || !schemaHistory.length"
|
||
|
@click.prevent="schemaDiffDialog = true"
|
||
|
>
|
||
3 years ago
|
<v-icon small left> mdi-source-branch </v-icon>
|
||
3 years ago
|
History <span v-if="schemaHistory.length" class="history-count">({{ schemaHistory.length }})</span>
|
||
4 years ago
|
</x-btn>
|
||
3 years ago
|
<x-btn
|
||
3 years ago
|
v-ge="['rows', 'save']"
|
||
3 years ago
|
outlined
|
||
3 years ago
|
:tooltip="$t('tooltip.saveChanges')"
|
||
3 years ago
|
color="primary"
|
||
|
x-small
|
||
|
:disabled="loading"
|
||
|
@click.prevent="saveSchema"
|
||
|
>
|
||
3 years ago
|
<v-icon small left> save </v-icon>
|
||
3 years ago
|
<!-- Save -->
|
||
|
{{ $t('general.save') }}
|
||
4 years ago
|
</x-btn>
|
||
|
</div>
|
||
3 years ago
|
<monaco-editor v-model="schema" theme="" style="min-height: 500px" />
|
||
4 years ago
|
</v-card>
|
||
|
</v-col>
|
||
|
<v-col>
|
||
3 years ago
|
<v-card v-if="filteredData.length" class="flex-shrink-1" style="">
|
||
4 years ago
|
<div class="text-center" style="padding: 3px">
|
||
|
<span class="title schema-card-title">Resolvers & Middlewares</span>
|
||
|
</div>
|
||
|
<v-simple-table v-if="resolvers" dense>
|
||
|
<!-- style="width: auto; min-width: 500px">-->
|
||
|
<thead>
|
||
3 years ago
|
<!-- <tr>-->
|
||
|
|
||
|
<!-- <th colspan="3" class="text-center">-->
|
||
|
|
||
|
<!-- <div class="text-center">-->
|
||
|
|
||
|
<!-- <span class="title card-title">Resolvers</span>-->
|
||
|
<!-- </div>-->
|
||
|
|
||
|
<!-- </th>-->
|
||
|
|
||
|
<!-- </tr>-->
|
||
|
<tr>
|
||
|
<th colspan="3" class="text-center">
|
||
|
<v-text-field
|
||
|
v-model="search"
|
||
|
dense
|
||
|
hide-details
|
||
|
class="ma-2"
|
||
3 years ago
|
:placeholder="`Search '${nodes.table_name}' resolvers`"
|
||
3 years ago
|
prepend-inner-icon="search"
|
||
|
outlined
|
||
|
/>
|
||
|
</th>
|
||
|
</tr>
|
||
4 years ago
|
</thead>
|
||
|
<tbody>
|
||
3 years ago
|
<template v-for="({ resolver, title, functions }, i) in filteredData">
|
||
|
<tr v-if="resolver" :key="i">
|
||
3 years ago
|
<td width="20" class="px-0" />
|
||
|
<td class="pl-0">
|
||
|
<v-tooltip bottom>
|
||
|
<template #activator="{ on }">
|
||
|
<span v-on="on">{{ resolver }}</span>
|
||
|
</template>
|
||
|
<span>{{ resolver }}</span>
|
||
|
</v-tooltip>
|
||
|
</td>
|
||
3 years ago
|
<td width="60" class="pa-1 text-center method-cell">
|
||
3 years ago
|
<v-tooltip bottom>
|
||
|
<template #activator="{ on }">
|
||
|
<v-hover v-slot="{ hover }">
|
||
|
<v-icon
|
||
|
small
|
||
3 years ago
|
:color="hover ? 'primary' : ''"
|
||
|
@click="showSourceCode(resolver, functions)"
|
||
3 years ago
|
v-on="on"
|
||
|
>
|
||
|
mdi-pencil
|
||
|
</v-icon>
|
||
|
</v-hover>
|
||
|
</template>
|
||
|
Edit business logic
|
||
|
</v-tooltip>
|
||
|
</td>
|
||
|
</tr>
|
||
3 years ago
|
<tr v-else :key="i">
|
||
3 years ago
|
<td width="20" class="px-0" />
|
||
|
<td class="pl-0">
|
||
|
<v-tooltip bottom>
|
||
|
<template #activator="{ on }">
|
||
|
<span class="" v-on="on">{{ title }} - Middleware</span>
|
||
|
</template>
|
||
|
<span>{{ title }} - Middleware</span>
|
||
|
</v-tooltip>
|
||
|
</td>
|
||
3 years ago
|
<td width="60" class="pa-1 text-center method-cell">
|
||
3 years ago
|
<v-tooltip bottom>
|
||
|
<template #activator="{ on }">
|
||
|
<v-hover v-slot="{ hover }">
|
||
|
<v-icon
|
||
|
small
|
||
3 years ago
|
:color="hover ? 'primary' : ''"
|
||
|
@click="showMiddlewareSourceCode(title, functions)"
|
||
3 years ago
|
v-on="on"
|
||
|
>
|
||
|
mdi-pencil
|
||
|
</v-icon>
|
||
|
</v-hover>
|
||
|
</template>
|
||
|
Edit business logic
|
||
|
</v-tooltip>
|
||
|
</td>
|
||
|
</tr>
|
||
|
</template>
|
||
4 years ago
|
</tbody>
|
||
|
</v-simple-table>
|
||
|
|
||
3 years ago
|
<v-alert v-else outlined type="info"> Permission file not found </v-alert>
|
||
4 years ago
|
</v-card>
|
||
|
</v-col>
|
||
|
</v-row>
|
||
|
|
||
3 years ago
|
<gql-handler-code-editor
|
||
|
v-model="showCodeEditor"
|
||
|
:nodes="nodes"
|
||
|
:functions="selectedFunctions"
|
||
|
:resolver="editResolver"
|
||
|
:is-middleware="isMiddleware"
|
||
|
/>
|
||
4 years ago
|
|
||
|
<v-dialog v-model="schemaDiffDialog" scrollable min-width="600px">
|
||
|
<v-card>
|
||
3 years ago
|
<xc-diff v-model="schema" :history="schemaHistory" />
|
||
4 years ago
|
</v-card>
|
||
|
</v-dialog>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import GqlHandlerCodeEditor from '~/components/project/GqlHandlerCodeEditor';
|
||
|
import MonacoEditor from '@/components/monaco/MonacoEditor';
|
||
|
import XcDiff from '~/components/XcDiff';
|
||
4 years ago
|
|
||
|
export default {
|
||
3 years ago
|
name: 'LogicGql',
|
||
|
components: { XcDiff, MonacoEditor, GqlHandlerCodeEditor },
|
||
4 years ago
|
props: ['nodes'],
|
||
|
data: () => ({
|
||
3 years ago
|
showSwagger: false,
|
||
4 years ago
|
selectedFunctions: null,
|
||
|
schema: '',
|
||
|
schemaHistory: [''],
|
||
|
loading: false,
|
||
|
search: '',
|
||
|
groupedData: {},
|
||
|
resolvers: [],
|
||
|
|
||
|
editResolver: '',
|
||
|
showCodeEditor: false,
|
||
|
schemaDiffDialog: false,
|
||
3 years ago
|
isMiddleware: false,
|
||
4 years ago
|
}),
|
||
3 years ago
|
computed: {
|
||
3 years ago
|
filteredData() {
|
||
3 years ago
|
return this.resolvers.filter(
|
||
|
({ resolver }) => !resolver || !this.search || resolver.toLowerCase().includes(this.search.toLowerCase())
|
||
|
);
|
||
|
},
|
||
3 years ago
|
},
|
||
3 years ago
|
async created() {
|
||
3 years ago
|
await this.loadResolvers();
|
||
|
await this.loadSchema();
|
||
3 years ago
|
},
|
||
4 years ago
|
methods: {
|
||
3 years ago
|
showSourceCode(resolver, functions) {
|
||
3 years ago
|
this.selectedFunctions = functions;
|
||
|
this.editResolver = resolver;
|
||
|
this.isMiddleware = false;
|
||
|
this.showCodeEditor = true;
|
||
4 years ago
|
},
|
||
3 years ago
|
showMiddlewareSourceCode(table, functions) {
|
||
3 years ago
|
this.selectedFunctions = functions;
|
||
|
this.editResolver = table;
|
||
|
this.isMiddleware = true;
|
||
|
this.showCodeEditor = true;
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
async saveSchema() {
|
||
3 years ago
|
this.edited = false;
|
||
4 years ago
|
try {
|
||
3 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
},
|
||
|
'xcModelSchemaSet',
|
||
|
{
|
||
|
tn: this.nodes.table_name || this.nodes.view_name,
|
||
|
schema: this.schema,
|
||
|
},
|
||
|
]);
|
||
|
this.$toast.success('Successfully updated validations').goAway(3000);
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error('Failed to update validations').goAway(3000);
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async loadSchema() {
|
||
3 years ago
|
const tableMeta = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
},
|
||
|
'tableXcModelGet',
|
||
|
{
|
||
|
tn: this.nodes.table_name || this.nodes.view_name,
|
||
|
},
|
||
|
]);
|
||
|
this.schema = tableMeta.schema;
|
||
4 years ago
|
if (tableMeta.schema_previous) {
|
||
3 years ago
|
this.schemaHistory = JSON.parse(tableMeta.schema_previous).reverse();
|
||
4 years ago
|
} else {
|
||
3 years ago
|
this.schemaHistory = [];
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async loadResolvers() {
|
||
3 years ago
|
this.resolvers = (
|
||
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
},
|
||
|
'xcResolverPolicyGet',
|
||
|
{
|
||
|
tn: this.nodes.table_name || this.nodes.view_name,
|
||
|
},
|
||
|
])
|
||
|
).data.list;
|
||
|
},
|
||
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
|
<style scoped lang="scss">
|
||
3 years ago
|
@import '~vuetify/src/styles/styles';
|
||
4 years ago
|
|
||
|
$text-field-outlined-fieldset-padding: 0px;
|
||
|
|
||
|
//@import '~vuetify/src/styles/styles';
|
||
|
// Imports
|
||
|
//@import './_variables.scss'
|
||
|
|
||
|
.method-cell {
|
||
|
border-left: 1px solid #aaa;
|
||
|
}
|
||
|
|
||
|
.history-count {
|
||
|
font-size: 10px;
|
||
|
width: 12px;
|
||
|
height: 12px;
|
||
|
border-radius: 50%;
|
||
|
color: var(--v-primary-base);
|
||
|
display: inline-block;
|
||
|
text-align: center;
|
||
|
margin-left: 2px;
|
||
|
border: 1px solid var(--v-primary-base);
|
||
|
}
|
||
|
|
||
|
@function map-deep-get($map, $keys...) {
|
||
|
@each $key in $keys {
|
||
|
$map: map-get($map, $key);
|
||
|
}
|
||
|
@return $map;
|
||
|
}
|
||
|
|
||
|
::v-deep {
|
||
|
table th {
|
||
|
height: auto !important;
|
||
|
|
||
|
.v-input__control {
|
||
|
height: auto !important;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
.card-title {
|
||
|
color: var(--secondary-color);
|
||
|
}
|
||
|
}
|
||
|
</style>
|
||
|
<!--
|
||
|
/**
|
||
|
* @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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|