Skip to content

Commit 3de3939

Browse files
authored
Merge pull request #110 from Frisle/master
ADD: new features: install and edit widgets in DSW
2 parents 39bfc8c + 9748312 commit 3de3939

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

MDX2JSON/REST.cls

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ XData UrlMap
6161
<Route Url="/Widgets" Method="POST" Call="GetWidgetsList" />
6262
<Route Url="/Action/:Cube/:Action" Method="POST" Call="ExecuteAction"/>
6363

64+
<!-- Send dashboard JSON -->
65+
<Route Url="/saveWidget" Method="POST" Call="saveWidget"/>
66+
6467
<!-- Get info about system format and locale-->
6568
<Route Url="/Format" Method="GET" Call="GetFormat"/>
6669

@@ -133,6 +136,15 @@ ClassMethod Test() As %Status
133136
return $$$OK
134137
}
135138

139+
ClassMethod saveWidget() As %Status
140+
{
141+
set key = $$$R("key")
142+
set widgetData= $$$R("WidgetData")
143+
set dashboardData = $$$R("Dashboard")
144+
145+
return ##class(MDX2JSON.Utils).AddWidget(widgetData,dashboardData,key)
146+
}
147+
136148

137149
/// Get all data sources including "pivot", "kpi", "worksheets","metrics"
138150
ClassMethod GetListDataSources(Source) As %Status

MDX2JSON/Utils.cls

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,4 +538,78 @@ ClassMethod CreateAddonClass(Class As %Dictionary.CacheClassname) As %Status
538538
quit classObj.%Save()
539539
}
540540

541+
ClassMethod AddWidget(sWidget As %String, sDashboard As %String, key As %String) As %Status
542+
{
543+
set st = $$$OK
544+
set dExist=##class(%DeepSee.Dashboard.Utils).%DashboardExists(sDashboard) // check if dashboard exist
545+
If (dExist = 1)
546+
{
547+
Set tDash=##class(%DeepSee.Dashboard.Utils).%OpenDashboard(sDashboard, .st)
548+
set tWidgets = ##class(%DeepSee.Dashboard.Widget).%New()
549+
set tWidgets.name = sWidget.name
550+
quit:sWidget.name=""
551+
set tWidgets.title = sWidget.title
552+
set tWidgets.dataSource = sWidget.dataSource
553+
554+
// logic to work around weird line in ##classMDX2JSON.Dashboard.WidgetToProxyObject:
555+
// "set obj.type = Widget.subtype"
556+
if (sWidget.type = "pivot")
557+
{
558+
set tWidgets.type = "pivot"
559+
set tWidgets.subtype = "pivot"
560+
}
561+
elseif (sWidget.type '= "pivot")
562+
{
563+
set tWidgets.type = "pivot"
564+
set tWidgets.subtype = sWidget.type
565+
}
566+
567+
set count = 0 // indicates wether or not the same name as key exists
568+
for i=1:1:tDash.widgets.Count()
569+
{
570+
if (tDash.widgets.GetAt(i).name = sWidget.name)
571+
{
572+
set count = 1
573+
return $$$ERROR()
574+
}
575+
}
576+
577+
578+
if (($LENGTH(key) = 0) & (count = 0)) // if key is empty and count = 1 widget is not insert
579+
{
580+
$$$Insert(tDash.widgets, tWidgets)
581+
do tDash.%Save()
582+
583+
}elseif ($LENGTH(key) > 0)
584+
{
585+
586+
for i=1:1:tDash.widgets.Count()
587+
{
588+
if (tDash.widgets.GetAt(i).name = key)
589+
{
590+
set tDash.widgets.GetAt(i).name = sWidget.name
591+
set tDash.widgets.GetAt(i).title = sWidget.title
592+
set tDash.widgets.GetAt(i).dataSource = sWidget.dataSource
593+
594+
if (sWidget.type = "pivot")
595+
{
596+
set tDash.widgets.GetAt(i).type = "pivot"
597+
set tDash.widgets.GetAt(i).subtype = "pivot"
598+
}
599+
elseif (sWidget.type '= "pivot")
600+
{
601+
set tDash.widgets.GetAt(i).type = "pivot"
602+
set tDash.widgets.GetAt(i).subtype = sWidget.type
603+
}
604+
do tDash.%Save()
605+
606+
}
607+
}
608+
}
609+
610+
611+
}
612+
return st
613+
}
614+
541615
}

0 commit comments

Comments
 (0)