Skip to content

Commit

Permalink
Add report configuration tab to admission processes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoFelipe committed Jan 19, 2024
1 parent a44d319 commit bc959e0
Show file tree
Hide file tree
Showing 22 changed files with 311 additions and 6 deletions.
13 changes: 13 additions & 0 deletions app/assets/stylesheets/active_scaffold_overrides.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ a.disabled {
.active-scaffold-header div.actions a.class_schedule_pdf,
.active-scaffold-header div.actions a.show_config_list,
.active-scaffold-header div.actions a.configure_all,
.active-scaffold-header div.actions a.custom_report,
.active-scaffold-header div.actions div.action_group div {
margin: 0;
padding: 5px 5px 5px 25px;
Expand Down Expand Up @@ -137,6 +138,18 @@ a.disabled {
top: 25%;
}

.active-scaffold-header div.actions a.custom_report {
position: relative;
}

.active-scaffold-header div.actions a.custom_report:before {
content: "\f1c9"; /* this is your text. You can also use UTF-8 character codes as I do here */
font-family: FontAwesome;
left: 8px;
position: absolute;
top: 25%;
}

.active-scaffold-header div.actions a.to_pdf,
.active-scaffold-header div.actions a.class_schedule_pdf {
background-image: url("pdfIcon.gif");
Expand Down
122 changes: 121 additions & 1 deletion app/controllers/admissions/admission_processes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ class Admissions::AdmissionProcessesController < ApplicationController
page: true,
type: :member,
parameters: { format: :xlsx }
config.action_links.add "custom_report",
label: I18n.t("active_scaffold.admissions/admission_process.custom_report.title"),
type: :collection

config.columns[:form_template].form_ui = :record_select
config.columns[:form_template].options[:params] = {
Expand Down Expand Up @@ -106,16 +109,19 @@ class Admissions::AdmissionProcessesController < ApplicationController
)

def short_pdf
load_admission_report_config
get_admission_process_pdf("short_pdf")
end

def complete_pdf
load_admission_report_config
get_admission_process_pdf("complete_pdf")
end

def complete_xls
@admission_process = Admissions::AdmissionProcess.find(params[:id])
@admission_report_config = Admissions::AdmissionReportConfig.new.init_default
load_admission_report_config

respond_to do |format|
format.xlsx
end
Expand Down Expand Up @@ -280,7 +286,66 @@ def calculate_ranking
respond_to_action(:calculate_ranking)
end

def custom_report
do_custom_report
respond_to_action(:custom_report)
end

def custom_report_generate
do_custom_report_generate
respond_to_action(:custom_report_generate)
end

def reset_report
session.delete(:admission_report_config) if session.include? :admission_report_config
load_admission_report_config
@on_form = params[:on_form]
respond_to_action(:reset_report)
ensure
params.delete :on_form if params.include? :on_form
end

protected
def load_admission_report_config
@admission_report_config = Admissions::AdmissionReportConfig.new.init_default
if session[:admission_report_config].present?
update_record_from_params(
@admission_report_config,
Admissions::AdmissionReportConfigsController.active_scaffold_config.create.columns,
session[:admission_report_config]
)
end
end

def do_show
load_admission_report_config
super
end

def do_custom_report
load_admission_report_config
end

def do_custom_report_generate
do_custom_report
self.successful = false
update_record_from_params(
@admission_report_config,
Admissions::AdmissionReportConfigsController.active_scaffold_config.create.columns,
params[:record]
)
old_name = @admission_report_config.name
@admission_report_config.name = "Dinamico"
self.successful = successful? || [
@admission_report_config.keeping_errors { @admission_report_config.valid? },
@admission_report_config.associated_valid?
].all? # this syntax avoids a short-circuit
@admission_report_config.name = old_name
if successful?
session[:admission_report_config] = params.require(:record).permit!.to_h
end
end

def consolidate_phase_respond_on_iframe
flash[:info] = @message
flash[:error] = @exception
Expand Down Expand Up @@ -322,6 +387,61 @@ def calculate_ranking_respond_to_js
render action: "on_calculate_ranking", formats: [:js]
end

def custom_report_respond_to_html
if successful?
render(action: "custom_report")
else
return_to_main
end
end

def custom_report_respond_to_js
render(partial: "custom_report_form")
end

def custom_report_generate_respond_on_iframe
responds_to_parent do
render action: "on_custom_report", formats: [:js], layout: false
end
end

def custom_report_generate_respond_to_html
if successful? # just a regular post
message = "Relatório configurado"
if params[:dont_close]
flash.now[:info] = message
render(action: "custom_report")
else
flash[:info] = message
return_to_main
end
else
render(action: "custom_report")
end
end

def custom_report_generate_respond_to_js
render action: "on_custom_report"
end

def reset_report_respond_on_iframe
responds_to_parent do
render action: "on_custom_report", formats: [:js], layout: false
end
end

def reset_report_respond_to_html
if @on_form
render(action: "custom_report")
else
return_to_main
end
end

def reset_report_respond_to_js
render action: "on_custom_report"
end

private
def get_admission_process_pdf(type)
@admission_process = Admissions::AdmissionProcess.find(params[:id])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Admissions::AdmissionReportGroupsController < ApplicationController
active_scaffold "Admissions::AdmissionReportGroup" do |config|
config.create.label = :create_admission_report_group_label
columns = [
:admission_report_config, :order, :mode, :pdf_format, :operation, :columns
:admission_report_config, :order, :mode, :pdf_format, :in_simple, :operation, :columns
]

config.columns = columns
Expand Down
22 changes: 22 additions & 0 deletions app/helpers/admissions/admission_processes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,26 @@ def admission_applications_show_column(record, column)
record: record, column: column
}
end

def form_condition_form_column(record, options)
render(partial: "admissions/form_conditions/association_widget", locals: {
record: record,
options: options,
form_condition: record.form_condition
})
end

def admission_report_group_t(key, **args)
I18n.t("activerecord.attributes.admissions/admission_report_group.#{key}", **args)
end

def admissions_ranking_column_name_form_column(record, options)
form_field_name_widget(record, options, text: record.name)
end

def admissions_admission_report_column_name_form_column(record, options)
form_field_name_widget(record, options, text: record.name, query_options: {
in_letter: true
})
end
end
4 changes: 2 additions & 2 deletions app/helpers/admissions/admission_processes_pdf_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def add_width(remaining_width, target, widths)

def admission_applications_table(curr_pdf, options = {})
admission_process ||= options[:admission_process]
admission_report_config = Admissions::AdmissionReportConfig.new.init_default
admission_report_config = @admission_report_config || Admissions::AdmissionReportConfig.new.init_default
title = admission_process_pdf_title(admission_process)
config = admission_report_config.prepare_table(admission_process)
config[:base_url] = request.base_url
Expand Down Expand Up @@ -103,7 +103,7 @@ def show_filled(filled, field)

def admission_applications_complete_table(curr_pdf, options = {})
admission_process ||= options[:admission_process]
admission_report_config = Admissions::AdmissionReportConfig.new.init_default
admission_report_config = @admission_report_config || Admissions::AdmissionReportConfig.new.init_default
title = admission_process_pdf_title(admission_process)
config = admission_report_config.prepare_table(admission_process)
applications = config[:applications].map do |application|
Expand Down
12 changes: 12 additions & 0 deletions app/helpers/admissions/admission_report_columns_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) Universidade Federal Fluminense (UFF).
# This file is part of SAPOS. Please, consult the license terms in the LICENSE file.

# frozen_string_literal: true

module Admissions::AdmissionReportColumnsHelper
def name_form_column(record, options)
form_field_name_widget(record, options, text: record.name, query_options: {
in_letter: true
})
end
end
6 changes: 6 additions & 0 deletions app/helpers/admissions/admission_report_groups_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ module Admissions::AdmissionReportGroupsHelper
def admission_report_group_t(key, **args)
I18n.t("activerecord.attributes.admissions/admission_report_group.#{key}", **args)
end

def admissions_admission_report_column_name_form_column(record, options)
form_field_name_widget(record, options, text: record.name, query_options: {
in_letter: true
})
end
end
2 changes: 2 additions & 0 deletions app/models/admissions/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ module Admissions::Ability

def initialize_admissions(user, roles)
alias_action :map_student_form, :map_student_form_create_update, to: :map_student
alias_action :custom_report_generate, :reset_report, to: :custom_report
if roles[:manager]
can :undo_consolidation, Admissions::AdmissionApplication
can :override, Admissions::AdmissionApplication
can :cancel, Admissions::AdmissionApplication
can :configuration, Admissions::AdmissionApplication
can :read_all, Admissions::AdmissionApplication
can :map_student, Admissions::AdmissionApplication
can :custom_report, Admissions::AdmissionProcess
end
if roles[Role::ROLE_ADMINISTRADOR] || roles[Role::ROLE_COORDENACAO]
can :manage, ADMISSION_MODELS
Expand Down
2 changes: 1 addition & 1 deletion app/models/admissions/admission_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ def phase_name
end

def identifier
self.token[..6]
self.token[..5]
end

def can_edit_itself
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%
admission_report_config = Admissions::AdmissionReportConfig.new.init_default
admission_report_config = @admission_report_config || Admissions::AdmissionReportConfig.new.init_default
config = admission_report_config.prepare_table(record)
config[:base_url] = request.base_url
%>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<%

form_action ||= :custom_report_generate

scope ||= nil
url_options ||= params_for(:action => form_action)
xhr = request.xhr? if xhr.nil?

report_action_config = Admissions::AdmissionReportConfigsController.active_scaffold_config.create
multipart ||= report_action_config.multipart?
report_columns ||= report_action_config.columns
report_columns.constraint_columns << :name

persistent ||= false
floating_footer ||= false
method ||= :post
cancel_link = true if cancel_link.nil?
submit_text ||= form_action
apply_text ||= :"#{form_action}_apply"
body_partial ||= 'form'
form_id = element_form_id(action: form_action, id: "custom_report_definition")
%>
<%=
options = {:id => form_id,
:multipart => multipart,
:class => "as_form #{form_action.to_s}",
:method => :post,
'data-loading' => defined?(loading) ? loading : true}
cancel_options = {:class => 'as_cancel'}
options[:class] << ' floating-footer' if floating_footer
cancel_options[:remote] = true if xhr #cancel link does nt have to care about multipart forms
if xhr && multipart # file_uploads
form_remote_upload_tag url_options.merge({:iframe => true}), options
else
options[:remote] = true if xhr && !multipart
form_tag url_options, options
end
-%>
<h4> <%= t("active_scaffold.admissions/admission_process.custom_report.title") %> </h4>
<div id="<%= element_messages_id(:action => form_action) %>" class="messages-container">
<% unless xhr %>
<p class="error-message message server-error" style="display:none;">
<%= as_(:internal_error).html_safe %>
<a href="#" class="close" title="<%= as_(:close).html_safe %>"><%= as_(:close).html_safe %></a>
</p>
<% end %>
<%= render :partial => 'form_messages' %>
</div>


<% @record = @admission_report_config %>
<%= render :partial => body_partial, :locals => { :columns => report_columns, :form_action => form_action, :scope => nil } %>

<p class="form-footer">
<%= submit_tag "Usar configuração", name: "dont_close", :class => "submit" %>
<%= submit_tag "Resetar", name: "dont_close", formaction: url_for(params_for(action: :reset_report)), :class => "submit" %>
<%= link_to(as_(:cancel), main_path_to_return, cancel_options) if cancel_link %>
<%= loading_indicator_tag(action: form_action, id: "custom_report_definition") %>
</p>

</form>
39 changes: 39 additions & 0 deletions app/views/admissions/admission_processes/_list_messages.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<% column_count ||= columns.length + (grouped_search? ? 0 : 1) -%>
<tbody class="messages">
<tr class="record even-record">
<td colspan="<%= column_count -%>" class="messages-container">
<% unless active_scaffold_config.list.messages_above_header %>
<p class="error-message message server-error" style="display:none;">
<%= as_(:internal_error).html_safe %>
<span class="error-500"><%= as_(:error_500).html_safe %></span>
<a href="#" class="close" title="<%= as_(:close).html_safe %>"><%= as_(:close).html_safe %></a>
</p>
<div id="<%= active_scaffold_messages_id -%>" class="action-messages">
<%= render :partial => 'messages' %>
</div>
<% end %>
<%= content_tag :div, class: 'filtered-message',
style: ('display:none;' unless @filtered),
data: ({search: search_params || ''} if active_scaffold_config.store_user_settings && respond_to?(:search_params)) do %>
<%= @filtered.is_a?(Array) ? render(:partial => 'human_conditions', :locals => {:columns => @filtered}) : as_(active_scaffold_config.list.filtered_message) %>
<% if active_scaffold_config.list.show_search_reset && @filtered -%>
<div class="reset">
<%= loading_indicator_tag(:action => :record, :id => nil) %>
<%= render_action_link(active_scaffold_config.list.reset_link) %>
</div>
<% end -%>
<% end %>
<div class="filtered-message" id="admission-report-config-notice"
style="<%= "display:none" if !session.include? :admission_report_config %>">
<div class="reset">
<%= loading_indicator_tag(:action => :record, :id => nil) %>
<%= link_to t("active_scaffold.admissions/admission_process.custom_report.notice"),
url_for(params_for(action: :reset_report).merge({ dont_close: true })), data: { remote: true } %>
</div>
</div>
<p id="<%= empty_message_id %>" class="empty-message" <%= ' style="display:none;" '.html_safe unless @page.empty? %>>
<%= as_(active_scaffold_config.list.no_entries_message) %>
</p>
</td>
</tr>
</tbody>
Loading

0 comments on commit bc959e0

Please sign in to comment.