Commit 93fac5d4 authored by Nicolas Joyard's avatar Nicolas Joyard
Browse files

Rework sort UX

parent c160c418
Damiano ZOFFOLI,damiano.zoffoli@europarl.europa.eu,SD,Italy [IT]
Werner LANGEN,werner.langen@europarl.europa.eu,EPP,Germany [DE]
Hermann WINKLER,hermann.winkler@europarl.europa.eu,EPP,Germany [DE]
Kerstin WESTPHAL,kerstin.westphal@europarl.europa.eu,SD,Germany [DE]
Renate WEBER,renate.weber@europarl.europa.eu,ALDE,Ireland [IE]
Axel VOSS,axel.voss@europarl.europa.eu,EPP,Germany [DE]
Philippe Vigier,pvigier@assemblee-nationale.fr,UDI,France [FR]
Albert DESS,albert.dess@europarl.europa.eu,EPP,Germany [DE]
László TŐKÉS,laszlo.tokes@europarl.europa.eu,EPP,Hungary [HU]
Helga STEVENS,helga.stevens@europarl.europa.eu,ECR,Belgium [BE]
Joachim SCHUSTER,joachim.schuster@europarl.europa.eu,SD,Germany [DE]
Annie SCHREIJER-PIERIK,annie.schreijer-pierik@europarl.europa.eu,EPP,Netherlands [NL]
Verónica LOPE FONTAGNÉ,veronica.lopefontagne@europarl.europa.eu,EPP,Spain [ES]
Esther de LANGE,esther.delange@europarl.europa.eu,EPP,Netherlands [NL]
Angelika NIEBLER,angelika.niebler@europarl.europa.eu,EPP,Germany [DE]
Mirosław PIOTROWSKI,miroslaw.piotrowski@europarl.europa.eu,ECR,Poland [PL]
Thierry Benoit,"tbenoit@assemblee-nationale.fr, contact@thierry-benoit.fr",UDI,France [FR]
Pierre Lequiller,"plequiller@assemblee-nationale.fr, pierre.lequiller@gmail.com",LR,France [FR]
Claude Goasguen,cgoasguen@assemblee-nationale.fr,LR,France [FR]
Marc Dolez,"mdolez@assemblee-nationale.fr, contact@marc-dolez.org",GDR,France [FR]
Pierre Lellouche,plellouche@assemblee-nationale.fr,LR,France [FR]
Philippe Vigier,pvigier@assemblee-nationale.fr,UDI,France [FR]
Marcel Bonnot,"marcelbonnot@yahoo.fr, mbonnot@assemblee-nationale.fr",LR,France [FR]
Philippe Houillon,phouillon@assemblee-nationale.fr,LR,France [FR]
Dominique Dord,ddord@assemblee-nationale.fr,LR,France [FR]
Jean-Michel Couve,"couve.jean-michel@wanadoo.fr, jmcouve@assemblee-nationale.fr",LR,France [FR]
Pascale Got,pgot@assemblee-nationale.fr,SER,France [FR]
Alain Moyne-Bressand,"moyne-bressand.alain@wanadoo.fr, amoyne-bressand@assemblee-nationale.fr",LR,France [FR]
Jean-Louis Christ,"christjl@wanadoo.fr, jlchrist@assemblee-nationale.fr",LR,France [FR]
Olivier Dussopt,odussopt@assemblee-nationale.fr,SER,France [FR]
Jean-Claude Bouchet,"jcbouchet@assemblee-nationale.fr, jcbouchet@jcbouchet.fr",LR,France [FR]
Daniel Fasquelle,dfasquelle@assemblee-nationale.fr,LR,France [FR]
André Santini,asantini@assemblee-nationale.fr,UDI,France [FR]
Marcel Rogemont,"marcel.rogemont@wanadoo.fr, mrogemont@assemblee-nationale.fr",SER,France [FR]
Franck Reynier,freynier@assemblee-nationale.fr,UDI,France [FR]
Jean-Luc Reitzer,"jlr.depute@orange.fr, jlreitzer@assemblee-nationale.fr, jeanluc.reitzer@wanadoo.fr",LR,France [FR]
Marcel Rogemont,"marcel.rogemont@wanadoo.fr, mrogemont@assemblee-nationale.fr",SER,France [FR]
François Pupponi,fpupponi@assemblee-nationale.fr,SER,France [FR]
Mirosław PIOTROWSKI,miroslaw.piotrowski@europarl.europa.eu,ECR,Poland [PL]
Patrick O'FLYNN,patrick.oflynn@europarl.europa.eu,EFDD,United Kingdom [GB]
Paul NUTTALL,paul.nuttall@europarl.europa.eu,EFDD,United Kingdom [GB]
Angelika NIEBLER,angelika.niebler@europarl.europa.eu,EPP,Germany [DE]
Alain Moyne-Bressand,"moyne-bressand.alain@wanadoo.fr, amoyne-bressand@assemblee-nationale.fr",LR,France [FR]
Gesine MEISSNER,gesine.meissner@europarl.europa.eu,ALDE,Germany [DE]
Philippe Martin,pmartin@assemblee-nationale.fr,SER,France [FR]
Jacqueline Maquet,"j-maquet@orange.fr, jmaquet@assemblee-nationale.fr",SER,France [FR]
Verónica LOPE FONTAGNÉ,veronica.lopefontagne@europarl.europa.eu,EPP,Spain [ES]
Arne LIETZ,arne.lietz@europarl.europa.eu,SD,Germany [DE]
Pierre Lequiller,"plequiller@assemblee-nationale.fr, pierre.lequiller@gmail.com",LR,France [FR]
Annick Lepetit,"alepetit@assemblee-nationale.fr, annick-lepetit@wanadoo.fr",SER,France [FR]
Pierre Lellouche,plellouche@assemblee-nationale.fr,LR,France [FR]
Jo LEINEN,jo.leinen@europarl.europa.eu,SD,Germany [DE]
Werner LANGEN,werner.langen@europarl.europa.eu,EPP,Germany [DE]
Jean-Luc Reitzer,"jlr.depute@orange.fr, jlreitzer@assemblee-nationale.fr, jeanluc.reitzer@wanadoo.fr",LR,France [FR]
Czesław HOC,czeslaw.hoc@europarl.europa.eu,ECR,Poland [PL]
Dietmar KÖSTER,dietmar.koester@europarl.europa.eu,SD,Germany [DE]
Jan KELLER,jan.keller@europarl.europa.eu,SD,Czech Republic [CZ]
Patrick O'FLYNN,patrick.oflynn@europarl.europa.eu,EFDD,United Kingdom [GB]
Sylvia-Yvonne KAUFMANN,sylvia-yvonne.kaufmann@europarl.europa.eu,SD,Germany [DE]
Philippe Houillon,phouillon@assemblee-nationale.fr,LR,France [FR]
Czesław HOC,czeslaw.hoc@europarl.europa.eu,ECR,Poland [PL]
Iveta GRIGULE,iveta.grigule@europarl.europa.eu,ALDE,Latvia [LV]
Arne LIETZ,arne.lietz@europarl.europa.eu,SD,Germany [DE]
Annie SCHREIJER-PIERIK,annie.schreijer-pierik@europarl.europa.eu,EPP,Netherlands [NL]
Bolesław G. PIECHA,boleslaw.piecha@europarl.europa.eu,ECR,Poland [PL]
Pascale Got,pgot@assemblee-nationale.fr,SER,France [FR]
Claude Goasguen,cgoasguen@assemblee-nationale.fr,LR,France [FR]
Paul NUTTALL,paul.nuttall@europarl.europa.eu,EFDD,United Kingdom [GB]
Jan KELLER,jan.keller@europarl.europa.eu,SD,Czech Republic [CZ]
Iveta GRIGULE,iveta.grigule@europarl.europa.eu,ALDE,Latvia [LV]
Paul BRANNEN,paul.brannen@europarl.europa.eu,SD,United Kingdom [GB]
María Teresa GIMÉNEZ BARBAT,teresa.gimenezbarbat@europarl.europa.eu,ALDE,Ireland [IE]
Daniel Fasquelle,dfasquelle@assemblee-nationale.fr,LR,France [FR]
Olivier Dussopt,odussopt@assemblee-nationale.fr,SER,France [FR]
Dominique Dord,ddord@assemblee-nationale.fr,LR,France [FR]
Marc Dolez,"mdolez@assemblee-nationale.fr, contact@marc-dolez.org",GDR,France [FR]
Albert DESS,albert.dess@europarl.europa.eu,EPP,Germany [DE]
Esther de LANGE,esther.delange@europarl.europa.eu,EPP,Netherlands [NL]
Jean-Michel Couve,"couve.jean-michel@wanadoo.fr, jmcouve@assemblee-nationale.fr",LR,France [FR]
Jean-Louis Christ,"christjl@wanadoo.fr, jlchrist@assemblee-nationale.fr",LR,France [FR]
Helga STEVENS,helga.stevens@europarl.europa.eu,ECR,Belgium [BE]
Damiano ZOFFOLI,damiano.zoffoli@europarl.europa.eu,SD,Italy [IT]
Joachim SCHUSTER,joachim.schuster@europarl.europa.eu,SD,Germany [DE]
Jean-Paul Chanteguet,jpchanteguet@assemblee-nationale.fr,SER,France [FR]
Udo BULLMANN,udo.bullmann@europarl.europa.eu,SD,Germany [DE]
Paul BRANNEN,paul.brannen@europarl.europa.eu,SD,United Kingdom [GB]
Jean-Claude Bouchet,"jcbouchet@assemblee-nationale.fr, jcbouchet@jcbouchet.fr",LR,France [FR]
Marcel Bonnot,"marcelbonnot@yahoo.fr, mbonnot@assemblee-nationale.fr",LR,France [FR]
Thierry Benoit,"tbenoit@assemblee-nationale.fr, contact@thierry-benoit.fr",UDI,France [FR]
François Asensi,fasensi@assemblee-nationale.fr,GDR,France [FR]
Renate WEBER,renate.weber@europarl.europa.eu,ALDE,Ireland [IE]
Gesine MEISSNER,gesine.meissner@europarl.europa.eu,ALDE,Germany [DE]
Kerstin WESTPHAL,kerstin.westphal@europarl.europa.eu,SD,Germany [DE]
Jo LEINEN,jo.leinen@europarl.europa.eu,SD,Germany [DE]
Udo BULLMANN,udo.bullmann@europarl.europa.eu,SD,Germany [DE]
<li class="disabled">
<a href="?&amp;sort_by=name">name</a>
<li>
<a href="?&amp;sort=name-desc">Name Z-A</a>
</li>
---
<li class="disabled">
<a href="?&amp;sort_dir=asc">ascending</a>
</li>
---
<li>
<a href="?&amp;sort_dir=desc">descending</a>
</li>
\ No newline at end of file
<a href="?&amp;sort=name-asc">Name A-Z</a>
</li>
\ No newline at end of file
......@@ -24,28 +24,20 @@ class DossierListTest(BaseTest):
self.selector_test('.dossier-card')
def test_navbar_order_options(self):
self.selector_test('#listheader #orderby li, #listheader #orderdir li')
self.selector_test('#listheader #sort-menu li')
def test_navbar_order_title_asc(self):
def test_order_by_title_asc(self):
self.selector_test('.dossier-card h4',
'%s?sort_by=title&sort_dir=asc' % self.url)
'%s?sort=title-asc' % self.url)
def test_navbar_order_title_desc(self):
def test_order_by_title_desc(self):
self.selector_test('.dossier-card h4',
'%s?sort_by=title&sort_dir=desc' % self.url)
'%s?sort=title-desc' % self.url)
def test_navbar_order_nb_proposals_asc(self):
def test_order_by_recommendations(self):
self.selector_test('.dossier-card h4',
'%s?sort_by=nb_proposals&sort_dir=asc' % self.url)
'%s?sort=recommendations' % self.url)
def test_navbar_order_nb_proposals_desc(self):
def test_order_by_proposals(self):
self.selector_test('.dossier-card h4',
'%s?sort_by=nb_proposals&sort_dir=desc' % self.url)
def test_navbar_order_nb_recommendations_asc(self):
self.selector_test('.dossier-card h4',
'%s?sort_by=nb_recommendations&sort_dir=asc' % self.url)
def test_navbar_order_nb_recommendations_desc(self):
self.selector_test('.dossier-card h4',
'%s?sort_by=nb_recommendations&sort_dir=desc' % self.url)
'%s?sort=proposals' % self.url)
......@@ -22,23 +22,23 @@ class RepresentativeListTest(BaseTest):
self.selector_test('.representative-card')
def test_navbar_order_options(self):
self.selector_test('#listheader #orderby li, #listheader #orderdir li')
self.selector_test('#listheader #sort-menu li')
def test_navbar_order_name_asc(self):
def test_order_by_name_asc(self):
self.selector_test('.representative-card h4',
'%s?sort_by=last_name&sort_dir=asc' % self.url)
'%s?sort=name-asc' % self.url)
def test_navbar_order_name_desc(self):
def test_order_by_name_desc(self):
self.selector_test('.representative-card h4',
'%s?sort_by=last_name&sort_dir=desc' % self.url)
'%s?sort=name-desc' % self.url)
def test_navbar_order_score_asc(self):
def test_order_by_score_asc(self):
self.selector_test('.representative-card h4',
'%s?sort_by=score__score&sort_dir=asc' % self.url)
'%s?sort=score-asc' % self.url)
def test_navbar_order_score_desc(self):
def test_order_by_score_desc(self):
self.selector_test('.representative-card h4',
'%s?sort_by=score__score&sort_dir=desc' % self.url)
'%s?sort=score-desc' % self.url)
def test_search_no_results(self):
self.selector_test('.representative-card h4',
......@@ -83,4 +83,4 @@ class RepresentativeListTest(BaseTest):
self.request_test('%s?search=ma&csv' % self.url)
def test_order_csv(self):
self.request_test('%s?sort_by=last_name&sort_dir=desc&csv' % self.url)
self.request_test('%s?sort=score-desc&csv' % self.url)
......@@ -21,12 +21,12 @@ class ThemeListTest(BaseTest):
self.selector_test('.theme-card')
def test_navbar_order_options(self):
self.selector_test('#listheader #orderby li, #listheader #orderdir li')
self.selector_test('#listheader #sort-menu li')
def test_navbar_order_name_asc(self):
def test_order_by_name_asc(self):
self.selector_test('.theme-card h4',
'%s?sort_by=name&sort_dir=asc' % self.url)
'%s?sort=name-asc' % self.url)
def test_navbar_order_name_desc(self):
def test_order_by_name_desc(self):
self.selector_test('.theme-card h4',
'%s?sort_by=name&sort_dir=desc' % self.url)
'%s?sort=name-desc' % self.url)
......@@ -24,13 +24,29 @@ class DossierList(PaginationMixin, SortMixin, PositionFormMixin,
nb_recommendations=Count('proposals__recommendation', distinct=True),
nb_documents=Count('documents', distinct=True)
)
sort_fields = {
'title': 'title',
'nb_recommendations': 'recommendations',
'nb_proposals': 'proposals',
sort_modes = {
'title-asc': {
'order': 0,
'label': 'Title A-Z',
'fields': ['title']
},
'title-desc': {
'order': 1,
'label': 'Title Z-A',
'fields': ['-title']
},
'recommendations': {
'order': 2,
'label': 'Most recommendations',
'fields': ['-nb_recommendations']
},
'proposals': {
'order': 3,
'label': 'Most proposals',
'fields': ['-nb_proposals']
}
}
sort_default_field = 'nb_recommendations'
sort_default_dir = 'desc'
sort_default = 'recommendations'
sort_session_prefix = 'dossier_list'
def dossier_filter(self, qs):
......
......@@ -20,11 +20,29 @@ class RepresentativeList(CSVDownloadMixin, GridListMixin, PaginationMixin,
csv_name = 'representatives'
queryset = Representative.objects.select_related('score')
current_filter = None
sort_fields = {
'last_name': 'name',
'score__score': 'score',
sort_modes = {
'name-asc': {
'order': 0,
'label': 'Name A-Z',
'fields': ['last_name']
},
'name-desc': {
'order': 1,
'label': 'Name Z-A',
'fields': ['-last_name']
},
'score-asc': {
'order': 2,
'label': 'Best score',
'fields': ['-score__score']
},
'score-desc': {
'order': 2,
'label': 'Worst score',
'fields': ['score__score']
}
}
sort_default_field = 'last_name'
sort_default = 'name-asc'
sort_session_prefix = 'representative_list'
def get_context_data(self, **kwargs):
......
......@@ -23,10 +23,19 @@ class ThemeList(PaginationMixin, SortMixin, PositionFormMixin,
nb_positions=Count('positions', distinct=True)
)
sort_fields = {
'name': 'name',
sort_modes = {
'name-asc': {
'order': 0,
'label': 'Name A-Z',
'fields': ['name']
},
'name-desc': {
'order': 0,
'label': 'Name Z-A',
'fields': ['-name']
}
}
sort_default_field = 'name'
sort_default = 'name-asc'
sort_session_prefix = 'theme_list'
def theme_filter(self, qs):
......
......@@ -2,36 +2,20 @@
{% trans "Order by" %}
<div class="btn-group" id="orderby">
<button class="btn btn-default dropdown-toggle" type="button" id="orderby-button" data-toggle="dropdown"
<div class="btn-group" id="sort-menu">
<button class="btn btn-default dropdown-toggle" type="button" id="sort-button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="true">
{% for field, label in sort.fields.items %}
{% if sort.field == field %}{% trans label %}{% endif %}
{% for mode in sort.modes %}
{% if sort.mode == mode.id %}{% trans mode.label %}{% endif %}
{% endfor %}
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="orderby-button">
{% for field, label in sort.fields.items %}
<li {% if sort.field == field %}class="disabled"{% endif %}>
<a href="?{{ sort_by_querystring.urlencode }}&sort_by={{ field }}">{% trans label %}</a>
<ul class="dropdown-menu" aria-labelledby="sort-button">
{% for mode in sort.modes|dictsort:'order' %}
<li {% if sort.mode == mode.id %}class="disabled"{% endif %}>
<a href="?{{ sort_querystring.urlencode }}&sort={{ mode.id }}">{% trans mode.label %}</a>
</li>
{% endfor %}
</ul>
</div>
<div class="btn-group" id="orderdir">
<button class="btn btn-default dropdown-toggle" type="button" id="orderdir-button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="true">
{% if sort.dir == 'asc' %}{% trans "ascending" %}{% else %}{% trans "descending" %}{% endif %}
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="orderdir-button">
<li {% if sort.dir == 'asc' %}class="disabled"{% endif %}>
<a href="?{{ sort_dir_querystring.urlencode }}&sort_dir=asc">{% trans "ascending" %}</a>
</li>
<li {% if sort.dir == 'desc' %}class="disabled"{% endif %}>
<a href="?{{ sort_dir_querystring.urlencode }}&sort_dir=desc">{% trans "descending" %}</a>
</li>
</ul>
</div>
\ No newline at end of file
......@@ -4,7 +4,7 @@
<div class="container-fluid" id="listheader">
<div class="row">
<div class="col-sm-8">
{% if sort.fields|length > 0 %}
{% if sort.modes|length > 0 %}
{% include "blocks/_sorting.html" %}
{% endif %}
</div>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment