Skip to content

Commit f13ac97

Browse files
authored
Merge pull request #44 from jdunkerley/htmlRegEx
Html reg ex
2 parents 3ab3d2c + 1ef99c2 commit f13ac97

File tree

11 files changed

+10095
-0
lines changed

11 files changed

+10095
-0
lines changed

OmnibusRegex/Install.ps1

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
$ErrorActionPreference = "Stop"
2+
3+
$root = Split-Path -Parent $PSCommandPath
4+
Push-Location $root
5+
6+
gci . | Unblock-File
7+
8+
Write-Host "Finding Alteryx Admin Install Location..."
9+
$reg = Get-ItemProperty HKLM:\SOFTWARE\WOW6432Node\SRC\Alteryx -ErrorAction SilentlyContinue
10+
if ($reg -ne $null) {
11+
$bin = $reg.InstallDir64 + '\HtmlPlugins\OmnibusRegex'
12+
$cmd = "/c mklink /J ""$bin"" ""$root"""
13+
Start-Process cmd -ArgumentList $cmd -verb RunAs -wait
14+
}
15+
16+
Write-Host "Finding Alteryx User Install Location..."
17+
$reg = Get-ItemProperty HKCU:\SOFTWARE\SRC\Alteryx -ErrorAction SilentlyContinue
18+
if ($reg -ne $null) {
19+
$bin = $reg.InstallDir64 + '\HtmlPlugins\OmnibusRegex'
20+
New-Item -Path $bin -ItemType SymbolicLink -Value $root
21+
}
22+
23+
Pop-Location

OmnibusRegex/OmnibusHTMLHelper.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
window.PlugInHelper = (() => { return { Create: (alteryx, manager, window) => {
2+
const metaInfo = manager.metaInfo
3+
const formulaConstants = []
4+
5+
const jsEvent = (obj) => alteryx.JsEvent(JSON.stringify(obj))
6+
const openHelpPage = (url) => jsEvent({Event: 'OpenHelpPage', url})
7+
8+
let callbackId = 0;
9+
function makeCallback(callback) {
10+
const callbackName = `callback${callbackId++}`
11+
12+
window[callbackName] = (o) => {
13+
delete window[callbackName]
14+
callback(o)
15+
}
16+
17+
return callbackName
18+
}
19+
20+
// Get Formula Constants
21+
let formulaConstantsCallback = () => {}
22+
jsEvent({Event: 'GetFormulaConstants', callback: makeCallback((obj) => {
23+
formulaConstants.push(...obj.formulaConstants.map((c) => { return { name: c.FullName, isNumeric: c.IsNumeric, value: c.Value } }))
24+
formulaConstants.push(...obj.questionConstants.map((c) => { return { name: c.FullName, isNumeric: c.IsNumeric, value: c.Value } }))
25+
formulaConstantsCallback()
26+
})})
27+
28+
// Get Connections
29+
const connectionNames = Array(metaInfo.Count).fill().map((_, i) => metaInfo.Get(i).ConnectionName)
30+
const connections = {}
31+
connectionNames.forEach((n, i) => {
32+
const fields = metaInfo.Get(i)._GetFields().map((f, j) => { return { name: f.strName, type: f.strType, size: f.nSize, scale: f.nScale, description: f.strDescription, index: j } })
33+
connections[n] = fields
34+
})
35+
36+
// Read Input Data
37+
function getInputData(connection, rows, callback) {
38+
jsEvent({
39+
Event: 'GetInputData',
40+
callback: makeCallback(callback),
41+
anchorIndex: 0,
42+
connectionName: connection,
43+
numRecs: rows,
44+
offset: 0})
45+
}
46+
47+
function getInputDataArray(connection, rows, callback) {
48+
const newCallback = (o) => {
49+
const newObj = o.data ? o.data.map((d) => {
50+
const output = {}
51+
d.forEach((v, i) => output[o.fields[i].strName] = v)
52+
return output
53+
}) : {}
54+
callback(newObj)
55+
}
56+
getInputData(connection, rows, newCallback)
57+
}
58+
59+
// Test Expression
60+
function testExpression(expression, callback) {
61+
jsEvent({
62+
Event: 'TestExpression',
63+
callback: makeCallback(callback),
64+
expression,
65+
customFields: []
66+
})
67+
}
68+
69+
// Formula Preview
70+
function formulaPreview(connection, name, type, expression, callback) {
71+
const previewObject = [{name, type, expression}]
72+
73+
jsEvent({
74+
      Event'FormulaPreview',
75+
      connectionNameconnection,
76+
      anchorIndex0,
77+
      callbackmakeCallback(callback),
78+
      expressionspreviewObject
79+
    })
80+
81+
}
82+
83+
return {
84+
jsEvent,
85+
openHelpPage,
86+
formulaConstants,
87+
connectionNames,
88+
connections,
89+
getInputData,
90+
getInputDataArray,
91+
setFormulaConstantsCallback: (callback) => formulaConstantsCallback = callback,
92+
testExpression,
93+
formulaPreview
94+
}
95+
} } })()

