7604 |
25 Feb 19 |
nicklas |
/* $Id $ |
7604 |
25 Feb 19 |
nicklas |
2 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
Copyright (C) 2013 Nicklas Nordborg |
7604 |
25 Feb 19 |
nicklas |
4 |
|
7604 |
25 Feb 19 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
7604 |
25 Feb 19 |
nicklas |
Available at http://base.thep.lu.se/ |
7604 |
25 Feb 19 |
nicklas |
7 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is free software; you can redistribute it and/or |
7604 |
25 Feb 19 |
nicklas |
modify it under the terms of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
as published by the Free Software Foundation; either version 3 |
7604 |
25 Feb 19 |
nicklas |
of the License, or (at your option) any later version. |
7604 |
25 Feb 19 |
nicklas |
12 |
|
7604 |
25 Feb 19 |
nicklas |
BASE is distributed in the hope that it will be useful, |
7604 |
25 Feb 19 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
7604 |
25 Feb 19 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
7604 |
25 Feb 19 |
nicklas |
GNU General Public License for more details. |
7604 |
25 Feb 19 |
nicklas |
17 |
|
7604 |
25 Feb 19 |
nicklas |
You should have received a copy of the GNU General Public License |
7604 |
25 Feb 19 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
7604 |
25 Feb 19 |
nicklas |
20 |
------------------------------------------------------------------ |
7604 |
25 Feb 19 |
nicklas |
21 |
|
7604 |
25 Feb 19 |
nicklas |
@author Nicklas |
7604 |
25 Feb 19 |
nicklas |
23 |
*/ |
7604 |
25 Feb 19 |
nicklas |
'use strict'; |
7604 |
25 Feb 19 |
nicklas |
25 |
|
7604 |
25 Feb 19 |
nicklas |
var Jobs = function() |
7604 |
25 Feb 19 |
nicklas |
27 |
{ |
7604 |
25 Feb 19 |
nicklas |
var jobs = {}; |
7604 |
25 Feb 19 |
nicklas |
29 |
|
7604 |
25 Feb 19 |
nicklas |
30 |
/** |
7604 |
25 Feb 19 |
nicklas |
Initialize the page. |
7604 |
25 Feb 19 |
nicklas |
32 |
*/ |
7604 |
25 Feb 19 |
nicklas |
jobs.initPage = function() |
7604 |
25 Feb 19 |
nicklas |
34 |
{ |
7604 |
25 Feb 19 |
nicklas |
var pageId = Doc.getPageId(); |
7604 |
25 Feb 19 |
nicklas |
if (pageId == 'view-page') |
7604 |
25 Feb 19 |
nicklas |
37 |
{ |
7604 |
25 Feb 19 |
nicklas |
var itemId = Data.get('page-data', 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var attributes = {'item-type': 'JOB', 'item-id': itemId}; |
7604 |
25 Feb 19 |
nicklas |
40 |
|
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnUsingItems', Buttons.showUsingItems, attributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnDeletePermanently', Buttons.deleteItemPermanently, attributes); |
7604 |
25 Feb 19 |
nicklas |
Events.addEventHandler('btnDeletePermanently', 'base-notify', jobs.jobDeleted); |
7604 |
25 Feb 19 |
nicklas |
44 |
|
7604 |
25 Feb 19 |
nicklas |
// Pause/Abort button |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnPause', jobs.pauseJob); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnAbort', jobs.abortJob); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnForceError', jobs.forceError); |
7604 |
25 Feb 19 |
nicklas |
49 |
|
7604 |
25 Feb 19 |
nicklas |
// Restart job |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnRestartJob', jobs.restartJob); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnReconfigureJob', jobs.reconfigureJob); |
7604 |
25 Feb 19 |
nicklas |
53 |
|
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
55 |
|
7604 |
25 Feb 19 |
nicklas |
if (Data.int('page-data', 'auto-update')) |
7604 |
25 Feb 19 |
nicklas |
57 |
{ |
7604 |
25 Feb 19 |
nicklas |
jobs.sendProgressUpdateRequest(); |
7604 |
25 Feb 19 |
nicklas |
59 |
} |
7604 |
25 Feb 19 |
nicklas |
60 |
} |
7604 |
25 Feb 19 |
nicklas |
else if (pageId == 'list-page') |
7604 |
25 Feb 19 |
nicklas |
62 |
{ |
7604 |
25 Feb 19 |
nicklas |
var attributes = {'item-type': 'JOB'}; |
7604 |
25 Feb 19 |
nicklas |
var tableAttributes = {'table-id': 'jobs'}; |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnDeleteItems', Buttons.deleteItems, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnRestoreItems', Buttons.restoreItems, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnAbort', jobs.abortJobs, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnPause', jobs.pauseJobs, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnShareItems', Buttons.shareItems, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnSetOwner', Buttons.setOwnerOfItems, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnColumns', Buttons.configureColumns, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnExport', Buttons.runListPlugin, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnImport', Buttons.runListPlugin, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnRunPlugin', Buttons.runListPlugin, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
75 |
|
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
7604 |
25 Feb 19 |
nicklas |
Buttons.addClickHandler('btnOk', Buttons.returnSelected, tableAttributes); |
7604 |
25 Feb 19 |
nicklas |
78 |
} |
7604 |
25 Feb 19 |
nicklas |
79 |
} |
7604 |
25 Feb 19 |
nicklas |
80 |
|
7604 |
25 Feb 19 |
nicklas |
jobs.jobDeleted = function(event) |
7604 |
25 Feb 19 |
nicklas |
82 |
{ |
7604 |
25 Feb 19 |
nicklas |
window.opener.Items.list('JOB'); |
7604 |
25 Feb 19 |
nicklas |
window.close(); |
7604 |
25 Feb 19 |
nicklas |
85 |
} |
7604 |
25 Feb 19 |
nicklas |
86 |
|
7604 |
25 Feb 19 |
nicklas |
jobs.pauseJob = function() |
7604 |
25 Feb 19 |
nicklas |
88 |
{ |
7604 |
25 Feb 19 |
nicklas |
var jobId = Data.get('page-data', 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var url = 'index.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&cmd=PauseJob&item_id='+jobId; |
7604 |
25 Feb 19 |
nicklas |
location.replace(url); |
7604 |
25 Feb 19 |
nicklas |
93 |
} |
7604 |
25 Feb 19 |
nicklas |
94 |
|
7604 |
25 Feb 19 |
nicklas |
jobs.pauseJobs = function() |
7604 |
25 Feb 19 |
nicklas |
96 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['jobs']; |
7604 |
25 Feb 19 |
nicklas |
var numSelected = Table.checkIfSelected('jobs'); |
7604 |
25 Feb 19 |
nicklas |
if (numSelected == 0) return; |
7604 |
25 Feb 19 |
nicklas |
if (!confirm('You are about to pause '+numSelected+' jobs. Continue?')) |
7604 |
25 Feb 19 |
nicklas |
101 |
{ |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
103 |
} |
7604 |
25 Feb 19 |
nicklas |
frm.cmd.value = 'PauseJobs'; |
7604 |
25 Feb 19 |
nicklas |
frm.submit(); |
7604 |
25 Feb 19 |
nicklas |
106 |
} |
7604 |
25 Feb 19 |
nicklas |
107 |
|
7604 |
25 Feb 19 |
nicklas |
jobs.abortJobs = function() |
7604 |
25 Feb 19 |
nicklas |
109 |
{ |
7604 |
25 Feb 19 |
nicklas |
var frm = document.forms['jobs']; |
7604 |
25 Feb 19 |
nicklas |
var numSelected = Table.checkIfSelected('jobs'); |
7604 |
25 Feb 19 |
nicklas |
if (numSelected == 0) return; |
7604 |
25 Feb 19 |
nicklas |
if (!confirm('You are about to abort '+numSelected+' jobs. This can\'t be undone. Continue?')) |
7604 |
25 Feb 19 |
nicklas |
114 |
{ |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
116 |
} |
7604 |
25 Feb 19 |
nicklas |
frm.cmd.value = 'AbortJobs'; |
7604 |
25 Feb 19 |
nicklas |
frm.submit(); |
7604 |
25 Feb 19 |
nicklas |
119 |
} |
7604 |
25 Feb 19 |
nicklas |
120 |
|
7604 |
25 Feb 19 |
nicklas |
jobs.abortJob = function() |
7604 |
25 Feb 19 |
nicklas |
122 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (confirm('Are you sure? This action may not be undone')) |
7604 |
25 Feb 19 |
nicklas |
124 |
{ |
7604 |
25 Feb 19 |
nicklas |
var jobId = Data.get('page-data', 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var url = 'index.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&cmd=AbortJob&item_id='+jobId; |
7604 |
25 Feb 19 |
nicklas |
location.replace(url); |
7604 |
25 Feb 19 |
nicklas |
129 |
} |
7604 |
25 Feb 19 |
nicklas |
130 |
} |
7604 |
25 Feb 19 |
nicklas |
131 |
|
7604 |
25 Feb 19 |
nicklas |
jobs.forceError = function() |
7604 |
25 Feb 19 |
nicklas |
133 |
{ |
7604 |
25 Feb 19 |
nicklas |
var p = 'CAUTION!!\n'; |
7604 |
25 Feb 19 |
nicklas |
p += 'Use this for jobs that have crashed and can\'t be aborted normally.\n'; |
7604 |
25 Feb 19 |
nicklas |
var msg = prompt(p, 'Job has crashed'); |
7604 |
25 Feb 19 |
nicklas |
if (msg == null) return; |
7604 |
25 Feb 19 |
nicklas |
138 |
|
7604 |
25 Feb 19 |
nicklas |
var jobId = Data.get('page-data', 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var url = 'index.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&cmd=ForceError&item_id='+jobId; |
7604 |
25 Feb 19 |
nicklas |
url += '&msg='+encodeURIComponent(msg); |
7604 |
25 Feb 19 |
nicklas |
location.replace(url); |
7604 |
25 Feb 19 |
nicklas |
144 |
} |
7604 |
25 Feb 19 |
nicklas |
145 |
|
7604 |
25 Feb 19 |
nicklas |
146 |
|
7604 |
25 Feb 19 |
nicklas |
jobs.restartJob = function(event, options) |
7604 |
25 Feb 19 |
nicklas |
148 |
{ |
7604 |
25 Feb 19 |
nicklas |
var parameterVersion = Data.int('page-data', 'job-parameter-version'); |
7604 |
25 Feb 19 |
nicklas |
var latestVersion = Data.int('page-data', 'latest-parameter-version'); |
7604 |
25 Feb 19 |
nicklas |
var breakPoint = Data.get('page-data', 'breakpoint'); |
7604 |
25 Feb 19 |
nicklas |
var jobId = Data.get('page-data', 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var clearDryRun = event ? Data.int(event.currentTarget, 'clear-dry-run', 0) : 0; |
7604 |
25 Feb 19 |
nicklas |
154 |
|
7604 |
25 Feb 19 |
nicklas |
var useLatestConfiguration = 0; |
7604 |
25 Feb 19 |
nicklas |
var resumeFromBreakPoint = 0; |
7604 |
25 Feb 19 |
nicklas |
if (parameterVersion != latestVersion || breakPoint) |
7604 |
25 Feb 19 |
nicklas |
158 |
{ |
7604 |
25 Feb 19 |
nicklas |
if (!options) |
7604 |
25 Feb 19 |
nicklas |
160 |
{ |
7604 |
25 Feb 19 |
nicklas |
var url = 'restart_job_options.jsp?'; |
7604 |
25 Feb 19 |
nicklas |
Dialogs.openPopup(url, 'RestartJobOptions', 500, 300); |
7604 |
25 Feb 19 |
nicklas |
return; |
7604 |
25 Feb 19 |
nicklas |
164 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
166 |
{ |
7604 |
25 Feb 19 |
nicklas |
useLatestConfiguration = options.useLatestConfiguration || 0; |
7604 |
25 Feb 19 |
nicklas |
resumeFromBreakPoint = options.resumeFromBreakPoint || 0; |
7604 |
25 Feb 19 |
nicklas |
169 |
} |
7604 |
25 Feb 19 |
nicklas |
170 |
} |
7604 |
25 Feb 19 |
nicklas |
var url = 'index.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&cmd=RestartJob&item_id='+jobId; |
7604 |
25 Feb 19 |
nicklas |
url += '&useLatestConfiguration='+useLatestConfiguration; |
7604 |
25 Feb 19 |
nicklas |
url += '&resumeFromBreakPoint='+resumeFromBreakPoint; |
7604 |
25 Feb 19 |
nicklas |
if (clearDryRun) url += '&clearDryRun=' + clearDryRun; |
7604 |
25 Feb 19 |
nicklas |
location.replace(url); |
7604 |
25 Feb 19 |
nicklas |
177 |
} |
7604 |
25 Feb 19 |
nicklas |
178 |
|
7604 |
25 Feb 19 |
nicklas |
jobs.reconfigureJob = function() |
7604 |
25 Feb 19 |
nicklas |
180 |
{ |
7604 |
25 Feb 19 |
nicklas |
var jobId = Data.get('page-data', 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var url = '../../common/plugin/index.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&cmd=ConfigureJob&job_id='+jobId; |
7604 |
25 Feb 19 |
nicklas |
location.replace(url); |
7604 |
25 Feb 19 |
nicklas |
185 |
} |
7604 |
25 Feb 19 |
nicklas |
186 |
|
7604 |
25 Feb 19 |
nicklas |
jobs.sendProgressUpdateRequest = function() |
7604 |
25 Feb 19 |
nicklas |
188 |
{ |
7604 |
25 Feb 19 |
nicklas |
var jobId = Data.get('page-data', 'item-id'); |
7604 |
25 Feb 19 |
nicklas |
var url = 'ajax.jsp?ID='+App.getSessionId(); |
7604 |
25 Feb 19 |
nicklas |
url += '&cmd=GetProgress&item_id='+jobId+'&'+Math.random(); |
7604 |
25 Feb 19 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
7604 |
25 Feb 19 |
nicklas |
request.open("GET", url, true); |
7604 |
25 Feb 19 |
nicklas |
Ajax.setReadyStateHandler(request, jobs.progressUpdateCallback); |
7604 |
25 Feb 19 |
nicklas |
request.send(null); |
7604 |
25 Feb 19 |
nicklas |
196 |
} |
7604 |
25 Feb 19 |
nicklas |
197 |
|
7604 |
25 Feb 19 |
nicklas |
jobs.progressUpdateCallback = function(request) |
7604 |
25 Feb 19 |
nicklas |
199 |
{ |
7604 |
25 Feb 19 |
nicklas |
var progress = JSON.parse(request.responseText); |
7604 |
25 Feb 19 |
nicklas |
var nextAction = jobs.sendProgressUpdateRequest; |
7604 |
25 Feb 19 |
nicklas |
var nextTimeout = 1500; |
7604 |
25 Feb 19 |
nicklas |
if (progress && progress.status == 'ok') |
7604 |
25 Feb 19 |
nicklas |
204 |
{ |
7604 |
25 Feb 19 |
nicklas |
var status = progress.jobStatus; |
7604 |
25 Feb 19 |
nicklas |
var message = progress.message; |
7604 |
25 Feb 19 |
nicklas |
var percentComplete = progress.percentComplete; |
7604 |
25 Feb 19 |
nicklas |
var runningTime = progress.runningTime; |
7604 |
25 Feb 19 |
nicklas |
209 |
|
7604 |
25 Feb 19 |
nicklas |
if (status != Data.get('page-data', 'job-status')) |
7604 |
25 Feb 19 |
nicklas |
211 |
{ |
7604 |
25 Feb 19 |
nicklas |
nextAction = App.reloadWindow; |
7604 |
25 Feb 19 |
nicklas |
nextTimeout = 100; |
7604 |
25 Feb 19 |
nicklas |
214 |
} |
7604 |
25 Feb 19 |
nicklas |
if (status == 'EXECUTING' || status == 'ABORTING') |
7604 |
25 Feb 19 |
nicklas |
216 |
{ |
7604 |
25 Feb 19 |
nicklas |
jobs.displayProgress(percentComplete, message, runningTime); |
7604 |
25 Feb 19 |
nicklas |
218 |
} |
7604 |
25 Feb 19 |
nicklas |
219 |
} |
7604 |
25 Feb 19 |
nicklas |
setTimeout(nextAction, nextTimeout); |
7604 |
25 Feb 19 |
nicklas |
221 |
} |
7604 |
25 Feb 19 |
nicklas |
222 |
|
7604 |
25 Feb 19 |
nicklas |
jobs.displayProgress = function(percentDone, message, runningTime) |
7604 |
25 Feb 19 |
nicklas |
224 |
{ |
7604 |
25 Feb 19 |
nicklas |
// Percent complete |
7604 |
25 Feb 19 |
nicklas |
var doneElement = Doc.element('percentDone'); |
7604 |
25 Feb 19 |
nicklas |
var remainElement = Doc.element('percentRemain'); |
7604 |
25 Feb 19 |
nicklas |
var unknownElement = Doc.element('percentUnknown'); |
7604 |
25 Feb 19 |
nicklas |
if (percentDone == -1) |
7604 |
25 Feb 19 |
nicklas |
230 |
{ |
7604 |
25 Feb 19 |
nicklas |
Doc.hide('percentDone'); |
7604 |
25 Feb 19 |
nicklas |
Doc.hide('percentRemain'); |
7604 |
25 Feb 19 |
nicklas |
Doc.show('percentUnknown'); |
7604 |
25 Feb 19 |
nicklas |
Doc.hide('percentText'); |
7604 |
25 Feb 19 |
nicklas |
235 |
} |
7604 |
25 Feb 19 |
nicklas |
else |
7604 |
25 Feb 19 |
nicklas |
237 |
{ |
7604 |
25 Feb 19 |
nicklas |
Doc.hide('percentUnknown'); |
7604 |
25 Feb 19 |
nicklas |
Doc.show('percentText'); |
7604 |
25 Feb 19 |
nicklas |
Doc.element('percentText').innerHTML = percentDone+'%'; |
7604 |
25 Feb 19 |
nicklas |
doneElement.style.width = percentDone+'%'; |
7604 |
25 Feb 19 |
nicklas |
remainElement.style.width = (100-percentDone)+'%'; |
7604 |
25 Feb 19 |
nicklas |
Doc.showHide('percentDone', percentDone > 0); |
7604 |
25 Feb 19 |
nicklas |
Doc.showHide('percentRemain', percentDone < 100); |
7604 |
25 Feb 19 |
nicklas |
245 |
} |
7604 |
25 Feb 19 |
nicklas |
246 |
|
7604 |
25 Feb 19 |
nicklas |
// Message |
7604 |
25 Feb 19 |
nicklas |
Doc.element('message').innerHTML = message; |
7604 |
25 Feb 19 |
nicklas |
249 |
|
7604 |
25 Feb 19 |
nicklas |
// Running time |
7604 |
25 Feb 19 |
nicklas |
Doc.element('runningTime').innerHTML = runningTime; |
7604 |
25 Feb 19 |
nicklas |
252 |
} |
7604 |
25 Feb 19 |
nicklas |
253 |
|
7604 |
25 Feb 19 |
nicklas |
return jobs; |
7604 |
25 Feb 19 |
nicklas |
255 |
}(); |
7604 |
25 Feb 19 |
nicklas |
256 |
|
7604 |
25 Feb 19 |
nicklas |
Doc.onLoad(Jobs.initPage); |