Skip to content

Commit 88f5e93

Browse files
committed
make subject filter optional, add filter summary
1 parent 57b6787 commit 88f5e93

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

src/components/grid.vue

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<template>
22
<div class="tcs-grid">
3-
<div class="tcs-flex">
4-
<div class="subject-select"></div>
3+
<div v-if="$root.config.subject_filter">
54
<subject_select class="subject-select"></subject_select>
5+
<div class="tcs-summary">
6+
{{ description }}
7+
</div>
68
</div>
79
<div class="tcs-flex">
810
<div v-for="contractor in contractors" class="tcs-col">
@@ -23,8 +25,19 @@ export default {
2325
components: { subject_select },
2426
data () {
2527
// very weird but this works, while $root.contractors used directly in the template above sometimes gives
26-
// an array containing one empty object: [object{}]
28+
// an array containing one empty object: [object{}] and therefore fails
2729
return {contractors: this.$root.contractors}
30+
},
31+
computed: {
32+
description () {
33+
if (this.$root.selected_subject_id) {
34+
const msg_id_suffix = this.$root.contractors.length === 1 ? 'single' : 'plural'
35+
return this.$root.get_text('subject_filter_summary_' + msg_id_suffix, {
36+
count: this.$root.contractors.length,
37+
subject: this.$root.get_selected_subject().name,
38+
})
39+
}
40+
}
2841
}
2942
}
3043
</script>

src/main.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ const STRINGS = {
8787
grecaptcha_missing: 'This captcha is required',
8888
required: ' (Required)',
8989
subject_filter: 'Filter by subject',
90+
subject_filter_summary_single: '{subject}: showing 1 result',
91+
subject_filter_summary_plural: '{subject}: showing {count} results',
9092
}
9193

9294
const MODES = ['grid', 'enquiry', 'enquiry-modal']
@@ -138,6 +140,10 @@ module.exports = function (public_key, config) {
138140
config.element = '#socket'
139141
}
140142

143+
if (config.subject_filter === undefined) {
144+
config.subject_filter = true
145+
}
146+
141147
if (document.querySelector(config.element) === null) {
142148
config.console.error(`SOCKET: page element "${config.element}" does not exist, unable to start socket view.`)
143149
return

src/styles/grid.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@
66

77
.subject-select {
88
width: 50%;
9+
margin: 0 0 0 auto;
10+
padding: 0 2px;
11+
box-sizing: border-box;
12+
}
13+
14+
.tcs-summary {
15+
padding: 5px 2px;
16+
text-align: right;
17+
font-size: 13px;
18+
color: #666;
19+
min-height: 18px;
20+
}
21+
22+
@media(max-width: 600px) {
23+
.subject-select {
24+
width: 100%;
25+
}
926
}
1027

1128
.tcs-flex {
@@ -51,6 +68,9 @@
5168
}
5269

5370
@media(max-width: 400px) {
71+
.subject-select {
72+
width: 100%;
73+
}
5474
.tcs-grid {
5575
padding: 10px 2px;
5676
}

test/unit/specs/grid.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('grid.vue', () => {
1515
data: {
1616
contractors: [{name: 'Fred Bloggs', link: '123-fred-bloggs', photo: 'http://path/to/img.jpg'}],
1717
subjects: [],
18+
config: {subject_filter: true},
1819
},
1920
methods: {
2021
get_contractor_list: () => null,

0 commit comments

Comments
 (0)