Skip to content
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

プラクティスの進捗を % でなく、完了プラクティスの個数 / プラクティス全体の個数 として表示する #3191

Merged
merged 6 commits into from
Sep 6, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ $bar-height: .75rem
+position(relative, top $bar-height * -1)
box-shadow: rgba(black, .2) 0 .0625rem .0625rem

.completed-practices-progress__percentage-number
.completed-practices-progress__number
+text-block(.875rem 1rem, right)
+size(2.5rem 1rem)
7 changes: 4 additions & 3 deletions app/javascript/user-practice-progress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
role='progressbar',
:style='`width: ${roundedPercentage}`'
)
.completed-practices-progress__percentage-number
| {{ roundedPercentage }}
.completed-practices-progress__number
| {{ fraction }}
</template>
<script>
export default {
Expand All @@ -19,7 +19,8 @@ export default {
},
data() {
return {
percentage: this.user.cached_completed_percentage
percentage: this.user.cached_completed_percentage,
fraction: this.user.completed_fraction
}
},
computed: {
Expand Down
19 changes: 13 additions & 6 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,13 @@ def away?
end

def completed_percentage
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

パーセントが不要ならこのメソッド自体不要かも?

Copy link
Contributor

@konaga-k konaga-k Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ピンク色のプログレスバーを表示する計算でまだ必要になると思ってたんですがどうでしょう

@rjtt17
実はいらなかったりします?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@komagata
CC: @konaga-k
ご確認ありがとうございました🙇‍♂️
プログレスバーを表示している、app/views/users/practices/_completed_practices_progress.html.slim app/javascript/user-practice-progress.vue 等でパーセント使っているので、残しておいたのですが、不要でしょうか?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rjtt17 そちらを見逃していました。それだったら問題ございません〜

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@komagata ご確認ありがとうございました🙇‍♂️

practices_include_progress = course.practices.where(include_progress: true)

completed_practices_include_progress =
practices_include_progress.joins(:learnings)
.merge(Learning.complete.where(user_id: id))

completed_practices_include_progress.size.to_f / practices_include_progress.size * MAX_PERCENTAGE
end

def completed_fraction
"#{completed_practices_include_progress.size}/#{practices_include_progress.size}"
end

def completed_practices_size(category)
Practice
.joins({ categories: :categories_practices }, :learnings)
Expand Down Expand Up @@ -565,4 +563,13 @@ def update_mentor_memo(new_memo)
def password_required?
new_record? || password.present?
end

def practices_include_progress
course.practices.where(include_progress: true)
end

def completed_practices_include_progress
practices_include_progress.joins(:learnings)
.merge(Learning.complete.where(user_id: id))
end
end
2 changes: 1 addition & 1 deletion app/views/api/users/_list_user.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
json.(user, :id, :login_name, :name, :discord_account, :description, :github_account, :twitter_account, :facebook_url, :blog_url, :times_url, :job_seeker, :free, :job, :os, :experience, :email, :role, :icon_title,:cached_completed_percentage)
json.(user, :id, :login_name, :name, :discord_account, :description, :github_account, :twitter_account, :facebook_url, :blog_url, :times_url, :job_seeker, :free, :job, :os, :experience, :email, :role, :icon_title, :cached_completed_percentage, :completed_fraction)
json.tag_list user.tags.pluck(:name)
json.url user_url(user)
json.updated_at l(user.updated_at)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
- percentage = user.cached_completed_percentage
- fraction = user.completed_fraction
.completed-practices-progress
.completed-practices-progress__bar-container
.completed-practices-progress__bar
.completed-practices-progress__percentage-bar(aria-valuemax='100' aria-valuemin='0' aria-valuenow="#{percentage}" role='progressbar' style="width: #{number_to_percentage percentage, precision: 0};")
.completed-practices-progress__percentage-number
= number_to_percentage percentage, precision: 0
.completed-practices-progress__number
= fraction
28 changes: 27 additions & 1 deletion test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,37 @@ class UserTest < ActiveSupport::TestCase
assert_not_equal old_percentage, user.completed_percentage

old_percentage = user.completed_percentage
user.completed_practices << practices(:practice52)
user.completed_practices << practices(:practice55)

assert_equal old_percentage, user.completed_percentage
end

test '#completed_fraction don\'t calculate practice that include_progress: false' do
user = users(:komagata)
old_fraction = user.completed_fraction
user.completed_practices << practices(:practice5)

assert_not_equal old_fraction, user.completed_fraction

old_fraction = user.completed_fraction
user.completed_practices << practices(:practice53)

assert_equal old_fraction, user.completed_fraction
end

test '#completed_fraction don\'t calculate practice unrelated cource' do
user = users(:komagata)
old_fraction = user.completed_fraction
user.completed_practices << practices(:practice5)

assert_not_equal old_fraction, user.completed_fraction

old_fraction = user.completed_fraction
user.completed_practices << practices(:practice55)

assert_equal old_fraction, user.completed_fraction
end

test '#depressed?' do
user = users(:kimura)
2.times do |i|
Expand Down