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 %> -
- <% @projects.each do |project| %> - <% if project[:id].to_s == @selected_project_id.to_s %> -
<%= project[:name] %>
- <% else %> -
<%= project[:name] %>
+<% if @use_drop_down_menu %> + +<% else %> +
+ <% @projects.each do |project_id, project| %> + <% if project_id == @selected_project_id %> +
<%= project[:name] %>
+ <% else %> +
<%= project[:name] %>
+ <% end %> <% end %> - <% end %> -
+
+<% end %>
- <% @statuses.each do |status| %> -
+ <% @statuses.each do |status_id, status| %> +
<%= status[:name] %>
-
"> - <% @issues.select {|issue| issue[:status_id] == status[:id] }.each do |issue| %> - <% project_color = @projects.select {|item| item[:id] == issue[:project].id }[0][:color] %> - <% if status[:is_closed] && Setting.plugin_dashboard['display_minimized_closed_issue_cards'] %> -
+
"> + <% @issues.select { |issue| issue[:status_id] == status_id }.each do |issue| %> + <% project_color = @projects[issue[:project_id]][:color] %> + <% project_name = @projects[issue[:project_id]][:name] %> + <% if status[:is_closed] && @display_minimized_closed_issue_cards %> +
<%= "#" + issue[:id].to_s %>
<% else %> -
+
<%= issue[:created_at] %> -
<%= issue[:project].name %>
+ <% if @show_project_badge %> +
<%= project_name %>
+ <% end %>
<%= issue[:subject] %> <%= issue[:author] %> @@ -51,4 +68,4 @@ \ No newline at end of file + \ No newline at end of file diff --git a/app/views/settings/_dashboard_settings.erb b/app/views/settings/_dashboard_settings.erb index dc442af..38656c4 100644 --- a/app/views/settings/_dashboard_settings.erb +++ b/app/views/settings/_dashboard_settings.erb @@ -27,6 +27,12 @@ <%=l :settings_header_other %> + + <%=l :settings_use_drop_down_menu %> + + <%= check_box_tag "settings[use_drop_down_menu]", false, @settings['use_drop_down_menu'] %> + + <%=l :settings_display_closed_statuses %> @@ -39,5 +45,11 @@ <%= check_box_tag "settings[display_minimized_closed_issue_cards]", false, @settings['display_minimized_closed_issue_cards'] %> + + <%=l :settings_display_child_projects_tasks %> + + <%= check_box_tag "settings[display_child_projects_tasks]", false, @settings['display_child_projects_tasks'] %> + + \ No newline at end of file diff --git a/assets/javascripts/script.js b/assets/javascripts/script.js index 82dcafb..960b5b9 100644 --- a/assets/javascripts/script.js +++ b/assets/javascripts/script.js @@ -14,18 +14,29 @@ function goToIssue(id) { location.href = `${baseUri}/issues/${id}`; } +function chooseProject(projectId) { + if (projectId == "-1") { + location.search = ""; + } else { + location.search = `project_id=${projectId}`; + } +} + function init() { document.querySelector('#main-menu').remove(); document.querySelectorAll('.select_project_item').forEach(item => { item.addEventListener('click', function() { - if (this.dataset.id == "-1") { - location.search = ""; - } else { - location.search = `project_id=${this.dataset.id}`; - } + chooseProject(this.dataset.id); }) }); + const projectsSelector = document.querySelector('[name=project]'); + if (projectsSelector != null) { + projectsSelector.addEventListener('change', function(e) { + chooseProject(this.value); + }); + } + document.querySelector("#content").style.overflow = "hidden"; } \ No newline at end of file diff --git a/assets/stylesheets/style.css b/assets/stylesheets/style.css index f14214e..01c67a9 100644 --- a/assets/stylesheets/style.css +++ b/assets/stylesheets/style.css @@ -4,9 +4,12 @@ width: 100%; } +.select_project { + margin-left: 10px; +} + .status_column { display: inline-flex; - border-radius: 5px; width: 100%; margin-left: 3px; margin-right: 3px; @@ -16,7 +19,7 @@ .status_column_header { display: flex; width: 100%; - height: 50px; + height: min-content; align-items: center; font-size: medium; font-weight: 500; @@ -25,13 +28,13 @@ } .status_column_header span { - margin-left: 10px; + padding: 8px; } .status_column_issues { display: flex; width: 100%; - height: 100%; + height: fit-content; flex-direction: column; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; @@ -40,7 +43,7 @@ .status_column_closed_issues { display: flex; width: 100%; - height: 100%; + height: fit-content; flex-direction: row; flex-wrap: wrap; border-bottom-left-radius: 5px; @@ -50,29 +53,24 @@ .issue_card { display: flex; width: 100%; + margin: 2px; border-radius: 5px; - height: auto; - min-height: 50px; - margin-top: 5px; - padding-top: 5px; - padding-bottom: 5px; + height: min-content; background-color: rgb(240, 240, 240); align-self: center; - margin-bottom: 5px; align-items: flex-start; flex-direction: column; justify-content: center; - box-shadow: 0px 0px 2px 0px lightgray; } .minimized_issue_card { display: inline-flex; + flex: auto; width: min-content; align-items: center; justify-content: center; - margin-top: 5px; - margin-bottom: 5px; - height: auto; + margin: 2px; + height: min-content; border-radius: 5px; border-bottom: 2px solid; background-color: rgb(240, 240, 240); @@ -135,13 +133,17 @@ } .issue_card_header_project { + display: flex; margin-left: auto; padding-top: 5px; padding-bottom: 5px; padding-left: 10px; padding-right: 10px; margin-right: 10px; - border-radius: 15px; + border-radius: 200px; + width: fit-content; + height: fit-content; + text-align: center; color: rgb(255, 255, 255); font-size: smaller; } @@ -158,13 +160,14 @@ padding-bottom: 5px; padding-left: 8px; padding-right: 8px; - border-radius: 15px; - margin-right: 10px; + border-radius: 200px; + margin-right: 5px; color: white; opacity: 0.5; - min-width: 50px; + min-width: fit-content; align-items: center; justify-content: center; + transition: opacity .1s ease-in-out; } .select_project_item:hover { diff --git a/config/locales/en.yml b/config/locales/en.yml index d6c29d4..967648d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3,8 +3,10 @@ en: settings_header_statuses: "Statuses colors" settings_header_projects: "Projects colors" settings_header_other: "Other" + settings_use_drop_down_menu: 'Use drop-down menu for the project choosing' settings_display_closed_statuses: 'Display "closed" statuses' + settings_display_child_projects_tasks: 'Display child projects tasks' settings_display_minimized_closed_issue_cards: 'Display minimized "closed" issue cards' - settings_enable_drag_and_drop: 'Enable "drag and drop" status changing' + settings_enable_drag_and_drop: '"Drag and drop" status changing' executor_not_set: "Not set" label_all: "All" \ No newline at end of file diff --git a/config/locales/ru.yml b/config/locales/ru.yml index f65b6d8..6ac1f71 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -3,8 +3,10 @@ ru: settings_header_statuses: "Цвета статусов" settings_header_projects: "Цвета проектов" settings_header_other: "Разное" + settings_use_drop_down_menu: 'Использовать выпадающий список для выбора проекта' settings_display_closed_statuses: 'Отображать "закрытые" статусы' + settings_display_child_projects_tasks: 'Отображать задачи дочерних проектов' settings_display_minimized_closed_issue_cards: 'Отображать свернутые карточки "закрытых" задач' - settings_enable_drag_and_drop: 'Включить "drag and drop" изменение статуса' + settings_enable_drag_and_drop: '"Drag and drop" изменение статуса' executor_not_set: "Не установлен" label_all: "Все" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index f3d1637..7bda2c4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,2 +1,2 @@ get 'dashboard', to: 'dashboard#index' -get 'dashboard/setIssueStatus', to: 'dashboard#setIssueStatus' +get 'dashboard/dashboard_data', to: 'dashboard#dashboard_data' diff --git a/init.rb b/init.rb index aa9e553..61bec1d 100644 --- a/init.rb +++ b/init.rb @@ -2,7 +2,7 @@ name 'Dashboard' author "Akpaev E.A." description "Plugin adds an issues dashboard to the application" - version '1.0.6' + version '1.0.7' url 'https://github.com/akpaevj/Dashboard' author_url 'https://github.com/akpaevj' menu :top_menu, :dashboard, { controller: 'dashboard', action: 'index' }, caption: :top_menu_item_title, first: true