Merge lp:~abreu-alexandre/unity-js-scopes/department into lp:unity-js-scopes
- department
- Merge into trunk
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Marcus Tomlinson | ||||
Approved revision: | 87 | ||||
Merged at revision: | 86 | ||||
Proposed branch: | lp:~abreu-alexandre/unity-js-scopes/department | ||||
Merge into: | lp:unity-js-scopes | ||||
Diff against target: |
291 lines (+201/-23) 5 files modified
src/bindings/src/addon.cc (+39/-23) src/bindings/src/department.cc (+104/-0) src/bindings/src/department.h (+51/-0) src/bindings/src/search-reply.cc (+4/-0) src/bindings/src/search-reply.h (+3/-0) |
||||
To merge this branch: | bzr merge lp:~abreu-alexandre/unity-js-scopes/department | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Marcus Tomlinson (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+274767@code.launchpad.net |
Commit message
Add department
Description of the change
Add department
PS Jenkins bot (ps-jenkins) wrote : | # |
Marcus Tomlinson (marcustomlinson) wrote : | # |
Left some inline comments
- 86. By Alexandre Abreu
-
fixes
Alexandre Abreu (abreu-alexandre) wrote : | # |
updated
Marcus Tomlinson (marcustomlinson) wrote : | # |
Looks like your working hard to get around converting Department::SPtr to Department::SCPtr in a few places.
E.g.
1) Your subdepartments() method doesn't match the base implementation (you're returning a list of Department::SPtr instead of the intended Department::SCPtr), and
2) your register_
I think you'd have a lot less headache if you changed: "unity:
Then you wouldn't have to do this either:
153: deps.push_
Which should really just be: deps.push_
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:86
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Marcus Tomlinson (marcustomlinson) wrote : | # |
> Looks like your working hard to get around converting Department::SPtr to
> Department::SCPtr in a few places.
>
> E.g.
> 1) Your subdepartments() method doesn't match the base implementation (you're
> returning a list of Department::SPtr instead of the intended
> Department::SCPtr), and
> 2) your register_
> original, it should be taking a Department::SCPtr argument.
>
>
> I think you'd have a lot less headache if you changed:
> "unity:
> "unity:
>
> Then you wouldn't have to do this either:
>
> 153:
> deps.push_
>
> Which should really just be: deps.push_
Perhaps to clarify a bit further. This shouldn't have to be so complicated:
std::vector<
Department:
std::
for (auto & d: department_
deps.
}
return deps;
}
Why not just:
unity::
return department_
}
The closer we match the base implementations the easier we make it on ourselves to maintain the bindings.
- 87. By Alexandre Abreu
-
Simplify
Alexandre Abreu (abreu-alexandre) wrote : | # |
I simplified things a bit, but I cannot really have unity::
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:87
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Marcus Tomlinson (marcustomlinson) wrote : | # |
> I simplified things a bit, but I cannot really have unity::
> & DepartmentList play along w/ plain wrapped Department, I see your point here
> obviously but it maked things more confusing when you have at some point
> wrapped Department being created and handed back to JS, and also
> unity::
> them off to things like SearchReply ...
Sorry yes, I did get a little confused with where you were dealing with the wrapped and base versions of the class, but looks much cleaner now thanks!
Preview Diff
1 | === modified file 'src/bindings/src/addon.cc' |
2 | --- src/bindings/src/addon.cc 2015-10-16 13:39:16 +0000 |
3 | +++ src/bindings/src/addon.cc 2015-10-20 14:40:24 +0000 |
4 | @@ -35,6 +35,7 @@ |
5 | #include "action-metadata.h" |
6 | #include "activation-query.h" |
7 | #include "categorised-result.h" |
8 | +#include "department.h" |
9 | #include "online-account-client.h" |
10 | #include "preview-query.h" |
11 | #include "preview-reply.h" |
12 | @@ -208,6 +209,43 @@ |
13 | .add_method("number_of_columns", &unity::scopes::ColumnLayout::number_of_columns) |
14 | .add_method("column", &unity::scopes::ColumnLayout::column); |
15 | |
16 | + v8cpp::Class<Department> department(isolate); |
17 | + department |
18 | + .set_constructor<v8::FunctionCallbackInfo<v8::Value>>() |
19 | + .add_method("set_subdepartments", &Department::set_subdepartments) |
20 | + .add_method("add_subdepartment", &Department::add_subdepartment) |
21 | + .add_method("set_alternate_label", &Department::set_alternate_label) |
22 | + .add_method("set_has_subdepartments", &Department::set_has_subdepartments) |
23 | + .add_method("id", &Department::id) |
24 | + .add_method("label", &Department::label) |
25 | + .add_method("alternate_label", &Department::alternate_label) |
26 | + .add_method("query", &Department::query) |
27 | + .add_method("subdepartments", &Department::subdepartments) |
28 | + .add_method("has_subdepartments", &Department::has_subdepartments); |
29 | + |
30 | + v8cpp::Class<unity::scopes::Location> location(isolate); |
31 | + location |
32 | + // unity::scopes::Location |
33 | + .add_method("altitude", &unity::scopes::Location::altitude) |
34 | + .add_method("has_altitude", &unity::scopes::Location::has_altitude) |
35 | + .add_method("area_code", &unity::scopes::Location::area_code) |
36 | + .add_method("has_area_code", &unity::scopes::Location::has_area_code) |
37 | + .add_method("city", &unity::scopes::Location::city) |
38 | + .add_method("has_city", &unity::scopes::Location::has_city) |
39 | + .add_method("has_country_code", &unity::scopes::Location::has_country_code) |
40 | + .add_method("country_code", &unity::scopes::Location::country_code) |
41 | + .add_method("has_country_name", &unity::scopes::Location::has_country_name) |
42 | + .add_method("country_name", &unity::scopes::Location::country_name) |
43 | + .add_method("has_horizontal_accuracy", &unity::scopes::Location::has_horizontal_accuracy) |
44 | + .add_method("horizontal_accuracy", &unity::scopes::Location::horizontal_accuracy) |
45 | + .add_method("latitude", &unity::scopes::Location::latitude) |
46 | + .add_method("longitude", &unity::scopes::Location::longitude) |
47 | + .add_method("has_region_code", &unity::scopes::Location::has_region_code) |
48 | + .add_method("region_code", &unity::scopes::Location::region_code) |
49 | + .add_method("has_region_name", &unity::scopes::Location::has_region_name) |
50 | + .add_method("region_name", &unity::scopes::Location::region_name) |
51 | + .add_method("has_vertical_accuracy", &unity::scopes::Location::has_vertical_accuracy); |
52 | + |
53 | v8cpp::Class<PreviewWidget> preview_widget(isolate); |
54 | preview_widget |
55 | .set_constructor<v8::Local<v8::Value>, v8::Local<v8::Value>>() |
56 | @@ -277,29 +315,6 @@ |
57 | .add_method("onrun", &SearchQuery::onrun) |
58 | .add_method("oncancelled", &SearchQuery::oncancelled); |
59 | |
60 | - v8cpp::Class<unity::scopes::Location> location(isolate); |
61 | - location |
62 | - // unity::scopes::Location |
63 | - .add_method("altitude", &unity::scopes::Location::altitude) |
64 | - .add_method("has_altitude", &unity::scopes::Location::has_altitude) |
65 | - .add_method("area_code", &unity::scopes::Location::area_code) |
66 | - .add_method("has_area_code", &unity::scopes::Location::has_area_code) |
67 | - .add_method("city", &unity::scopes::Location::city) |
68 | - .add_method("has_city", &unity::scopes::Location::has_city) |
69 | - .add_method("has_country_code", &unity::scopes::Location::has_country_code) |
70 | - .add_method("country_code", &unity::scopes::Location::country_code) |
71 | - .add_method("has_country_name", &unity::scopes::Location::has_country_name) |
72 | - .add_method("country_name", &unity::scopes::Location::country_name) |
73 | - .add_method("has_horizontal_accuracy", &unity::scopes::Location::has_horizontal_accuracy) |
74 | - .add_method("horizontal_accuracy", &unity::scopes::Location::horizontal_accuracy) |
75 | - .add_method("latitude", &unity::scopes::Location::latitude) |
76 | - .add_method("longitude", &unity::scopes::Location::longitude) |
77 | - .add_method("has_region_code", &unity::scopes::Location::has_region_code) |
78 | - .add_method("region_code", &unity::scopes::Location::region_code) |
79 | - .add_method("has_region_name", &unity::scopes::Location::has_region_name) |
80 | - .add_method("region_name", &unity::scopes::Location::region_name) |
81 | - .add_method("has_vertical_accuracy", &unity::scopes::Location::has_vertical_accuracy); |
82 | - |
83 | v8cpp::Class<SearchMetaData> search_metadata(isolate); |
84 | search_metadata |
85 | .add_inheritance<unity::scopes::SearchMetadata>() |
86 | @@ -352,6 +367,7 @@ |
87 | module.add_class("categorised_result", categorised_result); |
88 | module.add_class("category_renderer", category_renderer); |
89 | module.add_class("column_layout", column_layout); |
90 | + module.add_class("department", department); |
91 | module.add_class("location", location); |
92 | module.add_class("online_account_client", online_account_client); |
93 | module.add_class("preview_widget", preview_widget); |
94 | |
95 | === added file 'src/bindings/src/department.cc' |
96 | --- src/bindings/src/department.cc 1970-01-01 00:00:00 +0000 |
97 | +++ src/bindings/src/department.cc 2015-10-20 14:40:24 +0000 |
98 | @@ -0,0 +1,104 @@ |
99 | +/* |
100 | + * Copyright 2015 Canonical Ltd. |
101 | + * |
102 | + * This file is part of unity-js-scopes. |
103 | + * |
104 | + * unity-js-scopes is free software; you can redistribute it and/or modify |
105 | + * it under the terms of the GNU General Public License as published by |
106 | + * the Free Software Foundation; version 3. |
107 | + * |
108 | + * unity-js-scopes is distributed in the hope that it will be useful, |
109 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
110 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
111 | + * GNU General Public License for more details. |
112 | + * |
113 | + * You should have received a copy of the GNU General Public License |
114 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
115 | + */ |
116 | + |
117 | +#include "department.h" |
118 | + |
119 | + |
120 | +Department::Department(const unity::scopes::Department& d) |
121 | + : department_(new unity::scopes::Department(d)) { |
122 | +} |
123 | + |
124 | +Department::Department(v8::FunctionCallbackInfo<v8::Value> const & args) { |
125 | + if (args.Length() != 2 || args.Length() != 3) { |
126 | + throw std::runtime_error("Invalid number of arguments"); |
127 | + } |
128 | + |
129 | + if (args[0]->IsString()) { |
130 | + auto department_id = |
131 | + v8cpp::from_v8<std::string>(v8::Isolate::GetCurrent(), args[0]); |
132 | + auto cq = |
133 | + v8cpp::from_v8<std::shared_ptr<unity::scopes::CannedQuery>>( |
134 | + v8::Isolate::GetCurrent(), args[1]); |
135 | + auto label = |
136 | + v8cpp::from_v8<std::string>(v8::Isolate::GetCurrent(), args[2]); |
137 | + |
138 | + department_ = unity::scopes::Department::create(department_id, *cq, label); |
139 | + } else { |
140 | + auto cq = |
141 | + v8cpp::from_v8<std::shared_ptr<unity::scopes::CannedQuery>>( |
142 | + v8::Isolate::GetCurrent(), args[0]); |
143 | + auto label = |
144 | + v8cpp::from_v8<std::string>(v8::Isolate::GetCurrent(), args[1]); |
145 | + |
146 | + department_ = unity::scopes::Department::create(*cq, label); |
147 | + } |
148 | +} |
149 | + |
150 | +void Department::set_subdepartments(std::vector<std::shared_ptr<Department>> departments) { |
151 | + unity::scopes::DepartmentList deps; |
152 | + for (auto & d: departments) { |
153 | + deps.push_back(d->department()); |
154 | + } |
155 | + department_->set_subdepartments(deps); |
156 | +} |
157 | + |
158 | +void Department::add_subdepartment(std::shared_ptr<Department> const &department) { |
159 | + department_->add_subdepartment(department->department()); |
160 | +} |
161 | + |
162 | +void Department::set_alternate_label(std::string const &label) { |
163 | + department_->set_alternate_label(label); |
164 | +} |
165 | + |
166 | +void Department::set_has_subdepartments(bool subdepartments) { |
167 | + department_->set_has_subdepartments(subdepartments); |
168 | +} |
169 | + |
170 | +std::string Department::id() const { |
171 | + return department_->id(); |
172 | +} |
173 | + |
174 | +std::string Department::label() const { |
175 | + return department_->label(); |
176 | +} |
177 | + |
178 | +std::string Department::alternate_label() const { |
179 | + return department_->alternate_label(); |
180 | +} |
181 | + |
182 | +unity::scopes::CannedQuery |
183 | +Department::query () const { |
184 | + return department_->query(); |
185 | +} |
186 | + |
187 | +std::vector<std::shared_ptr<Department>> |
188 | +Department::subdepartments() const { |
189 | + std::vector<std::shared_ptr<Department>> deps; |
190 | + for (auto & d: department_->subdepartments()) { |
191 | + deps.push_back(std::make_shared<Department>(*d)); |
192 | + } |
193 | + return deps; |
194 | +} |
195 | + |
196 | +bool Department::has_subdepartments() const { |
197 | + return department_->has_subdepartments(); |
198 | +} |
199 | + |
200 | +unity::scopes::Department::SCPtr Department::department() { |
201 | + return department_; |
202 | +} |
203 | |
204 | === added file 'src/bindings/src/department.h' |
205 | --- src/bindings/src/department.h 1970-01-01 00:00:00 +0000 |
206 | +++ src/bindings/src/department.h 2015-10-20 14:40:24 +0000 |
207 | @@ -0,0 +1,51 @@ |
208 | +/* |
209 | + * Copyright 2015 Canonical Ltd. |
210 | + * |
211 | + * This file is part of unity-js-scopes. |
212 | + * |
213 | + * unity-js-scopes is free software; you can redistribute it and/or modify |
214 | + * it under the terms of the GNU General Public License as published by |
215 | + * the Free Software Foundation; version 3. |
216 | + * |
217 | + * unity-js-scopes is distributed in the hope that it will be useful, |
218 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
219 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
220 | + * GNU General Public License for more details. |
221 | + * |
222 | + * You should have received a copy of the GNU General Public License |
223 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
224 | + */ |
225 | + |
226 | +#ifndef _UNITY_JS_DEPARTMENT_H_ |
227 | +#define _UNITY_JS_DEPARTMENT_H_ |
228 | + |
229 | +#include <unity/scopes/Department.h> |
230 | +#include <unity/scopes/CannedQuery.h> |
231 | + |
232 | +#include <v8-cpp.h> |
233 | + |
234 | +class Department |
235 | +{ |
236 | + public: |
237 | + Department(const unity::scopes::Department& d); |
238 | + Department(v8::FunctionCallbackInfo<v8::Value> const& args); |
239 | + |
240 | + // v8 bindings |
241 | + void set_subdepartments(std::vector<std::shared_ptr<Department>> departments); |
242 | + void add_subdepartment(std::shared_ptr<Department> const &department); |
243 | + void set_alternate_label(std::string const &label); |
244 | + void set_has_subdepartments(bool subdepartments); |
245 | + std::string id() const; |
246 | + std::string label() const; |
247 | + std::string alternate_label() const; |
248 | + unity::scopes::CannedQuery query () const; |
249 | + std::vector<std::shared_ptr<Department>> subdepartments() const; |
250 | + bool has_subdepartments() const; |
251 | + |
252 | + unity::scopes::Department::SCPtr department(); |
253 | + |
254 | + private: |
255 | + std::shared_ptr<unity::scopes::Department> department_; |
256 | +}; |
257 | + |
258 | +#endif // _UNITY_JS_DEPARTMENT_H_ |
259 | |
260 | === modified file 'src/bindings/src/search-reply.cc' |
261 | --- src/bindings/src/search-reply.cc 2015-10-09 17:00:22 +0000 |
262 | +++ src/bindings/src/search-reply.cc 2015-10-20 14:40:24 +0000 |
263 | @@ -56,3 +56,7 @@ |
264 | { |
265 | reply_->finished(); |
266 | } |
267 | + |
268 | +void SearchReply::register_departments(std::shared_ptr<Department> department) { |
269 | + reply_->register_departments(department->department()); |
270 | +} |
271 | |
272 | === modified file 'src/bindings/src/search-reply.h' |
273 | --- src/bindings/src/search-reply.h 2015-10-09 17:00:22 +0000 |
274 | +++ src/bindings/src/search-reply.h 2015-10-20 14:40:24 +0000 |
275 | @@ -23,6 +23,7 @@ |
276 | #include <unity/scopes/Category.h> |
277 | |
278 | #include "categorised-result.h" |
279 | +#include "department.h" |
280 | |
281 | #include <v8-cpp.h> |
282 | |
283 | @@ -33,6 +34,8 @@ |
284 | SearchReply(unity::scopes::SearchReplyProxy const& reply); |
285 | ~SearchReply(); |
286 | |
287 | + void register_departments(std::shared_ptr<Department> department); |
288 | + |
289 | unity::scopes::Category::SCPtr register_category( |
290 | const std::string& id, |
291 | const std::string& title, |
PASSED: Continuous integration, rev:85 jenkins. qa.ubuntu. com/job/ unity-js- scopes- ci/12/ jenkins. qa.ubuntu. com/job/ unity-js- scopes- wily-amd64- ci/12 jenkins. qa.ubuntu. com/job/ unity-js- scopes- wily-armhf- ci/12 jenkins. qa.ubuntu. com/job/ unity-js- scopes- wily-armhf- ci/12/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ unity-js- scopes- wily-i386- ci/12
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- js-scopes- ci/12/rebuild
http://