This project is read-only.

Services and actions which render custom views

Jun 22, 2013 at 4:24 PM
Edited Jun 22, 2013 at 4:25 PM
Hi,
I'll try to describe my issue by example:

My app manages 'customers'. Each customer has multiple 'contents' associated with it.
I would like to display graphical statistics regarding all customers (a summary of all contents in the system), a single customer (all it's contents) or a single customer's content.

Intuitively, I would like to include a "statistics" item in the customer repository's menu for the first level. For a customer's statistics, I'd expect a "statistics" action in the single customer view (i.e. an action in the Customer class), and similarly I would have a "statistics" action in the single content view (an action in the Content class).

I read section 3.4 in the documentation ("Customising the MVC User Interface"), but still didn't figure out how to accomplish either of the repository/entity-level functionality while preserving the tight NO UI (for now I'm "manually" adding links to the views).

Any idea?

Thanks,
Ury

edit: I just realized I didn't make it clear: I don't want to mix the custom statistics views with the existing "view" or "edit" views. They need to be shown in a separate view.
Jun 22, 2013 at 4:34 PM
I don't understand where the need for 'customisation' arises, Ury ...

You have an action called Statistics() on the Customer object - so that will just show up on the Actions menu for that customer. Similarly for Content. Each can return a new content type called e.g. CustomerStatistics or ContentStatistics respectively. If you don't want those to be persisted objects, use the (recently added) ViewModel capability.
Jun 22, 2013 at 10:12 PM
Hi Richard,

I did add the Statistics() action, but I wasn't sure what's next. In order to invoke the controller/view which will eventually display a graph or render a report, should I return a new [NotPesisted] entity, and implement a custom controller for it?
It's not that I really need to 'customize' things. I'm just not sure how to link between the action and the view which will eventually display the statistics.

I hope it's clearer now,
Ury
Jun 22, 2013 at 10:26 PM
So, basically, you want to bounce out of the generic NOF views into a standard, custom MVC view?
Jun 23, 2013 at 8:21 AM
I don't really know if that's the best or only solution, but essentially yes - I want to navigate from the generic Customer viewing/editing view (for example) to a view with filters, graphs etc.
Jun 23, 2013 at 9:17 AM
This sounds like a good candidate for contributed actions... the contributed action service would act on the generic Customer to return custom views. Use the new view model stuff so that you can put actions onto those custom views.
Jun 24, 2013 at 7:29 AM
Thanks.
Can you please provide a short code sample regarding how to "act on the generic Customer to return custom views"?
Jun 24, 2013 at 1:20 PM
given an entity:

public class Customer { ... }

and a view model:

public class CustomerGraphViewModel : ViewModel<Customer> {
public List<Foo> UsefulInfo { get {
    return FooRepository.FindForCustomer(this.Root);
}
}

(where this view model would have an associated custom view: Views/CustomerGraphViewModel/ObjectView.aspx

then:

// register as a contributed action service
public class CustomerGraphContributedActions {
public CustomerGraphViewModel GraphFor(Customer customer) {
    var cg = Container.newViewModel<CustomerGraphViewModel>();
    cg.Root = customer;
    return customer;
}
}
Jun 25, 2013 at 9:49 AM
Great!
With a couple of modifications to the above code (and some routing), it works :)