Skip to content

Commit

Permalink
Merge branch 'master' into uniform-alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom committed Aug 30, 2024
2 parents 87f2361 + b3b3646 commit cebb5aa
Show file tree
Hide file tree
Showing 39 changed files with 626 additions and 449 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
ruby: ["2.7.1"]
bundler: ["2.1.4"]
ruby: ["3"]
runs-on: ${{ matrix.os }}
name: Update Dependencies

steps:
- name: Checkout ${{ github.sha }}
uses: actions/checkout@v3

- name: Setup Ruby ${{ matrix.ruby }} using Bundler ${{ matrix.bundler }}
- name: Setup Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler: ${{ matrix.bundler }}

- name: Cache dependencies
uses: actions/cache@v3
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ GEM
rake (13.0.6)
regexp_parser (2.1.1)
require_all (3.0.0)
rexml (3.3.3)
rexml (3.3.6)
strscan
rspec (3.10.0)
rspec-core (~> 3.10.0)
Expand Down
16 changes: 8 additions & 8 deletions apps/dashboard/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.3.3)
concurrent-ruby (1.3.4)
crass (1.0.6)
cssbundling-rails (1.4.1)
railties (>= 6.0.0)
Expand All @@ -116,7 +116,7 @@ GEM
globalid (1.2.1)
activesupport (>= 6.1)
http-accept (1.7.0)
http-cookie (1.0.6)
http-cookie (1.0.7)
domain_name (~> 0.5)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
Expand Down Expand Up @@ -145,14 +145,14 @@ GEM
method_source (1.1.0)
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2024.0702)
mime-types-data (3.2024.0820)
mini_mime (1.1.5)
mini_portile2 (2.8.7)
minitest (5.24.1)
minitest (5.25.1)
mocha (2.4.5)
ruby2_keywords (>= 0.0.5)
multi_json (1.15.0)
mustermann (3.0.0)
mustermann (3.0.2)
ruby2_keywords (~> 0.0.1)
net-imap (0.3.7)
date
Expand Down Expand Up @@ -234,7 +234,7 @@ GEM
netrc (~> 0.8)
rexml (3.3.6)
strscan
rss (0.3.0)
rss (0.3.1)
rexml
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
Expand All @@ -259,7 +259,7 @@ GEM
sprockets (4.2.1)
concurrent-ruby (~> 1.0)
rack (>= 2.2.4, < 4)
sprockets-rails (3.5.1)
sprockets-rails (3.5.2)
actionpack (>= 6.1)
activesupport (>= 6.1)
sprockets (>= 3.0.0)
Expand All @@ -283,7 +283,7 @@ GEM
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.17)
zip_kit (6.3.0)
zip_kit (6.3.1)

PLATFORMS
ruby
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/controllers/launchers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LaunchersController < ApplicationController
:auto_batch_clusters, :auto_batch_clusters_exclude, :auto_batch_clusters_fixed,
:bc_num_slots, :bc_num_slots_fixed, :bc_num_slots_min, :bc_num_slots_max,
:bc_num_hours, :bc_num_hours_fixed, :bc_num_hours_min, :bc_num_hours_max,
:auto_job_name
:auto_job_name, :auto_job_name_fixed
].freeze

def new
Expand Down
4 changes: 4 additions & 0 deletions apps/dashboard/app/javascript/files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ import {} from './data_table.js';
import {} from './file_ops.js';
import {} from './sweet_alert.js';
import {} from './uppy_ops.js';
import { setPageLoadState } from './page_load';

addEventListener("DOMContentLoaded", (_event) => {
setPageLoadState();
});
19 changes: 19 additions & 0 deletions apps/dashboard/app/javascript/files/page_load.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

