mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
Restructure toggle ispublic requests
This commit is contained in:
parent
cfa4fa68f2
commit
7770d4d478
@ -119,7 +119,11 @@ class SpaCyNLPPipelineModelList extends ResourceList {
|
||||
let listAction = listActionElement.dataset.listAction;
|
||||
switch (listAction) {
|
||||
case 'toggle-is-public': {
|
||||
Utils.spaCyNLPPipelineModelToggleIsPublicRequest(this.userId, itemId);
|
||||
let newIsPublicValue = listActionElement.checked;
|
||||
Utils.updateSpaCyNLPPipelineModelIsPublicRequest(itemId, newIsPublicValue)
|
||||
.catch((response) => {
|
||||
listActionElement.checked = !newIsPublicValue;
|
||||
});
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
@ -128,7 +128,11 @@ class TesseractOCRPipelineModelList extends ResourceList {
|
||||
let listAction = listActionElement.dataset.listAction;
|
||||
switch (listAction) {
|
||||
case 'toggle-is-public': {
|
||||
Utils.tesseractOCRPipelineModelToggleIsPublicRequest(this.userId, itemId);
|
||||
let newIsPublicValue = listActionElement.checked;
|
||||
Utils.updateTesseractOCRPipelineModelIsPublicRequest(itemId, newIsPublicValue)
|
||||
.catch((response) => {
|
||||
listActionElement.checked = !newIsPublicValue;
|
||||
});
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
@ -101,13 +101,21 @@ class Utils {
|
||||
|
||||
static updateCorpusFollowerRole(corpusId, followerId, roleName) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(`/corpora/${corpusId}/followers/${followerId}/role`, {method: 'POST', headers: {Accept: 'application/json', 'Content-Type': 'application/json'}, body: JSON.stringify({role: roleName})})
|
||||
let fetchRessource = `/corpora/${corpusId}/followers/${followerId}/role`;
|
||||
let fetchOptions = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({role: roleName})
|
||||
};
|
||||
fetch(fetchRessource, fetchOptions)
|
||||
.then(
|
||||
(response) => {
|
||||
if (response.ok) {
|
||||
app.flash('Role updated', 'corpus');
|
||||
resolve(response);
|
||||
return;
|
||||
} else {
|
||||
app.flash(`${response.statusText}`, 'error');
|
||||
reject(response);
|
||||
@ -179,7 +187,15 @@ class Utils {
|
||||
|
||||
static unfollowCorpusRequest(corpusId, followerId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(`/corpora/${corpusId}/followers/${followerId}/unfollow`, {method: 'POST', headers: {Accept: 'application/json'}})
|
||||
let fetchRessource = `/corpora/${corpusId}/followers/${followerId}/unfollow`;
|
||||
let fetchOptions = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
fetch(fetchRessource, fetchOptions)
|
||||
.then(
|
||||
(response) => {
|
||||
if (response.ok) {
|
||||
@ -683,23 +699,27 @@ class Utils {
|
||||
});
|
||||
}
|
||||
|
||||
static tesseractOCRPipelineModelToggleIsPublicRequest(userId, tesseractOCRPipelineModelId, is_public) {
|
||||
static updateTesseractOCRPipelineModelIsPublicRequest(tesseractOCRPipelineModelId, newIsPublicValue) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let tesseractOCRPipelineModel;
|
||||
try {
|
||||
tesseractOCRPipelineModel = app.data.users[userId].tesseract_ocr_pipeline_models[tesseractOCRPipelineModelId];
|
||||
} catch (error) {
|
||||
tesseractOCRPipelineModel = {};
|
||||
}
|
||||
|
||||
fetch(`/contributions/tesseract-ocr-pipeline-models/${tesseractOCRPipelineModelId}/toggle-public-status`, {method: 'POST', headers: {Accept: 'application/json'}})
|
||||
let fetchRessource = `/contributions/tesseract-ocr-pipeline-models/${tesseractOCRPipelineModelId}/is_public`;
|
||||
let fetchOptions = {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(newIsPublicValue)
|
||||
};
|
||||
fetch(fetchRessource, fetchOptions)
|
||||
.then(
|
||||
(response) => {
|
||||
if (response.status === 403) {
|
||||
app.flash('Forbidden', 'error');
|
||||
if (response.ok) {
|
||||
response.json().then((data) => {app.flash(data);});
|
||||
resolve(response);
|
||||
} else {
|
||||
app.flash(`${response.statusText}`, 'error');
|
||||
reject(response);
|
||||
}
|
||||
resolve(response);
|
||||
},
|
||||
(response) => {
|
||||
app.flash('Something went wrong', 'error');
|
||||
@ -709,23 +729,27 @@ class Utils {
|
||||
});
|
||||
}
|
||||
|
||||
static spaCyNLPPipelineModelToggleIsPublicRequest(userId, spaCyNLPPipelineModelId) {
|
||||
static updateSpaCyNLPPipelineModelIsPublicRequest(SpaCyNLPPipelineModelId, newIsPublicValue) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let spaCyNLPPipelineModel;
|
||||
try {
|
||||
spaCyNLPPipelineModel = app.data.users[userId].spacy_nlp_pipeline_models[spaCyNLPPipelineModelId];
|
||||
} catch (error) {
|
||||
spaCyNLPPipelineModel = {};
|
||||
}
|
||||
|
||||
fetch(`/contributions/spacy-nlp-pipeline-models/${spaCyNLPPipelineModelId}/toggle-public-status`, {method: 'POST', headers: {Accept: 'application/json'}})
|
||||
let fetchRessource = `/contributions/spacy-nlp-pipeline-models/${SpaCyNLPPipelineModelId}/is_public`;
|
||||
let fetchOptions = {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(newIsPublicValue)
|
||||
};
|
||||
fetch(fetchRessource, fetchOptions)
|
||||
.then(
|
||||
(response) => {
|
||||
if (response.status === 403) {
|
||||
app.flash('Forbidden', 'error');
|
||||
if (response.ok) {
|
||||
response.json().then((data) => {app.flash(data);});
|
||||
resolve(response);
|
||||
} else {
|
||||
app.flash(`${response.statusText}`, 'error');
|
||||
reject(response);
|
||||
}
|
||||
resolve(response);
|
||||
},
|
||||
(response) => {
|
||||
app.flash('Something went wrong', 'error');
|
||||
|
Loading…
Reference in New Issue
Block a user