Skip to content

Commit

Permalink
Merge pull request #3027 from fjordllc/feature/add-not-assigned-tab-t…
Browse files Browse the repository at this point in the history
…o-products-page

【メンター向け機能】提出物に未アサインタブを追加
  • Loading branch information
komagata authored Aug 13, 2021
2 parents d67efd5 + e57d961 commit ff249f6
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 6 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Metrics/ClassLength:
- app/models/notification_facade.rb
- app/models/practice.rb
- app/models/user.rb
- app/models/product.rb

AllCops:
Exclude:
Expand Down
11 changes: 11 additions & 0 deletions app/controllers/api/products/unassigned_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class API::Products::UnassignedController < API::BaseController
before_action :require_staff_login_for_api
def index
@products = Product.unassigned.unchecked.not_wip.list.page(params[:page])
@latest_product_submitted_just_5days = @products.find { |product| product.elapsed_days == 5 }
@latest_product_submitted_just_6days = @products.find { |product| product.elapsed_days == 6 }
@latest_product_submitted_over_7days = @products.find { |product| product.elapsed_days >= 7 }
end
end
6 changes: 6 additions & 0 deletions app/controllers/products/unassigned_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

class Products::UnassignedController < ApplicationController
before_action :require_staff_login
def index; end
end
5 changes: 4 additions & 1 deletion app/javascript/product.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template lang="pug">
.thread-list-item(:class='product.wip ? "is-wip" : ""')
.thread-list-item__strip-label(v-if='notResponded')
.thread-list-item__strip-label(v-if='notResponded || unassigned')
.thread-list-item__elapsed-days.is-reply-warning.is-only-mentor(
v-if='isLatestProductSubmittedJust5days'
)
Expand Down Expand Up @@ -155,6 +155,9 @@ export default {
},
notResponded() {
return location.pathname === '/products/not_responded'
},
unassigned() {
return location.pathname === '/products/unassigned'
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions app/javascript/products.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export default {
return {
unchecked: '未完了',
'not-responded': '未返信',
'self-assigned': '自分の担当'
'self-assigned': '自分の担当',
unassigned: '未アサイン'
}[this.selectedTab]
},
pagerProps() {
Expand Down Expand Up @@ -111,7 +112,10 @@ export default {
return response.json()
})
.then((json) => {
if (location.pathname === '/products/not_responded') {
if (
location.pathname === '/products/not_responded' ||
location.pathname === '/products/unassigned'
) {
this.latestProductSubmittedJust5days =
json.latest_product_submitted_just_5days
this.latestProductSubmittedJust6days =
Expand Down
10 changes: 10 additions & 0 deletions app/models/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ def delete_not_responded_product_count
Rails.cache.delete 'not_responded_product_count'
end

def unassigned_product_count
Rails.cache.fetch 'unassigned_product_count' do
Product.unassigned.unchecked.not_wip.count
end
end

def delete_unassigned_product_count
Rails.cache.delete 'unassigned_product_count'
end

def self_assigned_product_count(current_user_id)
Rails.cache.fetch("#{current_user_id}-self_assigned_product_count") do
Product.self_assigned_product(current_user_id).unchecked.count
Expand Down
1 change: 1 addition & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Product < ApplicationRecord
->(user) { where(practice: user.practices_with_checked_product).checked.pluck(:id) }

scope :unchecked, -> { where.not(id: Check.where(checkable_type: 'Product').pluck(:checkable_id)) }
scope :unassigned, -> { where(checker_id: nil) }
scope :self_assigned_product, ->(current_user_id) { where(checker_id: current_user_id) }

scope :wip, -> { where(wip: true) }
Expand Down
2 changes: 2 additions & 0 deletions app/models/product_callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def after_create(product)

Cache.delete_unchecked_product_count
Cache.delete_not_responded_product_count
Cache.delete_unassigned_product_count
Cache.delete_self_assigned_product_count(product.checker_id)
end

Expand Down Expand Up @@ -35,6 +36,7 @@ def after_destroy(product)

Cache.delete_unchecked_product_count
Cache.delete_not_responded_product_count
Cache.delete_unassigned_product_count
Cache.delete_self_assigned_product_count(product.checker_id)
end

Expand Down
9 changes: 9 additions & 0 deletions app/views/api/products/unassigned/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
json.products do
json.array! @products do |product|
json.partial! "api/products/product", product: product
end
end
json.total_pages @products.page(1).total_pages
json.latest_product_submitted_just_5days @latest_product_submitted_just_5days
json.latest_product_submitted_just_6days @latest_product_submitted_just_6days
json.latest_product_submitted_over_7days @latest_product_submitted_over_7days
4 changes: 2 additions & 2 deletions app/views/application/_global_nav.slim
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ nav.global-nav
= link_to products_link, class: "global-nav-links__link #{current_link(/^products/)}" do
.global-nav-links__link-icon
i.fas.fa-fw.fa-hand-paper
- if admin_or_mentor_login? && Cache.not_responded_product_count.positive?
- if admin_login? || mentor_login? && Cache.unassigned_product_count.positive?
.global-nav__item-count.a-notification-count.is-only-mentor
= Cache.not_responded_product_count
= Cache.unassigned_product_count
.global-nav-links__link-label 提出物
li.global-nav-links__item
= link_to questions_path, class: "global-nav-links__link #{current_link(/^questions/)}" do
Expand Down
6 changes: 6 additions & 0 deletions app/views/products/_tabs.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
- if Cache.not_responded_product_count.positive?
.page-tabs__item-count.a-notification-count.is-only-mentor
= Cache.not_responded_product_count
li.page-tabs__item
= link_to products_unassigned_index_path, class: "page-tabs__item-link #{current_link(/^products-unassigned-index/)}", id: 'test-unassigned-tab' do
| 未アサイン
- if Cache.unassigned_product_count.positive?
.page-tabs__item-count.a-notification-count#test-unassigned-counter
= Cache.unassigned_product_count
li.page-tabs__item.is-only-mentor
= link_to products_self_assigned_index_path, class: "page-tabs__item-link #{current_link(/^products-self_assigned-index/)}" do
| 自分の担当
Expand Down
12 changes: 12 additions & 0 deletions app/views/products/unassigned/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- title '未アサインの提出物'

header.page-header
.container
.page-header__inner
h2.page-header__title
= title

.page-tools
= render 'products/tabs'

#js-products(data-title="#{title}" data-selected-tab="unassigned" data-mentor-login="#{mentor_login?}" data-current-user-id="#{current_user.id}")
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
namespace :products do
resources :unchecked, only: %i(index)
resources :not_responded, only: %i(index)
resources :unassigned, only: %i(index)
resources :self_assigned, only: %i(index)
resource :checker, only: %i(update), controller: 'checker'
resource :passed, only: %i(show), controller: 'passed'
Expand Down Expand Up @@ -152,6 +153,7 @@
namespace :products do
resources :unchecked, only: %i(index)
resources :not_responded, only: %i(index)
resources :unassigned, only: %i(index)
resources :self_assigned, only: %i(index)
end
resources :products
Expand Down
26 changes: 25 additions & 1 deletion test/system/products_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,31 @@ def assigned_product_count
click_button '編集'
fill_in 'js-user-mentor-memo', with: '編集後のユーザーメモです。'
click_button '保存する'
assert_text '編集後のユーザーメモです。'
end

test 'can see unassigned-tab' do
visit_with_auth products_path, 'komagata'
assert find('.page-tabs__item-link', text: '未アサイン')
end

test 'can access unassigned products page after click unassigned-tab' do
visit_with_auth products_path, 'komagata'
find('.page-tabs__item-link', text: '未アサイン').click
assert find('h2.page-header__title', text: '未アサインの提出物')
end

test 'show unassigned products counter and can change counter after click assignee-button on unassigned-tab' do
visit_with_auth products_path, 'komagata'
unassigned_tab = find('#test-unassigned-tab')
initial_counter = find('#test-unassigned-counter').text

assignee_buttons = all('.a-button.is-block.is-secondary.is-sm', text: '担当する')
assignee_buttons.first.click

unassigned_tab.click
wait_for_vuejs
operated_counter = find('#test-unassigned-counter').text
assert_not_equal initial_counter, operated_counter
end

test 'show number of comments' do
Expand Down

0 comments on commit ff249f6

Please sign in to comment.