Changing theme is not persistent Vaadin - vaadin

I'am changing theme by ui.setTheme("theme-name"). It works great until I change the page - then it goes back to the default one. How to make it persistent?
Every page class has #Theme annotation with default theme's name taken from Spring's application.yml.

This happens because every time a new page is loaded in the browser (i.e. not only changing from one view to another using e.g. Navigator), a new UI instance is created. That UI instance will use the default theme unless someone has explicitly run setTheme("some-theme") again.
There are a couple of different approaches to fixing this depending on how persistent you want the theme to be.
One approach is to add #PreserveOnRefresh to your UI subclass. This will make the previous UI instance reused when reloading or temporarily navigating to some other site. It will not preserve the UI and the theme setting if the user closes their browser tab and opens a new one later on.
The other approach is that you explicitly store the user's theme selection somewhere and then manually reapply that setting in e.g. UI.init or after the user has logged in. The two most obvious candidates for storing this is in a cookie or in the user database.

Related

How to handle "mostly-static but editable" content in a Rails app?

I've got a Rails app hosted online, where the standard content has CRUD operations enabled, and multiple editors can create, edit and delete the content using controls in the views. This is working well.
There's also an About page, which contains content that mostly won't change. This is hard-coded in a view, and any changes require me to edit the view, then push the changes to the live site.
I'd like to allow the editors to edit this content online, without requiring my involvement.
Presumably the About page's content will need to be stored in the database, but it doesn't seem logical to enable the full CRUD operations on it. Eg, there will only be 1 About page, and it shouldn't be possible to delete it.
What is the preferred Rails approach for allowing the About page's mostly-static content to be editable online?
If all you want is to avoid allowing editors to delete your page, you can just avoid not putting the delete action (delete, destroy) inside your views and controllers. However, you will need to enable the create, read and update actions (CRU) , as that really is the only way to update the site remotely, short of giving them access to your app directly and having them upload it directly on to your hosting server (not recommended).
I'm assuming you already have a functioning login/authentication system, so you would simply need to just extend that functionality to the about page, by requiring the editors to login and authenticate themselves, before being allowed to perform CRUD (without the delete, D) functions.
Note that even if you were to get rid of the delete function, they could delete the about page accidentally or on purpose by simply performing an update that has nothing inside of it. You should just to be safe be saving your webpages to some sort of version control software (i.e.: Git), so that even in an event where your information gets lost, a previous backup can be used to restore your website to a previous state.

jquery tablesorter issue with page number

I am developing an ASP.NET MVC 4 application using jquery.tablesorter.js, jquery.tablesorter.pager.js and jquery.tablesorter.widget.js. Now I get an issue with this tablesorter, that is, the page number is saved in the local storage.
I understand it is saved for some reasons. The problem is, for example, I last open the 3rd page of the table and leave the session, then re-open a session, it goes to the 3rd page automatically. If, for some reasons, there is not enough items for any item to go to the 3rd page, it simply shows an empty table and pager, and confuses the user.
Any idea is highly appreciated.
Thanks,
A. Zhang
If you don't want the pager to save the page & size, then set the savePages option to false.
If you do want the page to get saved, but you only want to use session storage, then set the storage_useSessionStorage widget option to true.
Please note: the above options only work with my fork of tablesorter.

Durandal+Knockout to develop a Single Page Application: Selectively show portions of page based upon authorization

I am using Durandal, knockout to create a Single Page Application. I need to do following (two pretty simple things):
Show/hide widgets that are only for administrator, based upon the user's authorization,
Change menu options based upon whether user is authenticated or not (for anonymous show - login/sign up and when authenticated show "Welcome .." .
If this was a regular MVC4 application I would have done it using
#if (User.Identity.IsAuthenticated) { ... } check in razor views, but with views in durandal this is ruled out.
I want to avoid putting sensitive business logic in javascript - user need not know what kind of options could have been available to him if he was an administrator.
What's the best way to achieve this in Durandal & Knockout? I have been coding so far using classic ASP.NET and lately using ASP.NET MVC. Developing SPA using Durandal is a new game for me...If anyone can give me only steps/pointers to do this that will help a lot too..thanks in advance!
The way I do it.
My menus are build inside a menubar.js file. The menuItems are observableArrays([]) initially and I subscribe to a topic "user-logged-in".
When the user logs in, I get the user's permissions/roles and store them locally in storage. and then send out notification "user-logged-in" with the user data.
My menubar recieves the notification, checks the permissions/roles and adds various menu items appropriately.
the shell.html has a view composition for the menubar.js. So if there are menuitems, it shows up, else it does not. so when the user logs in, the menuItems are populated and at this point the menu items show up.
When the user logs out, I clear the local storage cache and send out a message "user-logged-out".
The menubar.js recieves this message and clears it's menu items, essentially clearing the menu on the menubar.htm
You can essentially do the same for the widgets and use a visible binding to a property which hides or shows for a particular permission/role.
Also important is router.guardRoute. read up on this so that people cannot directly go to a route without logging in.
Hope that helps

already logged page should be display when open new tab in struts2

I developing Struts2 project.
In that project the user can log in and do something its work fine.
If that user open the new tab and type my project url it will show the same page(after login page).
How do I implement the above scenario?
One way would be doing like described here, in a question almost identical to your (concept is the same, only the implementation, on .NET, differs).
Calculate an unique value each time you pass in the Action, then put
it in a session variable (that is server side) and use it to feed an
hidden field on the web page (that is client side).
When the page will post back (submit) the form containing your hidden field, you
will see if the page field and the session field are the same.
If yes: it is (the only OR) the last page / tab opened.
If no: you are trying to submit the form from a page that is not the
last page opened.
This way, you will always have only one instance of the web application, and if you open another instance of the web application in a new page / tab, it will invalidate the previous one: only the last opened will be valid (because of multiple hidden fields, one for each page, but only one session variable).
IF you really need (do you?) to prevent the user opening a new tab instead of ensuring a single instance for the web-app, start working from this principle and eventually come back here (better with some code)

Force Umbraco to set Home.aspx as the default document?

I am desperately looking for a way to force (or even hack) Umbraco to set the default document to Content/Pages/Home.aspx, instead of the first page.
(Currently I created a dummy page that redirects to Home.aspx as the first page under Content - but it is not ideal especially for SEO)
This is easy to do, add a new field to your existing/current default document called 'umbracoInternalRedirectId', of type 'content-picker.'
While editing the content for that page, choose the contentpicker and point it to the page you want to be the default document and save/publish and you should be good to go.

Resources