I've been struggling with the right way to design a Rails model/controller for a dashboard/portal that can support easy/clean widget development. I've already (as a diversion) wrote a jQuery/jQuery-UI/CSS basic view that has worked out the column/order HTML and controls to reorder/minimize/remove the widgets, and now I'm coming back to how best to design the model and controller.
As a central place to find all widget information, I have a Widget model. (as a non-ActiveRecord for now) Ideally I'd like to have the Widget Index view simply take the Widgets from the Controller, and the model would contain widget attributes needed to render the view. This would include widget "partial" and "controller" attributes that the view could use to render a specific widget's partial view in my Dashboard view.
I don't want to have to overload my Widget controller with a bunch of potential widget specific data that their partial view might use. Instead I want to have the partial render itself, by just specifying the widget's partial and controller to use. Then the partial view and controller can do whatever they need to for that widget.
Widget Controller Index --> render #widgets --> widget1 widdget1_controller/partial view1
\ \-> widget2 widdget2_controller/partial view2
\--> widget3 widdget3_controller/partial view3
The Dashboard model would contain column, order, partial view, controller.
The Widget specific partial Views and Controllers would would located under a sub-folder of the controllers and views/widget folders to keep things clean.
I'm hoping this will help when trying to add AJAX support. Each widget controller can handle their own Controller Actions (like editing the widget or saving something) and I can have the client browser make AJAX calls to the partial for updated information without having to call the original Widget Controller, etc...
What do you guys think? Do you have a better suggestion?
This might be to late now, but there is an extension on cells called Apotomo, which basically extends cells with actions and ajax to make little widgets. It's pretty awesome, and they have tutorials on doing the whole widget thing you're talking about. If this is to late, I would guess it would be pretty easy to port your cells code over to the widgets as they're very similar.
I think Cells is what you looking for.
Related
I have a simple project that was started from a Master/Detail template for iOS7.
I'd like to layout the detail view controller just like iOS settings. Do folks recommend using a table for that or just laying out the controls one by one?
Here is a screenshot of the effect I am looking for:
This is probably a matter of taste/opinion but I prefer tables for this kind of thing for these reasons:
You get all the nice features of tables right out of the box (efficient scrolling, cell reuse and delegate methods to handle where to push new view controllers on to the stack, etc...).
Flexible data model backed cell data. Your table view needs to be backed by some "settings" model object collection, obviously. That collection can be modified to include or exclude settings programmatically. Combine this with custom cells and you're off and rolling. This is really nice if your UI needs to change on the fly.
Code Reuse. If you have another set of "settings" you can use this data-backed table view approach and change only your data model. Doing this manually means you have a new view controller for every settings view. In your example picture, I'd bet my lunch that the 3 view controllers you see in that image are the same type of object.
The table's delegate methods are really helpful when segueing or pushing to new view controllers. Imagine having 10 settings that all took you to separate view controllers. You'd have to manually hook those transitions one by one, yuck.
Of course if you only have 1-2 settings that will never change, perhaps manual is the way to go. For my money, though, tables make sense because things like this always seem to change.
I have 3 html anchor tags.
depending on what link is clicked, i want to render the same view, but pointing to a different controller action.
How would i render the partial view and point the view to a different action on the same controller.
Use RenderAction().
#Html.RenderAction("Details", "User", new {id = Model.Id})
Some help about how to render partial views.
This post on StackOverflow explains the difference between Html.Action and Html.RenderAction, that may interest you.
UPDATE:
For doing this in JavaScript I redirect you to this question: How to call Html.RenderAction() with parameters declarated in jscript?
I'm new to yii development.
In my system I'm trying to create a submenu system. The submenu will be shown based on the
controller. The submenu will be separate views, that I'll load in main layout.
I want to separate the logic of loading the submenu view from the main layout. But, I'm not sure where to write it.
Does Yii has view helpers like in RoR. Or, should I write it as a component?
Please give suggestions.
Thanks.
I'd just create a component for this, and instantiate that with the relevant menu options from the controllers. If present in all controllers, implement support in a BaseController and just set up an array of items in the child controllers.
Your default generated Yii application has a parent Controller in protected/components/Controller.php. If you need to access additional parameters in layout, add public properties to Controller, set them in your child controller, and use them in your view/layout files.
In your case, add a function to this parent Controller that returns a rendered submenu (with a renderPartial call for example) and call this function from your layout.
I'm looking for an example of a Sencha Touch 2 MVC application that has more than one model, view, controller. I want to see what is the recommended way of witching to a different subject in the application.
For example: Suppose I have an application to manage calls and messages. I will have some welcome screen with a welcome controller and no model, a recent calls model, view, controller, and a messages model, view, controller. My problem is with putting and removing everything I need in the main view port, without allocating elements that are not displayed.
All the examples I found use one controller to rule them all, and a viewport with cards. I was hoping for a better technique. Also from what I saw when I start the application they specify all the models and controllers of the application, but I did not see how it can be used or why it is a good design. I thought that we want to reduce allocations on the phone.
Any pointers to examples or guidelines for how to use several controllers will be greatly appreciated.
I guess you need to go for routing and destroying items then.
VIEW: Welcome -> okBtn press
CONTROLLER: Welcome -> onOkBtnPress -> call route START
Welcome -> deactivate -> destroy Welcome VIEW
START VIEW: view items
START CONTROLLER: route index -> Add new view to Viewport.
Without routing you need to add the new view in the Welcome view, which usually is not preferable.
So you basically call a route onBtnTap and destroy the old view onDeactiveView.
I am creating split view based application for iPad.
I have 1) a root view controller 2) a detail view controller
It is like menu and submenu.
Here I am planning to do. I would like to have navigation in root view controller.
It is recomonded to use or not. If it is recomended how is it possible.
There is a function in the Detail View Controller for showing or not showing the popover Button. Possibly you could adapt that in the App Delegate for the whole Detail View Controller? Just go through the source code provided by Apple. It is all well commented.
Not sure what you're asking. If you're asking whether it's recommended to do it like how you describe, then yes, that's the most recommended way to do it.
Root view controller (the smaller left side menu) usually contains the navigation stuff, while the detail view controller (the bigger right side view) contains all the detailed stuff.
You might want to take a look here for a How-To.
Other documents can be found here.