Merge lp:~widelands-dev/widelands-website/encyclopedia_beautification into lp:widelands-website

Proposed by kaputtnik
Status: Merged
Merged at revision: 453
Proposed branch: lp:~widelands-dev/widelands-website/encyclopedia_beautification
Merge into: lp:widelands-website
Diff against target: 487 lines (+249/-161)
7 files modified
media/css/help.css (+9/-1)
media/js/encyclopedia.js (+107/-0)
templates/wlhelp/base.html (+2/-1)
templates/wlhelp/buildings.html (+103/-78)
templates/wlhelp/index.html (+13/-5)
templates/wlhelp/inlines/display_buildings.html (+15/-2)
widelandslib/conf.py (+0/-74)
To merge this branch: bzr merge lp:~widelands-dev/widelands-website/encyclopedia_beautification
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+319645@code.launchpad.net

Commit message

Encyclopedia: Redesign of startpage and filter for buildings

Description of the change

To post a comment you must log in.
460. By kaputtnik

possibility to search only for size/type; added comments

461. By kaputtnik

added smooth scrolling; played with js

Revision history for this message
kaputtnik (franku) wrote :

Addressed the nits from https://bugs.launchpad.net/widelands-website/+bug/336021/comments/24

Merged and deployed now.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'media/css/help.css'
2--- media/css/help.css 2015-09-16 20:21:15 +0000
3+++ media/css/help.css 2017-03-14 20:13:56 +0000
4@@ -22,4 +22,12 @@
5
6 img.icon {
7 margin: 0px 10px 10px 0px;
8-}
9\ No newline at end of file
10+}
11+
12+/* Let Table headers look like h2 */
13+caption{
14+ font-size: 1.5em;
15+ color: #181;
16+ margin: 0.8em 0em 0.5em 0em;
17+ white-space: nowrap;
18+}
19
20=== added file 'media/js/encyclopedia.js'
21--- media/js/encyclopedia.js 1970-01-01 00:00:00 +0000
22+++ media/js/encyclopedia.js 2017-03-14 20:13:56 +0000
23@@ -0,0 +1,107 @@
24+$(document).ready(function() {
25+ var elem = document.getElementById('set_display');
26+ elem.addEventListener('click', set_display);
27+ // Find names of checkboxes:
28+ checkb_names = get_input_names();
29+ // Initialize after reload, e.g. pressing F5:
30+ init_checkboxes();
31+
32+ // Smooth scrolling, taken from
33+ // http://stackoverflow.com/a/18795112
34+ $('a[href*=#]').click(function(event){
35+ $('html, body').animate({
36+ scrollTop: $( $.attr(this, 'href') ).offset().top
37+ }, 500);
38+ event.preventDefault();
39+ });
40+});
41+
42+function get_input_names(){
43+ var inp = document.getElementById('size_select').getElementsByTagName('input');
44+ var n = [];
45+ for (var i=0; i<inp.length; i++){
46+ if (! n.includes(inp[i].name)){
47+ n.push(inp[i].name);
48+ }
49+ }
50+ return n;
51+}
52+
53+function set_display(){
54+ // Hide/unhide tables and/or rows
55+ // Tables get hidden when filtering by size
56+ // Rows get hidden when filtering by type
57+ for (var y=0; y<checkb_names.length; y++){
58+ var option_boxes = document.getElementsByName(checkb_names[y]);
59+ if ( check_checked(option_boxes) === false ){
60+ // Mark all as checked if none is checked for one type of filter
61+ // This makes it possible to search e.g. for all of type
62+ // 'Production' (and no 'size' is checked), or all of size
63+ // 'Big' (and no 'type' is checked)
64+ for (var j=0; j<option_boxes.length; j++){
65+ option_boxes[j].checked = true;
66+ }
67+ }
68+ for (var i = 0; i < option_boxes.length; i++) {
69+ var elements = document.getElementsByName(option_boxes[i].value);
70+ hide_unhide_elements(elements, option_boxes[i].checked);
71+ }
72+ }
73+ // Filtering by type may lead into empty tables resulting in showing just
74+ // rows with <th> or caption
75+ hide_empty_tables();
76+}
77+
78+function hide_unhide_elements(elem_list, checked){
79+ elem_list.forEach( function(elem){
80+ if (checked){
81+ elem.style.display = '';
82+ }else{
83+ elem.style.display = 'none';
84+ }
85+ });
86+}
87+
88+function check_checked(chb_list){
89+ // Check if none of the checkbox is checked in this list
90+ var c=0;
91+ chb_list.forEach( function(chb){
92+ if (! chb.checked){
93+ c++;
94+ }
95+ });
96+ if (c == chb_list.length){
97+ return false;
98+ }
99+ return true;
100+}
101+
102+function hide_empty_tables(){
103+ // Hide a table if no row is displayed in it
104+ var tables = document.getElementsByTagName('table');
105+ for (var i=0; i<tables.length; i++){
106+ var table = tables[i];
107+ var hidden_rows = 0;
108+ for (var x=0, row; row = table.rows[x]; x++){
109+ if (row.style.display == 'none'){
110+ hidden_rows++;
111+ }
112+ }
113+ // +1 here because we need to count also <th>
114+ if (table.rows.length == hidden_rows+1){
115+ table.style.display = 'none';
116+ }else{
117+ table.style.display = '';
118+ }
119+ }
120+}
121+
122+function init_checkboxes(){
123+ // Mark all checkboxes as checked
124+ for (var x=0; x<checkb_names.length; x++){
125+ var option_boxes = document.getElementsByName(checkb_names[x]);
126+ for (i=0; i < option_boxes.length; i++){
127+ option_boxes[i].checked = true;
128+ }
129+ }
130+}
131
132=== modified file 'templates/wlhelp/base.html'
133--- templates/wlhelp/base.html 2015-02-18 22:30:08 +0000
134+++ templates/wlhelp/base.html 2017-03-14 20:13:56 +0000
135@@ -5,6 +5,7 @@
136 {% endblock %}
137
138 {% block extra_head %}
139-<link rel="stylesheet" type="text/css" media="all" href="{{ MEDIA_URL }}css/help.css" />
140+ <link rel="stylesheet" type="text/css" media="all" href="{{ MEDIA_URL }}css/help.css" />
141+ <script type="text/javascript" src="{{ MEDIA_URL }}js/encyclopedia.js"></script>
142 {{ block.super}}
143 {% endblock %}
144\ No newline at end of file
145
146=== modified file 'templates/wlhelp/buildings.html'
147--- templates/wlhelp/buildings.html 2016-03-02 21:02:38 +0000
148+++ templates/wlhelp/buildings.html 2017-03-14 20:13:56 +0000
149@@ -10,86 +10,111 @@
150 {% block content %}
151 <h1>{{ tribe.displayname }}: Buildings</h1>
152 <div class="blogEntry">
153+ <div class="posRight">
154+ <form id="size_select">
155+ <fieldset style="display: inline; border: none">
156+ {# Attribute 'name': Groups filters (sizes/types) #}
157+ {# Attribute 'value': Corresponding names of html elements (tables/rows) #}
158+ <legend>Show Buildings by Size and/or Type:</legend>
159+ <input type="checkbox" id="small" name="sizes" value="size-S" checked="checked" />
160+ <label for="small">Small</label>
161+ <input type="checkbox" id="medium" name="sizes" value="size-M" checked="checked" />
162+ <label for="medium">Medium</label>
163+ <input type="checkbox" id="big" name="sizes" value="size-B" checked="checked" />
164+ <label for="big">Big</label>
165+ <input type="checkbox" id="mines" name="sizes" value="size-I" checked="checked" />
166+ <label for="mines">Mines</label><br />
167+ <input type="checkbox" id="warehouse" name="types" value="type-W" checked="checked" />
168+ <label for="warehouse">Warehouse</label>
169+ <input type="checkbox" id="production" name="types" value="type-P" checked="checked" />
170+ <label for="production">Production</label>
171+ <input type="checkbox" id="military" name="types" value="type-M" checked="checked" />
172+ <label for="military">Military</label>
173+ <input type="checkbox" id="training" name="types" value="type-T" checked="checked" />
174+ <label for="training">Trainingsites</label><br />
175+ <button type="button" id="set_display" class="button">Update</button>
176+ </fieldset>
177+ </form>
178+ </div>
179 <a href="{% url 'wlhelp_index' %}">Encyclopedia</a> &#187;
180 <a href="{% url 'wlhelp_tribe_details' tribe.name %}">{{ tribe.displayname }}</a> &#187;
181 Buildings
182- <br /><br />
183-
184-{# Headquarters #}
185- <h2>Headquarters</h2>
186- {% with buildings.headquarters as buildings %}
187- {% include "wlhelp/inlines/display_buildings.html" %}
188- {% endwith %}
189-
190-{# Small buildings #}
191-{% if buildings.small.count %}
192- <h2>Small Buildings</h2>
193- {% with buildings.small as buildings %}
194- {% include "wlhelp/inlines/display_buildings.html" %}
195- {% endwith %}
196-{% endif %}
197-{% if buildings.small_enhanced.count %}
198- <h2>Small Enhanced Buildings</h2>
199- {% with buildings.small_enhanced as buildings %}
200- {% include "wlhelp/inlines/display_buildings.html" %}
201- {% endwith %}
202-{% endif %}
203-
204-{# Medium buildings #}
205-{% if buildings.medium.count %}
206- <h2>Medium Buildings</h2>
207- {% with buildings.medium as buildings %}
208- {% include "wlhelp/inlines/display_buildings.html" %}
209- {% endwith %}
210-{% endif %}
211-{% if buildings.medium_enhanced.count %}
212- <h2>Medium Enhanced Buildings</h2>
213- {% with buildings.medium_enhanced as buildings %}
214- {% include "wlhelp/inlines/display_buildings.html" %}
215- {% endwith %}
216-{% endif %}
217-
218-{# Big buildings #}
219-{% if buildings.big.count %}
220- <h2>Big Buildings</h2>
221- {% with buildings.big as buildings %}
222- {% include "wlhelp/inlines/display_buildings.html" %}
223- {% endwith %}
224-{% endif %}
225-{% if buildings.big_enhanced.count %}
226- <h2>Big Enhanced Buildings</h2>
227- {% with buildings.big_enhanced as buildings %}
228- {% include "wlhelp/inlines/display_buildings.html" %}
229- {% endwith %}
230-{% endif %}
231-
232-{# Mines #}
233-{% if buildings.mine.count %}
234- <h2>Mines</h2>
235- {% with buildings.mine as buildings %}
236- {% include "wlhelp/inlines/display_buildings.html" %}
237- {% endwith %}
238-{% endif %}
239-{% if buildings.mine_enhanced.count %}
240- <h2>Enhanced Mines</h2>
241- {% with buildings.mine_enhanced as buildings %}
242- {% include "wlhelp/inlines/display_buildings.html" %}
243- {% endwith %}
244-{% endif %}
245-
246-{# Ports #}
247-{% if buildings.port.count %}
248- <h2>Ports</h2>
249- {% with buildings.port as buildings %}
250- {% include "wlhelp/inlines/display_buildings.html" %}
251- {% endwith %}
252-{% endif %}
253-{% if buildings.port_enhanced.count %}
254- <h2>Enhanced Ports</h2>
255- {% with buildings.port_enhanced as buildings %}
256- {% include "wlhelp/inlines/display_buildings.html" %}
257- {% endwith %}
258-{% endif %}
259-
260+
261+ {# Headquarters #}
262+ <div name="size-B">
263+ {% with buildings.headquarters as buildings %}
264+ {% include "wlhelp/inlines/display_buildings.html" with header="Headquarters" %}
265+ {% endwith %}
266+ </div>
267+
268+ <div name="size-S">
269+ {# Small buildings #}
270+ {% if buildings.small.count %}
271+ {% with buildings.small as buildings %}
272+ {% include "wlhelp/inlines/display_buildings.html" with header="Small Buildings" %}
273+ {% endwith %}
274+ {% endif %}
275+ {% if buildings.small_enhanced.count %}
276+ {% with buildings.small_enhanced as buildings %}
277+ {% include "wlhelp/inlines/display_buildings.html" with header="Small Enhanced Buildings" %}
278+ {% endwith %}
279+ {% endif %}
280+ </div>
281+
282+ <div name="size-M">
283+ {# Medium buildings #}
284+ {% if buildings.medium.count %}
285+ {% with buildings.medium as buildings %}
286+ {% include "wlhelp/inlines/display_buildings.html" with header="Medium Buildings" %}
287+ {% endwith %}
288+ {% endif %}
289+ {% if buildings.medium_enhanced.count %}
290+ {% with buildings.medium_enhanced as buildings %}
291+ {% include "wlhelp/inlines/display_buildings.html" with header="Medium Enhanced Buildings" %}
292+ {% endwith %}
293+ {% endif %}
294+ </div>
295+
296+ <div name="size-B">
297+ {# Big buildings #}
298+ {% if buildings.big.count %}
299+ {% with buildings.big as buildings %}
300+ {% include "wlhelp/inlines/display_buildings.html" with header="Big Buildings" %}
301+ {% endwith %}
302+ {% endif %}
303+ {% if buildings.big_enhanced.count %}
304+ {% with buildings.big_enhanced as buildings %}
305+ {% include "wlhelp/inlines/display_buildings.html" with header="Big Enhanced Buildings" %}
306+ {% endwith %}
307+ {% endif %}
308+ </div>
309+
310+ <div name="size-I">
311+ {# Mines #}
312+ {% if buildings.mine.count %}
313+ {% with buildings.mine as buildings %}
314+ {% include "wlhelp/inlines/display_buildings.html" with header="Mines" %}
315+ {% endwith %}
316+ {% endif %}
317+ {% if buildings.mine_enhanced.count %}
318+ {% with buildings.mine_enhanced as buildings %}
319+ {% include "wlhelp/inlines/display_buildings.html" with header="Enhanced Mines" %}
320+ {% endwith %}
321+ {% endif %}
322+ </div>
323+
324+ <div name="size-B">
325+ {# Ports #}
326+ {% if buildings.port.count %}
327+ {% with buildings.port as buildings %}
328+ {% include "wlhelp/inlines/display_buildings.html" with header="Ports" %}
329+ {% endwith %}
330+ {% endif %}
331+ {% if buildings.port_enhanced.count %}
332+ {% with buildings.port_enhanced as buildings %}
333+ {% include "wlhelp/inlines/display_buildings.html" with header="Enhanced Ports" %}
334+ {% endwith %}
335+ {% endif %}
336+ </div>
337 </div>
338 {% endblock %}
339
340=== modified file 'templates/wlhelp/index.html'
341--- templates/wlhelp/index.html 2016-07-02 12:38:06 +0000
342+++ templates/wlhelp/index.html 2017-03-14 20:13:56 +0000
343@@ -11,12 +11,20 @@
344 <h1>Encyclopedia</h1>
345 <div class="blogEntry">
346 Encyclopedia &#187; Index
347-<br /><br />
348-<p>This is a list of all tribes in Widelands:</p>
349-<ul>
350+<h2>All Tribes in Widelands:</h2>
351 {% for tribe in tribes %}
352- <li><a href="{% url 'wlhelp_tribe_details' tribe.name %}">{{ tribe.displayname }}</a></li>
353+<p><img class="posLeft icon" src="{{ tribe.icon_url }}" alt="">
354+ <a href="{% url 'wlhelp_tribe_details' tribe.name %}"><b>{{ tribe.displayname }}</b></a><br />
355+ {{ tribe.descr }}</p>
356+ <ul style="list-style: circle; margin-left: 1em; margin-top: -0.2em;">
357+ <li><a href="{% url 'wlhelp_buildings' tribe.name %}">Buildings</a></li>
358+ <li><a href="{% url 'wlhelp_wares' tribe.name %}">Wares</a></li>
359+ <li><a href="{% url 'wlhelp_workers' tribe.name %}">Workers</a></li>
360+ <li><a href="{{ tribe.network_pdf_url }}" target="_blank">Economy Network as PDF</a></li>
361+ <li><a href="{{ tribe.network_gif_url }}" target="_blank">Economy Network as GIF</a></li>
362+ </ul>
363+ </li>
364+</ul>
365 {% endfor %}
366-</ul>
367 </div>
368 {% endblock %}
369
370=== modified file 'templates/wlhelp/inlines/display_buildings.html'
371--- templates/wlhelp/inlines/display_buildings.html 2016-07-02 12:38:06 +0000
372+++ templates/wlhelp/inlines/display_buildings.html 2017-03-14 20:13:56 +0000
373@@ -1,4 +1,5 @@
374 <table class="help">
375+ <caption class="posLeft">{{ header }}</caption>
376 <tr>
377 <th>Image</th>
378 <th>Description</th>
379@@ -7,7 +8,7 @@
380 <th>Stores</th>
381 </tr>
382 {% for b in buildings %}
383- <tr class="{% cycle "odd" "even" %}">
384+ <tr class="{% cycle "odd" "even" %}" name="type-{{ b.type }}">
385 <td>
386 <a href="{% url 'wlhelp_building_details' b.tribe.name b.name %}" title="{{ b.displayname }}" id="{{ b.name }}">
387 {{ b.displayname }}
388@@ -15,7 +16,19 @@
389 <img alt="{{b.displayname}}" src="{{ b.image_url }}" />
390 </a>
391 </td>
392- <td>{{ b.help }}</td>
393+ <td>
394+ {{ b.help }}
395+ {% if b.enhanced_from or b.enhancement %}
396+ <ul>
397+ {% if b.enhanced_from %}
398+ <li>Could be enhanced from: <a href="#{{ b.enhanced_from.name }}">{{ b.enhanced_from.displayname }}</a></li>
399+ {% endif %}
400+ {% if b.enhancement %}
401+ <li>Could be enhanced to: <a href="#{{ b.enhancement.name }}">{{ b.enhancement.displayname}}</a></li>
402+ {% endif %}
403+ </ul>
404+ {% endif %}
405+ </td>
406 <td>
407 {% for costs in b.get_build_cost %}
408 {% for w in costs %}
409
410=== removed file 'widelandslib/conf.py'
411--- widelandslib/conf.py 2016-12-13 18:28:51 +0000
412+++ widelandslib/conf.py 1970-01-01 00:00:00 +0000
413@@ -1,74 +0,0 @@
414-#!/usr/bin/env python -tt
415-# encoding: utf-8
416-
417-from ConfigParser import *
418-import cStringIO
419-
420-__all__ = [
421- 'WidelandsConfigParser'
422-]
423-
424-
425-def clear_string(s):
426- idx = s.find('#')
427- if idx != -1:
428- s = s[:idx]
429-
430- s = s.strip("'\" _")
431- return s
432-
433-
434-class WidelandsConfigParser(SafeConfigParser):
435-
436- def __init__(self, fn):
437- """
438- Basically we only add one option: getstring which removes
439- ticks and '_' (the translation marker)
440- """
441- SafeConfigParser.__init__(self)
442-
443- string = ''
444- try:
445- string = fn.read()
446- except AttributeError:
447- string = open(fn, 'r').read()
448-
449- string = string.replace('%', '%%')
450-
451- try:
452- self.readfp(cStringIO.StringIO(string))
453- except MissingSectionHeaderError:
454- string = '[global]\n' + string
455- self.readfp(cStringIO.StringIO(string))
456-
457- def items(self, *args, **kwargs):
458- return dict(
459- (k, clear_string(v)) for (k, v) in
460- SafeConfigParser.items(self, *args, **kwargs)
461- ).items()
462-
463- def getstring(self, s, opt, default=None):
464- try:
465- return clear_string(self.get(s, opt))
466- except NoOptionError:
467- if default is not None:
468- return default
469- raise
470-
471- def getint(self, s, opt, default=None):
472- try:
473- return SafeConfigParser.getint(self, s, opt)
474- except NoOptionError:
475- if default is not None:
476- return default
477- raise
478- except ValueError:
479- return int(clear_string(SafeConfigParser.get(self, s, opt)))
480-
481- def getboolean(self, s, opt, default=None):
482- try:
483- return SafeConfigParser.getboolean(self, s, opt)
484- except NoOptionError:
485- if default is not None:
486- return default
487- raise

Subscribers

People subscribed via source and target branches