-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from paviliondev/abstract_filters
Abstract connection filters to make them re-usable
- Loading branch information
Showing
25 changed files
with
274 additions
and
198 deletions.
There are no files selected for viewing
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
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
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
7 changes: 0 additions & 7 deletions
7
app/serializers/discourse_events/connection_filter_serializer.rb
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
module DiscourseEvents | ||
class FilterSerializer < ApplicationSerializer | ||
attributes :id, :query_column, :query_operator, :query_value | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { notEmpty, readOnly } from "@ember/object/computed"; | |
import { service } from "@ember/service"; | ||
import discourseComputed from "discourse-common/utils/decorators"; | ||
import Connection from "../models/connection"; | ||
import EventsConnectionFilters from "./modal/events-connection-filters"; | ||
import EventsFilters from "./modal/events-filters"; | ||
|
||
function filtersMatch(filters1, filters2) { | ||
if ((filters1 && !filters2) || (!filters1 && filters2)) { | ||
|
@@ -21,7 +21,9 @@ function filtersMatch(filters1, filters2) { | |
return filters1.every((f1) => | ||
filters2.some((f2) => { | ||
return ( | ||
f2.query_column === f1.query_column && f2.query_value === f1.query_value | ||
f2.query_column === f1.query_column && | ||
f2.query_operator === f2.query_operator && | ||
f2.query_value === f1.query_value | ||
); | ||
}) | ||
); | ||
|
@@ -57,6 +59,7 @@ export default Component.extend({ | |
"connection.to_time", | ||
"connection.filters.[]", | ||
"[email protected]_column", | ||
"[email protected]_operator", | ||
"[email protected]_value" | ||
) | ||
connectionChanged( | ||
|
@@ -130,10 +133,8 @@ export default Component.extend({ | |
}, | ||
|
||
openFilters() { | ||
this.modal.show(EventsConnectionFilters, { | ||
model: { | ||
connection: this.get("connection"), | ||
}, | ||
this.modal.show(EventsFilters, { | ||
model: this.get("connection"), | ||
}); | ||
}, | ||
|
||
|
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
49 changes: 0 additions & 49 deletions
49
assets/javascripts/discourse/components/modal/events-connection-filters.hbs
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
assets/javascripts/discourse/components/modal/events-connection-filters.js
This file was deleted.
Oops, something went wrong.
64 changes: 64 additions & 0 deletions
64
assets/javascripts/discourse/components/modal/events-filters.hbs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<DModal | ||
class="events-filters-modal" | ||
@title={{i18n "admin.events.filters.title"}} | ||
> | ||
<:body> | ||
{{#if hasFilters}} | ||
<table class="filters"> | ||
<thead> | ||
<th>{{i18n "admin.events.filter.query_column.label"}}</th> | ||
<th>{{i18n "admin.events.filter.query_operator.label"}}</th> | ||
<th>{{i18n "admin.events.filter.query_value.label"}}</th> | ||
<th></th> | ||
</thead> | ||
<tbody> | ||
{{#each model.filters as |filter|}} | ||
<tr class="filter"> | ||
<td> | ||
<ComboBox | ||
@content={{queryColumns}} | ||
@value={{filter.query_column}} | ||
@onChange={{action (mut filter.query_column)}} | ||
class="filter-column" | ||
/> | ||
</td> | ||
<td> | ||
<ComboBox | ||
@content={{queryOperators}} | ||
@value={{filter.query_operator}} | ||
@onChange={{action (mut filter.query_operator)}} | ||
class="filter-operator" | ||
/> | ||
</td> | ||
<td> | ||
<Input @value={{filter.query_value}} class="filter-value" /> | ||
</td> | ||
<td> | ||
<DButton | ||
@action={{action "removeFilter" filter}} | ||
@icon="times" | ||
@title="admin.events.filter.remove.title" | ||
/> | ||
</td> | ||
</tr> | ||
{{/each}} | ||
</tbody> | ||
</table> | ||
{{/if}} | ||
<DButton | ||
@action={{action "addFilter"}} | ||
@icon="plus" | ||
@class="add-filter" | ||
@label="admin.events.filters.add.label" | ||
@title="admin.events.filters.add.title" | ||
/> | ||
</:body> | ||
<:footer> | ||
<DButton | ||
@class="btn-primary" | ||
@action={{@closeModal}} | ||
@label="admin.events.filters.done.label" | ||
@title="admin.events.filters.done.title" | ||
/> | ||
</:footer> | ||
</DModal> |
52 changes: 52 additions & 0 deletions
52
assets/javascripts/discourse/components/modal/events-filters.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { A } from "@ember/array"; | ||
import Component from "@ember/component"; | ||
import { notEmpty } from "@ember/object/computed"; | ||
import discourseComputed from "discourse-common/utils/decorators"; | ||
import Filter from "../../models/filter"; | ||
|
||
const QUERY_COLUMNS = [ | ||
{ | ||
name: "Event Name", | ||
id: "name", | ||
}, | ||
]; | ||
|
||
const QUERY_OPERATORS = [ | ||
{ | ||
name: "Like", | ||
id: "like", | ||
}, | ||
]; | ||
|
||
export default Component.extend({ | ||
hasFilters: notEmpty("model.filters"), | ||
|
||
@discourseComputed | ||
queryColumns() { | ||
return QUERY_COLUMNS; | ||
}, | ||
|
||
@discourseComputed | ||
queryOperators() { | ||
return QUERY_OPERATORS; | ||
}, | ||
|
||
didInsertElement() { | ||
this._super(...arguments); | ||
|
||
if (!this.model.filters) { | ||
this.model.set("filters", A()); | ||
} | ||
}, | ||
|
||
actions: { | ||
addFilter() { | ||
const filter = Filter.create({ id: "new" }); | ||
this.model.get("filters").pushObject(filter); | ||
}, | ||
|
||
removeFilter(filter) { | ||
this.model.get("filters").removeObject(filter); | ||
}, | ||
}, | ||
}); |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import EmberObject from "@ember/object"; | ||
|
||
const Filter = EmberObject.extend(); | ||
|
||
export default Filter; |
Oops, something went wrong.