Skip to content

Commit 8711218

Browse files
authored
Merge pull request #112 from Frisle/master
ADD: new method UpdateWidget. FIX: Http500 issues. REFACTOR: rewrited metod AddWidget
2 parents 929634b + 5673d9c commit 8711218

2 files changed

Lines changed: 79 additions & 74 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: 77 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -538,77 +538,98 @@ 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
560561
}
561-
elseif (sWidget.type '= "pivot")
562-
{
563-
set tWidgets.type = "pivot"
564-
set tWidgets.subtype = sWidget.type
565-
}
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")
569+
}
570+
571+
set tWidgets = ##class(%DeepSee.Dashboard.Widget).%New()
572+
do ..UpdateWidget(tWidgets, sWidget)
566573

567-
set count = 0 // indicates wether or not the same name as key exists
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
581+
582+
set dWidgets = tDash.widgets.GetAt(i)
583+
584+
// Check if we trying to change widget name with exists one
585+
if ((dWidgets.name '= key) && (dWidgets.name = sWidget.name)) {
586+
return $$$ERROR($$$GeneralError,"Widget " _ sWidget.name _ " already exists")
587+
573588
}
574-
}
575589

576-
577-
if (($LENGTH(key) = 0) & (count = 0)) // if key is empty and count = 1 widget is not insert
578-
{
579-
$$$Insert(tDash.widgets, tWidgets)
580-
do tDash.%Save()
581-
582-
}elseif ($LENGTH(key) > 0)
583-
{
584-
585-
for i=1:1:tDash.widgets.Count()
590+
if (dWidgets.name = key)
586591
{
587-
if (tDash.widgets.GetAt(i).name = key)
588-
{
589-
set tDash.widgets.GetAt(i).name = sWidget.name
590-
set tDash.widgets.GetAt(i).title = sWidget.title
591-
set tDash.widgets.GetAt(i).dataSource = sWidget.dataSource
592-
593-
if (sWidget.type = "pivot")
594-
{
595-
set tDash.widgets.GetAt(i).type = "pivot"
596-
set tDash.widgets.GetAt(i).subtype = "pivot"
597-
}
598-
elseif (sWidget.type '= "pivot")
599-
{
600-
set tDash.widgets.GetAt(i).type = "pivot"
601-
set tDash.widgets.GetAt(i).subtype = sWidget.type
602-
}
603-
do tDash.%Save()
604-
605-
}
592+
set changed = dWidgets
606593
}
607594
}
595+
if (changed '= "") {
596+
do ..UpdateWidget(changed, sWidget)
597+
do tDash.%Save()
598+
}
599+
}
600+
601+
return st
602+
}
608603

604+
/// the collection of necessary parameters for building widget
605+
ClassMethod UpdateWidget(widgetToUpdate As %DeepSee.Dashboard.Widget, data As %ZEN.proxyObject)
606+
{
607+
set widgetToUpdate.name = data.name
608+
set widgetToUpdate.title = data.title
609+
set widgetToUpdate.dataSource = data.dataSource
610+
set widgetToUpdate.dataLink = data.dataLink
611+
612+
if (data.displayInfo '= "") {
613+
set widgetToUpdate.top = data.displayInfo.top
614+
set widgetToUpdate.left = data.displayInfo.left
615+
set widgetToUpdate.width = data.displayInfo.width
616+
set widgetToUpdate.height = data.displayInfo.height
617+
set widgetToUpdate.homeColL = data.displayInfo.topCol
618+
set widgetToUpdate.homeRowL = data.displayInfo.leftRow
619+
set widgetToUpdate.colSpanL = data.displayInfo.colWidth
620+
set widgetToUpdate.rowSpanL = data.displayInfo.rowHeight
621+
}
609622

610-
}
611-
return st
623+
if (data.type = "pivot")
624+
{
625+
set widgetToUpdate.type = "pivot"
626+
set widgetToUpdate.subtype = "pivot"
627+
}
628+
elseif (data.type '= "pivot")
629+
{
630+
set widgetToUpdate.type = "pivot"
631+
set widgetToUpdate.subtype = data.type
632+
}
612633
}
613634

614635
}

0 commit comments

Comments
 (0)