UniversalDashboard.MaterialUICarousel.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
$JsFile = Get-ChildItem "$PSScriptRoot\index.*.bundle.js"
# Source maps to make it easier to debug in the browser
$Maps = Get-ChildItem "$PSScriptRoot\*.map"

$AssetId = [UniversalDashboard.Services.AssetService]::Instance.RegisterScript($JsFile.FullName)
# Register all the source map files so we can make debugging easier.
foreach ($item in $Maps) {
    [UniversalDashboard.Services.AssetService]::Instance.RegisterAsset($item.FullName) | Out-Null
}

function New-UDMUCarousel {
    param
    (
        [Parameter()]
        [string]$Id = [guid]::NewGuid(),
        [Parameter()]
        [string]$ClassName,
        [Parameter()]
        [switch]$Autoplay,
        [Parameter()]
        [switch]$Landscape,
        [Parameter()]
        [switch]$Mobile,
        [Parameter()]
        [switch]$Open,
        [Parameter()]
        [hashtable]$ButtonProps,
        [Parameter()]
        [hashtable]$ContainerStyle,
        [Parameter()]
        [hashtable]$ModalProps,
        [Parameter()]
        [string]$Label,
        [Parameter()]
        [int]$Interval,
        [Parameter()]
        [scriptblock]$Content,
        [Parameter()]
        [scriptblock]$OnClose,
        [Parameter()]
        [scriptblock]$OnStart,
        [Parameter()]
        [switch]$IsEndpoint,
        [Parameter()]
        [int]$RefreshInterval = 5000,
        [Parameter()]
        [switch]$AutoRefresh
    )

    End {

        if ($null -ne $Content) {
            if ($IsEndpoint.IsPresent) {
                if ($Content -is [scriptblock]) {
                    $Endpoint = New-UDEndpoint -Endpoint $Content -Id $Id 
                    $CarouselContent = $Content.Invoke()
                }
                elseif ($Content -isnot [UniversalDashboard.Models.Endpoint]) {
                    throw "Content must be a script block or UDEndpoint"
                }
            }
            else {
                $CarouselContent = $Content.Invoke()
            }
        }

        if ($null -ne $OnClose) {
            if ($OnClose -is [scriptblock]) {
                $OnCloseEndpoint = New-UDEndpoint -Endpoint $OnClose -Id ($Id + "onClose")
            }
            elseif ($OnClose -isnot [UniversalDashboard.Models.Endpoint]) {
                throw "OnClose must be a script block or UDEndpoint"
            }
        }

        if ($null -ne $OnStart) {
            if ($OnStart -is [scriptblock]) {
                $OnStartEndpoint = New-UDEndpoint -Endpoint $OnStart -Id ($Id + "onStart")
            }
            elseif ($OnStart -isnot [UniversalDashboard.Models.Endpoint]) {
                throw "OnStart must be a script block or UDEndpoint"
            }
        }

        @{
            assetId         = $AssetId 
            isPlugin        = $true 
            id              = $Id 
            type            = 'mu-carousel'
            autoplay        = $Autoplay.IsPresent
            ButtonProps     = $ButtonProps
            containerStyle  = $ContainerStyle
            interval        = $Interval
            label           = $Label
            landscape       = $Landscape.IsPresent
            mobile          = $Mobile.IsPresent
            ModalProps      = $ModalProps
            open            = $Open.IsPresent
            content         = $CarouselContent
            className       = $ClassName
            autoRefresh     = $AutoRefresh.IsPresent
            refreshInterval = $RefreshInterval
        }
    }
}

function New-UDMUCarouselSlide {
    param(
        [Parameter()]
        [string]$Id = [guid]::NewGuid(),
        [Parameter()]
        [string]$ClassName,
        [Parameter()]
        [string]$Title,
        [Parameter()]
        [string]$SubTitle,
        [Parameter()]
        [object]$Media,
        [Parameter()]
        [hashtable]$MediaBackgroundStyle,
        [Parameter()]
        [hashtable]$Style
    )

    End{
        @{
            assetId  = $AssetId 
            isPlugin = $true 
            id       = $Id 
            type     = 'mu-carousel-slide'
            className = $ClassName
            media = $Media
            mediaBackgroundStyle = $MediaBackgroundStyle
            style = $Style
            subtitle = $SubTitle
            title = $Title
        }
    }
}