export function setPageLoadState() {
const configEle = document.getElementById('files_page_load_config');

if(configEle === null) {
return;
}

const data = configEle.dataset;

history.replaceState({
currentDirectory: data['currentDirectory'],
currentDirectoryUrl: data['currentDirectoryUrl'],
currentDirectoryUpdatedAt: data['currentDirectoryUpdatedAt'],
currentFilesPath: data['currentFilesPath'],
currentFilesUploadPath: data['currentFilesUploadPath'],
currentFilesystem: data['currentFilesystem']
}, null);
}
38 changes: 34 additions & 4 deletions apps/dashboard/app/javascript/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,58 @@ function pollForJobInfo(element) {
// html open as well.
const currentData = element.querySelector(`#${element.id}_data`);
let currentlyOpen = false;
const responseElement = stringToHtml(html);

if(currentData != null) {
currentlyOpen = currentData.classList.contains('show');
}

// if it's currently open keep it open.
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)
const jobStatus = responseElement.dataset['jobStatus'];
if(jobStatus === 'completed') {
moveCompletedPanel(element.id, responseElement.outerHTML);
} else {
replaceHTML(element.id, responseElement.outerHTML);
}

return jobStatus;
})
.then((status) => {
if(status != 'completed') {
setTimeout(pollForJobInfo, 30000, element);
}
})
.then(setTimeout(pollForJobInfo, 30000, element))
.catch((err) => {
console.log('Cannot not retrive job details due to error:');
console.log(err);
});
}

function stringToHtml(html) {
const template = document.createElement('template');
template.innerHTML = html.trim();
return template.content.firstChild;
}

function moveCompletedPanel(id, newHTML) {
const oldElement = document.getElementById(id);
if(oldElement !== null) {
oldElement.remove();
}

const div = document.createElement('div');
div.id = id;

const row = document.getElementById('completed_jobs');
row.appendChild(div);

replaceHTML(id, newHTML);
}

