Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[idea] Make second parameter of /list an Observable, not just the inner values #389

Closed
dirkpostma opened this issue Jul 26, 2016 · 4 comments · Fixed by #826
Closed

[idea] Make second parameter of /list an Observable, not just the inner values #389

dirkpostma opened this issue Jul 26, 2016 · 4 comments · Fixed by #826

Comments

@dirkpostma
Copy link

dirkpostma commented Jul 26, 2016

I have a list of employees. Every employee has a name and and active property, e.g.

{
   name: "Dirk Postma",
   active: true
}

In my view I'd like to be able to filter by active flag, for example:

this.filteredItems = af.database.list('employees', {
    query: {
        orderByChild: 'active',
        equalTo: this.querySubject
    }
});

toggleActiveFilter() {
   this.showActive = !this.showActive;
   this.querySubject.next(this.showActive);
}

This works, great stuff!

Now one step further: I'd like to be able to show either active employees or ALL employees (both active and inactive). I would like to have something like this:

this.filteredItems = af.database.list('employees',  this.querySubject });

toggleActiveFilter() {
    this.showActive = !this.showActive;

    if (this.showActive) {
        // Show active employees only
        this.querySubject.next({
            query: {
                orderByChild: 'active',
                equalTo: true
            }
        });
    } else {
        // show all employees
        this.querySubject.next(null);
    }
}

Basically: make the second parameter itself an Observable in stead of just the inner values of e.g. equalTo.

Is this an idea?

@agu-z
Copy link

agu-z commented Aug 4, 2016

I'm not sure if exactly that is what we need but I think we should be able to accomplish it.

@joyceview
Copy link

@dirkpostma Is that mean that way we can have filter on top of another filter? If so, that's really a good idea.

According to my understanding, right now there is no way we can do filter on top of filter, right? Like in your example, we can only get employees active, but can not get active employee with certain last name. Am I right?

@katowulf
Copy link
Contributor

katowulf commented Aug 25, 2016

It's not going to be possible to use multiple filter criteria since this isn't supported by the SDK.

It seems like it would be a nice addition to make this.query observable instead of this.querySubject.

For the original problem, could we not take advantage of the ordering criteria and simply using startAt, changing the setup as follows?

this.filteredItems = af.database.list('employees', {
    query: {
        orderByChild: 'active',
        startAt: this.querySubject
    }
});

toggleShowAll() {
   this.showAll = !this.showAll;
   // to include inactives, we "startAt" false
   // to only include actives, we "startAt" true
   this.querySubject.next(this.showAll? false : true);
}

@davideast
Copy link
Member

Active conversation in #770.

cartant added a commit to cartant/angularfire that referenced this issue Jan 15, 2017
Adds an auditTime(0) operator to the composed query observable so that
changes made to multiple subjects are emitted as a single query (emitted
in the event loop) rather than as separate queries (emitted
immediately).

Closes angular#389 and angular#770.
davideast pushed a commit that referenced this issue Feb 9, 2017
Adds an auditTime(0) operator to the composed query observable so that
changes made to multiple subjects are emitted as a single query (emitted
in the event loop) rather than as separate queries (emitted
immediately).

Closes #389 and #770.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants