Merge lp:~abreu-alexandre/unity-js-scopes/add-filter-state-handling into lp:unity-js-scopes

Proposed by Alexandre Abreu
Status: Merged
Approved by: Marcus Tomlinson
Approved revision: 88
Merged at revision: 87
Proposed branch: lp:~abreu-alexandre/unity-js-scopes/add-filter-state-handling
Merge into: lp:unity-js-scopes
Diff against target: 601 lines (+391/-26)
11 files modified
examples/simple/simple.js (+11/-1)
src/bindings/src/addon.cc (+45/-11)
src/bindings/src/canned-query.cc (+90/-0)
src/bindings/src/canned-query.h (+49/-0)
src/bindings/src/option-selector-filter.cc (+86/-0)
src/bindings/src/option-selector-filter.h (+54/-0)
src/bindings/src/scope-base.cc (+3/-2)
src/bindings/src/search-query.cc (+2/-2)
src/bindings/src/search-query.h (+3/-1)
src/bindings/src/search-reply.cc (+46/-7)
src/bindings/src/search-reply.h (+2/-2)
To merge this branch: bzr merge lp:~abreu-alexandre/unity-js-scopes/add-filter-state-handling
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Marcus Tomlinson (community) Approve
Review via email: mp+274605@code.launchpad.net

Commit message

Add FilterState handling

Description of the change

Add FilterState handling

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
87. By Alexandre Abreu

merge trunk

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

Left some inline comments.

review: Needs Fixing
88. By Alexandre Abreu

updated

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

updated

Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

