Skip to content

Commit

Permalink
BE changes to clean up the code, added tooltips to origin types
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasdrga committed Oct 3, 2024
1 parent ee63679 commit afeebfa
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 219 deletions.
244 changes: 119 additions & 125 deletions app/controllers/admin/metais/project_origins_controller.rb

Large diffs are not rendered by default.

30 changes: 6 additions & 24 deletions app/controllers/metais/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,13 @@ def show
@project_info = @project.get_project_origin_info
@project_origins = @project.project_origins

@assumption_events = []
@real_events = []
@project_origins.each do |project_origin|
@assumption_events.concat(project_origin.events.where(event_type: Metais::ProjectEventType.find_by(name: 'Predpoklad')))
@real_events.concat(project_origin.events.where(event_type: Metais::ProjectEventType.find_by(name: 'Realita')))
end
@assumption_events.sort_by! { |event| event.date }
@real_events.sort_by! { |event| event.date }
@assumption_events = @project_origins.flat_map { |project_origin| project_origin.events.assumpted }
@real_events = @project_origins.flat_map { |project_origin| project_origin.events.real }

@all_suppliers = []
@project_origins.each do |project_origin|
@all_suppliers.concat(project_origin.suppliers)
end
@all_suppliers.sort_by! { |event| event.date || Time.zone.parse('2999-12-31')}
@combined_suppliers = @project_origins.flat_map(&:suppliers).sort_by { |supplier| supplier.date || Time.zone.parse('2999-12-31') }
@combined_links = @project_origins.flat_map(&:links)
@combined_documents = @project_origins.flat_map(&:documents)

@all_links = []
@project_origins.each do |project_origin|
@all_links.concat(project_origin.links)
end

@all_documents = @project_origins.flat_map(&:documents)
@grouped_documents = @all_documents.group_by(&:description)
@grouped_documents = @grouped_documents.sort_by { |description, docs| docs.first.group_order || Float::INFINITY }

@project_origin = @project.project_origins.first
@project_origin = Metais::ProjectOrigin.includes(:documents, :suppliers).find(@project_origin.id)
@grouped_documents = @combined_documents.group_by(&:description).sort_by { |description, docs| docs.first.group_order || Float::INFINITY }
end
end
34 changes: 17 additions & 17 deletions app/helpers/metais/projects_helper.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
module Metais::ProjectsHelper
def origin_type_logo(origin_type)
if origin_type.is_a?(Integer)
case origin_type
when 3
'icons/sd_logo.png'
when 2
'icons/ai_logo.png'
else
'icons/metais_logo.png'
end
if origin_type.is_a?(Integer)
case origin_type
when 3
['icons/sd_logo.png', 'Slovensko.Digital']
when 2
['icons/ai_logo.png', 'Umelá inteligencia']
else
case origin_type.name
when 'Human'
'icons/sd_logo.png'
when 'AI'
'icons/ai_logo.png'
else
'icons/metais_logo.png'
end
['icons/metais_logo.png', 'MetaIS']
end
else
case origin_type.name
when 'Human'
['icons/sd_logo.png', 'Slovensko.Digital']
when 'AI'
['icons/ai_logo.png', 'Umelá inteligencia']
else
['icons/metais_logo.png', 'MetaIS']
end
end
end

def convert_to_list(text)
items = text.split('\n')
Expand Down
4 changes: 3 additions & 1 deletion app/models/metais/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def evaluations
end

def get_project_origin_info
return @project_origin_info if defined?(@project_origin_info)

finance_source_mappings = {"Medzirezortný program 0EK Informačné technológie financované zo štátneho rozpočtu" => "Štátny rozpočet"}

