Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SD-2693/Metais-projects #151

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
dfd99d1
Metais projects added
tomasdrga Aug 21, 2024
b321e94
Use structure.sql instead of schema.rb
tomasdrga Aug 21, 2024
d6f76c1
Cleaned up jobs, change some editing stuff
tomasdrga Aug 21, 2024
8290907
try to use db scturcture in tests
celuchmarek Aug 22, 2024
0556bd3
Added jobs for data extraction from python model
tomasdrga Aug 22, 2024
7d9b7a5
Merge branch 'SD-2693/Metais-projects' of github.com:slovensko-digita…
tomasdrga Aug 22, 2024
0bb2f84
Jobs rspec tests added
tomasdrga Aug 23, 2024
9ca24b3
Added documents to edit, tailwind style status badges, project index …
tomasdrga Aug 23, 2024
74fa0a1
Change the model structure between projects and metais_projects
tomasdrga Aug 25, 2024
b7ee240
Added prefix file for metais module
tomasdrga Aug 25, 2024
8ac7751
Metais in separate rake task
tomasdrga Aug 25, 2024
0b18cb7
multiple fixes
celuchmarek Aug 26, 2024
a3c7678
Merge branch 'master' into SD-2693/Metais-projects
celuchmarek Aug 26, 2024
d2e0d00
metais admin and ai
celuchmarek Aug 26, 2024
2faf6fe
raise an error on problematic extraction result job
celuchmarek Aug 27, 2024
ea545c1
Filter changes, small fixes, texts, fe
tomasdrga Sep 16, 2024
7ede0ae
Filter moved to models, added the same filter to admin, small fe changes
tomasdrga Sep 17, 2024
9cecb36
Fixed admin editing, FE stuff, filters for evaluations, misc stuff
tomasdrga Sep 24, 2024
747defa
Ordering of project documents, js errors fixed
tomasdrga Sep 25, 2024
bc05039
Modified the CI workflow to create datahub_test db
tomasdrga Sep 26, 2024
0ace20a
fixed failing rspec tests
tomasdrga Sep 30, 2024
f87241e
Added datahub db structure
tomasdrga Sep 30, 2024
21bd5b0
Test doubles in correct format
tomasdrga Sep 30, 2024
45de608
Change from instance double to double
tomasdrga Sep 30, 2024
ee63679
SyncProjectEventsJobSpec further changes
tomasdrga Sep 30, 2024
afeebfa
BE changes to clean up the code, added tooltips to origin types
tomasdrga Oct 3, 2024
e46e9f9
Added legend for project origin types, be fixes
tomasdrga Oct 3, 2024
e338404
Rake tasks execution time moved, linking of projects through metais c…
tomasdrga Oct 4, 2024
7e0473a
Separated the delete logic from data extraction result job, modified …
tomasdrga Oct 4, 2024
b2e270e
Update app/jobs/link_metais_projects_and_evaluations_job.rb
celuchmarek Oct 7, 2024
c2cbf41
grammar fix
celuchmarek Oct 7, 2024
56ff094
simplify sorting
celuchmarek Oct 7, 2024
74ace44
add AI button and fix AI result handle empty
celuchmarek Oct 9, 2024
f59eadb
handle no project plan in ai
celuchmarek Oct 9, 2024
d20b654
handle file deletion if even ai docs not found
celuchmarek Oct 9, 2024
5528eb2
fix redirect after ai start post
celuchmarek Oct 9, 2024
9b049b2
Sort direction field change fixed
tomasdrga Oct 10, 2024
b4fe070
Merged changes
tomasdrga Oct 10, 2024
bcd551c
Resolved conflict in metais/project.rb
tomasdrga Oct 10, 2024
d8834a0
Data extraction jobs modified for new extractor
tomasdrga Jan 31, 2025
2336ed1
Merged master branch into SD-2693/Metais-projects
tomasdrga Jan 31, 2025
347ba57
Migrated structure.sql
tomasdrga Jan 31, 2025
3dd0af5
Removed transaction timeout from structure.sql
tomasdrga Jan 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 69 additions & 25 deletions app/controllers/metais/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
class Metais::ProjectsController < ApplicationController
def index
@guarantor_data = Metais::ProjectOrigin.guarantor_data
@status_data = Metais::ProjectOrigin.status_data
@evaluation_counts = Metais::Project.evaluation_counts

per_page = 25
page = params[:page] || 1

@projects = Metais::Project.all

if params[:guarantor].present? || params[:title].present? || params[:status].present? || params[:code].present? || params[:min_price].present? || params[:max_price].present? || params[:sort].present?
@projects = @projects.joins(:project_origins)
end


distinct_projects_subquery = Metais::Project
.joins(:project_origins)
.joins("JOIN (SELECT project_id, MAX(origin_type_id) AS max_origin_type_id
FROM metais.project_origins
GROUP BY project_id)
po_max
ON metais.projects.id = po_max.project_id
AND metais.project_origins.origin_type_id = po_max.max_origin_type_id")
.select('DISTINCT metais.projects.id')

@projects = Metais::Project
.joins(:project_origins)
.joins("JOIN (SELECT project_id, MAX(origin_type_id) AS max_origin_type_id
FROM metais.project_origins
GROUP BY project_id)
po_max
ON metais.projects.id = po_max.project_id
AND metais.project_origins.origin_type_id = po_max.max_origin_type_id")
.where(id: distinct_projects_subquery)
.select('metais.projects.*, project_origins.approved_investment, project_origins.investment')
celuchmarek marked this conversation as resolved.
Show resolved Hide resolved

if params[:guarantor].present?
@projects = @projects.where('project_origins.guarantor = ?', params[:guarantor])
end
Expand All @@ -23,15 +43,21 @@ def index
end

