Hi,
and thank you for the compliment. I didn’t like the corporate colors at first but that changed over time. White, gray and orange has a certain charm.
In principle I don’t mind providing the code as far as it goes but on the other hand there are dependencies, badly written functions, more complex relationships and a lot of repetitions.
The solution from the picture consists of 32000 lines of code over 5 dashboards, 5 APIs and that’s not including the 20 scripts and 2 modules. The backend has 3 databases and without them nothing works.
Here is an excerpt from my code concept about dashboard and API:
$Theme = @{
light = @{
palette = @{
type = 'light'
primary = @{
main = '#454545'
light = '#ffc568'
dark = '#dc7700'
}
divider = '#ef6c00'
warning = @{
main = '#ffc107'
}
secondary = @{
main = '#ff6d00'
}
background = @{
default = '#e0e0e0'
}
}
shape = @{
borderRadius = 7
}
props = @{
MuiList = @{
dense = "true"
}
MuiMenuItem = @{
dense = "true"
}
MuiTable = @{
size = 'small'
}
MuiTabs = @{
textColor = 'secondary'
indicatorColor = 'secondary'
}
}
}
dark = @{
palette = @{
type = 'dark'
primary = @{
main = '#f5f5f5'
light = '#ffc568'
dark = '#dc7700'
}
divider = '#ef6c00'
warning = @{
main = '#ffc107'
}
secondary = @{
main = '#ff6d00'
}
background = @{
default = '#303030'
paper = '#424242'
}
}
shape = @{
borderRadius = 7
}
props = @{
MuiList = @{
dense = "true"
}
MuiMenuItem = @{
dense = "true"
}
MuiTable = @{
size = 'small'
}
MuiTabs = @{
textColor = 'secondary'
indicatorColor = 'secondary'
}
}
}
}
#Region Function
#Example to get Data from API
function Get-EinmalaufwandBestand {
param([switch]$Renew)
if (!([string]::IsNullOrEmpty($Session:Schaltzentrale.SelectedVerfahren.ID))) {
if (($Session:Schaltzentrale.GetEinmalaufwandBestand -ne $Session:Schaltzentrale.SelectedVerfahren.ID) -or ([string]::IsNullOrEmpty($Session:Schaltzentrale.GetEinmalaufwandBestand) -or ($Renew.IsPresent))) {
$transData = [PSCustomObject]::new(@{
User = $User
Role = $Session:Schaltzentrale.PSURolleMitB
VerfahrenID = $Session:Schaltzentrale.SelectedVerfahren.ID
})
$OutputRest = Send-LDIRestData -RestURI $Session:Schaltzentrale.SQLURI -Method "Post" -Command "GetEinmalaufwandBestand" -transData $transData -BearerToken $Secret:SchaltzentraleRestBearerToken
if (!($OutputRest -like "FehlerX:*")) {
foreach ($i in $OutputRest) { if ($i.ServerID -eq 0) { $i.Servername = "VerfahrenAllgemein" } }
$Session:Schaltzentrale.SollEinmalaufwandBestand = $OutputRest
$Session:Schaltzentrale.GetEinmalaufwandBestand = $Session:Schaltzentrale.SelectedVerfahren.ID
} else { $Session:Schaltzentrale.SollEinmalaufwandBestand = $Null ; $Session:Schaltzentrale.GetEinmalaufwandBestand = 0 }
}
} else { $Session:Schaltzentrale.SollEinmalaufwandBestand = $Null }
}
#endregion
#region Example API Data query
#not part of a dashboard:
# i had some encoding issues because of not using english os. the byte encoding is working for me
#part of the module:
function Send-LDIRestData {
param(
$transData, # $transData = [PSCustomObject]::new(@{ User = "computer\user" ; Role = "test" })
$Command, # $Command = "GetSollServer"
$RestURI, # $RestURI = "$PSUServer/LDIPSUData"
$Method, # $Method ="Post"
$BearerToken
) # $a = Invoke-RestMethod $RestURI -Method $Method -Body (@{ Command = $Command ; Data = $transDataJB } | ConvertTo-Json) -UseDefaultCredentials
$transDataJ = $transData | ConvertTo-Json
$transDataJB = [System.Text.Encoding]::UTF8.GetBytes($transDataJ)
$OutputREST = Invoke-RestMethod $RestURI -Method $Method -Body (@{
Command = $Command
Data = $transDataJB
} | ConvertTo-Json) -Headers @{ Authorization = "Bearer $BearerToken" } -ContentType 'application/json' #-Credential $RestServiceAccount -AllowUnencryptedAuthentication
if ($OutputRest -like "FehlerX:*") {
$ToastID = Get-Random -Minimum 100000 -Maximum 9999999
Show-UDToast -Message "Fehler bei: $Command `n`nStatus: $OutputREST" -id "ToastRest$ToastID" -Title "Fehler" -MessageColor "Red" -CloseOnClick -Icon 'exclamation_circle' -IconColor 'Red' -Duration 10000
} elseif ($OutputREST.LDIPSURESTTyp -eq "Toast") {
if ($OutputREST.ToastString.Length -gt 0) {
Show-UDToast -Message "`n$($OutputREST.ToastString | out-string)" -id "ToastRest$ToastID" -Title "Meldung" -MessageColor "Black" -CloseOnClick -Icon 'info_circle' -IconColor 'F17100' -Duration 10000
}
}
$encoding = [System.Text.Encoding]::GetEncoding(28591)
return [text.encoding]::UTF8.getstring($encoding.GetBytes(($OutputREST | convertto-json))) | ConvertFrom-Json
}
#API skelleton:
Import-Module LDIPSUMSSQL
$PSDefaultParameterValues = @{ '*:Encoding' = 'utf8' }
$Fields = $Body | ConvertFrom-Json
$Error.Clear()
$TransData = [System.Text.Encoding]::UTF8.GetString($Fields.Data) | ConvertFrom-Json
$User = $TransData.User
$Role = $TransData.Role
$EinfacheAbfrage = "Ja"
switch ( $Fields.Command ) {
'GetVerfahren' {
$Table = "Soll.Verfahren"
$SQLQuery = "Select * From [PSU.$Role].[dbo].[Soll.Verfahren] ORDER BY Name;"
$Output = "Ja"
} #and many more switch options... only example
}
if ($EinfacheAbfrage -eq "Ja") {
$AntwortQuery = @()
try {
$AntwortQuery += Invoke-LDIPSUSQL -Table "$Table" -Query $SQLQuery -User "$User" -Role "$Role" -RemoteIPAddress $RemoteIPAddress -Identity $Identity
} catch {}
if ($Output -eq "Nein") { if ($error.count -gt 0) { $Antwort = "FehlerX: $Error" } else { $Antwort = "Ok" } }
else {
if ($error.count -gt 0) {
$Antwort = "FehlerX: $Error"
} else {
try {
if ($AntwortQuery.count -gt 0) {
$Antwort = $AntwortQuery | Select-Object ($AntwortQuery | Get-Member -MemberType Property -ErrorAction Stop).Name
} else {
$Antwort = $Null
}
} catch { $Antwort = "FehlerX: $(foreach ($i in $Error){"$($i.Message) `n" })" }
}
}
$Antwort | ConvertTo-Json
} else {
$Antwort | ConvertTo-Json
}
# the Invoke-LDIPSUSQL is a special function written by my own for sql querys and a log option for all not select querys...
#endregion
#Dashboard continue:
Import-Module Schaltzentrale
$PSDefaultParameterValues = @{ '*:Encoding' = 'utf8' }
$PSUServerCN = "localhost"
$PSUServer = "http://$($PSUServerCN):5000"
$PSUFilePath = "C:\PSU"
$PaperBackgroud = '#F17100f0'
$ProgressColor = '#F17100'
$TabStyle = '.MuiTab-textColorPrimary.Mui-selected { color: #ff6d00; background: #767676;};.MuiTabs-indicator { background: #ff6d00;}'
#region Icons
# $Suche = "Home" ; $Icons = [Enum]::GetNames([UniversalDashboard.Models.FontAwesomeIcons]) ; $icons.where({$_ -like "*$Suche*"})
$IconKontaktAllgemein = New-UDIcon -Icon 'AddressBook' -Size 'lg'
$IconVerfahrenVertragsdaten = New-UDIcon -Icon 'filecontract' -Size 'lg'
#...
#endregion
$Navigation = {
New-UDListItem -Label "Verfahren" -OnClick { Invoke-UDRedirect -Url '/Verfahren' } -Icon $IconVerfahrenAllgemein -SubTitle "Verwaltung"
New-UDListItem -Label "Ressourcen" -OnClick { Invoke-UDRedirect '/Ressourcen' } -SubTitle "Server usw." -Icon $IconServerAllgemein
New-UDListItem -Label "Verwaltung" -OnClick { Invoke-UDRedirect '/Verwaltung' } -SubTitle "SLA, Sicherheit usw." -Icon $IconVerwaltungZentral
New-UDListItem -Label "Aufgaben" -OnClick { Invoke-UDRedirect "$PSUServer/SchaltzentralePSR" -OpenInNewWindow } -SubTitle "PSRemoting usw." -Icon $IconVerwaltungAufgabe
New-UDListItem -Label "Zentrales Adressbuch" -OnClick { Invoke-UDRedirect -Url "$PSUServer/ZentraleKontaktVerwaltung" -OpenInNewWindow } -Icon $IconKontaktAllgemein -SubTitle "Kontakte, Tel, EMail"
New-UDListItem -Label "Zentrale Informationen" -OnClick { Invoke-UDRedirect "$PSUServer/BetriebLDI" -OpenInNewWindow } -Icon $IconZentralInfo -SubTitle "KRT, LTNs, IPs"
New-UDListItem -Label "Zentrale Verwaltung" -OnClick { Invoke-UDRedirect "$PSUServer/Schaltkontrollzentrale" -OpenInNewWindow } -Icon $IconZentralVerwaltung -SubTitle "Rollenadministration"
New-UDListItem -Label "Informationen" -Children {
New-UDListItem -Label "Bereitgestellt von:" -Nested -SubTitle "Daniel Krauß"
New-UDListItem -Label "Bereitgestellt für:" -Nested -SubTitle "Daniel Krauß"
New-UDListItem -Label "Bereitgestellt für:" -Nested -SubTitle "B4 FG1"
} #-Open
}
$Pages = @()
$Pages += New-UDPage -Name 'Verfahren' -Content {
if ($null -eq $Session:SchaltzentraleVars) {
#using $Session for data between pages
$Session:SchaltzentraleVars = "1"
$Session:Schaltzentrale = [HashTable]::Synchronized(@{})
$Session:Schaltzentrale.SQLURI = "$PSUServer/LDIPSUData"
$Session:Schaltzentrale.AdministrationURI = "$PSUServer/LDIPSUAdministration"
$Session:Schaltzentrale.AdressbuchURI = "$PSUServer/LDIPSUAdressbuch"
$Session:Schaltzentrale.LDIPSUDashboardLoginLog = "$PSUServer/LDIPSUDashboardLoginLog"
$Session:Schaltzentrale.DataVerfahrenrolle = [System.Collections.ArrayList]::new()
$Session:Schaltzentrale.DataVerfahrenTyp = [System.Collections.ArrayList]::new()
$Session:Schaltzentrale.Verfahren = [System.Collections.ArrayList]::new()
$Session:Schaltzentrale.SelectedVerfahren = ""
$Session:Schaltzentrale.PSURolleMitB = ""
$Session:Schaltzentrale.UserSid = (New-Object System.Security.Principal.NTAccount($User)).Translate([System.Security.Principal.SecurityIdentifier]).Value
#...
}
$LayoutSeite = '{"lg":[{"w":2,"h":3,"x":10,"y":0,"i":"grid-element-BetriebLDIPaperRolle","moved":false,"static":false},{"w":2,"h":3,"x":0,"y":0,"i":"grid-element-BetriebLDIPaperVerfahren","moved":false,"static":false},{"w":2,"h":3,"x":3,"y":0,"i":"grid-element-LDIVerwaltungPaperNeuesVerfahren","moved":false,"static":false},{"w":12,"h":18,"x":0,"y":3,"i":"grid-element-BetriebLDIVerfahrenTabs","moved":false,"static":false}]}'
New-UDStyle -Style $TabStyle -Content {
New-UDGridLayout -Content {
#... Buttons... papers...selects...ect.
} -Layout $LayoutSeite #-Design #
}
} -Logo '/images/favicon.png' -NavigationLayout permanent -LoadNavigation $Navigation -HeaderContent {
New-UDDynamic -Content { New-UDTypography "Kalenderwoche: $([System.Globalization.DateTimeFormatInfo]::CurrentInfo.Calendar.GetWeekOfYear((get-date), 2, 1)) " } -AutoRefresh -AutoRefreshInterval 600
New-UDIcon -Icon Book -Style @{ marginRight = '12px' ; color = '#ff6d00' }
New-UDLink -Text 'Dokumentation' -OnClick { Invoke-UDRedirect "https://path/to/docu" -OpenInNewWindow } -Style @{ color = '#ff6d00' ; 'text-decoration' = 'underline' }
}
$Pages += New-UDPage -Name 'Ressourcen' -Content {
if ($null -eq $Session:SchaltzentraleVars) {
#using $Session for data between pages
$Session:SchaltzentraleVars = "1"
$Session:Schaltzentrale = [HashTable]::Synchronized(@{})
$Session:Schaltzentrale.SQLURI = "$PSUServer/LDIPSUData"
$Session:Schaltzentrale.AdministrationURI = "$PSUServer/LDIPSUAdministration"
$Session:Schaltzentrale.AdressbuchURI = "$PSUServer/LDIPSUAdressbuch"
$Session:Schaltzentrale.LDIPSUDashboardLoginLog = "$PSUServer/LDIPSUDashboardLoginLog"
$Session:Schaltzentrale.DataVerfahrenrolle = [System.Collections.ArrayList]::new()
$Session:Schaltzentrale.DataVerfahrenTyp = [System.Collections.ArrayList]::new()
$Session:Schaltzentrale.Verfahren = [System.Collections.ArrayList]::new()
$Session:Schaltzentrale.SelectedVerfahren = ""
$Session:Schaltzentrale.PSURolleMitB = ""
$Session:Schaltzentrale.UserSid = (New-Object System.Security.Principal.NTAccount($User)).Translate([System.Security.Principal.SecurityIdentifier]).Value
#...
}
$LayoutSeite = '{"lg":[{"w":2,"h":3,"x":10,"y":0,"i":"grid-element-BetriebLDIPaperRolle","moved":false,"static":false},{"w":2,"h":3,"x":0,"y":0,"i":"grid-element-BetriebLDIPaperVerfahren","moved":false,"static":false},{"w":2,"h":3,"x":3,"y":0,"i":"grid-element-LDIVerwaltungPaperNeuesVerfahren","moved":false,"static":false},{"w":12,"h":18,"x":0,"y":3,"i":"grid-element-BetriebLDIVerfahrenTabs","moved":false,"static":false}]}'
New-UDStyle -Style $TabStyle -Content {
New-UDGridLayout -Content {
#... Buttons... papers...selects...ect.
} -Layout $LayoutSeite #-Design #
}
} -Logo '/images/favicon.png' -NavigationLayout permanent -LoadNavigation $Navigation -HeaderContent {
New-UDDynamic -Content { New-UDTypography "Kalenderwoche: $([System.Globalization.DateTimeFormatInfo]::CurrentInfo.Calendar.GetWeekOfYear((get-date), 2, 1)) " } -AutoRefresh -AutoRefreshInterval 600
New-UDIcon -Icon Book -Style @{ marginRight = '12px' ; color = '#ff6d00' }
New-UDLink -Text 'Dokumentation' -OnClick { Invoke-UDRedirect "https://path/to/docu" -OpenInNewWindow } -Style @{ color = '#ff6d00' ; 'text-decoration' = 'underline' }
}
#...
New-UDDashboard -Title "Schaltzentrale" -Pages $Pages -Theme $Theme
maybe it helps