From 76d013725a53e55f978ec0bda43657a54f00278e Mon Sep 17 00:00:00 2001 From: Jeff Ohrstrom Date: Mon, 26 Aug 2024 15:18:06 -0400 Subject: [PATCH] small fixups for job details panel (#3744) --- apps/dashboard/app/javascript/projects.js | 20 ++++++++++++++++++- apps/dashboard/app/models/hpc_job.rb | 16 ++++++++++++++- .../projects/_job_details.turbo_stream.erb | 2 +- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/apps/dashboard/app/javascript/projects.js b/apps/dashboard/app/javascript/projects.js index 750b6ceeb4..a4e13866ef 100644 --- a/apps/dashboard/app/javascript/projects.js +++ b/apps/dashboard/app/javascript/projects.js @@ -31,7 +31,25 @@ function pollForJobInfo(element) { fetch(url, { headers: { Accept: "text/vnd.turbo-stream.html" } }) .then(response => response.ok ? Promise.resolve(response) : Promise.reject(response.text())) .then((r) => r.text()) - .then((html) => replaceHTML(element.id, html)) + .then((html) => { + // if the job panel is currently open by the user, make the new + // html open as well. + const currentData = element.querySelector(`#${element.id}_data`); + let currentlyOpen = false; + + if(currentData != null) { + currentlyOpen = currentData.classList.contains('show'); + } + + if(currentlyOpen) { + const responseElement = new DOMParser().parseFromString(html, "text/xml"); + const dataDiv = responseElement.querySelector(`#${element.id}_data`); + dataDiv.classList.add('show'); + html = (new XMLSerializer()).serializeToString(responseElement); + } + + replaceHTML(element.id, html) + }) .then(setTimeout(pollForJobInfo, 30000, element)) .catch((err) => { console.log('Cannot not retrive job details due to error:'); diff --git a/apps/dashboard/app/models/hpc_job.rb b/apps/dashboard/app/models/hpc_job.rb index 2eb564a036..a1ceed0fd2 100644 --- a/apps/dashboard/app/models/hpc_job.rb +++ b/apps/dashboard/app/models/hpc_job.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class HpcJob < OodCore::Job::Info + include ActionView::Helpers::DateHelper + attr_reader :cluster COMPLETED = 'completed' @@ -28,6 +30,18 @@ def to_h end def to_human_display - to_h.transform_keys { |k| k.humanize }.compact_blank + to_h.reject do |key, _value| + key == 'native' + end.map do |key, value| + if ['wallclock_time', 'wallclock_limit'].include?(key) + [key, fix_time(value)] + else + [key, value] + end + end.to_h.transform_keys(&:humanize).compact_blank + end + + def fix_time(time) + distance_of_time_in_words(time, 0, false, :only => [:minutes, :hours], :accumulate_on => :hours) end end diff --git a/apps/dashboard/app/views/projects/_job_details.turbo_stream.erb b/apps/dashboard/app/views/projects/_job_details.turbo_stream.erb index 416cfdac3d..30d7bb1fb3 100644 --- a/apps/dashboard/app/views/projects/_job_details.turbo_stream.erb +++ b/apps/dashboard/app/views/projects/_job_details.turbo_stream.erb @@ -10,7 +10,7 @@ <%= job.id %> <%= status_text(job.status.to_s) %> -
+
<% job.to_human_display.each do |name, value| %>