Skip to content

Commit

Permalink
Filter election periods by time
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiamersmann committed Dec 24, 2020
1 parent 2940749 commit e8c1501
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/components/Root.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<data-button-group
:options=requestTypes
@clicked="setRequestType" />
<data-button-group
:options=timeOptions
@clicked="setTimeFilter" />
</nav>
<main :class=classes>
<div class="election-period-list">
Expand Down Expand Up @@ -65,6 +68,11 @@ const DEFAULT = {
{ label: 'Major', value: 'major', active: false },
{ label: 'Written', value: 'written', active: false },
],
timeOptions: [
{ label: 'All', value: 'all', active: true },
{ label: 'Current', value: 'current', active: false },
{ label: 'Previous', value: 'previous', active: false },
],
};
export default {
Expand All @@ -86,7 +94,9 @@ export default {
},
groups() {
const data = this.merged
.filter((d) => d.requests.get(this.requestType).length > 0);
.filter((d) => (
this.timeFilter === 'all' || d.hasEnded === (this.timeFilter === 'previous'))
&& d.requests.get(this.requestType).length > 0);
let sortFunc;
switch (this.sortBy) {
Expand Down Expand Up @@ -120,8 +130,10 @@ export default {
popup: null,
sortOptions: DEFAULT.sortOptions,
requestTypes: DEFAULT.requestTypes,
timeOptions: DEFAULT.timeOptions,
sortBy: 'alphabetically',
requestType: 'all',
timeFilter: 'all',
};
},
async created() {
Expand Down Expand Up @@ -162,6 +174,15 @@ export default {
}) => rest),
};
});
this.timeOptions = this.timeOptions.map((d) => {
const e = d;
const count = (e.value === 'all'
? this.merged.length
: this.merged.filter((f) => f.hasEnded === (e.value === 'previous')).length);
e.label = `${e.label} (${count})`;
return e;
});
},
methods: {
async fetchData() {
Expand Down Expand Up @@ -201,6 +222,9 @@ export default {
setRequestType(value) {
this.requestType = value;
},
setTimeFilter(value) {
this.timeFilter = value;
},
},
};
</script>
Expand Down

0 comments on commit e8c1501

Please sign in to comment.