angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Handle priority changes

Open anantn opened this issue 13 years ago • 26 comments

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"

anantn avatar Apr 23 '13 16:04 anantn

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/

katowulf avatar Aug 07 '13 16:08 katowulf

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?

katowulf avatar Aug 07 '13 17:08 katowulf

Should be fixed by https://github.com/firebase/angularFire/commit/d368161361abeeff7015d4274384d88211df2fd9 (for angularFireCollection at-least?)

anantn avatar Aug 07 '13 17:08 anantn

Hmm. Using the current angularFire.js on gh-pages, and this fiddle, it's not sorting records by priority inside ng-repeat.

katowulf avatar Aug 07 '13 17:08 katowulf

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).

anantn avatar Aug 07 '13 17:08 anantn

I've updated to the latest build in master, still seeing oddness when priorities change: http://jsfiddle.net/katowulf/vVk6E/7/

katowulf avatar Aug 07 '13 17:08 katowulf

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.

katowulf avatar Aug 07 '13 18:08 katowulf

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.

anantn avatar Aug 07 '13 18:08 anantn

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/

katowulf avatar Aug 07 '13 18:08 katowulf

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!

anantn avatar Aug 30 '13 18:08 anantn

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?

bennlich avatar Sep 25 '13 06:09 bennlich

Good call! Re-opening.

anantn avatar Oct 02 '13 23:10 anantn

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.

anantn avatar Nov 14 '13 01:11 anantn

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

katowulf avatar Nov 26 '13 16:11 katowulf

v2 has been merged into master and the example linked by @katowulf appears to work as expected!

anantn avatar Dec 12 '13 01:12 anantn

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)?

marekhrabe avatar Dec 26 '13 17:12 marekhrabe

It's probably this bug in the RC, fixed in the official release? https://github.com/firebase/angularFire/issues/172

katowulf avatar Dec 26 '13 17:12 katowulf

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.

marekhrabe avatar Dec 26 '13 17:12 marekhrabe

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.

katowulf avatar Dec 26 '13 18:12 katowulf

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)

marekhrabe avatar Dec 26 '13 18:12 marekhrabe