Ssmith has uploaded a new change for review.

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

Change subject: Fetch/use user default board for lib widget adds
......................................................................

Fetch/use user default board for lib widget adds

Change-Id: Id4242ee05d6edaa73cfe0d9f3cbea0c2f0797ef5
---
M src/components/app-content/app-content.js
1 file changed, 46 insertions(+), 36 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/dash 
refs/changes/64/196664/1

diff --git a/src/components/app-content/app-content.js 
b/src/components/app-content/app-content.js
index a6e51c1..7b950cb 100644
--- a/src/components/app-content/app-content.js
+++ b/src/components/app-content/app-content.js
@@ -2,37 +2,34 @@
     [   'jquery',
         'knockout',
         'text!./app-content.html'
-    ], function( $, ko, templateMarkup) {
+    ], function( $, ko, templateMarkup ) {
 
-    function AppContent(params) {
+    function AppContent( params ) {
         var self = this;
 
-        self.url = params.url || 'hi';
-        self.displayedBoard = ko.observable();
-        self.userBoards = ko.observableArray();
-        self.userdata = ko.observableArray();
-        self.displayPage = ko.observable('Home');
-        self.loggedIn = ko.observable(false);
-        self.welcome = ko.observable('');
-        self.widgetTemplates = ko.observableArray();
-        self.widgetInstances = ko.observableArray();
+        self.url                = params.url || 'hi';
+        self.displayedBoard     = ko.observable();
+        self.userBoards         = ko.observableArray();
+        self.userdata           = ko.observableArray();
+        self.displayPage        = ko.observable('Home');
+        self.loggedIn           = ko.observable(false);
+        self.welcome            = ko.observable('');
+        self.widgetTemplates    = ko.observableArray();
+        self.widgetInstances    = ko.observableArray();
 
-
-
-        //Get user info and configs like default board
-        $.get('/user/info', function(userInfo) {
-            if (userInfo) {
+        $.get( '/user/info', function( userInfo ) {
+            if ( userInfo ) {
                 self.userdata( userInfo );
                 self.welcome( userInfo.name.charAt(0).toUpperCase() + 
userInfo.name.slice(1) );
                 self.loggedIn( true );
 
-                $.get('board/' + self.userdata().defaultBoard, function( 
moredata ){
+                $.get( 'board/' + self.userdata().defaultBoard, function( 
moredata ){
                     self.displayedBoard( moredata );
                 });
 
-                $.get('board/', function (boards){
-                    $.each(boards, function(i, board){
-                        if(board.ownerId === self.userdata().id){
+                $.get( 'board/', function ( boards ){
+                    $.each( boards, function( i, board ){
+                        if( board.ownerId === self.userdata().id ){
                             self.userBoards.push(board);
                         }
                     });
@@ -42,10 +39,7 @@
 
         self.addWidgetToBoard = function( event, data ){
             var widgetIDToAdd;
-            console.log('event: ', event);
-            console.log('data', data.target.id);
 
-            //create an instance of the widget
             $.ajax({
                 method: 'POST',
                 url: '/widget-instance',
@@ -57,18 +51,35 @@
                     isShared: false
                 }),
                 success: function( data ) {
-                    widgetIDToAdd = data.id;
-                    self.displayedBoard().widgets.push(data.id);
+                    widgetIDToAdd = data.id; var gettingBoard, 
defaultBoardConfig;
+
+                    if( self.userdata().defaultBoard !== 
parseInt(self.displayedBoard().id) ){
+                        var gettingBoard = $.ajax({
+                                url: '/board/' + self.userdata().defaultBoard,
+                                success: function( stuff ) {
+                                    defaultBoardConfig = stuff;
+                                }
+                            });
+                    } else {
+                        defaultBoardConfig = self.displayedBoard();
+                    };
+
+                    if( gettingBoard ){
+                        $.when( gettingBoard ).then( function( returnedData ){
+                            defaultBoardConfig = returnedData;
+                            defaultBoardConfig.widgets.push(data.id);
+                        });
+                    };
 
                     $.ajax({
                         method: 'PUT',
                         url: '/board/' + self.userdata().defaultBoard,
                         contentType: 'application/json; charset=UTF-8',
-                        data: JSON.stringify(self.displayedBoard()),
-                        success: function(stuff) {
+                        data: JSON.stringify( defaultBoardConfig ),
+                        success: function( stuff ) {
                             //change the look of the add widget button
-                            $('#add-widget-'+event.id).hide();
-                            $('#saved-widget-'+event.id).removeClass('hide');
+                            $( '#add-widget-' + event.id ).hide();
+                            $( '#saved-widget-' + event.id ).removeClass( 
'hide' );
                         }
                     });
                 }
@@ -76,16 +87,15 @@
 
         };
 
-        self.setDisplayPage = function(e, data){
-            var pages = ['Library', 'Profile', 'Home'], view = data.target.id;
+        self.setDisplayPage = function( e, data ){
+            var pages = [ 'Library', 'Profile', 'Home' ], view = 
data.target.id;
+
             if( pages.indexOf(data.target.id) > -1 ){
                 self.displayPage(view);
             } else if( isNaN( parseInt( view, 10 ) ) ) {
                 self.displayPage($.trim($(data.target).text()));
             } else {
-                $.get('board/' + view, function( bdata ){
-                    console.log('get board #', data.target.id);
-                    console.log('bdata: ', bdata);
+                $.get( 'board/' + view, function( bdata ){
                     self.displayedBoard( bdata );
                 });
             }
@@ -93,7 +103,7 @@
         };
 
         self.getWidgetTemplates = function(){
-            $.get('/widget', function(widgetTemplates){
+            $.get( '/widget', function( widgetTemplates ){
 
                 var wt = $.map(widgetTemplates, function(n){
                     return n;
@@ -105,7 +115,7 @@
         self.getWidgetTemplates();
 
         self.getUsersWidgetInstances = function(){
-            $.get('/widget-instance', function(widgetInstances){
+            $.get('/widget-instance', function( widgetInstances ){
 
                 var wi = $.map(widgetInstances, function(n){
                     return n;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id4242ee05d6edaa73cfe0d9f3cbea0c2f0797ef5
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/dash
Gerrit-Branch: master
Gerrit-Owner: Ssmith <ssm...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to