Angular multiple Post and Put request at same time using $q - angularjs

I want to create dynamic configuration where we need create(post) the record if not already created if it's created need to pass put request for that. In each accordion group there is form but we have only save button to save all.

When clicking on the save button, have it aggregate all the records and determine which ones are new and which are existing. Once you have all the records with their statuses, loop through each of the records and do POST and PUT based on their status.

Related

React router - different content if post in list vs own page

React router has very cool feature: if you have a list of items (Instagram for example) and if you click on one item, content opens in modal/overlay but if you copy-paste the link to new tab/window or share the link with a friend for example, it opens in its own page.
I would love to use this feature but I need to find a custom solution..
My posts are very data heavy
I've split posts data into 2 tables in database
1st is very lightweight containing essential data: 4-5 columns
2nd table is very heave, ~30 columns
When user uses search filter, list updates only with data from 1st table
If user clicks on post, it will open in a modal/overlay
I will recycle the data I already have (from 1st table) and also get rest of the data from 2nd table
However, when user shares the link or opens it in new tab/page, data from 1st table is not present. I would need to integrate a conditional logic:
If post opens in list view (modal/overlay), only get additinal 2nd table data
If it's opened in a new tab/window in its own page, get all the data, 1st table included
How could I integrate this with React router? Has anyone already tried it? This would also allow to use different layout/components when user opens item in page view. Is there a way to check it?
Or is there a flaw in my logic? I imagine list would update very fast because it doesn't require huge amount of data and also would modal/overlay because it recycles some of the data.
I read all the docs, also searched online - didn't find anything.
Modals in react router are great. I've used the pinterest example and adapted it to my own needs.
Ensure you do your check on state.modal===true in a master layout component to give you the modal styling.
you'll need to check if table 1 stuff is present in your state and dispatch an action to trigger the async call in componentDidMount. You should be fetching table 2 in all scenarios.

AngularJS dynamic table - RESTfull data

I have a big data portion that I would like to post in a table. However, the data should be sorted and paginated. I know I am able to pass the whole data to the client at once and then paginate it using angular, but this will be too slow. I prefer to pass the data page-by-page, so one the client want to open a page from a table to load the data for it.
Up until now I have created an API that returns me the data that I need, based on the page number and the number of rows on the page. However, I don't know how to use it with AngularJS.
Can you please help me?
It looks like a backend problem. If you are using a standard restful backend, use the limit/skip parameters, you can encapsulate into a paginate.
Example:
localhost:1337/dataTable?skip=0&limit=100
localhost:1337/dataTable?skip=100&limit=100
localhost:1337/dataTable?skip=200&limit=100
...
On the frontend use a table object like ng-Table, and use the pages to keep track of the offset, the page number and the total items available.
skip = (pagNum - 1 * pageSize)
limit = pageSize
Make your backend return you the page you want plus the available dataNumber so you can build the pages controller.
Documentation for skip/limit on sails
http://sailsjs.org/documentation/reference/waterline-orm/queries/limit
http://sailsjs.org/documentation/reference/waterline-orm/queries/skip
Best approach is to keep track of the limit and offset in your controller. Then when user selects new page (offset) or changes items per page (limit), update the corresponding values and use them to make a new http request.
You could call a function on ng-change of a dropdown and that drop down would contain values of page number and number of records to fetch. Or you can provide two text boxes one for page number other for number of records and keep a button and on its ng-click event that will take value of those text boxes and post to your server and bring back data based on new values in text boxes

how to overwrite an existing table row from the rest API output in angularjs?

I have some static html table rows with one column values.
I want to show them first with a loading icon and then would like to fire a rest call for each of the rows remaining values.
After i get the response for each of the row from the rest api, i would like to update the corresponding row in the table.
How would i do that in Angularjs? Any help would be much appreciated.
Just write a promise to call your rest api, then bind the data to the view on the promise success.If you are making individual calls for each rows, have each calls made on individual promises.

Concurrent update on record in Salesforce

In system I am developing, user can access particular page which is used to make DML operation on custom object. I want to fulfill following business case :
User A opens a Page made changes on page but did not click Save.
At the same time User B opens a page made changes and click Save. User B data got saved in record.
Now user A came and click Save. But as data is outdated I want to prompt user that "you are over righting the latest update. Do you want to continue."
Is there any faster out-of-box way available to achieve it ?
Assuming this is in a VisualForce page, you could check if the value has changed inside your Save method.
Query for the LastModifiedDate of all records you may change, and save that in your controller. This should be done in your controller's constructor and/or anywhere you re-load the record(s).
In the save method, first query the record(s) again to check if the LastModifiedDate has been changed. If it has been changed, prompt the user.
Assuming you are trying to insert a record into an object.
You can write a validation rule on that object. Check if that record is already inserted or not and show an error message.
Regards,
Naveen
autorabit

CakePHP - remove data from $this->request->data

I have a edit page for my ExpenseClaim model. The edit page lists all the related Expenses belonging to that ExpenseClaim in a form so users can edit the expenses. I have a X next to each expense so they can delete it if needed. This X just removes the rows fields from the DOM using JS.
When the save button is pressed I'd like any removed rows to be deleted from the Expense table but as $this->request->data isnt changing (the changes are only in the DOM) they don't get deleted. Any edited data does change but not removed data.
I thought about using a postLink but as that creates its own form and I'm already in a form I cant.
So how can I get cake to recognise the changed data? Or am I going about it the wrong way?
Thanks in advance
See this is a database entry and it cannot be deleted like this. And you cannot do it by unset also. The changes has to be reflected in the database.
Better you do an ajax request to the server with the id and delete the row from the database and onSuccess call back remove the element from the dom.
Doing these on a php array is really easy: `unset(array[$key])`.
You can | should | must - it depends on your code - use ajax to trigger these action.

Resources