Skip to content

Commit

Permalink
Merge pull request #3191 from fjordllc/feature/change-practices-progress
Browse files Browse the repository at this point in the history
プラクティスの進捗を % でなく、完了プラクティスの個数 / プラクティス全体の個数 として表示する
  • Loading branch information
komagata authored Sep 6, 2021
2 parents 2cefbf6 + 9272fd0 commit 3b6f9f3
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 14 deletions.
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 @@ -335,15 +335,13 @@ def away?
end

def completed_percentage
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 @@ -547,4 +545,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

0 comments on commit 3b6f9f3

Please sign in to comment.