Skip to content

Commit d667d18

Browse files
committed
fix #33 - avoid <SUBSCRIPT> error
1 parent e1fda8f commit d667d18

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

build-for-zpm/ClassExplorer/ClassView.cls

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,25 @@ ClassMethod getBaseOData(packageName As %String, baseNamespace As %String, saved
321321

322322
set ns = $namespace
323323
zn baseNamespace
324-
if $get(^ClassExplorer("savedView", ns_":"_savedName)) '= "" {
325-
set oData.savedView = $get(^ClassExplorer("savedView", ns_":"_savedName))
324+
set shortName = ..shortenSavedName(ns_":"_savedName)
325+
if $get(^ClassExplorer("savedView", shortName)) '= "" {
326+
set oData.savedView = $get(^ClassExplorer("savedView", shortName))
326327
}
327328
zn ns
328329

329330
quit oData
330331
}
331332

333+
/// Shorten the saved name to avoid SUBSCRIPT errors when saving into ^ClassExplorer
334+
ClassMethod shortenSavedName(savedName as %String) As %String [ Internal ]
335+
{
336+
// this is not watertight, but should be sufficient for this use case
337+
if $l(savedName)>100 {
338+
return $e(savedName, 1, 100) _ $zcrc(savedName, 7)
339+
}
340+
return savedName
341+
}
342+
332343
/// Returns if class with given name exists.
333344
ClassMethod classExists(className As %String) As %Boolean
334345
{

build-for-zpm/ClassExplorer/Router.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ClassMethod SaveView() As %Status
4242
{
4343
set name = %request.Get("name")
4444
set content = %request.Content.Read($$$MaxStringLength) // ~ 7mb
45-
set ^ClassExplorer("savedView", name) = content
45+
set ^ClassExplorer("savedView", ##class(ClassExplorer.ClassView).shortenSavedName(name)) = content
4646
write "{""OK"":true}"
4747
return $$$OK
4848
}
@@ -51,7 +51,7 @@ ClassMethod SaveView() As %Status
5151
ClassMethod ResetView() As %Status
5252
{
5353
set name = %request.Get("name")
54-
kill ^ClassExplorer("savedView", name)
54+
kill ^ClassExplorer("savedView", ##class(ClassExplorer.ClassView).shortenSavedName(name))
5555
write "{""OK"":true}"
5656
return $$$OK
5757
}

src/cls/ClassExplorer/ClassView.cls

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,25 @@ ClassMethod getBaseOData(packageName As %String, baseNamespace As %String, saved
321321

322322
set ns = $namespace
323323
zn baseNamespace
324-
if $get(^ClassExplorer("savedView", ns_":"_savedName)) '= "" {
325-
set oData.savedView = $get(^ClassExplorer("savedView", ns_":"_savedName))
324+
set shortName = ..shortenSavedName(ns_":"_savedName)
325+
if $get(^ClassExplorer("savedView", shortName)) '= "" {
326+
set oData.savedView = $get(^ClassExplorer("savedView", shortName))
326327
}
327328
zn ns
328329

329330
quit oData
330331
}
331332

333+
/// Shorten the saved name to avoid SUBSCRIPT errors when saving into ^ClassExplorer
334+
ClassMethod shortenSavedName(savedName as %String) As %String [ Internal ]
335+
{
336+
// this is not watertight, but should be sufficient for this use case
337+
if $l(savedName)>100 {
338+
return $e(savedName, 1, 100) _ $zcrc(savedName, 7)
339+
}
340+
return savedName
341+
}
342+
332343
/// Returns if class with given name exists.
333344
ClassMethod classExists(className As %String) As %Boolean
334345
{

src/cls/ClassExplorer/Router.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ClassMethod SaveView() As %Status
4242
{
4343
set name = %request.Get("name")
4444
set content = %request.Content.Read($$$MaxStringLength) // ~ 7mb
45-
set ^ClassExplorer("savedView", name) = content
45+
set ^ClassExplorer("savedView", ##class(ClassExplorer.ClassView).shortenSavedName(name)) = content
4646
write "{""OK"":true}"
4747
return $$$OK
4848
}
@@ -51,7 +51,7 @@ ClassMethod SaveView() As %Status
5151
ClassMethod ResetView() As %Status
5252
{
5353
set name = %request.Get("name")
54-
kill ^ClassExplorer("savedView", name)
54+
kill ^ClassExplorer("savedView", ##class(ClassExplorer.ClassView).shortenSavedName(name))
5555
write "{""OK"":true}"
5656
return $$$OK
5757
}

0 commit comments

Comments
 (0)