+1

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'examples/simple/simple.js'
--- examples/simple/simple.js 2015-10-13 17:53:25 +0000
+++ examples/simple/simple.js 2015-10-22 13:54:24 +0000
@@ -50,7 +50,17 @@
50 new scopes.lib.categorised_result(category);50 new scopes.lib.categorised_result(category);
51 categorised_result.set_uri("http://www.ubuntu.com");51 categorised_result.set_uri("http://www.ubuntu.com");
52 categorised_result.set_title("'" + qs + "'");52 categorised_result.set_title("'" + qs + "'");
53 53
54 var filter_state =
55 new scopes.lib.filter_state();
56 var option_filter =
57 new scopes.lib.option_selector_filter('me', 'push', false);
58 var option = option_filter.add_option("id", "yes");
59
60 var p = search_reply.push([option_filter], filter_state);
61
62 console.log(' push : ' + p);
63
54 search_reply.push(categorised_result);64 search_reply.push(categorised_result);
55 },65 },
56 // cancelled66 // cancelled
5767
=== modified file 'src/bindings/src/addon.cc'
--- src/bindings/src/addon.cc 2015-10-19 14:03:37 +0000
+++ src/bindings/src/addon.cc 2015-10-22 13:54:24 +0000
@@ -21,7 +21,6 @@
21#include <stdexcept>21#include <stdexcept>
2222
23#include <unity/scopes/ActionMetadata.h>23#include <unity/scopes/ActionMetadata.h>
24#include <unity/scopes/CannedQuery.h>
25#include <unity/scopes/Category.h>24#include <unity/scopes/Category.h>
26#include <unity/scopes/CategoryRenderer.h>25#include <unity/scopes/CategoryRenderer.h>
27#include <unity/scopes/Result.h>26#include <unity/scopes/Result.h>
@@ -34,9 +33,11 @@
3433
35#include "action-metadata.h"34#include "action-metadata.h"
36#include "activation-query.h"35#include "activation-query.h"
36#include "canned-query.h"
37#include "categorised-result.h"37#include "categorised-result.h"
38#include "department.h"38#include "department.h"
39#include "online-account-client.h"39#include "online-account-client.h"
40#include "option-selector-filter.h"
40#include "preview-query.h"41#include "preview-query.h"
41#include "preview-reply.h"42#include "preview-reply.h"
42#include "preview-widget.h"43#include "preview-widget.h"
@@ -183,16 +184,17 @@
183 .add_method("set_category", &CategorisedResult::set_category)184 .add_method("set_category", &CategorisedResult::set_category)
184 .add_method("category", &CategorisedResult::category);185 .add_method("category", &CategorisedResult::category);
185186
186 v8cpp::Class<unity::scopes::CannedQuery> canned_query(isolate);187 v8cpp::Class<CannedQuery> canned_query(isolate);
187 canned_query188 canned_query
188 .add_method("set_department_id", &unity::scopes::CannedQuery::set_department_id)189 .set_constructor<v8::FunctionCallbackInfo<v8::Value>>()
189 .add_method("set_query_string", &unity::scopes::CannedQuery::set_query_string)190 .add_method("set_department_id", &CannedQuery::set_department_id)
190 .add_method("set_filter_state", &unity::scopes::CannedQuery::set_filter_state)191 .add_method("set_query_string", &CannedQuery::set_query_string)
191 .add_method("scope_id", &unity::scopes::CannedQuery::scope_id)192 .add_method("set_filter_state", &CannedQuery::set_filter_state)
192 .add_method("department_id", &unity::scopes::CannedQuery::department_id)193 .add_method("scope_id", &CannedQuery::scope_id)
193 .add_method("filter_state", &unity::scopes::CannedQuery::filter_state)194 .add_method("department_id", &CannedQuery::department_id)
194 .add_method("query_string", &unity::scopes::CannedQuery::query_string)195 .add_method("query_string", &CannedQuery::query_string)
195 .add_method("to_uri", &unity::scopes::CannedQuery::to_uri);196 .add_method("to_uri", &CannedQuery::to_uri)
197 .add_method("filter_state", &CannedQuery::filter_state);
196198
197 // TODO Should it be more of a value type? (it seems to be used that way199 // TODO Should it be more of a value type? (it seems to be used that way
198 // in unity API)200 // in unity API)
@@ -246,6 +248,33 @@
246 .add_method("region_name", &unity::scopes::Location::region_name)248 .add_method("region_name", &unity::scopes::Location::region_name)
247 .add_method("has_vertical_accuracy", &unity::scopes::Location::has_vertical_accuracy);249 .add_method("has_vertical_accuracy", &unity::scopes::Location::has_vertical_accuracy);
248250
251 v8cpp::Class<unity::scopes::FilterState> filter_state(isolate);
252 filter_state
253 .set_constructor<>()
254 .add_method("has_filter", &unity::scopes::FilterState::has_filter)
255 .add_method("remove", &unity::scopes::FilterState::remove);
256
257 v8cpp::Class<unity::scopes::FilterOption> filter_option(isolate);
258 filter_option
259 .add_method("id", &unity::scopes::FilterOption::id)
260 .add_method("label", &unity::scopes::FilterOption::label);
261
262 v8cpp::Class<OptionSelectorFilter> option_selector_filter(isolate);
263 option_selector_filter
264 .set_constructor<std::string, std::string, bool>()
265 .add_method("label", &OptionSelectorFilter::label)
266 .add_method("multi_select", &OptionSelectorFilter::multi_select)
267 .add_method("add_option", &OptionSelectorFilter::add_option)
268 .add_method("options", &OptionSelectorFilter::options)
269 .add_method("has_active_option", &OptionSelectorFilter::has_active_option)
270 .add_method("active_options", &OptionSelectorFilter::active_options)
271 .add_method("update_state", &OptionSelectorFilter::update_state)
272 // FilterBase
273 .add_method("set_display_hints", &OptionSelectorFilter::set_display_hints)
274 .add_method("display_hints", &OptionSelectorFilter::display_hints)
275 .add_method("id", &OptionSelectorFilter::id)
276 .add_method("filter_type", &OptionSelectorFilter::filter_type);
277
249 v8cpp::Class<PreviewWidget> preview_widget(isolate);278 v8cpp::Class<PreviewWidget> preview_widget(isolate);
250 preview_widget279 preview_widget
251 .set_constructor<v8::Local<v8::Value>, v8::Local<v8::Value>>()280 .set_constructor<v8::Local<v8::Value>, v8::Local<v8::Value>>()
@@ -311,7 +340,7 @@
311340
312 v8cpp::Class<SearchQuery> search_query(isolate);341 v8cpp::Class<SearchQuery> search_query(isolate);
313 search_query342 search_query
314 .set_constructor<std::shared_ptr<unity::scopes::CannedQuery>, std::shared_ptr<unity::scopes::SearchMetadata>, v8::Local<v8::Function>, v8::Local<v8::Function>>()343 .set_constructor<std::shared_ptr<CannedQuery>, std::shared_ptr<unity::scopes::SearchMetadata>, v8::Local<v8::Function>, v8::Local<v8::Function>>()
315 .add_method("onrun", &SearchQuery::onrun)344 .add_method("onrun", &SearchQuery::onrun)
316 .add_method("oncancelled", &SearchQuery::oncancelled);345 .add_method("oncancelled", &SearchQuery::oncancelled);
317346
@@ -368,8 +397,11 @@
368 module.add_class("category_renderer", category_renderer);397 module.add_class("category_renderer", category_renderer);
369 module.add_class("column_layout", column_layout);398 module.add_class("column_layout", column_layout);
370 module.add_class("department", department);399 module.add_class("department", department);
400 module.add_class("filter_option", filter_option);
401 module.add_class("filter_state", filter_state);
371 module.add_class("location", location);402 module.add_class("location", location);
372 module.add_class("online_account_client", online_account_client);403 module.add_class("online_account_client", online_account_client);
404 module.add_class("option_selector_filter", option_selector_filter);
373 module.add_class("preview_widget", preview_widget);405 module.add_class("preview_widget", preview_widget);
374 module.add_class("preview_query", preview_query);406 module.add_class("preview_query", preview_query);
375 module.add_class("preview_reply", preview_reply);407 module.add_class("preview_reply", preview_reply);
@@ -387,6 +419,8 @@
387 // Standalone functions419 // Standalone functions
388 module.add_function("new_category_renderer_from_file", &new_category_renderer_from_file);420 module.add_function("new_category_renderer_from_file", &new_category_renderer_from_file);
389421
422 module.add_function("create_option_selector_filter", &unity::scopes::OptionSelectorFilter::create);
423
390 module.add_function("runtime_version", &get_scopes_runtime_version);424 module.add_function("runtime_version", &get_scopes_runtime_version);
391425
392 exports->SetPrototype(module.create_prototype());426 exports->SetPrototype(module.create_prototype());
393427
=== added file 'src/bindings/src/canned-query.cc'
--- src/bindings/src/canned-query.cc 1970-01-01 00:00:00 +0000
+++ src/bindings/src/canned-query.cc 2015-10-22 13:54:24 +0000
@@ -0,0 +1,90 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This file is part of unity-js-scopes.
5 *
6 * unity-js-scopes is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * unity-js-scopes is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "canned-query.h"
20
21CannedQuery::CannedQuery(v8::FunctionCallbackInfo<v8::Value> const& args) {
22 if (args.Length() != 3) {
23 throw std::runtime_error("Invalid number of arguments");
24 }
25
26 if (!args[0]->IsString()) {
27 throw std::runtime_error("Invalid type for argument index 1");
28 }
29
30 std::string scope_id =
31 *(v8::String::Utf8Value(args[0]->ToString()));
32
33 if (args[1]->IsString() && args[2]->IsString()) {
34
35 std::string query_str =
36 *(v8::String::Utf8Value(args[1]->ToString()));
37
38 std::string department_id =
39 *(v8::String::Utf8Value(args[2]->ToString()));
40
41 query_.reset(
42 new unity::scopes::CannedQuery(
43 scope_id,
44 query_str,
45 department_id));
46 } else {
47 query_.reset(
48 new unity::scopes::CannedQuery(scope_id));
49 }
50}
51
52CannedQuery::CannedQuery(const unity::scopes::CannedQuery& canned_query) {
53 query_.reset(new unity::scopes::CannedQuery(canned_query));
54}
55
56void CannedQuery::set_department_id(const std::string& department_id) {
57 query_->set_department_id(department_id);
58}
59
60void CannedQuery::set_query_string(const std::string& query_string) {
61 query_->set_query_string(query_string);
62}
63
64void CannedQuery::set_filter_state(std::shared_ptr<unity::scopes::FilterState> filter_state) {
65 query_->set_filter_state(*filter_state);
66}
67
68std::string CannedQuery::scope_id() const {
69 return query_->scope_id();
70}
71
72std::string CannedQuery::department_id() const {
73 return query_->department_id();
74}
75
76std::string CannedQuery::query_string() const {
77 return query_->query_string();
78}
79
80std::string CannedQuery::to_uri() const {
81 return query_->to_uri();
82}
83
84unity::scopes::FilterState CannedQuery::filter_state() const {
85 return query_->filter_state();
86}
87
88unity::scopes::CannedQuery & CannedQuery::canned_query() {
89 return *query_.get();
90}
091
=== added file 'src/bindings/src/canned-query.h'
--- src/bindings/src/canned-query.h 1970-01-01 00:00:00 +0000
+++ src/bindings/src/canned-query.h 2015-10-22 13:54:24 +0000
@@ -0,0 +1,49 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This file is part of unity-js-scopes.
5 *
6 * unity-js-scopes is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * unity-js-scopes is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef _UNITY_JS_CANNED_QUERY_H_
20#define _UNITY_JS_CANNED_QUERY_H_
21
22#include <unity/scopes/CannedQuery.h>
23
24#include <v8-cpp.h>
25
26class CannedQuery
27{
28 public:
29 CannedQuery(const unity::scopes::CannedQuery& canned_query);
30 CannedQuery(v8::FunctionCallbackInfo<v8::Value> const& args);
31
32 // v8 bindings
33 void set_department_id(const std::string& department_id);
34 void set_query_string(const std::string& query_string);
35 void set_filter_state(std::shared_ptr<unity::scopes::FilterState> filter_state);
36
37 std::string scope_id() const;
38 std::string department_id() const;
39 std::string query_string() const;
40 std::string to_uri() const;
41 unity::scopes::FilterState filter_state() const;
42
43 unity::scopes::CannedQuery & canned_query();
44
45 private:
46 std::unique_ptr<unity::scopes::CannedQuery> query_;
47};
48
49#endif // _UNITY_JS_CANNED_QUERY_H_
050
=== added file 'src/bindings/src/option-selector-filter.cc'
--- src/bindings/src/option-selector-filter.cc 1970-01-01 00:00:00 +0000
+++ src/bindings/src/option-selector-filter.cc 2015-10-22 13:54:24 +0000
@@ -0,0 +1,86 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This file is part of unity-js-scopes.
5 *
6 * unity-js-scopes is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * unity-js-scopes is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "option-selector-filter.h"
20
21
22OptionSelectorFilter::OptionSelectorFilter(
23 std::string const &id,
24 std::string const &label,
25 bool multi_select)
26 : filter_(unity::scopes::OptionSelectorFilter::create(id, label, multi_select)){
27}
28
29std::string OptionSelectorFilter::label() const {
30 return filter_->label();
31}
32
33bool OptionSelectorFilter::multi_select() const {
34 return filter_->multi_select();
35}
36
37unity::scopes::FilterOption::SCPtr OptionSelectorFilter::add_option(
38 std::string const& id,
39 std::string const& label) {
40 return filter_->add_option(id, label);
41}
42
43std::list<unity::scopes::FilterOption::SCPtr> OptionSelectorFilter::options() const {
44 return filter_->options();
45}
46
47bool OptionSelectorFilter::has_active_option(
48 unity::scopes::FilterState const& filter_state) const {
49 return filter_->has_active_option(filter_state);
50}
51
52std::set<unity::scopes::FilterOption::SCPtr> OptionSelectorFilter::active_options(
53 unity::scopes::FilterState const& filter_state) const {
54 return filter_->active_options(filter_state);
55}
56
57void OptionSelectorFilter::update_state(
58 unity::scopes::FilterState& filter_state,
59 unity::scopes::FilterOption::SCPtr option,
60 bool active) const {
61 filter_->update_state(filter_state, option, active);
62}
63
64void OptionSelectorFilter::set_display_hints(int hints) {
65 filter_->set_display_hints(hints);
66}
67
68int OptionSelectorFilter::display_hints() const {
69 return filter_->display_hints();
70}
71
72std::string OptionSelectorFilter::id() const {
73 return filter_->id();
74}
75
76unity::scopes::VariantMap OptionSelectorFilter::serialize() const {
77 return filter_->serialize();
78}
79
80std::string OptionSelectorFilter::filter_type() const {
81 return filter_->filter_type();
82}
83
84unity::scopes::OptionSelectorFilter::SPtr OptionSelectorFilter::get_filter() {
85 return filter_;
86}
087
=== added file 'src/bindings/src/option-selector-filter.h'
--- src/bindings/src/option-selector-filter.h 1970-01-01 00:00:00 +0000
+++ src/bindings/src/option-selector-filter.h 2015-10-22 13:54:24 +0000
@@ -0,0 +1,54 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This file is part of unity-js-scopes.
5 *
6 * unity-js-scopes is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * unity-js-scopes is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef _UNITY_JS_OPTION_SELECTOR_FILTER_H_
20#define _UNITY_JS_OPTION_SELECTOR_FILTER_H_
21
22#include <unity/scopes/OptionSelectorFilter.h>
23
24#include <v8-cpp.h>
25
26
27class OptionSelectorFilter
28{
29 public:
30 OptionSelectorFilter(std::string const &id, std::string const &label, bool multi_select);
31
32 std::string label() const;
33 bool multi_select() const;
34 unity::scopes::FilterOption::SCPtr add_option(std::string const& id, std::string const& label);
35 std::list<unity::scopes::FilterOption::SCPtr> options() const;
36 bool has_active_option(unity::scopes::FilterState const& filter_state) const;
37 std::set<unity::scopes::FilterOption::SCPtr> active_options(unity::scopes::FilterState const& filter_state) const;
38 void update_state(unity::scopes::FilterState& filter_state, unity::scopes::FilterOption::SCPtr option, bool active) const;
39
40 void set_display_hints(int hints);
41 int display_hints() const;
42 std::string id() const;
43 unity::scopes::VariantMap serialize() const;
44 std::string filter_type() const;
45
46 unity::scopes::OptionSelectorFilter::SPtr get_filter();
47
48 private:
49 unity::scopes::OptionSelectorFilter::SPtr filter_;
50};
51
52#endif // _UNITY_JS_OPTION_SELECTOR_FILTER_H_
53
54
055
=== modified file 'src/bindings/src/scope-base.cc'
--- src/bindings/src/scope-base.cc 2015-10-09 17:00:22 +0000
+++ src/bindings/src/scope-base.cc 2015-10-22 13:54:24 +0000
@@ -21,6 +21,7 @@
21#include "action-metadata.h"21#include "action-metadata.h"
22#include "activation-query.h"22#include "activation-query.h"
23#include "activation-query-proxy.h"23#include "activation-query-proxy.h"
24#include "canned-query.h"
24#include "search-query.h"25#include "search-query.h"
25#include "search-query-proxy.h"26#include "search-query-proxy.h"
26#include "search-metadata.h"27#include "search-metadata.h"
@@ -109,8 +110,8 @@
109 return EventQueue::instance().run<unity::scopes::SearchQueryBase::UPtr>(isolate_, [this, query, metadata]110 return EventQueue::instance().run<unity::scopes::SearchQueryBase::UPtr>(isolate_, [this, query, metadata]
110 {111 {
111 // wrap & fire112 // wrap & fire
112 std::shared_ptr<unity::scopes::CannedQuery> q(113 std::shared_ptr<CannedQuery> q(
113 new unity::scopes::CannedQuery(std::move(query)));114 new CannedQuery(query));
114115
115 std::shared_ptr<SearchMetaData> m(116 std::shared_ptr<SearchMetaData> m(
116 new SearchMetaData(metadata));117 new SearchMetaData(metadata));
117118
=== modified file 'src/bindings/src/search-query.cc'
--- src/bindings/src/search-query.cc 2015-10-13 17:53:25 +0000
+++ src/bindings/src/search-query.cc 2015-10-22 13:54:24 +0000
@@ -23,11 +23,11 @@
23#include "event_queue.h"23#include "event_queue.h"
2424
25SearchQuery::SearchQuery(25SearchQuery::SearchQuery(
26 std::shared_ptr<unity::scopes::CannedQuery> query,26 std::shared_ptr<CannedQuery> query,
27 std::shared_ptr<unity::scopes::SearchMetadata> metadata,27 std::shared_ptr<unity::scopes::SearchMetadata> metadata,
28 const v8::Local<v8::Function> &run_callback,28 const v8::Local<v8::Function> &run_callback,
29 const v8::Local<v8::Function> &cancelled_callback)29 const v8::Local<v8::Function> &cancelled_callback)
30 : unity::scopes::SearchQueryBase(*query, *metadata),30 : unity::scopes::SearchQueryBase(query->canned_query(), *metadata),
31 isolate_(v8::Isolate::GetCurrent()),31 isolate_(v8::Isolate::GetCurrent()),
32 run_callback_(v8::Isolate::GetCurrent(), run_callback),32 run_callback_(v8::Isolate::GetCurrent(), run_callback),
33 cancelled_callback_(v8::Isolate::GetCurrent(), cancelled_callback) {33 cancelled_callback_(v8::Isolate::GetCurrent(), cancelled_callback) {
3434
=== modified file 'src/bindings/src/search-query.h'
--- src/bindings/src/search-query.h 2015-10-13 17:53:25 +0000
+++ src/bindings/src/search-query.h 2015-10-22 13:54:24 +0000
@@ -21,13 +21,15 @@
2121
22#include <unity/scopes/SearchQueryBase.h>22#include <unity/scopes/SearchQueryBase.h>
2323
24#include "canned-query.h"
25
24#include <v8-cpp.h>26#include <v8-cpp.h>
2527
26class SearchQuery : public unity::scopes::SearchQueryBase,28class SearchQuery : public unity::scopes::SearchQueryBase,
27 public std::enable_shared_from_this<SearchQuery>29 public std::enable_shared_from_this<SearchQuery>
28{30{
29 public:31 public:
30 SearchQuery(std::shared_ptr<unity::scopes::CannedQuery> query,32 SearchQuery(std::shared_ptr<CannedQuery> query,
31 std::shared_ptr<unity::scopes::SearchMetadata> metadata,33 std::shared_ptr<unity::scopes::SearchMetadata> metadata,
32 const v8::Local<v8::Function> &run_callback,34 const v8::Local<v8::Function> &run_callback,
33 const v8::Local<v8::Function> &cancelled_callback);35 const v8::Local<v8::Function> &cancelled_callback);
3436
=== modified file 'src/bindings/src/search-reply.cc'
--- src/bindings/src/search-reply.cc 2015-10-19 14:03:37 +0000
+++ src/bindings/src/search-reply.cc 2015-10-22 13:54:24 +0000
@@ -18,16 +18,40 @@
1818
19#include "search-reply.h"19#include "search-reply.h"
2020
21#include "categorised-result.h"
22#include "option-selector-filter.h"
23
21#include <stdexcept>24#include <stdexcept>
2225
23#include <unity/scopes/SearchReply.h>26#include <unity/scopes/SearchReply.h>
2427
2528
29namespace {
30
31unity::scopes::Filters from_v8_to_filters(
32 v8::Isolate* isolate,
33 v8::Local<v8::Value> value) {
34 unity::scopes::Filters
35 filter_bases;
36 v8::Handle<v8::Object> o = v8::Handle<v8::Object>::Cast(value);
37 for (size_t i = 0;
38 i < o->Get(v8::String::NewFromUtf8(isolate, "length"))->ToObject()->Uint32Value();
39 ++i) {
40 v8::Local<v8::Value> fv = o->Get(i);
41 try {
42 auto f = v8cpp::from_v8<std::shared_ptr<OptionSelectorFilter>>(isolate, fv);
43 filter_bases.push_back(f->get_filter());
44 } catch(...) { }
45 }
46 return filter_bases;
47}
48
49}
50
51
26SearchReply::SearchReply(unity::scopes::SearchReplyProxy const& reply)52SearchReply::SearchReply(unity::scopes::SearchReplyProxy const& reply)
27 : reply_(reply){53 : isolate_(v8::Isolate::GetCurrent())
28}54 , reply_(reply){
29
30SearchReply::~SearchReply() {
31}55}
3256
33unity::scopes::Category::SCPtr SearchReply::lookup_category(57unity::scopes::Category::SCPtr SearchReply::lookup_category(
@@ -35,9 +59,24 @@
35 return reply_->lookup_category(id);59 return reply_->lookup_category(id);
36}60}
3761
38void SearchReply::push(62bool SearchReply::push(v8::FunctionCallbackInfo<v8::Value> const& args) {
39 std::shared_ptr<CategorisedResult> categorised_result) {63 if (args.Length() != 1 && args.Length() != 2) {
40 reply_->push(*categorised_result);64 throw std::runtime_error("Invalid number of arguments");
65 }
66
67 if (args.Length() == 1) {
68 auto cr =
69 v8cpp::from_v8<std::shared_ptr<CategorisedResult>>(isolate_, args[0]);
70 return reply_->push(*cr);
71 }
72
73 auto filter_state =
74 v8cpp::from_v8<std::shared_ptr<unity::scopes::FilterState>>(isolate_, args[1]);
75
76 // TODO fix v8cpp shortcoming here
77 return reply_->push(
78 from_v8_to_filters(isolate_, args[0]),
79 *filter_state);
41}80}
4281
43unity::scopes::Category::SCPtr SearchReply::register_category(82unity::scopes::Category::SCPtr SearchReply::register_category(
4483
=== modified file 'src/bindings/src/search-reply.h'
--- src/bindings/src/search-reply.h 2015-10-16 19:33:32 +0000
+++ src/bindings/src/search-reply.h 2015-10-22 13:54:24 +0000
@@ -32,7 +32,6 @@
32{32{
33 public:33 public:
34 SearchReply(unity::scopes::SearchReplyProxy const& reply);34 SearchReply(unity::scopes::SearchReplyProxy const& reply);
35 ~SearchReply();
3635
37 void register_departments(std::shared_ptr<Department> department);36 void register_departments(std::shared_ptr<Department> department);
3837
@@ -45,12 +44,13 @@
45 unity::scopes::Category::SCPtr44 unity::scopes::Category::SCPtr
46 lookup_category(const std::string& id);45 lookup_category(const std::string& id);
4746
48 void push(std::shared_ptr<CategorisedResult> categorised_result);47 bool push(v8::FunctionCallbackInfo<v8::Value> const& args);
4948
50 void finished();49 void finished();
5150
52 private:51 private:
5352
53 v8::Isolate* isolate_;
54 unity::scopes::SearchReplyProxy const reply_;54 unity::scopes::SearchReplyProxy const reply_;
55};55};
5656

Subscribers

People subscribed via source and target branches

to all changes: