Skip to content

Commit

Permalink
renovate the academic group list to show the actions as buttons and s…
Browse files Browse the repository at this point in the history
…upport localization
  • Loading branch information
mpugach committed Sep 10, 2022
1 parent 214a146 commit 6f46729
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 47 deletions.
9 changes: 9 additions & 0 deletions app/assets/stylesheets/_text-align.sass
@@ -0,0 +1,9 @@
.table > thead > tr > th.text-middle,
.table > tbody > tr > td.text-middle,
.text-middle
vertical-align: middle

.table > thead > tr > th.text-top,
.table > tbody > tr > td.text-top,
.text-top
vertical-align: top
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.sass
Expand Up @@ -44,6 +44,7 @@ $rails: true
@import 'events-table'
@import 'class-schedules'
@import 'scrollable-table'
@import 'text-align'

// This must come after all the boostrap styles are loaded so that these styles can override those.
@import 'post-bootstrap'
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/statistics_controller.rb
Expand Up @@ -5,7 +5,7 @@ class StatisticsController < ApplicationController
def index
@academic_group = policy_scope(AcademicGroup).find(params[:academic_group_id])

authorize @academic_group
authorize @academic_group, :statistics?

schedules = @academic_group.class_schedules.where('start_time < ?', Time.zone.now).order(:start_time)
schedule_dates = schedules.pluck(:start_time).map(&:to_date)
Expand Down
61 changes: 40 additions & 21 deletions app/views/academic_groups/index.html.haml
@@ -1,23 +1,42 @@
- provide(:title, 'All Academic Groups')
- provide(:title, t('.title'))

%h1 Academic Groups
.row
.col-xs-12
%h1.text-center
= t('.title')

.row
.col-xs-12
.table-responsive
%table.table.table-condensed.table-striped
%thead
%tr
%th.text-top=t('.table_title_name')
%th.text-top.text-center=t('.table_title_established')
%th.text-top.text-center=t('.table_title_graduated')
%th.text-top=t('.table_title_description')
%th.text-top.text-center=t('.table_title_students')

- if @academic_groups.any? { |c| policy(c).tap { |p| break p.edit? || p.destroy? || p.statistics? } }
%th.text-top.text-right=t('.table_title_actions')

%tbody
- @academic_groups.each do |academic_group|
%tr{class: 'academic_group', id: academic_group.id}
%td= link_to academic_group.title, academic_group
%td.text-center= l(academic_group.establ_date) if academic_group.establ_date.present?
%td.text-center= l(academic_group.graduated_at, format: :with_day) unless academic_group.active?
%td= academic_group.group_description
%td.text-center= academic_group.active_students.count

- if policy(academic_group).tap { |p| break p.edit? || p.destroy? || p.statistics? }
%td.col-xs-2.col-sm-4.col-md-3.text-right.text-middle
= link_to_action policy(academic_group).statistics?,
academic_group_statistics_path(academic_group),
'info',
t('links.statistics'),
'stats'
= link_to_edit policy(academic_group).edit?,
edit_academic_group_path(academic_group)
= link_to_destroy policy(academic_group).destroy?, academic_group

