Bug fixes

This commit is contained in:
Inga Kirschnick 2022-11-21 15:41:07 +01:00
parent 3f5750a000
commit 0128c6310b
3 changed files with 47 additions and 170 deletions

View File

@ -17,20 +17,8 @@ class App {
fetch(`/users/${userId}?backrefs=true&relationships=true`, {headers: {Accept: 'application/json'}}) fetch(`/users/${userId}?backrefs=true&relationships=true`, {headers: {Accept: 'application/json'}})
.then( .then(
(response) => { (response) => {
switch (response.status) { if (response.status === 403) {this.flash('Forbidden', 'error'); reject(response);}
case 403: { return response.json();
this.flash('Forbidden', 'error');
break;
}
case 404: {
this.flash('Not Found', 'error');
break;
}
default: {
response.json();
break;
}
}
}, },
(response) => { (response) => {
this.flash('Something went wrong', 'error'); this.flash('Something went wrong', 'error');

View File

@ -84,7 +84,7 @@ class SpaCyNLPPipelineModelList extends RessourceList {
this.listjs.list.addEventListener('change', (event) => {this.onChange(event)}); this.listjs.list.addEventListener('change', (event) => {this.onChange(event)});
} }
init (user) { init(user) {
this._init(user.spacy_nlp_pipeline_models); this._init(user.spacy_nlp_pipeline_models);
for (let switchElement of this.listjs.list.querySelectorAll('.shared')) { for (let switchElement of this.listjs.list.querySelectorAll('.shared')) {
if (user.role.name !== 'Administrator' || user.role.name !== 'Contributor') { if (user.role.name !== 'Administrator' || user.role.name !== 'Contributor') {

View File

@ -12,24 +12,11 @@ class Utils {
fetch(`/corpora/${corpus.id}/build`, {method: 'POST', headers: {Accept: 'application/json'}}) fetch(`/corpora/${corpus.id}/build`, {method: 'POST', headers: {Accept: 'application/json'}})
.then( .then(
(response) => { (response) => {
switch(response.status) { if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
case 403: if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);}
app.flash('Forbidden', 'error'); if (response.status === 409) {app.flash('Conflict', 'error'); reject(response);}
reject(response); app.flash(`Corpus "${corpus.title}" marked for building`, 'corpus');
break; resolve(response);
case 404:
app.flash('Not Found', 'error');
reject(response);
break;
case 409:
app.flash('Conflict', 'error');
reject(response);
break;
default:
app.flash(`Corpus "${corpus.title}" marked for building`, 'corpus');
resolve(response);
break;
}
}, },
(response) => { (response) => {
app.flash('Something went wrong', 'error'); app.flash('Something went wrong', 'error');
@ -75,20 +62,10 @@ class Utils {
fetch(`/corpora/${corpus.id}`, {method: 'DELETE', headers: {Accept: 'application/json'}}) fetch(`/corpora/${corpus.id}`, {method: 'DELETE', headers: {Accept: 'application/json'}})
.then( .then(
(response) => { (response) => {
switch(response.status) { if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
case 403: if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);}
app.flash('Forbidden', 'error'); app.flash(`Corpus "${corpus.title}" marked for deletion`, 'corpus');
reject(response); resolve(response);
break;
case 404:
app.flash('Not Found', 'error');
reject(response);
break;
default:
app.flash(`Corpus "${corpus.title}" marked for deletion`, 'corpus');
resolve(response);
break;
}
}, },
(response) => { (response) => {
app.flash('Something went wrong', 'error'); app.flash('Something went wrong', 'error');
@ -137,20 +114,10 @@ class Utils {
fetch(`/corpora/${corpusId}/files/${corpusFileId}`, {method: 'DELETE', headers: {Accept: 'application/json'}}) fetch(`/corpora/${corpusId}/files/${corpusFileId}`, {method: 'DELETE', headers: {Accept: 'application/json'}})
.then( .then(
(response) => { (response) => {
switch(response.status) { if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
case 403: if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);}
app.flash('Forbidden', 'error'); app.flash(`Corpus File "${corpusFileTitle}" deleted`, 'corpus');
reject(response); resolve(response);
break;
case 404:
app.flash('Not Found', 'error');
reject(response);
break;
default:
app.flash(`Corpus file "${corpusFileTitle}" marked for deletion`, 'corpus');
resolve(response);
break;
}
}, },
(response) => { (response) => {
app.flash('Something went wrong', 'error'); app.flash('Something went wrong', 'error');
@ -196,20 +163,10 @@ class Utils {
fetch(`/contributions/spacy-nlp-pipeline-models/${spaCyNLPPipelineModelId}`, {method: 'DELETE'}) fetch(`/contributions/spacy-nlp-pipeline-models/${spaCyNLPPipelineModelId}`, {method: 'DELETE'})
.then( .then(
(response) => { (response) => {
switch(response.status) { if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
case 403: if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);}
app.flash('Forbidden', 'error'); app.flash(`SpaCy NLP Pipeline Model "${spaCyNLPPipelineModelTitle}" marked for deletion`);
reject(response); resolve(response);
break;
case 404:
app.flash('Not Found', 'error');
reject(response);
break;
default:
app.flash(`SpaCy NLP Pipeline Model "${spaCyNLPPipelineModelTitle}" marked for deletion`);
resolve(response);
break;
}
}, },
(response) => { (response) => {
app.flash('Something went wrong', 'error'); app.flash('Something went wrong', 'error');
@ -255,21 +212,10 @@ class Utils {
fetch(`/contributions/tesseract-ocr-pipeline-models/${tesseractOCRPipelineModelId}`, {method: 'DELETE'}) fetch(`/contributions/tesseract-ocr-pipeline-models/${tesseractOCRPipelineModelId}`, {method: 'DELETE'})
.then( .then(
(response) => { (response) => {
switch(response.status) { if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
case 403: if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);}
app.flash('Forbidden', 'error'); app.flash(`Tesseract OCR Pipeline Model "${tesseractOCRPipelineModelTitle}" marked for deletion`);
reject(response); resolve(response);
break;
case 404:
app.flash('Not Found', 'error');
reject(response);
break;
default:
app.flash(`Tesseract OCR Pipeline Model "${tesseractOCRPipelineModelTitle}" marked for deletion`);
resolve(response);
break;
}
}, },
(response) => { (response) => {
app.flash('Something went wrong', 'error'); app.flash('Something went wrong', 'error');
@ -317,20 +263,10 @@ class Utils {
fetch(`/jobs/${job.id}`, {method: 'DELETE', headers: {Accept: 'application/json'}}) fetch(`/jobs/${job.id}`, {method: 'DELETE', headers: {Accept: 'application/json'}})
.then( .then(
(response) => { (response) => {
switch(response.status) { if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
case 403: if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);}
app.flash('Forbidden', 'error'); app.flash(`Job "${jobTitle}" marked for deletion`, 'job');
reject(response); resolve(response);
break;
case 404:
app.flash('Not Found', 'error');
reject(response);
break;
default:
app.flash(`Job "${jobTitle}" marked for deletion`, 'job');
resolve(response);
break;
}
}, },
(response) => { (response) => {
app.flash('Something went wrong', 'error'); app.flash('Something went wrong', 'error');
@ -349,20 +285,9 @@ class Utils {
fetch(`/jobs/${job.id}/log`, {method: 'GET', headers: {Accept: 'application/json, text/plain'}}) fetch(`/jobs/${job.id}/log`, {method: 'GET', headers: {Accept: 'application/json, text/plain'}})
.then( .then(
(response) => { (response) => {
switch(response.status) { if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
case 403: if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);}
app.flash('Forbidden', 'error'); return response.text();
reject(response);
break;
case 404:
app.flash('Not Found', 'error');
reject(response);
break;
default:
resolve(response);
response.text();
break;
}
}, },
(response) => { (response) => {
app.flash('Something went wrong', 'error'); app.flash('Something went wrong', 'error');
@ -395,6 +320,7 @@ class Utils {
} }
); );
modal.open(); modal.open();
resolve(text);
} }
); );
}); });
@ -436,23 +362,11 @@ class Utils {
fetch(`/jobs/${job.id}/restart`, {method: 'POST', headers: {Accept: 'application/json'}}) fetch(`/jobs/${job.id}/restart`, {method: 'POST', headers: {Accept: 'application/json'}})
.then( .then(
(response) => { (response) => {
switch(response.status) { if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
case 403: if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);}
app.flash('Forbidden', 'error'); if (response.status === 409) {app.flash('Conflict', 'error'); reject(response);}
reject(response); app.flash(`Job "${jobTitle}" restarted.`, 'job');
break; resolve(response);
case 404:
app.flash('Not Found', 'error');
reject(response);
break;
case 409:
app.flash('Conflict', 'error');
reject(response);
default:
app.flash(`Job "${jobTitle}" restarted.`, 'job');
resolve(response);
break;
}
}, },
(response) => { (response) => {
app.flash('Something went wrong', 'error'); app.flash('Something went wrong', 'error');
@ -500,21 +414,10 @@ class Utils {
fetch(`/users/${user.id}`, {method: 'DELETE', headers: {Accept: 'application/json'}}) fetch(`/users/${user.id}`, {method: 'DELETE', headers: {Accept: 'application/json'}})
.then( .then(
(response) => { (response) => {
switch(response.status) { if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
case 403: if (response.status === 404) {app.flash('Not Found', 'error'); reject(response);}
app.flash('Forbidden', 'error'); app.flash(`User "${userName}" marked for deletion`);
reject(response); resolve(response);
break;
case 404:
app.flash('Not Found', 'error');
reject(response);
break;
default:
app.flash(`User "${userName}" marked for deletion`);
resolve(response);
break;
}
}, },
(response) => { (response) => {
app.flash('Something went wrong', 'error'); app.flash('Something went wrong', 'error');
@ -538,16 +441,9 @@ class Utils {
fetch(`/contributions/tesseract-ocr-pipeline-models/${tesseractOCRPipelineModel.id}/toggle-public-status`, {method: 'POST', headers: {Accept: 'application/json'}}) fetch(`/contributions/tesseract-ocr-pipeline-models/${tesseractOCRPipelineModel.id}/toggle-public-status`, {method: 'POST', headers: {Accept: 'application/json'}})
.then( .then(
(response) => { (response) => {
switch(response.status) { if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
case 403: app.flash(msg);
app.flash('Forbidden', 'error'); resolve(response);
reject(response);
break;
default:
app.flash(msg);
resolve(response);
break;
}
}, },
(response) => { (response) => {
app.flash('Something went wrong', 'error'); app.flash('Something went wrong', 'error');
@ -569,16 +465,9 @@ class Utils {
fetch(`/contributions/spacy-nlp-pipeline-models/${spaCyNLPPipelineModel.id}/toggle-public-status`, {method: 'POST', headers: {Accept: 'application/json'}}) fetch(`/contributions/spacy-nlp-pipeline-models/${spaCyNLPPipelineModel.id}/toggle-public-status`, {method: 'POST', headers: {Accept: 'application/json'}})
.then( .then(
(response) => { (response) => {
switch(response.status) { if (response.status === 403) {app.flash('Forbidden', 'error'); reject(response);}
case 403: app.flash(msg);
app.flash('Forbidden', 'error'); resolve(response);
reject(response);
break;
default:
app.flash(msg);
resolve(response);
break;
}
}, },
(response) => { (response) => {
app.flash('Something went wrong', 'error'); app.flash('Something went wrong', 'error');