Merge lp:~zematynnad/ubuntu-webcatalog/screenshot_enlarge_845911 into lp:ubuntu-webcatalog

Proposed by Danny Tamez
Status: Merged
Approved by: Anthony Lenton
Approved revision: 117
Merged at revision: 123
Proposed branch: lp:~zematynnad/ubuntu-webcatalog/screenshot_enlarge_845911
Merge into: lp:ubuntu-webcatalog
Diff against target: 300 lines (+127/-81)
7 files modified
src/webcatalog/static/css/carousel.css (+20/-1)
src/webcatalog/static/js/carousel.js (+2/-2)
src/webcatalog/static/js/screenshots.js (+96/-0)
src/webcatalog/templates/light/index.1col.html (+1/-1)
src/webcatalog/templates/webcatalog/application_detail.html (+4/-2)
src/webcatalog/templates/webcatalog/screenshot_widget.html (+4/-58)
src/webcatalog/tests/test_views.py (+0/-17)
To merge this branch: bzr merge lp:~zematynnad/ubuntu-webcatalog/screenshot_enlarge_845911
Reviewer Review Type Date Requested Status
Anthony Lenton (community) Approve
Natalia Bidart (community) Approve
Review via email: mp+102926@code.launchpad.net

Commit message

Adds a panel for enlarged application screenshot images.

Description of the change

Overview
========
This branch adds a panel that displays an enlarged image for the application screenshots.

Details
========
If there are no screnshots and none are loaded via ajax then no panel is needed and no panel is loaded.
If there is a single image or a carousel for multiple screenshots then the panel will be displayed when the user clicks on a thumbnail.

Pic of one screenshot and then the enlarged image:
http://simplest-image-hosting.net/png-0-rz2643
http://simplest-image-hosting.net/png-0-en2643
Pic of carousel and then the enlarged image:
http://simplest-image-hosting.net/png-0-jp2643
http://simplest-image-hosting.net/png-0-md2643

To Test
========
$fab bootstrap test

To post a comment you must log in.
109. By Danny Tamez

Merge from trunk

110. By Danny Tamez

Handle case where the viewer is needed for only 1 screenshot returned via ajax.

111. By Danny Tamez

Removing unneeded assignment.

Revision history for this message
Michael Nelson (michael.nelson) wrote :
Download full text (13.2 KiB)

On Fri, Apr 20, 2012 at 9:54 PM, Danny Tamez <email address hidden> wrote:
> Danny Tamez has proposed merging lp:~zematynnad/ubuntu-webcatalog/screenshot_enlarge_845911 into lp:ubuntu-webcatalog.
>
> Requested reviews:
>  Canonical Consumer Applications Hackers (canonical-ca-hackers)
> Related bugs:
>  Bug #845911 in Ubuntu Apps Directory: "WC should ape USC screenshot behaviour"
>  https://bugs.launchpad.net/ubuntu-webcatalog/+bug/845911
>
> For more details, see:
> https://code.launchpad.net/~zematynnad/ubuntu-webcatalog/screenshot_enlarge_845911/+merge/102926
>
> Overview
> ========
> This branch adds a panel that displays an enlarged image for the application screenshots.
>
> Details
> ========
> If there are no screnshots and none are loaded via ajax then no panel is needed and no panel is loaded.
> If there is a single image or a carousel for multiple screenshots then the panel will be displayed when the user clicks on a thumbnail.
>
> Pic of one screenshot and then the enlarged image:
> http://simplest-image-hosting.net/png-0-rz2643
> http://simplest-image-hosting.net/png-0-en2643
> Pic of carousel and then the enlarged image:
> http://simplest-image-hosting.net/png-0-jp2643
> http://simplest-image-hosting.net/png-0-md2643

Cool - thanks for the screenshots! It looks great!

Just summarising the comments below:
 1) It'd be great if the new JS code that you're adding could be
