AMBARI-11984. No 'Preview' for template widget if invalid expression name existed.(xiwang)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/99fe8097 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/99fe8097 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/99fe8097 Branch: refs/heads/branch-2.1 Commit: 99fe8097c3daa12e05b591265877b81e35deb417 Parents: 488acc5 Author: Xi Wang <[email protected]> Authored: Wed Jun 17 11:42:59 2015 -0700 Committer: Xi Wang <[email protected]> Committed: Wed Jun 17 12:30:31 2015 -0700 ---------------------------------------------------------------------- .../service/widgets/create/step2_controller.js | 21 ++++++++++++++++++-- ambari-web/app/messages.js | 1 + .../app/styles/enhanced_service_dashboard.less | 8 ++++++++ .../service/widgets/create/step2_template.hbs | 5 ++++- 4 files changed, 32 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/99fe8097/ambari-web/app/controllers/main/service/widgets/create/step2_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/service/widgets/create/step2_controller.js b/ambari-web/app/controllers/main/service/widgets/create/step2_controller.js index d1ad4e1..0ab4048 100644 --- a/ambari-web/app/controllers/main/service/widgets/create/step2_controller.js +++ b/ambari-web/app/controllers/main/service/widgets/create/step2_controller.js @@ -111,13 +111,13 @@ App.WidgetWizardStep2Controller = Em.Controller.extend({ case "GRAPH": return !this.isGraphDataComplete(this.get('dataSets')); case "TEMPLATE": - return !this.isTemplateDataComplete(this.get('expressions'), this.get('templateValue')); + return this.get('isTemplateInvalid') || !this.isTemplateDataComplete(this.get('expressions'), this.get('templateValue')); } return false; }.property( '[email protected]', '[email protected]', - 'templateValue' + 'templateValue', 'isTemplateInvalid' ), /** @@ -313,6 +313,23 @@ App.WidgetWizardStep2Controller = Em.Controller.extend({ parseTemplateExpression: function (templateValue, expressions) { var metrics = []; var self = this; + + // check if there is invalid expression name eg. {{myExpre}} + var isTemplateInvalid = false; + var validExpressionName = /\{\{(Expression[\d])\}\}/g; + var expressionName = /\{\{((?!}}).)*\}\}/g; + if (templateValue) { + var expressionNames = templateValue.match(expressionName); + if (expressionNames) { + expressionNames.forEach(function(name) { + if (!name.match(validExpressionName)) { + isTemplateInvalid = true; + } + }); + } + } + this.set('isTemplateInvalid', isTemplateInvalid); + var expression = templateValue.replace(/\{\{Expression[\d]\}\}/g, function (exp) { var result; if (expressions.someProperty('alias', exp)) { http://git-wip-us.apache.org/repos/asf/ambari/blob/99fe8097/ambari-web/app/messages.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js index 0f5a8a9..6d579d5 100644 --- a/ambari-web/app/messages.js +++ b/ambari-web/app/messages.js @@ -2595,6 +2595,7 @@ Em.I18n.translations = { 'widget.create.wizard.step2.body.text':'Define the expression with any metrics and valid operators. </br>Use parentheses when necessary.', 'widget.create.wizard.step2.body.template':'Define the template with any number of expressions and any string. An expression can be referenced from a template by enclosing its name with double curly braces.', 'widget.create.wizard.step2.body.warning':'Note: Valid operators are +, -, *, /', + 'widget.create.wizard.step2.body.template.invalid.msg':'Invalid expression name existed. Should use name "Expression#" with double curly braces.', 'widget.create.wizard.step2.addExpression': 'Add Expression', 'widget.create.wizard.step2.addDataset': 'Add data set', 'widget.create.wizard.step2.allComponents': 'All {0}s', http://git-wip-us.apache.org/repos/asf/ambari/blob/99fe8097/ambari-web/app/styles/enhanced_service_dashboard.less ---------------------------------------------------------------------- diff --git a/ambari-web/app/styles/enhanced_service_dashboard.less b/ambari-web/app/styles/enhanced_service_dashboard.less index 1cb687a..71c99d7 100644 --- a/ambari-web/app/styles/enhanced_service_dashboard.less +++ b/ambari-web/app/styles/enhanced_service_dashboard.less @@ -322,6 +322,14 @@ } } } + .template.error { + .ember-text-area{ + border: 1px solid #b94a48; + -webkit-box-shadow: none; + -moz-box-shadow: none; + box-shadow: none; + } + } .badge-container { width: 80px; .OK, .WARNING, .CRITICAL { http://git-wip-us.apache.org/repos/asf/ambari/blob/99fe8097/ambari-web/app/templates/main/service/widgets/create/step2_template.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/service/widgets/create/step2_template.hbs b/ambari-web/app/templates/main/service/widgets/create/step2_template.hbs index 13ae142..6a8a469 100644 --- a/ambari-web/app/templates/main/service/widgets/create/step2_template.hbs +++ b/ambari-web/app/templates/main/service/widgets/create/step2_template.hbs @@ -22,9 +22,12 @@ {{t widget.create.wizard.step2.body.template}} </div> -<div class="template"> +<div {{bindAttr class=":template isTemplateInvalid:error"}}> <h5>{{t widget.create.wizard.step2.template.header}}</h5> {{view Ember.TextArea valueBinding="templateValue" placeholderBinding="view.templatePlaceholder"}} + {{#if isTemplateInvalid}} + <div>{{t widget.create.wizard.step2.body.template.invalid.msg}}</div> + {{/if}} </div> <div class="alert alert-info">
