Skip to content

Commit

Permalink
(Terrastories#865) Create sort element to allow super-admin to sort c…
Browse files Browse the repository at this point in the history
…ommunities by last updated, date created, and alphabetical (Terrastories#868)

* Add sort buttons to communities dashboard (Terrastories#865)

* Add dashboard translations for sort strings
  • Loading branch information
gVirtu authored Nov 1, 2022
1 parent 9ba7d1b commit 2192c95
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 4 deletions.
4 changes: 3 additions & 1 deletion rails/app/controllers/dashboard/communities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def filter_params
params.permit(
:limit,
:offset,
:name
:name,
:sort_by,
:sort_dir
)
end

Expand Down
14 changes: 11 additions & 3 deletions rails/app/pages/communities_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ class CommunitiesPage < Page
def initialize(meta = {})
@meta = meta

unless %w(name created_at updated_at).include? @meta[:sort_by]
@meta[:sort_by] = nil
end

unless %w(asc desc).include? @meta[:sort_dir]
@meta[:sort_dir] = nil
end

@meta[:limit] ||= 20
@meta[:offset] ||= 0
@meta[:sort_by] ||= "name"
@meta[:sort_dir] ||= "asc"
@meta[:sort_by] ||= "updated_at"
@meta[:sort_dir] ||= "desc"
end

def relation
Expand All @@ -15,4 +23,4 @@ def relation

communities.order(@meta[:sort_by] => @meta[:sort_dir])
end
end
end
9 changes: 9 additions & 0 deletions rails/app/views/dashboard/communities/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
</div>
<%= f.submit t("search.label"), name: nil %>
<% end %>

<div>
<%= t("sort.label") %>
<%= link_to t("sort.updated_at"), communities_url(request.query_parameters.merge(sort_by: "updated_at", sort_dir: "desc")) %>
|
<%= link_to t("sort.created_at"), communities_url(request.query_parameters.merge(sort_by: "created_at", sort_dir: "desc")) %>
|
<%= link_to t("sort.name"), communities_url(request.query_parameters.merge(sort_by: "name", sort_dir: "asc")) %>
</div>
<% end %>

<div class="infinite-scroll">
Expand Down
5 changes: 5 additions & 0 deletions rails/config/locales/am/dashboard.am.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ am:
next: ቀጣይ
no_results: የሚገኙ ምንም %{resources} የሉም።
no_nested_results: ይህ %{resource} %{resources} የለውም።
sort:
label: የተደረደረው በ፡
name: ፊደላት
created_at: ቀን ተፈጠረ
updated_at: ቀን የዘመነ
5 changes: 5 additions & 0 deletions rails/config/locales/en/dashboard.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ en:
next: Next
no_results: There are no %{resources} available.
no_nested_results: This %{resource} has no %{resources}.
sort:
label: "Sort by:"
name: alphabetical
created_at: date created
updated_at: date last updated
5 changes: 5 additions & 0 deletions rails/config/locales/es/dashboard.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ es:
next: Sig
no_results: No hay %{resources} disponibles.
no_nested_results: Este %{resource} no tiene %{resources}.
sort:
label: "Ordenar por:"
name: alfabético
created_at: fecha de creación
updated_at: fecha de última actualización
5 changes: 5 additions & 0 deletions rails/config/locales/ja/dashboard.ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ ja:
next: Next
no_results: There are no %{resources} available.
no_nested_results: This %{resource} has no %{resources}.
sort:
label: "並び替え:"
name: アルファベット順
created_at: 作成日
updated_at: 最終更新日
5 changes: 5 additions & 0 deletions rails/config/locales/mat/dashboard.mat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ mat:
next: Volgende
no_results: Er zijn geen %{resources} beschikbaar.
no_nested_results: Deze %{resource} heeft geen %{resources}.
sort:
label: "Sorteer op:"
name: alfabetisch
created_at: datum gecreeërd
updated_at: datum laatst bijgewerkt
5 changes: 5 additions & 0 deletions rails/config/locales/nl/dashboard.nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ nl:
next: Volgende
no_results: Er zijn geen %{resources} beschikbaar.
no_nested_results: Deze %{resource} heeft geen %{resources}.
sort:
label: "Sorteer op:"
name: alfabetisch
created_at: datum gecreeërd
updated_at: datum laatst bijgewerkt
5 changes: 5 additions & 0 deletions rails/config/locales/pt/dashboard.pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ pt:
next: Prox
no_results: Não há nenhum %{resources} disponível.
no_nested_results: Este %{resource} não contém nenhum %{resources}.
sort:
label: "Ordenar por:"
name: alfabética
created_at: data da criação
updated_at: data da última atualização
5 changes: 5 additions & 0 deletions rails/config/locales/sw/dashboard.sw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ sw:
next: Inayofuata
no_results: Hakuna %{resources} zinazopatikana.
no_nested_results: This %{resource} has no %{resources}.
sort:
label: "Panga kwa:"
name: kialfabeti
created_at: tarehe iliyoundwa
updated_at: tarehe ya sasisho la mwisho
5 changes: 5 additions & 0 deletions rails/config/locales/zh/dashboard.zh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ zh:
next: 下一页
no_results: 此%{resources}不可用。
no_nested_results: 此%{resource}没有%{resources}。
sort:
label: 排序方式:
name: 按字母顺序
created_at: 创建日期
updated_at: 上次更新日期

0 comments on commit 2192c95

Please sign in to comment.