');
this._notificationBar.setup(function () { return App.ui.inspector; });
this._splitterBody = new WebWidgets.HorizontalSplitter({ appendTo: main_container, isRoot: true, initialSizePercent: 75, minPanelSizePixels: 24 });
this._splitterBody.rightPanel.addClass('desktop-oi-panel');
this.setupRightSide(this._splitterBody.rightPanel);
this._jqCentre = this._splitterBody.leftPanel;
var cover = $('
');
cover.mouseup(function (e) { return _this.clickOnRItem(e.clientX, e.clientY); });
cover.appendTo(this._jqCentre);
};
RItemForwarder.prototype.setupRightSide = function (rightPanel) {
var _this = this;
rightPanel.append($(""));
rightPanel.append(App.ui.inspector.inspector.element);
App.ui.inspector.inspector.appendToParent(rightPanel, function (do_expand, desired_width) {
var main_rect = $(".main-container")[0].getBoundingClientRect();
if (!desired_width)
desired_width = main_rect.width * (do_expand ? 0.4 : 0.2);
var desired_pct = ((main_rect.width - desired_width) / main_rect.width) * 100;
_this._splitterBody.setLeftPercent(desired_pct);
});
App.ui.inspector.inspector.applyBackgroundGradient(rightPanel);
setInterval(function () {
return $(".highlight-ambiguous").toggleClass("on");
}, 500);
var collapsed_handles = new CollapsedPanelHandles($("none"), rightPanel, 24, ["Properties"]);
collapsed_handles.getJq().click(function () {
var pixels = $(window).width() - Math.max(140, $(window).width() - rightPanel.data("restore-to-pagex"));
_this._splitterBody.setLeftPixels(pixels);
collapsed_handles.update(_this._splitterBody.rightPanel.width());
});
this._splitterBody.onResize = function () {
return collapsed_handles.update(_this._splitterBody.rightPanel.width());
};
};
RItemForwarder.prototype.clickOnRItem = function (x, y) {
var inside = $('div.dash').filter(function (i, elt) {
var p = $(elt).position();
var w = $(elt).width();
var h = $(elt).height();
var x0 = p.left;
var y0 = p.top;
return x0 <= x && x <= x0 + w && y0 <= y && y <= y0 + h;
});
if (inside.length !== 1)
return;
var guid = $(inside[0]).attr("id");
var index = this.getSelectedGuids().indexOf(guid);
if (index === -1)
return;
var gui = this._guis[index];
this._selected.leaveRItem(true, "RItemForwarder:clickOnRItem");
this.selectRItem(gui);
this._selected.enterRItem(guid);
};
RItemForwarder.prototype.selectRItem = function (gui) {
this.setState(gui.guids[0], gui.getState());
App.ui.inspector.setGui(gui);
$("div.dash.selected").removeClass("selected");
$("div#{0}.dash".format(RItemGui.makeId(gui.guids[0]))).addClass("selected");
this._selected = gui;
};
RItemForwarder.prototype.selected = function () {
return this._selected;
};
RItemForwarder.prototype.using = function (guid) {
var index = this.getSelectedGuids().indexOf(guid);
if (index < 0)
throw new Error('unknown item');
var gui = this._guis[index];
this.setState(gui.guids[0], gui.getState());
App.ui.inspector.setGui(gui);
return gui;
};
RItemForwarder.prototype.getPendingOperations = function () {
var pending = new PendingOperations();
if (this._waitingForNotificationTimeout !== undefined)
pending.add('RItemForwarder', '', '_waitingForNotificationTimeout');
if (this._guis.length === 0 && this._multi)
pending.addRange(this._multi.getPendingOperations());
this._guis.forEach(function (g) {
return pending.addRange(g.getPendingOperations());
});
return pending;
};
RItemForwarder.prototype._onNotificationsChanged = function () {
var _this = this;
clearTimeout(this._waitingForNotificationTimeout);
this._waitingForNotificationTimeout = setTimeout(function () { return _this._waitingForNotificationTimeout = undefined; }, 500);
};
RItemForwarder.prototype.multipleOutputsAreOutOfDate = function (out_of_date) {
this._notificationBar.multipleOutputs(out_of_date);
};
RItemForwarder.delayedEnterRItem = null;
return RItemForwarder;
}());
var rItemForwarder;
$(document).ready(function () {
var params = Util.hashParams();
if (params['setting'] === "desktop") {
setTimeout(function () {
rItemForwarder = new RItemForwarder();
Util.addPendingOperationsGetter(rItemForwarder);
setTimeout(function () {
QServerRequestsDesktop.RItemReady();
});
$(window).on('hashchange', function () {
QServerRequestsDesktop.RItemReady();
});
});
}
});
;
// /Scripts/Dashboard/RItem/LastUpdatedMessageMaintainer.ts
var LastUpdatedMessageMaintainer = /** @class */ (function () {
function LastUpdatedMessageMaintainer(gui, jqObj, ritem_oi) {
this._gui = gui;
this._ritem_oi = ritem_oi;
this._jqObj = jqObj;
}
LastUpdatedMessageMaintainer.prototype.durationAsText = function (updated) {
if (!updated)
return Translate("unknown");
var since = (new Date().getTime() - updated.getTime()) / 60000;
if (since > 12 * 60)
return Translate("{0} at {1}").format(updated.toLocaleDateString(), updated.toLocaleTimeString());
if (since > 2 * 60)
return Translate("{0} hours ago").format(Math.floor(since / 60));
if (since > 60)
return Translate("an hour ago");
if (since > 2)
return Translate("{0} minutes ago").format(Math.floor(since));
if (since > 1)
return Translate("a minute ago");
return Translate("just now");
};
LastUpdatedMessageMaintainer.prototype.textForUpdate = function () {
return this.durationAsText(this._gui.getState().updated);
};
LastUpdatedMessageMaintainer.prototype.refreshUpdate = function () {
};
LastUpdatedMessageMaintainer.prototype.setLastUpdatedDate = function (updated) {
this._gui._state.updated = updated;
this.setTooltip(Translate("Updated on {0} at {1}").format(updated.toLocaleDateString(), updated.toLocaleTimeString()));
this.refreshUpdate();
};
LastUpdatedMessageMaintainer.prototype.setText = function (message) {
};
LastUpdatedMessageMaintainer.prototype.setTooltip = function (message) {
};
LastUpdatedMessageMaintainer.prototype.setTextAndTooltip = function (message) {
this.setText(message);
this.setTooltip(message);
if (message === "calculating..." || message === "populating...")
this._jqObj.removeClass("red");
};
return LastUpdatedMessageMaintainer;
}());
;
// /Scripts/Dashboard/RItem/RItemGui.ts
/**
* Common GUI code for R items.
*
* This is an abstract class for sharing code and is extended by these real classes:
* RItemForDashboard (editing/viewing a single item on a dashboard page)
* RItemMultiGui (multi-item selection on the desktop)
* RItemStandaloneGui (editing a single item on the desktop)
*/
var RItemGui = /** @class */ (function () {
function RItemGui(guids, centre, state, notification_bar, disable_resizing) {
this.guids = guids;
this.onStateChanged = new EventSource();
this._editMode = false;
this.multiple = false;
this._tableStylesSubscriptionRequest = { Request: 'GetTableFormatsCss' };
this._zoom = 1;
this._committables = [];
/** Jan says this is for table tests. This is why nobody bothers to set it to false,
* because they aren't doing multiple operations on the same R Item. */
this.outputReadyForTraining = false;
this.guiControlsReadyForTraining = true;
this.lastStatistics = [];
this._waitingForRControls = false;
this._hasChangedState = false;
this._lastSequenceSent = -1;
this.ribbonForControls = new RItemRibbonForControls(this);
this._htmlWidgetContainer = new HtmlwidgetContainer(this);
this._jqCenter = centre;
this._disableResizing = disable_resizing;
this._state = state;
if (Environment.isEditor)
this.setInspector(App.ui.inspector);
this._notificationBar = notification_bar;
this.setupBody();
this.lastUpdatedMessageMaintainer = new LastUpdatedMessageMaintainer(this, this._jqObj, null);
}
RItemGui.prototype.applyInitialState = function () {
if (this._state.layout)
this.applyLayout(this._state.layout);
if (this._state.outputs)
this.setOutputs(this._state.outputs);
if (this._state.guiControls && Environment.isEditor)
this.gotRControls(this._state.guiControls);
if (this._state.executedCode)
this.showExecutedCodeInOutput(this._state.executedCode);
if (this._disableResizing)
this.disableResizing();
if (this._state.highlightedCodeSpans)
this.highlightSpans();
this._applyCalculating(this._state.calculating);
};
RItemGui.prototype.updateInputsUpdateControl = function () {
throw new Error("hi georgii. seriously, I want to see if this is called from somewhere");
};
RItemGui.prototype.setInspector = function (inspector) {
if (inspector && inspector !== App.ui.inspector)
throw new Error("Unexpected inspector.");
};
RItemGui.prototype.setNotificationBar = function (notification_bar) {
this._notificationBar = notification_bar;
};
RItemGui.makeId = function (guid) { return "ritem-id-" + guid; };
RItemGui.prototype.id = function () {
return RItemGui.makeId(this.guids[0]);
};
RItemGui.prototype.setupBody = function () {
};
RItemGui.prototype.disableResizing = function () {
this._disableResizing = true;
if (Environment.isEditor)
return;
if (this._vsplitter) {
this._vsplitter.destroy();
this._vsplitter = null;
}
if (this._hsplitter && this._hsplitter.destroy) {
this._hsplitter.destroy();
this._hsplitter = null;
}
};
RItemGui.prototype.tearDownBody = function () {
this._jqCenter.empty();
};
RItemGui.prototype.setupLeftSide = function (leftPanel) {
var _this = this;
this._pageFrame = leftPanel;
this._contentFrame = $('
');
if (this._state.size && this._state.size.Height > 0 && this._state.size.Width > 0)
this._contentFrame.css({ left: 0, top: 0, width: this._state.size.Width, height: this._state.size.Height });
if (Application.isForDataset())
this._contentFrame.addClass("cant-resize");
else if (!this._disableResizing)
this._contentFrame.resizable({
handles: "e,s,se",
resize: function (event, ui) { return _this.resize({ width: ui.size.width, height: ui.size.height }); },
stop: function (event, ui) {
var size = { width: ui.size.width, height: ui.size.height };
_this.resize(size);
_this.onUserResizeStop(size);
}
});
var div = $('
'.format(this.id())).append(this._contentFrame);
leftPanel.append(div);
this._vsplitter = new WebWidgets.VerticalSplitter({ appendTo: this._contentFrame, isRoot: false, initialSizePercent: 25 });
this.modifyOutputSplitter(this._vsplitter);
this._vsplitter.bottomPanel.addClass("flip-container flip-notanimating");
this._codeContainer = $('
').appendTo(this._vsplitter.topPanel);
this.rItemCodeEditor = new RibbonCodeEditor('inplace', null, 'r', false, undefined, undefined, undefined, undefined);
this.rItemCodeEditor.hideToolbar();
this.rItemCodeEditor.enabled(true);
this.rItemCodeEditor.setReadOnly(true);
if (Util.isForScreenshot())
this.rItemCodeEditor.hideScrollbars();
this.rItemCodeEditor.addToDialog(this._codeContainer);
this.rItemCodeEditor.getJqPrimaryControl()
.addClass("inplace")
.attr("id", "editor-" + this.guids[0])
.droppable({
drop: function (event, ui) {
if (event.clientX < $(".oi-container").offset().left) {
var drag_helper = ui.helper.data("ritem-drag-helper");
if (drag_helper) {
var text = drag_helper.getSortedSelection().map(function (item) { return item.title; }).map(function (text) { return text.matches(/[^a-zA-Z0-9\._]/) ? "`" + text + "`" : text; }).join(' + ');
_this.rItemCodeEditor.insertSnippet(text, event.pageX, event.pageY);
}
}
}
});
this._jqObj = $('
');
this._jqConsole = $('
');
this._jqQueued = $('
QUEUED FOR CALCULATION
');
this._jqCalculating = $('CALCULATING
');
this._outputContainer = $('')
.append(this._jqObj)
.append(this._jqConsole)
.append(this._jqQueued)
.append(this._jqCalculating);
if (!Util.isForScreenshot()) {
this._jqObj.addClass("flip-front flip-1");
this._jqConsole.addClass("flip-back flip-1");
this._outputContainer.addClass("flipper");
}
this._vsplitter.bottomPanel.append(this._outputContainer);
};
RItemGui.prototype.setZoom = function (new_zoom) {
this._zoom = new_zoom;
this.reZoomOutput();
};
RItemGui.prototype.reZoomOutput = function () {
if (this._zoom !== 1)
if (this._jqObj)
this._jqObj.children().css({
'transform': "scale(" + this._zoom + ")",
'transform-origin': '0 0'
});
};
RItemGui.prototype.workareaZoom = function (workarea_zoom) {
if (this.rItemCodeEditor)
this.rItemCodeEditor.workareaZoom(workarea_zoom);
};
RItemGui.prototype.displayInputValues = function (options, code, spans) {
this.setLastUpdatedText(Translate("calculating..."));
this.setOptions(options);
};
/** Called by the CodeEditorCoordinator when the user changes the code
* in any code editor instance (may be multiple). Or the Q OLT tests
* have set code programmatically. */
RItemGui.prototype.editCode = function (guid, value) {
var _this = this;
this._lastEditedCode = RibbonCodeEditor.getRCode(guid);
var text = value === undefined ? this._lastEditedCode : value;
if (text === this._state.lastSavedCode) {
return;
}
this._state.lastSavedCode = text;
QServerRequestsCommon.RItemAutoSave({
GUID: this.guids[0],
Code: text
});
QServerRequestsCommon.RItemRehighlightCode({
GUID: guid
}, function (response) {
_this._state.highlightedCodeSpans = response.Highlights;
if (_this._state.highlightedCodeSpans)
_this.highlightSpans();
});
};
RItemGui.prototype.highlightCode = function (guid) {
clearTimeout(this._state.highlightingTimer);
this._state.highlightingTimer = setTimeout(function () {
}, 500);
};
RItemGui.prototype.onUpdateClicked = function () {
var _this = this;
App.ui.inspector.commit();
this._updateClickedTimer = setTimeout(function () {
if (!Application.isForDataset() &&
!Subscription.getSubscriptions()
.any(function (sub) { return (sub.request.Request === 'GetREditPreCalcStuff' &&
sub.request.GUID === _this.guids[0]) ||
(sub.request
.Request ===
'RenderItem' &&
sub.request.GUID === _this.guids[0]); })) {
reportJavaScriptError(new Error('RItemUpdateClicked requested when there is no subscription waiting on results! RS-1411'));
}
QServerRequestsCommon.ItemUpdateClicked({
GUID: _this.guids[0],
Code: null
}, function () {
_this.onAfterUpdateClicked();
_this.lastStatistics = QServer.lastStatistics;
});
});
};
RItemGui.prototype.onCancelClicked = function () {
QServerRequestsCommon.ItemCancelClicked({ GUID: this.guids[0] });
};
RItemGui.prototype.onAfterUpdateClicked = function () {
if (Application.isForDataset())
this.requestAndDisplayOutput();
};
RItemGui.prototype.setOptions = function (options) {
this._state.setFromOptions(options);
this.setDebugVisibility(this._state.showDebug, false);
if (this._state.layoutRefreshRequired)
this.changeLayout(this._state.layout);
if (!Application.isForDataset())
this.resize(this._state.getISize());
if (!this._editMode)
return;
if (!App.isSoleSelection(this.guids[0]))
return;
if (App.ui.inspector)
App.ui.inspector.update("RItemGui:setOptions");
if (Application.isForDataset())
return;
this._notificationBar.setState(this.guids[0], this._state);
};
RItemGui.prototype.changeOptions = function (options, user_done_it) {
QServerRequestsCommon.SetItemsUi({
ActiveTab: App.isDesktop ? null : Dashboard.instance.getSelectedTab().guid,
GUIDs: this.getItemGuids(),
Value: options,
UserDoneIt: user_done_it
});
};
RItemGui.prototype.changeOption = function (key, value, user_done_it) {
var options = {};
options[key] = value;
return this.changeOptions(options, user_done_it);
};
RItemGui.prototype.resize = function (size) {
var box = $('div#{0} #resizable-box'.format(this.id()));
box.css({
width: size.width,
height: size.height
});
if (this.rItemCodeEditor && this._state.layout && this._state.layout !== Layout.OutputOnly)
this.rItemCodeEditor.mayHaveResized("resized");
};
RItemGui.prototype.onUserResizeStop = function (size) {
this.changeOption("size", size, true);
this._state.size = { Width: size.width, Height: size.height };
};
RItemGui.prototype.updateSplits = function (user_done_it) {
if (this._state.oldLayout === Layout.Left)
this._state.hSplit = this._hsplitter.leftPercent / 100;
else if (this._state.oldLayout === Layout.Top)
this._state.vSplit = this._vsplitter.topPercent / 100;
else if (this._state.oldLayout === Layout.Right)
this._state.hSplit = 1 - this._hsplitter.leftPercent / 100;
else if (this._state.oldLayout === Layout.Bottom)
this._state.vSplit = 1 - this._vsplitter.topPercent / 100;
this.changeOptions({
splitH: this._state.hSplit,
splitV: this._state.vSplit
}, user_done_it);
};
RItemGui.prototype.updateLayout = function (user_done_it) {
this.changeOption("codeposition", this._state.oldLayout, user_done_it);
if (this.rItemCodeEditor)
this.rItemCodeEditor.mayHaveResized("updatelayout");
};
RItemGui.getOutputTypeForChoice = function (choice) {
switch (choice.toLowerCase()) {
case "widget":
return OutputType.WIDGET;
case "help":
return OutputType.HELP;
case "plot":
return OutputType.PLOT;
case "table":
return OutputType.TABLE;
case "text":
return OutputType.TEXT;
case "error":
return OutputType.ERROR;
}
return undefined;
};
RItemGui.prototype.chooseOutputType = function (choice, user_done_it) {
this._state.outputType = RItemGui.getOutputTypeForChoice(choice) || this._state.outputType;
this.onOutputTypeChosen();
this.changeOption("output type", this._state.outputType, user_done_it);
};
RItemGui.prototype.onOutputTypeChosen = function () {
this._displayAppropriateOutput();
if (this._editMode) {
this._notificationBar.clearMustChooseOutputType();
this._notificationBar.clearMultipleOutputTypesNotification();
}
};
RItemGui.prototype.modifyOutputSplitter = function (splitter) {
var _this = this;
splitter.onResize = function () {
return _this.rItemCodeEditor.mayHaveResized("modifyOutputSplitter");
};
splitter.onStopResize = function () {
return _this.updateSplits(true);
};
};
RItemGui.prototype.setMultipleOutputTypesNotification = function () {
if (this._editMode)
this._notificationBar.setMultipleOutputTypesNotification();
};
RItemGui.prototype.setAvailableOutputTypes = function (list, choice, enabled) {
if (!Environment.isEditor)
return;
if (!App.isSoleSelection(this.guids[0]))
return;
App.ui.inspector.setAvailableOutputTypes(list, choice, enabled);
if (!this._editMode)
return;
if (typeof acts === "undefined")
return;
var hyperlink_enabled = true;
switch (this._state.outputType) {
case OutputType.WIDGET:
case OutputType.TABLE:
case OutputType.TABLE_PLOT:
hyperlink_enabled = false;
default:
break;
}
acts.ribbon.ctl('btnHyperlink').enabled(hyperlink_enabled);
};
RItemGui.availableOutputTypes = function (dict) {
var valid = {};
valid[OutputType.TABLE] = dict["table"] != null;
valid[OutputType.TEXT] = dict["text"] != null;
valid[OutputType.PLOT] = dict["plots"] != null;
valid[OutputType.ERROR] = dict["html-error"] != null;
valid[OutputType.WIDGET] = dict["htmlwidgets"] != null && dict["htmlwidget-head"] != null;
valid[OutputType.HELP] = dict["help"] != null;
return valid;
};
RItemGui.prototype.displayAvailableOutputTypes = function (valid) {
var _this = this;
var list = [];
if (valid[OutputType.WIDGET])
list.push("Widget");
if (valid[OutputType.HELP])
list.push("Help");
if (valid[OutputType.PLOT])
list.push("Plot");
if (valid[OutputType.TABLE])
list.push("Table");
if (valid[OutputType.TEXT])
list.push("Text");
if (this._state.listOfAvailableOutputTypes && this._state.listOfAvailableOutputTypes.length > 0
&& list.any(function (x) { return !_this._state.listOfAvailableOutputTypes.contains(x); }) && list.length > 1)
this.setMultipleOutputTypesNotification();
this._state.listOfAvailableOutputTypes = list;
var enabled = true;
var choice = '';
switch (this._state.outputType) {
case OutputType.WIDGET:
choice = "Widget";
break;
case OutputType.HELP:
choice = "Help";
break;
case OutputType.PLOT:
choice = "Plot";
break;
case OutputType.TABLE:
choice = "Table";
break;
case OutputType.TEXT:
choice = "Text";
break;
case OutputType.ERROR:
enabled = false;
break;
}
this.setAvailableOutputTypes(list, choice, enabled);
};
RItemGui.prototype.setOutputs = function (dict) {
var _this = this;
this.resetNotificationBar();
this._state.setOutputs(dict);
var valid = RItemGui.availableOutputTypes(dict);
if (!Application.isForDataset())
this.displayAvailableOutputTypes(valid);
else if (valid[OutputType.ERROR])
this._state.outputType = OutputType.ERROR;
else if (valid[OutputType.TABLE])
this._state.outputType = OutputType.TABLE;
else if (valid[OutputType.HELP])
this._state.outputType = OutputType.HELP;
else if (valid[OutputType.WIDGET])
this._state.outputType = OutputType.WIDGET;
else if (valid[OutputType.PLOT])
this._state.outputType = OutputType.PLOT;
else if (valid[OutputType.TEXT])
this._state.outputType = OutputType.TEXT;
else
this._state.outputType = OutputType.UNKNOWN;
this._displayAppropriateOutput();
var render_timeout = dict["plots"] ? Math.max(100, dict["plots"].length / 2000) : 100;
if (this._state.outputType !== OutputType.WIDGET) {
setTimeout(function () { return _this.outputReadyForTraining = true; }, render_timeout);
}
};
RItemGui.prototype.setMustChooseOutputType = function (type1, type2) {
var _this = this;
if (this._editMode)
this._notificationBar.setMustChooseOutputType(type1, type2, function (choice) { return _this.chooseOutputType(choice, true); });
};
RItemGui.prototype._effectiveOutputType = function () {
var effective_output = this._state.outputType;
var outputs = this._state.getOutputs();
if (outputs && outputs["html-error"]
&& (this._state.updateMode === "Automatic"
|| this._state.outputType === OutputType.ERROR
|| this._state.outputType === OutputType.UNKNOWN))
effective_output = OutputType.ERROR;
return effective_output;
};
RItemGui.prototype._displayAppropriateOutput = function () {
this._jqObj.removeClassesByRegExp(/routput-type-/);
var outputs = this._state.getOutputs();
if (outputs == null)
return;
this._jqConsole.empty();
var div = $('
').html(outputs["console"]).css("margin", "8px");
this._addPreloadHeader(div.children('div.debug-preloaded'));
this._jqConsole.append(div);
this._jqObj.addClass("routput-type-" + this._state.outputType);
if (this.wasEmptyRCode()) {
this.clear();
if (App.isDesktop)
this.addElement($('
').addClass('r-empty-output-text').html(Translate('Enter R code') + ' →'));
}
else {
this._jqObj.closest(".content.r-ritem").removeClass("empty-r-code");
switch (this._effectiveOutputType()) {
case OutputType.TABLE: {
if (outputs["table"] != null)
this.displayTable(outputs["table"]);
else
this._displayListOfTables(outputs["listoftables"]);
break;
}
case OutputType.TEXT:
this.displayText(outputs["text"], outputs["scalar"]);
break;
case OutputType.TEXT_PLOT:
case OutputType.PLOT:
this.displayPlot(outputs["plots"]);
break;
case OutputType.ERROR:
this._displayHtmlError(outputs["html-error"], outputs["error"], outputs["error-quoted-item-guids"] ? JSON.parse(outputs["error-quoted-item-guids"]) : null);
break;
case OutputType.WIDGET:
this._htmlWidgetContainer.display(outputs["htmlwidget-head"], outputs["htmlwidgets"], this._state.widgetState);
break;
case OutputType.HELP:
this._displayEltHtml(outputs["help"]);
break;
case OutputType.TABLE_PLOT:
this.displayTableAndPlot(outputs["table"], outputs["plots"]);
this.setMustChooseOutputType("Table", "Plot");
break;
default:
this.clear();
break;
}
}
if (!Application.isForDataset())
this.applyAppearanceParameters(this._state.appearance, "RItemGui:_displayAppropriateOutput, with this._state.appearance");
};
RItemGui.prototype.isEmptyRCode = function () {
if (!this._state.lastSavedCode || !this._state.lastSavedCode.trim().length)
return true;
return false;
};
RItemGui.prototype.hasGuiControls = function () {
return this._state && this._state.guiControls && this._state.guiControls.Controls && !!this._state.guiControls.Controls.filter(function (c) { return !!c.Type; }).length;
};
RItemGui.prototype.wasEmptyRCode = function () {
if (this.guids.length > 1)
return false;
var guid = this.guids[0];
var outputs = this._state.getOutputs();
if (outputs && this._state.outputType === OutputType.UNKNOWN) {
var item = App.resolve(guid);
if (!item)
return false; // this can happen in embedded modes - we return that there is no warning
var report_tree_item = new ReportTreeItem(item);
return report_tree_item.hasEmptyRCodeWarning();
}
return false;
};
RItemGui.prototype._addPreloadHeader = function (div) {
var arrow1 = "";
var arrow2 = "";
div.prepend($('
{0}
'.format(Translate("Preloaded Packages")))
.prepend(arrow1)
.prepend(arrow2));
div.children(".debug-preloaded-header,.arrow-expanded,.arrow-collapsed")
.hover(function (e) {
$(e.target)
.addClass("hover")
.siblings().addClass("hover");
}, function (e) {
$(e.target)
.removeClass("hover")
.siblings().removeClass("hover");
})
.click(function () {
var parent = $("div.debug-preloaded");
if (parent.hasClass("collapse"))
parent.removeClass("collapse");
else
parent.addClass("collapse");
});
};
RItemGui.prototype.addElement = function (elt, rezoom_now) {
if (rezoom_now === void 0) { rezoom_now = true; }
if (!this._jqObj)
this.clear();
this._jqObj.empty();
this._jqObj.append(elt);
if (rezoom_now)
this.reZoomOutput();
if (Util.isInternetExplorerVersionOrPrevious(11)) {
var plot_svg = elt.find('svg.ritem-image');
if (plot_svg.length) {
setTimeout(function () {
plot_svg = elt.find('svg.ritem-image');
if (plot_svg.length)
plot_svg.parent()[0].innerHTML = " " + plot_svg.parent()[0].innerHTML;
}, 0);
}
}
};
/** Display a table, by reading in an ITabularAdapter JSON string.
* This is used by the R item's main table output, and any preview tables
* shown in the bottom-right preview window. */
RItemGui.prototype.displayTable = function (json_table_data, parent) {
var outputs = this._state.getOutputs();
var additional_class = outputs ? outputs["table class"] : null;
this.createAndDisplayTableFromJsonData(json_table_data, additional_class, parent);
var data = JSON.parse(json_table_data);
var pagination = data.Settings.PaginationParameters;
if (pagination && pagination.EndElement - pagination.StartElement > 1)
this._jqObj.addClass('noVerticalScroll');
};
RItemGui.prototype.createAndDisplayTableFromJsonData = function (json_table_data, additional_class, parent) {
var table = new Table(JSON.parse(json_table_data));
var table_div = $('');
table_div.addClass('datagrid');
if (!!additional_class)
table_div.addClass(additional_class);
table_div.append(table.tableJQ);
this.handleTableEvents(table);
if (!parent)
parent = this._jqObj;
if (!parent)
throw new Error("Expected parent to have a value");
parent.empty();
parent.append(table_div);
this.reZoomOutput();
if (this._state.tabularFilteringOptions)
table.populateFilterDialog(this._state.tabularFilteringOptions);
};
RItemGui.prototype.handleTableEvents = function (table) {
var _this = this;
table.tableJQ.on('tableaction', function (event, action) {
return QServerRequestsCommon.RItemTableAction({ Action: action, GUID: _this.guids[0] }, function () {
if (!App.isSoleSelection(_this.guids[0]))
return;
_this.onAfterTableAction();
});
});
table.tableJQ.on('tablefilteropen', function (event, header) {
return QServerRequestsCommon.RItemTableFilterOpen({ Header: header, GUID: _this.guids[0] }, function (response) {
if (!App.isSoleSelection(_this.guids[0]))
return;
table.populateFilterDialog(response.Options);
_this.outputReadyForTraining = true;
App.ui.inspector.update("output Ready for training");
});
});
};
RItemGui.prototype.onAfterTableAction = function () {
if (Application.isForDataset())
this.requestAndDisplayOutput();
};
RItemGui.prototype._displayListOfTables = function (html) {
this.clear();
var arrow1 = "";
var arrow2 = "";
var div = $('
')
.addClass("datagrid")
.html(html)
.css("border", "none");
div.children().prepend(arrow1).prepend(arrow2);
div.children().children(".datagridlabel,.datagridlabel-arrow,.arrow-expanded,.arrow-collapsed")
.hover(function (e) {
$(e.target)
.addClass("hover")
.siblings().addClass("hover");
}, function (e) {
$(e.target)
.removeClass("hover")
.siblings().removeClass("hover");
})
.click(function (e) {
var tgt = $(e.target);
var parent = tgt.parent();
if (tgt.is("path"))
parent = parent.parent().parent();
if (tgt.is("svg"))
parent = parent.parent();
if (parent.hasClass("collapse"))
parent.removeClass("collapse");
else
parent.addClass("collapse");
});
this.addElement(div);
};
RItemGui.prototype.subscribeToTableStyles = function () {
if (!Subscription.isSubscribed(this._tableStylesSubscriptionRequest)) {
Subscription.subscribe(this._tableStylesSubscriptionRequest, function (response) {
$('style[data-tableformatstyle]').remove();
$("").appendTo('head');
});
}
};
RItemGui.prototype.displayPlot = function (plot_html) {
this.clear();
if (plot_html === undefined && this._state.hasGuiControls && Util.isDesktop())
this.addElement($('
').addClass('r-empty-output-text').html(Translate('Select Inputs') + ' →'));
else
this.addElement(this.plotElement(plot_html).css({ "overflow": "hidden", "height": "100%" }));
};
RItemGui.prototype.displayTableAndPlot = function (json_table_data, plot_html) {
this.clear();
var parent = $('
').addClass("ritem-pair-container");
this.displayTable(json_table_data, parent);
var plot = $('
').addClass("ritem-plots").append(this.plotElement(plot_html));
this.addElement(parent.append(plot));
};
RItemGui.prototype.plotElement = function (plot_html) {
if (plot_html !== undefined && plot_html !== null) {
var plot_id_1 = (RItemGui._nextPlotId++).toString() + "-";
plot_html = plot_html
.replace(/(id="glyph)(\d+-\d+")/g, function (m, p1, p2) { return p1 + plot_id_1 + p2; })
.replace(/(href="#glyph)(\d+-\d+")/g, function (m, p1, p2) { return p1 + plot_id_1 + p2; });
}
var div = $('
').html(plot_html);
div.find('svg').attr('class', 'ritem-image');
return div;
};
RItemGui.prototype.displayText = function (text, scalar_output_json) {
if (scalar_output_json) {
var output = JSON.parse(scalar_output_json);
text = JavaScriptItemHelper.decimalsToShow(output.value, output.decimalPlaces);
if (output.showPercentage)
text += '%';
else if (output.moneySymbol)
text = output.moneySymbol + text;
}
this.clear();
var div = $('
')
.addClass("ritem-text-output")
.text(text);
var parent = $('
')
.addClass("ritem-text-container")
.append(div);
this.addElement(parent);
};
RItemGui.prototype._displayHtmlError = function (text, plaintext_error_message, quoted_item_guids) {
var _this = this;
this.clear();
var div = $("
")
.addClass("ritem-text-error")
.html(text);
var plaintext_span = div.find(".rerror-plaintext-error-message");
if (plaintext_span.length && plaintext_error_message && quoted_item_guids && Environment.isEditor) {
plaintext_span.html(NotifyUtils.insertReferenceLinks(plaintext_error_message, quoted_item_guids));
plaintext_span.find(".reference-to-item").click(function (event) {
return Util.followLink(event.target);
});
}
this.addElement(div);
if (App.ui.inspector && App.isSoleSelection(this.guids[0]))
App.ui.inspector.update("error ready");
var timeout_id = setTimeout(function () {
_this.outputReadyForTraining = true; // because when an error occurs, we won't receive the actual output
}, 100);
setDisplayrTimeoutOptions(timeout_id, { fnHash: 'ready and output ready for training' });
};
RItemGui.prototype._displayImage = function (image) {
this.addElement($('')
.addClass("ritem-image")
.attr("src", "data:image/png;base64," + image));
};
RItemGui.prototype._displayEltHtml = function (html) {
this.clear();
var div = $("
");
div.append(Util.htmlDocument(html));
div.css("margin", "8px");
this.addElement(div);
};
RItemGui.prototype.applyAppearanceParameters = function (appearance, reason) {
if (!this._jqObj)
return; // we have not been added to the page.
var output_div_with_background = this._jqObj;
var output_div_with_scrollbars = this._getOutputDivWithScrollbars();
if (this._effectiveOutputType() !== OutputType.TEXT) {
output_div_with_background.css({
"background": ""
});
output_div_with_scrollbars.css({
"border-width": "",
"border-color": "",
"border-style": ""
});
return;
}
var output = output_div_with_scrollbars.find(".ritem-text-output");
var border = appearance.border;
if (border) {
if (output_div_with_background)
output_div_with_background.css({
"background": appearance.background || 'transparent' // null means transparent; see RibbonPopupColor
});
if (output_div_with_scrollbars)
output_div_with_scrollbars.css({
"border-width": border.size + "px",
"border-color": border.color || 'transparent',
"border-style": border.on ? border.style : "none"
});
output.css({
"padding": appearance.padding
});
}
var font = appearance.font;
var text = appearance.text;
if (font && text) {
if (output)
output.css({
"font-family": font.family,
"font-size": font.size + "pt",
"color": font.color || 'transparent',
"font-weight": font.bold ? "bold" : "normal",
"font-style": font.italic ? "italic" : "normal",
"text-decoration": font.underline ? (font.strikeout ? "underline line-through" : "underline") : (font.strikeout ? "line-through" : "none"),
"text-align": text.hAlign,
"vertical-align": text.vAlign,
"white-space": text.wrap ? "pre-wrap" : "pre"
});
if (output_div_with_scrollbars)
output_div_with_scrollbars.css({
"min-height": Math.ceil(font.size * 1.2) + "pt"
});
}
this._setDomScrollbars();
};
RItemGui.prototype._getOutputDivWithScrollbars = function () { return this._jqObj; };
RItemGui.prototype._setDomScrollbars = function () {
if (Util.isForScreenshot())
return;
var output_div_with_scrollbars = this._getOutputDivWithScrollbars();
var has_scroll = Util.getElementScrollbars(output_div_with_scrollbars[0]);
var css = Util.getTableCssForScrolling(has_scroll.x, has_scroll.y);
if (this._effectiveOutputType() !== OutputType.TEXT) {
output_div_with_scrollbars.css({ overflow: "" });
return;
}
output_div_with_scrollbars.css(css);
};
RItemGui.prototype.clear = function () {
if (this._jqObj) {
this._jqObj.empty();
this._jqObj.removeClass('noVerticalScroll');
this._htmlWidgetContainer.clear();
}
};
RItemGui.prototype.changeLayout = function (layout) {
this.applyLayout(layout);
if (this._editMode || App.isWeb) {
this._state.oldLayout = layout;
this.itemDidReattachToWorkarea();
}
};
RItemGui.prototype.itemDidReattachToWorkarea = function () {
if (this._state.outputType === OutputType.WIDGET) {
this.clear();
this._displayAppropriateOutput();
}
};
RItemGui.prototype.applyLayout = function (layout) {
var vsplitter_wanted = layout === Layout.Top || layout === Layout.Bottom;
var hsplitter_wanted = layout === Layout.Left || layout === Layout.Right;
if (this._lastLayoutApplied && this._lastLayoutApplied === layout &&
vsplitter_wanted === !!this._vsplitter && hsplitter_wanted === !!this._hsplitter) {
return; // avoid resetting any widget iframe when nothing has changed. cf. HtmlWidgetContainer.display()
}
else {
this._lastLayoutApplied = layout;
this._codeContainer.detach();
this._outputContainer.detach();
if (this._hsplitter) {
this._hsplitter.destroy();
this._hsplitter = null;
}
if (this._vsplitter) {
this._vsplitter.destroy();
this._vsplitter = null;
}
if (this._state.oldLayout === Layout.CodeOnly || this._state.oldLayout === Layout.OutputOnly)
this._contentFrame.removeClass("flip-container");
this._contentFrame.children(".splitPanel").remove();
switch (layout) {
case Layout.CodeOnly:
this._contentFrame.append(this._codeContainer);
break;
case Layout.OutputOnly:
this._outputContainer.children().removeClass("notransition");
this._contentFrame.addClass("flip-container flip-notanimating").append(this._outputContainer);
break;
case Layout.Left:
this._hsplitter = new WebWidgets.HorizontalSplitter({ appendTo: this._contentFrame, isRoot: false, initialSizePercent: 100 * this._state.hSplit });
this.modifyOutputSplitter(this._hsplitter);
this._hsplitter.leftPanel.append(this._codeContainer);
this._hsplitter.rightPanel.addClass("flip-container flip-notanimating").append(this._outputContainer);
break;
case Layout.Top:
this._vsplitter = new WebWidgets.VerticalSplitter({ appendTo: this._contentFrame, isRoot: false, initialSizePercent: 100 * this._state.vSplit });
this.modifyOutputSplitter(this._vsplitter);
this._vsplitter.topPanel.append(this._codeContainer);
this._vsplitter.bottomPanel.addClass("flip-container flip-notanimating").append(this._outputContainer);
break;
case Layout.Right:
this._hsplitter = new WebWidgets.HorizontalSplitter({ appendTo: this._contentFrame, isRoot: false, initialSizePercent: 100 - 100 * this._state.hSplit });
this.modifyOutputSplitter(this._hsplitter);
this._hsplitter.leftPanel.addClass("flip-container flip-notanimating").append(this._outputContainer);
this._hsplitter.rightPanel.append(this._codeContainer);
break;
case Layout.Bottom:
this._vsplitter = new WebWidgets.VerticalSplitter({ appendTo: this._contentFrame, isRoot: false, initialSizePercent: 100 - 100 * this._state.vSplit });
this.modifyOutputSplitter(this._vsplitter);
this._vsplitter.topPanel.addClass("flip-container flip-notanimating").append(this._outputContainer);
this._vsplitter.bottomPanel.append(this._codeContainer);
break;
}
if (Util.isForScreenshot())
(this._state.showDebug ? this._jqObj : this._jqConsole).css('display', 'none');
else
this.set_flip("div#{0} .flip-1".format(this.id()), this._state.showDebug);
}
};
RItemGui.prototype.set_flip = function (clss, flipToBack) {
$(clss).addClass("notransition");
if (flipToBack)
$(clss).addClass("flipped");
else
$(clss).removeClass("flipped");
setDisplayrTimeoutOptions(setTimeout(function () { $(clss).removeClass("notransition"); }, 600), { fnHash: 'removing R Gui transition' });
};
RItemGui.prototype.resetPreviewer = function () {
if (App.ui.previewer)
App.ui.previewer.hide();
};
RItemGui.prototype.resetNotificationBar = function () {
if (this._editMode) {
this._notificationBar.clearMustChooseOutputType();
this._notificationBar.clearError();
this._notificationBar.clearWarnings();
}
};
RItemGui.prototype.enterRItemForEditMode = function (guid) {
this.enterRItem(guid);
this._editMode = true;
this.guiControlsReadyForTraining = false;
this._firstPreCalcStuff = true;
this.getPreCalcStuff();
};
RItemGui.prototype.enterRItem = function (guid) {
var _this = this;
this.resetPreviewer();
this.guids[0] = guid;
if (!Application.isForDataset()) {
if (this.subscribe('GetRControls', function (response) {
if (App.isSoleSelection(guid))
_this.gotRControls(response);
}))
this.guiControlsReadyForTraining = true;
}
};
RItemGui.prototype.leaveRItem = function (refresh_r_item, reason) {
this.unsubscribe('GetRControls');
this.unsubscribe('GetREditPreCalcStuff');
this.unsubscribe('GetREditPostCalcStuff');
if (this._state)
this._state.guiControls = undefined; // reset so that next time we are entered, we know we do not have controls
this._editMode = false; // defensive coding; just in case someone has reference to the RItemGui or change events fire, we want to ignore state changes
this.guiControlsReadyForTraining = true; // if the item is unselected before it completes entering edit mode, this needs to be reset
clearTimeout(this._state.autosaveTimer);
clearTimeout(this._state.highlightingTimer);
clearTimeout(this._updateClickedTimer);
if (refresh_r_item && this.getItemGuids().length === 1) {
QServerRequestsCommon.RItemLeaveEditMode({ GUID: this.getItemGuids()[0], Code: null });
}
};
/** Called before the reference to this RItemGui is thrown away and never used again.
* This is different from leaveRItem(), because in that case the RItemGui is re-used
* and enterRItem() may be called again.
* Here we throw away event handlers to avoid duplicate events (like the code editor change event)
* triggering server actions (like RItemRehighlightCode). */
RItemGui.prototype.detach = function () {
if (this._editMode) {
this.unsubscribe('GetRControls');
this.unsubscribe('GetREditPreCalcStuff');
this.unsubscribe('GetREditPostCalcStuff');
}
clearTimeout(this._state.autosaveTimer);
clearTimeout(this._state.highlightingTimer);
};
RItemGui.prototype.getItemGuids = function () {
return this.guids;
};
RItemGui.prototype.subscribe = function (name, callback) {
var request = this.subscriptionRequest(name);
if (!Subscription.isSubscribed(request)) {
Subscription.subscribe(request, callback);
return true;
}
return false;
};
RItemGui.prototype.unsubscribe = function (name) {
var request = this.subscriptionRequest(name);
if (Subscription.isSubscribed(request))
Subscription.unsubscribe(request);
};
RItemGui.prototype.subscriptionRequest = function (name) {
var guid = this.guids[0] ? this.guids[0] : "no-guid";
return { Request: name, GUID: guid };
};
RItemGui.prototype.hasPreCalcStuff = function () {
return !!this._firstPreCalcStuff;
};
RItemGui.prototype._applyCalculating = function (calculating) {
if (this._jqQueued) {
this._jqQueued.toggle(calculating === 'Queued');
this._jqCalculating.toggle(calculating === 'Calculating');
if (App.ui.inspector) {
App.ui.inspector.inspector.element
.toggleClass('item-calculating', calculating === 'Calculating')
.toggleClass('item-queued', calculating === 'Queued');
}
}
};
RItemGui.prototype.isFullyLoaded = function () {
return !this._waitingForPreCalcStuff && !this._waitingForPostCalcStuff && this._state && !!this._state.guiControls && !this._waitingForRControls;
};
RItemGui.prototype.getPreCalcStuff = function () {
var _this = this;
this._waitingForPreCalcStuff = true;
$("#no-warnings").html("please wait");
var handle_precalcstuff = function (response) {
if (!_this._editMode)
return;
_this._applyCalculating(response.Calculating);
var code = _this._firstPreCalcStuff ? response.Code : null;
if (response.Code)
_this._state.lastSavedCode = response.Code;
_this._state.highlightedCodeSpans = response.Highlights.Highlights;
_this.setLastUpdatedText(Translate("calculating..."));
_this.setOptions(response.Options);
_this._waitingForPreCalcStuff = false;
$("#no-warnings").html("No suggestions");
if (!_this._firstPreCalcStuff)
return;
_this._firstPreCalcStuff = false;
if (Util.isDesktop())
QServerRequestsCommon.RItemAutoUpdate({ GUIDs: [_this.guids[0]] }, function () {
return _this.requestAndDisplayOutput();
});
else
_this.requestAndDisplayOutput();
};
if (Application.isForDataset())
QServerRequestsCommon.GetREditPreCalcStuff({ GUID: this.guids[0] }, handle_precalcstuff);
else
this.subscribe('GetREditPreCalcStuff', handle_precalcstuff);
};
RItemGui.prototype.requestAndDisplayOutput = function () {
var _this = this;
var got_postcalcstuff = function (response) {
_this._waitingForPostCalcStuff = false;
if (!_this._editMode)
return;
_this.setOutputs(response.Outputs);
if (App.isDesktopDialog)
for (var _i = 0, _a = response.StaticErrorsAndWarnings.filter(function (e) { return e.IsStatic && !e.WarningOnly; }); _i < _a.length; _i++) {
var error = _a[_i];
_this._notificationBar.setError("ERROR: " + error.Message).hideCloseButton();
}
if (response.ExecutedCode !== null)
_this.showExecutedCodeInOutput(response.ExecutedCode);
if (App.isSoleSelection(_this.guids[0]))
App.ui.inspector.update("RItemGui:got_postcalcstuff");
setDisplayrTimeoutOptions(setTimeout(function () { _this.guiControlsReadyForTraining = true; }, 100), { fnHash: 'gui controls ready for training' });
};
this._waitingForPostCalcStuff = true;
if (Application.isForDataset())
QServerRequestsCommon.GetREditPostCalcStuff({ GUID: this.guids[0] }, got_postcalcstuff);
else {
this.unsubscribe('GetREditPostCalcStuff');
this.subscribe('GetREditPostCalcStuff', got_postcalcstuff);
}
};
RItemGui.prototype.replaceOutputWithItemRender = function (state) {
this._state = state;
};
RItemGui.prototype.showExecutedCodeInOutput = function (code, force_change) {
if (force_change === void 0) { force_change = false; }
for (var _i = 0, _a = RibbonCodeEditor.getEditorsFor(this.guids[0]).filter(function (e) { return e.name === "inplace"; }); _i < _a.length; _i++) {
var an_editor = _a[_i];
an_editor.text(code);
}
};
RItemGui.prototype.highlightSpans = function () {
var spans = this._state.highlightedCodeSpans;
for (var _i = 0, _a = RibbonCodeEditor.getEditorsFor(this.guids[0]).filter(function (editor) { return editor.name === "inplace" || editor.name === "propertyRCode"; }); _i < _a.length; _i++) {
var editor = _a[_i];
editor.highlightSpans(spans);
}
};
RItemGui.prototype.gotRControls = function (response) {
var _this = this;
this._waitingForRControls = false;
this._state.guiControls = response;
setTimeout(function () {
_this.guiControlsReadyForTraining = true;
}, 100);
if (App.isSoleSelection(this.guids[0]) && this._editMode)
App.ui.inspector.update("RItemGui:GotRControls (none)");
};
RItemGui.prototype.setRGuiControlValue = function (input, control) {
var _this = this;
var name = input.ControlName;
switch (input.Type) {
case "CheckBox":
{
var chkbox = control;
this.setValueForRControl(name, chkbox.checked() ? "true" : "false");
chkbox.checked(input.Value);
break;
}
case "DropBox":
{
var dropbox = control;
var multi = dropbox.multi();
var value = multi ? dropbox.values().join(";") : dropbox.value() ? dropbox.value() : null;
this.StateChanged("GetRControls", multi ? "SetGuidsForRControl" : "SetGuidForRControl", name, value, function (r) { return _this.gotRControls(r); });
break;
}
case "ComboBox":
case "StatisticPicker":
{
var cbobox = control;
this.setValueForRControl(name, cbobox.value());
break;
}
case "NumberBox":
case "TextBox": {
var txtbox = control;
this.setValueForRControl(name, txtbox.text());
break;
}
case "NumericUpDown":
{
var updown = control;
this.setValueForRControl(name, updown.value().toString());
break;
}
case "ColorPicker": {
var color = control;
this.setValueForRControl(name, RItemGui.rgbAsString(color));
break;
}
case "DataEntry":
{
var de = control;
this.setValueForRControl(name, JSON.parse(de.value()));
break;
}
}
};
RItemGui.prototype.setValueForRControl = function (name, value) {
var _this = this;
this.StateChanged("GetRControls", "SetValueForRControl", name, value, function (response) {
_this.gotRControls(response);
});
};
RItemGui.prototype.commitTextBoxes = function () {
if (this._committables)
for (var _i = 0, _a = this._committables; _i < _a.length; _i++) {
var textbox = _a[_i];
if (instanceOf(textbox, SCTextBox))
textbox.onEditCommit(false, "committing gui input controls");
else if (instanceOf(textbox, RibbonUpDown))
textbox.onEditCommit(0, false, "committing gui input controls");
else
throw new Error("Unknown committable type: " + textbox.constructor.name);
}
};
RItemGui.rgbAsString = function (control) {
var color = control.value();
if (!color)
return null; // ScriptColorPicker understands null as transparent
var rgb = RibbonPopupColor.strToColor(color); // "rgb(r, g, b)"
return rgb.replace('rgb(', '').replace('rgba(', '').replace(')', ''); // ScriptColorPicker expects "r, g, b"
};
RItemGui.prototype.StateChanged = function (get_request, set_request, set_name, set_value, get_success, set_success) {
var guids = this.getItemGuids();
if (guids.length > 1)
throw new Error("This is a single-item selected operation only.");
var guid = guids[0];
if (!guid)
throw new Error("no selected guid");
var request = {
Request: set_request,
Guid: guid,
Name: set_name,
Value: set_value
};
if (set_name === "Code")
$.extend(request, { Code: set_value });
if (Util.hashParams()['for_dataset'] === "true") {
Util.qServerRequest(request, set_success);
Util.qServerRequest({
Request: get_request,
GUID: guid
}, function (response) { return get_success(response); });
return;
}
this._hasChangedState = true;
if (Util.isDesktop() || Environment.isEditor) {
this._waitingForRControls = true;
Util.qServerRequest(request, function (response) {
if (set_success)
set_success(response);
});
this.committedCurrentValue();
return;
}
throw new Error("Interesting. Why are we changing state in view mode dashboards?");
};
RItemGui.prototype.committedCurrentValue = function () {
this._lastSequenceSent = QServer.getLastSeqSent();
};
RItemGui.prototype.setDebugVisibility = function (visible, originated_in_checkbox) {
if (this._state.showDebug === visible)
return;
this._state.showDebug = visible;
if (originated_in_checkbox) {
this.do_flip("div#{0} .flip-1".format(this.id()), visible);
this.changeOption("debugconsole", visible, originated_in_checkbox);
}
else {
this.set_flip("div#{0} .flip-1".format(this.id()), visible);
}
};
RItemGui.prototype.do_flip = function (clss, flipToBack) {
var _this = this;
var id = this.id();
$('div#{0} #resizable-box > .splitPanel'.format(id)).css("overflow", "visible");
var other = (this._state.oldLayout === Layout.Top) === clss.endsWith(".flip-0") ? "bottom" : "top";
$('div#{0} #resizable-box .splitPanel-{1}'.format(id, other)).css("z-index", "-1");
$('div#{0} #resizable-box .ui-icon-gripsmall-diagonal-se'.format(id)).css('visibility', "hidden");
var fc = $(clss).closest('.flip-container');
fc.addClass('flip-animating');
setTimeout(function () {
fc.addClass('flip-transition');
if (flipToBack)
$(clss).addClass("flipped");
else
$(clss).removeClass("flipped");
setTimeout(function () {
fc.removeClass('flip-transition');
fc.removeClass('flip-animating');
$('div#{0} #resizable-box .splitPanel-{1}'.format(id, other)).css("z-index", "0");
$('div#{0} #resizable-box > .splitPanel'.format(id)).css("overflow", "hidden");
if (!flipToBack && _this.rItemCodeEditor)
_this.rItemCodeEditor.mayHaveResized("flipping");
$('div#{0} #resizable-box .ui-icon-gripsmall-diagonal-se'.format(id)).css('visibility', "visible");
}, 600);
}, 0);
};
RItemGui.prototype.showDependencies = function (svg, width) {
this.clear();
var elt = $('
');
this.addElement(elt);
elt.append($('')
.addClass("ritem-image")
.css("width", 4 * width + "px")
.css("background", "url(data:image/svg+xml;base64,{0})".format(svg)));
};
RItemGui.prototype.showPreview = function (html, is_man_page) {
};
RItemGui.prototype.setLastUpdatedText = function (message) {
this.lastUpdatedMessageMaintainer.setTextAndTooltip(message);
};
RItemGui.prototype.doneDisplaying = function () {
var _this = this;
var timeout_id = setTimeout(function () {
_this.guiControlsReadyForTraining = true;
_this.outputReadyForTraining = true;
if (App.ui.inspector)
App.ui.inspector.update("ready for training");
}, 100);
setDisplayrTimeoutOptions(timeout_id, { fnHash: 'REALLY ready for training' });
};
RItemGui.prototype.getPendingOperations = function () {
var pending = new PendingOperations();
if (!this.guiControlsReadyForTraining) {
pending.add('RItemGui', '', '!guiControlsReadyForTraining');
return pending;
}
if (!this.outputReadyForTraining) {
pending.add('RItemGui', '', '!outputReadyForTraining');
return pending;
}
if (this._jqCalculating.is(':visible')) {
pending.add('RItemGui', '', 'calculating');
return pending;
}
if (this._jqQueued.is(':visible')) {
pending.add('RItemGui', '', 'queued for calculation');
return pending;
}
if (this._state.outputType === OutputType.WIDGET) {
pending.addRange(this._htmlWidgetContainer.getPendingOperations());
return pending;
}
return pending;
};
RItemGui.prototype.getState = function () {
return this._state;
};
RItemGui.prototype.getCodeEditors = function () {
return RibbonCodeEditor.getEditorsFor(this.guids[0]);
};
RItemGui.prototype.hasChangedState = function () {
return this._hasChangedState;
};
RItemGui._nextPlotId = 0;
return RItemGui;
}());
/**
* Allows us to get notfications before ribbon controls change, so that
* we can commit any outstanding text editors (who won't get an onblur
* in time).
*/
var RItemRibbonForControls = /** @class */ (function () {
function RItemRibbonForControls(gui) {
var _this = this;
this.onBeforeChange = new EventSource();
this.onChanged = new EventSource();
this._gui = gui;
this.onBeforeChange.add(function (ctl) {
if (!(ctl instanceof RibbonTextBox) && !(ctl instanceof RibbonUpDown))
_this._gui.commitTextBoxes();
});
}
RItemRibbonForControls.prototype.addToCtlMap = function (ctl) {
};
RItemRibbonForControls.prototype.hideRibbon = function () {
};
return RItemRibbonForControls;
}());
;
// /Scripts/Dashboard/RItem/RItemMultiGui.ts
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var RItemMultiGui = /** @class */ (function (_super) {
__extends(RItemMultiGui, _super);
function RItemMultiGui(guids, centre, state, notification_bar) {
var _this = _super.call(this, guids, centre, state, notification_bar, false) || this;
_this._guids = [];
return _this;
}
RItemMultiGui.prototype.setupBody = function () {
};
RItemMultiGui.prototype.setupLeftSide = function (leftPanel) {
leftPanel.empty();
var contentFrame = $('
')
.addClass("cant-resize");
var div = $('
'.format(this.id())).append(contentFrame);
leftPanel.append(div);
this._jqObj = $('
');
contentFrame.append(this._jqObj);
};
RItemMultiGui.prototype.updateInspectorSize = function () {
};
RItemMultiGui.prototype.resizeOutput = function () {
};
RItemMultiGui.prototype.setAvailableOutputTypes = function (list, choice, enabled) {
};
RItemMultiGui.prototype.changeLayout = function (layout) {
this._state.oldLayout = layout;
};
RItemMultiGui.prototype.refreshMultipleRItems = function (guids, summary, options, zoom) {
this._editMode = true;
this.setupLeftSide(this._jqCenter);
this.clear();
this._guids = guids;
this.setZoom(zoom);
this.displayMultipleItems(summary);
this.setLastUpdatedText("");
};
RItemMultiGui.prototype.displayMultipleItems = function (items) {
var _this = this;
this.multiple = true;
this.clear();
this.showNoCode();
this._jqObj.removeClass("red");
var div = $('
')
.addClass('multi-item')
.text(Translate("Multiple R items have been selected."))
.append($('
')) .append($('
')); var table = $('
')) .append($('
')); var table = $('