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.
1377 lines
47 KiB
1377 lines
47 KiB
3 years ago
|
<!-- eslint-disable -->
|
||
4 years ago
|
<template>
|
||
3 years ago
|
<v-container fluid class="api-client grid-list-xs pa-0" style="height: 100%">
|
||
|
<splitpanes style="height: 100%" class="xc-theme">
|
||
4 years ago
|
<pane min-size="20" max-size="50" size="30" style="overflow: auto">
|
||
|
<!-- <p class="body-2 my-1 text-center grey--text text--lighten-1" v-show="!isDashboard">-->
|
||
|
<!-- {..} REST API CLIENT</p>-->
|
||
|
<v-row class="pa-0 ma-0 pa-2 pl-2">
|
||
3 years ago
|
<div class="cursor-pointer d-flex" style="width: 100%">
|
||
3 years ago
|
<x-icon
|
||
3 years ago
|
v-ge="['api-client', 'open-new-collection']"
|
||
3 years ago
|
icon-class="mr-1 cursor-pointer"
|
||
|
small
|
||
|
color="primary"
|
||
|
tooltip="Create New API Collection"
|
||
|
@click="openNewCollection('/')"
|
||
|
>
|
||
|
mdi-folder-plus-outline
|
||
4 years ago
|
</x-icon>
|
||
|
|
||
|
<!-- <x-icon class="mr-1" color="primary" tooltip="Open API Collection" @click="openApiFileCollection">-->
|
||
|
<!-- mdi-folder-open-outline-->
|
||
|
<!-- </x-icon>-->
|
||
|
<v-dialog v-model="importCollection.modal" persistent max-width="550">
|
||
3 years ago
|
<template #activator="{ on }">
|
||
3 years ago
|
<v-icon color="" v-on="on"> mdi-import </v-icon>
|
||
4 years ago
|
</template>
|
||
|
<v-card class="pa-3" style="position: relative">
|
||
3 years ago
|
<v-icon
|
||
3 years ago
|
v-ge="['api-client', 'open-new-collection-close']"
|
||
|
style="position: absolute; right: 20px; top: 20px"
|
||
3 years ago
|
@click="importCollection.modal = false"
|
||
|
>
|
||
4 years ago
|
mdi-close
|
||
|
</v-icon>
|
||
|
|
||
3 years ago
|
<v-card-title class="headline justify-center mb-2"> Import </v-card-title>
|
||
|
<v-card-subtitle class="text-center"> (JSON Format Only) </v-card-subtitle>
|
||
4 years ago
|
|
||
|
<div style="" class="py-3">
|
||
|
<v-card-text>
|
||
|
<v-select
|
||
3 years ago
|
v-model="importCollection.type"
|
||
4 years ago
|
dense
|
||
|
hide-details
|
||
|
outlined
|
||
|
:items="importCollection.types"
|
||
|
filled
|
||
|
label="API Specification"
|
||
3 years ago
|
/>
|
||
4 years ago
|
</v-card-text>
|
||
|
<v-card-actions>
|
||
3 years ago
|
<v-tabs background-color="indigo accent-4" dark style="border: 1px solid indigo; margin: 0 10px">
|
||
4 years ago
|
<v-tab>FILE</v-tab>
|
||
3 years ago
|
<v-tab :disabled="!isSwaggerImport"> URL </v-tab>
|
||
|
<v-tab :disabled="!isSwaggerImport"> JSON </v-tab>
|
||
4 years ago
|
<v-tab-item>
|
||
3 years ago
|
<div class="px-2 py-10 text-center" style="min-height: 250px">
|
||
4 years ago
|
<v-row>
|
||
|
<v-col>
|
||
3 years ago
|
<v-text-field
|
||
|
v-model="importCollection.file.srcFilePath"
|
||
|
hide-details
|
||
|
label="Select file"
|
||
|
dense
|
||
|
outlined
|
||
|
>
|
||
|
<template #append>
|
||
3 years ago
|
<v-btn v-ge="['api-client', 'select-import-file']" small @click="selectImportFile()">
|
||
4 years ago
|
Choose File ...
|
||
|
</v-btn>
|
||
|
</template>
|
||
|
</v-text-field>
|
||
|
</v-col>
|
||
|
</v-row>
|
||
|
|
||
|
<v-row v-show="isSwaggerImport">
|
||
|
<v-col>
|
||
3 years ago
|
<v-text-field
|
||
|
v-model="importCollection.file.dstFilePath"
|
||
|
hide-details
|
||
|
label="Destination file path"
|
||
|
dense
|
||
|
outlined
|
||
|
hide-details
|
||
|
/>
|
||
4 years ago
|
</v-col>
|
||
|
</v-row>
|
||
|
|
||
|
<v-btn
|
||
3 years ago
|
v-ge="['api-client', 'import-collection']"
|
||
4 years ago
|
class="mt-4"
|
||
|
color="primary"
|
||
3 years ago
|
@click="
|
||
|
importFile(
|
||
|
importCollection.type,
|
||
|
importCollection.file.srcFilePath,
|
||
|
importCollection.file.dstFilePath
|
||
|
)
|
||
|
"
|
||
3 years ago
|
>
|
||
4 years ago
|
Import
|
||
|
</v-btn>
|
||
|
</div>
|
||
|
</v-tab-item>
|
||
3 years ago
|
<v-tab-item>
|
||
3 years ago
|
<div style="min-height: 250px" class="text-center">
|
||
|
<div class="px-2 pt-10">
|
||
3 years ago
|
<v-text-field v-model="importCollection.url" placeholder="Enter url" />
|
||
4 years ago
|
</div>
|
||
|
|
||
3 years ago
|
<v-btn
|
||
3 years ago
|
v-ge="['api-client', 'import-collection-from-url']"
|
||
3 years ago
|
color="primary"
|
||
3 years ago
|
@click="importFromUrl(importCollection.type, importCollection.url)"
|
||
3 years ago
|
>
|
||
|
Import
|
||
4 years ago
|
</v-btn>
|
||
|
</div>
|
||
|
</v-tab-item>
|
||
3 years ago
|
<v-tab-item>
|
||
3 years ago
|
<div style="min-height: 250px" class="text-center">
|
||
|
<div class="px-2 pt-2">
|
||
|
<v-textarea v-model="importCollection.text" placeholder="Enter JSON String" />
|
||
4 years ago
|
</div>
|
||
3 years ago
|
<v-btn
|
||
3 years ago
|
v-ge="['api-client', 'import-collection-from-text']"
|
||
3 years ago
|
color="primary"
|
||
3 years ago
|
@click="importFromText(importCollection.type, importCollection.text)"
|
||
3 years ago
|
>
|
||
|
Import
|
||
4 years ago
|
</v-btn>
|
||
|
</div>
|
||
|
</v-tab-item>
|
||
|
</v-tabs>
|
||
|
</v-card-actions>
|
||
|
</div>
|
||
|
</v-card>
|
||
|
</v-dialog>
|
||
3 years ago
|
<v-spacer />
|
||
|
<span v-show="!isDashboard" class="flex-shrink-1 body-2 my-1 text-center grey--text">
|
||
3 years ago
|
{..} REST API CLIENT ( is in <v-icon small color="warning">mdi-alpha</v-icon>)</span
|
||
|
>
|
||
4 years ago
|
|
||
|
<span v-show="isDashboard" class="caption float-right warning--text mt-1" style="font-style: italic">
|
||
|
API Client is in<v-icon small color="warning">mdi-alpha</v-icon>
|
||
|
</span>
|
||
|
</div>
|
||
|
</v-row>
|
||
3 years ago
|
<v-divider />
|
||
4 years ago
|
|
||
3 years ago
|
<v-tabs v-model="apiRootTab" height="32" style="border-top: 1px solid darkgrey">
|
||
|
<v-tab style="text-transform: none"> History </v-tab>
|
||
|
<v-tab style="text-transform: none"> Collections </v-tab>
|
||
4 years ago
|
|
||
|
<v-tab-item style="border-top: 1px solid grey">
|
||
|
<div class="apis-list">
|
||
3 years ago
|
<div v-for="(api, i) in historyList" :key="i" class="pa-0 ma-0">
|
||
|
<v-list-item v-ge="['api-client', 'history']" dense two-line @click="apiClickedOnHistoryList(api)">
|
||
3 years ago
|
<v-hover v-slot="{ hover }">
|
||
4 years ago
|
<v-list-item-content>
|
||
|
<v-list-item-title class="grey--text">
|
||
3 years ago
|
<v-btn
|
||
|
class="pl-0 ml-0"
|
||
|
small
|
||
|
text
|
||
|
:tooltip="api.meta.path"
|
||
|
:color="apiMethodMeta[api.meta.method.toUpperCase()].color"
|
||
4 years ago
|
>
|
||
|
<b>
|
||
3 years ago
|
<v-icon
|
||
|
class="mx-0 ml-n2"
|
||
|
:class="{
|
||
|
'white--text': !api.meta.response || !api.meta.response.status,
|
||
|
'red--text': api.meta.response && api.meta.response.status >= 400,
|
||
3 years ago
|
'green--text': api.meta.response && api.meta.response.status < 400,
|
||
3 years ago
|
}"
|
||
|
>
|
||
4 years ago
|
mdi-circle-small
|
||
|
</v-icon>
|
||
3 years ago
|
{{ api.meta.method }}
|
||
|
</b>
|
||
4 years ago
|
</v-btn>
|
||
|
|
||
|
{{ api.meta.path }}
|
||
|
</v-list-item-title>
|
||
|
<v-list-item-subtitle v-show="!i || hover" class="text-right">
|
||
|
<span v-show="!i && !hover" class="grey--text text--darken-1 caption">(Last invoked API) </span>
|
||
|
|
||
3 years ago
|
<v-icon v-if="_isDev" v-ge="['api-client', 'node-info']" small @click.stop="showNodeInfo(api)">
|
||
4 years ago
|
mdi-information
|
||
|
</v-icon>
|
||
3 years ago
|
<v-btn
|
||
|
v-show="hover"
|
||
3 years ago
|
v-ge="['api-client', 'delete-list']"
|
||
3 years ago
|
small
|
||
|
text
|
||
|
class=" "
|
||
|
@click="apiDeleteFromList(i)"
|
||
|
>
|
||
3 years ago
|
<v-icon small> mdi-delete </v-icon>
|
||
4 years ago
|
</v-btn>
|
||
|
</v-list-item-subtitle>
|
||
|
</v-list-item-content>
|
||
|
</v-hover>
|
||
|
</v-list-item>
|
||
3 years ago
|
<v-divider />
|
||
4 years ago
|
</div>
|
||
|
</div>
|
||
|
</v-tab-item>
|
||
|
<v-tab-item style="border-top: 1px solid grey">
|
||
3 years ago
|
<v-expansion-panels v-model="curApiCollectionPanel" accordion focusable>
|
||
3 years ago
|
<v-expansion-panel v-for="(apiTv, i) in apiTvs" :key="i">
|
||
4 years ago
|
<v-expansion-panel-header hide-actions>
|
||
3 years ago
|
<template #default="{ open }">
|
||
4 years ago
|
<div class="d-flex">
|
||
3 years ago
|
<v-icon color="">
|
||
|
{{ open ? 'mdi-menu-down' : 'mdi-menu-right' }}
|
||
|
</v-icon>
|
||
3 years ago
|
<v-icon small color="grey" class="ml-1 mr-2"> mdi-folder </v-icon>
|
||
4 years ago
|
|
||
3 years ago
|
<span class="body-2 flex-grow-1">{{
|
||
|
$store.getters['apiClientSwagger/GtrCurrentApiFilePaths'][i].fileName
|
||
|
}}</span>
|
||
3 years ago
|
|
||
|
<x-icon
|
||
|
color="white grey"
|
||
|
class="float-right mr-3"
|
||
|
small
|
||
3 years ago
|
@click="(showCtxMenu[i] = true), (x = $event.clientX), (y = $event.clientY)"
|
||
3 years ago
|
@click.stop=""
|
||
|
>
|
||
4 years ago
|
mdi-dots-horizontal
|
||
|
</x-icon>
|
||
|
|
||
3 years ago
|
<recursive-menu
|
||
|
v-model="showCtxMenu[i]"
|
||
3 years ago
|
v-ge="['api-client', 'collection-context-menu']"
|
||
3 years ago
|
:position-x="x"
|
||
|
:position-y="y"
|
||
|
:items="{
|
||
3 years ago
|
'Add Folder': 'add-folder',
|
||
|
'Add Request': 'add-request',
|
||
|
'Reveal in Folder': 'reveal-in-folder',
|
||
|
'Delete Collection': 'delete-collection',
|
||
|
'Refresh Collection': 'refresh-collection',
|
||
3 years ago
|
}"
|
||
3 years ago
|
@click="ctxMenuClickHandler($event, i)"
|
||
3 years ago
|
/>
|
||
4 years ago
|
</div>
|
||
|
</template>
|
||
|
</v-expansion-panel-header>
|
||
|
<v-expansion-panel-content class="expansion-wrap-0 pl-4">
|
||
|
<vue-tree-list
|
||
|
v-if="apiTvs[i]"
|
||
3 years ago
|
style="cursor: pointer"
|
||
4 years ago
|
class="body-2 sql-query-treeview px-1 pt-2 api-treeview"
|
||
3 years ago
|
:model="apiTv"
|
||
|
default-tree-node-name="new node"
|
||
|
default-leaf-node-name="new leaf"
|
||
|
:default-expanded="false"
|
||
4 years ago
|
@click="tvNodeOnClick"
|
||
|
@change-name="tvNodeRename"
|
||
|
@delete-node="tvNodeDelete"
|
||
|
@add-node="onAddNode"
|
||
3 years ago
|
>
|
||
|
<span slot="leafNodeIcon" />
|
||
3 years ago
|
<v-icon slot="treeNodeIcon" small color="grey" class="mr-1"> mdi-folder-star </v-icon>
|
||
|
|
||
|
<v-icon slot="addTreeNode" small> mdi-folder-plus </v-icon>
|
||
|
<v-icon slot="addLeafNode" small> mdi-file-plus </v-icon>
|
||
|
<v-icon slot="editNode" small class="mt-n1"> mdi-file-edit </v-icon>
|
||
|
<v-icon slot="delNode" small> mdi-delete </v-icon>
|
||
|
<template #label="{ item: api }">
|
||
3 years ago
|
<div
|
||
|
v-if="api.isLeaf"
|
||
|
class="d-flex pa-1 ma-n1"
|
||
|
style="width: 100%"
|
||
|
:style="
|
||
3 years ago
|
api.id === currentApi.id && !currentApi.meta.history ? 'background:rgb(240, 240, 240)' : ''
|
||
3 years ago
|
"
|
||
|
>
|
||
4 years ago
|
<!-- <v-icon class="mx-0"-->
|
||
|
<!-- :class="`${apiMeta[api.method].color}--text`"-->
|
||
|
<!-- small>-->
|
||
|
<!-- mdi-bookmark-outline-->
|
||
|
<!-- </v-icon>-->
|
||
3 years ago
|
<span
|
||
3 years ago
|
style="display: inline-block; min-width: 45px"
|
||
|
:class="
|
||
|
apiMethodMeta[api.meta.method.toUpperCase()]
|
||
|
? `${apiMethodMeta[api.meta.method.toUpperCase()].color}--text`
|
||
|
: ''
|
||
|
"
|
||
3 years ago
|
>
|
||
3 years ago
|
{{ api.meta.method.toUpperCase() === 'DELETE' ? 'DEL' : api.meta.method.toUpperCase() }}
|
||
|
</span>
|
||
4 years ago
|
|
||
3 years ago
|
<span
|
||
|
class="grey--text d-block text--darken-1"
|
||
3 years ago
|
style="text-overflow: ellipsis; overflow: hidden; white-space: nowrap"
|
||
|
>{{ api.name }}</span
|
||
|
>
|
||
3 years ago
|
<v-spacer />
|
||
3 years ago
|
<v-icon v-if="_isDev" v-ge="['api-client', 'node-info']" small @click.stop="showNodeInfo(api)">
|
||
4 years ago
|
mdi-information
|
||
|
</v-icon>
|
||
|
</div>
|
||
3 years ago
|
<div
|
||
|
v-else
|
||
|
class="d-flex"
|
||
3 years ago
|
style="width: 100%; text-overflow: ellipsis; overflow: hidden; white-space: nowrap"
|
||
3 years ago
|
>
|
||
4 years ago
|
<span>{{ api.name }}</span>
|
||
|
|
||
3 years ago
|
<v-spacer />
|
||
3 years ago
|
<v-icon v-if="_isDev" v-ge="['api-client', 'node-info']" small @click.stop="showNodeInfo(api)">
|
||
4 years ago
|
mdi-information
|
||
|
</v-icon>
|
||
|
</div>
|
||
|
</template>
|
||
|
</vue-tree-list>
|
||
|
</v-expansion-panel-content>
|
||
|
</v-expansion-panel>
|
||
|
</v-expansion-panels>
|
||
|
</v-tab-item>
|
||
|
</v-tabs>
|
||
|
</pane>
|
||
|
<pane min-size="10" size="70" style="overflow: auto">
|
||
3 years ago
|
<v-toolbar
|
||
3 years ago
|
class="toolbar-border-bottom elevation-0 d-flex req-inputs"
|
||
3 years ago
|
height="55"
|
||
3 years ago
|
style="position: relative; z-index: 2; width: 100%"
|
||
3 years ago
|
>
|
||
4 years ago
|
<v-select
|
||
|
v-model="api.method"
|
||
3 years ago
|
v-ge="['api-client', 'method']"
|
||
3 years ago
|
:items="Object.keys(apiMethodMeta)"
|
||
4 years ago
|
dense
|
||
|
solo
|
||
|
hide-details
|
||
|
outlined
|
||
|
class="body-2"
|
||
3 years ago
|
style="
|
||
|
max-width: 130px;
|
||
|
border-bottom-right-radius: 0;
|
||
|
border-top-right-radius: 0;
|
||
|
border-right: 1px solid grey;
|
||
|
"
|
||
3 years ago
|
/>
|
||
4 years ago
|
|
||
|
<xAutoComplete
|
||
3 years ago
|
v-model="api.path"
|
||
4 years ago
|
outlined
|
||
|
class="flex-grow-1"
|
||
|
:env="selectedEnv"
|
||
|
placeholder="Enter HTTP URL"
|
||
|
solo
|
||
|
dense
|
||
|
hide-details
|
||
|
autofocus
|
||
|
styles="border-bottom-left-radius: 0;border-top-left-radius:0 "
|
||
3 years ago
|
/>
|
||
4 years ago
|
|
||
3 years ago
|
<x-btn
|
||
3 years ago
|
v-ge="['api-client', 'api-send']"
|
||
3 years ago
|
btn.class="primary"
|
||
|
dense
|
||
|
tooltip="Send Request"
|
||
|
@click.prevent="apiSend()"
|
||
|
>
|
||
3 years ago
|
<v-icon v-if="isPerfFilled" small class="ml-n3"> mdi-truck-fast </v-icon>
|
||
|
<v-icon v-else small class="ml-n3"> mdi-send </v-icon>
|
||
4 years ago
|
SEND
|
||
|
</x-btn>
|
||
3 years ago
|
<x-btn
|
||
3 years ago
|
v-ge="['api-client', 'save']"
|
||
3 years ago
|
btn.class="outlined"
|
||
|
dense
|
||
|
:icon="api.history ? 'save' : 'mdi-content-save-edit'"
|
||
|
tooltip="Save API"
|
||
|
@click.prevent="saveOrUpdateApi(api)"
|
||
|
/>
|
||
|
<x-btn
|
||
3 years ago
|
v-ge="['api-client', 'environment']"
|
||
3 years ago
|
icon="mdi-eye-outline"
|
||
|
tooltip="Environments"
|
||
|
@click="environmentDialog = true"
|
||
|
/>
|
||
4 years ago
|
</v-toolbar>
|
||
|
|
||
3 years ago
|
<splitpanes horizontal style="height: calc(100% - 64px)" class="xc-theme">
|
||
|
<pane min-size="25" size="50" style="overflow: auto" class="pa-1">
|
||
|
<v-tabs class="req-tabs" height="24">
|
||
|
<v-tab v-ge="['api-client', 'params']" class="caption">
|
||
|
Params <b v-if="paramsCount" class="green--text">({{ paramsCount }})</b>
|
||
3 years ago
|
</v-tab>
|
||
3 years ago
|
<v-tab v-ge="['api-client', 'headers']" class="caption">
|
||
|
Headers <b v-if="headersCount" class="green--text">({{ headersCount }})</b>
|
||
3 years ago
|
</v-tab>
|
||
3 years ago
|
<v-tab v-ge="['api-client', 'body']" class="caption"> Body </v-tab>
|
||
|
<v-tab v-ge="['api-client', 'auth']" class="caption"> Auth </v-tab>
|
||
|
<v-tab v-ge="['api-client', 'perf-test']" class="caption"> Perf Test </v-tab>
|
||
|
<div class="flex-grow-1 d-flex text-right pr-4 justify-end">
|
||
|
<div class="flex-shrink-1">
|
||
4 years ago
|
<v-select
|
||
|
v-model="selectedEnv"
|
||
|
height="19"
|
||
|
class="caption envs"
|
||
|
dense
|
||
|
:items="environmentList"
|
||
|
placeholder="Environment"
|
||
|
single-line
|
||
|
>
|
||
3 years ago
|
<template #selection="{ item }">
|
||
|
<span style="text-transform: uppercase">{{ item }}</span
|
||
|
> <span class="grey--text">(env)</span>
|
||
4 years ago
|
</template>
|
||
|
</v-select>
|
||
|
</div>
|
||
|
</div>
|
||
|
<!-- <div class="flex-grow-1 text-right pr-4 caption" v-if="api.response">-->
|
||
|
<!-- <!– <x-icon iconClass="mr-4" v-if="$store.getters['project/GtrProjectJson']" @click="environmentDialog = true" tooltip="Environments">–>-->
|
||
|
<!-- <!– mdi-eye-outline–>-->
|
||
|
<!-- <!– </x-icon>–>-->
|
||
|
<!-- </div>-->
|
||
|
<v-tab-item>
|
||
3 years ago
|
<params v-model="api.parameters" :env.sync="selectedEnv" />
|
||
4 years ago
|
</v-tab-item>
|
||
|
<v-tab-item>
|
||
3 years ago
|
<headers v-model="api.headers" :env.sync="selectedEnv" />
|
||
4 years ago
|
</v-tab-item>
|
||
|
<v-tab-item>
|
||
|
<monaco-json-editor
|
||
3 years ago
|
v-model="api.body"
|
||
4 years ago
|
style="height: 250px"
|
||
|
class="editor card"
|
||
|
theme="vs-dark"
|
||
4 years ago
|
lang="json"
|
||
3 years ago
|
:options="{ validate: true, documentFormattingEdits: true, foldingRanges: true }"
|
||
3 years ago
|
/>
|
||
4 years ago
|
</v-tab-item>
|
||
|
<v-tab-item>
|
||
|
<!-- <monaco-editor-->
|
||
|
<!-- :code.sync="api.auth"-->
|
||
|
<!-- cssStyle="height:250px"></monaco-editor>-->
|
||
|
</v-tab-item>
|
||
|
|
||
|
<v-tab-item>
|
||
3 years ago
|
<perf-test v-model="api.perf" />
|
||
4 years ago
|
</v-tab-item>
|
||
|
</v-tabs>
|
||
|
</pane>
|
||
|
<pane min-size="25" size="50" style="overflow: auto" class="pa-1">
|
||
|
<!-- <h3 class="mb-2 grey--text lighten-1">-->
|
||
|
<!-- Response Body :-->
|
||
|
<!-- <div v-if="api.response">-->
|
||
|
<!-- <span v-if="api.response.status === 200" class="green--text">{{api.response.status}}</span>-->
|
||
|
<!-- <span v-if="api.response.status !== 200" class="red--text">{{api.response.status}}</span>-->
|
||
|
<!-- </div>-->
|
||
|
<!-- </h3>-->
|
||
|
|
||
3 years ago
|
<v-tabs v-if="api.response" height="24">
|
||
|
<v-tab v-ge="['api-client', 'response-body']" class="caption"> Body </v-tab>
|
||
|
<v-tab v-ge="['api-client', 'respomse-headers']" class="caption">
|
||
|
Headers<span v-if="api.response.headers" class="green--text"
|
||
|
>( {{ Object.keys(api.response.headers).length }} )</span
|
||
|
>
|
||
3 years ago
|
</v-tab>
|
||
|
<div v-if="api.response" class="flex-grow-1 text-right pr-4 caption">
|
||
|
<template v-if="api.response.status">
|
||
3 years ago
|
<span class="grey--text">Status:</span
|
||
|
><span
|
||
3 years ago
|
:class="{
|
||
3 years ago
|
'green--text': api.response.status === 200,
|
||
|
'red--text': api.response.status !== 200,
|
||
3 years ago
|
}"
|
||
3 years ago
|
><b>{{ api.response.status }}</b></span
|
||
|
>
|
||
3 years ago
|
</template>
|
||
3 years ago
|
|
||
3 years ago
|
<template v-if="api.timeTaken">
|
||
3 years ago
|
<span class="grey--text">Time:</span
|
||
|
><span class="green--text"
|
||
|
><b>{{ api.timeTaken }}ms</b></span
|
||
|
>
|
||
4 years ago
|
</template>
|
||
|
</div>
|
||
|
<v-tab-item>
|
||
3 years ago
|
<pre
|
||
|
v-if="api.response"
|
||
|
class="black pa-1 grey--text w-100 caption"
|
||
3 years ago
|
style="overflow-x: auto; min-height: 100px; overflow-y: auto; min-width: 100%"
|
||
|
>{{ api.response.data }}</pre
|
||
|
>
|
||
4 years ago
|
|
||
|
<!-- <pre v-if="api.response" class="black pa-1" style="overflow-x: auto;min-height:50px;overflow-y:auto">{{api.response.data}}</pre>-->
|
||
|
</v-tab-item>
|
||
|
<v-tab-item>
|
||
3 years ago
|
<pre
|
||
|
v-if="api.response"
|
||
|
class="black pa-1 grey--text w-100 caption"
|
||
3 years ago
|
style="overflow-x: auto; min-height: 100px; overflow-y: auto; min-width: 100%"
|
||
|
>{{ api.response.headers }}</pre
|
||
|
>
|
||
4 years ago
|
</v-tab-item>
|
||
|
</v-tabs>
|
||
|
</pane>
|
||
|
</splitpanes>
|
||
|
</pane>
|
||
|
</splitpanes>
|
||
3 years ago
|
<environment v-model="environmentDialog" env="_noco" />
|
||
4 years ago
|
|
||
|
<v-dialog v-model="bookmarkApiDialog" max-width="500">
|
||
|
<v-card>
|
||
3 years ago
|
<v-card-title class="justify-center"> Bookmark API </v-card-title>
|
||
4 years ago
|
|
||
|
<v-card-text>
|
||
|
<div class="text-right">
|
||
3 years ago
|
<v-btn
|
||
3 years ago
|
v-ge="['api-client', 'open-new-collection']"
|
||
3 years ago
|
small
|
||
|
color="primary"
|
||
|
outlined
|
||
|
@click="openNewCollection('/')"
|
||
|
>
|
||
3 years ago
|
<v-icon small> mdi-plus </v-icon> New Collection
|
||
4 years ago
|
</v-btn>
|
||
|
</div>
|
||
|
<v-list dense>
|
||
|
<v-list-item-group v-model="choosenApiCollection">
|
||
3 years ago
|
<v-list-item
|
||
3 years ago
|
v-for="(item, i) in $store.getters['apiClientSwagger/GtrCurrentApiFilePaths']"
|
||
3 years ago
|
:key="i"
|
||
|
:value="i"
|
||
|
style="border: 1px solid grey"
|
||
|
>
|
||
4 years ago
|
<v-list-item-title>{{ item.fileName }}</v-list-item-title>
|
||
|
</v-list-item>
|
||
|
</v-list-item-group>
|
||
|
</v-list>
|
||
|
</v-card-text>
|
||
|
<v-card-actions class="justify-center pb-5">
|
||
3 years ago
|
<v-btn v-ge="['api-client', 'bookmark']" small @click="bookmarkApiDialog = false">
|
||
3 years ago
|
<!-- Cancel -->
|
||
|
{{ $t('general.cancel') }}
|
||
3 years ago
|
</v-btn>
|
||
|
<v-btn
|
||
|
small
|
||
|
color="primary"
|
||
|
:disabled="choosenApiCollection === null || choosenApiCollection === undefined"
|
||
|
@click="bookmarkApi(choosenApiCollection)"
|
||
|
>
|
||
|
Save API
|
||
4 years ago
|
</v-btn>
|
||
|
</v-card-actions>
|
||
|
</v-card>
|
||
|
</v-dialog>
|
||
|
</v-container>
|
||
|
</template>
|
||
|
<script>
|
||
3 years ago
|
/* eslint-disable */
|
||
4 years ago
|
|
||
3 years ago
|
import { mapGetters } from 'vuex';
|
||
4 years ago
|
|
||
3 years ago
|
import Vue from 'vue';
|
||
4 years ago
|
|
||
3 years ago
|
import { VueTreeList, Tree, TreeNode } from 'vue-tree-list';
|
||
|
import { Splitpanes, Pane } from 'splitpanes';
|
||
|
import params from '../apiClient/Params';
|
||
|
import headers from '../apiClient/Headers';
|
||
4 years ago
|
|
||
3 years ago
|
import { MonacoJsonEditor } from '../monaco/index';
|
||
4 years ago
|
|
||
3 years ago
|
import environment from '../Environment';
|
||
|
import PerfTest from '../apiClient/PerfTest';
|
||
4 years ago
|
|
||
|
// const {app, dialog, path, fs, shell, XcApis} = require("electron").remote.require(
|
||
|
// "./libs"
|
||
|
// );
|
||
|
|
||
3 years ago
|
import * as XcApiHelp from '../../helpers/XcApiHelp';
|
||
4 years ago
|
|
||
|
// const {config} = require('electron').remote.require('./libs');
|
||
|
|
||
|
export default {
|
||
|
components: {
|
||
|
PerfTest,
|
||
|
MonacoJsonEditor,
|
||
|
VueTreeList,
|
||
3 years ago
|
Splitpanes,
|
||
|
Pane,
|
||
4 years ago
|
params,
|
||
|
headers,
|
||
3 years ago
|
environment,
|
||
4 years ago
|
},
|
||
3 years ago
|
data() {
|
||
4 years ago
|
return {
|
||
|
choosenApiCollection: null,
|
||
|
bookmarkApiDialog: false,
|
||
|
apiRootTab: 0,
|
||
|
importCollection: {
|
||
|
modal: false,
|
||
|
type: 'Swagger 3.0',
|
||
3 years ago
|
types: [
|
||
|
{
|
||
|
text: 'Swagger 3.0',
|
||
|
value: 'Swagger 3.0',
|
||
|
},
|
||
|
{
|
||
|
text: 'XC',
|
||
|
value: 'XC',
|
||
|
},
|
||
|
],
|
||
4 years ago
|
file: {
|
||
|
srcFilePath: '',
|
||
3 years ago
|
dstFilePath: '',
|
||
|
},
|
||
4 years ago
|
},
|
||
|
fileHistory: null,
|
||
|
historyList: [],
|
||
|
environmentDialog: false,
|
||
|
showCtxMenu: {},
|
||
|
apiTvs: [],
|
||
|
apiFilePaths: [],
|
||
|
apiFileCollections: [],
|
||
|
curApiCollectionPanel: null,
|
||
|
|
||
|
x: 0,
|
||
|
y: 0,
|
||
|
|
||
|
apiMethodMeta: {
|
||
|
GET: {
|
||
3 years ago
|
color: 'success',
|
||
4 years ago
|
},
|
||
|
POST: {
|
||
3 years ago
|
color: 'warning',
|
||
4 years ago
|
},
|
||
|
DELETE: {
|
||
3 years ago
|
color: 'error',
|
||
4 years ago
|
},
|
||
|
PUT: {
|
||
3 years ago
|
color: 'info',
|
||
4 years ago
|
},
|
||
|
HEAD: {
|
||
3 years ago
|
color: 'info',
|
||
4 years ago
|
},
|
||
|
PATCH: {
|
||
3 years ago
|
color: 'info',
|
||
|
},
|
||
4 years ago
|
},
|
||
|
|
||
|
// current api
|
||
|
api: {
|
||
|
method: 'GET',
|
||
|
path: '',
|
||
|
body: '',
|
||
|
params: [],
|
||
|
auth: '',
|
||
|
headers: [],
|
||
|
response: {},
|
||
|
perf: {},
|
||
3 years ago
|
meta: {},
|
||
4 years ago
|
},
|
||
|
currentApi: {},
|
||
3 years ago
|
currentNode: null,
|
||
|
};
|
||
4 years ago
|
},
|
||
|
computed: {
|
||
3 years ago
|
isPerfFilled() {
|
||
|
return this.api.perf && Object.values(this.api.perf).some(v => v);
|
||
4 years ago
|
},
|
||
|
...mapGetters({
|
||
3 years ago
|
sqlMgr: 'sqlMgr/sqlMgr',
|
||
|
currentProjectFolder: 'project/currentProjectFolder',
|
||
|
projectApisFolderPath: 'project/projectApisFolderPath',
|
||
3 years ago
|
projectApisFolder: 'project/projectApisFolder',
|
||
4 years ago
|
}),
|
||
3 years ago
|
isSwaggerImport() {
|
||
|
return this.importCollection.type === 'Swagger 3.0';
|
||
4 years ago
|
},
|
||
3 years ago
|
paramsCount() {
|
||
|
return this.api.parameters && this.api.parameters.filter(p => p.name && p.enabled).length;
|
||
4 years ago
|
},
|
||
3 years ago
|
headersCount() {
|
||
|
return this.api.headers && this.api.headers.filter(h => h.name && h.enabled).length;
|
||
4 years ago
|
},
|
||
3 years ago
|
environmentList() {
|
||
4 years ago
|
if (this.isDashboard) {
|
||
3 years ago
|
return Object.keys(this.$store.getters['project/GtrApiEnvironment']);
|
||
4 years ago
|
} else {
|
||
3 years ago
|
return Object.keys(this.$store.getters['project/GtrDefaultApiEnvironment']);
|
||
4 years ago
|
}
|
||
|
},
|
||
|
selectedEnv: {
|
||
3 years ago
|
get() {
|
||
|
return (
|
||
|
this.$store.state.apiClientSwagger.activeEnvironment[this.$store.state.apiClientSwagger.currentProjectKey] ||
|
||
|
this.environmentList[0]
|
||
|
);
|
||
3 years ago
|
},
|
||
3 years ago
|
set(env) {
|
||
|
this.$store.commit('apiClientSwagger/MutActiveEnvironment', { env });
|
||
|
},
|
||
|
},
|
||
4 years ago
|
},
|
||
3 years ago
|
watch: {
|
||
3 years ago
|
async historyList(newData) {
|
||
3 years ago
|
await this.fileHistory.write({
|
||
|
path: config.electron.apiHistoryPath,
|
||
3 years ago
|
data: newData,
|
||
|
});
|
||
|
},
|
||
3 years ago
|
},
|
||
|
|
||
3 years ago
|
async created() {
|
||
3 years ago
|
try {
|
||
|
/* load history collection - default path is within app directory */
|
||
3 years ago
|
await this.loadHistoryFile();
|
||
3 years ago
|
|
||
|
if (this.$route.params && this.$route.params.project) {
|
||
|
/* get collection paths previously opened for this project */
|
||
|
this.$store.dispatch('apiClientSwagger/loadApiCollectionForProject', {
|
||
|
projectId: this.$route.params.project,
|
||
3 years ago
|
projectName: this.$store.getters['project/GtrProjectName'],
|
||
|
});
|
||
3 years ago
|
} else {
|
||
|
/* get collection paths previously opened */
|
||
3 years ago
|
this.$store.dispatch('apiClientSwagger/loadApiCollectionForProject', {});
|
||
3 years ago
|
}
|
||
|
|
||
|
/* load the filecollection json as treeviews */
|
||
|
for (let i = 0; i < this.$store.getters['apiClientSwagger/GtrCurrentApiFilePaths'].length; ++i) {
|
||
3 years ago
|
await this.loadFileCollection(this.$store.getters['apiClientSwagger/GtrCurrentApiFilePaths'][i]);
|
||
3 years ago
|
}
|
||
|
} catch (e) {
|
||
3 years ago
|
console.log('Failed to load previously opened query collections', e);
|
||
3 years ago
|
}
|
||
|
|
||
|
if (this.nodes && this.nodes.url) {
|
||
3 years ago
|
Vue.set(this.api, 'method', 'GET');
|
||
|
this.api.path = this.nodes.url;
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
this.api.meta = {};
|
||
3 years ago
|
|
||
|
try {
|
||
3 years ago
|
const info = (
|
||
|
await this.$axios.get('/nc/projectApiInfo', {
|
||
|
headers: {
|
||
|
'xc-auth': this.$store.state.users.token,
|
||
|
},
|
||
|
})
|
||
|
).data;
|
||
|
const rest = Object.values(info).find(v => v.apiUrl);
|
||
3 years ago
|
if (rest) {
|
||
3 years ago
|
Vue.set(this.api, 'method', 'GET');
|
||
|
Vue.set(this.api, 'path', rest.apiUrl);
|
||
3 years ago
|
}
|
||
3 years ago
|
} catch (e) {}
|
||
3 years ago
|
},
|
||
3 years ago
|
mounted() {},
|
||
|
beforeDestroy() {},
|
||
4 years ago
|
methods: {
|
||
3 years ago
|
showNodeInfo(api) {
|
||
|
console.log('Node info : ', api);
|
||
4 years ago
|
},
|
||
3 years ago
|
async handleKeyDown({ metaKey, key, altKey, shiftKey, ctrlKey }) {
|
||
4 years ago
|
// cmd + s -> save
|
||
|
// cmd + l -> reload
|
||
|
// cmd + n -> new
|
||
|
// cmd + d -> delete
|
||
|
// cmd + enter -> send api
|
||
|
|
||
|
switch ([metaKey, key].join('_')) {
|
||
3 years ago
|
case 'true_s':
|
||
|
await this.bookmarkApi();
|
||
|
break;
|
||
|
case 'true_e':
|
||
|
this.environmentDialog = true;
|
||
|
break;
|
||
4 years ago
|
// case 'true_n' :
|
||
|
// this.addColumn();
|
||
|
// break;
|
||
3 years ago
|
case 'true_d':
|
||
|
await this.deleteProcedure('showDialog');
|
||
|
break;
|
||
|
case 'true_Enter':
|
||
|
await this.apiSend();
|
||
|
break;
|
||
4 years ago
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
async openCollectionFolder(pathString) {
|
||
|
shell.showItemInFolder(pathString);
|
||
4 years ago
|
},
|
||
3 years ago
|
async openNewCollection() {
|
||
4 years ago
|
try {
|
||
3 years ago
|
const toLocalPath = this.isDashboard
|
||
|
? path.join(this.currentProjectFolder, 'server', 'tool', this.projectApisFolder)
|
||
|
: '';
|
||
4 years ago
|
|
||
3 years ago
|
const userChosenPath = dialog.showSaveDialog({
|
||
4 years ago
|
defaultPath: toLocalPath,
|
||
3 years ago
|
filters: [{ name: 'JSON', extensions: ['json'] }],
|
||
|
});
|
||
4 years ago
|
|
||
|
if (userChosenPath) {
|
||
3 years ago
|
fs.writeFileSync(userChosenPath, '[]', 'utf-8');
|
||
3 years ago
|
const pathObj = {
|
||
4 years ago
|
path: userChosenPath,
|
||
3 years ago
|
fileName: path.basename(userChosenPath),
|
||
|
};
|
||
|
this.$store.commit('apiClientSwagger/MutApiFilePathsAdd', pathObj);
|
||
|
await this.loadFileCollection(pathObj);
|
||
4 years ago
|
}
|
||
3 years ago
|
this.$toast.success('New API collection loaded successfully').goAway(5000);
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log(e);
|
||
|
throw e;
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async openSwaggerJSONFile(srcPath, dstPath) {
|
||
|
const dstFileName = path.basename(dstPath);
|
||
4 years ago
|
await XC.importSwaggerJson({
|
||
|
srcPath,
|
||
3 years ago
|
dstPath,
|
||
|
});
|
||
4 years ago
|
const pathObj = {
|
||
|
path: dstPath,
|
||
3 years ago
|
fileName: dstFileName,
|
||
|
};
|
||
|
this.$store.commit('apiClientSwagger/MutApiFilePathsAdd', pathObj);
|
||
|
await this.loadFileCollection(pathObj);
|
||
4 years ago
|
},
|
||
3 years ago
|
selectImportFile() {
|
||
4 years ago
|
const file = dialog.showOpenDialog({
|
||
3 years ago
|
properties: ['openFile'],
|
||
|
});
|
||
4 years ago
|
|
||
3 years ago
|
const dstFileName = `${path.basename(file[0], '.json')}.xc.json`;
|
||
4 years ago
|
|
||
3 years ago
|
let dstPath = '';
|
||
4 years ago
|
if (this.isDashboard) {
|
||
3 years ago
|
dstPath = this.projectApisFolderPath;
|
||
4 years ago
|
} else {
|
||
3 years ago
|
dstPath = path.dirname(config.electron.apiHistoryPath);
|
||
4 years ago
|
}
|
||
|
|
||
|
if (file && file[0]) {
|
||
3 years ago
|
this.$set(this.importCollection.file, 'srcFilePath', file[0] + '');
|
||
|
this.$set(this.importCollection.file, 'dstFilePath', path.join(dstPath, dstFileName));
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async importFile(type, srcPath, dstPath) {
|
||
|
this.apiRootTab = 1;
|
||
|
this.$set(this.importCollection, 'modal', false);
|
||
4 years ago
|
try {
|
||
|
if (type === 'Swagger 3.0') {
|
||
3 years ago
|
await this.openSwaggerJSONFile(srcPath, dstPath);
|
||
4 years ago
|
} else {
|
||
3 years ago
|
await this.openApiFileCollection(srcPath, dstPath);
|
||
4 years ago
|
}
|
||
3 years ago
|
this.$toast.success('File imported successfully').goAway(3000);
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log('File import error : ', e);
|
||
|
this.$toast.error('File importing failed').goAway(3000);
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async importFromUrl(type, url) {
|
||
|
this.apiRootTab = 1;
|
||
|
this.$set(this.importCollection, 'modal', false);
|
||
4 years ago
|
try {
|
||
|
if (type === 'Swagger 3.0') {
|
||
3 years ago
|
await this.importSwaggerFromUrl(url);
|
||
4 years ago
|
} else {
|
||
3 years ago
|
await this.importXcFromUrl(url);
|
||
4 years ago
|
}
|
||
3 years ago
|
this.$toast.success('Import from URL completed successfully').goAway(3000);
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log('URL import error : ', e);
|
||
|
this.$toast.error('Import from URL failed').goAway(3000);
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async importFromText(type, text) {
|
||
|
this.apiRootTab = 1;
|
||
|
this.$set(this.importCollection, 'modal', false);
|
||
4 years ago
|
try {
|
||
|
if (type === 'Swagger 3.0') {
|
||
3 years ago
|
await this.importSwaggerFromText(text);
|
||
4 years ago
|
} else {
|
||
3 years ago
|
await this.importXcFromText(text);
|
||
4 years ago
|
}
|
||
3 years ago
|
this.$toast.success('Import from Text completed successfully').goAway(3000);
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log('Text import error : ', e);
|
||
|
this.$toast.error('Import from Text failed').goAway(3000);
|
||
4 years ago
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
async importSwaggerFromUrl(url) {
|
||
|
const data = await this.$axios.$get(url);
|
||
4 years ago
|
|
||
3 years ago
|
const dstFileName = `${Date.now()}.xc.json`;
|
||
4 years ago
|
|
||
3 years ago
|
let dstPath = '';
|
||
4 years ago
|
if (this.isDashboard) {
|
||
3 years ago
|
dstPath = this.projectApisFolderPath;
|
||
4 years ago
|
} else {
|
||
3 years ago
|
dstPath = path.dirname(config.electron.apiHistoryPath);
|
||
4 years ago
|
}
|
||
|
|
||
|
await XC.importSwaggerObject({
|
||
|
swagger: data,
|
||
3 years ago
|
dstPath: path.join(dstPath, dstFileName),
|
||
|
});
|
||
4 years ago
|
|
||
|
const pathObj = {
|
||
|
path: path.join(dstPath, dstFileName),
|
||
3 years ago
|
fileName: dstFileName,
|
||
|
};
|
||
4 years ago
|
|
||
3 years ago
|
this.$store.commit('apiClientSwagger/MutApiFilePathsAdd', pathObj);
|
||
|
await this.loadFileCollection(pathObj);
|
||
4 years ago
|
},
|
||
3 years ago
|
async importSwaggerFromText(text) {
|
||
|
const data = JSON.parse(text);
|
||
4 years ago
|
|
||
3 years ago
|
const dstFileName = `${Date.now()}.xc.json`;
|
||
4 years ago
|
|
||
3 years ago
|
let dstPath = '';
|
||
4 years ago
|
if (this.isDashboard) {
|
||
3 years ago
|
dstPath = this.projectApisFolderPath;
|
||
4 years ago
|
} else {
|
||
3 years ago
|
dstPath = path.dirname(config.electron.apiHistoryPath);
|
||
4 years ago
|
}
|
||
|
|
||
|
await XC.importSwaggerObject({
|
||
|
swagger: data,
|
||
3 years ago
|
dstPath: path.join(dstPath, dstFileName),
|
||
|
});
|
||
4 years ago
|
|
||
|
const pathObj = {
|
||
|
path: path.join(dstPath, dstFileName),
|
||
3 years ago
|
fileName: dstFileName,
|
||
|
};
|
||
4 years ago
|
|
||
3 years ago
|
this.$store.commit('apiClientSwagger/MutApiFilePathsAdd', pathObj);
|
||
|
await this.loadFileCollection(pathObj);
|
||
4 years ago
|
|
||
3 years ago
|
this.$toast.success('Import from Text completed successfully').goAway(3000);
|
||
4 years ago
|
},
|
||
3 years ago
|
async importXcFromUrl(url) {
|
||
|
const data = await this.$axios.$get(url);
|
||
4 years ago
|
|
||
3 years ago
|
const dstFileName = `${Date.now()}.xc.json`;
|
||
4 years ago
|
|
||
3 years ago
|
let dstPath = '';
|
||
4 years ago
|
if (this.isDashboard) {
|
||
3 years ago
|
dstPath = this.projectApisFolderPath;
|
||
4 years ago
|
} else {
|
||
3 years ago
|
dstPath = path.dirname(config.electron.apiHistoryPath);
|
||
4 years ago
|
}
|
||
|
|
||
|
// await XcApis.importSwaggerObject({
|
||
|
// swagger: data,
|
||
|
// dstPath: path.join(dstPath, dstFileName)
|
||
|
// })
|
||
|
|
||
|
const pathObj = {
|
||
|
path: path.join(dstPath, dstFileName),
|
||
3 years ago
|
fileName: dstFileName,
|
||
|
};
|
||
4 years ago
|
|
||
3 years ago
|
this.$store.commit('apiClientSwagger/MutApiFilePathsAdd', pathObj);
|
||
|
await this.loadFileCollection(pathObj);
|
||
4 years ago
|
},
|
||
3 years ago
|
async importXcFromText(text) {
|
||
|
const data = JSON.parse(text);
|
||
4 years ago
|
|
||
3 years ago
|
const dstFileName = `${Date.now()}.xc.json`;
|
||
4 years ago
|
|
||
3 years ago
|
let dstPath = '';
|
||
4 years ago
|
if (this.isDashboard) {
|
||
3 years ago
|
dstPath = this.projectApisFolderPath;
|
||
4 years ago
|
} else {
|
||
3 years ago
|
dstPath = path.dirname(config.electron.apiHistoryPath);
|
||
4 years ago
|
}
|
||
|
//
|
||
|
// await XcApis.importSwaggerObject({
|
||
|
// swagger: data,
|
||
|
// dstPath: path.join(dstPath, dstFileName)
|
||
|
// })
|
||
|
|
||
|
const pathObj = {
|
||
|
path: path.join(dstPath, dstFileName),
|
||
3 years ago
|
fileName: dstFileName,
|
||
|
};
|
||
4 years ago
|
|
||
3 years ago
|
this.$store.commit('apiClientSwagger/MutApiFilePathsAdd', pathObj);
|
||
|
await this.loadFileCollection(pathObj);
|
||
4 years ago
|
|
||
3 years ago
|
this.$toast.success('Import from Text completed successfully').goAway(3000);
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
async ctxMenuClickHandler(actionEvent, index) {
|
||
4 years ago
|
switch (actionEvent.value) {
|
||
|
case 'add-folder':
|
||
3 years ago
|
this.tvNodeFolderAdd(index);
|
||
|
break;
|
||
4 years ago
|
case 'add-request':
|
||
3 years ago
|
this.curApiCollectionPanel = index;
|
||
|
this.tvNodeRequestAdd(index);
|
||
|
break;
|
||
4 years ago
|
case 'reveal-in-folder':
|
||
3 years ago
|
await this.openCollectionFolder(this.$store.getters['apiClientSwagger/GtrCurrentApiFilePaths'][index].path);
|
||
|
break;
|
||
3 years ago
|
case 'delete-collection':
|
||
3 years ago
|
this.$store.commit('apiClientSwagger/MutApiFilePathsRemove', index);
|
||
|
this.apiFileCollections.splice(index, 1);
|
||
|
this.apiTvs.splice(index, 1);
|
||
|
break;
|
||
3 years ago
|
case 'refresh-collection':
|
||
3 years ago
|
await this.refreshFileCollection(index);
|
||
|
break;
|
||
4 years ago
|
default:
|
||
3 years ago
|
break;
|
||
4 years ago
|
}
|
||
3 years ago
|
// this.deleteQueryByPath(this.apiTvs, this.menuItem.path);
|
||
4 years ago
|
},
|
||
3 years ago
|
openUrl(url) {
|
||
|
shell.openExternal(url);
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
apiClickedOnList(api) {
|
||
4 years ago
|
if (api.isLeaf) {
|
||
3 years ago
|
api = XcApiHelp.apiPrepareForInvocation(api);
|
||
4 years ago
|
|
||
3 years ago
|
this.currentApi = JSON.parse(JSON.stringify(api));
|
||
4 years ago
|
this.api = {
|
||
|
perf: {},
|
||
3 years ago
|
...this.currentApi.meta,
|
||
|
};
|
||
4 years ago
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
apiClickedOnHistoryList(api) {
|
||
|
this.currentApi = JSON.parse(JSON.stringify(api));
|
||
4 years ago
|
this.api = {
|
||
|
perf: {},
|
||
|
...api.meta,
|
||
|
history: true,
|
||
3 years ago
|
isLeaf: true,
|
||
|
};
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
apiDeleteFromList(index) {
|
||
|
this.$store.commit('apiClientSwagger/MutListRemove', index);
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
async apiSend() {
|
||
4 years ago
|
if (!this.api.path.trim()) {
|
||
3 years ago
|
this.$toast.info('Please enter http url').goAway(3000);
|
||
|
return;
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
const envs = this.isDashboard
|
||
|
? this.$store.getters['project/GtrApiEnvironment'][this.selectedEnv]
|
||
3 years ago
|
: this.$store.getters['project/GtrDefaultApiEnvironment'][this.selectedEnv];
|
||
4 years ago
|
|
||
3 years ago
|
const apiDecoded = JSON.parse(
|
||
4 years ago
|
JSON.stringify(this.api).replace(/{{\s*(\w+)\s*}}/g, (m, m1) => {
|
||
|
if (m1 in envs) {
|
||
3 years ago
|
return envs[m1];
|
||
4 years ago
|
} else {
|
||
3 years ago
|
this.$toast.info('Environment variable is not found : ' + m1).goAway(3000);
|
||
|
return m;
|
||
4 years ago
|
}
|
||
|
})
|
||
3 years ago
|
);
|
||
4 years ago
|
|
||
3 years ago
|
const swaggerResult = await this.$store.dispatch('apiClientSwagger/send', { api: this.api, apiDecoded });
|
||
4 years ago
|
|
||
3 years ago
|
this.historyList = [{ ...this.currentApi, meta: swaggerResult, pid: 0 }, ...this.historyList];
|
||
4 years ago
|
|
||
3 years ago
|
const result = swaggerResult.response;
|
||
|
this.api = swaggerResult;
|
||
4 years ago
|
|
||
|
if (result) {
|
||
|
if (result.status === 200) {
|
||
3 years ago
|
// this.$toast.success('API invoked successfully',{duration:1000});
|
||
4 years ago
|
} else {
|
||
3 years ago
|
this.$toast.error(`Error:${result.status}`, { duration: 1000 });
|
||
4 years ago
|
}
|
||
|
} else {
|
||
3 years ago
|
this.$toast.error('Some internal error occurred', { duration: 1000 });
|
||
4 years ago
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
async fileCollectionReload() {
|
||
|
const data = new Tree(await this.apiFileCollection.read());
|
||
4 years ago
|
|
||
3 years ago
|
this.apiTv = data;
|
||
4 years ago
|
// this.$set(this, 'apiCollections', data);
|
||
|
},
|
||
|
|
||
3 years ago
|
async tvNodeDelete(node) {
|
||
|
console.log(node, this.curApiCollectionPanel);
|
||
|
node.remove();
|
||
|
await this.savefileCollections(this.curApiCollectionPanel);
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
async tvNodeRename(params) {
|
||
|
await this.savefileCollections(this.curApiCollectionPanel);
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
async onAddNode(params) {
|
||
|
await this.savefileCollections(this.curApiCollectionPanel);
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
async tvNodeOnClick(node) {
|
||
|
const { parent, children, ...params } = node;
|
||
|
this.currentNode = node;
|
||
4 years ago
|
|
||
3 years ago
|
this.apiClickedOnList(params);
|
||
4 years ago
|
// if (params.query) ;
|
||
|
// this.selectQuery(params)
|
||
|
},
|
||
|
|
||
3 years ago
|
async savefileCollections(index = 0) {
|
||
|
await this.apiFileCollections[index].write({ data: this.tvToObject(index) });
|
||
4 years ago
|
// this.apiTvs = await this.fileCollections.read();
|
||
|
// this.$set(this.apiTvs, index, this.apiTvs);
|
||
|
},
|
||
|
|
||
3 years ago
|
tvToObject(index) {
|
||
4 years ago
|
try {
|
||
3 years ago
|
const vm = this;
|
||
4 years ago
|
|
||
3 years ago
|
function _dfs(oldNode) {
|
||
|
const newNode = {};
|
||
4 years ago
|
|
||
3 years ago
|
XcApiHelp.nodeHandleIfNew(oldNode);
|
||
4 years ago
|
|
||
3 years ago
|
for (const k in oldNode) {
|
||
4 years ago
|
if (k !== 'children' && k !== 'parent') {
|
||
3 years ago
|
newNode[k] = oldNode[k];
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
|
if (oldNode.children && oldNode.children.length > 0) {
|
||
3 years ago
|
newNode.children = [];
|
||
3 years ago
|
for (let i = 0, len = oldNode.children.length; i < len; i++) {
|
||
3 years ago
|
newNode.children.push(_dfs(oldNode.children[i]));
|
||
4 years ago
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
return newNode;
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
return _dfs(vm.apiTvs[index]).children;
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error('Error while parsing api collection').goAway(3000);
|
||
4 years ago
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
async tvNodeFolderAdd(index) {
|
||
|
const node = new TreeNode({ name: 'New Folder', isLeaf: false, children: [] });
|
||
|
if (!this.apiTvs[index].children) {
|
||
|
this.apiTvs[index].children = [];
|
||
|
}
|
||
|
this.apiTvs[index].addChildren(node);
|
||
4 years ago
|
|
||
3 years ago
|
await this.saveFileCollection(index);
|
||
4 years ago
|
},
|
||
3 years ago
|
async tvNodeRequestAdd(index) {
|
||
|
const node = new TreeNode({ name: 'New Request', isLeaf: true });
|
||
|
if (!this.apiTvs[index].children) {
|
||
|
this.apiTvs[index].children = [];
|
||
|
}
|
||
|
this.apiTvs[index].addChildren(node);
|
||
4 years ago
|
|
||
3 years ago
|
await this.saveFileCollection(index);
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
openApiFileCollection(filePath = null) {
|
||
|
const vm = this;
|
||
4 years ago
|
// console.log(obj, key);
|
||
|
|
||
3 years ago
|
const file = filePath
|
||
|
? [filePath]
|
||
|
: dialog.showOpenDialog({
|
||
3 years ago
|
properties: ['openFile'],
|
||
|
});
|
||
4 years ago
|
|
||
|
if (file && file[0]) {
|
||
3 years ago
|
const fileName = path.basename(file[0]);
|
||
4 years ago
|
const pathObj = {
|
||
|
path: file[0] + '',
|
||
3 years ago
|
fileName,
|
||
|
};
|
||
4 years ago
|
|
||
3 years ago
|
if (this.$store.getters['apiClientSwagger/GtrCurrentApiFilePaths'].every(({ path: p }) => p !== pathObj.path)) {
|
||
3 years ago
|
this.$store.commit('apiClientSwagger/MutApiFilePathsAdd', pathObj);
|
||
|
this.loadFileCollection(pathObj);
|
||
4 years ago
|
} else {
|
||
3 years ago
|
this.$toast.info('File already exist in collection').goAway(4000);
|
||
4 years ago
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
async saveFileCollection(index = 0) {
|
||
|
await this.apiFileCollections[index].write({ data: this.tvToObject(index) });
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
async loadFileCollection(path, index = 0) {
|
||
4 years ago
|
try {
|
||
|
/* create file collection and get its data */
|
||
3 years ago
|
const fileCollection = new XC(path);
|
||
|
await fileCollection.init();
|
||
|
this.apiFileCollections.push(fileCollection);
|
||
|
const treeData = await fileCollection.read();
|
||
4 years ago
|
|
||
|
/* create a tree view and push it */
|
||
3 years ago
|
const data = new Tree(treeData.length && treeData[0].name === 'swagger.json' ? treeData[0].children : treeData);
|
||
|
this.apiTvs.push(data);
|
||
4 years ago
|
|
||
3 years ago
|
this.curApiCollectionPanel = this.apiFileCollections.length - 1;
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log('Error in loadFileCollection:', e);
|
||
|
throw e;
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async loadHistoryFile() {
|
||
4 years ago
|
// try {
|
||
|
// this.fileHistory = new XcApis({path: config.electron.apiHistoryPath});
|
||
|
// this.historyList = await this.fileHistory.read();
|
||
|
// } catch (e) {
|
||
|
// console.log('Error in loadFileHistory:', e);
|
||
|
// throw e;
|
||
|
// }
|
||
|
},
|
||
3 years ago
|
async refreshFileCollection(index = 0) {
|
||
4 years ago
|
try {
|
||
3 years ago
|
const path = this.$store.getters['apiClientSwagger/GtrCurrentApiFilePaths'][index];
|
||
|
const fileCollection = new XC(path);
|
||
|
await fileCollection.init();
|
||
|
this.apiFileCollections[index] = fileCollection;
|
||
|
const data = new Tree(await fileCollection.read());
|
||
|
this.$set(this.apiTvs, index, data);
|
||
4 years ago
|
} catch (e) {
|
||
3 years ago
|
console.log('Error in loadFileCollection:', e);
|
||
|
throw e;
|
||
4 years ago
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
async bookmarkApi(panelIndex) {
|
||
|
this.bookmarkApiDialog = false;
|
||
4 years ago
|
if (this.apiFileCollections.length) {
|
||
3 years ago
|
delete this.currentApi.meta.history;
|
||
|
const q = this.currentApi;
|
||
3 years ago
|
const node = new TreeNode({
|
||
4 years ago
|
name: q.meta.path,
|
||
|
swagger: {},
|
||
|
isLeaf: true,
|
||
3 years ago
|
id: Date.now(),
|
||
|
pid: 0,
|
||
3 years ago
|
...q,
|
||
|
});
|
||
4 years ago
|
|
||
3 years ago
|
if (!this.apiTvs[panelIndex].children) {
|
||
|
this.apiTvs[panelIndex].children = [];
|
||
|
}
|
||
|
this.apiTvs[panelIndex].addChildren(node);
|
||
|
await this.savefileCollections(panelIndex);
|
||
|
await this.refreshFileCollection(panelIndex);
|
||
|
|
||
|
this.$toast
|
||
|
.success(
|
||
|
`API added to ${this.$store.getters['apiClientSwagger/GtrCurrentApiFilePaths'][panelIndex].fileName} collection successfully`
|
||
|
)
|
||
|
.goAway(3000);
|
||
4 years ago
|
} else {
|
||
3 years ago
|
this.$toast.info('Create a new collection to bookmark the api.').goAway(3000);
|
||
|
this.openNewCollection('/');
|
||
4 years ago
|
}
|
||
|
},
|
||
3 years ago
|
async saveOrUpdateApi() {
|
||
4 years ago
|
if (this.api.history) {
|
||
3 years ago
|
this.bookmarkApiDialog = true;
|
||
4 years ago
|
} else {
|
||
3 years ago
|
const q = this.currentApi;
|
||
4 years ago
|
const api = {
|
||
|
...q,
|
||
3 years ago
|
meta: { ...this.api },
|
||
3 years ago
|
pid: 0,
|
||
|
};
|
||
|
const activePanelIndex = this.curApiCollectionPanel;
|
||
|
await this.apiFileCollections[activePanelIndex].updateApi({ api });
|
||
|
await this.refreshFileCollection(activePanelIndex);
|
||
|
this.$toast
|
||
|
.success(
|
||
|
`API updated in ${this.$store.getters['apiClientSwagger/GtrCurrentApiFilePaths'][activePanelIndex].fileName} collection successfully`
|
||
|
)
|
||
|
.goAway(3000);
|
||
4 years ago
|
}
|
||
3 years ago
|
},
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
beforeCreated() {},
|
||
|
destroy() {},
|
||
3 years ago
|
directives: {},
|
||
3 years ago
|
validate({ params }) {
|
||
|
return true;
|
||
4 years ago
|
},
|
||
3 years ago
|
head() {
|
||
|
return {};
|
||
4 years ago
|
},
|
||
3 years ago
|
props: ['nodes'],
|
||
|
};
|
||
4 years ago
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
|
.apis-list {
|
||
|
height: calc(100%);
|
||
|
overflow-y: auto;
|
||
|
}
|
||
|
|
||
|
.apis-request {
|
||
|
overflow-y: auto;
|
||
|
}
|
||
|
|
||
|
/deep/ > .req-inputs .v-toolbar__content {
|
||
|
width: 100%;
|
||
|
display: flex;
|
||
|
padding: 2px;
|
||
|
}
|
||
|
|
||
|
/deep/ .req-tabs > .v-tabs-items {
|
||
3 years ago
|
border-top: 1px solid #7f828b33;
|
||
4 years ago
|
}
|
||
|
|
||
|
.envs /deep/ .v-select__selections {
|
||
3 years ago
|
color: var(--v-accent-base);
|
||
4 years ago
|
}
|
||
|
|
||
|
/*.envs /deep/ .v-select__selections input { display: none}*/
|
||
3 years ago
|
code {
|
||
|
min-height: 200px;
|
||
4 years ago
|
}
|
||
|
</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/>.
|
||
|
*
|
||
|
*/
|
||
|
-->
|