stripped of any django template code and moved to an external js file
(or YUI module file). The template pages are getting way too much
inline JS IMO (which usually translates to non-reusable code and hard
to understand templates). This would mean the page simply does
something like: new Y.uwc.ScreenshotsPanel({...config options});

Another option is that it could be built-in to the carousel, or a
subclass of the carousel? This would obviously be easier if we updated
the carousel to handle just one image properly rather than having if
statements that only include the carousel when there's > 1 image.

2) If you wanted to and were keen, the same could be done for the
other JS code there, but otherwise I'll create a bug or do it as a
fly-by on another branch at some point.

It may be worth checking with Anthony, as he might have a different
opinion and think it's not worthwhile - if so, I'm happy to +1 this as
is - it just scares me seeing more and more non-reusable JS with
template tags intertwined going directly into our templates.

Let me know what you think!

>
> To Test
> ========
> $fab bootstrap test
> --
> https://code.launchpad.net/~zematynnad/ubuntu-webcatalog/screenshot_enlarge_845911/+merge/102926
> Your team Canonical Consumer Applications Hackers is requested to review the proposed merge of lp:~zematynnad/ubuntu-webcatalog/screenshot_enlarge_845911 into lp:ubuntu-webcatalog.
>
> === modified file 'src/webcatalog/static/css/carousel.css'
> --- src/webcatalog/static/css/carousel.css      2012-04-19 23:05:19 +0000
> +++ src/webcatalog/static/css/carousel.css      2012-04-20 19:53:20 +0000
> @@ -219,3 +219,21 @@
>     top: -15px;
>     clear: both;
>  }
> +.yui3-panel {
> +    outline: none;
> +}
> +#viewerPanel {
> +    -webkit-box-shadow: 0px 0px 2px ...

112. By Danny Tamez

Moved javascript into a reusable function in a separate js file.

113. By Danny Tamez

Adding js file for screenshots.

114. By Danny Tamez

Merge from trunk

115. By Danny Tamez

Removing transitions from screenshot enlarger.

116. By Danny Tamez

Make the height variable to accomodate different screenshot aspect ratios.

Revision history for this message
Danny Tamez (zematynnad) wrote :

Naty,

I've tried to reproduce the problem you're experiencing with the header in 4 different browsers with no luck. Could you please let me know the browser and version you are using to see if I can perhaps duplicate it using that same browser/version?

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

I'm running Firefox 12.0.

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

IRL tested. It works pretty good, there is an issue in a weird, hard-to-reproduce, corner case, that I'm not sure is worth delaying this branch any longer (you can see the video showing this at http://ubuntuone.com/3O3eXt5SH8ZD2yutoZVuNj).

So, Danny and I agreed that:

(04:55:53 PM) zematynnad: do you want to run it by achuni or just leave a note and approve?
(04:56:34 PM) nessita: I can approve, and perhaps you can run this by achuni to get a final sign off? mostly because I'm such an ignorant when it comes to javascript
(04:56:57 PM) zematynnad: sure thing

review: Approve
Revision history for this message
Danny Tamez (zematynnad) wrote :
117. By Danny Tamez

Adding cursor pointer when over the screenshot.

