Merge lp:~m982/unity-js-scopes/add-activation-response-update-preview-support into lp:unity-js-scopes

Proposed by Michael Weimann
Status: Merged
Approved by: Alexandre Abreu
Approved revision: 133
Merge reported by: Alexandre Abreu
Merged at revision: not available
Proposed branch: lp:~m982/unity-js-scopes/add-activation-response-update-preview-support
Merge into: lp:unity-js-scopes
Diff against target: 162 lines (+78/-10)
3 files modified
examples/soundcloud/soundcloud.js (+61/-9)
src/bindings/src/activation-response.cc (+16/-0)
src/bindings/src/activation-response.h (+1/-1)
To merge this branch: bzr merge lp:~m982/unity-js-scopes/add-activation-response-update-preview-support
Reviewer Review Type Date Requested Status
Alexandre Abreu (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+286106@code.launchpad.net

Description of the change

Adds support for ActivationResponse with the status UpdatePreview. To detect an UpdatePreview the ActivationResponse constructor tests for an Array argument. If it's an Array it maps it to a real ActivationResponse with a PreviewWidgetList.

How to test: Run the soundcloud example scope. You'll find an "Update" action on the preview. Sadly I didn't find unit tests to extend to cover this.

To post a comment you must log in.
Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

Good code & feature update ! Thank you, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'examples/soundcloud/soundcloud.js'
--- examples/soundcloud/soundcloud.js 2016-02-13 16:01:06 +0000
+++ examples/soundcloud/soundcloud.js 2016-02-15 20:51:32 +0000
@@ -140,7 +140,7 @@
140 "",140 "",
141 "",141 "",
142 category_renderer);142 category_renderer);
143 143
144 var query_string =144 var query_string =
145 canned_query.query_string().trim();145 canned_query.query_string().trim();
146146
@@ -186,11 +186,15 @@
186 var r = this.result();186 var r = this.result();
187187
188 var layout1col = new scopes.lib.ColumnLayout(1)188 var layout1col = new scopes.lib.ColumnLayout(1)
189 layout1col.add_column(["imageId", "headerId", "actionsId"])189 layout1col.add_column([
190 "imageId",
191 "headerId",
192 "actionsId",
193 "updatePreviewActionsId"])
190194
191 var layout2col = new scopes.lib.ColumnLayout(2)195 var layout2col = new scopes.lib.ColumnLayout(2)
192 layout2col.add_column(["imageId"])196 layout2col.add_column(["imageId"])
193 layout2col.add_column(["headerId", "actionsId"])197 layout2col.add_column(["headerId", "actionsId", "updatePreviewActionsId"])
194198
195 preview_reply.register_layout([layout1col, layout2col]);199 preview_reply.register_layout([layout1col, layout2col]);
196200
@@ -201,6 +205,9 @@
201 var art_widget = new scopes.lib.PreviewWidget("imageId", "image");205 var art_widget = new scopes.lib.PreviewWidget("imageId", "image");
202 art_widget.add_attribute_mapping("source", "art");206 art_widget.add_attribute_mapping("source", "art");
203207
208 var update_preview_button_widget =
209 createUpdatePreviewActionsIdWidget("Update");
210
204 var actions_widget = new scopes.lib.PreviewWidget("actionsId", "actions");211 var actions_widget = new scopes.lib.PreviewWidget("actionsId", "actions");
205 actions_widget.add_attribute_value(212 actions_widget.add_attribute_value(
206 "actions",213 "actions",
@@ -220,8 +227,15 @@
220 }227 }
221 ]228 ]
222 );229 );
223 preview_reply.push([header_widget, art_widget, actions_widget])230
224 preview_reply.finished()231 preview_reply.push([
232 header_widget,
233 art_widget,
234 actions_widget,
235 update_preview_button_widget
236 ]);
237
238 preview_reply.finished();
225 },239 },
226 // cancelled240 // cancelled
227 function() {241 function() {
@@ -254,10 +268,20 @@
254 action_id,268 action_id,
255 // activate269 // activate
256 function() {270 function() {
257 console.log('activate called')271 console.log('activate called');
258 272
259 return new scopes.lib.ActivationResponse(273 var result;
260 scopes.defs.ActivationResponseStatus.NotHandled);274 switch (action_id) {
275 case 'updateId':
276 result = activateUpdatePreview();
277 break;
278 default:
279 result = new scopes.lib.ActivationResponse(
280 scopes.defs.ActivationResponseStatus.NotHandled);
281 break;
282 }
283
284 return result;
261 },285 },
262 // cancelled286 // cancelled
263 function() {287 function() {
@@ -266,3 +290,31 @@
266 }290 }
267 }291 }
268);292);
293
294/**
295 * Updates the "updatePreviewActionsId" widget:
296 * Sets the widget's label to "Updated !".
297 */
298function activateUpdatePreview(result) {
299 var widgets = [];
300 var update_preview_button_widget =
301 createUpdatePreviewActionsIdWidget("Updated !");
302 widgets.push(update_preview_button_widget);
303 return new scopes.lib.ActivationResponse(widgets);
304}
305
306function createUpdatePreviewActionsIdWidget(label) {
307 var update_preview_button_widget =
308 new scopes.lib.PreviewWidget("updatePreviewActionsId", "actions");
309 update_preview_button_widget.add_attribute_value(
310 "actions",
311 [
312 {
313 id: "updateId",
314 label: label
315 }
316 ]
317 );
318 return update_preview_button_widget;
319}
320
269321
=== modified file 'src/bindings/src/activation-response.cc'
--- src/bindings/src/activation-response.cc 2016-02-13 20:54:36 +0000
+++ src/bindings/src/activation-response.cc 2016-02-15 20:51:32 +0000
@@ -17,6 +17,7 @@
17 */17 */
1818
19#include "activation-response.h"19#include "activation-response.h"
20#include "preview-widget.h"
2021
21#include "event_queue.h"22#include "event_queue.h"
2223
@@ -34,6 +35,21 @@
34 new unity::scopes::ActivationResponse(35 new unity::scopes::ActivationResponse(
35 static_cast<unity::scopes::ActivationResponse::Status>(36 static_cast<unity::scopes::ActivationResponse::Status>(
36 status)));37 status)));
38 } else if (arg->IsArray()) {
39 // assume UpdatePreview
40 std::vector<std::shared_ptr<PreviewWidget>> const& widgets =
41 v8cpp::from_v8<std::vector<std::shared_ptr<PreviewWidget>>>(
42 v8::Isolate::GetCurrent(),
43 arg);
44
45 unity::scopes::PreviewWidgetList widgets_list;
46 for (auto const& widget : widgets)
47 {
48 widgets_list.push_back(widget->preview_widget());
49 }
50
51 activation_response_.reset(
52 new unity::scopes::ActivationResponse(widgets_list));
37 } else {53 } else {
38 auto query =54 auto query =
39 v8cpp::from_v8<std::shared_ptr<CannedQuery>>(55 v8cpp::from_v8<std::shared_ptr<CannedQuery>>(
4056
=== modified file 'src/bindings/src/activation-response.h'
--- src/bindings/src/activation-response.h 2016-02-13 20:54:36 +0000
+++ src/bindings/src/activation-response.h 2016-02-15 20:51:32 +0000
@@ -41,7 +41,7 @@
41--doc:constructor41--doc:constructor
42 *42 *
43 * @constructor43 * @constructor
44 * @param status|query ActivationResponseStatus to create a response with given status or CannedQuery to create an ActivationResponse with status defs.ActivationResponseStatus.PerformQuery and a search query to be executed44 * @param status|query|{Array of PreviewWidget} ActivationResponseStatus to create a response with given status OR CannedQuery to create an ActivationResponse with status defs.ActivationResponseStatus.PerformQuery and a search query to be executed OR an array of PreviewWidgets to create an ActivationResponse with status defs.ActivationResponseStatus.UpdatePreview to update the given widgets
45--/doc:constructor45--/doc:constructor
4646
47--doc:prototype ActivationResponse47--doc:prototype ActivationResponse

Subscribers

People subscribed via source and target branches

to all changes: