From b5a7162683922405d826a777e2d149a9fc2bd86c Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 11 Jan 2018 12:19:51 +0000 Subject: [PATCH 1/3] adding labels filter --- public/index.html | 4 ++++ src/components/contractors/Contractors.js | 3 ++- src/components/enquiry/EnquiryButton.js | 2 +- src/index.js | 2 ++ src/utils.js | 9 +++++++-- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/public/index.html b/public/index.html index 148f956e..f532289f 100644 --- a/public/index.html +++ b/public/index.html @@ -37,6 +37,10 @@ router_mode: 'history', api_root: api_root, mode: 'grid', + // contractor_filter: { + // labels: ['foo', 'bar'], + // label_exclude: ['whatever'] + // }, event_callback: function (name, v) { console.log(name, v) } diff --git a/src/components/contractors/Contractors.js b/src/components/contractors/Contractors.js index c4bd5500..628e8090 100644 --- a/src/components/contractors/Contractors.js +++ b/src/components/contractors/Contractors.js @@ -49,7 +49,8 @@ class Contractors extends Component { this.setState({selected_subject}) const sub_id = selected_subject && selected_subject.id - const contractors = await this.props.root.requests.get('contractors', {subject: sub_id || null}) + const args = Object.assign({}, this.props.config.contractor_filter, {subject: sub_id || null}) + const contractors = await this.props.root.requests.get('contractors', args) this.props.config.event_callback('updated_contractors', contractors) this.setState({ contractors, diff --git a/src/components/enquiry/EnquiryButton.js b/src/components/enquiry/EnquiryButton.js index 11110519..cd24e756 100644 --- a/src/components/enquiry/EnquiryButton.js +++ b/src/components/enquiry/EnquiryButton.js @@ -4,7 +4,7 @@ import EnquiryModal from './EnquiryModal' const EnquiryButton = ({root, config}) => (
-
+
{root.get_text('enquiry_button')} diff --git a/src/index.js b/src/index.js index 1e205c93..81bc486a 100644 --- a/src/index.js +++ b/src/index.js @@ -97,6 +97,8 @@ window.socket = function (public_key, config) { config.element = '#socket' } + config.contractor_filter = config.contractor_filter || {} + if (config.subject_filter === undefined) { config.subject_filter = true } diff --git a/src/utils.js b/src/utils.js index 58533d40..953c74c5 100644 --- a/src/utils.js +++ b/src/utils.js @@ -128,9 +128,14 @@ export const requests = { get: async (app, path, args) => { if (args) { const arg_list = [] + const add_arg = (n, v) => arg_list.push(encodeURIComponent(n) + '=' + encodeURIComponent(v)) for (let [name, value] of Object.entries(args)) { - if (value !== null) { - arg_list.push(encodeURIComponent(name) + '=' + encodeURIComponent(value)) + if (Array.isArray(value)) { + for (let value_ of value) { + add_arg(name, value_) + } + } else if (value !== null && value !== undefined) { + add_arg(name, value) } } if (arg_list.length > 0) { From 2a604bbca5333c2d04664d65f859c640ac260035 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 11 Jan 2018 13:03:30 +0000 Subject: [PATCH 2/3] tweaks --- public/index.html | 10 ++++------ src/index.js | 10 +++++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/public/index.html b/public/index.html index f532289f..25907bcf 100644 --- a/public/index.html +++ b/public/index.html @@ -30,17 +30,15 @@