function updateProjectSize(element) {
const UNDETERMINED = 'Undetermined Size';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

module SmartAttributes
class AttributeFactory

# Build this attribute object. Must specify a valid directory in opts
#
# @param opts [Hash] attribute's options
Expand All @@ -18,8 +17,7 @@ class AutoJobName < Attribute
# Defaults to ondemand/[dev,sys]/projects
# @return [String] attribute value
def value
env = Rails.env.production? ? 'sys' : 'dev'
opts[:value] || "ondemand/#{env}/projects"
job_name(opts[:value] || 'Project Manager Job')
end

def widget
Expand All @@ -36,6 +34,16 @@ def label(*)
def submit(*)
{ script: { job_name: value } }
end

# TODO: need to sanitize the job name for some schedulers
def job_name(name)
[
ENV['OOD_PORTAL'], # the OOD portal id
ENV['RAILS_RELATIVE_URL_ROOT'].to_s.sub(%r{^/[^/]+/}, ''), # the OOD app
'project-manager',
name # the user supplied job name
].reject(&:blank?).join('/')
end
end
end
end
4 changes: 4 additions & 0 deletions apps/dashboard/app/models/batch_connect/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ def metadata
ood_app.metadata.merge(form_config.fetch(:metadata, {}))
end

def form_header
form_config.fetch(:form_header, '')
end

def ssh_allow?
form_config[:ssh_allow]
end
Expand Down
9 changes: 7 additions & 2 deletions apps/dashboard/app/models/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ def scripts?(project_dir)
end
end

ID_REX = /\A\w{8}\Z/.freeze

validates(:id, format: { with: ID_REX, allow_blank: true, message: :format }, on: [:save])
validates(:id, format: { with: ID_REX, message: :format }, on: [:update])

def initialize(opts = {})
opts = opts.to_h.with_indifferent_access

@project_dir = opts[:project_dir] || raise(StandardError, 'You must set the project directory')
@id = opts[:id]
@id = opts[:id] if opts[:id].to_s.empty? || opts[:id].to_s.match?(ID_REX)
@title = opts[:title].to_s
@created_at = opts[:created_at]
sm_opts = {
Expand Down Expand Up @@ -144,7 +149,7 @@ def []=(_id, value)
end

def save
@id = Launcher.next_id if @id.nil?
@id = Launcher.next_id if @id.nil? || !@id.to_s.match?(ID_REX)
@created_at = Time.now.to_i if @created_at.nil?
script_path = Launcher.script_path(project_dir, id)
script_path.mkpath unless script_path.exist?
Expand Down
9 changes: 7 additions & 2 deletions apps/dashboard/app/models/posix_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ class PosixFile

attr_reader :path, :stat

delegate :basename, :descend, :parent, :join, :to_s, :read, :write, :mkdir, :directory?, :realpath, :pipe?, :readable?, to: :path
delegate :basename, :descend, :parent, :join, :to_s, :read, :write, :mkdir, to: :path
delegate :directory?, :realpath, :readable?, :file?, to: :path

# include to give us number_to_human_size
include ActionView::Helpers::NumberHelper
Expand Down Expand Up @@ -61,10 +62,14 @@ def to_h
owner: PosixFile.username_from_cache(stat.uid),
mode: stat.mode,
dev: stat.dev,
downloadable: !pipe? && readable?
downloadable: downloadable?
}
end

def downloadable?
(directory? || file?) && readable?
end

def human_size
directory? ? '-' : number_to_human_size(stat.size, precision: 3)
end
Expand Down
8 changes: 8 additions & 0 deletions apps/dashboard/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ def jobs
Project.jobs(directory)
end

def active_jobs
jobs.reject(&:completed?)
end

def completed_jobs
jobs.select(&:completed?)
end

def job(job_id, cluster)
cached_job = jobs.detect { |j| j.id == job_id && j.cluster == cluster }
return cached_job if cached_job.completed?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

<%= sanitize OodAppkit.markdown.render(@app.form_header) %>

<%= render "prefill_templates" if Configuration.bc_saved_settings? %>

<%= bootstrap_form_for(@session_context, html: { autocomplete: "off" }) do |f| %>
Expand Down
13 changes: 0 additions & 13 deletions apps/dashboard/app/views/files/_inline_js.html.erb

This file was deleted.

12 changes: 12 additions & 0 deletions apps/dashboard/app/views/files/_page_load_config.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

<div hidden="" id="files_page_load_config"
data-current-directory="<%= @path %>"
data-current-directory-url="<%= files_path(@filesystem, @path) %>"
data-current-directory-updatead-at="<%= Time.now.to_i %>"
data-current-files-path="<%= files_path(@filesystem, '/') %>"
data-current-filesystem="<%= @filesystem %>"
data-download-error-title="<%= t('dashboard.files_directory_download_error_modal_title') %>"
data-current-files-upload-path="<%= url_for(fs: @filesystem, action: 'upload') if Configuration.upload_enabled? %>"
>

</div>
3 changes: 2 additions & 1 deletion apps/dashboard/app/views/files/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
</div>
<%= render partial: "files_table" %>
</div>
<%= render partial: "inline_js" %>

<%= render(partial: 'page_load_config') %>
22 changes: 3 additions & 19 deletions apps/dashboard/app/views/projects/_job_details.turbo_stream.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,8 @@
id = "job_#{job.cluster}_#{job.id}"
-%>

<turbo-stream action="replace" target="<%= id %>">
<turbo-stream action="replace" target="<%= id %>" data-job-status="<%= job.status %>">
<template>
<button class="badge <%= status_class(job.status.to_s) %> rounded-pill border-0 btn" type="button" data-bs-toggle="collapse" data-bs-target="#<%= id %>_data">
<span>
<%= job.id %> <%= status_text(job.status.to_s) %>
</span>
</button>
<div class="collapse col-md-4" id="<%= id %>_data">
<div class="card card-body">
<table class="table table-bordered table-sm m-0 mb-2">
<% job.to_human_display.each do |name, value| %>
<tr>
<td><strong><%= name %></strong></td>
<td><%= value %></td>
</tr>
<% end %>
</table>
</div>
</div>
</template>
<%= render(partial: 'job_details_content', locals: { job: job }, :formats=>[:html]) %>
</template>
</turbo-stream>
Loading

0 comments on commit cebb5aa

Please sign in to comment.