@@ -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