xamarin forms shell doesn't navigate to nested view - forms

I have a xamarin forms project which uses the new AppShell. I have a flyout menu with some menu items. One of the menu items is called e.g. MyComputer. Open it up it shows a list of folders. When I click on one folder a new page opens and shows a list of folders again - and so on - like nested folders. Unfortunately when using the new await Shell.Current.GoToAsync("folder"); to open a folder within a folder page nothing happens. No navigation is executed. It seems that it is not allowed to push the same page onto the navigation stack. However this worked with the "old" navigation myPage.Navigation.PushAsync(folderPage);. Because the original documentation for AppShell contains no restrictions for nested views I think that I'm missing something.
My AppShell.xaml
<FlyoutItem FlyoutDisplayOptions="AsMultipleItems" Route="app">
<ShellContent Title="MyComputer" Route="myComputer" ContentTemplate="{DataTemplate views:MyComputerPage}"/>
</FlyoutItem>
Register my folder page:
Routing.RegisterRoute("folder", typeof(FolderPage));
Calling the folder page from MyComputerPage (this works):
await Shell.Current.GoToAsync("folder?name=myFolder1");
Calling folder page from FolderPage (this is not working, nothing happens, no navigation executed):
await Shell.Current.GoToAsync("folder?name=myFolder1b");
I want to navigate like this:
MyComputerPage -> FolderPage -> FolderPage -> FolderPage -> ...
Just for better understanding how does the folder structure could look like:
myFolder1
myFolder1a
myFolder1aX
myFolder1aY
myFolder1aZ
myFolder1b
myFolder1c
myFolder2
myFolder3
EDIT:
#Junior Jiang - MSFT here you go:

About Relative Route and Passing Data , from shared gif and code , maybe you mistake something when using them.
if all the routes in an application are unique, navigation can be performed by only specifying the unique route name as a relative URI:
await Shell.Current.GoToAsync("TargetPageName");
//such as await Shell.Current.GoToAsync("myFolder1Page");
Data can be passed as query parameters when performing programmatic navigation.
await Shell.Current.GoToAsync($"TargetPageName?DefinedKeyName={BePassedValue}");
//such as Shell.Current.GoToAsync($"myFolder1Page?name={ValueOfmyFolder1Page}");
To receive data, the class that represents the page being navigated to, or the class for the page's BindingContext, must be decorated with a QueryPropertyAttribute for each query parameter:
[QueryProperty("Name", "name")]
public partial class myFolder1Page: ContentPage
{
public string Name
{
set
{
BindingContext = FolderData.FoldePages.FirstOrDefault(m => m.Name == Uri.UnescapeDataString(value));
}
}
...
}
So here your problem , first need to rename page name to fit this route method.
eg:
In MyComputerPage , when you navigate to myFolder1 page , you can register myFolder1 page's key be myFolder1 page.
Then if no data :
await Shell.Current.GoToAsync("myFolder1");
Pass data :
await Shell.Current.GoToAsync($"myFolder1?name={ValueOfmyFolder1}");
When this working and next page registering as same,then have entered in myFolder1 page ,next want to navigate to myFolder1a page , should write as follow:
await Shell.Current.GoToAsync("myFolder1a");//no data
await Shell.Current.GoToAsync($"myFolder1a?name={ValueOfmyFolder1a}");// pass data
Next , want to navigate to myFolder1aX page ,should write as follow:
await Shell.Current.GoToAsync("myFolder1aX");//no data
await Shell.Current.GoToAsync($"myFolder1aX?name={ValueOfmyFolder1aX}");//pass data

Related

Refreshing dynamic form fields after data has changed

