|
|
@ -1,7 +1,7 @@ |
|
|
|
<template> |
|
|
|
<template> |
|
|
|
<v-dialog :value="true"> |
|
|
|
<v-dialog v-model="modal"> |
|
|
|
<v-card style="overflow: hidden"> |
|
|
|
<v-card style="overflow: hidden"> |
|
|
|
<v-tabs v-model="tab" height="30"> |
|
|
|
<v-tabs v-model="tab" height="30" @change="client=null"> |
|
|
|
<v-tab |
|
|
|
<v-tab |
|
|
|
v-for="{lang} in langs" |
|
|
|
v-for="{lang} in langs" |
|
|
|
:key="lang" |
|
|
|
:key="lang" |
|
|
@ -11,17 +11,31 @@ |
|
|
|
</v-tab> |
|
|
|
</v-tab> |
|
|
|
</v-tabs> |
|
|
|
</v-tabs> |
|
|
|
<div class="nc-snippet-wrapper"> |
|
|
|
<div class="nc-snippet-wrapper"> |
|
|
|
<div class="nc-snippet-actions"> |
|
|
|
<div class="nc-snippet-actions d-flex"> |
|
|
|
<v-icon>mdi-clipboard</v-icon>sdds |
|
|
|
<v-btn color="primary" class="rounded caption " @click="copyToClipboard"> |
|
|
|
<v-select |
|
|
|
<v-icon small> |
|
|
|
|
|
|
|
mdi-clipboard-outline |
|
|
|
|
|
|
|
</v-icon> Copy To Clipboard |
|
|
|
|
|
|
|
</v-btn> |
|
|
|
|
|
|
|
<div |
|
|
|
v-if="langs[tab].clients" |
|
|
|
v-if="langs[tab].clients" |
|
|
|
v-model="client" |
|
|
|
class=" ml-2 d-flex align-center" |
|
|
|
class="nc-snippet-client" |
|
|
|
> |
|
|
|
outlined |
|
|
|
<v-menu bottom offset-y> |
|
|
|
dense |
|
|
|
<template #activator="{on}"> |
|
|
|
hide-details |
|
|
|
<v-btn class="caption" color="primary" v-on="on"> |
|
|
|
style="max-width: 100px" |
|
|
|
{{ client || langs[tab].clients[0] }} <v-icon small> |
|
|
|
/> |
|
|
|
mdi-chevron-down |
|
|
|
|
|
|
|
</v-icon> |
|
|
|
|
|
|
|
</v-btn> |
|
|
|
|
|
|
|
</template> |
|
|
|
|
|
|
|
<v-list dense> |
|
|
|
|
|
|
|
<v-list-item v-for="c in langs[tab].clients" :key="c" dense @click="client = c"> |
|
|
|
|
|
|
|
<v-list-item-title>{{ c }}</v-list-item-title> |
|
|
|
|
|
|
|
</v-list-item> |
|
|
|
|
|
|
|
</v-list> |
|
|
|
|
|
|
|
</v-menu> |
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<custom-monaco-editor style="min-height:500px;max-width: 100%" :value="code" read-only /> |
|
|
|
<custom-monaco-editor style="min-height:500px;max-width: 100%" :value="code" read-only /> |
|
|
|
</div> |
|
|
|
</div> |
|
|
@ -32,6 +46,7 @@ |
|
|
|
<script> |
|
|
|
<script> |
|
|
|
import HTTPSnippet from 'httpsnippet' |
|
|
|
import HTTPSnippet from 'httpsnippet' |
|
|
|
import CustomMonacoEditor from '~/components/monaco/CustomMonacoEditor' |
|
|
|
import CustomMonacoEditor from '~/components/monaco/CustomMonacoEditor' |
|
|
|
|
|
|
|
import { copyTextToClipboard } from '~/helpers/xutils' |
|
|
|
export default { |
|
|
|
export default { |
|
|
|
name: 'CodeSnippet', |
|
|
|
name: 'CodeSnippet', |
|
|
|
components: { CustomMonacoEditor }, |
|
|
|
components: { CustomMonacoEditor }, |
|
|
@ -40,48 +55,110 @@ export default { |
|
|
|
view: Object, |
|
|
|
view: Object, |
|
|
|
filters: [Object, Array], |
|
|
|
filters: [Object, Array], |
|
|
|
sorts: [Object, Array], |
|
|
|
sorts: [Object, Array], |
|
|
|
fileds: [Object, Array] |
|
|
|
fileds: [Object, Array], |
|
|
|
|
|
|
|
queryParams: Object, |
|
|
|
|
|
|
|
value: Boolean |
|
|
|
}, |
|
|
|
}, |
|
|
|
data: () => ({ |
|
|
|
data: () => ({ |
|
|
|
tab: 0, |
|
|
|
tab: 0, |
|
|
|
client: null, |
|
|
|
client: null, |
|
|
|
langs: [ |
|
|
|
langs: [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
lang: 'shell', |
|
|
|
|
|
|
|
clients: ['curl', 'wget'] |
|
|
|
|
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
lang: 'javascript', |
|
|
|
lang: 'javascript', |
|
|
|
clients: ['XMLHttpRequest', 'jQuery.ajax'] |
|
|
|
clients: ['axios', 'fetch', 'jquery', 'xhr'] |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
lang: 'node' |
|
|
|
lang: 'node', |
|
|
|
|
|
|
|
clients: ['axios', 'fetch', 'request', 'native', 'unirest'] |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
lang: 'shell' |
|
|
|
lang: 'nocodb-sdk', |
|
|
|
|
|
|
|
clients: ['javascript', 'node'] |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
lang: 'php' |
|
|
|
lang: 'php' |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
lang: 'python' |
|
|
|
lang: 'python', |
|
|
|
|
|
|
|
clients: ['python3', |
|
|
|
|
|
|
|
'requests'] |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
lang: 'ruby' |
|
|
|
lang: 'ruby' |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
lang: 'java' |
|
|
|
|
|
|
|
}, |
|
|
|
{ |
|
|
|
{ |
|
|
|
lang: 'c' |
|
|
|
lang: 'c' |
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
|
] |
|
|
|
}), |
|
|
|
}), |
|
|
|
computed: { |
|
|
|
computed: { |
|
|
|
|
|
|
|
modal: { |
|
|
|
|
|
|
|
get() { |
|
|
|
|
|
|
|
return this.value |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
set(v) { |
|
|
|
|
|
|
|
this.$emit('input', v) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
apiUrl() { |
|
|
|
|
|
|
|
return new URL(`/api/v1/db/data/noco/${this.projectId}/${this.meta.title}/views/${this.view.title}`, this.$store.state.project.projectInfo.ncSiteUrl).href |
|
|
|
|
|
|
|
}, |
|
|
|
snippet() { |
|
|
|
snippet() { |
|
|
|
return new HTTPSnippet({ |
|
|
|
return new HTTPSnippet({ |
|
|
|
method: 'GET', |
|
|
|
method: 'GET', |
|
|
|
headers: [ |
|
|
|
headers: [ |
|
|
|
{ name: 'xc-auth', value: this.$store.state.users.token, comment: 'JWT Auth token' } |
|
|
|
{ name: 'xc-auth', value: this.$store.state.users.token, comment: 'JWT Auth token' } |
|
|
|
], |
|
|
|
], |
|
|
|
url: new URL(`/api/v1/db/data/noco/${this.projectId}/${this.meta.title}/views/${this.view.title}`, this.$store.state.project.projectInfo.ncSiteUrl).href |
|
|
|
url: this.apiUrl, |
|
|
|
|
|
|
|
queryString: Object.entries(this.queryParams || {}).map(([name, value]) => { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
name, value: String(value) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
code() { |
|
|
|
code() { |
|
|
|
return this.snippet.convert(this.langs[this.tab].lang, this.client) |
|
|
|
if (this.langs[this.tab].lang === 'nocodb-sdk') { |
|
|
|
|
|
|
|
return `${ |
|
|
|
|
|
|
|
this.client === 'node' |
|
|
|
|
|
|
|
? 'const { Api } require("nocodb-sdk");' |
|
|
|
|
|
|
|
: 'import { Api } from "nocodb-sdk";' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const api = new Api({ |
|
|
|
|
|
|
|
baseURL: ${JSON.stringify(this.apiUrl)}, |
|
|
|
|
|
|
|
headers: { |
|
|
|
|
|
|
|
"xc-auth": ${JSON.stringify(this.$store.state.users.token)} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api.dbViewRow.list( |
|
|
|
|
|
|
|
"noco", |
|
|
|
|
|
|
|
${JSON.stringify(this.projectName)}, |
|
|
|
|
|
|
|
${JSON.stringify(this.meta.title)}, |
|
|
|
|
|
|
|
${JSON.stringify(this.view.title)}, |
|
|
|
|
|
|
|
${JSON.stringify(this.queryParams, null, 2)} |
|
|
|
|
|
|
|
).then(function (data) { |
|
|
|
|
|
|
|
console.log(data); |
|
|
|
|
|
|
|
}).catch(function (error) { |
|
|
|
|
|
|
|
console.error(error); |
|
|
|
|
|
|
|
});` |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return this.snippet.convert(this.langs[this.tab].lang, this.client || (this.langs[this.tab].clients && this.langs[this.tab].clients[0]), {}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
methods: { |
|
|
|
|
|
|
|
copyToClipboard() { |
|
|
|
|
|
|
|
copyTextToClipboard(this.code) |
|
|
|
|
|
|
|
this.$toast.success('Code copied to clipboard successfully.').goAway(3000) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -94,6 +171,7 @@ export default { |
|
|
|
.nc-snippet-actions{ |
|
|
|
.nc-snippet-actions{ |
|
|
|
position: absolute; |
|
|
|
position: absolute; |
|
|
|
right: 10px; |
|
|
|
right: 10px; |
|
|
|
top:40px; |
|
|
|
bottom:10px; |
|
|
|
|
|
|
|
z-index: 99999; |
|
|
|
} |
|
|
|
} |
|
|
|
</style> |
|
|
|
</style> |
|
|
|