How to push my Records into SC.ArrayController content? - sproutcore

I am trying to get my sample data (records created from fixtures) into my SC.ListView. I know the records are built properly because I am able to get particular data by finding it by its primaryKey.
The SC.ListView is pulling its content via contentBinding: 'MyApp.thisController.arrangedObjects' from this SC.ArrayController:
MyApp.thisController = SC.ArrayController.create(SC.SelectionSupport, {
allowsMultipleSelection: NO,
content: MyApp.store.find(MyApp.MyRecordType)
});
To init the store I use the function from the official guide:
store: SC.Store.create().from(SC.Record.fixtures)
How do I set my content property in the controller right to import the SC.RecordArray?

this will only work if your store is created before your controller. Try doing
MyApp.thisController.set('content', MyApp.store.find(....));
after the app loads, in the console. If that works, you need to query the store after your app initializes.

my problem was that the store was generated AFTER the controller tried to set the content, which is very confusing because with the following code from another tutorial it is working fine.
store: SC.Store.create().from(SC.FixturesDataSource.create({
simulateRemoteResponse: YES,
latency: 250
}))
Anyone knows to tell me why the store creation in the question text fails to generate before?

Related

Not all NSUserDefaults are restored on app relaunch

I am converting 2 custom lists into a json string and storing it the NSUserDefaults. Something like so:-
NSUserDefaults.StandardUserDefaults.SetString(JsonConvert.SerializeObject(stationList.Take(50)), "StationList1");
NSUserDefaults.StandardUserDefaults.SetString(JsonConvert.SerializeObject(stationList.Skip(50).Take(50)), "StationList2");
If I try and retrieve them immediately after saving them like below I get the saved values:-
savedStationList1 = NSUserDefaults.StandardUserDefaults.StringForKey("StationList1");
savedStationList2 = NSUserDefaults.StandardUserDefaults.StringForKey("StationList2");
But the issue is if I restart the app, and try to get the above values in another part of the code, I only get the value for:-
savedStationList2 = NSUserDefaults.StandardUserDefaults.StringForKey("StationList2");
and the value for below is always null :-
savedStationList1 = NSUserDefaults.StandardUserDefaults.StringForKey("StationList1");
I do not override these values anywhere within the app. Is there a way I can solve this?
Any help is appreciated
Although natively the iOS system does store data added through 'userdefaults' it may not do this instantly. I would suggest adding the following line:
NSUserDefaults.StandardUserDefaults.Synchronise();
After you store data to standard user defaults run the synchronise and test that you can extract the data, you should find that this will now work correctly for you.

Not able to import EntityState Added

I'm having an issue with importing cached data. I have a very simple page right now to use as a proof of concept. There is a single table in the back end. I have all CRUD functionality working. When the user makes a change to the local data, I update a record in local storage.
var bundle = em.exportEntities(em.getChanges());
window.localStorage.setItem("waterLevelChanges", bundle);
after the page is loaded I import the entities
var bundle = window.localStorage.getItem("waterLevelChanges");
if (bundle)
em.importEntities(bundle);
This works perfectly if I'm editing an existing record. However, any records that I have added, but not saved to the database won't populate. In the bundle they have an EntityState of "Added". I read that there is an issue if you don't use the temp keys, but I'm letting Breeze use the temp keys and manage them as it likes. I have verified the data is stored in the local cache by looking in the developer tools. I can also see it in the bundle when I debug.
Our tests show that your stated scenario should work fine.
See this DocCode:export/importTests.js test where a new Order is exported, saved to browser storage, and reimported; it's "Added" state is confirmed. The Order type has server-generated, temporary keys.
I think you'll have to create a repro of your failing scenario to convince me that it doesn't work. Perhaps you might start by forking this Todos plunker and modifying it to make your point; a TodoItem also has has server-generated, temporary keys.

Saving to Parse database from Google Apps Script

I'm trying to save data to a Parse database from a Google Apps Script function. I attempted to use the ParseDB library (https://script.google.com/macros/library/d/MxhsVzdWH6ZQMWWeAA9tObPxhMjh3Sh48/12), but I can't seem to get it working. It seems like I'm not accessing the ParseDBInstance correctly:
function onFormSubmit(e) {
// e.namedValues is an object containing question fields associated with lists of responses
var db = getMyDb('redacted',
'redacted',
'response');
Logger.log(db);
db.save({
test: 'a_string'
});
}
I can't find anything online indicating how I'm supposed to be doing this...and I feel like I'm just doing something dumb (pretty new to apps script/javascript in general/parse).
Any suggestions would be much appreciated!
You need to click 'resources > libraries" then use the key "MxhsVzdWH6ZQMWWeAA9tObPxhMjh3Sh48"
You can then use the library by calling ParseDb.getMyDb(applicationId, restApiKey, class)