OmnibusRegex/OmnibusRegEx.html

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>James HTML Play</title>
6+
7+
<script type="text/javascript">
8+
document.write(`<link rel="stylesheet" type="text/css" href="${window.Alteryx.LibDir}1/css/alteryx-config.css">`)
9+
document.write(`<link rel="stylesheet" type="text/css" href="${window.Alteryx.LibDir}1/lib/alteryx/gui/plugin-widgets/alteryx-desktop-widgets.css">`)
10+
document.write(`<link rel="stylesheet" type="text/css" href="${window.Alteryx.LibDir}1/lib/build/designerDesktop.css">`)
11+
document.write(`<script src="${window.Alteryx.LibDir}1/lib/build/designerDesktop.bundle.js">\x3c/script>`)
12+
</script>
13+
<script src="codemirror.js"></script>
14+
<script src="codemirror-regex.js"></script>
15+
<link rel="stylesheet" href="codemirror.css">
16+
<link rel="stylesheet" href="codemirror-regex.css">
17+
</head>
18+
<body>
19+
<form>
20+
<fieldset>
21+
<legend class='blueTitle'>Output Method</legend>
22+
<div>
23+
<label for="regexType">Mode</label>
24+
<alteryx-pluginwidget type="DropDown" id="method" dataName="Method"></alteryx-pluginwidget>
25+
</div>
26+
</fieldset>
27+
<fieldset>
28+
<legend class='blueTitle'>Input Field</legend>
29+
<div>
30+
<label for="fieldSelector">Name</label>
31+
<alteryx-pluginwidget type="DropDown" dataType="FieldSelector" id="fieldSelector" dataName="Field" connectionNumber="0" inputNumber="0" fieldType="StringOrDate"></alteryx-pluginwidget>
32+
</div>
33+
<div>
34+
<alteryx-pluginwidget type="CheckBox" id="showPreview" showAsToggle="true" text="Show Preview" dataName="showPreview"></alteryx-pluginwidget>
35+
<pre id="preview" style="background-color: #f7f7f7">&nbsp;</pre>
36+
</div>
37+
</fieldset>
38+
<fieldset>
39+
<legend class='blueTitle'>Regular Expression</legend>
40+
<div>
41+
<!--DataName RegExExpression-->
42+
<label for="regularExpression">Expression</label>
43+
<textarea id="regularExpression" style="height: 1.5em"></textarea>
44+
</div>
45+
<div>
46+
<alteryx-pluginwidget type="CheckBox" id="caseInsensitive" dataName="CaseInsensitive" showAsToggle="true" text="Case Insensitive"></alteryx-pluginwidget>
47+
</div>
48+
<div id="previewRegex">
49+
<label for="previewResult">Preview</label>
50+
<pre id="previewResult" style="background-color: #f7f7f7">&nbsp;</pre>
51+
</div>
52+
</fieldset>
53+
<fieldset id="MatchFieldSet">
54+
<legend class='blueTitle'>Match Field</legend>
55+
<div>
56+
<label for="matchField">Name</label>
57+
<alteryx-pluginwidget type="TextBox" id="matchField" dataName="MatchField"></alteryx-pluginwidget>
58+
</div>
59+
<div>
60+
<alteryx-pluginwidget type="CheckBox" id="errorUnmatched" dataName="ErrorUnmatched" showAsToggle="true" text="Error if not matched"></alteryx-pluginwidget>
61+
</div>
62+
</fieldset>
63+
<fieldset id="ReplaceFieldSet">
64+
<legend class='blueTitle'>Replace</legend>
65+
<div>
66+
<label for="replaceExpression">Expression</label>
67+
<alteryx-pluginwidget type="TextBox" id="replaceExpression" dataName="ReplaceExpression"></alteryx-pluginwidget>
68+
</div>
69+
<!--<div>
70+
<alteryx-pluginwidget type="CheckBox" id="copyUnmatched" dataName="CopyUnmatched" showAsToggle="true" text="Copy unmatched text to output"></alteryx-pluginwidget>
71+
</div>-->
72+
</fieldset>
73+
</form>
74+
<script type="text/javascript" src="OmnibusHTMLHelper.js"></script>
75+
<script type="text/javascript" src="OmnibusRegEx.js"></script>
76+
</body>
77+
</html>

0 commit comments

Comments
 (0)