Handle priority changes
From: http://stackoverflow.com/questions/16159576/im-convinced-that-ref-auth-is-bugged
"If you want to see the bugs in AngularFire, change priority of items. Then you'll see AngularFire unable to correctly move the items in the collection"
Also http://stackoverflow.com/questions/18008457/angularfire-priority-changes-not-working-inserting-duplicate-items-instead
Additionally, primitives (e.g. if the value is a string) get converted to objects/arrays if a priority exists on the records. See this fiddle: http://jsfiddle.net/katowulf/dFsqC/
Here's a test case that should work when priorities function: http://jsfiddle.net/katowulf/vVk6E/6/, Ideally it would work with strings as values too?
Should be fixed by https://github.com/firebase/angularFire/commit/d368161361abeeff7015d4274384d88211df2fd9 (for angularFireCollection at-least?)
Hmm. Using the current angularFire.js on gh-pages, and this fiddle, it's not sorting records by priority inside ng-repeat.
The canonical angularFire.js is in the master branch, the one on gh-pages is there only because the example on angularjs.org is linking to it (and when https://github.com/angular/angularjs.org/pull/64 is merged we can remove it).
I've updated to the latest build in master, still seeing oddness when priorities change: http://jsfiddle.net/katowulf/vVk6E/7/
It does work if I use ng-repeat="widget in widgets | orderBy:widget.priority", is that the intended solution? Shouldn't the records in angularFireCollection exactly match the Firebase order? See the fiddle, which shows the raw data in sorted order, but the ng-repeat results are inconsistent.
I think it's because priorities are getting set to strings when modified via the text box, but priorities initially (and on reset()) are numbers.
I've fixed the integer/string issue (silly dev, code is for experts!). But it's still a bit wonky, and occasionally tossing out duplicates: http://jsfiddle.net/katowulf/vVk6E/
This version seems to work for me with the latest angularfire: http://jsfiddle.net/vVk6E/12/. Please re-open if you still see the issue!
Hmm. I'm still seeing issues with the fiddle. Changing the priority of "a" to 7 works, but changing it back to 1 doesn't. Also, orderBy:priority will only work for numerical priorities. Maybe the angularFire lib should include a custom orderByPriority filter?
Good call! Re-opening.
Ok, this should be fixed in the "v2" branch, working example here: http://jsfiddle.net/6ahZj/1/
I'll leave this ticket open and close it when we've merged the 'v2' branch into master.
Here's a working example of drag and drop sort using the new orderByPriority filter with Angular 1.2.0 and angularFire 0.5-rc2
http://plnkr.co/edit/Hq9ABcUYAJhXNWD3jyGs?p=preview
v2 has been merged into master and the example linked by @katowulf appears to work as expected!
Hi guys, actually latest example form @katowulf doesn't really work. It looks like it does, but there is an error in JavaScript console and priority-setting callback (sortableOptions.stop) never gets called.
Uncaught TypeError: Object #<Object> has no method 'splice' @ sortable.js:83
Is just the example implementation broken or is the issue somewhere in the library?
Isn't the problem that we are not sorting an array (which is typical for JavaScript), but rather an object (which is more convenient in Firebase world)?
It's probably this bug in the RC, fixed in the official release? https://github.com/firebase/angularFire/issues/172
If official release means http://cdn.firebase.com/libs/angularfire/0.5.0/angularfire.js then demo still doesn't work due to the same error. Edit: and the same with latest angularfire.min.js from master.
I just tried both the plunkr and the fiddles and they work without issue.
Please start a new issue and include os/browser versions and a working code repro to help us troubleshoot.
I don't think it's a browser issue. I tried your plnkr on Mac OS X 10.9.1 in Chrome stable, Chrome Canary, Firefox and Safari with exact same results. Even tried to use stable version instead of rc1 which is in the source there, but without luck.
Drag&Drop seems to work, but it is not reflected in Firebase (priority is not changed).
Reproducing: load this demo, open it's firebase forge to see changes and try to drag and drop an item.
Expected result: no JavaScript error and item priority updated. It should be visible in Forge that items changed order.
Result: Firebase doesn't get updated and error in JavaScript console is raised: Uncaught TypeError: Object #<Object> has no method 'splice'. (Seems like closely related to #172)