diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index cc6a851..62fbf6f 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -1,62 +1,86 @@ -class DashboardController < ApplicationController +# frozen_string_literal: true +class DashboardController < ApplicationController def index - if request.query_parameters.key?("project_id") - @selected_project_id = request.query_parameters["project_id"] - else - @selected_project_id = -1 - end - - @statuses = getStatuses() - @projects = getProjects() - @issues = getIssues(@selected_project_id) + @use_drop_down_menu = Setting.plugin_dashboard['use_drop_down_menu'] + @selected_project_id = params[:project_id].nil? ? -1 : params[:project_id].to_i + show_sub_tasks = Setting.plugin_dashboard['display_child_projects_tasks'] + @show_project_badge = @selected_project_id == -1 || @selected_project_id != -1 && show_sub_tasks + @display_minimized_closed_issue_cards = Setting.plugin_dashboard['display_closed_statuses'] ? Setting.plugin_dashboard['display_minimized_closed_issue_cards'] : false + @statuses = get_statuses + @projects = get_projects + @issues = get_issues(@selected_project_id, show_sub_tasks) end private - def getStatuses - items = Setting.plugin_dashboard['display_closed_statuses'] ? (IssueStatus.sorted()) : (IssueStatus.sorted().where('is_closed = false')) - items.map { |item| { - :id => item.id, - :name => item.name, - :color => Setting.plugin_dashboard["status_color_" + item.id.to_s], - :is_closed => item.is_closed + def get_statuses + data = {} + items = Setting.plugin_dashboard['display_closed_statuses'] ? IssueStatus.sorted : IssueStatus.sorted.where('is_closed = false') + items.each do |item| + data[item.id] = { + :name => item.name, + :color => Setting.plugin_dashboard["status_color_" + item.id.to_s], + :is_closed => item.is_closed } - } + end + data end - def getProjects(project_id = -1) - items = [] - - items.push({ - :id => -1, + def get_projects + data = {-1 => { :name => l(:label_all), :color => '#4ec7ff' - }) + }} - Project.visible().where('status = 1').each do |item| - items.push({ - :id => item.id, + Project.visible.each do |item| + data[item.id] = { :name => item.name, :color => Setting.plugin_dashboard["project_color_" + item.id.to_s] - }) + } end - - items + data end - def getIssues(project_id = -1) - items = project_id == -1 ? (Issue.visible()) : (Issue.visible().where(:projects => {:id => project_id})) - items.map { |item| { + def get_issues(project_id, with_sub_tasks) + id_array = [] + + if project_id != -1 + id_array.push(project_id) + end + + # fill array of children ids + if project_id != -1 && with_sub_tasks + project = Project.find(project_id) + children = nil + loop do + if project.children.any? + children = project.children.first + id_array.push(children.id) + project = children + else + break + end + end + end + + items = id_array.empty? ? Issue.visible : Issue.visible.where(:projects => {:id => id_array}) + + unless Setting.plugin_dashboard['display_closed_statuses'] + items = items.open + end + + data = items.map do |item| + { :id => item.id, :subject => item.subject, :status_id => item.status.id, - :project => item.project, + :project_id => item.project.id, :created_at => item.start_date, :author => item.author.name(User::USER_FORMATS[:firstname_lastname]), - :executor => item.assigned_to.nil? ? ('') : (item.assigned_to.name()) + :executor => item.assigned_to.nil? ? '' : item.assigned_to.name } - } + end + data.sort_by { |item| item[:created_at]} end - -end \ No newline at end of file +end diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 5cb8ae7..9c4374f 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -5,34 +5,51 @@ <% end %> -