Ejegg has uploaded a new change for review.

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

Change subject: Add route listing all available widget instances
......................................................................

Add route listing all available widget instances

And move the board listing to the standard REST endpoint

Bug: T86095
Change-Id: Idb996b27f7ede1ef84d9072ab4cefc766556135e
---
M persistence.js
M routes/user.js
M server.js
3 files changed, 44 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/dash 
refs/changes/97/185197/1

diff --git a/persistence.js b/persistence.js
index e1360ab..ef4cee9 100644
--- a/persistence.js
+++ b/persistence.js
@@ -119,6 +119,36 @@
                });
        },
        /**
+        * List all widget instances available to a user
+        * @param number userId local ID of user
+        * @returns Promise that resolves with a JSON representation of all
+        * widget instances owned by or shared with the user, or rejects with 
error
+        */
+       listWidgetInstances: function( userId ) {
+               var connection = getConnection(),
+                       select = 'SELECT id, widget_id, owner_id, display_name, 
description, is_shared, configuration FROM dash_widget_instance WHERE is_shared 
OR owner_id = ?';
+
+               return connection.query( select, [ userId ] ).then( function( 
dbResults ) {
+                       var rows = dbResults[0],
+                               count = rows.length,
+                               i,
+                               result = [];
+
+                       for ( i = 0; i < count; i++ ) {
+                               result[i] = {
+                                       id: rows[i].id,
+                                       widgetId: rows[i].widget_id,
+                                       ownerId: rows[i].owner_id,
+                                       displayName: rows[i].display_name,
+                                       description: rows[i].description,
+                                       isShared: rows[i].is_shared === 1,
+                                       configuration: JSON.parse( 
rows[i].configuration )
+                               };
+                       }
+                       return result;
+               });
+       },
+       /**
         * Saves a board
         * @param Object instance should have ownerId, displayName, description,
         * isShared, and widgets (an ordered array of widget instance ids) set.
diff --git a/routes/user.js b/routes/user.js
index ce41e3a..f39fdf5 100644
--- a/routes/user.js
+++ b/routes/user.js
@@ -26,5 +26,17 @@
                }, function( error ) {
                        res.json( { error: error } );
                });
+       },
+       widgetInstances: function( req, res ) {
+               if ( !req.session || !req.session.passport || 
!req.session.passport.user ) {
+                       res.json( { error: 'Error: Not logged in' } );
+                       return;
+               }
+
+               persistence.listWidgetInstances( 
req.session.passport.user.localId ).then( function( instances ) {
+                       res.json( instances );
+               }, function( error ) {
+                       res.json( { error: error } );
+               });
        }
 };
diff --git a/server.js b/server.js
index 0e14d41..565b3b2 100644
--- a/server.js
+++ b/server.js
@@ -73,11 +73,12 @@
 app.get( '/data/:widget', routes.data );
 app.get( '/metadata/:widget', routes.metadata );
 app.get( '/user/info', routes.user.info );
-app.get( '/user/boards', routes.user.boards );
 app.get( '/widget', routes.widget.list );
+app.get( '/widget-instance', routes.user.widgetInstances );
 app.post( '/widget-instance', routes.widget.saveInstance );
 app.put( '/widget-instance/:id', routes.widget.saveInstance );
 app.get( '/widget-instance/:id', routes.widget.getInstance );
+app.get( '/board', routes.user.boards );
 app.post( '/board', routes.board.save );
 app.put( '/board/:id', routes.board.save );
 app.get( '/board/:id', routes.board.get );

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

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

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

Reply via email to