.table-responsive
%table.table.table-condensed.table-striped
%thead
%tr
%th Name
%th Established
%th Graduated
%th Description
%th Students
%th Statistics
%tbody
- @academic_groups.each do |academic_group|
%tr{class: 'academic_group', id: academic_group.id}
%td= link_to academic_group.title, academic_group
%td= l(academic_group.establ_date) if academic_group.establ_date.present?
%td= l(academic_group.graduated_at, format: :with_day) unless academic_group.active?
%td= academic_group.group_description
%td= academic_group.active_students.count
%td= link_to 'view', academic_group_statistics_path(academic_group)
29 changes: 19 additions & 10 deletions config/locales/general.ru.yml
Expand Up @@ -41,16 +41,17 @@ ru:
application_title: Студенты Киевской Духовной Академии Сознания Кришны
links:
apply_to_program: 'Подать заявление'
back: 'Назад'
crop_photo: 'Обрезать фотографию'
delete: 'Удалить'
edit: 'Редактировать'
edit_profile: 'Редактировать профиль'
graduate: 'Выпуск'
list: 'Список'
new: 'Создать'
update: 'Сохранить'
withdraw: 'Отозвать заявление'
back: 'Назад'
crop_photo: 'Обрезать фотографию'
delete: 'Удалить'
edit_profile: 'Редактировать профиль'
edit: 'Редактировать'
graduate: 'Выпуск'
list: 'Список'
new: 'Создать'
statistics: 'Статистика'
update: 'Сохранить'
withdraw: 'Отозвать заявление'
alerts:
delete_confirmation: 'Вы уверены что хотите это УДАЛИТЬ???'
content:
Expand Down Expand Up @@ -216,6 +217,14 @@ ru:
tab_group_list: 'Список группы'
tab_schedules: 'Расписание'
telephones: 'Телефоны'
index:
title: 'Академические группы'
table_title_name: 'Название'
table_title_established: 'Дата создания'
table_title_graduated: 'Дата окончания'
table_title_description: 'Описание'
table_title_students: 'Количество студентов'
table_title_actions: 'Действия'
class_schedules:
create_and_clone: 'Создать и копировать'
table_headers:
Expand Down
29 changes: 19 additions & 10 deletions config/locales/general.uk.yml
Expand Up @@ -41,16 +41,17 @@ uk:
application_title: Студенти Київської Духовної Академії Свідомості Кришни
links:
apply_to_program: 'Подати заяву'
back: 'Назад'
crop_photo: 'Обрізати фотографію'
delete: 'Видалити'
edit: 'Редагувати'
edit_profile: 'Редагувати профіль'
graduate: 'Випуск'
list: 'Список'
new: 'Створити'
update: 'Зберегти'
withdraw: 'Відкликати заяву'
back: 'Назад'
crop_photo: 'Обрізати фотографію'
delete: 'Видалити'
edit_profile: 'Редагувати профіль'
edit: 'Редагувати'
graduate: 'Випуск'
list: 'Список'
new: 'Створити'
statistics: 'Статистика'
update: 'Зберегти'
withdraw: 'Відкликати заяву'
alerts:
delete_confirmation: 'Ви впевнені що хочете це ВИДАЛИТИ???'
content:
Expand Down Expand Up @@ -216,6 +217,14 @@ uk:
tab_group_list: 'Список групи'
tab_schedules: 'Розклад'
telephones: 'Телефони'
index:
title: 'Академічні групи'
table_title_name: 'Назва'
table_title_established: 'Дата створення'
table_title_graduated: 'Дата закінчення'
table_title_description: 'Опис'
table_title_students: 'Кількість студентів'
table_title_actions: 'Дії'
class_schedules:
create_and_clone: 'Створити і копіювати'
table_headers:
Expand Down
2 changes: 1 addition & 1 deletion spec/support/helper_methods.rb
Expand Up @@ -58,7 +58,7 @@ def academic_group_activities
AcademicGroupsController.action_methods -
%w(autocomplete_person get_prefix get_autocomplete_order
get_autocomplete_items autocomplete_person_complex_name) +
%w(group_list_pdf attendance_template_pdf)
%w(group_list_pdf attendance_template_pdf statistics)
).map { |action| 'academic_group:' << action }
end

Expand Down
12 changes: 8 additions & 4 deletions spec/views/akadem_groups/index.html.haml_spec.rb
Expand Up @@ -2,14 +2,18 @@

describe 'academic_groups/index' do
Given(:models_count) { 20 }
Given(:title) { 'All Academic Groups' }
Given(:h1) { 'Academic Groups' }
Given(:row_class) { 'academic_group' }
Given(:title) { I18n.t('academic_groups.index.title') }
Given(:h1) { I18n.t('academic_groups.index.title') }
Given(:row_class) { 'academic_group' }

Given { models_count.times { create :academic_group } }
Given { login_as_admin }

When { visit academic_groups_path }

it_behaves_like 'index.html', %w(Name Established Description)
it_behaves_like 'index.html', [
I18n.t('academic_groups.index.table_title_name'),
I18n.t('academic_groups.index.table_title_established'),
I18n.t('academic_groups.index.table_title_description')
]
end

0 comments on commit 6f46729

Please sign in to comment.