2010-02-01 04:22:35 +01:00
|
|
|
function ProcessWidget(div) {
|
|
|
|
this._div = div;
|
|
|
|
this._timerID = null;
|
2010-02-09 01:26:57 +01:00
|
|
|
this._processCount = 0;
|
2010-02-26 22:56:41 +01:00
|
|
|
|
|
|
|
this._updateOptions = {};
|
|
|
|
this._onDones = [];
|
2010-03-23 01:26:28 +01:00
|
|
|
this._latestHistoryEntry = null;
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
$(window).keypress(function(evt) {
|
|
|
|
if (evt.ctrlKey || evt.metaKey) {
|
|
|
|
var t = evt.target;
|
|
|
|
if (t) {
|
|
|
|
var tagName = t.tagName.toLowerCase();
|
|
|
|
if (tagName == "textarea" || tagName == "input") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.undo();
|
|
|
|
}
|
|
|
|
});
|
2010-02-26 22:56:41 +01:00
|
|
|
|
|
|
|
this.update({});
|
2010-02-01 04:22:35 +01:00
|
|
|
}
|
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
ProcessWidget.prototype.resize = function() {
|
|
|
|
};
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
ProcessWidget.prototype.update = function(updateOptions, onDone) {
|
2010-03-23 01:26:28 +01:00
|
|
|
this._latestHistoryEntry = null;
|
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
for (var n in updateOptions) {
|
|
|
|
if (updateOptions.hasOwnProperty(n)) {
|
|
|
|
this._updateOptions[n] = updateOptions[n];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (onDone) {
|
|
|
|
this._onDones.push(onDone);
|
|
|
|
}
|
|
|
|
|
2010-02-01 04:22:35 +01:00
|
|
|
if (this._timerID != null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
Ajax.chainGetJSON(
|
|
|
|
"/command/get-processes?" + $.param({ project: theProject.id }), null,
|
|
|
|
function(data) {
|
2010-03-23 01:26:28 +01:00
|
|
|
self._latestHistoryEntry = null;
|
2010-03-05 02:13:59 +01:00
|
|
|
self._render(data);
|
2010-02-01 04:22:35 +01:00
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2010-03-23 01:26:28 +01:00
|
|
|
ProcessWidget.prototype.showUndo = function(historyEntry) {
|
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this._latestHistoryEntry = historyEntry;
|
|
|
|
|
|
|
|
this._div.empty().show().html(
|
|
|
|
'<div class="process-panel-inner"><div class="process-panel-undo">' +
|
|
|
|
'<a href="javascript:{}" bind="undo">Undo</a> <span bind="description"></span>' +
|
|
|
|
'</div></div>'
|
|
|
|
);
|
|
|
|
var elmts = DOM.bind(this._div);
|
|
|
|
|
|
|
|
elmts.description.text(historyEntry.description);
|
|
|
|
elmts.undo.click(function() { self.undo() });
|
|
|
|
};
|
|
|
|
|
|
|
|
ProcessWidget.prototype.undo = function() {
|
|
|
|
if (this._latestHistoryEntry != null) {
|
|
|
|
Gridworks.postProcess(
|
|
|
|
"undo-redo",
|
|
|
|
{ undoID: this._latestHistoryEntry.id },
|
|
|
|
null,
|
|
|
|
{ everythingChanged: true }
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-03-04 02:14:48 +01:00
|
|
|
ProcessWidget.prototype._cancelAll = function() {
|
2010-03-05 02:13:59 +01:00
|
|
|
var self = this;
|
2010-03-04 02:14:48 +01:00
|
|
|
$.post(
|
|
|
|
"/command/cancel-processes?" + $.param({ project: theProject.id }),
|
|
|
|
null,
|
2010-03-05 02:13:59 +01:00
|
|
|
function(o) {
|
|
|
|
self._data = null;
|
|
|
|
self._runOnDones();
|
|
|
|
},
|
2010-03-04 02:14:48 +01:00
|
|
|
"json"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2010-03-05 02:13:59 +01:00
|
|
|
ProcessWidget.prototype._render = function(newData) {
|
2010-02-01 04:22:35 +01:00
|
|
|
var self = this;
|
2010-03-05 02:13:59 +01:00
|
|
|
var newProcessMap = {};
|
2010-02-01 04:22:35 +01:00
|
|
|
|
|
|
|
this._div.empty();
|
|
|
|
|
2010-03-05 02:13:59 +01:00
|
|
|
if (newData.processes.length == 0) {
|
2010-02-01 04:22:35 +01:00
|
|
|
this._div.hide();
|
2010-02-26 22:56:41 +01:00
|
|
|
} else {
|
|
|
|
this._div.show();
|
2010-02-09 01:26:57 +01:00
|
|
|
|
2010-03-04 02:14:48 +01:00
|
|
|
var innerDiv = $('<div></div>').addClass("process-panel-inner").appendTo(this._div);
|
|
|
|
|
|
|
|
var headDiv = $('<div></div>').addClass("process-panel-head").appendTo(innerDiv);
|
2010-02-26 22:56:41 +01:00
|
|
|
$('<img src="images/small-spinner.gif" />')
|
2010-03-04 02:14:48 +01:00
|
|
|
.css("margin-right", "3px")
|
2010-02-26 22:56:41 +01:00
|
|
|
.css("opacity", "0.3")
|
2010-03-04 02:14:48 +01:00
|
|
|
.appendTo(headDiv);
|
|
|
|
$('<a href="javascript:{}"></a>')
|
|
|
|
.addClass("action")
|
|
|
|
.text("cancel all")
|
|
|
|
.click(function() {
|
|
|
|
self._cancelAll();
|
2010-03-05 02:13:59 +01:00
|
|
|
|
2010-03-04 02:14:48 +01:00
|
|
|
$(this).text("canceling all processes...").unbind();
|
|
|
|
})
|
|
|
|
.appendTo(headDiv);
|
|
|
|
|
|
|
|
var bodyDiv = $('<div></div>').addClass("process-panel-body").appendTo(innerDiv);
|
2010-02-26 22:56:41 +01:00
|
|
|
var renderProcess = function(process) {
|
|
|
|
var div = $('<div></div>').addClass("process-panel-entry").appendTo(bodyDiv);
|
2010-02-09 01:26:57 +01:00
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
if (process.status == "pending") {
|
|
|
|
div.text(process.description + " (pending)");
|
|
|
|
} else {
|
|
|
|
div.text(process.description + " (" + process.progress + "%)");
|
|
|
|
}
|
|
|
|
};
|
2010-02-01 04:22:35 +01:00
|
|
|
|
2010-03-05 02:13:59 +01:00
|
|
|
var processes = newData.processes;
|
2010-02-26 22:56:41 +01:00
|
|
|
for (var i = 0; i < processes.length; i++) {
|
2010-03-05 02:13:59 +01:00
|
|
|
var process = processes[i];
|
|
|
|
renderProcess(process);
|
|
|
|
if ("onDone" in process) {
|
|
|
|
newProcessMap[process.id] = process;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((this._data) && this._data.processes.length > 0) {
|
|
|
|
var oldProcesses = this._data.processes;
|
|
|
|
for (var i = 0; i < oldProcesses.length; i++) {
|
|
|
|
var process = oldProcesses[i];
|
|
|
|
if ("onDone" in process && !(process.id in newProcessMap)) {
|
|
|
|
this._perform(process.onDone);
|
|
|
|
}
|
2010-02-01 04:22:35 +01:00
|
|
|
}
|
|
|
|
}
|
2010-03-05 02:13:59 +01:00
|
|
|
this._data = newData;
|
2010-02-01 04:22:35 +01:00
|
|
|
|
2010-02-26 22:56:41 +01:00
|
|
|
if (this._data.processes.length > 0 && this._timerID == null) {
|
2010-02-01 04:22:35 +01:00
|
|
|
this._timerID = window.setTimeout(function() {
|
|
|
|
self._timerID = null;
|
|
|
|
self.update();
|
|
|
|
}, 500);
|
2010-02-26 22:56:41 +01:00
|
|
|
} else {
|
2010-03-05 02:13:59 +01:00
|
|
|
this._runOnDones();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ProcessWidget.prototype._perform = function(jobs) {
|
|
|
|
for (var i = 0; i < jobs.length; i++) {
|
|
|
|
var job = jobs[i];
|
|
|
|
if (job.action == "createFacet") {
|
|
|
|
try {
|
|
|
|
ui.browsingEngine.addFacet(
|
|
|
|
job.facetType,
|
|
|
|
job.facetConfig,
|
|
|
|
job.facetOptions
|
|
|
|
);
|
|
|
|
} catch (e) {
|
|
|
|
//
|
2010-02-26 22:56:41 +01:00
|
|
|
}
|
2010-03-05 02:13:59 +01:00
|
|
|
}
|
2010-02-01 04:22:35 +01:00
|
|
|
}
|
|
|
|
};
|
2010-03-05 02:13:59 +01:00
|
|
|
|
|
|
|
ProcessWidget.prototype._runOnDones = function() {
|
|
|
|
var updateOptions = this._updateOptions;
|
|
|
|
var onDones = this._onDones;
|
|
|
|
|
|
|
|
this._updateOptions = {};
|
|
|
|
this._onDones = [];
|
|
|
|
|
|
|
|
Gridworks.update(updateOptions, function() {
|
|
|
|
for (var i = 0; i < onDones.length; i++) {
|
|
|
|
try {
|
|
|
|
onDones[i]();
|
|
|
|
} catch (e) {
|
|
|
|
Gridworks.reportException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|