diff --git a/app/controllers/account/calculators_controller.rb b/app/controllers/account/calculators_controller.rb index 6d63ff39e..682719813 100644 --- a/app/controllers/account/calculators_controller.rb +++ b/app/controllers/account/calculators_controller.rb @@ -4,6 +4,10 @@ class Account::CalculatorsController < Account::BaseController before_action :calculator, only: [:edit, :update, :destroy] load_and_authorize_resource + def index + @calculators = SortService.new(collection, params).call + end + def show # TODO: fill it end @@ -40,6 +44,10 @@ def destroy private + def collection + Calculator.all + end + def calculator @calculator = Calculator.friendly.find(params[:slug]) end diff --git a/app/controllers/account/products_controller.rb b/app/controllers/account/products_controller.rb index bf9591050..dc689656c 100644 --- a/app/controllers/account/products_controller.rb +++ b/app/controllers/account/products_controller.rb @@ -1,6 +1,6 @@ class Account::ProductsController < Account::BaseController def index - @products = Sort.new(collection, params).sort + @products = SortService.new(collection, params).call end def show diff --git a/app/controllers/account/users_controller.rb b/app/controllers/account/users_controller.rb index 774ade4fb..7bece8a5e 100644 --- a/app/controllers/account/users_controller.rb +++ b/app/controllers/account/users_controller.rb @@ -10,7 +10,7 @@ class Account::UsersController < Account::BaseController load_and_authorize_resource def index - @users = User.all + @users = SortService.new(collection, params).call respond_to do |format| format.html @@ -70,6 +70,10 @@ def user_params prms end + def collection + User.all + end + def resource User.find(params[:id]) end diff --git a/app/helpers/account/products_helper.rb b/app/helpers/account/products_helper.rb deleted file mode 100644 index 56849ae70..000000000 --- a/app/helpers/account/products_helper.rb +++ /dev/null @@ -1,10 +0,0 @@ -module Account::ProductsHelper - def collection - [ - [I18n.t("sort.id_asc"), "id asc"], - [I18n.t("sort.id_desc"), "id desc"], - [I18n.t("sort.title_asc"), "title asc"], - [I18n.t("sort.title_desc"), "title desc"] - ] - end -end diff --git a/app/helpers/account/sort_helper.rb b/app/helpers/account/sort_helper.rb new file mode 100644 index 000000000..e65715aec --- /dev/null +++ b/app/helpers/account/sort_helper.rb @@ -0,0 +1,32 @@ +module Account::SortHelper + def products_criterias + [ + [I18n.t("sort.id_asc"), "id asc"], + [I18n.t("sort.id_desc"), "id desc"], + [I18n.t("sort.title_asc"), "title asc"], + [I18n.t("sort.title_desc"), "title desc"] + ] + end + + def calculators_criterias + [ + [I18n.t("sort.id_asc"), "id asc"], + [I18n.t("sort.id_desc"), "id desc"], + [I18n.t("sort.name_asc"), "name asc"], + [I18n.t("sort.name_desc"), "name desc"], + [I18n.t("sort.slug_asc"), "slug asc"], + [I18n.t("sort.slug_desc"), "slug desc"] + ] + end + + def users_criterias + [ + [I18n.t("sort.id_asc"), "id asc"], + [I18n.t("sort.id_desc"), "id desc"], + [I18n.t("sort.email_asc"), "email asc"], + [I18n.t("sort.email_desc"), "email desc"], + [I18n.t("sort.last_sign_in_at_asc"), "last_sign_in_at asc"], + [I18n.t("sort.last_sign_in_at_desc"), "last_sign_in_at desc"] + ] + end +end diff --git a/app/services/sort.rb b/app/services/sort_service.rb similarity index 90% rename from app/services/sort.rb rename to app/services/sort_service.rb index 2d0653d8f..51ae8a253 100644 --- a/app/services/sort.rb +++ b/app/services/sort_service.rb @@ -1,4 +1,4 @@ -class Sort +class SortService attr_accessor :collection, :params def initialize(collection, params) @@ -6,7 +6,7 @@ def initialize(collection, params) @params = params end - def sort + def call collection.order(sorting_params) end diff --git a/app/views/account/calculators/index.html.slim b/app/views/account/calculators/index.html.slim index bc94840ef..edf091f48 100644 --- a/app/views/account/calculators/index.html.slim +++ b/app/views/account/calculators/index.html.slim @@ -9,6 +9,12 @@ i.fa.fa-plus.mr-2 span =t('.add_calculator_button') + p.d-inline.mr-3 + = t('sort.sort_by') + div.d-inline-block + = form_with method: :get do |form| + = form.select :sort, calculators_criterias, { selected: params[:sort], include_blank: true }, class: 'form-control mr-5', onchange: 'this.form.submit()' + table.table.admin-table thead tr diff --git a/app/views/account/products/index.html.slim b/app/views/account/products/index.html.slim index bc07b9763..42411a94d 100644 --- a/app/views/account/products/index.html.slim +++ b/app/views/account/products/index.html.slim @@ -8,8 +8,7 @@ = t('sort.sort_by') div.d-inline-block = form_with method: :get do |form| - - = form.select :sort, collection, { selected: params[:sort], include_blank: true }, class: 'form-control mr-5', onchange: 'this.form.submit()' + = form.select :sort, products_criterias, { selected: params[:sort], include_blank: true }, class: 'form-control mr-5', onchange: 'this.form.submit()' table.table thead diff --git a/app/views/account/users/index.html.slim b/app/views/account/users/index.html.slim index 80004fd47..7a704ca4c 100644 --- a/app/views/account/users/index.html.slim +++ b/app/views/account/users/index.html.slim @@ -1,9 +1,18 @@ div class="container home" + + .row .col - h1 = t '.main_header' - h3 = link_to icon('fa-solid', 'download'), account_users_path(format: "csv") - table.table + p.d-inline.mr-3 + = t('sort.sort_by') + div.d-inline-block + = form_with method: :get do |form| + = form.select :sort, users_criterias, { selected: params[:sort], include_blank: true }, class: 'form-control mr-5', onchange: 'this.form.submit()' + + h3.d-inline.float-right.mt-3 + = link_to icon('fa-solid', 'download'), account_users_path(format: "csv") + + table.table.mt-2 thead tr td = t '.table.email_col' diff --git a/config/locales/en/en.yml b/config/locales/en/en.yml index 0c3940030..177e7e25d 100644 --- a/config/locales/en/en.yml +++ b/config/locales/en/en.yml @@ -705,3 +705,11 @@ en: id_desc: ID, descending title_asc: Title, ascending title_desc: Title, descending + name_asc: Name, ascending + name_desc: Name, descending + slug_asc: Slug, ascending + slug_desc: Slug, descending + email_asc: Email, ascending + email_desc: Email, descending + last_sign_in_at_asc: Last sign in, ascending + last_sign_in_at_desc: Last sign in, descending diff --git a/config/locales/uk/uk.yml b/config/locales/uk/uk.yml index 2f77624c3..08f48cc94 100644 --- a/config/locales/uk/uk.yml +++ b/config/locales/uk/uk.yml @@ -761,3 +761,11 @@ uk: id_desc: ID, за спаданням title_asc: Назва, за зростанням title_desc: Назва, за спаданням + name_asc: Назва, за зростанням + name_desc: Назва, за спаданням + slug_asc: Шлях, за зростанням + slug_desc: Шлях, за спаданням + email_asc: Електронна адреса, за зростанням + email_desc: Електронна адреса, за спаданням + last_sign_in_at_asc: Час останнього візиту, за зростанням + last_sign_in_at_desc: Час останнього візиту, за спаданням