From f092759f8a701f6837d7b12cfbf115eaf25c7c89 Mon Sep 17 00:00:00 2001 From: Ryan Watts Date: Thu, 5 Nov 2015 00:35:22 -0700 Subject: [PATCH] [v0.1.1] - Improvements for sending count data to the widget. --- README.md | 33 ++++++++++++++++++------------ orionjs_dashboard_api.js | 31 ++++++++++++++++++++++++++++ orionjs_dashboard_materialize.html | 2 +- package.js | 2 +- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 8331bfc..94ac787 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ This package is an extension of **Orion** and has a dependency on the `orionjs:b ```sh $ meteor add rwatts:orionjs-dashboard ``` -2. Register your widget by following **Example 1 Below** `Client` +2. Register your widget by following `Client` 3. Register access to the dashboard by setting `Options.set('showDashboard', true)` within your lib directory. If you have used the Example project from the Orion repository this will typically be in the *lib/options.js* file. -4. If using the default widget template follow the instructions in **Example 1 Below** +4. If using the default widget template follow the instructions below 5. Navigate to `/admin/dashboard/` to see your new widget. ## Register a custom Widget @@ -27,19 +27,26 @@ For the best experience, if utilizing the default widgets, you will need to use > A tutorial will be provided in the documentation demonstrating how to complete this task. -## Examples -### Example 1 +## Default Widget Guide + +### Publish Counts `Server` +```js +Meteor.publish('allProducts', function () { + Counts.publish(this, 'totalProducts', Products.find()); +}); +``` + +### Register Widget `Client` ```js -// Client -// Basic options passed to the default template orion.dashboard.registerWidget({ - template: 'default', // use default if you have not created a custom widget - count: Counts.get('somePublication'), // you must publish the counts from within the publication for them to be accessible from the widget. - baseColor: 'teal', // the base color of the widget - textColor: 'white', // sets the text color to white - label: 'Users', // sets the label of the widget - icon: 'books', // sets the icon for materialize use google's icon set for bootstrap use font awesome icons. - path: '/admin/users/' // sets the path the widget will navigate to upon clicking on it + template: 'default', + publication: 'allProducts', + count: 'totalProducts', + label: 'Products', + path: '/admin/products/', + baseColor: 'blue', + icon: 'shopping_cart', + textColor: 'white' }); ``` diff --git a/orionjs_dashboard_api.js b/orionjs_dashboard_api.js index 9086cdb..e875282 100644 --- a/orionjs_dashboard_api.js +++ b/orionjs_dashboard_api.js @@ -61,5 +61,36 @@ orion.dashboard.registerWidget = function (data){ ReactiveTemplates.helpers('orionDashboard', { widgets: function () { return orion.dashboard._widgets; + }, + count: function () { + return Counter.get(this); + } +}); + +/** + * @property ReactiveTemplates.onCreated('orionDashboardWidget') + * @where {client} + * @public + * @return {undefined} + * + * Subscribes to the publication passed to the widget. + */ +ReactiveTemplates.onCreated('orionDashboardWidget', function () { + var data = this.data + this.subscribe(data.publication); +}); + +ReactiveTemplates.helpers('orionDashboardWidget', { + /** + * @method getCount + * @public + * @param {String} count The count passed to through registerWidget + * @return {Number} Returns the total counts from the publication. + * + * Returns the total count of records based on the Counter + * passed through the registerWidget function. + */ + getCount: function (count) { + return Counts.get(count); } }); diff --git a/orionjs_dashboard_materialize.html b/orionjs_dashboard_materialize.html index e03a25f..68771a5 100644 --- a/orionjs_dashboard_materialize.html +++ b/orionjs_dashboard_materialize.html @@ -18,7 +18,7 @@
-

{{count}} Records

+

{{getCount count}} Records

{{icon}} diff --git a/package.js b/package.js index b1c9ae8..b9e2759 100644 --- a/package.js +++ b/package.js @@ -1,6 +1,6 @@ Package.describe({ name: 'rwatts:orionjs-dashboard', - version: '0.1.0', + version: '0.1.1', // Brief, one-line summary of the package. summary: 'Adds a Dashboard and Widgets to Orion.', // URL to the Git repository containing the source code for this package.