if params[:code].present?
@projects = @projects.where('code = ?', params[:code])
@projects = @projects.where('code ILIKE ?', "%#{params[:code]}%")
end

if params[:min_price].present?
@projects = @projects.where('project_origins.investment >= ?', params[:min_price])
min_price = params[:min_price].to_f
@projects = @projects.where(
'COALESCE(NULLIF(metais.project_origins.approved_investment, 0), metais.project_origins.investment, 0) >= ?', min_price
)
end

if params[:max_price].present?
@projects = @projects.where('project_origins.investment <= ?', params[:max_price])
max_price = params[:max_price].to_f
@projects = @projects.where(
'COALESCE(NULLIF(metais.project_origins.approved_investment, 0), metais.project_origins.investment, 0) <= ?', max_price
)
end

if params[:has_evaluation].present?
Expand All @@ -45,22 +71,40 @@ def index
}.map(&:id))
end

case params[:sort]
when 'alpha'
@projects = @projects.order('project_origins.title ASC')
@projects = @projects.distinct.select("metais.projects.*, project_origins.title")
when 'date'
@projects = @projects.order('project_origins.metais_created_at ASC')
@projects = @projects.distinct.select("metais.projects.*, project_origins.metais_created_at")

when 'price'
@projects = @projects.order('project_origins.investment ASC')
@projects = @projects.distinct.select("metais.projects.*, project_origins.investment")

else
@projects = @projects.order(updated_at: :desc)
@projects = @projects.distinct.select("metais.projects.*")
if params[:sort].present?
case params[:sort]
when 'alpha'
if params[:sort_direction].present?
sort_direction = params[:sort_direction].upcase == 'ASC' ? 'ASC' : 'DESC'
else
sort_direction = 'DESC'
end
@projects = @projects.order("metais.project_origins.title #{sort_direction}")
when 'date'
if params[:sort_direction].present?
sort_direction = params[:sort_direction].upcase == 'ASC' ? 'ASC' : 'DESC'
else
sort_direction = 'DESC'
end
@projects = @projects.order("metais.project_origins.metais_created_at #{sort_direction}")
when 'price'
if params[:sort_direction].present?
sort_direction = params[:sort_direction].upcase == 'ASC' ? 'ASC' : 'DESC'
else
sort_direction = 'DESC'
end
@projects = @projects.order("COALESCE(NULLIF(metais.project_origins.approved_investment, 0),
NULLIF(metais.project_origins.investment, 0),
0) #{sort_direction} NULLS FIRST")

else
if params[:sort_direction].present?
sort_direction = params[:sort_direction].upcase == 'ASC' ? 'ASC' : 'DESC'
else
sort_direction = 'DESC'
end
@projects = @projects.select("distinct on (updated_at) projects.*").order("updated_at #{sort_direction}")
end
end

@projects = @projects.page(page).per(per_page)
Expand Down
17 changes: 14 additions & 3 deletions app/models/metais/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
class Metais::Project < ApplicationRecord
has_many :project_origins, :class_name => 'Metais::ProjectOrigin'
has_and_belongs_to_many :projects, class_name: 'Project',
join_table: 'public.projects_metais_projects',
foreign_key: 'metais_project_id',
association_foreign_key: 'project_id'
join_table: 'public.projects_metais_projects',
foreign_key: 'metais_project_id',
association_foreign_key: 'project_id'

def evaluations
::Project.joins('''
Expand All @@ -39,4 +39,15 @@ def get_project_origin_info

project_info
end

def self.evaluation_counts
total_count = Metais::Project.count
yes_count = Metais::Project
.joins('INNER JOIN public.projects_metais_projects ON public.projects_metais_projects.metais_project_id = metais.projects.id')
.distinct
.count('metais.projects.id')
no_count = total_count - yes_count

{ yes: yes_count, no: no_count }
end
end
14 changes: 14 additions & 0 deletions app/models/metais/project_origin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,18 @@ class Metais::ProjectOrigin < ApplicationRecord
has_many :suppliers, class_name: 'Metais::ProjectSupplier', foreign_key: 'project_origin_id'
has_many :events, class_name: 'Metais::ProjectEvent', foreign_key: 'project_origin_id'
has_many :links, class_name: 'Metais::ProjectLink', foreign_key: 'project_origin_id'

def self.guarantor_data
{
counts: self.group(:guarantor).count,
unique_guarantors: self.pluck(:guarantor).reject(&:blank?).uniq
}
end

def self.status_data
{
counts: self.group(:status).count,
unique_statuses: self.pluck(:status).reject(&:blank?).uniq
}
end
celuchmarek marked this conversation as resolved.
Show resolved Hide resolved
end
2 changes: 1 addition & 1 deletion app/views/admin/metais/projects/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<tr id="<%= dom_id project %>">
<td><%= project.id %></td>
<td class="w-50" colspan="10">
<%= link_to project.project_origins.first.title, admin_metais_project_path(project) %>
<%= link_to project.project_origins.first.title, metais_project_path(project) %>
</td>
<td class="text-center">
<%= project.project_origins.count %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/components/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<%= link_to 'Štátne IT projekty', metais_projects_path, class: 'nav-link' %>
</li>
<li class="nav-item mr-lg-4 <%= "active" if current_page?(projects_path) %>">
<%= link_to 'Hodnotenia', projects_path, class: 'nav-link' %>
<%= link_to 'Hodnotenia Red Flags', projects_path, class: 'nav-link' %>
</li>
<li class="nav-item mr-lg-4 d-lg-none <%= "active" if current_page?(about_path) %>">
<%= link_to 'Čo je Red Flags', about_path, class: 'nav-link' %>
Expand Down
Loading
Loading