Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions media/js/detail-edit/feedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ APP.on("errata:save:dispatch:success", () => {
// Event handler: errata save error reported by server.
APP.on("errata:save:dispatch:error", (response) => {
UTILS.hideFeedback();
if (response && response.responseJSON && response.responseJSON.errorCode) {
UTILS.displayInfoDialog(`Errata is invalid - ${response.responseJSON.errorMessage}.`);
if (response && response.errorCode) {
UTILS.displayInfoDialog(`Errata is invalid - ${response.errorMessage}.`);
} else {
UTILS.displayInfoDialog("An error occurred whilst saving the errata details - please try again. If the problem persists then contact support.");
}
Expand Down
35 changes: 29 additions & 6 deletions media/js/detail-edit/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ const dispatchPost = (url, payload, eventNamespace) => {
"Content-Type": 'application/json; charset=UTF-8',
"X-XSRFToken": Cookies.get('_xsrf')
};

if (STATE.user.isAnonymous === false) {
headers = {
headers = {
"Authorization": STATE.user.oauthCredentials,
...headers
};
Expand All @@ -50,11 +51,33 @@ const dispatchPost = (url, payload, eventNamespace) => {
dataType: 'json',
headers: headers
})
.always((r) => {
if (r.status === 200) {
APP.trigger(`${eventNamespace}:success`, payload);
} else {
APP.trigger(`${eventNamespace}:error`, r);
.done((data, textStatus, xhr) => {
APP.trigger(`${eventNamespace}:success`, data || {});
})
.fail((xhr, textStatus, errorThrown) => {
let response = {};

try {
response = xhr.responseJSON;

if (!response && xhr.responseText) {
response = JSON.parse(xhr.responseText);
}
} catch (e) {
response = {};
}

const error = {
status: xhr.status,
errorCode: response?.error_code || null,
errorField: response?.error_field || null,
errorMessage:
response?.error_message ||
errorThrown ||
xhr.statusText ||
"Unknown error"
};

APP.trigger(`${eventNamespace}:error`, error);
});
};
12 changes: 8 additions & 4 deletions media/js/detail-edit/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,14 @@ export default Backbone.View.extend({
},

// Event handler: errata:save:dispatch:error.
_onSaveToServerError: function ({ responseJSON: error }) {
if (error.errorField) {
this.$(".field-value ." + error.errorField).addClass('has-error');
this.$("#" + error.errorField + "ErrorMessage").text(error.errorMessage);
_onSaveToServerError: function (error = {}) {
const field = error.errorField;

if (!field) {
return;
}

this.$(".field-value ." + error.errorField).addClass('has-error');
this.$("#" + error.errorField + "ErrorMessage").text(error.errorMessage);
}
});
44 changes: 29 additions & 15 deletions media/js/detail-view/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import * as STATE from './state.js';
// Search result.
export class Issue {
// Instance ctor.
constructor(i) {
_.each(_.keys(i), (k) => {
this[k] = i[k];
constructor(json_input) {
_.each(_.keys(json_input), (property) => {
this[property] = json_input[property];
})
this.datasets = this.datasets.sort();
this.ext = new IssueExtensionInfo(this);
Expand All @@ -30,23 +30,27 @@ export class Issue {
// Extended issue information.
class IssueExtensionInfo {
// Instance ctor.
constructor(i) {
this.facets = _.map(i.facets, (term, collection) => new IssueFacet(collection, term));
this.institute = i.institute.toUpperCase();
this.project = STATE.getVocabTerm('project', i.project);
this.projectFacets = _.filter(this.project.facets, (j) => { return j.startsWith('institut') === false});
constructor(issue) {
this.facets = [];
_.each(issue.facets, (terms, collection) => {
_.each(terms, (term) => {
this.facets.push(new IssueFacet(collection, term));
});
});
this.institute = issue.institute.toUpperCase();
this.project = STATE.getVocabTerm('project', issue.project);
this.projectFacets = _.filter(this.project.facets, (facet) => { return facet.startsWith('institut') === false});
this.projectDocURL = this.project.isDocumented ? "https://documentation.es-doc.org/" + this.project.canonicalName : null;
this.severity = STATE.getVocabTerm('severity', i.severity);
this.status = STATE.getVocabTerm('status', i.status);
this.affectedFacets = _.map(this.projectFacets, (j) => new AffectedFacetSet(i.project, this.facets, j));
this.severity = STATE.getVocabTerm('severity', issue.severity);
this.status = STATE.getVocabTerm('status', issue.status);
this.affectedFacets = _.map(this.projectFacets, (collectionID) => new AffectedFacetSet(issue.project, this.facets, collectionID));
}
}

// Issue facet information.
class IssueFacet {
// Instance ctor.
constructor(collection, term) {
this.namespace = term;
this.typeof = collection;
this.value = term;
}
Expand All @@ -56,14 +60,24 @@ class IssueFacet {
class AffectedFacetSet {
constructor(project, facets, collectionID) {
this.collection = STATE.getVocabCollection(collectionID);

this.terms = _.filter(this.collection.terms, (term) => {
return _.find(facets, (facet) => {
return term.drs_name === facet.namespace;
return (
facet.typeof === collectionID &&
term.drs_name === facet.value
);
})
});

if (_.isUndefined(this.collection.cimDocumentType) === false) {
_.each(this.terms, (i) => {
i.documentationURL = 'https://documentation.es-doc.org/' + project + '/' + this.collection.cimDocumentTypeAlternativeName + 's/' + i.canonicalName;
_.each(this.terms, (term) => {
term.documentationURL =
'https://documentation.es-doc.org/' +
project + '/' +
this.collection.cimDocumentTypeAlternativeName +
's/' +
term.canonicalName;
});
}
}
Expand Down