You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by at...@apache.org on 2015/04/20 15:06:53 UTC
ambari git commit: AMBARI-10595 Implement ability to clone a widget.
(atkach)
Repository: ambari
Updated Branches:
refs/heads/trunk 6f33889d9 -> 5cf68111d
AMBARI-10595 Implement ability to clone a widget. (atkach)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/5cf68111
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/5cf68111
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/5cf68111
Branch: refs/heads/trunk
Commit: 5cf68111db1a8bc322c3775cfd44f5e006059bee
Parents: 6f33889
Author: Andrii Tkach <at...@hortonworks.com>
Authored: Mon Apr 20 15:45:26 2015 +0300
Committer: Andrii Tkach <at...@hortonworks.com>
Committed: Mon Apr 20 16:06:44 2015 +0300
----------------------------------------------------------------------
ambari-web/app/messages.js | 3 ++
ambari-web/app/mixins/common/widget_mixin.js | 56 ++++++++++++++++++++
.../test/mixins/common/widget_mixin_test.js | 43 ++++++++++++++-
3 files changed, 101 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/5cf68111/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index 28238ed..7149062 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -263,6 +263,7 @@ Em.I18n.translations = {
'common.label': 'Label',
'common.preview': 'Preview',
'common.scope': 'Scope',
+ 'common.clone': 'Clone',
'models.alert_instance.tiggered.verbose': "Occured on {0} <br> Checked on {1}",
'models.alert_definition.triggered.verbose': "Occured on {0}",
@@ -2514,6 +2515,8 @@ Em.I18n.translations = {
'widget.create.wizard.step3.widgetName': 'Widget Name',
'widget.create.wizard.step3.header': 'Name and Description',
+ 'widget.clone.body': 'Are you sure you want to clone current widget {0}?',
+
'dashboard.widgets.wizard.step2.addMetrics': 'Add Metrics and operators here...',
'dashboard.widgets.wizard.step2.newMetric': '+ New Metric',
'dashboard.widgets.wizard.step2.newOperator': '+ New Operator',
http://git-wip-us.apache.org/repos/asf/ambari/blob/5cf68111/ambari-web/app/mixins/common/widget_mixin.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/widget_mixin.js b/ambari-web/app/mixins/common/widget_mixin.js
index 33d81fc..63688b2 100644
--- a/ambari-web/app/mixins/common/widget_mixin.js
+++ b/ambari-web/app/mixins/common/widget_mixin.js
@@ -325,10 +325,66 @@ App.WidgetMixin = Ember.Mixin.create({
}
);
},
+
/*
* make call when clicking on "clone icon" on widget
*/
cloneWidget: function (event) {
+ var self = this;
+ return App.showConfirmationPopup(
+ function() {
+ self.postWidgetDefinition();
+ },
+ Em.I18n.t('widget.clone.body').format(self.get('content.displayName')),
+ null,
+ null,
+ Em.I18n.t('common.clone')
+ );
+ },
+
+ /**
+ * collect all needed data to create new widget
+ * @returns {{WidgetInfo: {widget_name: *, display_name: *, widget_type: *, description: *, scope: *, metrics: *, values: *, properties: *}}}
+ */
+ collectWidgetData: function () {
+ return {
+ WidgetInfo: {
+ widget_name: this.get('content.widgetName'),
+ display_name: this.get('content.displayName'),
+ widget_type: this.get('content.widgetType'),
+ description: this.get('content.widgetDescription'),
+ scope: this.get('content.scope'),
+ "metrics": this.get('content.metrics').map(function (metric) {
+ return {
+ "name": metric.name,
+ "service_name": metric.serviceName,
+ "component_name": metric.componentName,
+ "metric_path": metric.metric_path,
+ "category": metric.category
+ }
+ }),
+ values: this.get('content.values'),
+ properties: this.get('content.properties')
+ }
+ };
+ },
+
+ /**
+ * post widget definition to server
+ * @returns {$.ajax}
+ */
+ postWidgetDefinition: function () {
+ return App.ajax.send({
+ name: 'widgets.wizard.add',
+ sender: this,
+ data: {
+ data: this.collectWidgetData()
+ },
+ success: 'postWidgetDefinitionSuccessCallback'
+ });
+ },
+
+ postWidgetDefinitionSuccessCallback: function() {
},
http://git-wip-us.apache.org/repos/asf/ambari/blob/5cf68111/ambari-web/test/mixins/common/widget_mixin_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mixins/common/widget_mixin_test.js b/ambari-web/test/mixins/common/widget_mixin_test.js
index f29eb66..88a3770 100644
--- a/ambari-web/test/mixins/common/widget_mixin_test.js
+++ b/ambari-web/test/mixins/common/widget_mixin_test.js
@@ -311,5 +311,46 @@ describe('App.WidgetMixin', function() {
});
});
-});
+ describe("#cloneWidget()", function() {
+ var mixinObject = mixinClass.create();
+ before(function () {
+ sinon.spy(App, 'showConfirmationPopup');
+ sinon.stub(mixinObject, 'postWidgetDefinition', Em.K);
+ });
+ after(function () {
+ App.showConfirmationPopup.restore();
+ mixinObject.postWidgetDefinition.restore();
+ });
+ it("", function() {
+ var popup = mixinObject.cloneWidget();
+ expect(App.showConfirmationPopup.calledOnce).to.be.true;
+ popup.onPrimary();
+ expect(mixinObject.postWidgetDefinition.calledOnce).to.be.true;
+ });
+ });
+
+ describe("#postWidgetDefinition()", function() {
+ var mixinObject = mixinClass.create();
+
+ before(function () {
+ sinon.spy(App.ajax, 'send');
+ sinon.stub(mixinObject, 'collectWidgetData').returns({});
+ });
+ after(function () {
+ App.ajax.send.restore();
+ mixinObject.collectWidgetData.restore();
+ });
+ it("", function() {
+ mixinObject.postWidgetDefinition();
+ expect(App.ajax.send.getCall(0).args[0]).to.eql({
+ name: 'widgets.wizard.add',
+ sender: mixinObject,
+ data: {
+ data: {}
+ },
+ success: 'postWidgetDefinitionSuccessCallback'
+ });
+ });
+ });
+});