mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-12 00:50:40 +00:00
Restructure javascript
This commit is contained in:
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);
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user