From 4daf3359b9228990318201002bf8ad17026ae53b Mon Sep 17 00:00:00 2001 From: Patrick Jentsch Date: Thu, 12 Oct 2023 10:03:12 +0200 Subject: [PATCH] move constants in cqi package into seperate file --- app/static/js/cqi/api/client.js | 8 ++++---- app/static/js/cqi/constants.js | 6 ++++++ app/static/js/cqi/index.js | 5 ----- app/static/js/cqi/models/subcorpora.js | 16 ++++++++-------- app/templates/_scripts.html.j2 | 1 + 5 files changed, 19 insertions(+), 17 deletions(-) create mode 100644 app/static/js/cqi/constants.js diff --git a/app/static/js/cqi/api/client.js b/app/static/js/cqi/api/client.js index 14bf3690..23695987 100644 --- a/app/static/js/cqi/api/client.js +++ b/app/static/js/cqi/api/client.js @@ -524,7 +524,7 @@ cqi.api.APIClient = class APIClient { /** * Dump the values of for match ranges .. - * in . is one of the CQI_CONST_FIELD_* constants. + * in . is one of the cqi.constants.FIELD_* constants. * * @param {string} subcorpus * @param {number} field @@ -561,9 +561,9 @@ cqi.api.APIClient = class APIClient { * * returns (id, frequency) pairs flattened into a list of size 2* * field is one of - * - CQI_CONST_FIELD_MATCH - * - CQI_CONST_FIELD_TARGET - * - CQI_CONST_FIELD_KEYWORD + * - cqi.constants.FIELD_MATCH + * - cqi.constants.FIELD_TARGET + * - cqi.constants.FIELD_KEYWORD * * NB: pairs are sorted by frequency desc. * diff --git a/app/static/js/cqi/constants.js b/app/static/js/cqi/constants.js new file mode 100644 index 00000000..d888e240 --- /dev/null +++ b/app/static/js/cqi/constants.js @@ -0,0 +1,6 @@ +cqi.constants = {}; + +cqi.constants.FIELD_KEYWORD = 9; +cqi.constants.FIELD_MATCH = 16; +cqi.constants.FIELD_MATCHEND = 17; +cqi.constants.FIELD_TARGET = 0; diff --git a/app/static/js/cqi/index.js b/app/static/js/cqi/index.js index 1558b308..d941a870 100644 --- a/app/static/js/cqi/index.js +++ b/app/static/js/cqi/index.js @@ -1,6 +1 @@ var cqi = {}; - -cqi.CONST_FIELD_KEYWORD = 9; -cqi.CONST_FIELD_MATCH = 16; -cqi.CONST_FIELD_MATCHEND = 17; -cqi.CONST_FIELD_TARGET = 0; diff --git a/app/static/js/cqi/models/subcorpora.js b/app/static/js/cqi/models/subcorpora.js index 86e6cf67..aeba9485 100644 --- a/app/static/js/cqi/models/subcorpora.js +++ b/app/static/js/cqi/models/subcorpora.js @@ -145,17 +145,17 @@ cqi.models.subcorpora.SubcorpusCollection = class SubcorpusCollection extends cq let apiName = `${this.corpus.apiName}:${subcorpusName}`; /** @type {object} */ let fields = {}; - if (await this.client.api.cqp_subcorpus_has_field(apiName, cqi.CONST_FIELD_MATCH)) { - fields.match = cqi.CONST_FIELD_MATCH; + if (await this.client.api.cqp_subcorpus_has_field(apiName, cqi.constants.FIELD_MATCH)) { + fields.match = cqi.constants.FIELD_MATCH; } - if (await this.client.api.cqp_subcorpus_has_field(apiName, cqi.CONST_FIELD_MATCHEND)) { - fields.matchend = cqi.CONST_FIELD_MATCHEND + if (await this.client.api.cqp_subcorpus_has_field(apiName, cqi.constants.FIELD_MATCHEND)) { + fields.matchend = cqi.constants.FIELD_MATCHEND } - if (await this.client.api.cqp_subcorpus_has_field(apiName, cqi.CONST_FIELD_TARGET)) { - fields.target = cqi.CONST_FIELD_TARGET + if (await this.client.api.cqp_subcorpus_has_field(apiName, cqi.constants.FIELD_TARGET)) { + fields.target = cqi.constants.FIELD_TARGET } - if (await this.client.api.cqp_subcorpus_has_field(apiName, cqi.CONST_FIELD_KEYWORD)) { - fields.keyword = cqi.CONST_FIELD_KEYWORD + if (await this.client.api.cqp_subcorpus_has_field(apiName, cqi.constants.FIELD_KEYWORD)) { + fields.keyword = cqi.constants.FIELD_KEYWORD } return { api_name: apiName, diff --git a/app/templates/_scripts.html.j2 b/app/templates/_scripts.html.j2 index 2b84659a..8e8dd343 100644 --- a/app/templates/_scripts.html.j2 +++ b/app/templates/_scripts.html.j2 @@ -18,6 +18,7 @@ filters='rjsmin', output='gen/cqi.%(version)s.js', 'js/cqi/index.js', + 'js/cqi/constants.js', 'js/cqi/errors.js', 'js/cqi/status.js', 'js/cqi/api/index.js',