Skip to content

Commit

Permalink
Merge pull request #3 from akpaevj/feature-select-project
Browse files Browse the repository at this point in the history
Added project select field
  • Loading branch information
akpaevj authored May 16, 2021
2 parents f21f1d3 + 4a0a119 commit a26e8f4
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 29 deletions.
88 changes: 64 additions & 24 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,72 @@
class DashboardController < ApplicationController

def index
issues = []
for issue in Issue.visible() do
executor = ""
if !issue.assigned_to.nil?
executor = issue.assigned_to.name()
end

issues.push({
"id" => issue.id,
"subject" => issue.subject,
"status_id" => issue.status.id,
"author" => issue.author.name(User::USER_FORMATS[:firstname_lastname]),
"executor" => executor
})
if request.query_parameters.key?("project_id")
@selected_project_id = request.query_parameters["project_id"]
else
@selected_project_id = -1
end

@statuses = []
for status in IssueStatus.sorted() do
if !status.is_closed
@statuses.push({
"id" => status.id,
"name" => status.name,
"color" => Setting.plugin_dashboard["status_color_" + status.id.to_s],
"issues" => issues.select {|i| i["status_id"] == status.id }
})
end
@statuses = getData(@selected_project_id)
@projects = getProjects(@selected_project_id)
end
end

private

def getProjects(selected_project_id = -1)
projects = []
projects.push({
"id" => -1,
"name" => l(:label_all)
})

for project in Project.visible() do
selected = ""
if selected_project_id.to_s == project.id.to_s
selected = "selected"
end

projects.push({
"id" => project.id,
"name" => project.name,
"selected" => selected
})
end
return projects
end

def getData(project_id = -1)
issues = []
for issue in Issue.visible() do
if project_id != -1 && issue.project_id.to_s != project_id.to_s
next
end

executor = ""
if !issue.assigned_to.nil?
executor = issue.assigned_to.name()
end

issues.push({
"id" => issue.id,
"subject" => issue.subject,
"status_id" => issue.status.id,
"author" => issue.author.name(User::USER_FORMATS[:firstname_lastname]),
"executor" => executor
})
end

statuses = []
for status in IssueStatus.sorted() do
if !status.is_closed
statuses.push({
"id" => status.id,
"name" => status.name,
"color" => Setting.plugin_dashboard["status_color_" + status.id.to_s],
"issues" => issues.select {|i| i["status_id"] == status.id }
})
end
end
return statuses
end
14 changes: 13 additions & 1 deletion app/views/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
<% end %>

<label class="select_project"> <%=l :field_project %>
<select name="project">
<% @projects.each do |project| %>
<option <%= project["selected"] %> value="<%= project['id'] %>"><%= project["name"] %></option>
<% end %>
</select>
</label>

<div class="issues_container">
<% @statuses.each do |status| %>
<div class="status_column" data-id="<%= status['id'] %>">
Expand All @@ -25,4 +33,8 @@
</div>
</div>
<% end %>
</div>
</div>

<script>
init();
</script>
12 changes: 11 additions & 1 deletion assets/javascripts/script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function getUriWithoutDashboard() {
const reg = new RegExp('((?<=.+)\/dashboard$|\/$)');
const reg = new RegExp('((?<=.+)\/dashboard.*$|\/$)');
let baseUri = location.pathname;

if (baseUri.match(reg)!= null) {
Expand All @@ -12,4 +12,14 @@ function getUriWithoutDashboard() {
function goToIssue(id) {
const baseUri = getUriWithoutDashboard();
location.pathname = `${baseUri}/issues/${id}`;
}

function init() {
document.querySelector('[name=project]').addEventListener('change', function(e) {
if (this.value == "-1") {
location.search = "";
} else {
location.search = `project_id=${this.value}`;
}
});
}
4 changes: 4 additions & 0 deletions assets/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,8 @@
.issue_card .issue_card_executor i {
color: purple;
font-size: medium;
}

.select_project {
margin-left: 10px;
}
3 changes: 2 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
en:
top_menu_item_title: "Dashboard"
settings_header: "Colors of the status column header"
executor_not_set: "Not set"
executor_not_set: "Not set"
label_all: "All"
3 changes: 2 additions & 1 deletion config/locales/ru.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ru:
top_menu_item_title: "Панель задач"
settings_header: "Цвета заголовков колонок статусов"
executor_not_set: "Не установлен"
executor_not_set: "Не установлен"
label_all: "Все"
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name 'Dashboard'
author "Akpaev E.A."
description "Plugin adds an issues dashboard to the application"
version '1.0.2'
version '1.0.3'
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
Expand Down

0 comments on commit a26e8f4

Please sign in to comment.