From d3b42f91691af66c15a705763f562e3c052aa650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BA=D0=BF=D0=B0=D0=B5=D0=B2=20=D0=95=D0=B2=D0=B3?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0?= =?UTF-8?q?=D0=BD=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Fri, 21 May 2021 10:24:21 +0300 Subject: [PATCH 1/2] added button for colors generating --- app/controllers/dashboard_controller.rb | 9 +------ app/views/dashboard/index.html.erb | 2 +- app/views/settings/_dashboard_settings.erb | 15 ++++++++++++ assets/javascripts/script.js | 28 ++++++++++++---------- config/locales/en.yml | 1 + config/locales/ru.yml | 1 + 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index c1b96a3..d8171f8 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -6,6 +6,7 @@ def index @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 + @use_drag_and_drop = Setting.plugin_dashboard['enable_drag_and_drop'] @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 @@ -43,14 +44,6 @@ def get_statuses data end - def get_random_dark_color - 'hsl(' + Random.new.rand(0..360).to_s + ', 60%, 75%)' - end - - def get_random_light_color - 'hsl(' + Random.new.rand(0..360).to_s + ', 100%, 50%)' - end - def get_projects data = {-1 => { :name => l(:label_all), diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 780ac2d..c6329d7 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -61,6 +61,6 @@ \ No newline at end of file diff --git a/app/views/settings/_dashboard_settings.erb b/app/views/settings/_dashboard_settings.erb index 38656c4..ded2312 100644 --- a/app/views/settings/_dashboard_settings.erb +++ b/app/views/settings/_dashboard_settings.erb @@ -1,3 +1,7 @@ +<% content_for :header_tags do %> + <%= javascript_include_tag 'settings', plugin: 'dashboard' %> +<% end %> + @@ -24,9 +28,20 @@ <% end %> + + + + +
+ + +
<%=l :settings_header_other %>
<%=l :settings_enable_drag_and_drop %> + + <%= check_box_tag "settings[enable_drag_and_drop]", true, @settings['enable_drag_and_drop'] %> +
<%=l :settings_use_drop_down_menu %> diff --git a/assets/javascripts/script.js b/assets/javascripts/script.js index 3f70066..9aeb7e8 100644 --- a/assets/javascripts/script.js +++ b/assets/javascripts/script.js @@ -34,7 +34,7 @@ async function setIssueStatus(issueId, statusId, item, oldContainer, oldIndex) { } } -function init() { +function init(useDragAndDrop) { document.querySelector('#main-menu').remove(); document.querySelectorAll('.select_project_item').forEach(item => { @@ -52,17 +52,19 @@ function init() { document.querySelector("#content").style.overflow = "hidden"; - document.querySelectorAll('.status_column_closed_issues, .status_column_issues').forEach(item => { - new Sortable(item, { - group: 'issues', - animation: 150, - draggable: '.issue_card', - onEnd: async function(evt) { - const newStatus = evt.to.closest('.status_column').dataset.id; - const issueId = evt.item.dataset.id; - - await setIssueStatus(issueId, newStatus, evt.item, evt.from, evt.oldIndex); - } + if (useDragAndDrop) { + document.querySelectorAll('.status_column_closed_issues, .status_column_issues').forEach(item => { + new Sortable(item, { + group: 'issues', + animation: 150, + draggable: '.issue_card', + onEnd: async function(evt) { + const newStatus = evt.to.closest('.status_column').dataset.id; + const issueId = evt.item.dataset.id; + + await setIssueStatus(issueId, newStatus, evt.item, evt.from, evt.oldIndex); + } + }) }) - }) + } } \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 967648d..a02a128 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -8,5 +8,6 @@ en: 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: '"Drag and drop" status changing' + settings_generate_colors: "Generate colors" 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 6ac1f71..0133eb7 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -8,5 +8,6 @@ ru: settings_display_child_projects_tasks: 'Отображать задачи дочерних проектов' settings_display_minimized_closed_issue_cards: 'Отображать свернутые карточки "закрытых" задач' settings_enable_drag_and_drop: '"Drag and drop" изменение статуса' + settings_generate_colors: "Сгенерировать цвета" executor_not_set: "Не установлен" label_all: "Все" \ No newline at end of file From e9ae2bc0ef3dbced993c3c8b3da94a70241b15e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BA=D0=BF=D0=B0=D0=B5=D0=B2=20=D0=95=D0=B2=D0=B3?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0?= =?UTF-8?q?=D0=BD=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Fri, 21 May 2021 10:25:51 +0300 Subject: [PATCH 2/2] . --- assets/javascripts/settings.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 assets/javascripts/settings.js diff --git a/assets/javascripts/settings.js b/assets/javascripts/settings.js new file mode 100644 index 0000000..6f564c6 --- /dev/null +++ b/assets/javascripts/settings.js @@ -0,0 +1,22 @@ +function hslToHex(h, s, l) { + l /= 100; + const a = s * Math.min(l, 1 - l) / 100; + const f = n => { + const k = (n + h / 30) % 12; + const color = l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1); + return Math.round(255 * color).toString(16).padStart(2, '0'); + }; + return `#${f(0)}${f(8)}${f(4)}`; + } + +function getRandomColor() { + return hslToHex(Math.random() * 360, 100, 45); +} + +function generateColors() { + document.querySelectorAll('input[type=color]').forEach(function(item) { + if (item.value == '#000000') { + item.value = getRandomColor(); + } + }); +} \ No newline at end of file