Creating a generic UI error handling mechanism
This commit is contained in:
1 parent
3c1e4c51cd
commit
798b197d4a
13 files changed
+81
-9
No files matched your search
@@ -55,3 +55,7 @@ Template.section.onCreated(() => {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Template.registerHelper('hasSection', sectionName => {
|
||||
return !!OHIF.blaze.getSectionContent(Template.instance().view, sectionName);
|
||||
});
|
||||
@@ -4,9 +4,23 @@
|
||||
{{#form class=(concat 'modal-content ' this.formClass) hideValidationBox=true
|
||||
api=(extend instance.api instance.data.api) schema=this.schema
|
||||
}}
|
||||
{{>dialogHeader this}}
|
||||
{{#if or this.title (hasSection 'dialogHeader')}}
|
||||
{{>dialogHeader this}}
|
||||
{{/if}}
|
||||
<div class="modal-body">
|
||||
{{this.bodyText}}
|
||||
<div class="messages">
|
||||
{{#each message in this.messages}}
|
||||
<div class="message">{{{message}}}</div>
|
||||
{{else}}
|
||||
{{#if isError}}
|
||||
{{>pageError (extend this error=this.details)}}
|
||||
{{else}}
|
||||
{{#let message=(choose this.bodyText this.reason this.message 'An error has ocurred.')}}
|
||||
<div class="message">{{message}}</div>
|
||||
{{/let}}
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
</div>
|
||||
{{>UI.contentBlock}}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
|
||||
@@ -105,3 +105,10 @@ Template.dialogForm.events({
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Template.dialogForm.helpers({
|
||||
isError() {
|
||||
const data = Template.instance().data;
|
||||
return data instanceof Error || (data && data.error instanceof Error);
|
||||
}
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
<template name="dialogHeader">
|
||||
<div class="modal-header">
|
||||
{{>section 'dialogHeader'}}
|
||||
{{#if this.title}}
|
||||
{{#if or this.title (hasSection 'dialogHeader')}}
|
||||
{{#button class='close' action='cancel'
|
||||
tagAttributes=(extend this.tagAttributes
|
||||
data-dismiss='modal' aria-label='Close'
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
{{#each message in this.messages}}
|
||||
<div class="message">{{{message}}}</div>
|
||||
{{else}}
|
||||
{{#if eq this.errorType 'Meteor.Error'}}
|
||||
{{#if isError}}
|
||||
{{>pageError (extend this error=this.details)}}
|
||||
{{else}}
|
||||
{{#let message=(choose this.reason this.message 'An error has ocurred.')}}
|
||||
|
||||
@@ -7,3 +7,10 @@ Template.dialogInfo.onRendered(() => {
|
||||
|
||||
$modal.one('hidden.bs.modal', () => instance.data.promiseResolve());
|
||||
});
|
||||
|
||||
Template.dialogInfo.helpers({
|
||||
isError() {
|
||||
const data = Template.instance().data;
|
||||
return data instanceof Error || (data && data.error instanceof Error);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Meteor } from 'meteor/meteor';
|
||||
import { OHIF } from 'meteor/ohif:core';
|
||||
|
||||
OHIF.ui.handleError = error => {
|
||||
let { title, message } = error;
|
||||
|
||||
if (!title) {
|
||||
if (error instanceof Meteor.Error) {
|
||||
title = error.error;
|
||||
} else if (error instanceof Error) {
|
||||
title = error.name;
|
||||
}
|
||||
}
|
||||
|
||||
if (!message) {
|
||||
if (error instanceof Meteor.Error) {
|
||||
message = error.reason;
|
||||
} else if (error instanceof Error) {
|
||||
message = error.message;
|
||||
}
|
||||
}
|
||||
|
||||
const data = Object.assign({
|
||||
title,
|
||||
message,
|
||||
class: 'themed',
|
||||
hideConfirm: true,
|
||||
cancelLabel: 'Dismiss',
|
||||
cancelClass: 'btn-secondary'
|
||||
}, error || {});
|
||||
|
||||
OHIF.ui.showDialog('dialogForm', data);
|
||||
};
|
||||
@@ -10,4 +10,5 @@ import './notifications/notifications.js';
|
||||
import './popover/display.js';
|
||||
import './resizable/resizable.js';
|
||||
import './unsavedChanges/unsavedChanges.js';
|
||||
import './handleError.js';
|
||||
import './styleProperty.js';
|
||||
Reference in new issue
Block a user