forked from eduard93/Cache-MDX2JSON
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathDashboardRS.cls.xml
More file actions
219 lines (194 loc) · 6.98 KB
/
DashboardRS.cls.xml
File metadata and controls
219 lines (194 loc) · 6.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?xml version="1.0" encoding="UTF-8"?>
<Export generator="IRIS" version="26">
<Class name="MDX2JSON.DashboardRS">
<Description>
Custom result set to get dashboard list, visible to user in a specific folder</Description>
<Super>%SQL.CustomResultSet</Super>
<TimeCreated>63943,47866.588743</TimeCreated>
<Parameter name="global">
<Default>^DeepSee.FolderItemD</Default>
</Parameter>
<Parameter name="dashclass">
<Default>%DeepSee.Dashboard.Definition</Default>
</Parameter>
<Property name="title">
<Type>%String</Type>
</Property>
<Property name="path">
<Type>%String</Type>
</Property>
<Property name="cover">
<Type>%String</Type>
</Property>
<Property name="id">
<Type>%String</Type>
<Private>1</Private>
</Property>
<Property name="folder">
<Type>%String</Type>
<Private>1</Private>
</Property>
<Method name="%OpenCursor">
<FormalSpec>folderName:%String=""</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
return:((folderName'="") && ('$IsObject(##class(%DeepSee.UserLibrary.Utils).%FindFolder(folderName)))) $$$ERROR($$$GeneralError,"Folder " _ folderName _ " does not exist")
set ..id = ""
set ..folder = folderName
return $$$OK
]]></Implementation>
</Method>
<Method name="%Next">
<FormalSpec><![CDATA[&sc:%Library.Status]]></FormalSpec>
<PlaceAfter>%Execute</PlaceAfter>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[
set sc = $$$OK
do ..SetNextId()
set id = ..id
return:id="" $$$NO
set ..title = ##class(%DeepSee.UserPortal.Utils).%ResolveText(##class(%DeepSee.UserLibrary.FolderItem).titleGetStored(id))
set ..path = ..GetDashFullName(id)
set ..cover = ##class(MDX2JSON.Dashboard).GetDashCover(##class(%DeepSee.UserLibrary.FolderItem).bookCoverGetStored(id))
return $$$YES
]]></Implementation>
</Method>
<Method name="SetNextId">
<Description>
Iterate over data global till we find dashboard definition
thet satisfies all conditions</Description>
<Implementation><![CDATA[
set ..id = $order(@..#global@(..id))
if ((..id'="") && ('..CheckConditions(..id))) {
// we are not at the last row and we failed condition check
// so we get the next id
do ..SetNextId()
}
]]></Implementation>
</Method>
<Method name="CheckConditions">
<Description>
Check if element with that id satisfies our conditions</Description>
<FormalSpec>id</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
/// first we check that it's a dashboard (not a pivot, etc.)
set oid = ##class(%DeepSee.UserLibrary.FolderItem).%ComposeOid(id)
do ##class(%DeepSee.UserLibrary.FolderItem).%OnDetermineClass(oid, .class)
return:class'=..#dashclass $$$NO
/// second that it's not a hidden or deleted dashboard
set folder = ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)
set folderpath = ##class(%DeepSee.UserLibrary.Folder).%GetFullName(folder)
return:(($extract(folderpath,1,6)="$TRASH") || ($extract(folderpath,1,6)="$TRASH")) $$$NO
/// third we check if a dashboard is in a correct folder
return:($extract(folderpath,1,$length(..folder))'=..folder) $$$NO
/// fourth we check if the user has access to a dashboard
return:'..CheckItemResource(id) $$$NO
return $$$YES
]]></Implementation>
</Method>
<Method name="GetDashFullName">
<Description>
Get dashboard full name by id</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>id:%String</FormalSpec>
<Implementation><![CDATA[
set folder = ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)
set name = ##class(%DeepSee.UserLibrary.FolderItem).nameGetStored(id)
return ##class(%DeepSee.Dashboard.Definition).fullNameCompute(id, folder, name)
]]></Implementation>
</Method>
<Method name="CheckItemResource">
<Description>
Test if the current user has access to this item.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>id:%String,privilege:%String="USE"</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
set access = $$$NO
set resource = ..GetItemResource(id)
if ((resource="")||($System.Security.Check(resource, privilege))) {
set access = $$$YES
}
return access
]]></Implementation>
</Method>
<Method name="GetItemResource">
<Description>
Get the resource value for this item.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>id:%String</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
set resource = ##class(%DeepSee.UserLibrary.FolderItem).resourceGetStored(id)
if (resource="") {
// inherit from folder
if ##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id)'="" {
set resource = ..GetFolderResource(##class(%DeepSee.UserLibrary.FolderItem).folderGetStored(id))
}
}
return resource
]]></Implementation>
</Method>
<Method name="GetFolderResource">
<Description>
Get the resource value for this folder.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>folderId:%String</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
if (##class(%DeepSee.UserLibrary.Folder).resourceGetStored(folderId)'="") {
return ##class(%DeepSee.UserLibrary.Folder).resourceGetStored(folderId)
} elseif (##class(%DeepSee.UserLibrary.Folder).folderGetStored(folderId)'="") {
return ..GetFolderResource(##class(%DeepSee.UserLibrary.Folder).folderGetStored(folderId))
}
return ""
]]></Implementation>
</Method>
<Method name="Test">
<Description>
Get all dashes from SAMPLES namespace
do ##class(MDX2JSON.DashboardRS).Test()</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>folderName:%String=""</FormalSpec>
<Implementation><![CDATA[
new $namespace
set $namespace = "Samples"
set rs = ..%New(,folderName)
do rs.%Display()
]]></Implementation>
</Method>
<Method name="WriteJSON">
<Description>
Execute query and output results as JSON</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>folderName:%String=""</FormalSpec>
<Implementation><![CDATA[
#define CRLF $c(13,10)
#define ZENJSISNUM(%val) ($IsValidNum(%val)&&(%val=+(%val)))
#define ZENJSNUM(%num) $fnumber(%num,"LON")
#; JSON utility macros that use the JSON translation table instead of the JS translation table
#define ZENJSTABLE(%format) ("JS"_$S(%format["u":"ML",1:""))
#define ZENJSONTABLE(%format) ("JSON"_$S((%format["u"):"ML",1:""))
#define ZENJSONESCAPE(%str,%format) $S(%format["s":$ZCVT(%str,"O",$$$ZENJSONTABLE(%format)),1:$Replace($ZCVT(%str,"O",$$$ZENJSTABLE(%format)),"\'","'"))
#define ZENJSONSTR(%str,%format) (""""_$$$ZENJSONESCAPE(%str,%format)_"""")
#define ZENJSONPROP(%prop,%format) $$$ZENJSONSTR(%prop,%format)
#define ZENJSONVALUE(%val,%format) $S($$$ZENJSISNUM(%val):$$$ZENJSNUM(%val),$C(0)=(%val)||$ListValid(%val):"""""",1:$$$ZENJSONSTR(%val,%format))
#define ZENJSONPAIR(%pr,%val,%format) $$$ZENJSONPROP(%pr,%format)_":"_$$$ZENJSONVALUE(%val,%format)
set rs = ..%New(,folderName)
write "{ ""children"":["
set separator=0
while rs.%Next() {
write:separator ",",$$$CRLF
write "{"
write $$$ZENJSONPAIR("title",rs.title,""),","
write $$$ZENJSONPAIR("path",rs.path,""),","
write $$$ZENJSONPAIR("Cover",rs.cover,"")
write "}"
set separator = 1
}
write "]}"
]]></Implementation>
</Method>
</Class>
</Export>