Skip to content

Simplify favorites and landing page for multi-namespace setup #538

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 17 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added 'git push --force' in expert mode (#527)
- Add remote repository to settings page (#448)
- Added change context option to pull page (#468)
- Added favorite namespaces setting for a user (#468, #510)
- Added environment awareness in configuration, and showing of environment name in UI (#124)

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

## [2.6.0] - 2024-10-07

Expand Down
8 changes: 7 additions & 1 deletion cls/SourceControl/Git/Settings.cls
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Property environmentName As %String(MAXLEN = "") [ InitialExpression = {##class(

Property Mappings [ MultiDimensional ];

Property favoriteNamespaces As %DynamicArray;

Method %OnNew() As %Status
{
set mappingsNode = ##class(SourceControl.Git.Utils).MappingsNode()
Expand All @@ -69,6 +71,7 @@ Method %OnNew() As %Status
if ('isDefault) {
set ..gitBinPath = gitBinPath
}
set ..favoriteNamespaces = ##class(SourceControl.Git.Utils).FavoriteNamespaces()
quit $$$OK
}

Expand Down Expand Up @@ -130,9 +133,11 @@ Method %Save() As %Status
// update value of basicUserMode to reflect the updated setting for basicMode
set ..userBasicMode = ##class(SourceControl.Git.Utils).UserBasicMode()


kill @##class(SourceControl.Git.Utils).MappingsNode()
merge @##class(SourceControl.Git.Utils).MappingsNode() = ..Mappings

do ##class(SourceControl.Git.Utils).ConfigureFavoriteNamespaces($username, ..favoriteNamespaces)

quit $$$OK
}

Expand Down Expand Up @@ -163,6 +168,7 @@ ClassMethod Configure() As %Boolean [ CodeMode = objectgenerator ]
set sequence = $order(orderedProperties(sequence),1,property)
quit:sequence=""
continue:property="userBasicMode"
continue:property="favoriteNamespaces"
do %code.WriteLine(" set value = inst."_property)
set prompt = $$$comMemberKeyGet(%class.Name,$$$cCLASSproperty,property,$$$cPROPdescription)
set promptQuoted = $$$QUOTE(prompt_":")
Expand Down
85 changes: 75 additions & 10 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ ClassMethod SettingsUIReadOnly() As %Status [ CodeMode = expression ]
$Get(@..#Storage@("settings","settingsUIReadOnly"), 0)
}

ClassMethod FavoriteNamespaces() As %String
{
set favNamespaces = []
do ..GetFavoriteNamespaces(.favNamespaces,[])
return favNamespaces
}

/// Returns the current (or previous) value of the flag.
ClassMethod Locked(newFlagValue As %Boolean) As %Boolean
{
Expand Down Expand Up @@ -2485,28 +2492,32 @@ ClassMethod Localize()
}
}

ClassMethod GetContexts() As %DynamicArray
ClassMethod GetContexts(onlyNamespaces As %Boolean) As %DynamicArray
{
set contexts = []
set namespaces = ..GetGitEnabledNamespaces()
set ptr = 0
while $listnext(namespaces,ptr,value) {
do contexts.%Push(value)
if '($FIND(value,"^^")){
do contexts.%Push(value)
}
}

set name = ""

// Using embedded for backwards compatability
&sql(DECLARE C1 CURSOR FOR SELECT name into :name from %Library.RoutineMgr_StudioOpenDialog('*.ZPM'))
&sql(OPEN C1)
throw:SQLCODE<0 ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE, %msg)
&sql(FETCH C1)
while(SQLCODE = 0) {
set package = name
do contexts.%Push(package)
if '(onlyNamespaces) {
&sql(DECLARE C1 CURSOR FOR SELECT name into :name from %Library.RoutineMgr_StudioOpenDialog('*.ZPM'))
&sql(OPEN C1)
throw:SQLCODE<0 ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE, %msg)
&sql(FETCH C1)
while(SQLCODE = 0) {
set package = name
do contexts.%Push(package)
&sql(FETCH C1)
}
&sql(CLOSE C1)
}
&sql(CLOSE C1)

return contexts
}
Expand Down Expand Up @@ -2832,4 +2843,58 @@ ClassMethod SetConfiguredRemote(url) As %String
quit output
}

ClassMethod ConfigureFavoriteNamespaces(username As %String, newNamespaces As %String)
{
// Delete all the GIT favorite links for the user
&sql(DELETE FROM %SYS_Portal.Users WHERE Username = :username AND Page LIKE '%Git%')

set iterator = newNamespaces.%GetIterator()
while iterator.%GetNext(.key, .value) {
set installNamespace = value

// Insert Git link
set caption = "Git: " _ installNamespace
set link = "/isc/studio/usertemplates/gitsourcecontrol/webuidriver.csp/" _ installNamespace _ "/"
&sql(INSERT OR UPDATE INTO %SYS_Portal.Users (Username, Page, Data) VALUES (:username, :caption, :link))

// Insert Git Pull link
set caption = "Git Pull: " _ installNamespace
set link = "/isc/studio/usertemplates/gitsourcecontrol/pull.csp?$NAMESPACE=" _ installNamespace
&sql(INSERT OR UPDATE INTO %SYS_Portal.Users (Username, Page, Data) VALUES (:username, :caption, :link))
}

// Update Security.Applications
&sql(UPDATE Security.Applications SET GroupById = '%ISCMgtPortal' WHERE ID = '/isc/studio/usertemplates')
}

ClassMethod GetFavoriteNamespaces(ByRef favNamespaces As %DynamicArray, ByRef nonFavNamespaces As %DynamicArray)
{
set allNamespaces = ..GetContexts(1)
set iterator = allNamespaces.%GetIterator()

set username = $USERNAME
set pagePrefix = "Git:"
&sql(DECLARE FavCursor CURSOR FOR SELECT Page into :page from %SYS_Portal.Users where username = :username and page %STARTSWITH :pagePrefix)

while iterator.%GetNext(.key, .value) {
set foundFlag = 0
&sql(OPEN FavCursor)
throw:SQLCODE<0 ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE, %msg)
&sql(FETCH FavCursor)
while (SQLCODE = 0) {
set pageValue = "Git: "_value
if (page = pageValue) {
do favNamespaces.%Push(value)
set foundFlag = 1
}
&sql(FETCH FavCursor)
}
&sql(CLOSE FavCursor)

if ('foundFlag) {
do nonFavNamespaces.%Push(value)
}
}
}

}
3 changes: 2 additions & 1 deletion cls/SourceControl/Git/WebUIDriver.cls
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
do discardsInBranch.%ToJSON(%data)
set handled = 1
} elseif (pathStart = "contexts") {
set contexts = ##class(SourceControl.Git.Utils).GetContexts()
set onlyNamespaces = %request.Data("onlyNamespaces", 1)
set contexts = ##class(SourceControl.Git.Utils).GetContexts(onlyNamespaces)
do contexts.%ToJSON(%data)
set handled = 1
}
Expand Down
1 change: 1 addition & 0 deletions cls/_zpkg/isc/sc/git/Socket.cls
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ClassMethod Run()
{
If %request.Get("method") = "preview" {
Set branchName = ##class(SourceControl.Git.Utils).GetCurrentBranch()
Write !,"Current namespace: ",$NAMESPACE
Write !,"Current branch: ",branchName
Do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "fetch")
Kill errStream, outStream
Expand Down
33 changes: 33 additions & 0 deletions csp/gitprojectsettings.csp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ body {
}
set i = i+1
}

