Skip to content

Commit

Permalink
Merge pull request #114 from Frisle/master
Browse files Browse the repository at this point in the history
ADD: new method DeleteWidget, new endpoint, dataSource check
  • Loading branch information
eduard93 committed May 23, 2023
2 parents 694b312 + 73ccdfc commit 20cdbe0
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 16 deletions.
2 changes: 1 addition & 1 deletion MDX2JSON/Dashboard.cls
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ ClassMethod GetCubeMeasuresDataType(Widget, Number, CubeName, Output DataType As
set st = $$$OK
set dataSource = $piece(Widget.dataSource, ".", *) // get dataSource type

if (dataSource '= "kpi"){
if ((dataSource '= "kpi") && (dataSource '= "")){
if ($FIND(Widget.controls.GetAt(Number).targetProperty, "[") && $FIND(Widget.controls.GetAt(Number).targetProperty, ".")){
set tMeasure = $TRANSLATE(Widget.controls.GetAt(Number).targetProperty, "[]", "")

Expand Down
9 changes: 9 additions & 0 deletions MDX2JSON/REST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ XData UrlMap

<!-- Send dashboard JSON -->
<Route Url="/saveWidget" Method="POST" Call="saveWidget"/>
<Route Url="/deleteWidget" Method="POST" Call="deleteWidget"/>

<!-- Get info about system format and locale-->
<Route Url="/Format" Method="GET" Call="GetFormat"/>
Expand Down Expand Up @@ -136,6 +137,14 @@ ClassMethod Test() As %Status
return $$$OK
}

ClassMethod deleteWidget() As %Status
{
set name = $$$R("key")
set dashboardData = $$$R("Dashboard")

return ##class(MDX2JSON.Utils).DeleteWidget(name,dashboardData)
}

ClassMethod saveWidget() As %Status
{
set key = $$$R("key")
Expand Down
88 changes: 73 additions & 15 deletions MDX2JSON/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,9 @@ ClassMethod CreateAddonClass(Class As %Dictionary.CacheClassname) As %Status
quit classObj.%Save()
}

/// Add new widgets and edit existing ones.
/// Add new widgets and edit existing ones directly from DeepSeeWeb
/// it takes widget name(key) as unique identifier as string, dashboard name as string
/// and object with parameters as zen.proxyObject
ClassMethod AddWidget(sWidget As %String, sDashboard As %String, key As %String) As %Status
{
set st = $$$OK
Expand Down Expand Up @@ -569,7 +571,7 @@ ClassMethod AddWidget(sWidget As %String, sDashboard As %String, key As %String)
}

set tWidgets = ##class(%DeepSee.Dashboard.Widget).%New()
do ..UpdateWidget(tWidgets, sWidget)
set st = ..UpdateWidget(tWidgets, sWidget)

$$$Insert(tDash.widgets, tWidgets)
do tDash.%Save()
Expand All @@ -593,21 +595,86 @@ ClassMethod AddWidget(sWidget As %String, sDashboard As %String, key As %String)
}
}
if (changed '= "") {
do ..UpdateWidget(changed, sWidget)
set st = ..UpdateWidget(changed, sWidget)
do tDash.%Save()
}
}

return st
}

/// This method remove widget from dashboard directly from DeepSeeWeb
/// it takes widget name as unique identifier and dashboard name
ClassMethod DeleteWidget(wName As %String, sDashboard As %String) As %Status
{
set st = $$$OK

set dExist=##class(%DeepSee.Dashboard.Utils).%DashboardExists(sDashboard)

// Check if dashboard exists
If (dExist '= 1)
{
Quit $$$ERROR($$$GeneralError,"Dashboard " _ sDashboard _ " does not exists")
}
Set tDash=##class(%DeepSee.Dashboard.Utils).%OpenDashboard(sDashboard, .st)

// Check if widget with name is exists
set isExists = 0
for i=1:1:tDash.widgets.Count()
{
if (tDash.widgets.GetAt(i).name = wName)
{
set isExists = 1
}
}

if (isExists = 1)
{
for i=1:1:tDash.widgets.Count()
{
if (tDash.widgets.GetAt(i).name = wName)
{
do tDash.widgets.RemoveAt(i)
do tDash.%Save()
}
}
}else
{
quit $$$ERROR($$$GeneralError,"Widget " _ wName _ " is not exists")

}

return st
}


/// the collection of necessary parameters for building widget
ClassMethod UpdateWidget(widgetToUpdate As %DeepSee.Dashboard.Widget, data As %ZEN.proxyObject)
ClassMethod UpdateWidget(widgetToUpdate As %DeepSee.Dashboard.Widget, data As %ZEN.proxyObject) As %Status
{
set st = $$$OK

set widgetToUpdate.name = data.name
set widgetToUpdate.title = data.title
set widgetToUpdate.dataSource = data.dataSource
if (data.dataSource = "")
{
quit $$$ERROR($$$GeneralError,"Parameter DataSource is not set")
}else
{
set widgetToUpdate.dataSource = data.dataSource
}

set widgetToUpdate.dataLink = data.dataLink

if (data.type = "pivot")
{
set widgetToUpdate.type = "pivot"
set widgetToUpdate.subtype = "pivot"
}
elseif (data.type '= "pivot")
{
set widgetToUpdate.type = "pivot"
set widgetToUpdate.subtype = data.type
}

if (data.displayInfo '= "") {
set widgetToUpdate.top = data.displayInfo.top
Expand All @@ -620,16 +687,7 @@ ClassMethod UpdateWidget(widgetToUpdate As %DeepSee.Dashboard.Widget, data As %Z
set widgetToUpdate.rowSpanL = data.displayInfo.rowHeight
}

if (data.type = "pivot")
{
set widgetToUpdate.type = "pivot"
set widgetToUpdate.subtype = "pivot"
}
elseif (data.type '= "pivot")
{
set widgetToUpdate.type = "pivot"
set widgetToUpdate.subtype = data.type
}
return st
}

}

0 comments on commit 20cdbe0

Please sign in to comment.