Skip to content

Commit

Permalink
Merge pull request #112 from Frisle/master
Browse files Browse the repository at this point in the history
ADD: new method UpdateWidget. FIX: Http500 issues. REFACTOR: rewrited metod AddWidget
  • Loading branch information
eduard93 committed May 22, 2023
2 parents 929634b + 5673d9c commit 8711218
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 74 deletions.
20 changes: 2 additions & 18 deletions MDX2JSON/AbstractREST.cls
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ClassMethod OnPreDispatch(pUrl As %String, pMethod As %String, ByRef pContinue A

Set st = ..ConvertRequestBody()
If $$$ISERR(st) {
Do ..Http500(st)
#; Do ..Http500(st)
Set pContinue = $$$NO
Quit st
}
Expand All @@ -37,7 +37,7 @@ ClassMethod OnPreDispatch(pUrl As %String, pMethod As %String, ByRef pContinue A
Set Namespace = %request.Get("Namespace", $namespace)
Set st = ..CheckNamespace(.Namespace)
If $$$ISERR(st) {
Do ..Http500(st)
#; Do ..Http500(st)
Set pContinue = $$$NO
Quit
}
Expand Down Expand Up @@ -114,22 +114,6 @@ ClassMethod Login(skipheader As %Boolean = 1) As %Status
Return $$$OK
}

/// Issue an '500' error and give some indication as to what occurred.<br>
/// <b>pStatus</b> - %status, not %Exception.AbstractException.
ClassMethod Http500(pStatus As %Exception.AbstractException) As %Status
{
// we are expecting status
#; Set the response Http status
Set %response.Status="500 Internal Server Error"

#; Skip duplicate calls
Quit:$isObject(pStatus) $$$OK

#; Return a helpful error string
Write "{""Error"":"_$$$ZENJSSTR($System.Status.GetErrorText(pStatus,%session.Language))_"}"

Quit $$$OK
}

/// Returns info about MDX2JSON package mapping
ClassMethod GetMappings() As %ArrayOfObjects
Expand Down
133 changes: 77 additions & 56 deletions MDX2JSON/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -538,77 +538,98 @@ ClassMethod CreateAddonClass(Class As %Dictionary.CacheClassname) As %Status
quit classObj.%Save()
}

/// Add new widgets and edit existing ones.
ClassMethod AddWidget(sWidget As %String, sDashboard As %String, key As %String) As %Status
{
set st = $$$OK
set dExist=##class(%DeepSee.Dashboard.Utils).%DashboardExists(sDashboard) // check if dashboard exist
If (dExist = 1)
set dExist=##class(%DeepSee.Dashboard.Utils).%DashboardExists(sDashboard)

// Check if dashboard exists
If (dExist '= 1)
{
Set tDash=##class(%DeepSee.Dashboard.Utils).%OpenDashboard(sDashboard, .st)
set tWidgets = ##class(%DeepSee.Dashboard.Widget).%New()
set tWidgets.name = sWidget.name
quit:sWidget.name=""
set tWidgets.title = sWidget.title
set tWidgets.dataSource = sWidget.dataSource

// logic to work around weird line in ##classMDX2JSON.Dashboard.WidgetToProxyObject:
// "set obj.type = Widget.subtype"
if (sWidget.type = "pivot")
{
set tWidgets.type = "pivot"
set tWidgets.subtype = "pivot"
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 = sWidget.name)
{
set isExists = 1
}
elseif (sWidget.type '= "pivot")
{
set tWidgets.type = "pivot"
set tWidgets.subtype = sWidget.type
}
}

// Adding new widget
if ($LENGTH(key) = 0) { // if key received empty then we expect new widget if not then else logic is working
// Check if we trying to create widget with exists name
if (isExists = 1) {
return $$$ERROR($$$GeneralError,"Widget " _ sWidget.name _ " already exists")
}

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

set count = 0 // indicates wether or not the same name as key exists
$$$Insert(tDash.widgets, tWidgets)
do tDash.%Save()

} else {
// Edit exists widget
for i=1:1:tDash.widgets.Count()
{
if (tDash.widgets.GetAt(i).name = sWidget.name)
{
set count = 1

set dWidgets = tDash.widgets.GetAt(i)

// Check if we trying to change widget name with exists one
if ((dWidgets.name '= key) && (dWidgets.name = sWidget.name)) {
return $$$ERROR($$$GeneralError,"Widget " _ sWidget.name _ " already exists")

}
}


if (($LENGTH(key) = 0) & (count = 0)) // if key is empty and count = 1 widget is not insert
{
$$$Insert(tDash.widgets, tWidgets)
do tDash.%Save()

}elseif ($LENGTH(key) > 0)
{

for i=1:1:tDash.widgets.Count()
if (dWidgets.name = key)
{
if (tDash.widgets.GetAt(i).name = key)
{
set tDash.widgets.GetAt(i).name = sWidget.name
set tDash.widgets.GetAt(i).title = sWidget.title
set tDash.widgets.GetAt(i).dataSource = sWidget.dataSource

if (sWidget.type = "pivot")
{
set tDash.widgets.GetAt(i).type = "pivot"
set tDash.widgets.GetAt(i).subtype = "pivot"
}
elseif (sWidget.type '= "pivot")
{
set tDash.widgets.GetAt(i).type = "pivot"
set tDash.widgets.GetAt(i).subtype = sWidget.type
}
do tDash.%Save()

}
set changed = dWidgets
}
}
if (changed '= "") {
do ..UpdateWidget(changed, sWidget)
do tDash.%Save()
}
}

return st
}

/// the collection of necessary parameters for building widget
ClassMethod UpdateWidget(widgetToUpdate As %DeepSee.Dashboard.Widget, data As %ZEN.proxyObject)
{
set widgetToUpdate.name = data.name
set widgetToUpdate.title = data.title
set widgetToUpdate.dataSource = data.dataSource
set widgetToUpdate.dataLink = data.dataLink

if (data.displayInfo '= "") {
set widgetToUpdate.top = data.displayInfo.top
set widgetToUpdate.left = data.displayInfo.left
set widgetToUpdate.width = data.displayInfo.width
set widgetToUpdate.height = data.displayInfo.height
set widgetToUpdate.homeColL = data.displayInfo.topCol
set widgetToUpdate.homeRowL = data.displayInfo.leftRow
set widgetToUpdate.colSpanL = data.displayInfo.colWidth
set widgetToUpdate.rowSpanL = data.displayInfo.rowHeight
}

}
return st
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
}
}

}

0 comments on commit 8711218

Please sign in to comment.