-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
会社個別 > 提出物一覧を vue.js 化した #4549
会社個別 > 提出物一覧を vue.js 化した #4549
Changes from all commits
4ec09cc
a39ff55
cc0c98b
dc00bf7
7c05f27
8c9bdc2
f88bf37
01c9b5a
8a3fb70
5646ab6
f985538
e2b18f8
df60ae1
4db6652
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
class API::ProductsController < API::BaseController | ||
before_action :require_staff_login_for_api, only: :index | ||
before_action :require_login_for_api, only: :index | ||
|
||
def index | ||
@company = Company.find(params[:company_id]) if params[:company_id] | ||
@products = Product | ||
.list | ||
.ascending_by_date_of_publishing_and_id | ||
.page(params[:page]) | ||
@products_grouped_by_elapsed_days = @products.group_by { |product| product.elapsed_days >= 7 ? 7 : product.elapsed_days } | ||
@products = @products.joins(:user).where(users: { company_id: params[:company_id] }) if params[:company_id] | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Vue from 'vue' | ||
import CompanyProducts from './company-products.vue' | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
const selector = '#js-company-products' | ||
const products = document.querySelector(selector) | ||
if (products) { | ||
const title = products.getAttribute('data-title') | ||
const companyID = products.getAttribute('company-id') | ||
const isMentor = products.getAttribute('data-mentor-login') | ||
const currentUserId = products.getAttribute('data-current-user-id') | ||
new Vue({ | ||
render: (h) => | ||
h(CompanyProducts, { | ||
props: { | ||
title: title, | ||
companyID: companyID, | ||
isMentor: isMentor === 'true', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 文字列で渡すことでwarningを回避しているんですね! |
||
currentUserId: currentUserId | ||
} | ||
}) | ||
}).$mount(selector) | ||
} | ||
}) |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,123 @@ | ||||||||
<template lang="pug"> | ||||||||
.page-body | ||||||||
.container(v-if='products.length === 0') | ||||||||
.o-empty-message | ||||||||
.o-empty-message__icon | ||||||||
i.far.fa-smile | ||||||||
p.o-empty-message__text | ||||||||
| {{ title }}はありません | ||||||||
.container.is-md(v-else) | ||||||||
nav.pagination(v-if='totalPages > 1') | ||||||||
pager(v-bind='pagerProps') | ||||||||
.thread-list.a-card | ||||||||
.thread-list__items | ||||||||
product( | ||||||||
v-for='product in products', | ||||||||
:key='product.id', | ||||||||
:product='product', | ||||||||
:currentUserId='currentUserId', | ||||||||
:isMentor='isMentor' | ||||||||
) | ||||||||
nav.pagination(v-if='totalPages > 1') | ||||||||
pager(v-bind='pagerProps') | ||||||||
</template> | ||||||||
|
||||||||
<script> | ||||||||
import Pager from 'pager.vue' | ||||||||
import Product from 'product.vue' | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. コメント有難うございます!komagataさんに確認いたします。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @clio209 こちらそのままで問題ございません〜 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @garammasala29 さん |
||||||||
|
||||||||
export default { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
公式ドキュメントなど1行空いていることが多い気がしますね |
||||||||
components: { | ||||||||
product: Product, | ||||||||
pager: Pager | ||||||||
}, | ||||||||
props: { | ||||||||
companyID: { type: String, required: true }, | ||||||||
title: { type: String, required: true }, | ||||||||
isMentor: { type: Boolean, required: true }, | ||||||||
currentUserId: { type: String, required: true } | ||||||||
}, | ||||||||
data() { | ||||||||
return { | ||||||||
products: [], | ||||||||
currentPage: Number(this.getParams().page) || 1, | ||||||||
totalPages: 0, | ||||||||
params: this.getParams() | ||||||||
} | ||||||||
}, | ||||||||
computed: { | ||||||||
url() { | ||||||||
return ( | ||||||||
'/api/products/' + | ||||||||
`?page=${this.currentPage}` + | ||||||||
(this.companyID ? `&company_id=${this.companyID}` : '') | ||||||||
) | ||||||||
}, | ||||||||
pagerProps() { | ||||||||
return { | ||||||||
initialPageNumber: this.currentPage, | ||||||||
pageCount: this.totalPages, | ||||||||
pageRange: 5, | ||||||||
clickHandle: this.paginateClickCallback | ||||||||
} | ||||||||
} | ||||||||
}, | ||||||||
created() { | ||||||||
window.onpopstate = () => { | ||||||||
location.replace(location.href) | ||||||||
} | ||||||||
this.getProducts() | ||||||||
}, | ||||||||
methods: { | ||||||||
token() { | ||||||||
const meta = document.querySelector('meta[name="csrf-token"]') | ||||||||
return meta ? meta.getAttribute('content') : '' | ||||||||
}, | ||||||||
getProducts() { | ||||||||
fetch(this.url, { | ||||||||
method: 'GET', | ||||||||
headers: { | ||||||||
'Content-Type': 'application/json; charset=utf-8', | ||||||||
'X-Requested-With': 'XMLHttpRequest', | ||||||||
'X-CSRF-Token': this.token() | ||||||||
}, | ||||||||
credentials: 'same-origin', | ||||||||
redirect: 'manual' | ||||||||
}) | ||||||||
.then((response) => { | ||||||||
return response.json() | ||||||||
}) | ||||||||
.then((json) => { | ||||||||
this.products = [] | ||||||||
json.products.forEach((product) => { | ||||||||
this.products.push(product) | ||||||||
}) | ||||||||
this.totalPages = json.total_pages | ||||||||
}) | ||||||||
.catch((error) => { | ||||||||
console.warn(error) | ||||||||
}) | ||||||||
}, | ||||||||
getParams() { | ||||||||
const params = {} | ||||||||
location.search | ||||||||
.slice(1) | ||||||||
.split('&') | ||||||||
.forEach((query) => { | ||||||||
const queryArr = query.split('=') | ||||||||
params[queryArr[0]] = queryArr[1] | ||||||||
}) | ||||||||
return params | ||||||||
}, | ||||||||
paginateClickCallback(pageNumber) { | ||||||||
this.currentPage = pageNumber | ||||||||
this.getProducts() | ||||||||
history.pushState(null, null, this.newUrl(pageNumber)) | ||||||||
window.scrollTo(0, 0) | ||||||||
}, | ||||||||
newUrl(pageNumber) { | ||||||||
return location.pathname + (pageNumber === 1 ? '' : `?page=${pageNumber}`) | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
</script> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ header.page-header | |
- if current_user.admin? || current_user.mentor? | ||
= render 'products/tabs' | ||
|
||
#js-products(data-title="#{title}" data-selected-tab="all" data-mentor-login="#{mentor_login?}" data-current-user-id="#{current_user.id}") | ||
#js-products(data-title="#{title}" data-selected-tab="all" data-mentor-login="#{mentor_login?}" data-current-user-id="#{current_user.id}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 今回のissueに関連はないかなと思うので、差分が出ていて気になりました! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. すいません、毎回コンフリクトが起こり、色々弄って先祖返りしたりしたためかと思われます。。恥💦💦 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
なるほど、joinsメソッドでテーブルを結合させて絞り込んでいるんですね👍