Ssmith has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/189840

Change subject: Save configuration for fraud gauge.
......................................................................

Save configuration for fraud gauge.

Change-Id: I11c1e0eecb74c5389f7fb672c04db3ac8936c054
WIP: this patch will cover saving for each widget.
---
M src/components/app-content/app-content.js
M src/components/boards/generic-board/generic-board.html
M src/components/widgets/fraud-gauge/fraud-gauge.html
M src/components/widgets/fraud-gauge/fraud-gauge.js
M src/components/widgets/totals-earned-chart/totals-earned-chart.html
M src/components/widgets/totals-earned-chart/totals-earned-chart.js
M src/css/style.css
7 files changed, 46 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/dash 
refs/changes/40/189840/1

diff --git a/src/components/app-content/app-content.js 
b/src/components/app-content/app-content.js
index 8147df4..3c93c64 100644
--- a/src/components/app-content/app-content.js
+++ b/src/components/app-content/app-content.js
@@ -17,6 +17,8 @@
         self.widgetTemplates = ko.observableArray();
         self.widgetInstances = ko.observableArray();
 
+
+
         //Get user info and configs like default board
         $.get('/user/info', function(userInfo) {
             if (userInfo) {
diff --git a/src/components/boards/generic-board/generic-board.html 
b/src/components/boards/generic-board/generic-board.html
index 9408094..6f3e711 100644
--- a/src/components/boards/generic-board/generic-board.html
+++ b/src/components/boards/generic-board/generic-board.html
@@ -20,7 +20,7 @@
     </span>
 
     <div class="row" data-bind="foreach: displayedBoard().widgets">
-        <div data-bind="component: { name: widgetCode, params: { title: 
displayName, description: description, configuration: configuration } }"><span 
data-bind="text: display_name"></span></div>
+        <div data-bind="component: { name: widgetCode, params: { title: 
displayName, description: description, configuration: configuration, 
widgetInstance: id } }"><span data-bind="text: display_name"></span></div>
     </div>
 
 </div>
\ No newline at end of file
diff --git a/src/components/widgets/fraud-gauge/fraud-gauge.html 
b/src/components/widgets/fraud-gauge/fraud-gauge.html
index ee4c49a..e3b9fed 100644
--- a/src/components/widgets/fraud-gauge/fraud-gauge.html
+++ b/src/components/widgets/fraud-gauge/fraud-gauge.html
@@ -1,4 +1,5 @@
 <div class="row">
+    <div data-bind="attr: {class: columnSize}">
     <div class="panel panel-purple" id="fraudGaugeWidget">
         <div class="panel-heading">
             <span data-bind='text: title'></span>
@@ -10,7 +11,7 @@
         <div class="panel-body">
 
             <div class="row">
-                <div class="col-md-12 gauge">
+                <div class="gauge">
 
                     <div class="row">
                         <h3 class="text-center" data-bind="visible: 
gaugeIsSetUp(), text: selectedTimePeriod"></h3>
@@ -126,6 +127,6 @@
             </div>
         </div>
 
-
+    </div>
     </div>
 </div>
diff --git a/src/components/widgets/fraud-gauge/fraud-gauge.js 
b/src/components/widgets/fraud-gauge/fraud-gauge.js
index c3b7824..6053409 100644
--- a/src/components/widgets/fraud-gauge/fraud-gauge.js
+++ b/src/components/widgets/fraud-gauge/fraud-gauge.js
@@ -34,6 +34,9 @@
     self.filters = ko.observableArray();
     self.title = ko.observable(params.title);
 
