Created
October 28, 2019 11:49
-
-
Save brunoocasali/bfbc84c59465e34ff53981957a089e8a to your computer and use it in GitHub Desktop.
admhql code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@glimmer/component'; | |
import { tracked } from '@glimmer/tracking'; | |
import { restartableTask } from 'ember-concurrency-decorators'; | |
import { inject as service } from '@ember/service'; | |
import query from 'uaw/gql/queries/allOpinionsSearch'; | |
export default class DataLoaderComponent extends Component { | |
@service apollo; | |
@service filters; | |
@tracked results = []; | |
constructor() { | |
super(...arguments); | |
this.filters.on('filtersDidChange', () => this.fetchData.perform()); | |
this.fetchData.perform(); | |
} | |
@restartableTask | |
*fetchData() { | |
let variables = { filter: this.filters.parsedFilters }; | |
this.results = yield this.apollo | |
.query({ query, variables }, 'allOpinionsSearch') | |
.catch(error => console.error(error)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Controller from "@ember/controller"; | |
import QueryParams from "ember-parachute"; | |
import { or } from "@ember/object/computed"; | |
import { tracked } from "@glimmer/tracking"; | |
export const AppQueryParams = new QueryParams({ | |
companyActive: { | |
as: "active", | |
defaultValue: true, | |
refresh: true | |
}, | |
complainReason: { | |
as: "reason", | |
defaultValue: "all", | |
refresh: true | |
} | |
}); | |
export default class OpinionsController extends Controller.extend(AppQueryParams.Mixin) { | |
@or("queryParamsState.{companyActive,complainReason}.changed") queryParamsChanged; | |
@tracked companyActive = true; | |
@tracked complainReason = "all"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The service who trigger events all over the project about filter changing | |
import Service from '@ember/service'; | |
import Evented from '@ember/object/evented'; | |
import { action } from '@ember/object'; | |
import { tracked } from '@glimmer/tracking'; | |
export default class FiltersService extends Service.extend(Evented) { | |
@tracked companyActive; | |
@tracked complainReason; | |
@action | |
propagate() { | |
this.trigger('filtersDidChange'); | |
} | |
setupByURL(queryParams) { | |
for (let [key, value] of Object.entries(queryParams)) { | |
this[key] = value; | |
} | |
} | |
get parsedFilters() { | |
let data = { | |
companyActive: JSON.parse(this.companyActive), | |
complainReason: this.complainReason.toUpperCase(), | |
} | |
return data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment