Skip to content

Commit

Permalink
ControlExtensions cache dataitem reference
Browse files Browse the repository at this point in the history
  • Loading branch information
rajsite committed Feb 6, 2022
1 parent 69ecd42 commit e802f3d
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 39 deletions.
13 changes: 10 additions & 3 deletions ControlExtensions/ControlExtensions.gcomp/ControlExtensions.gcomp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<SourceFile Checksum="1812DD6FC374F1566C87E389B2429A4781C63F57FDDE0EE8AF314636B894F3C0658BC3360005BFC395A0302306FCBAF92C6827FDD0B36CC3A7402100EE669509" Timestamp="1D810EB54098307" xmlns="http://www.ni.com/PlatformFramework">
<SourceFile Checksum="9B8E83C533CDA331CB367B07AD87B3262B0299BD9905D496A7BB18C494891113663AB53B4BC07985FFA8F51372A1162DDCC6C1FD155C5FD08B2DBE8DDE98D7A2" Timestamp="1D81BAB8044BA15" xmlns="http://www.ni.com/PlatformFramework">
<SourceModelFeatureSet>
<ParsableNamespace AssemblyFileVersion="9.1.0.50238" FeatureSetName="GComponentFeatureSet" Name="http://www.ni.com/GComponent.xsd" OldestCompatibleVersion="9.0.0.0" Version="9.0.0.49152" />
<ParsableNamespace AssemblyFileVersion="9.1.0.50238" FeatureSetName="JavaScript Library" Name="http://www.ni.com/JavaScriptLibrary" OldestCompatibleVersion="6.4.0.49152" Version="6.4.0.49152" />
Expand All @@ -9,7 +9,15 @@
<ComponentDefinition DefaultConfigurationName="Configuration1" Id="ff4afffde9164b77b6f7a16980894ac2" RootNamespaceId="4072e95289a64408bdf084daa61499d7" xmlns="http://www.ni.com/GComponent.xsd">
<Icon Id="1662d89a18404c96bd62ff103598eed7" ListViewIconCrop="0 0 40 40" xmlns="http://www.ni.com/PlatformFramework">
<IconPanel Height="[float]40" Id="c74c6c5796c64edb90ada8881ff6e812" Left="[float]0" PanelSizeMode="Resize" Top="[float]0" Width="[float]40">
<IconTemplate Height="[float]40" Id="1512e338d4d54ed98c72534a7f4c9ace" Left="[float]0" TemplateName="[string]Blank" Top="[float]0" Width="[float]40" />
<IconTemplate ClipMargin="[SMThickness]3,3,3,3" Height="[float]40" HorizontalAlignment="[HorizontalAlignment]Stretch" Id="a52fe506c2d843e98968a84f1fc1ff43" Left="[float]0" TemplateName="[string]Banner" Top="[float]0" VerticalAlignment="[VerticalAlignment]Stretch" Width="[float]40">
<Path Data="[PathGeometry]M 0,11 L 0,2 C 0,0.899999976 0.899999976,0 2,0 L 2,11 L 0,11 Z" Fill="[SMSolidColorBrush]#ffa35a13" Height="[float]11" HorizontalAlignment="[HorizontalAlignment]Left" Id="a34551bf284941d8b5e272f96d0c0d04" IsHitTestVisible="[bool]False" Left="[float]0" Margin="[SMThickness]2,2,2,2" MinHeight="[float]1" MinWidth="[float]1" Top="[float]0" VerticalAlignment="[VerticalAlignment]Top" Width="[float]2" />
<Rectangle Fill="[SMSolidColorBrush]#ffa35a13" Height="[float]11" Id="39628edb376043a4a12cca591381a48c" IsHitTestVisible="[bool]False" Left="[float]0" Margin="[SMThickness]4,2,4,2" MinHeight="[float]1" MinWidth="[float]1" Top="[float]0" VerticalAlignment="[VerticalAlignment]Top" Width="[float]NaN" />
<Path Data="[PathGeometry]M 2,11 L 2,2 C 2,0.899999976 1.10000002,0 0,0 L 0,11 L 2,11 Z" Fill="[SMSolidColorBrush]#ffa35a13" Height="[float]11" HorizontalAlignment="[HorizontalAlignment]Right" Id="941904fd3a7549b283a207804020067c" IsHitTestVisible="[bool]False" Left="[float]0" Margin="[SMThickness]2,2,2,2" MinHeight="[float]1" MinWidth="[float]1" Top="[float]0" VerticalAlignment="[VerticalAlignment]Top" Width="[float]2" />
</IconTemplate>
<Text Foreground="[SMColor]#ffffffff" Height="[float]11" Id="9b21998ccb94db486366937220b1efc" Left="[float]3" SizeMode="[TextModelSizeMode]Fixed" Text="[string]Control" TextAlignment="[TextAlignment]Left" TextWrapping="[TextWrapping]Wrap" Top="[float]2" VerticalScrollBarVisibility="[ScrollBarVisibility]Hidden" Width="[float]35">
<FontSetting FontFamily="Segoe UI" FontSize="6" Id="1361b0f7b41d415290580c80be773bb8" />
</Text>
<Image BaseName="[string]Image" Height="[float]22" Id="e530e2f06c04d9586fcb770a8684d0d" Left="[float]23" Source="[EmbeddedDrawingImage]&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#xA;&lt;svg&#xA; height=&quot;24px&quot;&#xA; viewBox=&quot;0 0 24 24&quot;&#xA; width=&quot;24px&quot;&#xA; fill=&quot;#FFFFFF&quot;&#xA; version=&quot;1.1&quot;&#xA; id=&quot;svg6&quot;&#xA; sodipodi:docname=&quot;extension_white_24dp.svg&quot;&#xA; inkscape:version=&quot;1.1 (c68e22c387, 2021-05-23)&quot;&#xA; xmlns:inkscape=&quot;http://www.inkscape.org/namespaces/inkscape&quot;&#xA; xmlns:sodipodi=&quot;http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd&quot;&#xA; xmlns=&quot;http://www.w3.org/2000/svg&quot;&#xA; xmlns:svg=&quot;http://www.w3.org/2000/svg&quot;&gt;&#xA; &lt;defs&#xA; id=&quot;defs10&quot; /&gt;&#xA; &lt;sodipodi:namedview&#xA; id=&quot;namedview8&quot;&#xA; pagecolor=&quot;#ffffff&quot;&#xA; bordercolor=&quot;#666666&quot;&#xA; borderopacity=&quot;1.0&quot;&#xA; inkscape:pageshadow=&quot;2&quot;&#xA; inkscape:pageopacity=&quot;0.0&quot;&#xA; inkscape:pagecheckerboard=&quot;true&quot;&#xA; showgrid=&quot;false&quot;&#xA; inkscape:zoom=&quot;33.791667&quot;&#xA; inkscape:cx=&quot;8.567201&quot;&#xA; inkscape:cy=&quot;11.156597&quot;&#xA; inkscape:window-width=&quot;1920&quot;&#xA; inkscape:window-height=&quot;996&quot;&#xA; inkscape:window-x=&quot;-8&quot;&#xA; inkscape:window-y=&quot;-8&quot;&#xA; inkscape:window-maximized=&quot;1&quot;&#xA; inkscape:current-layer=&quot;svg6&quot; /&gt;&#xA; &lt;path&#xA; d=&quot;M 0,0 H 30 V 30 H 0 Z&quot;&#xA; fill=&quot;none&quot;&#xA; id=&quot;path2&quot;&#xA; style=&quot;stroke-width:1.25&quot; /&gt;&#xA; &lt;path&#xA; d=&quot;M 11.285714,8.857144 H 10.857143 V 7.714286 C 10.857143,7.399999 10.6,7.142857 10.285714,7.142857 H 9.142856 V 6.714286 C 9.142856,6.319999 8.822857,6 8.428571,6 8.034286,6 7.714286,6.319999 7.714286,6.714286 V 7.142857 H 6.571429 c -0.314287,0 -0.568573,0.257142 -0.568573,0.571429 V 8.8 H 6.42857 c 0.425716,0 0.771429,0.345715 0.771429,0.771429 0,0.425713 -0.345713,0.771429 -0.771429,0.771429 H 6 v 1.085713 C 6,11.742857 6.257142,12 6.571429,12 h 1.085713 v -0.428572 c 0,-0.425714 0.345716,-0.771429 0.771429,-0.771429 0.425714,0 0.771429,0.345715 0.771429,0.771429 V 12 h 1.085714 C 10.6,12 10.857143,11.742857 10.857143,11.428571 v -1.142857 h 0.428571 C 11.680001,10.285714 12,9.965714 12,9.571429 12,9.177143 11.680001,8.857144 11.285714,8.857144 Z&quot;&#xA; id=&quot;path4&quot;&#xA; style=&quot;stroke-width:0.285715&quot; /&gt;&#xA; &lt;rect&#xA; style=&quot;opacity:0;fill:#0000ff;fill-rule:evenodd;stroke-width:1.47807&quot;&#xA; id=&quot;rect335&quot;&#xA; width=&quot;18.75&quot;&#xA; height=&quot;18.75&quot;&#xA; x=&quot;0&quot;&#xA; y=&quot;0&quot; /&gt;&#xA;&lt;/svg&gt;&#xA;" Stretch="[SMStretch]Uniform" Top="[float]-3" Width="[float]22" />
</IconPanel>
</Icon>
<CompilerSymbolTable Id="bf68540af73e4dedb2a68b647d2a5430" xmlns="http://www.ni.com/PlatformFramework" />
Expand All @@ -18,7 +26,6 @@
<GLibraryProperties Id="38902c40f45448619c0731b2a0c34776" />
<ComponentItemProperties AlwaysInclude="True" AssociatedEnvoyId="d53aefc799d54c8c8f6fed525bf4eb03" Id="413bb64a99e54fc695d4b4b5a1cf96a4" />
<ComponentItemProperties AssociatedEnvoyId="fff5c37face74d2da1b733564457aebd" Exported="True" Id="a847c037b17c4befa29a34d451ae2a67" />
<ComponentItemProperties AssociatedEnvoyId="6fab65d1d78c42528c7035b569fe4c97" Exported="True" Id="80244dd879e940bbb95ca6f605e82ff7" />
</ComponentConfiguration>
</ComponentDefinition>
<EnvoyManagerFile Id="8fcaac3fb1a144e3919e1a53dddeeb1a" xmlns="http://www.ni.com/PlatformFramework">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
(function () {
'use strict';

const obtainJavaScriptReferenceGObject = function () {
// Find web application
const webAppElements = document.querySelectorAll('ni-web-application');
if (webAppElements.length !== 1) {
throw new Error('Expected a single ni-web-application element in page.');
class DataItem {
constructor (viName, dataItemPath) {
this._viName = viName;
this._dataItemPath = dataItemPath;
this._vireo = undefined;
this._vireoHelpers = undefined;
this._valueRef = undefined;
}
const [webAppElement] = webAppElements;

const isSupported = webAppElement && webAppElement.vireoInstance && webAppElement.vireoHelpers;
if (!isSupported) {
throw new Error('ControlExtensions not supported in this version of G Web Development Software.');
getValueRef () {
if (this._valueRef === undefined) {
// Find web application
const webAppElements = document.querySelectorAll('ni-web-application');
if (webAppElements.length !== 1) {
throw new Error('Expected a single ni-web-application element in page.');
}
const [webAppElement] = webAppElements;

const isSupported = webAppElement && webAppElement.vireoInstance && webAppElement.vireoHelpers;
if (!isSupported) {
throw new Error('Not supported in this version of G Web Development Software.');
}

// Find vireo instance
const vireo = webAppElement.vireoInstance;
const vireoHelpers = webAppElement.vireoHelpers;

// Read value from dataspace
const viNameEncoded = vireoHelpers.staticHelpers.encodeIdentifier(this._viName);
const valueRef = vireo.eggShell.findValueRef(viNameEncoded, this._dataItemPath);
this._vireo = vireo;
this._vireoHelpers = vireoHelpers;
this._valueRef = valueRef;
}
return this._valueRef;
}
}

// Find vireo instance
const vireo = webAppElement.vireoInstance;
const vireoHelpers = webAppElement.vireoHelpers;
class ReferenceDataItem extends DataItem {
getValue () {
const valueRef = this.getValueRef();
return this._vireo.eggShell.readJavaScriptRefNum(valueRef);
}
}

const obtainJavaScriptReferenceGObjectDataItem = new ReferenceDataItem('ControlExtensions::Support::Obtain JavaScript Reference - GObject.gvi', 'dataItem_Referenceprobe');

// Read value from dataspace
const viName = 'ControlExtensions::Support::Obtain JavaScript Reference - GObject.gvi';
const viNameEncoded = vireoHelpers.staticHelpers.encodeIdentifier(viName);
const valueRef = vireo.eggShell.findValueRef(viNameEncoded, 'dataItem_Referenceprobe');
const value = vireo.eggShell.readJavaScriptRefNum(valueRef);
const obtainJavaScriptReferenceGObject = function () {
const value = obtainJavaScriptReferenceGObjectDataItem.getValue();
if ((value && value.element instanceof HTMLElement) === false) {
throw new Error('Expected reference to be an HTML control');
}
Expand Down
Loading

0 comments on commit e802f3d

Please sign in to comment.