Skip to content

Commit

Permalink
Schedules count for Courses list
Browse files Browse the repository at this point in the history
  • Loading branch information
mpugach committed Mar 6, 2023
1 parent b55523d commit 4306b56
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/courses_controller.rb
Expand Up @@ -15,7 +15,7 @@ def index
def show
@examinations = Examination.where(course_id: params[:id]).order(:title)
@academic_groups = @course.academic_groups.order(:title)
@class_schedules_count = @course.class_schedules.count
@class_schedules_count = @course.class_schedules_count

respond_with(@course)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/class_schedule.rb
Expand Up @@ -2,7 +2,7 @@ class ClassSchedule < ApplicationRecord
include ClassScheduleCustomValidations

belongs_to :classroom
belongs_to :course
belongs_to :course, counter_cache: true
belongs_to :teacher_profile

has_many :academic_group_schedules, dependent: :destroy
Expand Down
9 changes: 4 additions & 5 deletions app/views/courses/index.html.haml
Expand Up @@ -16,6 +16,7 @@
%th.text-top= t('.course_title')
%th.text-top= t('.course_variant')
%th.text-top= t('.course_examination_results_count')
%th.text-top= t('.course_class_schedules_count')

- if @courses.any? { |c| policy(c).tap { |p| break p.edit? || p.destroy? } }
%th.text-top.text-right= t('.actions')
Expand All @@ -27,11 +28,9 @@
= link_to_if policy(course).show?, course.title, course_path(course) do
= course.title

%td
= course.variant

%td
= course.examination_results_count
%td= course.variant
%td= course.examination_results_count
%td= course.class_schedules_count

- if policy(course).tap { |p| break p.edit? || p.destroy? }
%td.col-xs-2.col-sm-3.col-md-2.text-right
Expand Down
1 change: 1 addition & 0 deletions config/locales/general.ru.yml
Expand Up @@ -119,6 +119,7 @@ ru:
course_variant: 'Вариант'
title: 'Предметы'
course_examination_results_count: 'Количество сданных зачетных работ'
course_class_schedules_count: 'Создано расписаний'
show:
academic_group_title: 'Название'
actions: 'Действия'
Expand Down
1 change: 1 addition & 0 deletions config/locales/general.uk.yml
Expand Up @@ -119,6 +119,7 @@ uk:
course_variant: 'Варіант'
title: 'Предмети'
course_examination_results_count: 'Кількість зданих залікових робіт'
course_class_schedules_count: 'Створено розкладів'
show:
academic_group_title: 'Назва'
actions: 'Дії'
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20230306054610_add_schedules_count_to_course.rb
@@ -0,0 +1,5 @@
class AddSchedulesCountToCourse < ActiveRecord::Migration[5.0]
def change
add_column :courses, :class_schedules_count, :integer, default: 0
end
end
3 changes: 2 additions & 1 deletion 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: 20230305211926) do
ActiveRecord::Schema.define(version: 20230306054610) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -135,6 +135,7 @@
t.string "description", limit: 255
t.string "variant"
t.integer "examination_results_count", default: 0
t.integer "class_schedules_count", default: 0
end

create_table "examination_results", force: :cascade do |t|
Expand Down
6 changes: 4 additions & 2 deletions db/structure.sql
Expand Up @@ -513,7 +513,8 @@ CREATE TABLE public.courses (
title character varying(255),
description character varying(255),
variant character varying,
examination_results_count integer DEFAULT 0
examination_results_count integer DEFAULT 0,
class_schedules_count integer DEFAULT 0
);


Expand Down Expand Up @@ -2010,6 +2011,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230225063808'),
('20230226200547'),
('20230226201309'),
('20230305211926');
('20230305211926'),
('20230306054610');


0 comments on commit 4306b56

Please sign in to comment.