Skip to content

Commit

Permalink
Display job_family by count.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Guo committed Oct 28, 2024
1 parent b949506 commit b384700
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/controllers/admin/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ class HomeController < BaseController
before_action :check_brower, if: -> { request.format.html? }

def index
@job_family_data = JobRole.joins(:user_job_roles)
.group(:job_family)
.order("count(user_job_roles.user_id) desc")
.limit(7)
.count
end

protected
Expand Down
3 changes: 1 addition & 2 deletions app/javascript/lazy_controllers/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ const options = {
}
},
y: {
min: 30,
max: 89,
display: false,
grid: {
display: false
Expand Down Expand Up @@ -51,6 +49,7 @@ Stimulus.register("dashboard", class extends Controller {
}

connect() {
console.log(this.labelsValue, this.dataValue);
this.cardChart = new Chart(this.cardChartTarget, {
type: 'line',
data: {
Expand Down
10 changes: 5 additions & 5 deletions app/views/admin/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<div><%= t('user.active_user') -%></div>
</div>
</div>
<div class="c-chart-wrapper mt-3 mx-3" style="height:70px;" data-controller="dashboard"
data-dashboard-title-value='My First dataset'
data-dashboard-labels-value='["January", "February", "March", "April", "May", "June", "July"]'
data-dashboard-data-value='[65, 59, 84, 84, 51, 55, 40]'>
<canvas class="chart" height="70" data-dashboard-target="cardChart"></canvas>
<div class="c-chart-wrapper mt-3 mx-3" style="height:100px;" data-controller="dashboard"
data-dashboard-title-value='人数'
data-dashboard-labels-value='<%= @job_family_data.keys.to_json.html_safe -%>'
data-dashboard-data-value='<%= @job_family_data.values.to_json.html_safe -%>'>
<canvas class="chart" height="100" data-dashboard-target="cardChart"></canvas>
</div>
</div>
</div>
Expand Down

0 comments on commit b384700

Please sign in to comment.