Merge lp:~marcustomlinson/unity-js-scopes/filters into lp:unity-js-scopes

Proposed by Marcus Tomlinson on 2016-05-12
Status: Work in progress
Proposed branch: lp:~marcustomlinson/unity-js-scopes/filters
Merge into: lp:unity-js-scopes
Diff against target: 832 lines (+725/-0)
10 files modified
src/bindings/src/addon.cc (+63/-0)
src/bindings/src/filter-group.cc (+39/-0)
src/bindings/src/filter-group.h (+40/-0)
src/bindings/src/range-input-filter.cc (+180/-0)
src/bindings/src/range-input-filter.h (+65/-0)
src/bindings/src/search-reply.cc (+10/-0)
src/bindings/src/value-slider-filter.cc (+131/-0)
src/bindings/src/value-slider-filter.h (+61/-0)
src/bindings/src/value-slider-labels.cc (+90/-0)
src/bindings/src/value-slider-labels.h (+46/-0)
To merge this branch: bzr merge lp:~marcustomlinson/unity-js-scopes/filters
Reviewer Review Type Date Requested Status
WebApps 2016-05-12 Pending
Review via email: mp+294489@code.launchpad.net

Commit message

Added filters support

To post a comment you must log in.

Unmerged revisions

150. By Marcus Tomlinson on 2016-05-12

ValueSliderFilter complete

149. By Marcus Tomlinson on 2016-05-12

RangeInputFilter complete

148. By Marcus Tomlinson on 2016-05-12

FilterGroup complete

147. By Marcus Tomlinson on 2016-05-12

ValueSliderLabels complete

146. By Marcus Tomlinson on 2016-05-12

Fix ValueSliderLabels

145. By Marcus Tomlinson on 2016-05-12

Fix ValueSliderFilter

144. By Marcus Tomlinson on 2016-05-12

Fix RangeInputFilter

143. By Marcus Tomlinson on 2016-05-12

