-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
0b7e58a
refactor: Rebase
goo314 bc6c7ec
fix: Delete routers of profile-contest
goo314 07e6875
feat: Add ProfileContest vue
goo314 b9b44af
feat: Publish user contest page
goo314 365c56f
add: Add file in gitignore
goo314 1867d42
feat: Add Pagination component
goo314 59987a7
feat: Add methods for each button in pagination vue
goo314 606cd19
chore: Remove chart.js outside frontend folder
goo314 cdba955
fix: Show at most limit pages
goo314 0e421b4
style: Shorten style code
goo314 6694e96
fix: Add component communication(props, event)
goo314 fc89247
style: Apply Pagination vue
goo314 eea45dd
style: Edit code style
goo314 91e7d1e
feat: Create USerContestAPI
goo314 9a04321
add: Calate and return user rank in UserContestAPI
goo314 79abf47
style: Change code style
goo314 2d03088
add: Add rank field in ACMContestRank & Shorten UserContestAPI
goo314 61456b6
add: Connect UserContestAPI to ProfileContest page
goo314 8ee4300
feat: Add sorting contests function in ProfileContest
goo314 b8b6528
fix: Connect sorting api to ProfileContest
goo314 8facf45
feat: Add test for user-contest-api
goo314 26489aa
feat: add contestprize model
jimin9038 b7adf68
style: Change code style
goo314 03e7fe9
migrate model change
jimin9038 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -196,3 +196,6 @@ typings/ | |
|
||
# devcontainer | ||
.devcontainer/data | ||
|
||
# MacOS file | ||
.DS_Store |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Generated by Django 3.2.12 on 2022-03-02 05:13 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('contest', '0012_rename_total_score_acmcontestrank_total_penalty'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='contest', | ||
name='constraints', | ||
field=models.JSONField(default=list), | ||
), | ||
migrations.AddField( | ||
model_name='contest', | ||
name='requirements', | ||
field=models.JSONField(default=list), | ||
), | ||
migrations.AddField( | ||
model_name='contest', | ||
name='scoring', | ||
field=models.TextField(default='ACM-ICPC style'), | ||
), | ||
migrations.CreateModel( | ||
name='ContestPrize', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('color', models.TextField()), | ||
('name', models.TextField()), | ||
('reward', models.TextField()), | ||
('contest', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contest.contest')), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name='acmcontestrank', | ||
name='prize', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='contest.contestprize'), | ||
), | ||
migrations.AddField( | ||
model_name='oicontestrank', | ||
name='prize', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='contest.contestprize'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<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: { | ||
localLimit () { | ||
return Number(this.limit) | ||
}, | ||
numberOfPages () { // number of pages | ||
return Math.ceil(this.totalRows / this.perPage) | ||
}, | ||
startPage () { | ||
return Math.trunc((this.currentPage - 1) / this.localLimit) * this.localLimit + 1 | ||
}, | ||
endPage () { | ||
return this.startPage + this.localLimit - 1 <= this.numberOfPages ? this.startPage + this.localLimit - 1 : this.numberOfPages | ||
}, | ||
pageList () { | ||
return [...Array(this.endPage - this.startPage + 1).keys()].map(i => i + this.startPage) | ||
} | ||
} | ||
} | ||
</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; | ||
} | ||
|
||
.leftedge { | ||
border-top-left-radius: 0.25rem !important; | ||
border-bottom-left-radius: 0.25rem !important; | ||
} | ||
|
||
.rightedge { | ||
border-top-right-radius: 0.25rem !important; | ||
border-bottom-right-radius: 0.25rem !important; | ||
} | ||
|
||
.select { | ||
background-color: #bdbdbd; | ||
border: thin solid #bdbdbd; | ||
color: white; | ||
pointer-events: none; | ||
z-index: 1; | ||
} | ||
|
||
.page-btn:hover { | ||
background-color: #e9ecee; | ||
} | ||
|
||
</style> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
수정했어요!