set i = 1
set contexts = []

while ( $Data(%request.Data("favNamespace",i)) ){
if ($Get(%request.Data("favNamespace",i)) '= "") {
do contexts.%Push($Get(%request.Data("favNamespace",i)))
}
set i = i+1
}

set settings.favoriteNamespaces = contexts
}
do settings.%Save()
}
Expand Down Expand Up @@ -564,6 +576,27 @@ body {
</div> -->
</div>

<div class="form-group row mb-3">
<label for="addToFav" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Favorite namespaces for user to add link on Home page.">Favorite Namespaces</label>
<div class="col-sm-7">
<select multiple class="form-control" id="addToFav" name="favNamespace">
<server>
set nonFavNamespaces = []
set selectedNamespaces = []
do ##class(SourceControl.Git.Utils).GetFavoriteNamespaces(.selectedNamespaces,.nonFavNamespaces)
set iterator = selectedNamespaces.%GetIterator()
while iterator.%GetNext(.key, .value) {
&html<<option selected value=#(value)#>#(value)#</option>>
}
set iterator = nonFavNamespaces.%GetIterator()
while iterator.%GetNext(.key, .value) {
&html<<option value=#(value)#>#(value)#</option>>
}
</server>
</select>
<small> Hold the [Ctrl] or [Cmd] key while clicking to select multiple namespaces.</small>
</div>
</div>
<br/>
</fieldset>

Expand Down
17 changes: 17 additions & 0 deletions csp/pull.csp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
<link rel="stylesheet" type="text/css" href="css/git-webui.css" />
</head>
<body>
<pre for="contextSelect" style="padding-top: 2em;white-space: pre-wrap;height: 60px;">Change Context: <select id="newContext" onchange="updateContext()">
<server>
set $NAMESPACE = %request.Data("$NAMESPACE",1)
set contextList = ##class(SourceControl.Git.Utils).GetContexts(1)
set iterator = contextList.%GetIterator()
&html<<option>Select</option>>
while iterator.%GetNext(.key, .value) {
&html<<option value=#(value)#>#(value)#</option>>
}
</server>
</select>
</pre>
<pre id="preview" style="white-space: pre-wrap;">
</pre>
<button id="execute" onclick="execute()" disabled="true">Pull and Load Changes</button>
Expand Down Expand Up @@ -45,6 +57,11 @@ function execute() {
}
}

