Skip to content

Commit

Permalink
Programs list
Browse files Browse the repository at this point in the history
  • Loading branch information
mpugach committed Feb 26, 2023
1 parent 89b3b70 commit c033682
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/custom.js.coffee
Expand Up @@ -26,7 +26,7 @@ $ ->
horizontal: 'left'
stepping: 5

$('.popover-description, .popover-photo').popover({
$('.popover-description, .popover-photo, .popover-info').popover({
trigger: 'hover',
placement: 'auto top',
delay: { show: 600, hide: 0 },
Expand Down
2 changes: 2 additions & 0 deletions app/assets/stylesheets/_inline-info.sass
@@ -0,0 +1,2 @@
.inline-info
cursor: help
4 changes: 4 additions & 0 deletions app/assets/stylesheets/_link-to-person-with-photo.sass
@@ -0,0 +1,4 @@
.link-to-person-with-photo
display: flex
gap: 0.7em
align-items: center
2 changes: 2 additions & 0 deletions app/assets/stylesheets/application.sass
Expand Up @@ -46,6 +46,8 @@ $rails: true
@import 'scrollable-table'
@import 'text-align'
@import 'advanced-search-component'
@import 'link-to-person-with-photo'
@import 'inline-info'

// This must come after all the boostrap styles are loaded so that these styles can override those.
@import 'post-bootstrap'
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/programs_controller.rb
@@ -0,0 +1,13 @@
class ProgramsController < HtmlRespondableController
include Crudable

after_action :verify_policy_scoped, only: %i[index]

def index
@programs = policy_scope(Program).order(visible: :desc, position: :asc).includes(:manager)

authorize Program

respond_with(@programs)
end
end
20 changes: 20 additions & 0 deletions app/helpers/application_helper.rb
Expand Up @@ -41,6 +41,26 @@ def thumb_with_pop(person)
)
end

def inline_info(text)
return unless text

tag(
:i,
class: %w[fa fa-info-circle popover-info text-info inline-info],
aria: { hidden: 'true' },
data: { toggle: :popover, content: text }
)
end

def link_to_person_with_photo(person)
return unless person

content_tag(:div, class: 'link-to-person-with-photo') do
concat(thumb_with_pop(person))
concat(link_to_show_person_or_name(person, short: true))
end
end

def class_schedules_table_headers
%w[course teacher subject groups classroom time actions].map do |key|
I18n.t("class_schedules.table_headers.#{key}")
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/concerns/ability_shortcuts.rb
Expand Up @@ -11,6 +11,10 @@ def show_certificate_templates_menu?
current_person&.can_act?(%w[certificate_template:index certificate_template:new])
end

def show_programs_menu?
current_person&.can_act?(%w[program:index program:new])
end

def show_courses_menu?
current_person&.can_act?(%w[course:index course:new])
end
Expand Down
1 change: 1 addition & 0 deletions app/helpers/concerns/auto_generated_menu.rb
Expand Up @@ -2,6 +2,7 @@ module AutoGeneratedMenu
include AbilityShortcuts

SIDEBAR_MENU = [
%i[program programs fa-sitemap],
%i[course courses fa-book],
%i[class_schedule class_schedules fa-calendar],
%i[questionnaire questionnaires fa-question]
Expand Down
2 changes: 1 addition & 1 deletion app/models/study_application.rb
@@ -1,6 +1,6 @@
class StudyApplication < ApplicationRecord
belongs_to :person
belongs_to :program
belongs_to :program, counter_cache: true

validates :person_id, uniqueness: true
validates :program, :person, presence: true
Expand Down
2 changes: 2 additions & 0 deletions app/policies/program_policy.rb
@@ -0,0 +1,2 @@
class ProgramPolicy < BasePolicy
end
56 changes: 56 additions & 0 deletions app/views/programs/index.html.haml
@@ -0,0 +1,56 @@
- provide(:title, t('.title'))

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

- if current_person.can_act?('program:new')
.col-xs-12.col-sm-10.col-sm-offset-1.vert-offset-top-1.vert-offset-bottom-1.text-right
= link_to_new(true, new_program_path)

.col-xs-12.col-sm-10.col-sm-offset-1
.table-responsive
%table.table.table-condensed.table-striped
%thead
%tr
%th.text-top= t('.program_title')
%th.text-top
= t('.program_manager')
= inline_info(t('.program_manager_help'))
%th.text-top.text-center= t('.program_study_applications_count')
%th.text-top.text-center
= t('.program_position')
= inline_info(t('.program_position_help'))
%th.text-top.text-center
= t('.program_visibility')
= inline_info(t('.program_visibility_help'))

- if @programs.any? { |program| policy(program).tap { |p| break p.edit? || p.destroy? } }
%th.text-top.text-right= t('.actions')

%tbody
- @programs.each do |program|
- manager = program.manager
- title = program["title_#{locale}"]

%tr
%td
= link_to_if policy(program).show?, title, program_path(program) do
= title

%td
= link_to_person_with_photo(manager)

%td.text-center
= program.study_applications_count

%td.text-center
= program.position

%td.text-center
= t(".program_visibility_#{program.visible}")

- if policy(program).tap { |p| break p.edit? || p.destroy? }
%td.col-xs-2.col-sm-3.col-md-2.text-right
= link_to_edit(policy(program).edit?, edit_program_path(program))
= link_to_destroy(policy(program).destroy?, program_path(program))
17 changes: 17 additions & 0 deletions config/locales/general.ru.yml
Expand Up @@ -32,6 +32,9 @@ ru:
people_list: 'Все люди'
people_without_applications: 'Без заявлений'
people: 'Люди'
programs_add: 'Добавить курс'
programs_list: 'Список курсов'
programs: 'Учебные курсы'
questionnaires_list: 'Список опросников'
questionnaires: 'Опросники'
statistics_yearly_active_students: 'Активные студенты по годам'
Expand Down Expand Up @@ -189,6 +192,20 @@ ru:
study_applications: 'Заявления на обучение'
index:
search_placeholder: 'Кого Вы ищете?'
programs:
index:
title: 'Учебные курсы'
program_title: 'Название курса'
program_manager: 'Администратор курса'
program_manager_help: 'Его контакты видят студенты подавшие заявление курс и получает письма на почту когда подают новое заявление'
program_study_applications_count: 'Количество необработанных заявлений от студентов'
program_position: 'Позиция сортировки'
program_position_help: 'Чем меньше число, тем выше этот курс будет в списке, который видят студенты'
program_visibility: 'Видимость'
program_visibility_help: 'Не видимый курс видят администраторы, но он не предлагается студентам, чтобы подать на него заявление'
program_visibility_true: 'Да'
program_visibility_false: 'Не видим курс'
actions: 'Действия'
notes:
new:
title: 'Новая заметка'
Expand Down
17 changes: 17 additions & 0 deletions config/locales/general.uk.yml
Expand Up @@ -32,6 +32,9 @@ uk:
people_list: 'Усі люди'
people_without_applications: 'Без заяв'
people: 'Люди'
programs_add: 'Додати курс'
programs_list: 'Список курсів'
programs: 'Учбові курси'
questionnaires_list: 'Список опитувальників'
questionnaires: 'Опитувальники'
statistics_yearly_active_students: 'Активні студенти по рокам'
Expand Down Expand Up @@ -189,6 +192,20 @@ uk:
study_applications: 'Заяви на навчання'
index:
search_placeholder: 'Кого Ви шукаєте?'
programs:
index:
title: 'Учбові курси'
program_title: 'Назва курсу'
program_manager: 'Адміністратор курсу'
program_manager_help: 'Його контакти бачать студенти що подали заяву курс і він отрумує лісти на пошту коли подають нову заяву'
program_study_applications_count: 'Кількість неопрацьованих заявок від студентів'
program_position: 'Позиція для сортування'
program_position_help: 'Чим менше число, тим вище цей курс буде у списку, який бачать студенти'
program_visibility: 'Видимість'
program_visibility_help: 'Не видимий курс бачать адміністратори, але він не пропонується стунтам, щоб подати на нього заяву'
program_visibility_true: 'Так'
program_visibility_false: 'Не видимий курс'
actions: 'Дії'
notes:
new:
title: 'Нова нотатка'
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Expand Up @@ -48,6 +48,8 @@
resources :examinations, only: %i[new create edit update show destroy]
end

resources :programs, only: %i[index]

post '/academic_groups/:id/graduate', controller: :academic_groups, action: :graduate, as: :graduate_academic_group

scope module: :users do
Expand Down
@@ -0,0 +1,5 @@
class AddStudyApplicationsCountToPrograms < ActiveRecord::Migration[5.0]
def change
add_column :programs, :study_applications_count, :integer, default: 0
end
end
9 changes: 5 additions & 4 deletions db/schema.rb
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20220903054050) do
ActiveRecord::Schema.define(version: 20230222180223) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -220,15 +220,16 @@
create_table "programs", force: :cascade do |t|
t.datetime "created_at"
t.datetime "updated_at"
t.string "title_uk", limit: 255
t.string "title_ru", limit: 255
t.string "title_uk", limit: 255
t.string "title_ru", limit: 255
t.text "description_uk"
t.text "description_ru"
t.text "courses_uk"
t.text "courses_ru"
t.boolean "visible", default: false
t.boolean "visible", default: false
t.integer "manager_id"
t.integer "position"
t.integer "study_applications_count", default: 0
end

create_table "programs_questionnaires", id: false, force: :cascade do |t|
Expand Down
6 changes: 4 additions & 2 deletions db/structure.sql
Expand Up @@ -752,7 +752,8 @@ CREATE TABLE public.programs (
courses_ru text,
visible boolean DEFAULT false,
manager_id integer,
"position" integer
"position" integer,
study_applications_count integer DEFAULT 0
);


Expand Down Expand Up @@ -1961,6 +1962,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20220717060619'),
('20220717061020'),
('20220717072150'),
('20220903054050');
('20220903054050'),
('20230222180223');


6 changes: 5 additions & 1 deletion spec/support/helper_methods.rb
Expand Up @@ -13,7 +13,7 @@ def all_activities
class_schedule_activities + certificate_template_activities + journal_activities + examination_activities +
attendance_activities + examination_results + note_activities + statistics_activities +
questionnaire_activities + certificate_template_font_activities + certificate_activities +
certificate_import_activities
certificate_import_activities + program_activities
).sort
end

Expand Down Expand Up @@ -90,6 +90,10 @@ def certificate_template_font_activities
CertificateTemplateFontsController.action_methods.map { |action| 'certificate_template_font:' << action }
end

def program_activities
ProgramsController.action_methods.map { |action| 'program:' << action }
end

def journal_activities
JournalsController.action_methods.map { |action| 'paper_trail/version:' << action }
end
Expand Down

0 comments on commit c033682

Please sign in to comment.