diff --git a/apps/dashboard/app/helpers/application_helper.rb b/apps/dashboard/app/helpers/application_helper.rb index 2bcface8a5..ee6963ec1a 100644 --- a/apps/dashboard/app/helpers/application_helper.rb +++ b/apps/dashboard/app/helpers/application_helper.rb @@ -51,9 +51,9 @@ def help_custom_url ENV['OOD_DASHBOARD_HELP_CUSTOM_URL'] end - def fa_icon(icon, fa_style: 'fas', id: '', classes: 'app-icon') + def fa_icon(icon, fa_style: 'fas', id: '', classes: 'app-icon', title: "FontAwesome icon specified: #{icon}") content_tag(:i, '', id: id, class: [fa_style, "fa-#{icon}", 'fa-fw'].concat(Array(classes)), - title: "FontAwesome icon specified: #{icon}", "aria-hidden": true) + title: title, "aria-hidden": true) end def app_icon_tag(app) diff --git a/apps/dashboard/app/helpers/batch_connect/sessions_helper.rb b/apps/dashboard/app/helpers/batch_connect/sessions_helper.rb index 0f53d9ba34..441d3ad365 100644 --- a/apps/dashboard/app/helpers/batch_connect/sessions_helper.rb +++ b/apps/dashboard/app/helpers/batch_connect/sessions_helper.rb @@ -22,6 +22,7 @@ def session_panel(session) status << content_tag(:span, pluralize(num_cores, "core"), class: "badge badge-#{status_context(session)} badge-pill") unless num_cores.zero? end status << "#{status session}" + relaunch(status, session) tag.span(status.join(" | ").html_safe, class: "card-text") end ) @@ -195,6 +196,27 @@ def status_context(session) end end + def relaunch(status_array, session) + return unless Configuration.relaunch_session_enabled && session.completed? + + batch_connect_app = session.app + return unless batch_connect_app.valid? + + user_context = session.user_context + params = batch_connect_app.attributes.map{|attribute| ["batch_connect_session_context[#{attribute.id}]", user_context.fetch(attribute.id, '')]}.to_h + title = "#{t('dashboard.batch_connect_sessions_relaunch_title')} #{session.title} #{t('dashboard.batch_connect_sessions_word')}" + status_array << button_to( + batch_connect_session_contexts_path(token: batch_connect_app.token), + method: :post, + class: %w[btn px-1 py-0 btn-outline-dark relaunch], + form_class: %w[d-inline relaunch], + title: title, + data: { toggle: "tooltip", placement: "left" }, + params: params + ) do + "#{fa_icon('sync', classes: nil, title: '')}".html_safe + end + end def cancel_or_delete(session) if Configuration.cancel_session_enabled && !session.completed? @@ -210,7 +232,7 @@ def delete(session) method: :delete, class: "btn btn-danger float-right btn-delete", title: "#{t('dashboard.batch_connect_sessions_delete_title')} #{session.title} #{t('dashboard.batch_connect_sessions_word')}", - data: { confirm: t('dashboard.batch_connect_sessions_delete_confirm'), toggle: "tooltip", placement: "bottom", selector: true } + data: { confirm: t('dashboard.batch_connect_sessions_delete_confirm'), toggle: "tooltip", placement: "bottom", selector: 'button' } ) do "#{fa_icon('times-circle', classes: nil)} ".html_safe end @@ -222,7 +244,7 @@ def cancel(session) method: :post, class: "btn btn-danger float-right btn-cancel", title: "#{t('dashboard.batch_connect_sessions_cancel_title')} #{session.title} #{t('dashboard.batch_connect_sessions_word')}", - data: { confirm: t('dashboard.batch_connect_sessions_cancel_confirm'), toggle: "tooltip", placement: "bottom", selector: true } + data: { confirm: t('dashboard.batch_connect_sessions_cancel_confirm'), toggle: "tooltip", placement: "bottom", selector: 'button' } ) do "#{fa_icon('times-circle', classes: nil)} ".html_safe end diff --git a/apps/dashboard/app/javascript/packs/batch_connect_sessions.js b/apps/dashboard/app/javascript/packs/batch_connect_sessions.js index 35d6a0c857..3f6cf77d3a 100644 --- a/apps/dashboard/app/javascript/packs/batch_connect_sessions.js +++ b/apps/dashboard/app/javascript/packs/batch_connect_sessions.js @@ -31,3 +31,14 @@ function installSettingHandlers(name) { window.installSettingHandlers = installSettingHandlers; window.tryUpdateSetting = tryUpdateSetting; + +jQuery(function (){ + function showSpinner() { + $('body').addClass('modal-open'); + $('#full-page-spinner').removeClass('d-none'); + } + + $('button.relaunch').each((index, element) => { + $(element).on('click', showSpinner); + }); +}); diff --git a/apps/dashboard/app/models/user_configuration.rb b/apps/dashboard/app/models/user_configuration.rb index 617d17051d..c66662427f 100644 --- a/apps/dashboard/app/models/user_configuration.rb +++ b/apps/dashboard/app/models/user_configuration.rb @@ -101,6 +101,8 @@ def nav_categories # The current user profile. Used to select the configuration properties. def profile + return CurrentUser.user_settings[:profile_override].to_sym if CurrentUser.user_settings[:profile_override] + if Configuration.host_based_profiles request_hostname else diff --git a/apps/dashboard/app/views/batch_connect/sessions/index.html.erb b/apps/dashboard/app/views/batch_connect/sessions/index.html.erb index bfedbf0776..e916b74597 100644 --- a/apps/dashboard/app/views/batch_connect/sessions/index.html.erb +++ b/apps/dashboard/app/views/batch_connect/sessions/index.html.erb @@ -51,4 +51,7 @@ locals: { <%- end -%> + +
+
\ No newline at end of file diff --git a/apps/dashboard/app/views/layouts/application.html.erb b/apps/dashboard/app/views/layouts/application.html.erb index 3822d8578f..f60871faf5 100644 --- a/apps/dashboard/app/views/layouts/application.html.erb +++ b/apps/dashboard/app/views/layouts/application.html.erb @@ -15,6 +15,7 @@ <%= yield :head %> + false, :cancel_session_enabled => false, :hide_app_version => false, + :relaunch_session_enabled => false, }.freeze end diff --git a/apps/dashboard/config/locales/en.yml b/apps/dashboard/config/locales/en.yml index 24e1022064..53bab21840 100644 --- a/apps/dashboard/config/locales/en.yml +++ b/apps/dashboard/config/locales/en.yml @@ -108,6 +108,8 @@ en: batch_connect_sessions_delete_title: "Delete" batch_connect_sessions_cancel_confirm: "Are you sure?" batch_connect_sessions_cancel_title: "Cancel" + batch_connect_sessions_relaunch_confirm: "Are you sure?" + batch_connect_sessions_relaunch_title: "Relaunch" batch_connect_sessions_errors_staging: "Failed to stage the template with the following error:" batch_connect_sessions_errors_submission: "Failed to submit session with the following error:" batch_connect_sessions_novnc_launch: "Launch %{app_title}" diff --git a/apps/dashboard/test/fixtures/config/ondemand.d/booleans.yml b/apps/dashboard/test/fixtures/config/ondemand.d/booleans.yml index 01ce275326..6e0624a16e 100644 --- a/apps/dashboard/test/fixtures/config/ondemand.d/booleans.yml +++ b/apps/dashboard/test/fixtures/config/ondemand.d/booleans.yml @@ -11,4 +11,5 @@ disable_bc_shell: true cancel_session_enabled: true bc_clean_old_dirs: true hide_app_version: true +relaunch_session_enabled: true diff --git a/apps/dashboard/test/helpers/batch_connect/sessions_helper_test.rb b/apps/dashboard/test/helpers/batch_connect/sessions_helper_test.rb index b2f1f76ec2..564d92c592 100644 --- a/apps/dashboard/test/helpers/batch_connect/sessions_helper_test.rb +++ b/apps/dashboard/test/helpers/batch_connect/sessions_helper_test.rb @@ -53,10 +53,57 @@ class BatchConnect::SessionsHelperTest < ActionView::TestCase assert_equal delete_session_title, button['title'] end - def create_session(state = :running) + test 'relaunch should ignore sessions when relaunch_session_enabled is false' do + Configuration.stubs(:relaunch_session_enabled).returns(false) + status_array = [] + relaunch(status_array, create_session(:completed)) + assert_equal [], status_array + end + + test 'relaunch should ignore sessions when session is not completed' do + Configuration.stubs(:relaunch_session_enabled).returns(true) + OodCore::Job::Status.states.each do |state| + next if state == :completed + + status_array = [] + relaunch(status_array, create_session(state)) + assert_equal [], status_array + end + end + + test 'relaunch should ignore sessions when session application is not valid' do + Configuration.stubs(:relaunch_session_enabled).returns(true) + status_array = [] + relaunch(status_array, create_session(:completed, valid: false)) + assert_equal [], status_array + end + + test 'relaunch should add relaunch form when session is completed and relaunch_session_enabled is true' do + Configuration.stubs(:relaunch_session_enabled).returns(true) + status_array = [] + relaunch(status_array, create_session(:completed)) + + assert_equal 1, status_array.size + html = Nokogiri::HTML(status_array[0]) + form = html.at_css('form') + assert_equal batch_connect_session_contexts_path(token: 'sys/token'), form['action'] + assert_equal true, form['class'].include?('relaunch') + + button = html.at_css('button') + assert_equal 'Relaunch AppName Session', button['title'] + assert_equal true, button['class'].include?('relaunch') + end + + def create_session(state = :running, valid: true) value = '{"id":"1234","job_id":"1","created_at":1669139262,"token":"sys/token","title":"AppName","cache_completed":false}' BatchConnect::Session.new.from_json(value).tap do |session| session.stubs(:status).returns(OodCore::Job::Status.new(state: state)) + OpenStruct.new.tap do |sys_app| + sys_app.send('valid?=', valid) + sys_app.attributes = [] + sys_app.token = 'sys/token' + session.stubs(:app).returns(sys_app) + end end end diff --git a/apps/dashboard/test/integration/sessions_controller_test.rb b/apps/dashboard/test/integration/sessions_controller_test.rb index 0cbc5621fe..405f0d7b84 100644 --- a/apps/dashboard/test/integration/sessions_controller_test.rb +++ b/apps/dashboard/test/integration/sessions_controller_test.rb @@ -96,4 +96,20 @@ def setup assert_equal batch_connect_cancel_session_path('1234'), form.first['action'] end end + + test 'should render session panel with relaunch button when relaunch_session_enabled is true' do + Configuration.stubs(:relaunch_session_enabled).returns(true) + value = '{"id":"1234","job_id":"1","created_at":1669139262,"token":"sys/token","title":"session title","cache_completed":true}' + session = BatchConnect::Session.new.from_json(value) + session.stubs(:status).returns(OodCore::Job::Status.new(state: :completed)) + session.stubs(:app).returns(stub(valid?: true, token: 'sys/token', attributes: [], session_info_view: nil)) + BatchConnect::Session.stubs(:all).returns([session]) + + get batch_connect_sessions_path + assert_response :success + + assert_select 'div#id_1234 div.card-heading div.float-right form.relaunch' do |form| + assert_equal batch_connect_session_contexts_path(token: 'sys/token'), form.first['action'] + end + end end