Move tag statistics to its own route for asynchronous loading
This commit is contained in:
@ -63,4 +63,20 @@ class ExternalUsersController < ApplicationController
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tag_statistics
|
||||||
|
@user = ExternalUser.find(params[:id])
|
||||||
|
authorize!
|
||||||
|
|
||||||
|
statistics = []
|
||||||
|
tags = ProxyExercise.new().get_user_knowledge_and_max_knowledge(@user, @user.participations.uniq.compact)
|
||||||
|
tags[:user_topic_knowledge].each_pair do |key, value|
|
||||||
|
statistics.append({:key => key.name.to_s, :value => (100.0 / tags[:max_topic_knowledge][key] * value).round(2)})
|
||||||
|
end
|
||||||
|
statistics.sort_by! {|item| item[:value]}
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.json { render(json: statistics) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -2,4 +2,8 @@ class ExternalUserPolicy < AdminOnlyPolicy
|
|||||||
def statistics?
|
def statistics?
|
||||||
admin?
|
admin?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tag_statistics?
|
||||||
|
admin?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,9 +8,3 @@ br
|
|||||||
= link_to(t('shared.statistics'), statistics_external_user_path(@user))
|
= link_to(t('shared.statistics'), statistics_external_user_path(@user))
|
||||||
|
|
||||||
.tag-grid
|
.tag-grid
|
||||||
- tag_stats = ProxyExercise.new().get_user_knowledge_and_max_knowledge(@user, @user.participations.uniq.compact)
|
|
||||||
- tag_stats[:user_topic_knowledge].each do |key, value|
|
|
||||||
//p = key.name.to_s + ' -> ' + value.to_s + " (of #{tag_stats[:max_topic_knowledge][key].to_s })"
|
|
||||||
.tag-details
|
|
||||||
= key.name.to_s
|
|
||||||
= progress_bar((100.0 / tag_stats[:max_topic_knowledge][key] * value).round(2))
|
|
||||||
|
@ -128,6 +128,9 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
resources :external_users, only: [:index, :show], concerns: :statistics do
|
resources :external_users, only: [:index, :show], concerns: :statistics do
|
||||||
resources :exercises, concerns: :statistics
|
resources :exercises, concerns: :statistics
|
||||||
|
member do
|
||||||
|
get :tag_statistics
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
namespace :code_ocean do
|
namespace :code_ocean do
|
||||||
|
Reference in New Issue
Block a user