refactor(gui): linting

Signed-off-by: Pranav C <61551451+pranavxc@users.noreply.github.com>
This commit is contained in:
Pranav C
2021-07-19 16:30:37 +05:30
parent f9508c2d44
commit fa00be39b8
303 changed files with 34924 additions and 31761 deletions

View File

@@ -1,45 +1,41 @@
import inflection from 'inflection';
import inflection from 'inflection'
export default class GqlApi {
constructor(table, columns, meta, $ctx) {
constructor (table, columns, meta, $ctx) {
// this.table = table;
this.columns = columns;
this.meta = meta;
this.$ctx = $ctx;
this.columns = columns
this.meta = meta
this.$ctx = $ctx
}
// todo: - get version letter and use table alias
async list(params) {
async list (params) {
const data = await this.post(`/nc/${this.$ctx.$route.params.project_id}/v1/graphql`, {
query: await this.gqlQuery(params),
variables: null
});
return data.data.data[this.gqlQueryListName];
})
return data.data.data[this.gqlQueryListName]
}
async count(params) {
async count (params) {
const data = await this.post(`/nc/${this.$ctx.$route.params.project_id}/v1/graphql`, {
query: this.gqlCountQuery(params),
variables: null
});
return data.data.data[this.gqlQueryCountName];
})
return data.data.data[this.gqlQueryCountName]
}
post(url, params) {
post (url, params) {
return this.$axios({
url: `${this.$axios.defaults.baseURL}${url}`,
method: 'post',
data: params,
data: params
})
}
generateQueryParams(params) {
if (!params) return '(where:"")';
const res = [];
generateQueryParams (params) {
if (!params) { return '(where:"")' }
const res = []
if ('limit' in params) {
res.push(`limit: ${params.limit}`)
}
@@ -58,39 +54,39 @@ export default class GqlApi {
if (params.conditionGraph) {
res.push(`conditionGraph: ${JSON.stringify(JSON.stringify(params.conditionGraph))}`)
}
return `(${res.join(',')})`;
return `(${res.join(',')})`
}
async gqlQuery(params) {
async gqlQuery (params) {
return `{${this.gqlQueryListName}${this.generateQueryParams(params)}{${this.gqlReqBody}${await this.gqlRelationReqBody(params)}}}`
}
gqlReadQuery(id) {
gqlReadQuery (id) {
return `{${this.gqlQueryReadName}(id:"${id}"){${this.gqlReqBody}}}`
}
gqlCountQuery(params) {
gqlCountQuery (params) {
return `{${this.gqlQueryCountName}${this.generateQueryParams(params)}}`
}
get gqlQueryListName() {
return `${this.meta._tn}List`;
get gqlQueryListName () {
return `${this.meta._tn}List`
}
get gqlQueryReadName() {
return `${this.meta._tn}Read`;
get gqlQueryReadName () {
return `${this.meta._tn}Read`
}
get tableCamelized() {
return `${this.meta._tn}`;
get tableCamelized () {
return `${this.meta._tn}`
}
get gqlReqBody() {
get gqlReqBody () {
return `\n${this.columns.map(c => c._cn).join('\n')}\n`
}
async gqlRelationReqBody(params) {
let str = '';
async gqlRelationReqBody (params) {
let str = ''
if (params.hm) {
for (const child of params.hm.split(',')) {
await this.$ctx.$store.dispatch('meta/ActLoadMeta', {
@@ -98,7 +94,7 @@ export default class GqlApi {
env: this.$ctx.nodes.env,
tn: child
})
const meta = this.$ctx.$store.state.meta.metas[child];
const meta = this.$ctx.$store.state.meta.metas[child]
if (meta) {
str += `\n${meta._tn}List{\n${meta.columns.map(c => c._cn).join('\n')}\n}`
}
@@ -111,7 +107,7 @@ export default class GqlApi {
env: this.$ctx.nodes.env,
tn: parent
})
const meta = this.$ctx.$store.state.meta.metas[parent];
const meta = this.$ctx.$store.state.meta.metas[parent]
if (meta) {
str += `\n${meta._tn}Read{\n${meta.columns.map(c => c._cn).join('\n')}\n}`
}
@@ -124,33 +120,32 @@ export default class GqlApi {
env: this.$ctx.nodes.env,
tn: mm
})
const meta = this.$ctx.$store.state.meta.metas[mm];
const meta = this.$ctx.$store.state.meta.metas[mm]
if (meta) {
str += `\n${meta._tn}MMList{\n${meta.columns.map(c => c._cn).join('\n')}\n}`
}
}
}
return str;
return str
}
get gqlQueryCountName() {
return `${this.tableCamelized}Count`;
get gqlQueryCountName () {
return `${this.tableCamelized}Count`
}
get gqlMutationCreateName() {
return `${this.tableCamelized}Create`;
get gqlMutationCreateName () {
return `${this.tableCamelized}Create`
}
get gqlMutationUpdateName() {
return `${this.tableCamelized}Update`;
get gqlMutationUpdateName () {
return `${this.tableCamelized}Update`
}
get gqlMutationDeleteName() {
return `${this.tableCamelized}Delete`;
get gqlMutationDeleteName () {
return `${this.tableCamelized}Delete`
}
async paginatedList(params) {
async paginatedList (params) {
// const list = await this.list(params);
// const count = (await this.count({where: params.where || ''}));
const [list, count] = await Promise.all([
@@ -159,23 +154,22 @@ export default class GqlApi {
conditionGraph: params.conditionGraph,
condition: params.condition
})
]);
return {list, count};
])
return { list, count }
}
async update(id, data, oldData) {
async update (id, data, oldData) {
const data1 = await this.post(`/nc/${this.$ctx.$route.params.project_id}/v1/graphql`, {
query: `mutation update($id:String!, $data:${this.tableCamelized}Input){
${this.gqlMutationUpdateName}(id: $id, data: $data)
}`,
variables: {
id: id, data
id, data
}
});
})
const colName = Object.keys(data)[0];
this.$ctx.$store.dispatch('sqlMgr/ActSqlOp', [{dbAlias: this.$ctx.nodes.dbAlias}, 'xcAuditCreate', {
const colName = Object.keys(data)[0]
this.$ctx.$store.dispatch('sqlMgr/ActSqlOp', [{ dbAlias: this.$ctx.nodes.dbAlias }, 'xcAuditCreate', {
tn: this.table,
cn: colName,
pk: id,
@@ -183,10 +177,10 @@ export default class GqlApi {
prevValue: oldData[colName]
}])
return data1.data.data[this.gqlMutationUpdateName];
return data1.data.data[this.gqlMutationUpdateName]
}
async insert(data) {
async insert (data) {
const data1 = await this.post(`/nc/${this.$ctx.$route.params.project_id}/v1/graphql`, {
query: `mutation create($data:${this.tableCamelized}Input){
${this.gqlMutationCreateName}(data: $data){${this.gqlReqBody}}
@@ -194,44 +188,38 @@ export default class GqlApi {
variables: {
data
}
});
return data1.data.data[this.gqlMutationCreateName];
})
return data1.data.data[this.gqlMutationCreateName]
}
async delete(id) {
async delete (id) {
const data1 = await this.post(`/nc/${this.$ctx.$route.params.project_id}/v1/graphql`, {
query: `mutation delete($id:String!){
${this.gqlMutationDeleteName}(id: $id)
}`,
variables: {id}
});
variables: { id }
})
return data1.data.data[this.gqlMutationDeleteName];
return data1.data.data[this.gqlMutationDeleteName]
}
async read(id) {
async read (id) {
const data = await this.post(`/nc/${this.$ctx.$route.params.project_id}/v1/graphql`, {
query: this.gqlReadQuery(id),
variables: null
});
return data.data.data[this.gqlQueryReadName];
})
return data.data.data[this.gqlQueryReadName]
}
get $axios() {
return this.$ctx.$axios;
get $axios () {
return this.$ctx.$axios
}
get table() {
return this.meta && this.meta._tn && inflection.camelize(this.meta._tn);
get table () {
return this.meta && this.meta._tn && inflection.camelize(this.meta._tn)
}
async paginatedM2mNotChildrenList(params, assoc, pid) {
async paginatedM2mNotChildrenList (params, assoc, pid) {
const list = await this.post(`/nc/${this.$ctx.$route.params.project_id}/v1/graphql`, {
query: `query m2mNotChildren($pid: String!,$assoc:String!,$parent:String!, $limit:Int, $offset:Int){
m2mNotChildren(pid: $pid,assoc:$assoc,parent:$parent,limit:$limit, offset:$offset)
@@ -239,7 +227,7 @@ export default class GqlApi {
variables: {
parent: this.meta.tn, assoc, pid: pid + '', ...params
}
});
})
const count = await this.post(`/nc/${this.$ctx.$route.params.project_id}/v1/graphql`, {
query: `query m2mNotChildrenCount($pid: String!,$assoc:String!,$parent:String!){
m2mNotChildrenCount(pid: $pid,assoc:$assoc,parent:$parent)
@@ -247,11 +235,9 @@ export default class GqlApi {
variables: {
parent: this.meta.tn, assoc, pid: pid + ''
}
});
return {list: list.data.data.m2mNotChildren, count: count.data.data.m2mNotChildrenCount.count};
})
return { list: list.data.data.m2mNotChildren, count: count.data.data.m2mNotChildrenCount.count }
}
}
/**
* @copyright Copyright (c) 2021, Xgene Cloud Ltd