Minimal classes to build

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/bindings/src/addon.cc'
2--- src/bindings/src/addon.cc 2016-02-25 13:48:52 +0000
3+++ src/bindings/src/addon.cc 2016-05-12 12:10:04 +0000
4@@ -37,11 +37,13 @@
5 #include "canned-query.h"
6 #include "categorised-result.h"
7 #include "department.h"
8+#include "filter-group.h"
9 #include "online-account-client.h"
10 #include "option-selector-filter.h"
11 #include "preview-query.h"
12 #include "preview-reply.h"
13 #include "preview-widget.h"
14+#include "range-input-filter.h"
15 #include "scope-base.h"
16 #include "scope.h"
17 #include "search-query.h"
18@@ -49,6 +51,8 @@
19 #include "search-metadata.h"
20 #include "registry.h"
21 #include "result.h"
22+#include "value-slider-filter.h"
23+#include "value-slider-labels.h"
24 #include "variant.h"
25
26 // TODO static
27@@ -456,6 +460,61 @@
28 .add_member("token_secret", &unity::scopes::OnlineAccountClient::ServiceStatus::token_secret)
29 .add_member("error", &unity::scopes::OnlineAccountClient::ServiceStatus::error);
30
31+ v8cpp::Class<FilterGroup> filter_group(isolate);
32+ filter_group
33+ .set_constructor<std::string, std::string>()
34+ .add_method("id", &FilterGroup::id)
35+ .add_method("label", &FilterGroup::label);
36+
37+ v8cpp::Class<RangeInputFilter> range_input_filter(isolate);
38+ range_input_filter
39+ .set_constructor<v8::FunctionCallbackInfo<v8::Value>>()
40+ .add_method("set_display_hints", &RangeInputFilter::set_display_hints)
41+ .add_method("display_hints", &RangeInputFilter::display_hints)
42+ .add_method("id", &RangeInputFilter::id)
43+ .add_method("filter_type", &RangeInputFilter::filter_type)
44+ .add_method("set_title", &RangeInputFilter::set_title)
45+ .add_method("title", &RangeInputFilter::title)
46+ .add_method("filter_group", &RangeInputFilter::filter_group)
47+ .add_method("start_prefix_label", &RangeInputFilter::start_prefix_label)
48+ .add_method("start_postfix_label", &RangeInputFilter::start_postfix_label)
49+ .add_method("end_prefix_label", &RangeInputFilter::end_prefix_label)
50+ .add_method("end_postfix_label", &RangeInputFilter::end_postfix_label)
51+ .add_method("central_label", &RangeInputFilter::central_label)
52+ .add_method("default_start_value", &RangeInputFilter::default_start_value)
53+ .add_method("default_end_value", &RangeInputFilter::default_end_value)
54+ .add_method("has_start_value", &RangeInputFilter::has_start_value)
55+ .add_method("has_end_value", &RangeInputFilter::has_end_value)
56+ .add_method("start_value", &RangeInputFilter::start_value)
57+ .add_method("end_value", &RangeInputFilter::end_value)
58+ .add_method("update_state", &RangeInputFilter::update_state);
59+
60+ v8cpp::Class<ValueSliderFilter> value_slider_filter(isolate);
61+ value_slider_filter
62+ .set_constructor<v8::FunctionCallbackInfo<v8::Value>>()
63+ .add_method("set_display_hints", &ValueSliderFilter::set_display_hints)
64+ .add_method("display_hints", &ValueSliderFilter::display_hints)
65+ .add_method("id", &ValueSliderFilter::id)
66+ .add_method("filter_type", &ValueSliderFilter::filter_type)
67+ .add_method("set_title", &ValueSliderFilter::set_title)
68+ .add_method("title", &ValueSliderFilter::title)
69+ .add_method("filter_group", &ValueSliderFilter::filter_group)
70+ .add_method("set_default_value", &ValueSliderFilter::set_default_value)
71+ .add_method("default_value", &ValueSliderFilter::default_value)
72+ .add_method("min", &ValueSliderFilter::min)
73+ .add_method("max", &ValueSliderFilter::max)
74+ .add_method("has_value", &ValueSliderFilter::has_value)
75+ .add_method("value", &ValueSliderFilter::value)
76+ .add_method("labels", &ValueSliderFilter::labels)
77+ .add_method("update_state", &ValueSliderFilter::update_state);
78+
79+ v8cpp::Class<ValueSliderLabels> value_slider_labels(isolate);
80+ value_slider_labels
81+ .set_constructor<v8::FunctionCallbackInfo<v8::Value>>()
82+ .add_method("min_label", &ValueSliderLabels::min_label)
83+ .add_method("max_label", &ValueSliderLabels::max_label)
84+ .add_method("extra_labels", &ValueSliderLabels::extra_labels);
85+
86 v8cpp::Module module(isolate);
87 module.add_class("js_scope", js_scope);
88 module.add_class("scope_base", scope_base);
89@@ -468,6 +527,7 @@
90 module.add_class("CategoryRenderer", category_renderer);
91 module.add_class("ColumnLayout", column_layout);
92 module.add_class("Department", department);
93+ module.add_class("FilterGroup", filter_group);
94 module.add_class("FilterOption", filter_option);
95 module.add_class("FilterState", filter_state);
96 module.add_class("Location", location);
97@@ -478,12 +538,15 @@
98 module.add_class("PreviewWidget", preview_widget);
99 module.add_class("PreviewQuery", preview_query);
100 module.add_class("PreviewReply", preview_reply);
101+ module.add_class("RangeInputFilter", range_input_filter);
102 module.add_class("Registry", registry);
103 module.add_class("Result", result);
104 module.add_class("ScopeMetadata", scope_metadata);
105 module.add_class("SearchReply", search_reply);
106 module.add_class("SearchQuery", search_query);
107 module.add_class("SearchMetadata", search_metadata);
108+ module.add_class("ValueSliderFilter", value_slider_filter);
109+ module.add_class("ValueSliderLabels", value_slider_labels);
110 module.add_class("Variant", variant);
111 module.add_class("VariantBase", variant_base);
112
113
114=== added file 'src/bindings/src/filter-group.cc'
115--- src/bindings/src/filter-group.cc 1970-01-01 00:00:00 +0000
116+++ src/bindings/src/filter-group.cc 2016-05-12 12:10:04 +0000
117@@ -0,0 +1,39 @@
118+/*
119+ * Copyright 2016 Canonical Ltd.
120+ *
121+ * This file is part of unity-js-scopes.
122+ *
123+ * unity-js-scopes is free software; you can redistribute it and/or modify
124+ * it under the terms of the GNU General Public License as published by
125+ * the Free Software Foundation; version 3.
126+ *
127+ * unity-js-scopes is distributed in the hope that it will be useful,
128+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
129+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
130+ * GNU General Public License for more details.
131+ *
132+ * You should have received a copy of the GNU General Public License
133+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
134+ */
135+
136+#include "filter-group.h"
137+
138+
139+FilterGroup::FilterGroup(std::string const& id, std::string const& label)
140+ : filter_group_(unity::scopes::FilterGroup::create(id, label)){
141+}
142+
143+std::string FilterGroup::id() const
144+{
145+ return filter_group_->id();
146+}
147+
148+std::string FilterGroup::label() const
149+{
150+ return filter_group_->label();
151+}
152+
153+unity::scopes::FilterGroup::SCPtr FilterGroup::get_filter_group() const
154+{
155+ return filter_group_;
156+}
157
158=== added file 'src/bindings/src/filter-group.h'
159--- src/bindings/src/filter-group.h 1970-01-01 00:00:00 +0000
160+++ src/bindings/src/filter-group.h 2016-05-12 12:10:04 +0000
161@@ -0,0 +1,40 @@
162+/*
163+ * Copyright 2016 Canonical Ltd.
164+ *
165+ * This file is part of unity-js-scopes.
166+ *
167+ * unity-js-scopes is free software; you can redistribute it and/or modify
168+ * it under the terms of the GNU General Public License as published by
169+ * the Free Software Foundation; version 3.
170+ *
171+ * unity-js-scopes is distributed in the hope that it will be useful,
172+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
173+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
174+ * GNU General Public License for more details.
175+ *
176+ * You should have received a copy of the GNU General Public License
177+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
178+ */
179+
180+#ifndef _UNITY_JS_FILTER_GROUP_H_
181+#define _UNITY_JS_FILTER_GROUP_H_
182+
183+#include <unity/scopes/FilterGroup.h>
184+
185+class FilterGroup
186+{
187+public:
188+ FilterGroup(std::string const& id, std::string const& label);
189+
190+ std::string id() const;
191+ std::string label() const;
192+
193+ unity::scopes::FilterGroup::SCPtr get_filter_group() const;
194+
195+private:
196+ unity::scopes::FilterGroup::SCPtr filter_group_;
197+};
198+
199+#endif // _UNITY_JS_FILTER_GROUP_H_
200+
201+
202
203=== added file 'src/bindings/src/range-input-filter.cc'
204--- src/bindings/src/range-input-filter.cc 1970-01-01 00:00:00 +0000
205+++ src/bindings/src/range-input-filter.cc 2016-05-12 12:10:04 +0000
206@@ -0,0 +1,180 @@
207+/*
208+ * Copyright 2016 Canonical Ltd.
209+ *
210+ * This file is part of unity-js-scopes.
211+ *
212+ * unity-js-scopes is free software; you can redistribute it and/or modify
213+ * it under the terms of the GNU General Public License as published by
214+ * the Free Software Foundation; version 3.
215+ *
216+ * unity-js-scopes is distributed in the hope that it will be useful,
217+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
218+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
219+ * GNU General Public License for more details.
220+ *
221+ * You should have received a copy of the GNU General Public License
222+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
223+ */
224+
225+#include "common.h"
226+#include "range-input-filter.h"
227+
228+RangeInputFilter::RangeInputFilter(v8::FunctionCallbackInfo<v8::Value> const& args)
229+{
230+ if (args.Length() == 6)
231+ {
232+ auto a = v8cpp::from_v8<std::string>(args.GetIsolate(), args[0]);
233+ auto b = v8cpp::from_v8<std::string>(args.GetIsolate(), args[1]);
234+ auto c = v8cpp::from_v8<std::string>(args.GetIsolate(), args[2]);
235+ auto d = v8cpp::from_v8<std::string>(args.GetIsolate(), args[3]);
236+ auto e = v8cpp::from_v8<std::string>(args.GetIsolate(), args[4]);
237+ auto f = v8cpp::from_v8<std::string>(args.GetIsolate(), args[5]);
238+
239+ filter_ = unity::scopes::RangeInputFilter::create(a, b, c, d, e, f);
240+ }
241+ else if (args.Length() == 7)
242+ {
243+ auto a = v8cpp::from_v8<std::string>(args.GetIsolate(), args[0]);
244+ auto b = v8cpp::from_v8<std::string>(args.GetIsolate(), args[1]);
245+ auto c = v8cpp::from_v8<std::string>(args.GetIsolate(), args[2]);
246+ auto d = v8cpp::from_v8<std::string>(args.GetIsolate(), args[3]);
247+ auto e = v8cpp::from_v8<std::string>(args.GetIsolate(), args[4]);
248+ auto f = v8cpp::from_v8<std::string>(args.GetIsolate(), args[5]);
249+ auto g = v8cpp::from_v8<std::shared_ptr<FilterGroup>>(args.GetIsolate(), args[6]);
250+
251+ filter_ = unity::scopes::RangeInputFilter::create(a, b, c, d, e, f, g->get_filter_group());
252+ filter_group_ = g;
253+ }
254+ else if (args.Length() == 8)
255+ {
256+ auto a = v8cpp::from_v8<std::string>(args.GetIsolate(), args[0]);
257+ auto b = unity::scopesjs::to_variant(args[1]);
258+ auto c = unity::scopesjs::to_variant(args[2]);
259+ auto d = v8cpp::from_v8<std::string>(args.GetIsolate(), args[3]);
260+ auto e = v8cpp::from_v8<std::string>(args.GetIsolate(), args[4]);
261+ auto f = v8cpp::from_v8<std::string>(args.GetIsolate(), args[5]);
262+ auto g = v8cpp::from_v8<std::string>(args.GetIsolate(), args[6]);
263+ auto h = v8cpp::from_v8<std::string>(args.GetIsolate(), args[7]);
264+
265+ filter_ = unity::scopes::RangeInputFilter::create(a, b, c, d, e, f, g, h);
266+ }
267+ else if (args.Length() == 9)
268+ {
269+ auto a = v8cpp::from_v8<std::string>(args.GetIsolate(), args[0]);
270+ auto b = unity::scopesjs::to_variant(args[1]);
271+ auto c = unity::scopesjs::to_variant(args[2]);
272+ auto d = v8cpp::from_v8<std::string>(args.GetIsolate(), args[3]);
273+ auto e = v8cpp::from_v8<std::string>(args.GetIsolate(), args[4]);
274+ auto f = v8cpp::from_v8<std::string>(args.GetIsolate(), args[5]);
275+ auto g = v8cpp::from_v8<std::string>(args.GetIsolate(), args[6]);
276+ auto h = v8cpp::from_v8<std::string>(args.GetIsolate(), args[7]);
277+ auto i = v8cpp::from_v8<std::shared_ptr<FilterGroup>>(args.GetIsolate(), args[8]);
278+
279+ filter_ = unity::scopes::RangeInputFilter::create(a, b, c, d, e, f, g, h, i->get_filter_group());
280+ filter_group_ = i;
281+ }
282+ else
283+ {
284+ throw std::runtime_error("Invalid number of arguments");
285+ }
286+}
287+
288+void RangeInputFilter::set_display_hints(int hints)
289+{
290+ filter_->set_display_hints(hints);
291+}
292+
293+int RangeInputFilter::display_hints() const
294+{
295+ return filter_->display_hints();
296+}
297+
298+std::string RangeInputFilter::id() const
299+{
300+ return filter_->id();
301+}
302+
303+std::string RangeInputFilter::filter_type() const
304+{
305+ return filter_->filter_type();
306+}
307+
308+void RangeInputFilter::set_title(std::string const& title)
309+{
310+ filter_->set_title(title);
311+}
312+
313+std::string RangeInputFilter::title() const
314+{
315+ return filter_->title();
316+}
317+
318+std::shared_ptr<FilterGroup> RangeInputFilter::filter_group() const
319+{
320+ return filter_group_;
321+}
322+
323+std::string RangeInputFilter::start_prefix_label() const
324+{
325+ return filter_->start_prefix_label();
326+}
327+
328+std::string RangeInputFilter::start_postfix_label() const
329+{
330+ return filter_->start_postfix_label();
331+}
332+
333+std::string RangeInputFilter::end_prefix_label() const
334+{
335+ return filter_->end_prefix_label();
336+}
337+
338+std::string RangeInputFilter::end_postfix_label() const
339+{
340+ return filter_->end_postfix_label();
341+}
342+
343+std::string RangeInputFilter::central_label() const
344+{
345+ return filter_->central_label();
346+}
347+
348+unity::scopes::Variant RangeInputFilter::default_start_value() const
349+{
350+ return filter_->default_start_value();
351+}
352+
353+unity::scopes::Variant RangeInputFilter::default_end_value() const
354+{
355+ return filter_->default_end_value();
356+}
357+
358+bool RangeInputFilter::has_start_value(unity::scopes::FilterState const& filter_state) const
359+{
360+ return filter_->has_start_value(filter_state);
361+}
362+
363+bool RangeInputFilter::has_end_value(unity::scopes::FilterState const& filter_state) const
364+{
365+ return filter_->has_end_value(filter_state);
366+}
367+
368+double RangeInputFilter::start_value(unity::scopes::FilterState const& filter_state) const
369+{
370+ return filter_->start_value(filter_state);
371+}
372+
373+double RangeInputFilter::end_value(unity::scopes::FilterState const& filter_state) const
374+{
375+ return filter_->end_value(filter_state);
376+}
377+
378+void RangeInputFilter::update_state(unity::scopes::FilterState& filter_state, unity::scopes::Variant const& start_value, unity::scopes::Variant const& end_value) const
379+{
380+ return filter_->update_state(filter_state, start_value, end_value);
381+}
382+
383+unity::scopes::RangeInputFilter::SPtr RangeInputFilter::get_filter()
384+{
385+ return filter_;
386+}
387
388=== added file 'src/bindings/src/range-input-filter.h'
389--- src/bindings/src/range-input-filter.h 1970-01-01 00:00:00 +0000
390+++ src/bindings/src/range-input-filter.h 2016-05-12 12:10:04 +0000
391@@ -0,0 +1,65 @@
392+/*
393+ * Copyright 2016 Canonical Ltd.
394+ *
395+ * This file is part of unity-js-scopes.
396+ *
397+ * unity-js-scopes is free software; you can redistribute it and/or modify
398+ * it under the terms of the GNU General Public License as published by
399+ * the Free Software Foundation; version 3.
400+ *
401+ * unity-js-scopes is distributed in the hope that it will be useful,
402+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
403+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
404+ * GNU General Public License for more details.
405+ *
406+ * You should have received a copy of the GNU General Public License
407+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
408+ */
409+
410+#ifndef _UNITY_JS_RANGE_INPUT_FILTER_H_
411+#define _UNITY_JS_RANGE_INPUT_FILTER_H_
412+
413+#include "filter-group.h"
414+
415+#include <unity/scopes/RangeInputFilter.h>
416+
417+#include <v8-cpp.h>
418+
419+class RangeInputFilter
420+{
421+public:
422+ RangeInputFilter(v8::FunctionCallbackInfo<v8::Value> const& args);
423+
424+ // FilterBase
425+ void set_display_hints(int hints);
426+ int display_hints() const;
427+ std::string id() const;
428+ std::string filter_type() const;
429+ void set_title(std::string const& title);
430+ std::string title() const;
431+ std::shared_ptr<FilterGroup> filter_group() const;
432+
433+ // RangeInputFilter
434+ std::string start_prefix_label() const;
435+ std::string start_postfix_label() const;
436+ std::string end_prefix_label() const;
437+ std::string end_postfix_label() const;
438+ std::string central_label() const;
439+ unity::scopes::Variant default_start_value() const;
440+ unity::scopes::Variant default_end_value() const;
441+ bool has_start_value(unity::scopes::FilterState const& filter_state) const;
442+ bool has_end_value(unity::scopes::FilterState const& filter_state) const;
443+ double start_value(unity::scopes::FilterState const& filter_state) const;
444+ double end_value(unity::scopes::FilterState const& filter_state) const;
445+ void update_state(unity::scopes::FilterState& filter_state, unity::scopes::Variant const& start_value, unity::scopes::Variant const& end_value) const;
446+
447+ unity::scopes::RangeInputFilter::SPtr get_filter();
448+
449+private:
450+ unity::scopes::RangeInputFilter::SPtr filter_;
451+ std::shared_ptr<FilterGroup> filter_group_;
452+};
453+
454+#endif // _UNITY_JS_RANGE_INPUT_FILTER_H_
455+
456+
457
458=== modified file 'src/bindings/src/search-reply.cc'
459--- src/bindings/src/search-reply.cc 2015-11-08 15:49:12 +0000
460+++ src/bindings/src/search-reply.cc 2016-05-12 12:10:04 +0000
461@@ -20,6 +20,8 @@
462
463 #include "categorised-result.h"
464 #include "option-selector-filter.h"
465+#include "range-input-filter.h"
466+#include "value-slider-filter.h"
467
468 #include <stdexcept>
469
470@@ -42,6 +44,14 @@
471 auto f = v8cpp::from_v8<std::shared_ptr<OptionSelectorFilter>>(isolate, fv);
472 filter_bases.push_back(f->get_filter());
473 } catch(...) { }
474+ try {
475+ auto f = v8cpp::from_v8<std::shared_ptr<RangeInputFilter>>(isolate, fv);
476+ filter_bases.push_back(f->get_filter());
477+ } catch(...) { }
478+ try {
479+ auto f = v8cpp::from_v8<std::shared_ptr<ValueSliderFilter>>(isolate, fv);
480+ filter_bases.push_back(f->get_filter());
481+ } catch(...) { }
482 }
483 return filter_bases;
484 }
485
486=== added file 'src/bindings/src/value-slider-filter.cc'
487--- src/bindings/src/value-slider-filter.cc 1970-01-01 00:00:00 +0000
488+++ src/bindings/src/value-slider-filter.cc 2016-05-12 12:10:04 +0000
489@@ -0,0 +1,131 @@
490+/*
491+ * Copyright 2016 Canonical Ltd.
492+ *
493+ * This file is part of unity-js-scopes.
494+ *
495+ * unity-js-scopes is free software; you can redistribute it and/or modify
496+ * it under the terms of the GNU General Public License as published by
497+ * the Free Software Foundation; version 3.
498+ *
499+ * unity-js-scopes is distributed in the hope that it will be useful,
500+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
501+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
502+ * GNU General Public License for more details.
503+ *
504+ * You should have received a copy of the GNU General Public License
505+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
506+ */
507+
508+#include "value-slider-filter.h"
509+
510+ValueSliderFilter::ValueSliderFilter(v8::FunctionCallbackInfo<v8::Value> const& args)
511+{
512+ if (args.Length() == 5)
513+ {
514+ auto a = v8cpp::from_v8<std::string>(args.GetIsolate(), args[0]);
515+ auto b = v8cpp::from_v8<double>(args.GetIsolate(), args[1]);
516+ auto c = v8cpp::from_v8<double>(args.GetIsolate(), args[2]);
517+ auto d = v8cpp::from_v8<double>(args.GetIsolate(), args[3]);
518+ auto e = v8cpp::from_v8<std::shared_ptr<ValueSliderLabels>>(args.GetIsolate(), args[4]);
519+
520+ filter_ = unity::scopes::ValueSliderFilter::create(a, b, c, d, e->get_labels());
521+ labels_ = e;
522+ }
523+ else if (args.Length() == 6)
524+ {
525+ auto a = v8cpp::from_v8<std::string>(args.GetIsolate(), args[0]);
526+ auto b = v8cpp::from_v8<double>(args.GetIsolate(), args[1]);
527+ auto c = v8cpp::from_v8<double>(args.GetIsolate(), args[2]);
528+ auto d = v8cpp::from_v8<double>(args.GetIsolate(), args[3]);
529+ auto e = v8cpp::from_v8<std::shared_ptr<ValueSliderLabels>>(args.GetIsolate(), args[4]);
530+ auto f = v8cpp::from_v8<std::shared_ptr<FilterGroup>>(args.GetIsolate(), args[5]);
531+
532+ filter_ = unity::scopes::ValueSliderFilter::create(a, b, c, d, e->get_labels(), f->get_filter_group());
533+ labels_ = e;
534+ filter_group_ = f;
535+ }
536+ else
537+ {
538+ throw std::runtime_error("Invalid number of arguments");
539+ }
540+}
541+
542+void ValueSliderFilter::set_display_hints(int hints)
543+{
544+ filter_->set_display_hints(hints);
545+}
546+
547+int ValueSliderFilter::display_hints() const
548+{
549+ return filter_->display_hints();
550+}
551+
552+std::string ValueSliderFilter::id() const
553+{
554+ return filter_->id();
555+}
556+
557+std::string ValueSliderFilter::filter_type() const
558+{
559+ return filter_->filter_type();
560+}
561+
562+void ValueSliderFilter::set_title(std::string const& title)
563+{
564+ return filter_->set_title(title);
565+}
566+
567+std::string ValueSliderFilter::title() const
568+{
569+ return filter_->title();
570+}
571+
572+std::shared_ptr<FilterGroup> ValueSliderFilter::filter_group() const
573+{
574+ return filter_group_;
575+}
576+
577+void ValueSliderFilter::set_default_value(double val)
578+{
579+ return filter_->set_default_value(val);
580+}
581+
582+double ValueSliderFilter::default_value() const
583+{
584+ return filter_->default_value();
585+}
586+
587+double ValueSliderFilter::min() const
588+{
589+ return filter_->min();
590+}
591+
592+double ValueSliderFilter::max() const
593+{
594+ return filter_->max();
595+}
596+
597+bool ValueSliderFilter::has_value(unity::scopes::FilterState const& filter_state) const
598+{
599+ return filter_->has_value(filter_state);
600+}
601+
602+double ValueSliderFilter::value(unity::scopes::FilterState const& filter_state) const
603+{
604+ return filter_->value(filter_state);
605+}
606+
607+std::shared_ptr<ValueSliderLabels> ValueSliderFilter::labels() const
608+{
609+ return labels_;
610+}
611+
612+void ValueSliderFilter::update_state(unity::scopes::FilterState& filter_state, double value) const
613+{
614+ return filter_->update_state(filter_state, value);
615+}
616+
617+unity::scopes::ValueSliderFilter::SPtr ValueSliderFilter::get_filter()
618+{
619+ return filter_;
620+}
621
622=== added file 'src/bindings/src/value-slider-filter.h'
623--- src/bindings/src/value-slider-filter.h 1970-01-01 00:00:00 +0000
624+++ src/bindings/src/value-slider-filter.h 2016-05-12 12:10:04 +0000
625@@ -0,0 +1,61 @@
626+/*
627+ * Copyright 2016 Canonical Ltd.
628+ *
629+ * This file is part of unity-js-scopes.
630+ *
631+ * unity-js-scopes is free software; you can redistribute it and/or modify
632+ * it under the terms of the GNU General Public License as published by
633+ * the Free Software Foundation; version 3.
634+ *
635+ * unity-js-scopes is distributed in the hope that it will be useful,
636+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
637+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
638+ * GNU General Public License for more details.
639+ *
640+ * You should have received a copy of the GNU General Public License
641+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
642+ */
643+
644+#ifndef _UNITY_JS_VALUE_SLIDER_FILTER_H_
645+#define _UNITY_JS_VALUE_SLIDER_FILTER_H_
646+
647+#include "value-slider-labels.h"
648+#include "filter-group.h"
649+
650+#include <unity/scopes/ValueSliderFilter.h>
651+
652+class ValueSliderFilter
653+{
654+public:
655+ ValueSliderFilter(v8::FunctionCallbackInfo<v8::Value> const& args);
656+
657+ // FilterBase
658+ void set_display_hints(int hints);
659+ int display_hints() const;
660+ std::string id() const;
661+ std::string filter_type() const;
662+ void set_title(std::string const& title);
663+ std::string title() const;
664+ std::shared_ptr<FilterGroup> filter_group() const;
665+
666+ // ValueSliderFilter
667+ void set_default_value(double val);
668+ double default_value() const;
669+ double min() const;
670+ double max() const;
671+ bool has_value(unity::scopes::FilterState const& filter_state) const;
672+ double value(unity::scopes::FilterState const& filter_state) const;
673+ std::shared_ptr<ValueSliderLabels> labels() const;
674+ void update_state(unity::scopes::FilterState& filter_state, double value) const;
675+
676+ unity::scopes::ValueSliderFilter::SPtr get_filter();
677+
678+private:
679+ unity::scopes::ValueSliderFilter::SPtr filter_;
680+ std::shared_ptr<FilterGroup> filter_group_;
681+ std::shared_ptr<ValueSliderLabels> labels_;
682+};
683+
684+#endif // _UNITY_JS_VALUE_SLIDER_FILTER_H_
685+
686+
687
688=== added file 'src/bindings/src/value-slider-labels.cc'
689--- src/bindings/src/value-slider-labels.cc 1970-01-01 00:00:00 +0000
690+++ src/bindings/src/value-slider-labels.cc 2016-05-12 12:10:04 +0000
691@@ -0,0 +1,90 @@
692+/*
693+ * Copyright 2016 Canonical Ltd.
694+ *
695+ * This file is part of unity-js-scopes.
696+ *
697+ * unity-js-scopes is free software; you can redistribute it and/or modify
698+ * it under the terms of the GNU General Public License as published by
699+ * the Free Software Foundation; version 3.
700+ *
701+ * unity-js-scopes is distributed in the hope that it will be useful,
702+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
703+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
704+ * GNU General Public License for more details.
705+ *
706+ * You should have received a copy of the GNU General Public License
707+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
708+ */
709+
710+#include "value-slider-labels.h"
711+
712+#include "common.h"
713+
714+//std::string const& min_label, std::string const& max_label, ValueLabelPairList const& extra_labels
715+
716+ValueSliderLabels::ValueSliderLabels(v8::FunctionCallbackInfo<v8::Value> const& args)
717+{
718+ if (args.Length() != 2 && args.Length() != 3) {
719+ throw std::runtime_error("Invalid number of arguments");
720+ }
721+ if (!args[0]->IsString()) {
722+ throw std::runtime_error("Invalid argument type");
723+ }
724+ if (!args[1]->IsString()) {
725+ throw std::runtime_error("Invalid argument type");
726+ }
727+
728+ std::string min_label =
729+ *(v8::String::Utf8Value(args[0]->ToString()));
730+
731+ std::string max_label =
732+ *(v8::String::Utf8Value(args[1]->ToString()));
733+
734+ if (args.Length() == 3)
735+ {
736+ ValueLabelPairList extra_labels;
737+
738+ try
739+ {
740+ auto extra_labels_a = unity::scopesjs::to_variant(args[2]).get_array();
741+
742+ for (auto const& label : extra_labels_a)
743+ {
744+ auto label_pair = label.get_array();
745+ if (label_pair.size() == 2)
746+ {
747+ extra_labels.push_back(ValueLabelPair(label_pair[0].get_double(), label_pair[1].get_string()));
748+ }
749+ }
750+ } catch(...)
751+ {
752+ throw std::runtime_error("ValueSliderLabels::ValueSliderLabels: Malformed 'extra_labels' argument! Expected format: [[2, \"2\"], [4, \"4\"]]");
753+ }
754+
755+ labels_ = std::make_shared<unity::scopes::ValueSliderLabels>(unity::scopes::ValueSliderLabels(min_label, max_label, extra_labels));
756+ }
757+ else
758+ {
759+ labels_ = std::make_shared<unity::scopes::ValueSliderLabels>(unity::scopes::ValueSliderLabels(min_label, max_label));
760+ }
761+}
762+
763+std::string ValueSliderLabels::min_label() const
764+{
765+ return labels_->min_label();
766+}
767+
768+std::string ValueSliderLabels::max_label() const
769+{
770+ return labels_->max_label();
771+}
772+
773+ValueLabelPairList ValueSliderLabels::extra_labels() const
774+{
775+ return labels_->extra_labels();
776+}
777+
778+unity::scopes::ValueSliderLabels ValueSliderLabels::get_labels() const
779+{
780+ return *labels_;
781+}
782
783=== added file 'src/bindings/src/value-slider-labels.h'
784--- src/bindings/src/value-slider-labels.h 1970-01-01 00:00:00 +0000
785+++ src/bindings/src/value-slider-labels.h 2016-05-12 12:10:04 +0000
786@@ -0,0 +1,46 @@
787+/*
788+ * Copyright 2016 Canonical Ltd.
789+ *
790+ * This file is part of unity-js-scopes.
791+ *
792+ * unity-js-scopes is free software; you can redistribute it and/or modify
793+ * it under the terms of the GNU General Public License as published by
794+ * the Free Software Foundation; version 3.
795+ *
796+ * unity-js-scopes is distributed in the hope that it will be useful,
797+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
798+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
799+ * GNU General Public License for more details.
800+ *
801+ * You should have received a copy of the GNU General Public License
802+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
803+ */
804+
805+#ifndef _UNITY_JS_VALUE_SLIDER_LABELS_H_
806+#define _UNITY_JS_VALUE_SLIDER_LABELS_H_
807+
808+#include <unity/scopes/ValueSliderLabels.h>
809+
810+#include <v8-cpp.h>
811+
812+typedef std::pair<double, std::string> ValueLabelPair;
813+typedef std::vector<ValueLabelPair> ValueLabelPairList;
814+
815+class ValueSliderLabels
816+{
817+public:
818+ ValueSliderLabels(v8::FunctionCallbackInfo<v8::Value> const& args);
819+
820+ std::string min_label() const;
821+ std::string max_label() const;
822+ ValueLabelPairList extra_labels() const;
823+
824+ unity::scopes::ValueSliderLabels get_labels() const;
825+
826+private:
827+ std::shared_ptr<unity::scopes::ValueSliderLabels> labels_;
828+};
829+
830+#endif // _UNITY_JS_VALUE_SLIDER_LABELS_H_
831+
832+

Subscribers

People subscribed via source and target branches

to all changes: