Skip to content

Commit 975ce77

Browse files
committed
Switched to sql approach for favorite namespaces
1 parent eac8de8 commit 975ce77

File tree

5 files changed

+42
-36
lines changed

5 files changed

+42
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

1717
### Fixed
1818
- Fixed display of other users' username in workspace view on Unix (#530)
19-
- Fixed GetContexts utils function to return namespaces for WebUI (#468)
2019
- Fixed slowness loading some CSP pages with multiple instances sharing a webserver (#540)
20+
- Fixed GetContexts utils function to exclude implied namespaces from the list of namespaces(#468)
2121

2222
## [2.6.0] - 2024-10-07
2323

cls/SourceControl/Git/Settings.cls

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Property environmentName As %String(MAXLEN = "") [ InitialExpression = {##class(
5858

5959
Property Mappings [ MultiDimensional ];
6060

61-
Property favoriteNamespaces As %String [ InitialExpression = {##class(SourceControl.Git.Utils).FavoriteNamespaces()} ];
61+
Property favoriteNamespaces As %DynamicArray;
6262

6363
Method %OnNew() As %Status
6464
{
@@ -71,10 +71,7 @@ Method %OnNew() As %Status
7171
if ('isDefault) {
7272
set ..gitBinPath = gitBinPath
7373
}
74-
if ..favoriteNamespaces= "" {
75-
set namespaces = ##class(SourceControl.Git.Utils).GetContexts(1)
76-
set ..favoriteNamespaces = namespaces.%ToJSON()
77-
}
74+
set ..favoriteNamespaces = ##class(SourceControl.Git.Utils).FavoriteNamespaces()
7875
quit $$$OK
7976
}
8077

cls/SourceControl/Git/Utils.cls

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ $Get(@..#Storage@("settings","settingsUIReadOnly"), 0)
7474

7575
ClassMethod FavoriteNamespaces() As %String
7676
{
77-
quit $get(@..#Storage@("settings", "user", $username, "favNamespaces"),"")
77+
set favNamespaces = []
78+
do ..GetFavoriteNamespaces(.favNamespaces,[])
79+
return favNamespaces
7880
}
7981

8082
/// Returns the current (or previous) value of the flag.
@@ -2841,19 +2843,8 @@ ClassMethod SetConfiguredRemote(url) As %String
28412843
quit output
28422844
}
28432845

2844-
ClassMethod ConfigureFavoriteNamespaces(username As %String, favNamespaces As %String)
2846+
ClassMethod ConfigureFavoriteNamespaces(username As %String, newNamespaces As %String)
28452847
{
2846-
set newNamespaces = [].%FromJSON(favNamespaces)
2847-
set namespaces = ..GetContexts(1)
2848-
2849-
set iterator = namespaces.%GetIterator()
2850-
while iterator.%GetNext(.key, .value) {
2851-
new $Namespace
2852-
set $Namespace = value
2853-
kill @..#Storage@("settings", "user", $username, "favNamespaces")
2854-
set @..#Storage@("settings", "user", $username, "favNamespaces") = favNamespaces
2855-
}
2856-
28572848
// Delete all the GIT favorite links for the user
28582849
set iterator = newNamespaces.%GetIterator()
28592850
while iterator.%GetNext(.key, .value) {
@@ -2882,4 +2873,20 @@ ClassMethod ConfigureFavoriteNamespaces(username As %String, favNamespaces As %S
28822873
}
28832874
}
28842875

2876+
ClassMethod GetFavoriteNamespaces(ByRef favNamespaces As %DynamicArray, ByRef nonFavNamespaces As %DynamicArray) {
2877+
set allNamespaces = ..GetContexts(1)
2878+
set iterator = allNamespaces.%GetIterator()
2879+
2880+
while iterator.%GetNext(.key, .value) {
2881+
set sql = "select * from %SYS_Portal.Users where username='"_$username_"' and page='Git: "_value_"'"
2882+
set statement = ##class(%SQL.Statement).%New()
2883+
set res = ##class(%SQL.Statement).%ExecDirect(statement,sql)
2884+
if (res.%Next()) {
2885+
do favNamespaces.%Push(value)
2886+
} else {
2887+
do nonFavNamespaces.%Push(value)
2888+
}
2889+
}
2890+
}
2891+
28852892
}

csp/gitprojectsettings.csp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ body {
130130
}
131131
set i = i+1
132132
}
133+
134+
set i = 1
135+
set contexts = []
136+
137+
while ( $Data(%request.Data("favNamespace",i)) ){
138+
if ($Get(%request.Data("favNamespace",i)) '= "") {
139+
do contexts.%Push($Get(%request.Data("favNamespace",i)))
140+
}
141+
set i = i+1
142+
}
143+
144+
set settings.favoriteNamespaces = contexts
133145
}
134146
do settings.%Save()
135147
}
@@ -569,23 +581,14 @@ body {
569581
<div class="col-sm-7">
570582
<select multiple class="form-control" id="addToFav" name="favNamespace">
571583
<server>
572-
set contextList = ##class(SourceControl.Git.Utils).GetContexts(1)
573-
set selectedNamespaces = [].%FromJSON(settings.favoriteNamespaces)
584+
set nonFavNamespaces = []
585+
set selectedNamespaces = []
586+
do ##class(SourceControl.Git.Utils).GetFavoriteNamespaces(.selectedNamespaces,.nonFavNamespaces)
574587
set iterator = selectedNamespaces.%GetIterator()
575588
while iterator.%GetNext(.key, .value) {
576589
&html<<option selected value=#(value)#>#(value)#</option>>
577-
set k = -1
578-
set citerator = contextList.%GetIterator()
579-
while citerator.%GetNext(.ckey, .cvalue) {
580-
if (cvalue = value) {
581-
set k = ckey
582-
}
583-
}
584-
if (k > -1) {
585-
do contextList.%Remove(k)
586-
}
587590
}
588-
set iterator = contextList.%GetIterator()
591+
set iterator = nonFavNamespaces.%GetIterator()
589592
while iterator.%GetNext(.key, .value) {
590593
&html<<option value=#(value)#>#(value)#</option>>
591594
}

csp/pull.csp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<body>
1212
<pre for="contextSelect" style="padding-top: 2em;white-space: pre-wrap;">Change Context: <select id="newContext" onchange="updateContext()">
1313
<server>
14+
set $NAMESPACE = %request.Data("$NAMESPACE",1)
1415
set contextList = ##class(SourceControl.Git.Utils).GetContexts(1)
1516
set iterator = contextList.%GetIterator()
1617
&html<<option>Select</option>>
@@ -57,10 +58,8 @@ function execute() {
5758
}
5859

5960
function updateContext() {
60-
const contextSelect = document.getElementById('newContext');
61-
const selectedContext = contextSelect.value;
62-
63-
window.location.href = "/isc/studio/usertemplates/gitsourcecontrol/pull.csp?$NAMESPACE=" + selectedContext;
61+
var contextSelect = document.getElementById('newContext');
62+
window.location.href = "#(%request.URLPrefix)#/isc/studio/usertemplates/gitsourcecontrol/pull.csp?$NAMESPACE=" + contextSelect.value;
6463
}
6564

6665
preview();

0 commit comments

Comments
 (0)