How do I create a new server side view with Treeline? - sails.js

I'm building my first app with Treeline, and I'd like to create a new server side view. Using Sails, I'd normally add the route and associated view to config/routes.js, but when I link my Treeline project config/routes.js is overwritten by the routes defined in Treeline.
Any ideas? Thanks!

To serve a view in Treeline, you should change the response type- this will result in a separate response being used in the compiled code:
First click "respond", then "display view". After that, enter the name of the view and provide any locals you need access to (this is equivalent to res.view in Sails, or res.render in Express)

Related

Why this.setModel() behaves differently based on context

I have followed the tutorials and now I am trying to extend that learning into a real app. In my app I use a JSON model. Unlike the tutorials, mine is a real-world app and I have to get user credentials to act as a filter when I load the data model. In the tutorials the model is loaded in component.js. In my app I have to prompt the user for id and password so I have a login fragment that appears modally over the first view in the app. This happens to be a master view, and critically it runs after component.js. After validating the user I collect JSON data from the server via Ajax and place it into the default model via this.setData(my_json).
When testing the routing from master to detail view I produced a stubborn bug in that this.getModel() called in the detail view produced an empty model. Huh - I just set the model in the master view and can see the data in the table control - what gives?
I considered a routing issue but confirmed that was not the problem - I can console log the parameters that pass through the router and anyway the detail view appears so routing is ok.
Recap: I use this.setModel() in the master page then this.getModel() in the detail page but the latter is an empty model.
Question: I want the model to be available across the app. The tutorials focus on setting model in component.js but I cannot. What is the correct syntax for setting the global model from the master view for example, or any other place that is not the component.js.
I think I need to use the following in the master (last line is significant):
var oModel = new JSONModel(); // declare a JSON model
oModel.setData(<json string>); // load a JSON string fetched from serve etc.
sap.ui.getCore().setModel(oModel); // important - set as the core model
I think the source of my confusion is that in the tutorials it seems that models are set in the component via
this.setModel(oModel); // a line in component.js
I therefore assume that this in component.js context is app-global whilst this in a view relates to the view along, which makes sense. Am I right?
In the tutorials this.setModel(...) inside the Component.js will set the model on the Component directly. Therefore, the model is visible in all views inside that Component.
When you see this.getView().setModel(...) inside a controller you know that the model is only set on that one view (and therefore it's also visible for it's children).
However, if you see something like this.setModel(...) inside a controller you should check what happens inside this.setModel(...). It is possible that the model is set on the view, or on the Component, or even somewhere else! Some of the tutorials make use of the so called "BaseController" concept. This is basically a parent controller of other controllers and therefore this approach allows to code some handy APIs that you can easily reuse in the child controllers that extend from this BaseController. For example, have a look at the BaseController of the Worklist App. There you can see that the setModel(...) API is setting the model on the view. That means whenever you call this.setModel(...) in your controllers which extend from that BaseController your model is set on the view!
Furthermore, because in a Master-Detail app there is no hierarchy between Master and Details page (parent/child relation) your models on the Master view are not visible on the Detail view.
In your case it seems to be best setting the model on the Component directly. You can do this by calling
this.getOwnerComponent().setModel(...);
inside any of your controllers. Or just do it directly on the Component.js like in the Wordlist tutorial. You can propagate the data to that model later, i.e. at anytime later from within your controllers.

Function across multiple view controllers

I am trying to make a function so that I request a 'manager override' where it presents a screen for a manager to enter their password and press an approve button. How should I do this? Will it have to be in multiple functions? Is there a way that I can call one function and it present the information back? Would a completion work for what I need? I have no ideas where to start for this.
My set up is as follows:
A view controller asks for manager approval, then a screen slides up with text boxes and an approve button. I want the approve button to trigger authenticating and dismissing the screen
Assuming you don't want a Framework target (that sounds like overkill for what you want) simply mark the function as "public" and move it outside of any class. I just tried in a sample project and it works.
It looks important - remember to keep it in a file already in the project. (My sample project didn't work with menu option File|Add|New|File.)
Now, if you really want portability, check out how to create a Framework project.

In SailsJS, how do I check in a view partial that a route is active

I have a set of links in a partial that i'd want to change visually depending if the route they go to is active.
Is there a way to check if a route is active from the view?
If I understand correctly, it sounds like you're just looking to see which URL was requested?
The req object, which holds information about the current request, is available as a local variable in all views. So inside your view you can check req.url to determine which URL the user requested. If the view was rendered via a controller using res.view (rather than being rendered directly as a result of a view route), you can also check which controller/action was run by looking at req.options.controller and req.options.action. See the docs on req.options for more info.

Interface Builder shows old Received Actions

When I open my xib file in Interface Builder and click on File's Owner in the Document window, the Connections Inspector is showing far more actions below Received Actions than I have defined in the class as specified by the File's Owner Class Identity.
I have only two IBAction items defined in the class, and both of these actions are shown and hooked up to the appropriate buttons. I am not sure where these other ones are defined, as when I search the project for the text of the action shown, it is not found anywhere in my project. (I believe that the actions shown are from a previous software application that I did on this same computer.)
I cannot find any way to get rid of these, and while the application still works as it should, I would like to try to find a way to get these actions out of there.
I am using the most recently released iOS SDK 4.1.
You may need to just edit the xib file by hand and remove the invalid actions.

Discover which (if any) route will match a given URL from within Controller in ASP.NET MVC2 app

In my master page I have a placeholder where a Html.RenderPartial() will render a collection of (bread)crumbs which are effectively a list of links I build up using action, controller names and RouteValueDictionary's.
I have an action that is called from multiple places to view a short-list and so when building the list of breadcrumbs for this actions view to display. Ideally I'd like to use Request.UrlReferer as the penultimate crumb.
Before unconditionally using this URL I want to check that it will actually match at least 1 route so I can be sure if the user clicks it they will get a view from my app and if they don't I will simply use the home page instead.
Any suggestions how I would go about this?
Take a look at this post http://haacked.com/archive/2007/12/17/testing-routes-in-asp.net-mvc.aspx