Ember js Doesnt Update List retrive from model in template - javascript

I am creating a simple ember app which will retrieve data from Laravel backend server restfully. I can display edit create and delete these records from ember successfully, however when i do any of the crud operation from ember instead of edit, the template doesnt update itself.
Like when i edit the record from ember, ember tempate displays the edited content in realtime, but when i create a new record or delete the one existing, the ember list displays the old record list.
What should i do to make the app update its model data when any changes happen.
Here is my code:
http://jsbin.com/iSEmONuV/
the code in jsbin is non functional .. i just uploaded in jsbin as it is much easier in jsbin than in stackoverflow.. to paste code.. i am using local server to load data.. ihavent uploaded it in real server yet

The problem is createRecord/deleteRecord in ember model doesn't modify any current collections (Ember Data does). So if you create/delete a record that you believe should live on some collection (hasMany or what not) you'll need to manually add/remove it to/from the collection.

Related

How to update large dataset with MySQL migration scripts

We are developping a Nodejs app for a client that demanded that we use migration scripts to facilitate update the production database. Since i'm new to MySQL , i can't wrap my head around something, which is, how am i supposed to update tables content with only MySQL when i need to do some API calls to get the updated information, compare it to the current one and then update what needs to be updated.
What i did so far is, saving the new data in a JSON file. Is it possible to read a JSON with MySQL and import its content. This is what i want to do :
// read json file and star a loop
UPDATE table SET column = data WHERE id = json_id
// data and json_id are information from the JSON file
Is that possible ? if so how can i achieve that ?
Create a migration script. You can create a .sql file with scripts for create, update, and whatever you need for tables, stores procedures etc. Now when you want to deploy your app in production environment you can execute this script in the production instace and this will recreate your tables, sp's and even data if you want. You don't need an api endpoint for that.

Laravel AJAX call not working after reloading view?

I have a standard CRUD web app in Laravel that allows users to view and edit records. It also has a sorting mechanism that asynchronously (using AJAX) sorts the main records view.
This works fine until the user clicks on a record in the records view to edit it. Then they are redirected through the web router to a new Controller function that loads the update view for that record. When they click to save the SAME update function used to load the update view is fired a second time, and it updates the record and returns the ORIGINAL records view.
The problem is, the AJAX sort function for the records view only works BEFORE the update function is called. I've compared the HTML and JavaScript before and after a record is updated and it is IDENTICAL. So why does the AJAX function stop working?
My only guess is it has something to do with the web router. Predictably, the original read view is called with a GET method, and the update function uses POST, but I tried changing the "type" property in AJAX to POST with no luck.
Try adding _method=POST to your post data
Also do not forget to send csrf-token (axios does it automatically)

Ionic - Getting ID from previous page to update with new data on next page

I have some data from first page (or "Data Form" page) that needs to be loaded on next page (or "Add More Info" page) with same ID from first page before any controller is executed in my ionic application with sqlite database. In next page (or "Add More Info" page), I want add some new data to previous data with same ID before return again to first page.
You can check my flowchart below:
How can I achieve that?
You can check out my repo on github to fix this problem.
You have several options of that :
EASIEST BUT "dirty"
You can use $rootScope to store all you data and initialise them on each of controller.
Clean Solution parameters
You can define ui-router parameters for each of the variables you want to send.
See ui-router doc : https://github.com/angular-ui/ui-router/wiki/URL-Routing
using LocalStorage
For persistance, you can use localStorage. It is clean and won't impact your routing ruleS.
Better solution, using a service
See that explanation concerning data persistance and services :
https://stackoverflow.com/a/12574818/3687474
I'll personnaly go for the service solution that is scalable, portable and testable

knockout.js external model js file

I have an MVC.NET app which using Knockout.js (+ knockout.mapping) to deal with some cascading dropdowns. The data for these comes from a WebAPI call to an external service. As it happens this service requires an authentication token which expires after 2 hours, so I have the MVC app put the data from the service in a System.Web.Caching.Cache and return it from there unless the token has expired where it will grab it again from the service.
This is working fine.
However when I need to get this to the View, I am currently using the following method, which is to have a property of the ViewModel that I assign the service/Cache data to and then do this in the view:
var model = new ViewModel(#Html.Raw(Json.Encode(Model.ReferenceData)))
ko.applyBindings(model);
where Model.ReferenceData is the data from the service.
again this is working fine, but... the thing is with this, that the page then has all that Json data dumped in it on each request.
I would like to use an external JS file for the ReferenceData as then at least it can be cached by the browser and lessen the weight of the page on future requests.
However, I imagine that the overhead of generating a JS file is not that small, along with – what I really need is it to generate a link to that file that changes in much the same way that the built in MVC bundling of js files works – generating a link with a querystring.
My question is: is there an easy way of doing this?
For sure I can, when the cache is filled that first time, generate a js file and reference that from the View, but as I say getting that to change its link each time it is refreshed – or at least working out whether the data in it has changed and updating it only then is where the problem lies.
Any insight to this would be of great help
Thanks
Nat
Version the JS file (you can keep a GUID in the file it-self).
In Application_Start() get this version ID to a static variable.
In your controller pass this static variable data to ViewBag.
Ref your script with this ID
When you regenerate the file, update the version in file as well as your static variable. Next request from the client get the new version with new key.
Now if you want to update clients on the new version you have to use bi-directional protocol like web sockets or long-polling.

How to check if a model has been changed but has not been saved to the server? (Ember.js / Ember-data)

With ember models as they are changed by user input, they are persisted over the application with the changed values (until a refresh of some sort to reload the data from the server). Now these models and their changes have not been saved to the server.
So I am wondering how I can check if models have been changed but have not been saved to the server yet.
Use case: To let users know that the following changes have not been saved yet.
I am just looking for some sort of boolean variable if one is available through ember or ember-data.
If not, some help would be appreciated to roll my own (I'm very new to ember).
You want the isDirty attribute.

Categories