-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add User Contest in Profile Page & Add Pagination component #291
Changes from 12 commits
0b7e58a
bc6c7ec
07e6875
b9b44af
365c56f
1867d42
59987a7
606cd19
cdba955
0e421b4
6694e96
fc89247
eea45dd
91e7d1e
9a04321
79abf47
2d03088
61456b6
8ee4300
b8b6528
8facf45
26489aa
b7adf68
03e7fe9
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 |
---|---|---|
|
@@ -196,3 +196,6 @@ typings/ | |
|
||
# devcontainer | ||
.devcontainer/data | ||
|
||
# MacOS file | ||
.DS_Store |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<template> | ||
<div class="page-itm"> | ||
<div @click="changePage(1)" class="page-btn leftedge">«</div> | ||
<div @click="changePage(currentPage-1)" class="page-btn"><</div> | ||
<div | ||
v-for="page in pageList" | ||
:key="page" | ||
@click="changePage(page)" | ||
:class="[ page==currentPage? 'page-btn select': 'page-btn' ]"> | ||
{{page}} | ||
</div> | ||
<div @click="changePage(currentPage+1)" class="page-btn">></div> | ||
<div @click="changePage(numberOfPages)" class="page-btn rightedge">»</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'Pagination', | ||
props: { | ||
totalRows: { // number of total rows in table | ||
type: Number | ||
}, | ||
perPage: { // number of rows in table per one page | ||
type: Number | ||
}, | ||
limit: { | ||
type: String | ||
} | ||
}, | ||
data () { | ||
return { | ||
currentPage: 1 | ||
} | ||
}, | ||
methods: { | ||
changePage (page) { | ||
if (page >= 1 && page <= this.numberOfPages) { | ||
this.currentPage = page | ||
this.$emit('input', this.currentPage) | ||
} | ||
} | ||
}, | ||
computed: { | ||
numberOfPages () { // number of pages | ||
return Math.ceil(this.totalRows / this.perPage) | ||
}, | ||
startPage () { | ||
var start = (Math.trunc((this.currentPage - 1) / this.limit)) * this.limit + 1 | ||
return start | ||
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. 한 줄로 수정해주세요. 참고로 return Math.trunc((this.currentPage - 1) / this.limit) * this.limit + 1 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. 아하 네 |
||
}, | ||
endPage () { | ||
var end = this.startPage + Number(this.limit) - 1 | ||
return end <= this.numberOfPages ? end : this.numberOfPages | ||
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. return this.startPage + Number(this.limit) - 1 <= this.numberOfPages ? end : this.numberOfPages 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. 이것도 곧 수정하겠습니다 |
||
}, | ||
pageList () { | ||
var pages = [] | ||
for (let i = this.startPage; i <= this.endPage; i++) { | ||
pages.push(i) | ||
} | ||
return pages | ||
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. 구글링하다 나온건데, 이렇게 쓰는 게 좀 더 깔끔할 거 같아요. /* this.limit의 type이 Number라면 Number()는 필요 없음 */
return [...Array(Number(this.limit)).keys()].map(i => i + this.startPage) 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. 만약 페이지 수가 3이고, limit 값이 5이면 오류가 날 수 있을 것 같아요. 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. 한 줄로 고쳤습니다 |
||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.page-itm { | ||
width: 95%; | ||
margin: 20px 5% 16px 0; | ||
display: flex; | ||
justify-content: flex-end !important; | ||
flex-direction: row; | ||
} | ||
|
||
.page-btn { | ||
width: 35px; | ||
height: 38px; | ||
text-align: center; | ||
margin-left: -1px; | ||
line-height: 35px; | ||
color: #bdbdbd; | ||
border: thin solid #dadada; | ||
cursor: pointer; | ||
} | ||
|
||
.page-btn.leftedge { | ||
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. 아래 라인들도 마찬가지입니다! 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. 수정했습니다 |
||
border-top-left-radius: 0.25rem !important; | ||
border-bottom-left-radius: 0.25rem !important; | ||
} | ||
|
||
.page-btn.rightedge { | ||
border-top-right-radius: 0.25rem !important; | ||
border-bottom-right-radius: 0.25rem !important; | ||
} | ||
|
||
.page-btn.select { | ||
background-color: #bdbdbd; | ||
border: thin solid #bdbdbd; | ||
color: white; | ||
pointer-events: none; | ||
} | ||
|
||
.page-btn:hover { | ||
background-color: #e9ecee; | ||
} | ||
|
||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,155 @@ | ||
<script src="./node_modules/chart.js/dist/chart.js"></script> | ||
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. Chart.js 패키지는 NPM으로 설치했으니까, 이 라인은 필요 없습니다. 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. 네! |
||
<template> | ||
<div class="profile-contest"> | ||
<div class="section-title mt-4 mb-3"> | ||
My Contest Rank Transition | ||
<div class="section-title mt-4 mb-3">My Contest Rank Transition</div> | ||
|
||
<div class="rank-chart"> | ||
<canvas id="myChart"></canvas> | ||
</div> | ||
|
||
<div class="sort-container"> | ||
<b-dropdown text="Date" class="mr-4"> | ||
<b-dropdown-item>All</b-dropdown-item> | ||
<b-dropdown-item>Rank</b-dropdown-item> | ||
<b-dropdown-item>Prize</b-dropdown-item> | ||
</b-dropdown> | ||
</div> | ||
|
||
<div class="table"> | ||
<b-table hover :items="items" :fields="fields" head-variant="light"> | ||
<template #cell(title)="data">{{ data.item.title }}</template> | ||
<template #cell(prize)="data"> | ||
<b-icon | ||
icon="circle-fill" | ||
style="color: #ff6663" | ||
font-scale="1.2" | ||
></b-icon> | ||
{{ data.item.prize }} | ||
</template> | ||
</b-table> | ||
</div> | ||
<div class="pagination"> | ||
<Pagination | ||
v-model="currentPage" | ||
:total-rows="rows" | ||
:per-page="perPage" | ||
limit="5" | ||
></Pagination> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { Chart, registerables } from "chart.js"; | ||
import Pagination from "../Pagination.vue"; | ||
Chart.register(...registerables); | ||
|
||
export default { | ||
name: 'ProfileContest', | ||
components: { | ||
}, | ||
props: { | ||
}, | ||
data () { | ||
components: { Pagination }, | ||
props: {}, | ||
data() { | ||
return { | ||
} | ||
rows: 100, | ||
currentPage: 1, | ||
perPage: 3, | ||
Chart, | ||
fields: [ | ||
{ key: "date", label: "Date" }, | ||
{ key: "title", label: "Title" }, | ||
{ key: "rank", label: "Rank" }, | ||
{ key: "prize", label: "Prize" }, | ||
], | ||
items: [ | ||
{ | ||
date: "2021-12-31", | ||
title: "SKKU Coding Platform 모의대회", | ||
rank: "1", | ||
prize: "Top3", | ||
}, | ||
{ | ||
date: "2021-12-31", | ||
title: "SKKU Coding Platform 2차 모의대회", | ||
rank: "2", | ||
prize: "Top5", | ||
}, | ||
{ | ||
date: "2021-12-31", | ||
title: "SKKU Coding Platform 3차 모의대회", | ||
rank: "100", | ||
prize: "Top2", | ||
}, | ||
], | ||
}; | ||
}, | ||
async mounted () { | ||
async mounted() { | ||
this.drawChart(); | ||
}, | ||
methods: { | ||
|
||
drawChart() { | ||
const ctx = document.getElementById("myChart"); | ||
const myChart = new Chart(ctx, { | ||
type: "line", | ||
data: { | ||
labels: [ | ||
"Contest1", | ||
"Contest2", | ||
"Contest3", | ||
"Contest4", | ||
"Contest5", | ||
"Contest6", | ||
], | ||
datasets: [ | ||
{ | ||
label: "Me", | ||
data: [30, 85, 20, 100, 50, 1], | ||
borderColor: "#FF6663", | ||
backgroundColor: "#FF6663", | ||
}, | ||
], | ||
}, | ||
options: { | ||
responsive: true, | ||
plugins: { | ||
legend: { | ||
position: "top", | ||
}, | ||
}, | ||
}, | ||
}); | ||
}, | ||
}, | ||
computed: { | ||
} | ||
} | ||
computed: {}, | ||
}; | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.profile-contest { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center | ||
} | ||
.profile-contest { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
.rank-chart { | ||
width: 80%; | ||
} | ||
|
||
.sort-container { | ||
width: 95%; | ||
margin-top: 30px; | ||
display: flex; | ||
justify-content: flex-end !important; | ||
} | ||
|
||
.table { | ||
width: 95%; | ||
margin: 0 auto; | ||
cursor: pointer; | ||
} | ||
.pagination { | ||
width: 95%; | ||
margin-right: 5%; | ||
margin-top: 20px; | ||
display: flex; | ||
justify-content: flex-end !important; | ||
} | ||
</style> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,7 +119,7 @@ export default [ | |
{ | ||
name: 'profile', | ||
path: '/profile', | ||
meta: { requiresAuth: true, title: 'My Profile' }, | ||
meta: { title: 'My Profile' }, | ||
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. 백엔드 서버 없이 실행하면서 작업하다 보니 (ㅠㅠㅠ) 저부분은 무시해주세요! |
||
component: Profile | ||
}, | ||
{ | ||
|
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.
limit
은 어떤 목적으로 사용되는 변수인가요?String
type으로 되어있는데, 아래에는 숫자 연산(/, *)이 있어서 확인 부탁드려요.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.
Pagination에 페이지 번호가 최대 몇개 보여질지 나타내는 변수입니다.
총 페이지가 10이고, limit가 3일때 방향키를 누를때마다 (1,2,3), (4,5,6), (7,8,9), (10) 의 페이지가 차례대로 보여요.
b-pagination과 호환되게 코드를 작성하라고 하셔서,
b-pagination의 경우 props를 :limit="3" 가 아닌 limit="3" 문자열으로 받기에 이렇게 코드를 작성했습니다.
javascript상에서 문자열 3과 숫자 3과 동일하다고 들어서 코드의 실행에는 상관이 없지만 혹시 문제가 된다면 바꾸겠습니다 😃
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.
BootstrapVue 문서 확인해보니까
Number or String
으로 명시되어있는데, 여기도 그렇게 하는 게 나을 것 같아요.https://bootstrap-vue.org/docs/components/pagination#__BVID__579__row_limit
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.
BootstrapVue 코드도 확인해봤는데, 이렇게 integer로 명시적으로(explicit) 변환하는 함수가 있더라고요.
https://github.com/bootstrap-vue/bootstrap-vue/blob/c645a33790ccaa0e4695dc7b74f9c9d7a812aa8d/src/mixins/pagination.js#L79
물론 javascript가 dynamic typed라서 string도 number 연산이 가능하긴 하지만, 이런 암시적인(implicit) 코드를 짜면 어느 부분에서 에러가 날지 예측하기도 어렵고, 가독성도 떨어져서 가급적 지양하는 게 좋아요.
이 부분에서는 computed로
localLimit () { return Number(this.limit) }
처럼 사용하는 게 바람직해 보이네요.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.
수정했어요!