Response comments added to the wrong parent document

I have a view data source that uses a view key to access documents and show them in a repeat with var "posts". within the repeat I have a document data source with var "post" that gets's the the unid of the documents using posts.getUniversalID().
further down the repeat I have another document data source "newcomment" that is a response and take the parent id as: post.getDocument().getUniversalID()
below the newcomment data source I have an editbox and a submit button which saves the comment as a response to the "post" using newcomment.save()
Here is my problem
two people access the same xpage. personA enters the page and starts writing a comment to a post. in the same time personB creates a new post and submit it before personA submits the comment. What happens now is that the comments gets binded to the latest post and not to the post personA responded to.
I tried anothoher thing also, let's say there is 10 posts in that database. personA and personB access the xpages. personA start writing a comment to post number 8. at the same time personB creates two new posts in the database. when personA now submits the comment it seem to get bind to the same index which is now two posts up. but still index 8. which is ofcourse the wrong post.
If I change the repeat to "createControlsAtPageCreation" ie.e repeatControls=true the comment is attached to the correct post but then I run into another problem that the view is not updated to show the latest posts.
my repeat is wihtin a custom control that is loaded dynamically using the dynamic content control in extlib.
As information here is what I have found about the repeatControls settings
Setting the repeatControls property to true instructs the repeat control to create a new copy of its children for each iteration over the dataset.
When the Repeat control is configured with the property
repeatControls=“true” , it repeats its contents only once, at page load time
So my question here is that I do not understand what is going on. why is my comment attached to the wrong parent document? and is there a way I can prevent this and still have new posts displayed correctly
thanks for your help
Without the code it's a bit hard to imagine what exactly is going one here but this looks very similar to problem that I had with repeat control and value binding.
Long story short the problem was connecet to repeatControls property set to false. When it was like that data binding were working only for first element in collection - all data was somehow magically saved to this first object! I managed to get this working by using combination of dynamic content control rebuild and repeatControls set to true. Only then databindings were working property.
It seems like if You are repeating rendering only (and this is what repeatControls set to false do) the decoding phase of jsf lifecycle goes foobar.
Without your XSP markup, it's difficult to be absolutely definitive but it appears that you're app code is creating and persisting the datasources and components per row during page load - therefore increasing the overall size and complexity of the component tree also. You should alternatively try an approach that will lazy-load the datasource only when requested by the end-user (eg: edit / reply).
Refer to the XPages Extension Library demo application (XPagesExt.nsf) for examples that use such a dynamic approach. In particular, look at Core_InPlaceForm.xsp which demonstrates using the xe:inPlaceForm control within a xp:repeat. And also see Domino_ForumView.xsp which demonstrates using the xe:forumView and xe:forumPost controls to manage and visualize a hierarchical thread. Also consider the concurrency mode that best suits your requirements when it actually comes to saving any given post or comment (fail, createConflict, force, exception) and document locking for high contention situations. The above-mentioned controls all provide the highest level of dynamic control and datasource creation and destruction.
Please feel free to send me on a worked example database, where I can understand your exact use case - DM me or email me.

Issue using executeQueryLocally without server metadata

I'm not using EF, so have followed the NoDb sample to successfully load data from my WebApi without using the server side metadata. After the initial load, I was hoping to use the local data cache in the EntityManager while the user interacts with the page. The problem is when I call executeQueryLocally, the cached data set is empty. I stepped through the code to see why the data wasn't being saved to the cache, and there were two issues:
in _getEntityType, metadataStore.isEmpty() was returning true.
in _getEntityType, metadataStore._getEntityTypeNameForResourceName was returning nothing
To get around the this, I added calls in my code to metadataStore.addDataService and metadataStore._setEntityTypeForResourceName. After adding these, the cache was saved properly and executeQueryLocally worked. I'm assuming this was not the intended way to get this to work... Is there something else I am doing wrong? Or is this a bug that can be fixed?
Sorry for taking so long getting back to this one.
We just made the metadataStore.setEntityTypeForResourceName public in breeze v.1.1.3. ( we renamed the method to remove the first '_".
Otherwise, you did exactly the right thing. Good catch.

Resources