fields = %w[title status phase description guarantor project_manager start_date end_date
Expand All @@ -43,7 +45,7 @@ def get_project_origin_info
end
end

project_info
@project_origin_info = project_info
end

def self.evaluation_counts
Expand Down
8 changes: 8 additions & 0 deletions app/models/metais/project_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ class Metais::ProjectEvent < ApplicationRecord
belongs_to :project_origin, class_name: 'Metais::ProjectOrigin'
belongs_to :origin_type, class_name: 'Metais::OriginType'
belongs_to :event_type, class_name: 'Metais::ProjectEventType'

scope :assumpted, -> {
where(event_type: Metais::ProjectEventType.find_by(name: 'Predpoklad')).order(:date)
}

scope :real, -> {
where(event_type: Metais::ProjectEventType.find_by(name: 'Realita')).order(:date)
}
end
69 changes: 45 additions & 24 deletions app/views/admin/metais/project_origins/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
<div class="col-md-12 mb-3">
<h5><%= form.label :title, "Názov projektu" %>
<% if @project_info.title.present? %>
<%= image_tag origin_type_logo(@project_info.title.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.title.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h5>
<%= form.text_field :title, value: @project_info.title, class: "form-control" %>
</div>
<div class="col-md-12">
<h5><%= form.label :description, "Popis" %>
<% if @project_info.description.present? %>
<%= image_tag origin_type_logo(@project_info.description.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.description.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h5>
<%= form.text_area :description, value: @project_info.description, class: "form-control", rows: 12 %>
Expand All @@ -33,15 +35,17 @@
<div class="col-md-6">
<h6 class="m-0"><%= form.label :guarantor, "Garant" %>
<% if @project_info.guarantor.present? %>
<%= image_tag origin_type_logo(@project_info.guarantor.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.guarantor.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h6>
<%= form.text_field :guarantor, value: @project_info.guarantor, class: "form-control" %>
</div>
<div class="col-md-6">
<h6 class="m-0"><%= form.label :project_manager, "Projektový manažér" %>
<% if @project_info.project_manager.present? %>
<%= image_tag origin_type_logo(@project_info.project_manager.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.project_manager.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h6>
<%= form.text_field :project_manager, value: @project_info.project_manager, class: "form-control" %>
Expand All @@ -50,7 +54,8 @@
<div class="col-md-6 mt-3">
<h6 class="m-0"><%= form.label :finance_source, "Zdroj financovania" %>
<% if @project_info.finance_source.present? %>
<%= image_tag origin_type_logo(@project_info.finance_source.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.finance_source.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h6>
<% finance_source_mappings = {"Medzirezortný program 0EK Informačné technológie financované zo štátneho rozpočtu" => "Štátny rozpočet"} %>
Expand All @@ -60,13 +65,15 @@
<div class="col-md-6 mt-3">
<h6 class="m-0"><%= form.label :status, "Stav" %>
<% if @project_info.status.present? %>
<%= image_tag origin_type_logo(@project_info.status.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.status.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h6>
<%= form.select :status, Metais::ProjectOrigin.pluck(:status).uniq.reject(&:blank?), { selected: @project_info.status }, { class: "form-control" } %>
<h6 class="m-0 mt-3"><%= form.label :phase, "Fáza" %>
<% if @project_info.phase.present? %>
<%= image_tag origin_type_logo(@project_info.phase.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.phase.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h6>
<%= form.select :phase, Metais::ProjectOrigin.pluck(:phase).uniq.reject(&:blank?), { selected: @project_info.phase }, { class: "form-control" } %>
Expand All @@ -75,7 +82,8 @@
<div class="col-md-6 mt-3">
<h6 class="m-0"><%= form.label :start_date, "Dátum začiatku" %>
<% if @project_info.start_date.present? %>
<%= image_tag origin_type_logo(@project_info.start_date.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.start_date.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h6>
<%= form.date_field :start_date,
Expand All @@ -85,7 +93,8 @@
<div class="col-md-6 mt-3">
<h6 class="m-0"><%= form.label :end_date, "Termín ukončenia " %>
<% if @project_info.end_date.present? %>
<%= image_tag origin_type_logo(@project_info.end_date.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.end_date.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h6>
<%= form.date_field :end_date,
Expand All @@ -99,27 +108,31 @@
<div class="col-md-6">
<h6 class="m-0"><%= form.label :investment, "Investícia" %>
<% if @project_info.investment.present? %>
<%= image_tag origin_type_logo(@project_info.investment.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.investment.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h6>
<%= form.number_field :investment, value: @project_info.investment, step: 0.1, class: "form-control" %>
<h6 class="m-0 mt-3"><%= form.label :operation, "Ročné náklady" %>
<% if @project_info.operation.present? %>
<%= image_tag origin_type_logo(@project_info.operation.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.operation.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h6>
<%= form.number_field :operation, value: @project_info.operation, step: 0.1, class: "form-control" %>
</div>
<div class="col-md-6">
<h6 class="m-0"><%= form.label :approved_investment, "Schválená investícia" %>
<% if @project_info.approved_investment.present? %>
<%= image_tag origin_type_logo(@project_info.approved_investment.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.approved_investment.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h6>
<%= form.number_field :approved_investment, value: @project_info.approved_investment, step: 0.1, class: "form-control" %>
<h6 class="m-0 mt-3"><%= form.label :approved_operation, "Schválené ročné náklady" %>
<% if @project_info.approved_operation.present? %>
<%= image_tag origin_type_logo(@project_info.approved_operation.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.approved_operation.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h6>
<%= form.number_field :approved_operation, value: @project_info.approved_operation, step: 0.1, class: "form-control" %>
Expand All @@ -134,7 +147,8 @@
<div class="col-md-12">
<h5><%= form.label :targets_text, "Ciele a merateľné ukazovatele" %>
<% if @project_info.targets_text.present? %>
<%= image_tag origin_type_logo(@project_info.targets_text.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.targets_text.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h5>
<%= form.text_area :targets_text, value: @project_info.targets_text, class: "form-control", rows: 5 %>
Expand All @@ -145,7 +159,8 @@
<div class="col-md-12">
<h5><%= form.label :documents_text, "Dokumenty" %>
<% if @project_info.documents_text.present? %>
<%= image_tag origin_type_logo(@project_info.documents_text.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.documents_text.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h5>
<%= form.text_area :documents_text, value: @project_info.documents_text, class: "form-control", rows: 2 %>
Expand All @@ -156,7 +171,8 @@
<div class="col-md-12">
<h5><%= form.label :links_text, "Linky" %>
<% if @project_info.links_text.present? %>
<%= image_tag origin_type_logo(@project_info.links_text.origin), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(@project_info.links_text.origin) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<% end %>
</h5>
<%= form.text_area :links_text, value: @project_info.links_text, class: "form-control", rows: 2 %>
Expand Down Expand Up @@ -221,7 +237,8 @@
<% @assumption_events.each do |event| %>
<tr>
<td>
<%= image_tag origin_type_logo(event.origin_type), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(event.origin_type) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<%= event.name %>
</td>
<td><%= event.value %></td>
Expand Down Expand Up @@ -259,7 +276,8 @@
<% @real_events.each do |event| %>
<tr>
<td>
<%= image_tag origin_type_logo(event.origin_type), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(event.origin_type) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<%= event.name %>
</td>
<td><%= event.value %></td>
Expand Down Expand Up @@ -297,10 +315,11 @@
</tr>
</thead>
<tbody>
<% @all_suppliers.each do |supplier| %>
<% @combined_suppliers.each do |supplier| %>
<tr>
<td>
<%= image_tag origin_type_logo(supplier.origin_type), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(supplier.origin_type) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<b><%= supplier.supplier_type.name if supplier.supplier_type.present? %></b>
</td>
<td><%= link_to supplier.name, supplier.value, class: "w-100" %></td>
Expand Down Expand Up @@ -356,10 +375,11 @@
</tr>
</thead>
<tbody>
<% @all_documents.each do |document| %>
<% @combined_documents.each do |document| %>
<tr>
<td>
<%= image_tag origin_type_logo(document.origin_type), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(document.origin_type) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<b><%= document.name %></b>
</td>
<td><%= link_to document.value, document.value %></td>
Expand Down Expand Up @@ -395,10 +415,11 @@
</tr>
</thead>
<tbody>
<% @all_links.each do |link| %>
<% @combined_links.each do |link| %>
<tr>
<td>
<%= image_tag origin_type_logo(link.origin_type), style: "width: 16px; height: 16px;" %>
<% logo_path, tooltip_text = origin_type_logo(link.origin_type) %>
<%= image_tag logo_path, alt: tooltip_text, title: tooltip_text, style: "width: 16px; height: 16px;", class:"tag-tooltip" %>
<b><%= link.name %></b>
</td>
<td><%= link_to link.value, link.value %></td>
Expand Down
Loading

0 comments on commit afeebfa

Please sign in to comment.