Skip to content

Commit 3e275b8

Browse files
committed
FIX: edited AddWidget method, remove redundant Http500 method. ADD: new method to hold all widget parameters.
Rewrite method AddWidget, add new method UpdateWidget for convenience, remove method Http500 and all its instances
1 parent 9748312 commit 3e275b8

2 files changed

Lines changed: 66 additions & 75 deletions

File tree

MDX2JSON/AbstractREST.cls

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ClassMethod OnPreDispatch(pUrl As %String, pMethod As %String, ByRef pContinue A
2828

2929
Set st = ..ConvertRequestBody()
3030
If $$$ISERR(st) {
31-
Do ..Http500(st)
31+
#; Do ..Http500(st)
3232
Set pContinue = $$$NO
3333
Quit st
3434
}
@@ -37,7 +37,7 @@ ClassMethod OnPreDispatch(pUrl As %String, pMethod As %String, ByRef pContinue A
3737
Set Namespace = %request.Get("Namespace", $namespace)
3838
Set st = ..CheckNamespace(.Namespace)
3939
If $$$ISERR(st) {
40-
Do ..Http500(st)
40+
#; Do ..Http500(st)
4141
Set pContinue = $$$NO
4242
Quit
4343
}
@@ -114,22 +114,6 @@ ClassMethod Login(skipheader As %Boolean = 1) As %Status
114114
Return $$$OK
115115
}
116116

117-
/// Issue an '500' error and give some indication as to what occurred.<br>
118-
/// <b>pStatus</b> - %status, not %Exception.AbstractException.
119-
ClassMethod Http500(pStatus As %Exception.AbstractException) As %Status
120-
{
121-
// we are expecting status
122-
#; Set the response Http status
123-
Set %response.Status="500 Internal Server Error"
124-
125-
#; Skip duplicate calls
126-
Quit:$isObject(pStatus) $$$OK
127-
128-
#; Return a helpful error string
129-
Write "{""Error"":"_$$$ZENJSSTR($System.Status.GetErrorText(pStatus,%session.Language))_"}"
130-
131-
Quit $$$OK
132-
}
133117

134118
/// Returns info about MDX2JSON package mapping
135119
ClassMethod GetMappings() As %ArrayOfObjects

MDX2JSON/Utils.cls

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

541+
/// Add new widgets and edit existing ones.
541542
ClassMethod AddWidget(sWidget As %String, sDashboard As %String, key As %String) As %Status
542543
{
543544
set st = $$$OK
544-
set dExist=##class(%DeepSee.Dashboard.Utils).%DashboardExists(sDashboard) // check if dashboard exist
545-
If (dExist = 1)
545+
set dExist=##class(%DeepSee.Dashboard.Utils).%DashboardExists(sDashboard)
546+
547+
// Check if dashboard exists
548+
If (dExist '= 1)
546549
{
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"
550+
Quit $$$ERROR($$$GeneralError,"Dashboard " _ sDashboard _ " does not exists")
551+
}
552+
Set tDash=##class(%DeepSee.Dashboard.Utils).%OpenDashboard(sDashboard, .st)
553+
554+
// Check if widget with name is exists
555+
set isExists = 0
556+
for i=1:1:tDash.widgets.Count()
557+
{
558+
if (tDash.widgets.GetAt(i).name = sWidget.name)
559+
{
560+
set isExists = 1
561+
}
562+
}
563+
564+
// Adding new widget
565+
if ($LENGTH(key) = 0) { // if key received empty then we expect new widget if not then else logic is working
566+
// Check if we trying to create widget with exists name
567+
if (isExists = 1) {
568+
return $$$ERROR($$$GeneralError,"Widget " _ sWidget.name _ " already exists")
560569
}
561-
elseif (sWidget.type '= "pivot")
562-
{
563-
set tWidgets.type = "pivot"
564-
set tWidgets.subtype = sWidget.type
565-
}
566570

567-
set count = 0 // indicates wether or not the same name as key exists
571+
set tWidgets = ##class(%DeepSee.Dashboard.Widget).%New()
572+
do ..UpdateWidget(tWidgets, sWidget)
573+
574+
$$$Insert(tDash.widgets, tWidgets)
575+
do tDash.%Save()
576+
577+
} else {
578+
// Edit exists widget
568579
for i=1:1:tDash.widgets.Count()
569580
{
570-
if (tDash.widgets.GetAt(i).name = sWidget.name)
571-
{
572-
set count = 1
573-
return $$$ERROR()
581+
set dWidgets = tDash.widgets.GetAt(i)
582+
583+
// Check if we trying to change widget name with exists one
584+
if ((dWidgets.name '= key) && (dWidgets.name = sWidget.name)) {
585+
return $$$ERROR($$$GeneralError,"Widget " _ sWidget.name _ " already exists")
574586
}
575-
}
576587

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()
588+
if (dWidgets.name = key)
587589
{
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-
}
590+
set changed = dWidgets
607591
}
608592
}
593+
if (changed '= "") {
594+
do ..UpdateWidget(changed, sWidget)
595+
do tDash.%Save()
596+
}
597+
}
598+
599+
return st
600+
}
609601

602+
/// the collection of necessary parameters for building widget
603+
ClassMethod UpdateWidget(widgetToUpdate As %DeepSee.Dashboard.Widget, data As %ZEN.proxyObject)
604+
{
605+
set widgetToUpdate.name = data.name
606+
set widgetToUpdate.title = data.title
607+
set widgetToUpdate.dataSource = data.dataSource
608+
set widgetToUpdate.dataLink = data.dataLink
610609

611-
}
612-
return st
610+
if (data.type = "pivot")
611+
{
612+
set widgetToUpdate.type = "pivot"
613+
set widgetToUpdate.subtype = "pivot"
614+
}
615+
elseif (data.type '= "pivot")
616+
{
617+
set widgetToUpdate.type = "pivot"
618+
set widgetToUpdate.subtype = data.type
619+
}
613620
}
614621

615622
}

0 commit comments

Comments
 (0)