Skip to content

Commit

Permalink
Merge pull request #9 from lifewatch-eric/feature/ecoportal/jobs-admi…
Browse files Browse the repository at this point in the history
…nistration

Ontoportal align: Add jobs administration
  • Loading branch information
syphax-bouazzouni authored Jul 31, 2023
2 parents 8ff2c3b + 48e2a12 commit b2442db
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 1 deletion.
67 changes: 67 additions & 0 deletions app/assets/javascripts/bp_admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,73 @@ jQuery(".admin.index").ready(function() {

});


//==============================================================
// PROCESS SCHEDULING
//==============================================================

jQuery("#process-scheduling .job-schedule").each(function () {
renderSchedule(this)
});

jQuery(".show-scheduler-log").on("click", function (event) {
let jobName = event.target.dataset.jobName;
if (jobName) {
window.open(
BP_CONFIG.rest_url + "/admin/scheduled_jobs/" + encodeURIComponent(jobName) + "/log?apikey=" + BP_CONFIG.apikey + "&userapikey=" + BP_CONFIG.userapikey,
"_blank");
} else {
window.open(
BP_CONFIG.rest_url + "/admin/scheduled_jobs/log?apikey=" + BP_CONFIG.apikey + "&userapikey=" + BP_CONFIG.userapikey,
"_blank");
}
});

function renderSchedule(scheduleElement) {
let enabled = scheduleElement.dataset.enabled;
let schedulerType = scheduleElement.dataset.schedulerType;
let schedule = scheduleElement.dataset.schedule;

if (enabled != "true")
return;

if (schedule == "")
return;

let s = "";

if (schedulerType == "every") {
let unit = null;
if (schedule.endsWith("m")) {
schedule = schedule.substr(0, schedule.length - 1);
unit = "minute";
} else if(schedule.endsWith("s")) {
schedule = schedule.substr(0, schedule.length - 1);
unit = "second";
}

schedule = schedule.trim();

if (schedule.match(/^[1-9]\d*$/)) { // schedule number
if (!unit) {
unit = "second"; // default to unit second
}
s = "Every " + schedule + " " + unit + (Number.parseInt(schedule) != 1 ? "s" : "");
} else {
s = "Every " + schedule + (unit ? " " + unit : "");
}
} else {
try {
s = window.cronstrue.toString(schedule);
} catch(e) {
console.log("An error occurred when verbalizing the following cron: " + schedule, e);
}
}

if (s) {
scheduleElement.textContent = s;
}
}
/* users part */
function populateUserRows(data) {
let users = data['users'];
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@
//= require trumbowyg
//= require sharer.min

//= require cronstrue.min
21 changes: 21 additions & 0 deletions app/assets/stylesheets/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,28 @@ table.dataTable tbody tr.selected {
}
}

#process-scheduling {

.site-admin-page-header {
justify-content: space-between;

.job-title {
text-transform: uppercase;
}
}

.site-admin-page-section {
margin-bottom: 3rem
}

.job-schedule {
font-style: italic;
cursor: help;
}
}

div.groupFormError {
color: red;
padding-top: 3px;
}

3 changes: 3 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ class AdminController < ApplicationController

def index
@users = LinkedData::Client::Models::User.all

if session[:user].nil? || !session[:user].admin?
redirect_to :controller => 'login', :action => 'index', :redirect => '/admin'
else
json = LinkedData::Client::HTTP.get("#{ADMIN_URL}scheduled_jobs", raw: true)
@scheduledJobs = JSON.parse(json, :symbolize_names => true)
render action: "index"
end
end
Expand Down
33 changes: 32 additions & 1 deletion app/views/admin/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@
=link_to("Groups", "#groups", id: "groups-admin-tab", class: "nav-link", role: "tab", data: { toggle: "tab", href: "groups" }, aria: { controls: "groups", selected: "false" })
%li.nav-item
=link_to("Categories", "#categories", id: "categories-admin-tab", class: "nav-link #{selected_admin_section?('categories') ? 'active': ''}", role: "tab", data: { toggle: "tab", href: "categories" }, aria: { controls: "categories", selected: "false" })
%li.nav-item
=link_to("Metadata Administration", "#ontologies_metadata_curator", id: "ontologies_metadata_curator-admin-tab", class: "nav-link", role: "tab", data: { toggle: "tab"}, aria: { controls: "ontologies_metadata_curator", selected: "false" })
%li.nav-item
=link_to("Process Scheduling", "#process-scheduling", id: "process-scheduling-tab", class: "nav-link", role: "tab", data: { toggle: "tab", href: "process-scheduling" }, aria: { controls: "process-scheduling", selected: "false" })
%li.nav-item
=link_to("Persons & Organizations", "#agents", id: "agents-admin-tab", class: "nav-link #{selected_admin_section?('agents') ? 'active': ''}", role: "tab", data: { toggle: "tab", href: "agents" }, aria: { controls: "agents", selected: "false" })

%div#adminTabContent.tab-content

-# Site Administration tab
Expand Down Expand Up @@ -133,4 +138,30 @@
-# Process Scheduling tab
%div.tab-pane.fade{id: "process-scheduling", role: "tabpanel", aria: { labelledby: "process-scheduling-tab" }}
%div.my-5
%div.mb-2
The schedule is to be changed by altering the configuration of the module <em>ncbo_cron</em>. This module
must be restarted for the changes to take effect.
%div.mb-5
%a.btn.btn-outline-secondary.btn-sm.show-scheduler-log
Show log
- @scheduledJobs.each do |job_key, job_descr|
%div.site-admin-page-header
%div.job-title
= job_descr[:title]
- if job_descr[:enabled]
- title = job_descr[:scheduler_type] + ": " + job_descr[:schedule]
%div.job-schedule{title: title, data: {enabled: "true", scheduler_type: job_descr[:scheduler_type], schedule: job_descr[:schedule]}}
= title
- else
%div.job-schedule{data: {enabled: "false"}}
Disabled
%div.site-admin-page-section
%a.btn.btn-outline-secondary.btn-sm.show-scheduler-log{data: {job_name: job_key}}
Show log
Loading

0 comments on commit b2442db

Please sign in to comment.