-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added saved settings menu and details view (#3434)
* 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
Showing
17 changed files
with
420 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
apps/dashboard/app/assets/stylesheets/batch_connect/saved_settings.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
apps/dashboard/app/controllers/batch_connect/settings_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
apps/dashboard/app/views/batch_connect/settings/show.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' %> |
6 changes: 6 additions & 0 deletions
6
apps/dashboard/app/views/batch_connect/shared/_full_page_spinner.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
34 changes: 34 additions & 0 deletions
34
apps/dashboard/app/views/batch_connect/shared/_saved_settings_menu.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.