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
1=== modified file 'examples/soundcloud/soundcloud.js'
2--- examples/soundcloud/soundcloud.js 2016-02-13 16:01:06 +0000
3+++ examples/soundcloud/soundcloud.js 2016-02-15 20:51:32 +0000
4@@ -140,7 +140,7 @@
5 "",
6 "",
7 category_renderer);
8-
9+
10 var query_string =
11 canned_query.query_string().trim();
12
13@@ -186,11 +186,15 @@
14 var r = this.result();
15
16 var layout1col = new scopes.lib.ColumnLayout(1)
17- layout1col.add_column(["imageId", "headerId", "actionsId"])
18+ layout1col.add_column([
19+ "imageId",
20+ "headerId",
21+ "actionsId",
22+ "updatePreviewActionsId"])
23
24 var layout2col = new scopes.lib.ColumnLayout(2)
25 layout2col.add_column(["imageId"])
26- layout2col.add_column(["headerId", "actionsId"])
27+ layout2col.add_column(["headerId", "actionsId", "updatePreviewActionsId"])
28
29 preview_reply.register_layout([layout1col, layout2col]);
30
31@@ -201,6 +205,9 @@
32 var art_widget = new scopes.lib.PreviewWidget("imageId", "image");
33 art_widget.add_attribute_mapping("source", "art");
34
35+ var update_preview_button_widget =
36+ createUpdatePreviewActionsIdWidget("Update");
37+
38 var actions_widget = new scopes.lib.PreviewWidget("actionsId", "actions");
39 actions_widget.add_attribute_value(
40 "actions",
41@@ -220,8 +227,15 @@
42 }
43 ]
44 );
45- preview_reply.push([header_widget, art_widget, actions_widget])
46- preview_reply.finished()
47+
48+ preview_reply.push([
49+ header_widget,
50+ art_widget,
51+ actions_widget,
52+ update_preview_button_widget
53+ ]);
54+
55+ preview_reply.finished();
56 },
57 // cancelled
58 function() {
59@@ -254,10 +268,20 @@
60 action_id,
61 // activate
62 function() {
63- console.log('activate called')
64-
65- return new scopes.lib.ActivationResponse(
66- scopes.defs.ActivationResponseStatus.NotHandled);
67+ console.log('activate called');
68+
69+ var result;
70+ switch (action_id) {
71+ case 'updateId':
72+ result = activateUpdatePreview();
73+ break;
74+ default:
75+ result = new scopes.lib.ActivationResponse(
76+ scopes.defs.ActivationResponseStatus.NotHandled);
77+ break;
78+ }
79+
80+ return result;
81 },
82 // cancelled
83 function() {
84@@ -266,3 +290,31 @@
85 }
86 }
87 );
88+
89+/**
90+ * Updates the "updatePreviewActionsId" widget:
91+ * Sets the widget's label to "Updated !".
92+ */
93+function activateUpdatePreview(result) {
94+ var widgets = [];
95+ var update_preview_button_widget =
96+ createUpdatePreviewActionsIdWidget("Updated !");
97+ widgets.push(update_preview_button_widget);
98+ return new scopes.lib.ActivationResponse(widgets);
99+}
100+
101+function createUpdatePreviewActionsIdWidget(label) {
102+ var update_preview_button_widget =
103+ new scopes.lib.PreviewWidget("updatePreviewActionsId", "actions");
104+ update_preview_button_widget.add_attribute_value(
105+ "actions",
106+ [
107+ {
108+ id: "updateId",
109+ label: label
110+ }
111+ ]
112+ );
113+ return update_preview_button_widget;
114+}
115+
116
117=== modified file 'src/bindings/src/activation-response.cc'
118--- src/bindings/src/activation-response.cc 2016-02-13 20:54:36 +0000
119+++ src/bindings/src/activation-response.cc 2016-02-15 20:51:32 +0000
120@@ -17,6 +17,7 @@
121 */
122
123 #include "activation-response.h"
124+#include "preview-widget.h"
125
126 #include "event_queue.h"
127
128@@ -34,6 +35,21 @@
129 new unity::scopes::ActivationResponse(
130 static_cast<unity::scopes::ActivationResponse::Status>(
131 status)));
132+ } else if (arg->IsArray()) {
133+ // assume UpdatePreview
134+ std::vector<std::shared_ptr<PreviewWidget>> const& widgets =
135+ v8cpp::from_v8<std::vector<std::shared_ptr<PreviewWidget>>>(
136+ v8::Isolate::GetCurrent(),
137+ arg);
138+
139+ unity::scopes::PreviewWidgetList widgets_list;
140+ for (auto const& widget : widgets)
141+ {
142+ widgets_list.push_back(widget->preview_widget());
143+ }
144+
145+ activation_response_.reset(
146+ new unity::scopes::ActivationResponse(widgets_list));
147 } else {
148 auto query =
149 v8cpp::from_v8<std::shared_ptr<CannedQuery>>(
150
151=== modified file 'src/bindings/src/activation-response.h'
152--- src/bindings/src/activation-response.h 2016-02-13 20:54:36 +0000
153+++ src/bindings/src/activation-response.h 2016-02-15 20:51:32 +0000
154@@ -41,7 +41,7 @@
155 --doc:constructor
156 *
157 * @constructor
158- * @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 executed
159+ * @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
160 --/doc:constructor
161
162 --doc:prototype ActivationResponse

Subscribers

People subscribed via source and target branches

to all changes: