Skip to content

Commit

Permalink
Added error message for tempalte and model components. Added React su…
Browse files Browse the repository at this point in the history
…pport.
  • Loading branch information
freeman14 committed Oct 24, 2016
1 parent 4d055fb commit 298315b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 17 deletions.
11 changes: 9 additions & 2 deletions src/sb/components/model/model.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,19 @@ class ModelController {
}

render(event, component) {

// We need original template for prevent changes
// So store original component
this.originalComponent = component;

// Store model
this.model = JSON.stringify(component.model, null, Number(4));
try {
// Store model
this.model = JSON.stringify(component.model, null, Number(4));
this.renderError = false;
} catch (e) {
this.renderError = true;
}

}

}
Expand Down
5 changes: 4 additions & 1 deletion src/sb/components/model/model.html
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<div ui-ace="vm.settings" ng-model="vm.model" flex></div>
<div ng-if="!vm.renderError" ui-ace="vm.settings" ng-model="vm.model" flex></div>
<div class="error__message" ng-if="vm.renderError" flex>
Unable to load the model. Are you pass correct object?
</div>
39 changes: 27 additions & 12 deletions src/sb/components/template/template.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ class TemplateController {

this.$rootScope = $rootScope;

// Listen for new component data and render it
this.listener = $rootScope.$on('render', (event, component) => {
this.render(event, component);
});
if (process && process.env && process.env.TYPE === 'react') {
this.errorMessage = 'Sorry but for now SB not support live component editor for React. We work on this. Stay tuned!';
} else {

// Listen for new component data and render it
this.listener = $rootScope.$on('render', (event, component) => {
this.render(event, component);
});

// ACE editor settings
this.settings = {
mode: 'html',
useWrapMode: true,
onLoad: this.onEditorChange.bind(this)
}

this.errorMessage = 'Unable to load template. Are you pass it with string?';

// ACE editor settings
this.settings = {
mode: 'html',
useWrapMode: true,
onLoad: this.onEditorChange.bind(this)
}

}
Expand Down Expand Up @@ -45,13 +53,20 @@ class TemplateController {
// Try to render new template
try {
this.$rootScope.$broadcast('template', this.component);
} catch (e) {
console.log(`Can't render template: ${e}`)
} catch (e) {
console.log(`Can't render template: ${e}`)
}
}

render(event, component) {


if (typeof component.template !== 'string') {
this.renderError = true;
return;
}

this.renderError = false;

// We need original template for prevent changes
// So store original component
this.originalComponent = component;
Expand Down
3 changes: 2 additions & 1 deletion src/sb/components/template/template.partial.html
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<div ui-ace="vm.settings" ng-model="vm.component.template" flex></div>
<div ng-if="!vm.renderError" ui-ace="vm.settings" ng-model="vm.component.template" flex></div>
<div class="error__message" ng-if="vm.renderError" flex ng-bing="vm.errorMessage"></div>
10 changes: 9 additions & 1 deletion src/sb/styles/app.less
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
@import "./highlight.less";
@import "./highlight.less";

.error__message {
font-size: 18px;
justify-content: center;
align-items: center;
display: flex;
color: rgba(0, 0, 0, 0.54);
}

0 comments on commit 298315b

Please sign in to comment.