Skip to content

Commit b93456b

Browse files
committed
Use Name instead of empty Title
1 parent 8bcb883 commit b93456b

1 file changed

Lines changed: 163 additions & 164 deletions

File tree

MDX2JSON/DashboardRS.cls

Lines changed: 163 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,163 @@
1-
/// Custom result set to get dashboard list, visible to user in a specific folder
2-
Class MDX2JSON.DashboardRS Extends %SQL.CustomResultSet
3-
{
4-
5-
Parameter global = "^DeepSee.FolderItemD";
6-
7-
Parameter dashclass = "%DeepSee.Dashboard.Definition";
8-
9-
Property title As %String;
10-
11-
Property path As %String;
12-
13-
Property cover As %String;
14-
15-
Property id As %String [ Private ];
16-
17-
Property folder As %String [ Private ];
18-
19-
Method %OpenCursor(folderName As %String = "") As %Status
20-
{
21-
return:((folderName'="") && ('$IsObject(##class(%DeepSee.UserLibrary.Utils).%FindFolder(folderName)))) $$$ERROR($$$GeneralError,"Folder " _ folderName _ " does not exist")
22-
set ..id = ""
23-
set ..folder = folderName
24-
return $$$OK
25-
}
26-
27-
Method %Next(ByRef sc As %Library.Status) As %Integer [ PlaceAfter = %Execute ]
28-
{
29-
set sc = $$$OK
30-
do ..SetNextId()
31-
set id = ..id
32-
return:id="" $$$NO
33-
34-
set title = ##class(%DeepSee.UserPortal.Utils).%ResolveText(##class(%DeepSee.UserLibrary.FolderItem).titleGetStored(id))
35-
if (title = "") { // While empty Title use Name instead
36-
set title = ##class(%DeepSee.UserPortal.Utils).%ResolveText(##class(%DeepSee.UserLibrary.FolderItem).nameGetStored(id))
37-
}
38-
39-
set ..title = title
40-
set ..path = ..GetDashFullName(id)
41-
set ..cover = ##class(MDX2JSON.Dashboard).GetDashCover(##class(%DeepSee.UserLibrary.FolderItem).bookCoverGetStored(id))
42-
43-
return $$$YES
44-
}
45-
46-
/// Iterate over data global till we find dashboard definition
47-
/// thet satisfies all conditions
48-
Method SetNextId()
49-
{
50-
set ..id = $order(@..#global@(..id))
51-
if ((..id'="") && ('..CheckConditions(..id))) {
52-
// we are not at the last row and we failed condition check
53-
// so we get the next id
54-
do ..SetNextId()
55-
}
56-
}
57-
58-
/// Check if element with that id satisfies our conditions
59-
Method CheckConditions(id) As %Boolean
60-
{
61-
/// first we check that it's a dashboard (not a pivot, etc.)
62-
set oid = ##class(%DeepSee.UserLibrary.FolderItem).%ComposeOid(id)
63-
do ##class(%DeepSee.UserLibrary.FolderItem).%OnDetermineClass(oid, .class)
64-
return:class'=..#dashclass $$$NO
65-
66-
/// second that it's not a hidden or deleted dashboard
67-
set folder = ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)
68-
set folderpath = ##class(%DeepSee.UserLibrary.Folder).%GetFullName(folder)
69-
return:(($extract(folderpath,1,6)="$TRASH") || ($extract(folderpath,1,6)="$TRASH")) $$$NO
70-
71-
/// third we check if a dashboard is in a correct folder
72-
return:($extract(folderpath,1,$length(..folder))'=..folder) $$$NO
73-
74-
/// fourth we check if the user has access to a dashboard
75-
return:'..CheckItemResource(id) $$$NO
76-
77-
return $$$YES
78-
}
79-
80-
/// Get dashboard full name by id
81-
ClassMethod GetDashFullName(id As %String)
82-
{
83-
set folder = ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)
84-
set name = ##class(%DeepSee.UserLibrary.FolderItem).nameGetStored(id)
85-
return ##class(%DeepSee.Dashboard.Definition).fullNameCompute(id, folder, name)
86-
}
87-
88-
/// Test if the current user has access to this item.
89-
ClassMethod CheckItemResource(id As %String, privilege As %String = "USE") As %Boolean
90-
{
91-
set access = $$$NO
92-
set resource = ..GetItemResource(id)
93-
if ((resource="")||($System.Security.Check(resource, privilege))) {
94-
set access = $$$YES
95-
}
96-
return access
97-
}
98-
99-
/// Get the resource value for this item.
100-
ClassMethod GetItemResource(id As %String) As %String
101-
{
102-
set resource = ##class(%DeepSee.UserLibrary.FolderItem).resourceGetStored(id)
103-
if (resource="") {
104-
// inherit from folder
105-
if ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)'="" {
106-
set resource = ..GetFolderResource(##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id))
107-
}
108-
}
109-
return resource
110-
}
111-
112-
/// Get the resource value for this folder.
113-
ClassMethod GetFolderResource(folderId As %String) As %String
114-
{
115-
if (##class(%DeepSee.UserLibrary.Folder).resourceGetStored(folderId)'="") {
116-
return ##class(%DeepSee.UserLibrary.Folder).resourceGetStored(folderId)
117-
} elseif (##class(%DeepSee.UserLibrary.Folder).folderGetStored(folderId)'="") {
118-
return ..GetFolderResource(##class(%DeepSee.UserLibrary.Folder).folderGetStored(folderId))
119-
}
120-
return ""
121-
}
122-
123-
/// Get all dashes from SAMPLES namespace
124-
/// do ##class(MDX2JSON.DashboardRS).Test()
125-
ClassMethod Test(folderName As %String = "")
126-
{
127-
new $namespace
128-
set $namespace = "Samples"
129-
set rs = ..%New(,folderName)
130-
do rs.%Display()
131-
}
132-
133-
/// Execute query and output results as JSON
134-
ClassMethod WriteJSON(folderName As %String = "")
135-
{
136-
#define CRLF $c(13,10)
137-
#define ZENJSISNUM(%val) ($IsValidNum(%val)&&(%val=+(%val)))
138-
#define ZENJSNUM(%num) $fnumber(%num,"LON")
139-
#; JSON utility macros that use the JSON translation table instead of the JS translation table
140-
#define ZENJSTABLE(%format) ("JS"_$S(%format["u":"ML",1:""))
141-
#define ZENJSONTABLE(%format) ("JSON"_$S((%format["u"):"ML",1:""))
142-
#define ZENJSONESCAPE(%str,%format) $S(%format["s":$ZCVT(%str,"O",$$$ZENJSONTABLE(%format)),1:$Replace($ZCVT(%str,"O",$$$ZENJSTABLE(%format)),"\'","'"))
143-
#define ZENJSONSTR(%str,%format) (""""_$$$ZENJSONESCAPE(%str,%format)_"""")
144-
#define ZENJSONPROP(%prop,%format) $$$ZENJSONSTR(%prop,%format)
145-
#define ZENJSONVALUE(%val,%format) $S($$$ZENJSISNUM(%val):$$$ZENJSNUM(%val),$C(0)=(%val)||$ListValid(%val):"""""",1:$$$ZENJSONSTR(%val,%format))
146-
#define ZENJSONPAIR(%pr,%val,%format) $$$ZENJSONPROP(%pr,%format)_":"_$$$ZENJSONVALUE(%val,%format)
147-
148-
set rs = ..%New(,folderName)
149-
write "{ ""children"":["
150-
set separator=0
151-
while rs.%Next() {
152-
write:separator ",",$$$CRLF
153-
write "{"
154-
write $$$ZENJSONPAIR("title",rs.title,""),","
155-
write $$$ZENJSONPAIR("path",rs.path,""),","
156-
write $$$ZENJSONPAIR("Cover",rs.cover,"")
157-
write "}"
158-
159-
set separator = 1
160-
}
161-
write "]}"
162-
}
163-
164-
}
1+
/// Custom result set to get dashboard list, visible to user in a specific folder
2+
Class MDX2JSON.DashboardRS Extends %SQL.CustomResultSet
3+
{
4+
5+
Parameter global = "^DeepSee.FolderItemD";
6+
7+
Parameter dashclass = "%DeepSee.Dashboard.Definition";
8+
9+
Property title As %String;
10+
11+
Property path As %String;
12+
13+
Property cover As %String;
14+
15+
Property id As %String [ Private ];
16+
17+
Property folder As %String [ Private ];
18+
19+
Method %OpenCursor(folderName As %String = "") As %Status
20+
{
21+
return:((folderName'="") && ('$IsObject(##class(%DeepSee.UserLibrary.Utils).%FindFolder(folderName)))) $$$ERROR($$$GeneralError,"Folder " _ folderName _ " does not exist")
22+
set ..id = ""
23+
set ..folder = folderName
24+
return $$$OK
25+
}
26+
27+
Method %Next(ByRef sc As %Library.Status) As %Integer [ PlaceAfter = %Execute ]
28+
{
29+
set sc = $$$OK
30+
do ..SetNextId()
31+
set id = ..id
32+
return:id="" $$$NO
33+
34+
set title = ##class(%DeepSee.UserPortal.Utils).%ResolveText(##class(%DeepSee.UserLibrary.FolderItem).titleGetStored(id))
35+
// While empty Title use Name instead
36+
set:(title="") title = ##class(%DeepSee.UserPortal.Utils).%ResolveText(##class(%DeepSee.UserLibrary.FolderItem).nameGetStored(id))
37+
38+
set ..title = title
39+
set ..path = ..GetDashFullName(id)
40+
set ..cover = ##class(MDX2JSON.Dashboard).GetDashCover(##class(%DeepSee.UserLibrary.FolderItem).bookCoverGetStored(id))
41+
42+
return $$$YES
43+
}
44+
45+
/// Iterate over data global till we find dashboard definition
46+
/// thet satisfies all conditions
47+
Method SetNextId()
48+
{
49+
set ..id = $order(@..#global@(..id))
50+
if ((..id'="") && ('..CheckConditions(..id))) {
51+
// we are not at the last row and we failed condition check
52+
// so we get the next id
53+
do ..SetNextId()
54+
}
55+
}
56+
57+
/// Check if element with that id satisfies our conditions
58+
Method CheckConditions(id) As %Boolean
59+
{
60+
/// first we check that it's a dashboard (not a pivot, etc.)
61+
set oid = ##class(%DeepSee.UserLibrary.FolderItem).%ComposeOid(id)
62+
do ##class(%DeepSee.UserLibrary.FolderItem).%OnDetermineClass(oid, .class)
63+
return:class'=..#dashclass $$$NO
64+
65+
/// second that it's not a hidden or deleted dashboard
66+
set folder = ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)
67+
set folderpath = ##class(%DeepSee.UserLibrary.Folder).%GetFullName(folder)
68+
return:(($extract(folderpath,1,6)="$TRASH") || ($extract(folderpath,1,6)="$TRASH")) $$$NO
69+
70+
/// third we check if a dashboard is in a correct folder
71+
return:($extract(folderpath,1,$length(..folder))'=..folder) $$$NO
72+
73+
/// fourth we check if the user has access to a dashboard
74+
return:'..CheckItemResource(id) $$$NO
75+
76+
return $$$YES
77+
}
78+
79+
/// Get dashboard full name by id
80+
ClassMethod GetDashFullName(id As %String)
81+
{
82+
set folder = ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)
83+
set name = ##class(%DeepSee.UserLibrary.FolderItem).nameGetStored(id)
84+
return ##class(%DeepSee.Dashboard.Definition).fullNameCompute(id, folder, name)
85+
}
86+
87+
/// Test if the current user has access to this item.
88+
ClassMethod CheckItemResource(id As %String, privilege As %String = "USE") As %Boolean
89+
{
90+
set access = $$$NO
91+
set resource = ..GetItemResource(id)
92+
if ((resource="")||($System.Security.Check(resource, privilege))) {
93+
set access = $$$YES
94+
}
95+
return access
96+
}
97+
98+
/// Get the resource value for this item.
99+
ClassMethod GetItemResource(id As %String) As %String
100+
{
101+
set resource = ##class(%DeepSee.UserLibrary.FolderItem).resourceGetStored(id)
102+
if (resource="") {
103+
// inherit from folder
104+
if ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)'="" {
105+
set resource = ..GetFolderResource(##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id))
106+
}
107+
}
108+
return resource
109+
}
110+
111+
/// Get the resource value for this folder.
112+
ClassMethod GetFolderResource(folderId As %String) As %String
113+
{
114+
if (##class(%DeepSee.UserLibrary.Folder).resourceGetStored(folderId)'="") {
115+
return ##class(%DeepSee.UserLibrary.Folder).resourceGetStored(folderId)
116+
} elseif (##class(%DeepSee.UserLibrary.Folder).folderGetStored(folderId)'="") {
117+
return ..GetFolderResource(##class(%DeepSee.UserLibrary.Folder).folderGetStored(folderId))
118+
}
119+
return ""
120+
}
121+
122+
/// Get all dashes from SAMPLES namespace
123+
/// do ##class(MDX2JSON.DashboardRS).Test()
124+
ClassMethod Test(folderName As %String = "")
125+
{
126+
new $namespace
127+
set $namespace = "Samples"
128+
set rs = ..%New(,folderName)
129+
do rs.%Display()
130+
}
131+
132+
/// Execute query and output results as JSON
133+
ClassMethod WriteJSON(folderName As %String = "")
134+
{
135+
#define CRLF $c(13,10)
136+
#define ZENJSISNUM(%val) ($IsValidNum(%val)&&(%val=+(%val)))
137+
#define ZENJSNUM(%num) $fnumber(%num,"LON")
138+
#; JSON utility macros that use the JSON translation table instead of the JS translation table
139+
#define ZENJSTABLE(%format) ("JS"_$S(%format["u":"ML",1:""))
140+
#define ZENJSONTABLE(%format) ("JSON"_$S((%format["u"):"ML",1:""))
141+
#define ZENJSONESCAPE(%str,%format) $S(%format["s":$ZCVT(%str,"O",$$$ZENJSONTABLE(%format)),1:$Replace($ZCVT(%str,"O",$$$ZENJSTABLE(%format)),"\'","'"))
142+
#define ZENJSONSTR(%str,%format) (""""_$$$ZENJSONESCAPE(%str,%format)_"""")
143+
#define ZENJSONPROP(%prop,%format) $$$ZENJSONSTR(%prop,%format)
144+
#define ZENJSONVALUE(%val,%format) $S($$$ZENJSISNUM(%val):$$$ZENJSNUM(%val),$C(0)=(%val)||$ListValid(%val):"""""",1:$$$ZENJSONSTR(%val,%format))
145+
#define ZENJSONPAIR(%pr,%val,%format) $$$ZENJSONPROP(%pr,%format)_":"_$$$ZENJSONVALUE(%val,%format)
146+
147+
set rs = ..%New(,folderName)
148+
write "{ ""children"":["
149+
set separator=0
150+
while rs.%Next() {
151+
write:separator ",",$$$CRLF
152+
write "{"
153+
write $$$ZENJSONPAIR("title",rs.title,""),","
154+
write $$$ZENJSONPAIR("path",rs.path,""),","
155+
write $$$ZENJSONPAIR("Cover",rs.cover,"")
156+
write "}"
157+
158+
set separator = 1
159+
}
160+
write "]}"
161+
}
162+
163+
}

0 commit comments

Comments
 (0)