Closed (fixed)
Project:
Backbone
Version:
7.x-1.x-dev
Component:
Misc. Code
Priority:
Major
Category:
Task
Assigned:
Reporter:
Created:
1 Mar 2012 at 16:55 UTC
Updated:
7 Nov 2012 at 07:00 UTC
Jump to comment: Most recent file
Develop initial prototype of RestWS/Views Datasource flavor.
| Comment | File | Size | Author |
|---|---|---|---|
| #23 | backbone_restws_example-1463024-23.patch | 10.4 KB | frega |
| #23 | interdiff.txt | 2.76 KB | frega |
| #17 | backbone_restws_example-1463024-17.patch | 9.01 KB | frega |
| #16 | backbone_restws_example-1463024-16.patch | 9.21 KB | frega |
| #15 | backbone_restws_example-1463024-15.patch | 8 KB | frega |
Comments
Comment #1
ethanw commentedDevelopment on this has begun, involving a refactoring of the drupalbackbone.js file into one file containing classes common to both RestWS and Services flavors and another with objects that are backend specific.
Due to a difference in HTTP verb implementation in the REST approach of Backbone vs. RestWS, however, further work on this task will require the resolution of #1472634: HTTP PUT / POST Reversed for CRUD CREATE / UPDATE Operations.
Comment #2
ethanw commentedI'm marking this as postponed till the PUT/POST issue for RESTws is resolved.
Comment #3
ethanw commentedRestWS addresses the HTTP verb issue, this can now be taken back up.
Comment #4
ethanw commentedBasic RestWS support has been added to dev. This involved a significant refactor. All backend-specific code is now provided via additional models, with `hook_backbone_backends` used to indicate a module provides a backend.
A few other notes:
1. The RestWS-specific JS is much more minimal than the Services version, owing mainly to RestWS being designed to be much more similar to canonical REST implementations.
2. Also added is a backbone_restws_examples module. which has the examples from the DrupalCon Munich presentation adapted for RestWS.
3. I finally figured out why some properties were not being inherited multiple levels in the hierarchy, basically non-Backbone-standard properties that are not methods can't use the standard extend({prop:va}) syntax. See [this post to the Backbone.js Google group](https://groups.google.com/forum/?fromgroups=#!topic/backbonejs/463jkNR5dW4) for (hopefully) discussion on this.
4. You've got to specify RestWS in the Backbone admin page for the examples to work.
Comment #5
ethanw commentedComment #6
floptikal commentedFails when site in subfolder. Patch adds Drupal.settings.basePath.substr(1) to rooturl
Comment #7
frega commentedI ran into a similar issue like @floptikal. Didn't see this issue until right now ... so some of this might now apply.
- I think it might be better to have custom "url"-method in the Drupal.Backbone.Models.Entity that to adjust the urlRoot-Property.
- backbone_restws_examples.info - lacked a dependency on backbone_restws and unnecessarily declared a .module file
- Specifying RestWS in the Backbone admin page did not work for me instead I fixed the drupal_add_library-calls to use backbone_restws instead of backbone - but i might be missing something here, because i could see the corresponding drupal-variable 'backbone_backend_module' being used at all.
Please find a patch attached.
Comment #8
ethanw commented+1 for the custom URL idea, very flexible. Could be used on XS or non-Drupal-root-based Backbone apps as well. Nice idea.
Comment #9
frega commented@ethanw - can you paste / commit the view that's referenced in the backbone_restws_examples?
Comment #10
ethanw commentedNo view should be used. Should just be using restws query params.
Comment #11
frega commentedsorry, my bad - based on irc i was assuming that there was a views-view for the collections, but i see it's restws' entity listing (which are working in my installation :)
Comment #12
frega commentedok, i found out why the collections weren't working; newest restws-7.x-2.0-alpha2 is required (alpha1 doesn't support the .{FORMAT} notation afaics).
Comment #13
frega commentedI've got everything working now, looks lovely. Would you like me to write a patch, that does a little sanity checking, i.e.
1) make sure the version of restws is uptodate
2) find some nid instead of hard-coding nid 2 and warn if there aren't any nodes at all?
3) check that there is a node bundle "page" and that there are nodes of the bundle instantiated?
Comment #14
ethanw commentedAbsolutely. The current examples were straight from the presentation and do now edge case checking, etc.
Comment #15
frega commentedUpdated the restws example. Fixed drupal_add_library-calls. Removed hard-coded nids/node types. Added a few explanatory messages. A few whitespace issues.
Will file a separate patch for the hook_requirements-implementation for backbone_restws.module.
Comment #16
frega commentedSorry had to reroll, because I forgot to include url()-patch for modules/backbone_restws/js/drupalbackbone-restws.js.
Comment #17
frega commentedRerolled patch to match changes in commit a92078e. Also change dependency[] in backbone_restws_examples.info from restws to backbone_restws. This patch is kinda required for the backbone_restws_examples to work, so i'd be great if this could get reviewed quickly :)
Comment #18
frega commentedcan we commit this? it'd be nice to have working examples in the -dev branch :)
ps. if #1791186: backbone_example include backbone_services' drupalbackbone-services library gets committed the examples for both backbends should be working again ...
Comment #19
ethanw commentedThanks for the repeated pings, frega.
It looks like /backbone_restws_examples/node_event_bind isn't working with this patch, at least for me. It seems to not be filtering out the "read-only" attributes.
I found this was due to calling the initializer via __super__ when initially developing the RestWS piece, so perhaps that's what's happening here?
I'll be able to dig in more in a bit, but to start: are you seeing similar behavior?
Comment #20
frega commentedHi Ethan,
sorry, can't seem to reproduce this behaviour (Chrome 22.0.1229.79, and FF 15); can you reset your repo to the latest git/7.x-1.x, disable and uninstall all modules and then re-enable backbone_restws_examples with the patch above applied? I had some issues JS issues when both enabling backbone_services + backbone_restws.
Best, Fredrik
Comment #21
atlea commentedQuick review of the patch:
- collection_render is not using the node type as query, just plain fetch.
- settings should probably be passed to the behavior?
Here a patch for collection_render.js. Inline.. apologies for being so lazy. The changes to how settings is read should be made to the other behaviors as well.
Atle
Comment #22
atlea commented..and a note: RestWS seems to be failing when trying to update a node that contains an image. I have created an issue over at #1819594: PUT/update fails with 406 on entity/node that contains an image/file
Comment #23
frega commentedRerolled patch as per #21. Indeed prettier and better.
Note: because we don't wrap the instantiation of Backbone views/models/collections in a "once()" every Drupal.ajax-call will reinstantiate and run the behaviour again. This should probably be taken care of at some point :)
Comment #24
atlea commentedThe ajax could have changed the node, so loading and rendering it again might not be wrong.. one could check if the element is in the context to be refreshed or not..
e.g. wrap it in
Now, if i open up Console and type Drupal.attachBehaviors(); it should run (as document is the default context), but not if I type e.g. Drupal.attachBehaviors('.breadcrumb');
..but we must take care to not make this first example too complex!
Perhaps even shorten it down to:
Comment #25
frega commentedApplied patch from #23 in commit 7295703.
@atlea - I have set this issue to fixed (as the initial restws-version and the accompanying example work), and move the larger "architectural questions" you raise (interaction w/ Drupal.ajax/.behaviors, how to encapsulate "apps") to a separate issue, is that ok w/ you?
Comment #26
atlea commentedSure! On that note, I believe it is wrong to attach drupalbackbone.js to the page/using behaviors for library functions that don't interact with the page. But we can continue that discussion when you create a new issue. ;) - Atle