Skip to content

Commit

Permalink
Adds Decommissioned as a status.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Scherz committed Jun 14, 2024
1 parent ec87653 commit ea071a7
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 19 deletions.
6 changes: 4 additions & 2 deletions app/controllers/front_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ def search
@parameter = params[:search].downcase
search_term = "%#{@parameter}%"

software_records_columns = SoftwareRecord.columns.map { |column| "lower(#{column.name}) LIKE :search" }
@softwarerecords_results = SoftwareRecord.where(software_records_columns.join(' OR '), search: search_term)
software_records_columns = SoftwareRecord.columns.map { |column| "lower(software_records.#{column.name}) LIKE :search" }
@softwarerecords_results = SoftwareRecord.joins(:status)
.where.not(statuses: { status_type: 'Decommissioned' })
.where(software_records_columns.join(' OR '), search: search_term)

vendor_records_columns = VendorRecord.columns.map { |column| "lower(#{column.name}) LIKE :search" }
@vendorrecords_results = VendorRecord.where(vendor_records_columns.join(' OR '), search: search_term)
Expand Down
63 changes: 53 additions & 10 deletions app/controllers/software_records_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ def index
@params = request.query_parameters

@software_records = if @params['filter_by'].to_s == 'software_types' && !@params['software_type_filter'].nil? && !@params['software_type_filter'].empty?
SoftwareRecord.where(software_type_id: @params['software_type_filter']).order("#{sort_column} #{sort_direction}")
SoftwareRecord.joins(:status).where(software_type_id:
@params['software_type_filter']).where.not(statuses: { status_type: 'Decommissioned' }).order("#{sort_column} #{sort_direction}")
elsif @params['filter_by'].to_s == 'vendor_records' && !@params['vendor_record_filter'].nil? && !@params['vendor_record_filter'].empty?
SoftwareRecord.where(vendor_record_id: @params['vendor_record_filter']).order("#{sort_column} #{sort_direction}")
SoftwareRecord.joins(:status).where(vendor_record_id:
@params['vendor_record_filter']).where.not(statuses: { status_type: 'Decommissioned' }).order("#{sort_column} #{sort_direction}")
else
SoftwareRecord.order("#{sort_column} #{sort_direction}")
SoftwareRecord.joins(:status).where.not(statuses: { status_type: 'Decommissioned' }).order("#{sort_column}
#{sort_direction}")
end
@vendor_records = VendorRecord.all
@software_types = SoftwareType.all
@softwarerecords_count = SoftwareRecord.count
end

def self.indesign_dashboard(user)
design_status = Status.where(status_type: 'Design')
design_status = Status.where(status_type: %w[Design Development])
design_filter = SoftwareRecord.where(status_id: 0)
design_status.each do |design|
design_filter = design_filter.or(SoftwareRecord.where(status_id: design.id))
Expand Down Expand Up @@ -158,16 +161,53 @@ def check_and_decrypt(sensitive_data)
decrypt sensitive_data if sensitive_data.to_s.present?
end

def list_decommissioned
$page_title = 'Decommissioned Software | UCL Application Portfolio'
@params = request.query_parameters

@software_records = if @params['filter_by'].to_s == 'software_types' && !@params['software_type_filter'].nil? &&
!@params['software_type_filter'].empty?
SoftwareRecord.joins(:status).where(software_type_id: @params['software_type_filter']).where(status:
'Decommissioned').order("#{sort_priority} #{sort_direction_priority}")
elsif @params['filter_by'].to_s == 'vendor_records' && !@params['vendor_record_filter'].nil? &&
!@params['vendor_record_filter'].empty?
SoftwareRecord.joins(:status).where(vendor_record_id: @params['vendor_record_filter']).where(status:
'Decommissioned').order("#{sort_priority} #{sort_direction_priority}")
else
SoftwareRecord.joins(:status).where(statuses: { status_type: 'Decommissioned' }).order("#{sort_column}
#{sort_direction}")
end
@vendor_records = VendorRecord.all
@software_types = SoftwareType.all
@softwarerecords_count = SoftwareRecord.count
end

def edit_decommissioned
@software_record = SoftwareRecord.find(params[:id])
end

def update_decommissioned
@software_record = SoftwareRecord.find(params[:id])
if @software_record.update(software_record_params)
redirect_to list_decommissioned_path, notice: 'The Software title has been re-commissioned.'
else
render :edit_decommissioned
end
end

def list_upgrades
$page_title = 'Maintenance Priority| UCL Application Portfolio'
@params = request.query_parameters

@software_records = if @params['filter_by'].to_s == 'software_types' && !@params['software_type_filter'].nil? && !@params['software_type_filter'].empty?
SoftwareRecord.where(software_type_id: @params['software_type_filter']).order("#{sort_priority} #{sort_direction_priority}")
SoftwareRecord.joins(:status).where(software_type_id:
@params['software_type_filter']).where.not(statuses: { status_type: 'Decommissioned' }).order("#{sort_priority} #{sort_direction_priority}")
elsif @params['filter_by'].to_s == 'vendor_records' && !@params['vendor_record_filter'].nil? && !@params['vendor_record_filter'].empty?
SoftwareRecord.where(vendor_record_id: @params['vendor_record_filter']).order("#{sort_priority} #{sort_direction_priority}")
SoftwareRecord.joins(:status).where(vendor_record_id:
@params['vendor_record_filter']).where.not(statuses: { status_type: 'Decommissioned' }).order("#{sort_priority} #{sort_direction_priority}")
else
SoftwareRecord.order("#{sort_priority} #{sort_direction_priority}")
SoftwareRecord.joins(:status).where.not(statuses: { status_type: 'Decommissioned' }).order("#{sort_priority}
#{sort_direction_priority}")
end
@vendor_records = VendorRecord.all
@software_types = SoftwareType.all
Expand All @@ -179,12 +219,15 @@ def list_road_map
@params = request.query_parameters

@software_records = if @params['filter_by'].to_s == 'software_types' && !@params['software_type_filter'].nil? && !@params['software_type_filter'].empty?
SoftwareRecord.where(software_type_id: @params['software_type_filter']).order("#{sort_priority} #{sort_direction_priority}")
SoftwareRecord.joins(:status).where(software_type_id: @params['software_type_filter']).where.not(status:
'Decommissioned').order("#{sort_priority} #{sort_direction_priority}")
elsif @params['filter_by'].to_s == 'vendor_records' && !@params['vendor_record_filter'].nil? &&
!@params['vendor_record_filter'].empty?
SoftwareRecord.where(vendor_record_id: @params['vendor_record_filter']).order("#{sort_priority} #{sort_direction_priority}")
SoftwareRecord.joins(:status).where(vendor_record_id: @params['vendor_record_filter']).where.not(status:
'Decommissioned').order("#{sort_priority} #{sort_direction_priority}")
else
SoftwareRecord.order("#{sort_column} #{sort_direction}")
SoftwareRecord.joins(:status).where.not(statuses: { status_type: 'Decommissioned' }).order("#{sort_column}
#{sort_direction}")
end
@vendor_records = VendorRecord.all
@software_types = SoftwareType.all
Expand Down
9 changes: 5 additions & 4 deletions app/views/shared/_dashboard_menu.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
<a href="<%= hosting_environments_path %>"><i class="fab fa-envira float-right"></i> View all Hosting Environments</a>
<a href="<%= change_requests_path %>"><i class="fab fa-envira float-right"></i> View all Change Requests</a>
<hr style="background-color: white">
<a href="<%= list_upgrades_path %>"><i class="fas fa-users float-right"></i> Next Software Upgrades</a>
<a href="<%= list_upgrades_path %>"><i class="fas fa-users float-right"></i> Maintenance List</a>
<a href="<%= list_road_map_path %>"><i class="fas fa-users float-right"></i> Road Map List</a>
<a href="<%= list_decommissioned_path %>"><i class="fas fa-users float-right"></i> Decommissioned List</a>
<a href="<%= users_path %>"><i class="fas fa-users float-right"></i> Manage all Users</a>
<a href="<%= file_uploads_new_path %>"><i class="fas fa-file-import float-right"></i> Import Data</a>
<hr style="background-color: white">
Expand All @@ -47,9 +48,9 @@
<a href="<%= statuses_path %>"><i class="far fa-file-alt float-right"></i> View all Status</a>
<a href="<%= hosting_environments_path %>"><i class="fab fa-envira float-right"></i> View all Hosting Environments</a>
<hr style="background-color: white">
<a href="<%= list_upgrades_path %>"><i class="fas fa-users float-right"></i> Next Software Upgrades</a>
<a href="<%= list_upgrades_path %>"><i class="fas fa-users float-right"></i> Maintenance List</a>
<a href="<%= list_road_map_path %>"><i class="fas fa-users float-right"></i> Road Map List</a>
<a href="<%= change_requests_path %>"><i class="fab fa-envira float-right"></i> View all Change Requests</a>
<a href="<%= change_requests_path %>"><i class="fab fa-envira float-right"></i> Change Request List</a>
</div>
<br/>
<% end %>
Expand All @@ -65,7 +66,7 @@
<a href="<%= hosting_environments_path %>"><i class="fab fa-envira float-right"></i> View all Hosting Environments</a>
<a href="<%= change_requests_path %>"><i class="fab fa-envira float-right"></i> View all Change Request</a>
<hr style="background-color: white">
<a href="<%= list_upgrades_path %>"><i class="fas fa-users float-right"></i> Next Software Upgrades</a>
<a href="<%= list_upgrades_path %>"><i class="fas fa-users float-right"></i> Maintenance List</a>
<a href="<%= list_road_map_path %>"><i class="fas fa-users float-right"></i> Road Map List</a>
<hr style="background-color: white">
<a href="<%= export_software_records_path %>"><i class="fas fa-file-export float-right"></i> Export Software Records</a>
Expand Down
38 changes: 38 additions & 0 deletions app/views/software_records/edit_decommissioned.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="container animated fadeIn" style="opacity: 0.8;">
<div class="card-detail bg-dark text-white p-4">
<hr class="bg-white">

<h1 class="text-center" style="color: white;">Edit Software Status</h1>

<%= form_with(model: @software_record, url: update_decommissioned_software_record_path(@software_record), local: true, class: 'mt-4') do |form| %>
<% if @software_record.errors.any? %>
<div id="error_explanation" class="alert alert-danger">
<h2><%= pluralize(@software_record.errors.count, "error") %> prohibited this status from being saved:</h2>
<ul>
<% @software_record.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<% if !@software_record.title.nil? && !@software_record.title.to_s.empty? %>
<div class="form-group">
<%= form.label :title, class: 'form-label' %>
<p class="form-control-plaintext text-white"><%= @software_record.title %></p> <!-- Display the title but don't allow editing -->
</div>
<% end %>

<div class="form-group">
<%= form.label :status_id, class: 'form-label' %>
<%= form.collection_select :status_id, Status.all, :id, :title, prompt: "Select Status" %>
</div>

<div class="actions mt-3">
<%= form.submit 'Update', class: 'btn btn-primary' %>
<%= link_to 'Back', software_records_path, class: 'btn btn-secondary ml-2' %>
</div>
<% end %>
</div>
</div>

58 changes: 58 additions & 0 deletions app/views/software_records/list_decommissioned.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<section class="jumbotron text-center">
<br/>
<hr style = "background-color: black; width: 54%;">
<div class="container-fluid">
<h1 class="jumbotron-heading display-4" style="text-align: center; color: black; font-family: Courier New, Lucida, Console">Decommissioned
List</h1>
<em style="font-size: 14px; color: black">Collection of all the software application that have been decommissioned.</em><br/><br/>
</div>
<br/>
<hr style = "background-color: black; width: 54%;">
</section>

<% if @softwarerecords_count != 0 %>
<div class="container animated fadeInLeft" style="margin-bottom: 10rem">
<div class="row">
<table class="table software-records-table" style="word-break: initial;">
<thead>
<tr>
<th class="text-left" style="padding-left: 20px"><%= sortable "title", "Title" %>
<% if params[:direction] == "asc" || params[:direction] == nil %>
<i class="fa fa-caret-up"></i>
<% else %>
<i class="fa fa-caret-down"></i>
<% end %></th>

<% if current_user.role.to_s == "viewer" %>
<th class="text-left" style="padding-left: 20px">Actions</th>
<% elsif current_user.role.to_s == "owner" %>
<th colspan="2" class="text-left" style="padding-left: 20px">Actions</th>
<% else %>
<th colspan="3" class="text-left" style="padding-left: 20px">Actions</th>
<% end %>
</tr>
</thead>

<tbody>
<% @software_records.each do |software_record| %>
<tr>
<td style="padding-left: 40px; white-space: nowrap;"><%= software_record.title %></td>
<% if current_user.role.to_s == "viewer" %>
<td><%= link_to 'View', software_record , { :class => "btn btn-success action-btn" }%></td>
<% elsif current_user.role.to_s == "owner" %>
<td><%= link_to 'Change Status', edit_decommissioned_software_record_path(software_record), class: "btn btn-primary action-btn", style:
"white-space: nowrap;" %></td>
<% else %>
<td><%= link_to 'Change Status', edit_decommissioned_software_record_path(software_record), class: "btn btn-primary action-btn", style:
"white-space: nowrap;" %></td>

<% end %>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
<% else %>
<h3 class="text-center">No records found</h3>
<% end %>
6 changes: 4 additions & 2 deletions app/views/statuses/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
<div class="field">
<%= form.label :status_type %>
<% if component.eql?("new") %>
<%= form.select :status_type, options_for_select(['Design', 'Production', 'Other'], :selected=>"Design"), {}, {:class => "form-control"} %>
<%= form.select :status_type, options_for_select(['Design', 'Production', 'Decommissioned', 'Development', 'Other'], :selected=>"Design"),
{}, {:class => "form-control"} %>
<% else %>
<%= form.select :status_type, options_for_select(['Design', 'Production', 'Other'], :selected=>Status.find_by_id(params[:id]).status_type.to_s), {}, {:class => "form-control"} %>
<%= form.select :status_type, options_for_select(['Design', 'Production', 'Decommissioned', 'Development', 'Other'],
:selected=>Status.find_by_id(params[:id]).status_type.to_s), {}, {:class => "form-control"} %>
<% end %>
</div>
<br/><br/>
Expand Down
10 changes: 10 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,25 @@
root 'front#index'
get 'list_upgrades' => 'software_records#list_upgrades'
get 'list_road_map' => 'software_records#list_road_map'
get 'list_decommissioned' => 'software_records#list_decommissioned'

resources :software_records do
member do
get 'edit_road_map'
patch 'update_road_map'
end
end

resources :software_records do
member do
get 'edit_decommissioned'
patch 'update_decommissioned'
end
end

# get 'software_records/:id/edit_roadmap', to: 'software_records#edit_road_map', as: 'edit_road_map_software_record'
get 'edit_road_map_software_records' => 'software_records#list_road_map'
get 'edit_decommissioned_software_records' => 'software_records#list_decommissioned'
get 'about', to: 'front#about'
get 'contact', to: 'front#contact'
get 'request/new', to: 'front#new'
Expand Down
3 changes: 2 additions & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
# Create default status types
status = { 'Available': 'Production',
'Development': 'Design',
'Production': 'Production' }
'Production': 'Production',
'Decommissioned': 'Decommissioned' }

status.each do |name, desc|
Status.create(title: name, status_type: desc)
Expand Down
10 changes: 10 additions & 0 deletions lib/tasks/create_decommissioned.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

namespace 'app_port' do
desc 'Creates Decommissioned Status'
task create_decom: :environment do
# NOTE: In order to see progress in the logs, you must have logging at :info or above
WorksResave.work_resave
Status.new(title: 'Decommissioned', status_type: 'Decommissioned')
end
end

0 comments on commit ea071a7

Please sign in to comment.