Revision history for this message
Anthony Lenton (elachuni) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/webcatalog/static/css/carousel.css'
2--- src/webcatalog/static/css/carousel.css 2012-04-19 23:05:19 +0000
3+++ src/webcatalog/static/css/carousel.css 2012-05-23 22:59:16 +0000
4@@ -204,7 +204,8 @@
5 }
6 div.screenshot .carousel-wrapper .slide img {
7 margin: 0 auto;
8- display: block
9+ display: block;
10+ cursor: pointer;
11 }
12 div.screenshot .carousel .pagination li a.active {
13 background-color: #DD4814;
14@@ -219,3 +220,21 @@
15 top: -15px;
16 clear: both;
17 }
18+.yui3-panel {
19+ outline: none;
20+}
21+#viewerPanel {
22+ -webkit-box-shadow: 0px 0px 2px black;
23+ -moz-box-shadow: 0px 0px 2px black;
24+ box-shadow: 0px 0px 2px black;
25+}
26+#viewerPanel .yui3-widget-hd {
27+ font-weight: bold;
28+ background:url("/assets/light/images/header_bg.png") repeat-x scroll left top #DD4814;
29+}
30+#viewerPanel .yui3-widget-bd {
31+ padding: 40px 30px 40px;
32+}
33+#viewerPanel .yui3-widget-ft {
34+ background-color: white;
35+}
36
37=== modified file 'src/webcatalog/static/js/carousel.js'
38--- src/webcatalog/static/js/carousel.js 2012-04-18 21:27:46 +0000
39+++ src/webcatalog/static/js/carousel.js 2012-05-23 22:59:16 +0000
40@@ -158,7 +158,7 @@
41 this.caroAnim.run();
42 this.caroAnim.set("duration", origDuration);
43 }
44- },
45+ }
46 }, {
47 NAME: "carousel",
48 ATTRS: {
49@@ -187,5 +187,5 @@
50 });
51 Y.uwc.Carousel = Carousel;
52 }, '0.0.1', {
53- requires: ['base', 'node', 'anim', 'event']
54+ requires: ['base', 'node', 'anim', 'event','panel', 'transition']
55 });
56
57=== added file 'src/webcatalog/static/js/screenshots.js'
58--- src/webcatalog/static/js/screenshots.js 1970-01-01 00:00:00 +0000
59+++ src/webcatalog/static/js/screenshots.js 2012-05-23 22:59:16 +0000
60@@ -0,0 +1,96 @@
61+var setup_screenshots = function(num_screenshots, appName, combo_path, ajax_uri) {
62+ YUI({combine: true, comboBase: combo_path, root: 'yui/3.4.0/build/'}).use('io-base','uwc-carousel', function(Y) {
63+
64+ Y.on('domready', setupViewerPanel, false);
65+ // viewer needs to be setup even if there is only one screenshot and no carousel is used
66+ function setupViewerPanel(addedMoreViaAjax) {
67+ // don't set up if there are no screenshots
68+ if (num_screenshots == 0) {
69+ // but do set up if we get called a second time when adding screenshots via ajax
70+ if (!addedMoreViaAjax) {
71+ return;
72+ }
73+ }
74+ var panel = new Y.Panel({
75+ width: 860,
76+ centered: true,
77+ zIndex: 50,
78+ modal: true,
79+ visible: false,
80+ render: false,
81+ buttons: [
82+ {
83+ value: 'Close',
84+ section: 'footer',
85+ action: function(e) {
86+ e.preventDefault();
87+ panel.hide();
88+ }
89+ }
90+ ]
91+ });
92+ var bb = panel.get('boundingBox');
93+ var slides = Y.all('.slide img');
94+ slides.on("click", function(e){
95+ var slide = e.currentTarget;
96+ var url = slide.getAttribute('src');
97+ heading = appName + ' - screeshot ';
98+ panel.setStdModContent(Y.WidgetStdMod.HEADER, heading);
99+ panel.setStdModContent(Y.WidgetStdMod.BODY, '<img width="800" src="' + url +'"/>');
100+ panel.render('#viewerPanel');
101+ panel.show();
102+ }, this);
103+ }
104+
105+ if (num_screenshots > 1) {
106+ function setup_carousel() {
107+ var caro = new Y.uwc.Carousel({
108+ nodeContainer: "#screenshots-carousel",
109+ controlsContainer: "#nocontrols",
110+ autoPlay: false,
111+ slideAnimDuration: 0.6
112+ });
113+ Y.all('.slide').removeClass('disabled');
114+ }
115+ }
116+
117+ if (num_screenshots == 0) {
118+ var uri = ajax_uri;
119+ function complete(id, obj) {
120+ var json = JSON.parse(obj.responseText);
121+ if (json.length > 1) {
122+ var content_div = document.createElement('div');
123+ content_div.className = 'carousel-wrapper';
124+ var carousel_div = document.createElement('div');
125+ carousel_div.id = 'screenshots-carousel';
126+ carousel_div.className = 'carousel';
127+ content_div.appendChild(carousel_div)
128+ var ol = document.createElement('ol')
129+ ol.className = 'carouselol';
130+ carousel_div.appendChild(ol);
131+ for (var i in json) {
132+ var url = json[i];
133+ var li = document.createElement('li');
134+ li.className = 'slide';
135+ ol.appendChild(li);
136+ var img = document.createElement('img');
137+ img.src = url;
138+ li.appendChild(img);
139+ }
140+ var screenshots_div = Y.one('#screenshots_placeholder');
141+ screenshots_div.get('childNodes').remove();
142+ screenshots_div.appendChild(content_div);
143+ setup_carousel();
144+ setupViewerPanel(true);
145+ } else if (json.lenth == 1) {
146+ // in case we only got back 1 from ajax - still need the viewer
147+ setupViewerPanel(true);
148+ }
149+ };
150+ Y.on('io:complete', complete, Y);
151+ var request = Y.io(uri);
152+ } else {
153+ setup_carousel();
154+ }
155+ });
156+}
157
158=== modified file 'src/webcatalog/templates/light/index.1col.html'
159--- src/webcatalog/templates/light/index.1col.html 2012-04-17 13:52:41 +0000
160+++ src/webcatalog/templates/light/index.1col.html 2012-05-23 22:59:16 +0000
161@@ -8,7 +8,7 @@
162 <link rel="stylesheet" type="text/css" href="{% url wc-combo %}?light/css/reset.css&light/css/styles.css&light/css/forms.css"/>
163 {% endblock %}
164 </head>
165- <body>
166+ <body {% block body_extra %}{% endblock %}>
167 <div id="container">
168 <div id="container-inner">
169 <div id="header">
170
171=== modified file 'src/webcatalog/templates/webcatalog/application_detail.html'
172--- src/webcatalog/templates/webcatalog/application_detail.html 2012-05-04 10:20:34 +0000
173+++ src/webcatalog/templates/webcatalog/application_detail.html 2012-05-23 22:59:16 +0000
174@@ -6,7 +6,7 @@
175 {% block header %}Details for {{ application.name }}{% endblock %}
176 {% block head_extra %}
177 <link rel="stylesheet" type="text/css" href="{% url wc-combo %}?light/css/reset.css&light/css/styles.css&css/webcatalog.css&light/css/forms.css&css/carousel.css"/>
178-<script src="{% url wc-combo %}?yui/3.4.0/build/yui/yui-min.js&js/carousel.js"></script>
179+<script src="{% url wc-combo %}?yui/3.4.0/build/yui/yui-min.js&js/carousel.js&js/screenshots.js"></script>
180 <script>
181 YUI({combine: true, comboBase: '{% url wc-combo %}?', root: 'yui/3.4.0/build/'}).use('io-base', 'node-base', function (Y) {
182
183@@ -39,7 +39,7 @@
184 <meta property="og:title" content="{{ application.name }}" />
185 <meta property="og:image" content="{{ application.icon_url_or_default }}" />
186 {% endblock %}
187-
188+{% block body_extra %}class="yui3-skin-sam"{% endblock %}
189 {% block content %}
190 {% if messages %}
191 {% for message in messages %}
192@@ -141,4 +141,6 @@
193 </div>
194 </div>
195 </div>
196+<div id='viewerPanel'>
197+</div>
198 {% endblock %}
199
200=== modified file 'src/webcatalog/templates/webcatalog/screenshot_widget.html'
201--- src/webcatalog/templates/webcatalog/screenshot_widget.html 2012-04-18 21:27:46 +0000
202+++ src/webcatalog/templates/webcatalog/screenshot_widget.html 2012-05-23 22:59:16 +0000
203@@ -1,4 +1,5 @@
204 {% load url from future %}
205+<div id='console'></div>
206 <div id="screenshots_placeholder">
207 {% if application.screenshots|length_is:0 %}
208 <img src="http://screenshots.ubuntu.com/thumbnail-with-version/{{ application.package_name }}/ignored" />
209@@ -12,61 +13,6 @@
210 </div>
211 {% endif %}
212 </div>
213-
214-{% comment %}
215-If there are multiple screenshots, display a carousel. If there are none,
216-we could retrieve multiple screenshots via AJAX. So only skip this section
217-if the app has exactly 1 screenshot.
218-{% endcomment %}
219-{% if not application.screenshots|length_is:1 %}
220- <script type="text/javascript">
221- YUI({combine: true, comboBase: '{% url 'wc-combo' %}?', root: 'yui/3.4.0/build/'}).use('io-base', 'uwc-carousel', function(Y) {
222-
223- function setup_carousel() {
224- var caro = new Y.uwc.Carousel({
225- nodeContainer: "#screenshots-carousel",
226- controlsContainer: "#nocontrols",
227- autoPlay: false,
228- slideAnimDuration: 0.6
229- });
230- Y.all('.slide').removeClass('disabled');
231- }
232-
233-{% if application.screenshots|length_is:0 %}
234- var uri = "{% url 'wc-package-screenshots' application.package_name %}";
235- function complete(id, obj) {
236- var id = id; // Transaction ID.
237- var json = JSON.parse(obj.responseText);
238- if (json.length > 1) {
239- var content_div = document.createElement('div');
240- content_div.className = 'carousel-wrapper';
241- var carousel_div = document.createElement('div');
242- carousel_div.id = 'screenshots-carousel';
243- carousel_div.className = 'carousel';
244- content_div.appendChild(carousel_div)
245- var ol = document.createElement('ol')
246- ol.className = 'carouselol';
247- carousel_div.appendChild(ol);
248- for (var i in json) {
249- var url = json[i];
250- var li = document.createElement('li');
251- li.className = 'slide';
252- ol.appendChild(li);
253- var img = document.createElement('img');
254- img.src = url;
255- li.appendChild(img);
256- }
257- var screenshots_div = Y.one('#screenshots_placeholder');
258- screenshots_div.get('childNodes').remove();
259- screenshots_div.appendChild(content_div);
260- setup_carousel();
261- }
262- };
263- Y.on('io:complete', complete, Y);
264- var request = Y.io(uri);
265-{% else %}
266- setup_carousel();
267-{% endif %}
268- });
269- </script>
270-{% endif %}
271+<script type="text/javascript" charset="utf-8">
272+ setup_screenshots({{ application.screenshots|length }}, '{{ application.package_name }}', '{% url 'wc-combo' %}?', '{% url 'wc-package-screenshots' application.package_name %}');
273+</script>
274
275=== modified file 'src/webcatalog/tests/test_views.py'
276--- src/webcatalog/tests/test_views.py 2012-05-23 22:28:39 +0000
277+++ src/webcatalog/tests/test_views.py 2012-05-23 22:59:16 +0000
278@@ -338,23 +338,6 @@
279
280 self.assertNotContains(response, '<th>Version</th>')
281
282- def test_with_only_one_screenshot_there_is_no_carousel(self):
283- response, _ = self.get_app_and_response(
284- screenshot_url='http://example.com/screenshot.png')
285-
286- self.assertNotContains(response, 'Y.uwc.Carousel')
287-
288- def test_with_multiple_screenshots_there_is_js_carousel(self):
289- app = self.factory.make_application()
290- for i in range(3):
291- app.applicationmedia_set.create(
292- url='http://example.com/{0}.png'.format(i),
293- media_type='screenshot')
294-
295- response = self.client.get(self.get_app_details_url(app))
296-
297- self.assertContains(response, 'Y.uwc.Carousel', 1)
298-
299 def test_debtags_displayed(self):
300 app = self.factory.make_application(debtags='["joystick"]')
301

Subscribers

People subscribed via source and target branches