mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Restructure javascript
This commit is contained in:
parent
0d7fca9b0b
commit
6bb4594937
51
app/static/js/Requests/Contributions.js
Normal file
51
app/static/js/Requests/Contributions.js
Normal file
@ -0,0 +1,51 @@
|
||||
/*****************************************************************************
|
||||
* Contributions *
|
||||
* Fetch requests for /contributions routes *
|
||||
*****************************************************************************/
|
||||
Requests.contributions = {};
|
||||
|
||||
Requests.contributions.spacy_nlp_pipeline_models = {};
|
||||
|
||||
Requests.contributions.spacy_nlp_pipeline_models.ent = {};
|
||||
|
||||
Requests.contributions.spacy_nlp_pipeline_models.ent.delete = (spacyNlpPipelineModelId) => {
|
||||
let input = `/contributions/spacy-nlp-pipeline-models/${spacyNlpPipelineModelId}`;
|
||||
let init = {
|
||||
method: 'DELETE'
|
||||
};
|
||||
return Requests.JSONfetch(input, init);
|
||||
};
|
||||
|
||||
Requests.contributions.spacy_nlp_pipeline_models.ent.isPublic = {};
|
||||
|
||||
Requests.contributions.spacy_nlp_pipeline_models.ent.isPublic.update = (spacyNlpPipelineModelId, value) => {
|
||||
let input = `/contributions/spacy-nlp-pipeline-models/${spacyNlpPipelineModelId}/is_public`;
|
||||
let init = {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(value)
|
||||
};
|
||||
return Requests.JSONfetch(input, init);
|
||||
};
|
||||
|
||||
Requests.contributions.tesseract_ocr_pipeline_models = {};
|
||||
|
||||
Requests.contributions.tesseract_ocr_pipeline_models.ent = {};
|
||||
|
||||
Requests.contributions.tesseract_ocr_pipeline_models.ent.delete = (tesseractOcrPipelineModelId) => {
|
||||
let input = `/contributions/tesseract-ocr-pipeline-models/${tesseractOcrPipelineModelId}`;
|
||||
let init = {
|
||||
method: 'DELETE'
|
||||
};
|
||||
return Requests.JSONfetch(input, init);
|
||||
};
|
||||
|
||||
Requests.contributions.tesseract_ocr_pipeline_models.ent.isPublic = {};
|
||||
|
||||
Requests.contributions.tesseract_ocr_pipeline_models.ent.isPublic.update = (tesseractOcrPipelineModelId, value) => {
|
||||
let input = `/contributions/tesseract-ocr-pipeline-models/${tesseractOcrPipelineModelId}/is_public`;
|
||||
let init = {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(value)
|
||||
};
|
||||
return Requests.JSONfetch(input, init);
|
||||
};
|
37
app/static/js/Requests/Requests.js
Normal file
37
app/static/js/Requests/Requests.js
Normal file
@ -0,0 +1,37 @@
|
||||
Requests = {};
|
||||
|
||||
Requests.JSONfetch = (input, init={}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let fixedInit = {};
|
||||
fixedInit.headers = {};
|
||||
fixedInit.headers['Accept'] = 'application/json';
|
||||
if (init.hasOwnProperty('body')) {
|
||||
fixedInit.headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
fetch(input, Utils.mergeObjectsDeep(init, fixedInit))
|
||||
.then(
|
||||
(response) => {
|
||||
response.json()
|
||||
.then(
|
||||
(json) => {
|
||||
let message = json.message || json;
|
||||
let category = json.category || 'message';
|
||||
app.flash(message, category);
|
||||
},
|
||||
(error) => {
|
||||
app.flash(`[${response.status}]: ${response.statusText}`, 'error');
|
||||
}
|
||||
);
|
||||
if (response.ok) {
|
||||
resolve(response);
|
||||
} else {
|
||||
reject(response);
|
||||
}
|
||||
},
|
||||
(response) => {
|
||||
app.flash('Something went wrong', 'error');
|
||||
reject(response);
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
@ -1,16 +1,11 @@
|
||||
class CorpusDisplay extends RessourceDisplay {
|
||||
class CorpusDisplay extends ResourceDisplay {
|
||||
constructor(displayElement) {
|
||||
super(displayElement);
|
||||
this.corpusId = displayElement.dataset.corpusId;
|
||||
this.displayElement
|
||||
.querySelector('.action-button[data-action="build-request"]')
|
||||
.addEventListener('click', (event) => {
|
||||
Utils.buildCorpusRequest(this.userId, this.corpusId);
|
||||
});
|
||||
this.displayElement
|
||||
.querySelector('.action-button[data-action="delete-request"]')
|
||||
.addEventListener('click', (event) => {
|
||||
Utils.deleteCorpusRequest(this.userId, this.corpusId);
|
||||
Requests.corpora.corpus.build(this.corpusId);
|
||||
});
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
class JobDisplay extends RessourceDisplay {
|
||||
class JobDisplay extends ResourceDisplay {
|
||||
constructor(displayElement) {
|
||||
super(displayElement);
|
||||
this.jobId = this.displayElement.dataset.jobId;
|
@ -1,4 +1,4 @@
|
||||
class RessourceDisplay {
|
||||
class ResourceDisplay {
|
||||
constructor(displayElement) {
|
||||
this.displayElement = displayElement;
|
||||
this.userId = this.displayElement.dataset.userId;
|
@ -120,7 +120,7 @@ class SpaCyNLPPipelineModelList extends ResourceList {
|
||||
switch (listAction) {
|
||||
case 'toggle-is-public': {
|
||||
let newIsPublicValue = listActionElement.checked;
|
||||
Utils.updateSpaCyNLPPipelineModelIsPublicRequest(itemId, newIsPublicValue)
|
||||
Requests.contributions.spacy_nlp_pipeline_models.ent.isPublic.update(itemId, newIsPublicValue)
|
||||
.catch((response) => {
|
||||
listActionElement.checked = !newIsPublicValue;
|
||||
});
|
||||
@ -141,7 +141,7 @@ class SpaCyNLPPipelineModelList extends ResourceList {
|
||||
let listAction = listActionElement === null ? 'view' : listActionElement.dataset.listAction;
|
||||
switch (listAction) {
|
||||
case 'delete-request': {
|
||||
Utils.deleteSpaCyNLPPipelineModelRequest(this.userId, itemId);
|
||||
Requests.contributions.spacy_nlp_pipeline_models.ent.delete(itemId);
|
||||
break;
|
||||
}
|
||||
case 'view': {
|
||||
|
@ -129,7 +129,7 @@ class TesseractOCRPipelineModelList extends ResourceList {
|
||||
switch (listAction) {
|
||||
case 'toggle-is-public': {
|
||||
let newIsPublicValue = listActionElement.checked;
|
||||
Utils.updateTesseractOCRPipelineModelIsPublicRequest(itemId, newIsPublicValue)
|
||||
Requests.contributions.tesseract_ocr_pipeline_models.ent.isPublic.update(itemId, newIsPublicValue)
|
||||
.catch((response) => {
|
||||
listActionElement.checked = !newIsPublicValue;
|
||||
});
|
||||
@ -155,7 +155,7 @@ class TesseractOCRPipelineModelList extends ResourceList {
|
||||
let listAction = listActionElement === null ? 'view' : listActionElement.dataset.listAction;
|
||||
switch (listAction) {
|
||||
case 'delete-request': {
|
||||
Utils.deleteTesseractOCRPipelineModelRequest(this.userId, itemId);
|
||||
Requests.contributions.tesseract_ocr_pipeline_models.ent.delete(itemId);
|
||||
break;
|
||||
}
|
||||
case 'view': {
|
||||
|
@ -6,18 +6,37 @@
|
||||
output='gen/app.%(version)s.js',
|
||||
'js/App.js',
|
||||
'js/Utils.js',
|
||||
'js/Forms/Form.js',
|
||||
'js/Forms/CreateCorpusFileForm.js',
|
||||
'js/Forms/CreateJobForm.js',
|
||||
'js/Forms/CreateContributionForm.js',
|
||||
'js/CorpusAnalysis/CQiClient.js',
|
||||
'js/CorpusAnalysis/CorpusAnalysisApp.js',
|
||||
'js/CorpusAnalysis/CorpusAnalysisConcordance.js',
|
||||
'js/CorpusAnalysis/CorpusAnalysisReader.js',
|
||||
'js/CorpusAnalysis/QueryBuilder.js',
|
||||
'js/RessourceDisplays/RessourceDisplay.js',
|
||||
'js/RessourceDisplays/CorpusDisplay.js',
|
||||
'js/RessourceDisplays/JobDisplay.js',
|
||||
'js/XMLtoObject.js'
|
||||
%}
|
||||
<script src="{{ ASSET_URL }}"></script>
|
||||
{%- endassets %}
|
||||
{%- assets
|
||||
filters='rjsmin',
|
||||
output='gen/Forms.%(version)s.js',
|
||||
'js/Forms/Form.js',
|
||||
'js/Forms/CreateCorpusFileForm.js',
|
||||
'js/Forms/CreateJobForm.js',
|
||||
'js/Forms/CreateContributionForm.js'
|
||||
%}
|
||||
<script src="{{ ASSET_URL }}"></script>
|
||||
{%- endassets %}
|
||||
{%- assets
|
||||
filters='rjsmin',
|
||||
output='gen/ResourceDisplays.%(version)s.js',
|
||||
'js/ResourceDisplays/ResourceDisplay.js',
|
||||
'js/ResourceDisplays/CorpusDisplay.js',
|
||||
'js/ResourceDisplays/JobDisplay.js'
|
||||
%}
|
||||
<script src="{{ ASSET_URL }}"></script>
|
||||
{%- endassets %}
|
||||
{%- assets
|
||||
filters='rjsmin',
|
||||
output='gen/ResourceLists.%(version)s.js',
|
||||
'js/ResourceLists/ResourceList.js',
|
||||
'js/ResourceLists/CorpusFileList.js',
|
||||
'js/ResourceLists/PublicCorpusFileList.js',
|
||||
@ -31,8 +50,15 @@
|
||||
'js/ResourceLists/TesseractOCRPipelineModelList.js',
|
||||
'js/ResourceLists/UserList.js',
|
||||
'js/ResourceLists/AdminUserList.js',
|
||||
'js/ResourceLists/CorpusFollowerList.js',
|
||||
'js/XMLtoObject.js'
|
||||
'js/ResourceLists/CorpusFollowerList.js'
|
||||
%}
|
||||
<script src="{{ ASSET_URL }}"></script>
|
||||
{%- endassets %}
|
||||
{%- assets
|
||||
filters='rjsmin',
|
||||
output='gen/Requests.%(version)s.js',
|
||||
'js/Requests/Requests.js',
|
||||
'js/Requests/Contributions.js'
|
||||
%}
|
||||
<script src="{{ ASSET_URL }}"></script>
|
||||
{%- endassets %}
|
||||
|
Loading…
Reference in New Issue
Block a user