I have a ColdFusion page that has, among other things, forms that are built using DataTables.
This page manages a handful of things (documents, categories, doctypes, etc) and each tab has CRUD functionality going on.
Initially, on each tab, it simply displays the current set of (fill in the blank) but if you click the create/update links/icons, the form to do so pops up. Some of the form fields are actually lists of the others. For example, if I want to upload a new document, one of the form fields is the category for that document.
I get the information for that form field by using cfinvoke to a get function in a cfc, which returns as a query and I loop through, populating the dropdown.
My problem is this: If I go and create a new category on the category tab I need the dropdown of category choices to update over on the new document form. However, it's already been populated and won't recheck that info until I refresh the page and thus won't show my new category in the dropdown.
The way I see it, I need to reinvoke the CFC method, repopulating the query variable and then refresh the form to make it loop through the new data and fully populate the dropdown.
I've tried to call the cfinvoke and reset the form from within the callbacks section of the DTHelper() but that (kind of as expected) didn't work.
How would I force the refreshing of the data, and subsequently, the form when this all takes place using AJAX and the actual page never reloads? Or should I just be forcing a page reload in this situation? (which works, I tried that, but it's a page refresh)
So, my boss figured it out. You have to use drawCallback().
In my example it worked like so. First, give all your major category select boxes a class:
<select name="majorCategoryID" class="major-category-select">
...
</select>
Then modify the DataTable options for major category:
majorcat_dt = $("#majorcat-dt").DataTable({
ajax: "blah"
columns: [{ blah }],
drawCallback: function() {
/* remove all options from select boxes */
$(".major-category-select option").remove();
/* this is the crazy DataTables api call to get rows */
this.api().rows().data().each(function(row) {
$(".major-category-select").append("<option value='"+row.id+"'>"+row.name+"</option>");
});
}
});
This also removed the need for the cfinvoke in the first place since this also populates the dropdowns on page load as well.
Here is how I did something like that once.
javascript:
var minutes = 10;
var refreshInterval = minutes * 60 * 1000; // to get milliseconds
jQuery.fn.populateCensusDiv = function() {
$.ajax({
type:"POST",
url:"censusData.cfc?method=getCensusData",
cache:false,
success: function(msg) {
$("#census").html(msg);
}
});
setTimeout(function() {
$("#census").populateCensusDiv();
}, refreshInterval);
return this;
ColdFusion function
<cffunction name="getCensusData" access="remote" returntype="string"
//deleted code
returnFormat = "plain">
<cfscript>
var returnString = "";
</cfscript>
more code
<cfsavecontent variable="returnString">
more code
</cfsavecontent>
<cfreturn returnString>
</cffunction>
My context was an html table that got refreshed every 10 minutes. You can adapt it for your own needs.

What is the proper way to integrate dynamic content into the layout.ejs file in a Sails.JS application?

Say I wrote a blog app in Sails.js.
On every page in this app, there is a sidebar widget called "Recent Posts", where it lists the titles of the 5 most recent posts and clicking on them takes you to the post in question.
Because this sidebar widget is present on every page, it should be in layout.ejs. But, here we have a conflict - dynamic content is only supposed to be pulled from the database in the controller action for rendering a specific view.
This dynamic content isn't for a specific view, it's for the whole site (via layout.ejs).
By the conventions that I understand, I'd have to get that dynamic content data for the sidebar widget in every controller action that renders a view (otherwise I would get an undefined error when I attempt to call that local in my layout.ejs file).
Things I've tried / considered:
Load that dynamic content in every controller action that renders a view (this solution is very bad) and calling that dynamic content in layout.ejs as if it were a local for the specific view. This works fine, but goes against D.R.Y. principles and quite frankly is a pain in the ass to have to run the same query to the database in every controller action.
As per another similar stackoverflow question, create a new config (E.G. config/globals.js), load my dynamic content from my database into that config file as a variable, and then calling sails.config.globals.[variable_name] in my layout.ejs file. This also worked, since apparently config variables are available everywhere in the application -- but it 's a hacky solution that I'm not a fan of (the content I'm loading is simply the titles and slugs of 5 recent posts, not a "global config option", as the solution implies).
Run the query to get the dynamic content inside the .EJS file directly between some <% %> tags. I'm not sure if this would work, but even if it did, it goes against the separation of concerns MVC principle and I'd like to avoid doing this if at all possible (if it even works).
As per a lengthy IRC discussion # http://webchat.freenode.net/?channels=sailsjs, it was suggested to create a policy and map that policy to all my controllers. In that policy, query the database for the 5 most recent posts, and set them to the req.recentposts. The problem with this solution is that, while the recent posts data will be passed to every controller, I still have to pass that req.recentposts data to my view -- making it so I still have to modify every single res.view({}) in every action. I don't have to have the database query in every action, which is good, but I still have to add a line of code to every action that renders a view... this isn't D.R.Y. and I'm looking for a better solution.
So, what is the proper solution, without needing to load that dynamic content in every controller action (a solution that adheres to D.R.Y. is what I'm lookng for), to get some dynamic content available to my layout.ejs file?
In folder /config you should create a file express.js and add something like that:
module.exports.express = {
customMiddleware: function(app){
app.use(function(req, res, next){
// or whatever query you need
Posts.find().limit(5).exec(function(err, posts){
res.locals.recentPosts = posts;
// remember about next()
next();
});
});
}
}
Then just make some simple loop in your view:
<% for(var i=0; i<recentPosts.length; i++) { %>
<% recentPosts[i].title %>
<% } %>
Here are some links to proper places in documentation:
https://github.com/balderdashy/sails-docs/blob/0.9/reference/Configuration.md#express
and
https://github.com/balderdashy/sails-docs/blob/0.9/reference/Response.md#reslocals
I found out another way to do this. What I did was to create a service that could render .ejs files to plain html by simply taking advantage of the ejs library already in sails. This service could either be invoked by the controller, or even passed as a function in the locals, and executed from within the .ejs. The service called TopNavBarService would look like:
var ejs = require('ejs');
exports.render = function() {
/* database finds goes here */
var userInfo = {
'username' : 'Kallehopp',
'real_name' : 'Kalle Hoppson'
};
var html = null;
ejs.renderFile('./views/topNavBar.ejs', {'locals':userInfo}, function(err, result) { html = result; });
return html;
}
In the constroller it could look like:
module.exports = {
testAction: function (req, res) {
return res.view('testView', {
renderNavbar: TopNavBarService.render // service function as a local!
});
}
};
This way you can create your customized ejs-helper that could even take arguments (although not shown here). When invoked, the helper could access the database and render a part of the html.
<div>
<%- renderNavbar() %>
</div>

In CQ How to disable any field in child page properties dialog?

I have added a new selection type field "Theme" in page properties>Basic.
Now if I add a new page using the same template in WCM, there also I
am getting the option "Theme", which is quite obvious.
Is there any way by which I can hide the field in child page?
P.S this is happening because I am using the same template for the child page.
You can't use the same template and have the page property dialogs be different.
What you can do is overload the dialog
create a new template and corresponding resourceType component that
inherit from your current.
copy the dialog, or tab that you want to be different from the lowest parent of the component. Make sure the dialog is the only node under the component.
Make the changes you want to the dialog.
You would then have to include code in the page jsp to get the parent page property something like:
// if the parent page is always a certain level below the root you can use
// currentPage.getAbsoluteParent(3); to get the third page down from the top
// of the current path tree.
Page parentPage = currentPage.getParent();
ValueMap parentPageProperties;
if (parentPage != null) {
parentPageProperties = parentPage.getProperties();
}
// This tries to get the property 'theme' from the current page. If that fails
// then it tries to get the property from the parent page. If that fails it
// defaults to blank.
theme = properties.get("theme", parentPageProperties.get("theme", ""));
A quick solution would also be to create a second set of template / page component. Let's assume you've got template A, that uses page component B as resource type:
Create template X and play with allowedParents allowedChildren and allowedPaths properties so that the two are exclusive (actual solution depends on your content architecture)
Give X same title as A
Create page component Y that extends B, and defines it's own dialog
Make Y's dialog re-use any tabs from B using xtype=cqinclude (see foundation page's dialog for reference)

Validation Forms that were loaded via Ajax into jquery-ui tabs

I'm using jquery-ui tab example to add extra tabs. I changed that code to be able to add tabs that load a form via Ajax. I was able to create that just changing these:
var $tabs = $( "#tabs").tabs({
cache: true,
tabTemplate: "<li><a href='formularioAgricola.php' id='#{label}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span></li>"
//ajaxOptions: a
});
So I changed the tabTemplate to load the same Form always.
My problem is that I'm not sure how to retrieve, either to tell that every tag from that form use jquery-ui stuff, like buttons, datepickers, etc.
In a regular form I would do something like:
$("#btnRevisar").button()
But when we talk about form load via Ajax it is different.
and also, how can I try to differ one form from other one, if they are all named with the same name, is it possible?
Thanks guys
Carlos.
Within the tabs docs page, tab titled "Events" there is a "load" event. The "ui" argument gives you access to an object that includes the current panel that is loaded. If you are using same ID on forms, beware that ID's must be unique in a page.
var $tabs = $( "#tabs").tabs({
cache: true,
tabTemplate: "<li><a href='formularioAgricola.php' id='#{label}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span></li>",
/* add new option for load event*/
load: function( event, ui){
var $currTabContentPanel=$(ui.panel);
/* only look in currently loaded content for formClass*/
$currTabContentPanel.find('.formClass').doSomething()
}
});

Redirect back to list on syfmony generated form?

I've generated an admin section with Propel on syfmony. When I have added an item I wish it to redirect back to the list, and not to an edit view.
In fact, I actually want to remove the edit page as for these objects only new instances are allowed - no deletions or editing.
How do I achieve this?
probably the best way to do this is to override the Create action, but for your specific case though there is easier (but no so clean) solution.
Since you don't want to use edit action you can remove it from generator.yml list actions and then override '[YOUR_ITEM]_edit' route to point to items list page.
This way when new item is added you will be redirected back to items list page (overridden edit route) and also manual try to access edit action will redirect to items list page.
What you think?
I found the best way for this is to edit the form as such:
class CouponForm extends BaseCouponForm
{
public function configure()
{
$this->getValidator('used')->setOption('required', false);
$this->getValidator('valid_until')->setOption('required', true);
$this->getValidator('created_at')->setOption('required', false);
$this->getValidator('updated_at')->setOption('required', false);
}
}
and then in the generator.yml file edit the 'edit' actions:
edit:
actions: { _list: ~ }