Skip to content

Commit

Permalink
Merge pull request #14 from akpaevj/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
akpaevj authored May 20, 2021
2 parents b075cb4 + 2de35ce commit 060e49d
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 84 deletions.
100 changes: 62 additions & 38 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -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
end
53 changes: 35 additions & 18 deletions app/views/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,51 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<% end %>

<div class="select_project_container">
<% @projects.each do |project| %>
<% if project[:id].to_s == @selected_project_id.to_s %>
<div class="select_project_item select_project_item_selected" style="background-color: <%= project[:color] %>" data-id="<%= project[:id] %>"><%= project[:name] %></div>
<% else %>
<div class="select_project_item" style="background-color: <%= project[:color] %>" data-id="<%= project[:id] %>"><%= project[:name] %></div>
<% if @use_drop_down_menu %>
<label class="select_project"> <%=l :field_project %>
<select name="project">
<% @projects.each do |project_id, project| %>
<% if project_id == @selected_project_id %>
<option selected value="<%= project_id %>"><%= project[:name] %></option>
<% else %>
<option value="<%= project_id %>"><%= project[:name] %></option>
<% end %>
<% end %>
</select>
</label>
<% else %>
<div class="select_project_container">
<% @projects.each do |project_id, project| %>
<% if project_id == @selected_project_id %>
<div class="select_project_item select_project_item_selected" style="background-color: <%= project[:color] %>" data-id="<%= project_id %>"><%= project[:name] %></div>
<% else %>
<div class="select_project_item" style="background-color: <%= project[:color] %>" data-id="<%= project_id %>"><%= project[:name] %></div>
<% end %>
<% end %>
<% end %>
</div>
</div>
<% end %>

<div class="issues_container">
<% @statuses.each do |status| %>
<div class="status_column" data-id="<%= status[:id] %>">
<% @statuses.each do |status_id, status| %>
<div class="status_column" data-id="<%= status_id %>">
<div class="status_column_header" style="border-bottom-color: <%= status[:color] %>">
<span> <%= status[:name] %> </span>
</div>
<div class="<% status[:is_closed] ? ("status_column_closed_issues") : ("status_column_issues") %>">
<% @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'] %>
<div class="minimized_issue_card" style="border-bottom-color: <%= project_color %>" data-status="<%= status[:id] %>" data-id="<%= issue[:id] %>" onclick="goToIssue(<%= issue[:id] %>)">
<div class="<%= status[:is_closed] ? "status_column_closed_issues" : "status_column_issues" %>">
<% @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 %>
<div class="minimized_issue_card" style="border-bottom-color: <%= project_color %>" data-id="<%= issue[:id] %>" onclick="goToIssue(<%= issue[:id] %>)">
<span> <%= "#" + issue[:id].to_s %> </span>
</div>
<% else %>
<div class="issue_card" data-status="<%= status[:id] %>" data-id="<%= issue[:id] %>" onclick="goToIssue(<%= issue[:id] %>)">
<div class="issue_card" data-id="<%= issue[:id] %>" onclick="goToIssue(<%= issue[:id] %>)">
<div class="issue_card_header">
<span class="issue_card_header_date"><%= issue[:created_at] %></span>
<div class="issue_card_header_project" style="background-color: <%= project_color %>"><%= issue[:project].name %></div>
<% if @show_project_badge %>
<div class="issue_card_header_project" style="background-color: <%= project_color %>"><%= project_name %></div>
<% end %>
</div>
<span class="issue_card_title"> <%= issue[:subject] %> </span>
<span class="issue_card_author"><i class="bi bi-person"></i> <%= issue[:author] %> </span>
Expand All @@ -51,4 +68,4 @@

<script>
init();
</script>
</script>
12 changes: 12 additions & 0 deletions app/views/settings/_dashboard_settings.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
<tr>
<th colspan="2"> <%=l :settings_header_other %> </td>
</tr>
<tr>
<td> <%=l :settings_use_drop_down_menu %> </th>
<td>
<%= check_box_tag "settings[use_drop_down_menu]", false, @settings['use_drop_down_menu'] %>
</td>
</tr>
<tr>
<td> <%=l :settings_display_closed_statuses %> </th>
<td>
Expand All @@ -39,5 +45,11 @@
<%= check_box_tag "settings[display_minimized_closed_issue_cards]", false, @settings['display_minimized_closed_issue_cards'] %>
</td>
</tr>
<tr>
<td> <%=l :settings_display_child_projects_tasks %> </th>
<td>
<%= check_box_tag "settings[display_child_projects_tasks]", false, @settings['display_child_projects_tasks'] %>
</td>
</tr>
</tbody>
</table>
21 changes: 16 additions & 5 deletions assets/javascripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
41 changes: 22 additions & 19 deletions assets/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Loading

0 comments on commit 060e49d

Please sign in to comment.