Skip to content

Commit

Permalink
コーディングテスト用のタブを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
komagata committed Oct 16, 2024
1 parent f7541a5 commit c13be99
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 35 deletions.
1 change: 1 addition & 0 deletions app/helpers/page_tabs/practices_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def practice_page_tabs(practice, active_tab:)
tabs << { name: 'Docs', link: practice_pages_path(practice), count: practice.pages.length }
tabs << { name: '提出物', link: practice_products_path(practice) }
tabs << { name: '模範解答', link: practice_submission_answer_path(practice) }
tabs << { name: 'コーディングテスト', link: practice_coding_tests_path(practice) } if practice.coding_tests.present?
render PageTabsComponent.new(tabs:, active_tab:)
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/coding_test_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ class CodingTestSubmission < ApplicationRecord
belongs_to :coding_test
belongs_to :user

has_one :practice, through: :coding_test

validates :coding_test_id, uniqueness: { scope: :user_id }
end
4 changes: 4 additions & 0 deletions app/models/practice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class Practice < ApplicationRecord
has_one :submission_answer, dependent: :destroy
has_many :coding_tests, dependent: :nullify

has_many :coding_test_submissions,
through: :coding_tests,
source: :coding_test_submissions

validates :title, presence: true
validates :description, presence: true
validates :goal, presence: true
Expand Down
13 changes: 5 additions & 8 deletions app/views/coding_tests/coding_test_submissions/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
- title "「#{@coding_test.title}」の回答"
- description "コーディングテスト「#{@coding_test.title}」の回答の一覧ページです。"
- @practice = @coding_test.practice
- practice = @coding_test.practice

= render '/practices/page_header',
title: @practice.title,
category: @practice.category(current_user.course),
practice: @practice
= render '/practices/page_header', title: practice.title, practice: practice

// TODO#7935 タブを設置
//= render 'page_tabs', resource: @coding_test.practice
= practice_page_tabs(practice, active_tab: 'コーディングテスト')

.page-main
header.page-main-header
Expand All @@ -21,7 +17,8 @@
.page-main-header-actions
ul.page-main-header-actions__items
li.page-main-header-actions__item
= link_to [@practice, :coding_tests], class: 'a-button is-md is-secondary is-block is-back' do
= link_to coding_test_coding_test_submissions_path(@coding_test),
class: 'a-button is-md is-secondary is-block is-back' do
| テスト一覧
- if current_user.submitted?(@coding_test)
li.page-main-header-actions__item
Expand Down
18 changes: 8 additions & 10 deletions app/views/coding_tests/coding_test_submissions/show.html.slim
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
- cts = @coding_test_submission
- title "「#{@coding_test.title}」の回答コード"
- description "#{cts.user.login_name}さんの回答コードです。"
- category = @coding_test.practice.category(current_user.course)
ruby:
cts = @coding_test_submission
practice = cts.practice
title "#{@coding_test.title}」の回答コード"
description "#{cts.user.login_name}さんの回答コードです。"

= render '/practices/page_header',
title: @coding_test.practice.title,
category: category,
practice: @coding_test.practice
= render '/practices/page_header', title: practice.title, practice: practice

// TODO#7935 ここにタブを設置
= practice_page_tabs(practice, active_tab: 'コーディングテスト')

.page-main

Expand All @@ -22,7 +20,7 @@
.page-main-header-actions
ul.page-main-header-actions__items
li.page-main-header-actions__item
= link_to [@coding_test.practice, :coding_tests], class: 'a-button is-md is-secondary is-block is-back' do
= link_to practice_coding_tests_path(@coding_test_submission.practice), class: 'a-button is-md is-secondary is-block is-back' do
| テスト一覧
li.page-main-header-actions__item
= link_to [@coding_test, :coding_test_submissions], class: 'a-button is-md is-secondary is-block is-back' do
Expand Down
15 changes: 6 additions & 9 deletions app/views/coding_tests/show.html.slim
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
- title @coding_test.title
- description "#{@coding_test.title}のコーディングテストです。"
- category = @practice.category(current_user.course)
ruby:
title @coding_test.title
practice = @coding_test.practice
description "#{@coding_test.title}のコーディングテストです。"

= render '/practices/page_header',
title: @practice.title,
category: category,
practice: @practice
= render '/practices/page_header', title: practice.title, practice: practice

// TODO#7935 タブを設置
//= render 'page_tabs', resource: @practice
= practice_page_tabs(@practice, active_tab: 'コーディングテスト')

.page-main
header.page-main-header
Expand Down
3 changes: 2 additions & 1 deletion app/views/practices/_page_header.html.slim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- category = practice.category(current_user.course)
header.page-header
.container
.page-header__inner
Expand All @@ -9,7 +10,7 @@ header.page-header
ul.page-header-actions__items
- if current_user.mentor? && practice.submission && !practice.submission_answer
li.page-header-actions__item.is-hidden-sm-down.is-only-mentor
= link_to new_mentor_practice_submission_answer_path(@practice), class: 'a-button is-md is-secondary is-block' do
= link_to new_mentor_practice_submission_answer_path(practice), class: 'a-button is-md is-secondary is-block' do
i.fa-regular.fa-plus
span
| 模範解答作成
Expand Down
9 changes: 2 additions & 7 deletions app/views/practices/coding_tests/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
- title "#{@practice.title}のコーディングテスト"
- description 'コーディングテストの一覧ページです。'
- category = @practice.category(current_user.course)

= render '/practices/page_header',
title: @practice.title,
category: category,
practice: @practice
= render '/practices/page_header', title: @practice.title, practice: @practice

// TODO#7935 タブを設置
//= render 'page_tabs', resource: @practice
= practice_page_tabs(@practice, active_tab: 'コーディングテスト')

.page-main
header.page-main-header
Expand Down

0 comments on commit c13be99

Please sign in to comment.