Skip to content

Commit

Permalink
Added saved settings menu and details view (#3434)
Browse files Browse the repository at this point in the history
* Added saved settings menu and details view

* Moved saved settings operations to UserSettingsStore

* Created full_page_spinner.js file + added permit for expected saved settings request parameters

* Added unit tests for Settings and UserSettingsStore

* Added check to show page for missing saved settings
  • Loading branch information
abujeda authored Mar 25, 2024
1 parent 371cd76 commit 8a5aa29
Show file tree
Hide file tree
Showing 17 changed files with 420 additions and 9 deletions.
1 change: 1 addition & 0 deletions apps/dashboard/app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ small.form-text {
@import "products";
@import "batch_connect/sessions";
@import "batch_connect/session_contexts";
@import "batch_connect/saved_settings";
@import "insufficient_quota";
@import "insufficient_balance";
@import "fa_shims";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#saved-settings-menu {
.saved-settings-list .app-icon {
color: rgba(0, 0, 0, 0.25);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def new
end

set_app_groups
set_saved_settings
set_my_quotas
end

Expand Down Expand Up @@ -54,6 +55,7 @@ def create
set_prefill_templates
format.html do
set_app_groups
set_saved_settings
render :new
end
format.json { render json: @session_context.errors, status: :unprocessable_entity }
Expand All @@ -76,6 +78,11 @@ def set_app_groups
@apps_menu_group = bc_custom_apps_group
end

# Set the all the saved settings to render the navigation
def set_saved_settings
@bc_saved_settings = all_bc_templates
end

# Set the session context from the app
def set_session_context
@session_context = @app.build_session_context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# The controller for active batch connect sessions.
class BatchConnect::SessionsController < ApplicationController
include BatchConnectConcern
include UserSettingStore

# GET /batch_connect/sessions
# GET /batch_connect/sessions.json
Expand All @@ -9,6 +10,7 @@ def index
@sessions.each(&:update_cache_completed!)

set_app_groups
set_saved_settings
set_my_quotas
end

Expand Down Expand Up @@ -62,6 +64,11 @@ def set_app_groups
@apps_menu_group = bc_custom_apps_group
end

# Set the all the saved settings to render the navigation
def set_saved_settings
@bc_saved_settings = all_bc_templates
end

def delete_session_panel?
params[:delete] ? params[:delete] == 'true' : true
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# The controller to manage BatchConnect saved settings
class BatchConnect::SettingsController < ApplicationController
include BatchConnectConcern
include UserSettingStore

# GET /batch_connect/<app_token>/settings/<settings_name>
def show
set_app_groups
set_saved_settings

request_params = settings_request_params
app_token = request_params[:token]
settings_name = request_params[:id]
settings_values = bc_templates(app_token)[settings_name.to_sym]
if settings_values.nil?
redirect_to new_batch_connect_session_context_path(token: app_token),
alert: t('dashboard.bc_saved_settings.missing_settings')
return
end

@settings = BatchConnect::Settings.new(app_token, settings_name, settings_values)
if @settings.outdated?
flash.now[:alert] = t('dashboard.bc_saved_settings.outdated_message', app_title: @settings.app.title)
end
end

# DELETE /batch_connect/<app_token>/settings/<settings_name>
def destroy
request_params = settings_request_params
app_token = request_params[:token]
settings_name = request_params[:id]
delete_bc_template(app_token, settings_name)
redirect_to new_batch_connect_session_context_path(token: app_token),
notice: t('dashboard.bc_saved_settings.deleted_message', settings_name: settings_name)
end

private

def settings_request_params
params.permit(:token, :id)
end

# Set the all the saved settings to render the navigation
def set_saved_settings
@bc_saved_settings = all_bc_templates
end

# Set list of app lists for navigation
def set_app_groups
@sys_app_groups = bc_sys_app_groups
@usr_app_groups = bc_usr_app_groups
@dev_app_groups = bc_dev_app_groups
@apps_menu_group = bc_custom_apps_group
end
end
10 changes: 10 additions & 0 deletions apps/dashboard/app/javascript/full_page_spinner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
jQuery(function (){
function showSpinner() {
$('body').addClass('modal-open');
$('#full-page-spinner').removeClass('d-none');
}

$('.full-page-spinner').each((index, element) => {
$(element).closest('form').on('submit', showSpinner);
});
});
33 changes: 33 additions & 0 deletions apps/dashboard/app/models/batch_connect/settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module BatchConnect
# An Interactive Application saved parameters from the form.
class Settings
include ActiveModel::Model

attr_reader :token, :name, :values

def initialize(token, name, values)
@token = token.to_s
@name = name.to_s
@values = values.to_h
end

def app
@app ||= BatchConnect::App.from_token token
end

def outdated?
outdated = false
# CHECK IF THERE ARE NEW ATTRIBUTES NOT IN THE VALUES HASH
app.attributes.each do |attribute|
outdated = true unless values.key?(attribute.id.to_sym)
end
# CHECK IF THERE ARE OLD VALUES NO LONGER IN THE APP ATTRIBUTES STILL IN THE VALUES HASH
values.each do |attribute_id, _|
outdated = true if app.attributes.select { |attribute| attribute.id.to_sym == attribute_id }.empty?
end

outdated
end

end
end
19 changes: 17 additions & 2 deletions apps/dashboard/app/models/concerns/user_setting_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ def user_settings_path
Pathname.new(::Configuration.user_settings_file)
end

def all_bc_templates
user_settings[BC_TEMPLATES].to_h
end

def bc_templates(app_token)
templates = user_settings[BC_TEMPLATES]
return {} if templates.nil? || templates.empty?
templates = all_bc_templates
return {} if templates.empty?

user_settings[BC_TEMPLATES][app_token.to_sym].to_h
end
Expand All @@ -60,4 +64,15 @@ def save_bc_template(app_token, name, key_values)

update_user_settings(new_settings)
end

def delete_bc_template(app_token, name)
current_templates = all_bc_templates
current_templates.fetch(app_token.to_sym, {}).delete(name.to_sym)
# Delete app_token group when empty
current_templates.delete(app_token.to_sym) if current_templates.fetch(app_token.to_sym, {}).empty?

new_settings = {}
new_settings[BC_TEMPLATES] = current_templates
update_user_settings(new_settings)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ locals: {

<div class="row">
<div class="col-md-3">
<%= render partial: 'batch_connect/shared/saved_settings_menu' %>
<%=
render(
partial: "batch_connect/shared/app_menu",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ locals: {
<div class="row">
<%- if any_apps -%>
<div class="col-md-3">
<%= render partial: 'batch_connect/shared/saved_settings_menu' %>
<%=
render(
partial: "batch_connect/shared/app_menu",
Expand Down
97 changes: 97 additions & 0 deletions apps/dashboard/app/views/batch_connect/settings/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<% content_for :title, t('dashboard.bc_saved_settings.title') %>

<%= render partial: 'batch_connect/shared/breadcrumb',
locals: {
links: [
{
text: t('dashboard.breadcrumbs_home'),
href: root_path
},
{
text: "#{@settings.app.title}",
href: new_batch_connect_session_context_path(token: @settings.token)
},
{
text: @settings.name
}]
}
%>

<div class="row">
<div class="col-md-3">
<%= render partial: 'batch_connect/shared/saved_settings_menu' %>
<%=
render(
partial: "batch_connect/shared/app_menu",
locals: {
sys_app_groups: @sys_app_groups,
usr_app_groups: @usr_app_groups,
dev_app_groups: @dev_app_groups,
apps_menu_group: @apps_menu_group
}
)
%>
</div>
<div id="bc-saved-settings" class="col-md-9">
<div id="settings-card" class="card mb-4">
<div class="card-heading">
<div class="h5 card-header overflow-auto">
<div class="float-right">
<%
if @settings.app.valid?
params = @settings.values.map{|name, value| ["batch_connect_session_context[#{name}]", value]}.to_h
title = t('dashboard.bc_saved_settings.launch_title', app_title: @settings.app.title, settings_name: @settings.name)
%>
<%=
button_to(
batch_connect_session_contexts_path(token: @settings.token),
method: :post,
class: %w[btn btn-warning full-page-spinner],
form_class: %w[d-inline],
title: title,
'aria-label': title,
data: { toggle: "tooltip", placement: "left" },
params: params
) do
"#{fa_icon('play', classes: nil)} <span aria-hidden='true'>#{t('dashboard.bc_saved_settings.launch_label')}</span>".html_safe
end
%>
<span class="card-text"> | </span>
<% end %>
<%
title = t('dashboard.bc_saved_settings.delete_title', settings_name: @settings.name)
%>
<%=
button_to(
batch_connect_setting_path(token: @settings.token, id: @settings.name),
method: :delete,
class: %w[btn btn-danger full-page-spinner],
form_class: %w[d-inline],
title: title,
'aria-label': title,
data: { confirm: t('dashboard.bc_saved_settings.delete_confirm'), toggle: "tooltip", placement: "left"}
) do
"#{fa_icon('times-circle', classes: nil)} <span aria-hidden='true'>#{t('dashboard.bc_saved_settings.delete_label')}</span>".html_safe
end
%>
</div>

<span class="d-block card-text"><%= @settings.name %></span>
<span class="small"><%= @settings.app.title %></span>
</div>
</div>

<p class="list-group-item header"><%= t('dashboard.bc_saved_settings.settings_values_label') %></p>
<div class="card-body">
<% @settings.app.attributes.each do |attribute| %>
<p>
<strong><%= attribute.label %>:</strong>
<%= @settings.values[attribute.id.to_sym] %>
</p>
<% end %>
</div>
</div>

</div>
</div>
<%= render partial: 'batch_connect/shared/full_page_spinner' %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%- content_for :head do -%>
<%= javascript_include_tag('full_page_spinner', nonce: true) %>
<%- end -%>
<div id="full-page-spinner" class="d-none">
<div class="spinner-border" role="status"></div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<%- if Configuration.bc_saved_settings? -%>
<% all_settings = @bc_saved_settings %>
<div id="saved-settings-menu" class="card system-and-shared-apps-header">
<div class="card-header"><%= t('dashboard.bc_saved_settings.title') %></div>
<div class="list-group list-group-flush">
<% if all_settings.empty? %>
<span class="list-group-item list-group-item-action">
<%= t('dashboard.bc_saved_settings.no_settings_title') %>
</span>
<% end %>
<% all_settings.sort.each_with_index do | (app_token, app_saved_settings), index|
app = BatchConnect::App.from_token(app_token.to_s)
link = app.link
%>
<p class="list-group-item mb-0 header">
<a href="#" class="" data-toggle="collapse" data-target="<%= "#saved-settings-#{index}" %>" aria-expanded="true" aria-controls="<%= "saved-settings-#{index}" %>">
<%= icon_tag(link.icon_uri) unless link.icon_uri.to_s.blank? %>
<%= app.title %>
</a>
</p>
<div id="<%= "saved-settings-#{index}" %>" class="show saved-settings-list">
<% app_saved_settings.sort.each do |setting_name, _| %>
<a class="list-group-item list-group-item-action"
href="<%= batch_connect_setting_path(token: app.token, id: setting_name) %>"
title="">
<i id="" class="fa fa-file fa-fw app-icon" aria-hidden="true"></i>
<%= setting_name %>
</a>
<% end %>
</div>
<% end %>
</div>
</div>
<% end %>
13 changes: 13 additions & 0 deletions apps/dashboard/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,19 @@ en:

settings_updated: "Settings updated"

bc_saved_settings:
title: "Saved Settings"
no_settings_title: "You have no saved settings."
missing_settings: "Selected saved settings not found."
launch_label: "Launch"
launch_title: "Launch %{app_title} with %{settings_name} parameters"
delete_label: "Delete"
delete_title: "Delete %{settings_name} saved settings"
delete_confirm: "Are you sure?"
deleted_message: "Saved settings %{settings_name} deleted."
settings_values_label: "Values"
outdated_message: "%{app_title} parameters have changed since these settings were created."

user_configuration:
support_ticket_error: "support_ticket is misconfigured. \"email\" or \"rt_api\" sections are required in the configuration YAML."

Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
resources :sessions, only: [:index, :destroy]
post 'sessions/:id/cancel', to: 'sessions#cancel', as: 'cancel_session'
scope '*token', constraints: { token: %r{((usr/[^/]+)|dev|sys)/[^/]+(/[^/]+)?} } do
resources :settings, only: [:show, :destroy]
resources :session_contexts, only: [:new, :create]
root 'session_contexts#new'
end
Expand Down
Loading

0 comments on commit 8a5aa29

Please sign in to comment.