Skip to content

Instantly share code, notes, and snippets.

View adamdriscoll's full-sized avatar
:bowtie:

Adam Driscoll adamdriscoll

:bowtie:
View GitHub Profile
@adamdriscoll
adamdriscoll / map-cluster.ps1
Created September 13, 2019 12:35
Map Cluster Example for Universal Dashboard.
New-UDButton -Text "Add marker to cluster" -OnClick {
Add-UDElement -ParentId 'cluster-layer' -Content {
$Random = Get-Random -Minimum 0 -Maximum 100
$RandomLat = $Random + 400
New-UDMapMarker -Latitude "51.$RandomLat" -Longitude "-0.$Random"
}
}
New-UDButton -Text "Clear cluster" -OnClick {
@adamdriscoll
adamdriscoll / udhelment.register.js
Created September 7, 2019 16:35
Registering a component with Universal Dashboard.
import UDHelmet from './helmet';
UniversalDashboard.register("ud-helmet", UDHelmet);
@adamdriscoll
adamdriscoll / rendering.js
Created September 7, 2019 16:34
Rendering a component in LazyElement
var element = renderComponent(this.props.component, this.props.history, true);
@adamdriscoll
adamdriscoll / lazyElement.ComponentWillMount.js
Created September 7, 2019 16:32
Lazy Element componentWillMount function from Universal Dashboard
componentWillMount() {
var script = document.createElement('script');
script.onload = function() {
this.setState({loading:false});
}.bind(this)
script.src = getApiPath() + "/" + this.props.component.assetId;
document.head.appendChild(script);
}
@adamdriscoll
adamdriscoll / renderComponent.js
Created September 7, 2019 16:30
Render Component Function of Universal Dashboard
renderComponent: function(component, history, dynamicallyLoaded) {
if (component == null) return <React.Fragment/>;
if (Array.isArray(component)) {
return component.map(x => this.renderComponent(x, history));
}
var existingComponent = this.components.find(x => x.type === component.type);
if (existingComponent != null) {
@adamdriscoll
adamdriscoll / udhelment.json
Created September 7, 2019 16:27
Example UD Helmet JSON
{
'assetId': 'index.as3sdfq23afa.bundle.js',
'isPlugin': true,
'type': 'ud-helmet',
'id': 'myHelmet'
}
@adamdriscoll
adamdriscoll / UDHelmet.ps1
Created September 7, 2019 16:25
UDHelmet Function
function New-UDHelmet {
param(
[Parameter()]
[string]$Id = (New-Guid).ToString(),
[Parameter(Mandatory = $true)]
[scriptblock]$Content
)
End {
@{
@adamdriscoll
adamdriscoll / AssetLoading.cs
Created September 7, 2019 16:21
Arbitrary Asset Loading in Universal Dashboard
app.UseStatusCodePages(async context => {
if (context.HttpContext.Response.StatusCode == 404 && !context.HttpContext.Request.Path.StartsWithSegments("/api"))
{
var fileName = context.HttpContext.Request.Path.ToString().Split('/').Last();
var asset = AssetService.Instance.FindAsset(fileName);
if (asset != null)
{
var response = context.HttpContext.Response;
response.StatusCode = 200;
var file = File.ReadAllBytes(asset);
@adamdriscoll
adamdriscoll / Asset.cs
Created September 7, 2019 16:15
JavaScript Controller Asset Endpoint
[Route("{asset}")]
public IActionResult Index(string asset)
{
var filePath = AssetService.Instance.FindAsset(asset);
if (filePath == null)
{
Log.Warn($"Unknown element script: {asset}");
return StatusCode(404);
}
@adamdriscoll
adamdriscoll / RegisterAsset.ps1
Created September 7, 2019 16:13
Registering an asset with the Universal Dashboard Asset Service
$AssetId = [UniversalDashboard.Services.AssetService]::Instance.RegisterAsset($IndexJs.FullName)