Ionic 2 - Store user credentials (local storage vs nav params) - ionic2

I´m developing an Ionic 2 app. When I make login, I could store user credentials on SQLStorage, LocalStorage or transfer it as parameter on NavParam.
Example:
onLogin(){
this.nav.setRoot(MainPageComponent,user);
}
vs
let storage = new Storage(SqlStorage);
storage.set('name', 'Max');
What is the main advantage of storage over passing as parameter?

What is the main advantage of storage over passing as parameter?
If you use that information just in one page or two, you can send it as parameter. But the problem is that you will probably use the name in more than one place (maybe in a settings page, or in the side menu of the app, and so on), so storing that information somewhere would be a good idea so you can get it back when you need to.
Also, if you get that information in one page, and you want to show it in another one, but those pages are not connected directly in the workflow of your app, you would need to pass it through some other pages just to get it where you want to show it. So again, storing that data seems to be a better approach.
Please notice that if you use SQLStorage or LocalStorage, you should set also an expiration date to force the user to log in again after a given period of time.

Navparams is used for transferring the data between pages say, you have to open a particular item's details, you need to click on an Item and the parameters will be sent using Navprams to the itemDescription page.
You prefer localstorage.setItem('userId', $userId), because storing locally will solve the unwanted sign-in every time you open the app.
If you store in your local storage, then on every app on load, we can check the existence of the local variable.
if(localstorage.getItem('userId')==null){
this.signin();
}
else{
this.appOpen();
}
This one can help you!

Related

Automatical update of an Appian webpage on change of task status?

We have an Appian grid that shows all Appian tasks of a user. The corresponding data we obtain using queryProcessAnalytics(). How can we make this update automatically when the task status changes?
Currently, we have stored the result of queryProcessAnalytics() in a local variable and we set a!refreshVariables() to refresh this variable on every "user interaction" with refreshAlways: true. We also added a button Refresh that doesn't store anything away, but simply counts as a user interaction when it is clicked. The grid then refreshes automatically when the local variable with the data changes, because the grid is set to refresh when a used/dependent local variable has changed, which mainly means that the user is forced to click on Refresh to ensure to be up-to-date and see latest tasks.
We consider this a workaround as the refresh automatically on variable change in our understanding triggers refresh of local variable (and thus the grid) only once an another local variable changes, but does not trigger a refresh queryProcessAnalytics would suddenly throw a different result.
Any help towards a fully automatical solution is appreciated!
We searched the Appian community but to no avail. Most entries are rather old, e.g.
Grid refresh not working on Load()
You should use refreshInterval within your a!refreshVariables()with value 0,5. It will refresh every 30 seconds.
https://docs.appian.com/suite/help/21.3/fnc_evaluation_a_refreshvariable.html

How should the backend code be if I want to give a part of a large amount of data and provide more and more as the frontend asks?

I'm currently using loopbackjs for making the API endpoints, and graphQL as an intermediate for making queries from the frontend, where I use Relay and React framework.
Now, I have an application where a user can view a list of projects (The project has very generic information like creation date, name, etc.). This list of projects can be very large. So its infeasible to just send all the projects at once. Now, I want to send the first few projects to the frontend and then as the user scrolls down, I want to send a part of the remaining projects when the user reaches the end of the list provided to him/her in the frontend.
I've thought about maintaining a pointer sort of a thing, that indicates till where I've fetched the projects in the list so that I know from where I would fetch the further projects. But this pointer is dependent on the user so for every user I need to maintain a pointer. This gets everything very messy.
Is there a clean approach for doing what I want with the current stack I am using?
Here is how I fetch my first 25 projects:
projects(first: 25, after: $lastID) {
...
}
You could probably change the either variables passed to graphql to return you the infinite scrolling of list of projects. First 25 already helps u limit the amount u get back.
For more references you could find it here https://facebook.github.io/relay/docs/graphql-connections.html

Store Total Steps count in Request or Application scope?

I'm creating a multi-step form with pagination that will show a Next and Previous button depending on which step you are on. In order to display the buttons correctly, I need to store the total number of steps in a variable somewhere.
Do I store this in the Request scope e.g. REQUEST.TotalSteps = 5 or Application scope e.g. APPLICATION.TotalSteps = 5? The number of steps will rarely change so I'm thinking that Application scope is better suited, but I want to minimize the use of RAM because I have a lot of stuff stored in the SESSION scope for each other.
What would be the ideal option?
Depends on how you're gonna be using it really, and what framework you're using, how you're architecting your app and all that sort of thing. You only need the value in memory during the request(s) that need it, so TBH I'd just put it in the variables scope, making sure that the code that sets that variable is loaded for the requests that need it.
You'd not want to put it in session because it's not value specific to the visitor, nor does it have any relevance to the session: it's all just about that form.
Similarly it would not belong in the application scope (well: that has caveats, but given the low level of detail you give us as to how you've built you're app, let's assume this to be the case) because - again - it's not something the entire app needs; just the pages actually interested in how many pages that form has.
If you can give us more information regarding your architecture, I can possibly fine-tune this answer, but based on the info given: this is pretty much how you need to approach it, all things being equal.
The session scope is used to store information for the specific user. The application scope is used to store information that is available to the entire application. The request scope stores information during the course of the request. You want SESSION scope.

Caching data (image, rss) with django

That's my first question in here, I've been looking through old questions, but nothing matched with my problem. Here it is.
I'm creating some site with one main functionality. We want this site to display content of other sites, but in a specific way. User chooses let's say two pages from five and want to see their content. He clicks button 'Display' and goes to next page where he finds let's say view from web cam, and here comes problem.
I want to cache image that is hidden behind the url from which image was downloaded, so after refresh image won't be downloaded again, but browser will get it from cache.
I've been looking through documentation of Django, but nothing seemed to be useful.
I know that I should:
1) create table which stores cache
2) add to settings.py some CACHE_BACKEND = ...
3) use #cache_page(300) before declaration of function which returns content which should be cached,
but... it doesn't seem to work.
I will be greateful if someone tells how to solve that problem, maybe with some sort of code showing the mechanism.
Cheers,
Chris.
I think that right way to do this will be to store image somewhere on your server and delete it later with cron or something similar.
Django cache framework wasn't created for the purpose you are trying to use it.

Synchronizing DataGridView (DataTable) with the DB

I have the following situation: there is a table in the DB that is queried when the form loads and the retrieved data is filled into a DataGridView via the DataTable underneath. After the data is loaded the user is free to modify the data (add / delete rows, modify entries).
The form has 2 buttons: Apply and Refresh. The first one sends the changes to the database, the second one re-reads the data from the DB and erases any changes that have been made by the user.
My question is: is this the best way to keep a DataGridView synchronized with the DB (from a users point of view)?
For now these are the downsides:
the user must keep track of what he is doing and must press the button every while
the modifications are lost if the form is closed / app crash / ...
I tried sending the changes to the DB on CellEndEdit event but then the user also needs some Undo/Redo functionality and that is ... well ... a different story.
So, any suggestions?
I would say that the way you are currently doing it is fine. If you start attempting to update the database while the user is still making edits you can run in to issues updating or modfiying things that the user may ultimately decide they did not want to change. Additionally this has the chance to greatly increase the number of database calls.
Forcing the user to click apply helps ensure that only the changes the user actually wants are sent to the database.
As for losing the changes if the app crashes before applying them, I would be more concernced with why the app is crashing.
The only important thing to remember is that you should refetch the data before saving it and the refetched data should still match the data you originally displayed to the user. If it doesn't, someone else made a change your user will be unknowingly overwriting. Your users probably will not like that.
How you handle this is dependent on what your client needs in their database.