UNPKG

lpio

Version:

The last dashboard app you'll ever need

55 lines (45 loc) 1.77 kB
<link rel="import" href="../../../bower_components/polymer/polymer.html"> <link rel="import" href="../../lp-imports/jquery.html"> <script> window.ReduxBehaviors = window.ReduxBehaviors || {}; /** * * @polymerBehavior ReduxBehaviors.Widget * **/ ReduxBehaviors.WidgetImpl = { created: function(){ this._addReducer(this.widgetReducer); }, widgetReducer: function(action){ if(action.key == 'widgets'){ switch (action.type){ case 'setByDashboardId': return this.setByDashboardId(action); } } }, setByDashboardId: function(action){ if(!_.has(action,'widgets') || !_.has(action.widgets,'widgets') || !_.isArray(action.widgets.widgets || !_.has(action,'dashboardId') )){ console.error("setByDashboardId: bad payload"); return; } var state = this.state; var widgets = _.union(state.widgets||[],action.widgets.widgets); var widgetIds = []; action.widgets.widgets.forEach(function(widget){ widgetIds.push(widget._id); }); widgets = _.uniq(widgets,function(item){ return item._id; }); var widgetsByDashboardId = _.extend({},state.widgetsByDashboardId); widgetsByDashboardId[action.dashboardId] = widgetIds; this.mutate('widgets.widgets',widgets); this.mutate('widgets.widgetsByDashboardId',widgetsByDashboardId); this.mutate('widgets.isLoading',false); } }; ReduxBehaviors.Widget = [ReduxBehaviors.WidgetImpl]; </script>