+    self.config = params.configuration;
+    self.columnSize = ko.observable('col-md-' + self.config.width + " 
fraudGauge");
+
     $.get( 'metadata/fraud-gauge', function(reqData){
       self.data = reqData;
       //broken down data from above
@@ -258,13 +261,11 @@
         var queryString = self.convertToQuery(self.queryRequest);
 
 
-        //Todo: if this is already set up in configs, take that data.
-        //otherwise do this.
-        $.get( '/data/fraud?' + $.param({ '$filter': queryString }).replace(
+        $.get( '/data/fraud-gauge?' + $.param({ '$filter': queryString 
}).replace(
           /\+/g, '%20' ), function ( dataget ) {
-          self.gaugeIsSetUp(true);
-          
self.gaugeValue(parseFloat(dataget.results[0].fraud_percent).toFixed(2) );
-          self.queryStringSQL(dataget.sqlQuery);
+          self.gaugeIsSetUp( true );
+          self.gaugeValue( 
parseFloat(dataget.results[0].fraud_percent).toFixed(2) );
+          self.queryStringSQL( dataget.sqlQuery );
 
           self.gauge = c3.generate({
               bindto: '#FraudRiskScoreGauge',
@@ -293,7 +294,28 @@
                   }
               }
           });
+
+          //Save these settings to this instance
+          $.ajax({
+                method: 'PUT',
+                url: '/widget-instance/' + params.widgetInstance,
+                contentType: 'application/json; charset=UTF-8',
+                data: {
+                    configuration: {
+                        width: self.columnSize(),
+                        gaugeValue: self.gaugeValue(),
+                        queryStringSQL: self.queryStringSQL(),
+                        gauge: self.gauge
+                    },
+                    isShared: false
+                },
+                success: function(stuff) {
+                    alert( JSON.stringify( stuff ) );
+                }
+            });
         });
+
+
       }
 
     };
diff --git 
a/src/components/widgets/totals-earned-chart/totals-earned-chart.html 
b/src/components/widgets/totals-earned-chart/totals-earned-chart.html
index 3ea4b2b..cb8943a 100644
--- a/src/components/widgets/totals-earned-chart/totals-earned-chart.html
+++ b/src/components/widgets/totals-earned-chart/totals-earned-chart.html
@@ -1,4 +1,5 @@
 <div class="row">
+    <div data-bind="attr: {class: columnSize}">
     <div class="panel panel-transparent">
         <div class="panel-body">
             <!--Main updates: Goal, Total so far, Remaining to raise-->
@@ -45,6 +46,7 @@
             </div>
         </div>
     </div>
+    </div>
 </div>
 
 <div class="row">
diff --git a/src/components/widgets/totals-earned-chart/totals-earned-chart.js 
b/src/components/widgets/totals-earned-chart/totals-earned-chart.js
index bd48cf8..f5da75a 100644
--- a/src/components/widgets/totals-earned-chart/totals-earned-chart.js
+++ b/src/components/widgets/totals-earned-chart/totals-earned-chart.js
@@ -13,10 +13,9 @@
                timeFormat = 'dddd, MMMM Do YYYY, h:mm:ss a';
 
            self.title = ko.observable(params.title);
-
-               //self.title = ko.observable(params.title);
-               self.widgetWidth = ko.observable(params.configuration.width);
                self.dataLoading = ko.observable(true);
+           self.config = params.configuration;
+           self.columnSize = ko.observable('col-md-' + self.config.width + " 
totalsEarnedChart");
 
                //initialize day/hour data
         self.dayObj = [];
diff --git a/src/css/style.css b/src/css/style.css
index f11f16f..2032311 100644
--- a/src/css/style.css
+++ b/src/css/style.css
@@ -277,6 +277,10 @@
 
 /* Gauges */
 
+.fraudGauge {
+    padding: 0;
+}
+
 #fraudGaugeWidget .panel-body {
     padding: 0;
 }
@@ -333,6 +337,10 @@
     margin-left: -35px;
 }
 
+.totalsEarnedChart {
+    padding: 0;
+}
+
 #customTimePicker {
     width: 100px;
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/189840
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I11c1e0eecb74c5389f7fb672c04db3ac8936c054
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/dash
Gerrit-Branch: master
Gerrit-Owner: Ssmith <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to