Skip to content

Commit

Permalink
Merge pull request #2935 from fjordllc/feature/add_dashboard_and_my_p…
Browse files Browse the repository at this point in the history
…roducts_page_tabs_in_home

ダッシュボード配下に自分の提出物一覧をページを作成
  • Loading branch information
komagata authored Jul 20, 2021
2 parents 2e7c0dc + 2c26aa0 commit 56cb8fd
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/controllers/current_user/products/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
- title "#{@user.login_name}の提出物"
header.page-header
.container
.page-header__inner
h2.page-header__title
= title
.page-header-actions
ul.page-header-actions__items
li.page-header-actions__item
= link_to users_path, class: 'a-button is-md is-secondary is-block is-back' do
| ユーザー一覧

.page-tools
= render 'home/page_tabs', user: @current_user

.page-body
.container
- if @products.present?
.thread-list.a-card
= render partial: 'products/product', collection: @products, as: :product
- else
.o-empty-message
.o-empty-message__icon
i.far.fa-sad-tear
p.o-empty-message__text
| 提出物はまだありません。
23 changes: 23 additions & 0 deletions app/controllers/current_user/products_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

class CurrentUser::ProductsController < ApplicationController
before_action :require_login
before_action :set_user
before_action :set_products

def index; end

private

def set_user
@user = current_user
end

def set_products
@products = user.products.list
end

def user
@user ||= current_user
end
end
21 changes: 21 additions & 0 deletions app/views/current_user/products/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- title '自分の提出物'
header.page-header
.container
.page-header__inner
h2.page-header__title
| ダッシュボード

.page-tools
= render 'home/page_tabs', user: @user

.page-body
.container
- if @products.present?
.thread-list.a-card
= render partial: 'products/product', collection: @products, as: :product
- else
.o-empty-message
.o-empty-message__icon
i.far.fa-sad-tear
p.o-empty-message__text
| 提出物はまだありません。
4 changes: 4 additions & 0 deletions app/views/home/_page_tabs.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@
li.page-tabs__item
= link_to current_user_reports_path, class: "page-tabs__item-link #{current_page_tab_or_not('reports')}" do
| 自分の日報
- if !user.staff? || user.products.present?
li.page-tabs__item
= link_to current_user_products_path, class: "page-tabs__item-link #{current_page_tab_or_not('products')}" do
| 自分の提出物
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@

namespace :current_user do
resources :reports, only: %i(index)
resources :products, only: %i(index)
end

namespace "partial" do
Expand Down
10 changes: 10 additions & 0 deletions test/system/current_user/products_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require 'application_system_test_case'

class CurrentUser::ProductsTest < ApplicationSystemTestCase
test 'show current_user products when current_user is student' do
visit_with_auth '/current_user/products', 'kimura'
assert_equal '自分の提出物 | FJORD BOOT CAMP(フィヨルドブートキャンプ)', title
end
end

0 comments on commit 56cb8fd

Please sign in to comment.