4

I'm developing an application using ember.js and a rest API written with spring MVC. I have to create a dashboard with several widget on it. Every widget as its own behavior and will call different API method. I was thinking to have one controller subclass for each kind of widget. Then will instantiate them and will add ther views to a Container view. However ember will create a instance for each controller automatically, so is it a good path to follow? Any suggestion fom the ember.js community?

Thank you for the help.

Filippo De Luca
  • 704
  • 5
  • 21
  • 4
    perhaps you could have a look at http://code418.com/ember.js-dashboard/, written by @pangratz. The source code should be here: https://github.com/pangratz/dashboard – sly7_7 Oct 14 '12 at 10:51
  • I have seen that, It contains a lot of interesting stuff but not the solution to my problem. – Filippo De Luca Oct 16 '12 at 13:36
  • Ok, I mistakenly thought that it could fit to your needs :(, as there are many widgets in his project. But it seems this not the same widgets as you are looking for. – sly7_7 Oct 16 '12 at 13:42

2 Answers2

5

Your ideas sound pretty good.

There are certainly many ways to structure this. I would perhaps suggest making a DashboardView and DashboardController, and in its template, have several outlets, one for each widget "slot":

{{outlet topWidgetView}}
{{outlet leftWidgetView}}
...

Then in the router, in the dashboard route's connectOutlets method, connect the widgets after you've instantiated the dashboard:

router.get('applicationController').connectOutlet('dashboard');

router.get('dashboardController').connectOutlet({
  outletName: 'topWidgetView',
  name: 'fooWidget'
});
router.get('dashboardController').connectOutlet({
  outletName: 'leftWidgetView',
  name: 'barWidget'
});
Jo Liss
  • 30,333
  • 19
  • 121
  • 170
  • 1
    I wonder if I would use outlets here, since the page seems to be static, and widgets don't switch. But this solution has the advantage of beeing flexible – sly7_7 Oct 16 '12 at 07:18
  • It is not the case, because each area can have multiple Widgets. Basically each widget have x and y coordinate: x specifies the Area and y the order in that Area. – Filippo De Luca Oct 16 '12 at 16:10
4

Rather than a slot for each widget, I would rather have a slot by widget area (column, ...), which would be a ContainerView, into which one I would dynamically add widgets views, according to user's settings.

Mike Aski
  • 9,180
  • 4
  • 46
  • 63
  • You're welcome :-) Glad I could help. Do you need more information? If not, you can consider accepting the answer. – Mike Aski Oct 16 '12 at 15:01
  • Yes, using the Route any Controller will be instantiated by the Ember, there is any way to avoid that. I would like to have one type of Controller for each Type of Widget. So If I have two Widget with the Same type, I will have two instances of that Controller type. – Filippo De Luca Oct 17 '12 at 00:06
  • 1
    I think you should try to avoid coupling "dynamic" widgets instances to "static" implementation code. The best would be to have all the (specific/parametric) state of your widget hold into a model, and the (generic) behavior hold by the controller. So you may have a single stateless controller instance animating several widgets. – Mike Aski Oct 17 '12 at 04:25