1

My application requires a dashboard with a TODAY section that display different tasks created/defined by/for the user for that day. Each task belongs to a different type (from now on referred to as a module) and each module (along with its' tasks for that day) are grouped in widgets in the TODAY section. Also, there may not be any tasks of whatever module for a given day, so the widget for that particular module shouldn't be rendered.

Something like:


Hello username!
Here are your tasks for today:

Module 1

  • Task 1
  • Task 2

Module 3

  • Task 1

(notice that since there are no tasks for Module 2, it shouldn't be rendered in the dashboard)

I have a couple questions on how to implement this functionality:

  1. Who should know which tasks to show? Should the controller ask the user service what are the tasks for the current user?
  2. Each module widget will have its own controller that will take care handling user interaction with the model. How do I include the widgets along with their controllers in the condition that there are tasks to show for that particular module? Is this a valid approach?

    <div dashboard-widget
        ng-repeat="module in modules"
        ng-include="module.template"
        ng-controller="module.controller"
        widget-title="module.name"></div>
    
  3. Each module will also have a view/controller where the user will create tasks ot that particular module. Should the widgets for each module be a concern of the dashboard or of the modules themselves? i.e. Should the dashboard be the one who knows how it will display the data for each module?

Thiatt
  • 564
  • 1
  • 6
  • 21
  • This question is way to big and broad and application specific, so it's hard to give you a good answer. What you should really be doing is creating directives for each of the widgets. IMO, the controller would decide what to display based on info from the user service, the widgets would be directives that have their own controller, and the widgets will know how to handle what the user does with it, which shouldn't matter to the dashboard unless it impacts other widgets. – EmptyArsenal Jul 14 '15 at 23:13
  • What would be a good way to implement this so that adding more modules would require minimal/no change to the dashboard? Or is the best way to keep adding `ng-ifs` for each of the modules on the controller template? – Thiatt Jul 14 '15 at 23:21
  • The best thing to do would be to have a smart layout that could handle the addition or removal of widgets. You can either have a bunch of `ng-if`s in your dashboard, or append the widgets via the controller as you add them. Here's a solid SO post that sounds similar to what you're looking for: http://stackoverflow.com/questions/16806901/developing-an-angularjs-app-with-dynamic-set-of-modules – EmptyArsenal Jul 15 '15 at 00:04

0 Answers0