This is related to the modifying the deviceready line drupalgap_goto('offline') to drupalgap_goto('') for offline mode.

On install, I am trying to cache entities. I created a function that loads a list of Node Id's from a JSON view and then runs a loop. I tried node_load(nid), node_page_view_pageshow(nid) and drupalgap_goto('node/'+nid) but even though I can see it working in the console, when offline links with drupalgap_got('node/'+nid) loads a blank page.

Any Ideas Here?

CommentFileSizeAuthor
#3 tcw_cabo.js_.txt16 KBinfo@cgfix.com

Comments

tyler.frankenstein’s picture

Status: Active » Postponed (maintainer needs more info)

Please share your entire function that loads the nodes when the app starts. Particularly, I'm interested in what hook(s) you're using to accomplish this.

info@cgfix.com’s picture

/*
tcw_cabo_cache_all() run from tcw_cabo_cach_nodes() below
*/
function tcw_cabo_cach_nodes(){
//load all node id's
var path_to_view = 'drupalgap/views_datasource/drupalgap_content';
var node_ids = []
views_datasource_get_view_result(path_to_view, {
'success':function(data){
$.each(data.nodes, function(index, object){
node_ids.push( object.node.nid );
});
}
});
// loop through each nid
for( nid in node_ids ){
//load nodes into cache

//first attempt, runs - pages still not loading offline
/* node_load(nid, {
success: function(node) {
console.log("Node Loaded " + node.title);
console.log(node);
}
}); */

//second attempt - pages still not loading offline
/* drupalgap_goto('node/'+nid); */

//third attempt - - pages still not loading offline
node_page_view_pageshow(nid);

}
}
/*
tcw_cabo_cache_all() run on deviceready or deviceinstall
*/
function tcw_cabo_cache_all(){
tcw_cabo_events_pageshow(); //works
tcw_cabo_locations_pageshow(); //works
tcw_cabo_info_pageshow(); //works
tcw_cabo_cach_nodes(); //runs but pages don't load offline
tcw_cabo_cach_vocab(); //runs but pages don't load offline
tcw_cabo_cach_terms(); //runs but pages don't load offline
}

info@cgfix.com’s picture

StatusFileSize
new16 KB

attached is the entire module I wrote if you want to see it all together

info@cgfix.com’s picture

After studying the source code trail from node_load vs drupalgap_got(), I am starting to wonder if the problem maybe that even though I have loaded all the nodes into cache, they are not associated with any page callbacks and so then calling drupalgap_got() later does not find the it in cache and trys to load it from server?

tyler.frankenstein’s picture

If you have caching enabled in settings.js, and you call node_load() (or any entity loader function, you don't need to call entity_load()), the system will automatically place that entity into local storage once it is retrieved from the server. Anytime afterwards, when node_load() is called (even while building a page), the system will pull that node out of local storage.

info@cgfix.com’s picture

scratch that, I see whats happening. There is a variable 'content' that is created and added to the node object in cache probably when the page is rendered. I think I just need to know what function does that so I can cache it.

tyler.frankenstein’s picture

Yes, the entity_services_request_pre_postprocess_alter() function in the SDK handles rendering the content when the entity comes back from the server, and attaches it to the content variable: https://github.com/signalpoint/DrupalGap/blob/7.x-1.x/src/modules/entity...

Then entity_load() handles saving the entity to local storage: https://github.com/easystreet3/jDrupal/blob/7.x-1.x/src/entity.js#L55

At one time I know the entity was saved to local storage before the content was rendered, so when loading it from local storage, it would appear to have empty content. I thought I fixed that though, so it would be saved to local storage after the content was rendered.

Will you please confirm if, or if not, the entity's content is attached to it when loading an entity from local storage?

info@cgfix.com’s picture

I think I solved it. This seems to work.

node_load(nid, {
success: function(node) {
console.log("Node Loaded " + node.title);
drupalgap_entity_render_content('node', node);
// console.log(node);
}
});

info@cgfix.com’s picture

I am using version 7.x-1.8. In this version, entity_load does not render the content.

tyler.frankenstein’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)