function updateContext() {
var contextSelect = document.getElementById('newContext');
window.location.href = "#(%request.URLPrefix)#/isc/studio/usertemplates/gitsourcecontrol/pull.csp?$NAMESPACE=" + contextSelect.value;
}

preview();
</script>
</body>
Expand Down
8 changes: 5 additions & 3 deletions git-webui/release/share/git-webui/webui/js/git-webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,8 @@ webui.SideBarView = function(mainView, noEventHandlers) {
});
};

self.changeContextGet = function() {
$.get("contexts", function(contextList) {
self.changeContextGet = function(onlyNamespaces) {
$.get("contexts", { "onlyNamespaces": onlyNamespaces }, function(contextList) {
var contexts = JSON.parse(contextList);
self.changeContext(contexts);
});
Expand Down Expand Up @@ -1050,7 +1050,9 @@ webui.SideBarView = function(mainView, noEventHandlers) {
$(".btn-add", self.element).click(self.createNewLocalBranch);
$('.btn-prune-remote-branches', self.element).click(self.pruneRemoteBranches);
$("#sidebar-settings", self.element).click(self.goToSettingsPage);
$("#sidebar-context", self.element).click(self.changeContextGet);
$("#sidebar-context", self.element).click(function() {
self.changeContextGet(0);
});
$("#sidebar-home", self.element).click(self.goToHomePage);
}

Expand Down
8 changes: 5 additions & 3 deletions git-webui/src/share/git-webui/webui/js/git-webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,8 @@ webui.SideBarView = function(mainView, noEventHandlers) {
});
};

self.changeContextGet = function() {
$.get("contexts", function(contextList) {
self.changeContextGet = function(onlyNamespaces) {
$.get("contexts", { "onlyNamespaces": onlyNamespaces }, function(contextList) {
var contexts = JSON.parse(contextList);
self.changeContext(contexts);
});
Expand Down Expand Up @@ -1050,7 +1050,9 @@ webui.SideBarView = function(mainView, noEventHandlers) {
$(".btn-add", self.element).click(self.createNewLocalBranch);
$('.btn-prune-remote-branches', self.element).click(self.pruneRemoteBranches);
$("#sidebar-settings", self.element).click(self.goToSettingsPage);
$("#sidebar-context", self.element).click(self.changeContextGet);
$("#sidebar-context", self.element).click(function() {
self.changeContextGet(0);
});
$("#sidebar-home", self.element).click(self.goToHomePage);
}

Expand Down
Loading