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.
380 lines
12 KiB
380 lines
12 KiB
3 years ago
|
<!-- eslint-disable -->
|
||
|
|
||
4 years ago
|
<template>
|
||
|
<div>
|
||
|
<v-toolbar flat height="42" class="toolbar-border-bottom">
|
||
|
<v-toolbar-title>
|
||
3 years ago
|
<v-breadcrumbs
|
||
2 years ago
|
:items="[
|
||
|
{
|
||
|
text: nodes.env,
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
{
|
||
|
text: nodes.dbAlias,
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
{
|
||
|
text: name + ' (APIs)',
|
||
|
disabled: true,
|
||
|
href: '#',
|
||
|
},
|
||
|
]"
|
||
3 years ago
|
divider=">"
|
||
|
small
|
||
|
>
|
||
|
<template #divider>
|
||
2 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 />
|
||
4 years ago
|
|
||
3 years ago
|
<v-btn small outlined class="caption text-capitalize" color="primary" @click="showSwagger = !showSwagger">
|
||
|
<v-icon small color="primary">
|
||
|
{{ showSwagger ? 'mdi-eye-off-outline' : 'mdi-eye-outline' }}
|
||
2 years ago
|
</v-icon>
|
||
|
|
||
4 years ago
|
|
||
|
{{ showSwagger ? 'Hide Swagger' : 'Show Swagger' }}
|
||
|
</v-btn>
|
||
|
|
||
3 years ago
|
<x-btn
|
||
2 years ago
|
v-ge="['rows', 'reload']"
|
||
3 years ago
|
outlined
|
||
|
tooltip="Reload Rows"
|
||
|
color="primary"
|
||
|
small
|
||
|
btn.class="caption text-capitalize"
|
||
2 years ago
|
@click="
|
||
|
loadSwaggerDoc();
|
||
|
loadRoutes();
|
||
|
"
|
||
3 years ago
|
>
|
||
2 years ago
|
<v-icon small left> refresh </v-icon>
|
||
3 years ago
|
<!-- Reload -->
|
||
|
{{ $t('general.reload') }}
|
||
4 years ago
|
</x-btn>
|
||
|
</v-toolbar>
|
||
|
|
||
3 years ago
|
<v-text-field
|
||
|
v-model="search"
|
||
|
dense
|
||
|
hide-details
|
||
|
class="ma-2"
|
||
|
:placeholder="`Search ${name} routes`"
|
||
|
prepend-inner-icon="search"
|
||
|
outlined
|
||
|
/>
|
||
4 years ago
|
|
||
|
<!-- <div class="d-flex justify-center">-->
|
||
|
<v-container fluid>
|
||
|
<v-row>
|
||
|
<v-col v-if="showSwagger">
|
||
|
<v-card>
|
||
|
<div class="text-center" style="padding: 3px">
|
||
|
<span class="title schema-card-title">Swagger JSON</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 || !swaggerDocHistory.length"
|
||
|
@click.prevent="schemaDiffDialog = true"
|
||
|
>
|
||
2 years ago
|
<v-icon small left> mdi-source-branch </v-icon>
|
||
|
History
|
||
|
<span v-if="swaggerDocHistory.length" class="history-count">({{ swaggerDocHistory.length }})</span>
|
||
4 years ago
|
</x-btn>
|
||
3 years ago
|
<x-btn
|
||
2 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="saveSwaggerDoc"
|
||
|
>
|
||
2 years ago
|
<v-icon small left> save </v-icon>
|
||
3 years ago
|
<!-- Save -->
|
||
|
{{ $t('general.save') }}
|
||
4 years ago
|
</x-btn>
|
||
|
</div>
|
||
2 years ago
|
<monaco-json-editor v-model="swaggerDoc" theme="" style="min-height: 500px" />
|
||
4 years ago
|
</v-card>
|
||
|
</v-col>
|
||
|
<v-col>
|
||
3 years ago
|
<v-card v-if="filteredGroupedData.length" class="flex-shrink-1" style="">
|
||
|
<v-skeleton-loader v-if="loading" type="table" />
|
||
4 years ago
|
|
||
|
<v-simple-table v-else-if="routers" dense style="width: auto; min-width: 500px">
|
||
|
<thead>
|
||
3 years ago
|
<tr>
|
||
|
<th colspan="2" class="text-center">
|
||
|
<div class="d-flex justify-center">
|
||
|
<span class="title">Routes</span>
|
||
|
</div>
|
||
4 years ago
|
</th>
|
||
|
|
||
2 years ago
|
<template v-for="(method, i) in methods">
|
||
3 years ago
|
<th
|
||
|
:key="`${method}`"
|
||
|
width="60"
|
||
2 years ago
|
class="method-cell caption px-1 text-center text-uppercase font-weight-bold"
|
||
3 years ago
|
:class="`${methodColor[method]}--text`"
|
||
|
>
|
||
|
{{ method }}
|
||
|
</th>
|
||
|
</template>
|
||
|
</tr>
|
||
4 years ago
|
</thead>
|
||
|
<tbody>
|
||
2 years ago
|
<tr v-for="[path, route] in filteredGroupedData">
|
||
3 years ago
|
<td width="20" class="px-0" />
|
||
|
<td class="pl-0">
|
||
|
<v-tooltip bottom>
|
||
|
<template #activator="{ on }">
|
||
|
<span v-on="on">{{ path }}</span>
|
||
|
</template>
|
||
|
<span>{{ path }}</span>
|
||
|
</v-tooltip>
|
||
|
</td>
|
||
2 years ago
|
<template v-for="(method, i) in methods">
|
||
|
<td :key="`${path}_${method}}`" width="60" class="pa-1 text-center method-cell">
|
||
3 years ago
|
<v-tooltip bottom>
|
||
|
<template #activator="{ on }">
|
||
|
<v-hover v-if="route[method]" v-slot="{ hover }">
|
||
|
<v-icon
|
||
|
small
|
||
2 years ago
|
:color="hover ? methodColor[method] : ''"
|
||
|
@click="showSourceCode(route, method)"
|
||
3 years ago
|
v-on="on"
|
||
|
>
|
||
|
mdi-pencil
|
||
|
</v-icon>
|
||
|
</v-hover>
|
||
|
</template>
|
||
|
Edit business logic
|
||
|
</v-tooltip>
|
||
|
</td>
|
||
|
</template>
|
||
|
</tr>
|
||
|
|
||
2 years ago
|
<tr v-for="mw in middlewares">
|
||
3 years ago
|
<td width="20" class="px-0" />
|
||
|
<td class="pl-0">
|
||
|
<v-tooltip bottom>
|
||
|
<template #activator="{ on }">
|
||
|
<span v-on="on">{{ mw.title }} - Middleware</span>
|
||
|
</template>
|
||
|
<span>{{ mw.title }} - Middleware</span>
|
||
|
</v-tooltip>
|
||
|
</td>
|
||
2 years ago
|
<td :colspan="methods.length" width="60" class="pa-1 text-center method-cell">
|
||
4 years ago
|
<v-tooltip bottom>
|
||
3 years ago
|
<template #activator="{ on }">
|
||
|
<v-hover v-slot="{ hover }">
|
||
|
<v-icon
|
||
|
small
|
||
2 years ago
|
:color="hover ? methodColor[method] : ''"
|
||
3 years ago
|
@click="showMiddlewareSourceCode(mw)"
|
||
|
v-on="on"
|
||
|
>
|
||
|
mdi-pencil
|
||
4 years ago
|
</v-icon>
|
||
|
</v-hover>
|
||
|
</template>
|
||
3 years ago
|
Edit middleware business logic
|
||
4 years ago
|
</v-tooltip>
|
||
|
</td>
|
||
3 years ago
|
</tr>
|
||
4 years ago
|
</tbody>
|
||
|
</v-simple-table>
|
||
|
|
||
2 years ago
|
<v-alert v-else outlined type="info"> Permission file not found </v-alert>
|
||
4 years ago
|
</v-card>
|
||
|
<!-- </div>-->
|
||
|
</v-col>
|
||
|
<!-- </div>-->
|
||
|
</v-row>
|
||
|
</v-container>
|
||
|
<handler-code-editor
|
||
3 years ago
|
v-model="showCodeEditor"
|
||
4 years ago
|
:is-middleware="isMiddleware"
|
||
|
:nodes="nodes"
|
||
|
:route="editRoute"
|
||
|
:method="editMethod"
|
||
3 years ago
|
/>
|
||
4 years ago
|
|
||
|
<v-dialog v-model="schemaDiffDialog" scrollable min-width="600px">
|
||
|
<v-card>
|
||
2 years ago
|
<xc-diff v-model="swaggerDoc" :history="swaggerDocHistory" />
|
||
4 years ago
|
</v-card>
|
||
|
</v-dialog>
|
||
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
2 years ago
|
import HandlerCodeEditor from '~/components/project/RestHandlerCodeEditor';
|
||
|
import MonacoJsonEditor from '@/components/monaco/MonacoJsonEditor';
|
||
4 years ago
|
|
||
|
export default {
|
||
3 years ago
|
name: 'LogicRest',
|
||
|
components: { MonacoJsonEditor, HandlerCodeEditor },
|
||
4 years ago
|
props: ['nodes'],
|
||
|
data: () => ({
|
||
|
showSwagger: false,
|
||
|
loading: false,
|
||
|
search: '',
|
||
|
groupedData: {},
|
||
|
middlewares: [],
|
||
|
routers: null,
|
||
2 years ago
|
methods: ['get', 'post', 'put', 'delete'],
|
||
4 years ago
|
methodColor: {
|
||
3 years ago
|
get: 'success',
|
||
|
post: 'warning',
|
||
|
put: 'info',
|
||
|
patch: 'secondary',
|
||
2 years ago
|
delete: 'error',
|
||
4 years ago
|
},
|
||
|
editRoute: '',
|
||
|
editMethod: '',
|
||
|
isMiddleware: false,
|
||
|
showCodeEditor: false,
|
||
|
swaggerDocHistory: [],
|
||
|
swaggerDoc: '',
|
||
2 years ago
|
schemaDiffDialog: false,
|
||
4 years ago
|
}),
|
||
3 years ago
|
computed: {
|
||
3 years ago
|
filteredGroupedData() {
|
||
2 years ago
|
return Object.entries(this.groupedData).filter(
|
||
|
([path]) => !this.search || path.toLowerCase().includes(this.search.toLowerCase())
|
||
|
);
|
||
3 years ago
|
},
|
||
3 years ago
|
name() {
|
||
2 years ago
|
return this.nodes.table_name || this.nodes.view_name;
|
||
|
},
|
||
3 years ago
|
},
|
||
3 years ago
|
async created() {
|
||
2 years ago
|
await this.loadRoutes();
|
||
|
this.groupRoutes();
|
||
|
await this.loadSwaggerDoc();
|
||
3 years ago
|
},
|
||
4 years ago
|
methods: {
|
||
3 years ago
|
groupRoutes() {
|
||
2 years ago
|
const groupedData = {};
|
||
|
this.middlewares = [];
|
||
4 years ago
|
for (const route of this.routers) {
|
||
|
if (route.path) {
|
||
2 years ago
|
groupedData[route.path] = groupedData[route.path] || {};
|
||
|
groupedData[route.path][route.type] = route;
|
||
4 years ago
|
} else if (route.handler_type === 2) {
|
||
2 years ago
|
this.middlewares.push(route);
|
||
4 years ago
|
}
|
||
|
}
|
||
2 years ago
|
this.groupedData = groupedData;
|
||
4 years ago
|
},
|
||
3 years ago
|
showSourceCode(route, method) {
|
||
2 years ago
|
this.editRoute = route;
|
||
|
this.editMethod = method;
|
||
|
this.isMiddleware = false;
|
||
|
this.showCodeEditor = true;
|
||
4 years ago
|
},
|
||
3 years ago
|
showMiddlewareSourceCode(mw) {
|
||
2 years ago
|
this.editRoute = mw;
|
||
|
this.editMethod = null;
|
||
|
this.isMiddleware = true;
|
||
|
this.showCodeEditor = true;
|
||
4 years ago
|
},
|
||
3 years ago
|
async loadSwaggerDoc() {
|
||
2 years ago
|
const tableMeta = await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
},
|
||
|
'tableXcModelGet',
|
||
|
{
|
||
|
table_name: this.nodes.table_name || this.nodes.view_name,
|
||
|
},
|
||
|
]);
|
||
|
this.swaggerDoc = JSON.stringify(JSON.parse(tableMeta.schema), 0, 2);
|
||
3 years ago
|
// if (tableMeta.schema_previous) {
|
||
|
// this.swaggerDocHistory = JSON.parse(tableMeta.schema_previous).reverse().map(o => JSON.stringify(o, null, 2))
|
||
|
// } else {
|
||
|
// this.swaggerDocHistory = []
|
||
|
// }
|
||
4 years ago
|
},
|
||
3 years ago
|
async saveSwaggerDoc() {
|
||
2 years ago
|
this.edited = false;
|
||
4 years ago
|
try {
|
||
2 years ago
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
},
|
||
|
'xcModelSwaggerDocSet',
|
||
|
{
|
||
|
tn: this.nodes.table_name || this.nodes.view_name,
|
||
|
swaggerDoc: JSON.parse(this.swaggerDoc),
|
||
|
},
|
||
|
]);
|
||
|
this.$toast.success('Successfully updated swagger doc').goAway(3000);
|
||
4 years ago
|
} catch (e) {
|
||
2 years ago
|
this.$toast.error('Failed to update swagger doc').goAway(3000);
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async loadRoutes() {
|
||
2 years ago
|
this.loading = true;
|
||
|
this.routers = (
|
||
|
await this.$store.dispatch('sqlMgr/ActSqlOp', [
|
||
|
{
|
||
|
env: this.nodes.env,
|
||
|
dbAlias: this.nodes.dbAlias,
|
||
|
},
|
||
|
'xcRoutesPolicyGet',
|
||
|
{
|
||
|
tn: this.name,
|
||
|
},
|
||
|
])
|
||
|
).data.list;
|
||
|
this.loading = false;
|
||
|
},
|
||
|
},
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
|
.method-cell {
|
||
|
border-left: 1px solid #aaa;
|
||
|
}
|
||
|
</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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|