Skip to content

Commit

Permalink
New option "hide_common_stat" for rubrics
Browse files Browse the repository at this point in the history
  • Loading branch information
yamax2 committed Jun 11, 2021
1 parent 7a0bb90 commit c15d9e7
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ GEM
rb-fsevent (0.11.0)
rb-inotify (0.10.1)
ffi (~> 1.0)
redis (4.2.5)
redis (4.3.1)
redis-classy (2.4.1)
redis-namespace (~> 1.0)
redis-mutex (4.0.2)
Expand Down Expand Up @@ -300,7 +300,7 @@ GEM
rspec-mocks (~> 3.10)
rspec-support (~> 3.10)
rspec-support (3.10.2)
rubocop (1.16.0)
rubocop (1.16.1)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
Expand All @@ -318,7 +318,7 @@ GEM
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-rspec (2.3.0)
rubocop-rspec (2.4.0)
rubocop (~> 1.0)
rubocop-ast (>= 1.1.0)
ruby-progressbar (1.11.0)
Expand Down Expand Up @@ -462,4 +462,4 @@ DEPENDENCIES
yandex_client (>= 0.2)

BUNDLED WITH
2.2.19
2.2.20
2 changes: 1 addition & 1 deletion app/controllers/admin/rubrics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def parent_rubric
end

def rubric_params
params.require(:rubric).permit(:rubric_id, :name, :description, :desc_order)
params.require(:rubric).permit(:rubric_id, :name, :description, :desc_order, :hide_common_stat)
end
end
end
9 changes: 9 additions & 0 deletions app/views/admin/rubrics/_form.slim
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
span.switch-label*{data: {on: t('views.switches.on_text'), off: t('views.switches.off_text') }}
span.switch-handle

.row.form-group
.col.col-md-3
= f.label :hide_common_stat
.col-12.col-md-9
label.switch.switch-text.switch-primary
= f.check_box(:hide_common_stat, {class: 'switch-input type'})
span.switch-label*{data: {on: t('views.switches.on_text'), off: t('views.switches.off_text') }}
span.switch-handle

.row.form-group
.col.col-md-3
= f.label :description
Expand Down
14 changes: 8 additions & 6 deletions app/views/admin/rubrics/index.slim
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
table.table
thead
tr
- %i[id name created_at rubrics_count ord desc_order].each do |attr|
- %i[id name created_at rubrics_count ord desc_order hide_common_stat].each do |attr|
th
= sort_link @search, attr, Rubric.human_attribute_name(attr)
th
Expand All @@ -50,11 +50,13 @@
- else
= rubric[attr]

td
label.switch.switch-text.switch-primary
input.switch-input type="checkbox"*{checked: rubric.desc_order? ? 'checked' : nil, disabled: true}
span.switch-label*{data: {on: t('views.switches.on_text'), off: t('views.switches.off_text')}}
span.switch-handle
- %i[desc_order hide_common_stat].each do |attr|
td
label.switch.switch-text.switch-primary
input.switch-input type="checkbox"*{checked: rubric.public_send("#{attr}?") ? 'checked' : nil, disabled: true}
span.switch-label*{data: {on: t('views.switches.on_text'), off: t('views.switches.off_text')}}
span.switch-handle

td.action-buttons
= link_to admin_rubrics_path(id: rubric.id), title: t('.subrubrics', name: rubric.name),
class: 'btn btn-outline-info btn-sm' do
Expand Down
6 changes: 5 additions & 1 deletion app/views/pages/show.slim
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
= @rubric.description.to_s.html_safe
- if @summary
table.summary-table
- %i[started_at finished_at travel_duration distance avg_speed duration].each do |attr|
- attrs = %i[distance avg_speed duration]
- unless @rubric.hide_common_stat
- attrs = %i[started_at finished_at travel_duration] + attrs

- attrs.each do |attr|
tr
th
= t(attr, scope: 'pages.show.summary')
Expand Down
1 change: 1 addition & 0 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ru:
rubric: Рубрика
rubrics_count: Подрубрики
desc_order: Обратный порядок фото в листинге
hide_common_stat: Не показывать общую статистику
track:
avg_speed: Средняя скорость, км/ч
content: gpx-файл (содержимое)
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20210611133109_add_hide_common_stat_to_rubrics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AddHideCommonStatToRubrics < ActiveRecord::Migration[6.1]
def change
add_column :rubrics, :hide_common_stat, :boolean, default: false, null: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2021_06_09_111248) do
ActiveRecord::Schema.define(version: 2021_06_11_133109) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -54,6 +54,7 @@
t.integer "ord"
t.bigint "tracks_count", default: 0, null: false
t.boolean "desc_order", default: false, null: false
t.boolean "hide_common_stat", default: false, null: false
t.index ["main_photo_id"], name: "index_rubrics_on_main_photo_id", where: "(main_photo_id IS NOT NULL)"
t.index ["rubric_id"], name: "index_rubrics_on_rubric_id"
end
Expand Down
1 change: 1 addition & 0 deletions spec/models/rubric_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
it { is_expected.to have_db_column(:photos_count).of_type(:integer).with_options(null: false, default: 0) }

it { is_expected.to have_db_column(:desc_order).of_type(:boolean).with_options(null: false, default: false) }
it { is_expected.to have_db_column(:hide_common_stat).of_type(:boolean).with_options(null: false, default: false) }

it { is_expected.to have_db_index(:rubric_id) }
it { is_expected.to have_db_index(:main_photo_id) }
Expand Down

0 comments on commit c15d9e7

Please sign in to comment.