Skip to content

Commit 14c0ba7

Browse files
committed
feat: context can be changed in UI
1 parent c4b70c1 commit 14c0ba7

File tree

4 files changed

+112
-14
lines changed

4 files changed

+112
-14
lines changed

cls/SourceControl/Git/Utils.cls

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,16 +2356,21 @@ ClassMethod NamespacesClose(ByRef qHandle As %Binary) As %Status [ PlaceAfter =
23562356

23572357
ClassMethod GetContexts() As %DynamicArray
23582358
{
2359-
set namespaces = []
2359+
set contexts = []
23602360
set namespacesResultSet = ..NamespacesFunc()
23612361
while namespacesResultSet.%Next() {
23622362
set namespace = namespacesResultSet.Namespace
23632363
if namespacesResultSet.GitSourceControl && namespacesResultSet.Accessible {
2364-
do namespaces.%Push(namespace)
2364+
do contexts.%Push(namespace)
23652365
}
23662366
}
23672367

2368-
return namespaces
2368+
set packagesResultSet = ##class(%SQL.Statement).%ExecDirect(, "SELECT name from %Library.RoutineMgr_StudioOpenDialog('*.ZPM')")
2369+
while packagesResultSet.%Next() {
2370+
set package = packagesResultSet.Name
2371+
do contexts.%Push(package)
2372+
}
2373+
return contexts
23692374
}
23702375

23712376
ClassMethod ConfigureWeb()

cls/SourceControl/Git/WebUIDriver.cls

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
2020
set responseJSON = ..GetSettingsURL(%request)
2121
} elseif $extract(pagePath, 6, *) = "get-package-version"{
2222
set responseJSON = ..GetPackageVersion()
23+
} elseif $extract(pagePath, 6, *) = "namespace"{
24+
set responseJSON = $NAMESPACE
2325
} else {
2426
set %response.Status = ##class(%CSP.REST).#HTTP404NOTFOUND
2527
set responseJSON = {"error":("invalid URI: " _ pagePath)}
@@ -78,7 +80,8 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
7880
set handled = 1
7981
} elseif (pathStart = "contexts") {
8082
set contexts = ##class(SourceControl.Git.Utils).GetContexts()
81-
83+
do contexts.%ToJSON(%data)
84+
set handled = 1
8285
}
8386
} elseif (%request.Method = "POST") {
8487
// Things not handled from Python backend:

git-webui/release/share/git-webui/webui/js/git-webui.js

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,15 @@ webui.SideBarView = function(mainView, noEventHandlers) {
504504
})
505505
}
506506

507-
self.changeContext = function() {
507+
self.changeContextGet = function() {
508+
$.get("contexts", function(contextList) {
509+
var contexts = JSON.parse(contextList);
510+
self.changeContext(contexts);
511+
});
512+
}
513+
514+
self.changeContext = function(contexts) {
515+
508516
function removePopup(popup) {
509517
$(popup).children(".modal-fade").modal("hide");
510518
$(".modal-backdrop").remove();
@@ -533,12 +541,20 @@ webui.SideBarView = function(mainView, noEventHandlers) {
533541
$(
534542
'<div class="">'+
535543
'<h6>Select context for Git Source Control</h6>' +
536-
'<select class="custom-select">'+
537-
'<option selected>context!</option>' +
544+
'<select id="chosenContext" class="custom-select">'+
538545
'</select>' +
539546
'</div>'
540547
).appendTo(popupBody);
541548

549+
var selectDropdown = $(".custom-select", popupBody)[0];
550+
551+
contexts.forEach(function(context) {
552+
$(
553+
'<option value="' + context + '" ' + (context == self.currentContext ? "selected" : "") + ' >' + context + '</option>'
554+
).appendTo(selectDropdown);
555+
})
556+
557+
542558
var popupFooter = $(".modal-footer", popup)[0];
543559
webui.detachChildren(popupFooter);
544560

@@ -552,9 +568,36 @@ webui.SideBarView = function(mainView, noEventHandlers) {
552568
$('#changeContextModal').find('#cancelContextBtn', '.close').click(function() {
553569
removePopup(popup);
554570
});
571+
572+
$("#chooseContextBtn").on("click", function() {
573+
self.updateContext($("#chosenContext").val());
574+
});
575+
}
576+
577+
self.getCurrentContext = function() {
578+
var urlParts = window.location.href.split("/");
579+
if (urlParts[urlParts.length - 1] == "") {
580+
// return namespace as context
581+
return urlParts[urlParts.length - 2];
582+
} else {
583+
// return package as context
584+
return urlParts[urlParts.length - 1];
585+
}
586+
}
587+
588+
self.updateContext = function(context) {
589+
var urlParts = window.location.href.split("/");
590+
if (context.indexOf(".ZPM") != -1) {
591+
urlParts[urlParts.length - 1] = context;
592+
} else {
593+
urlParts[urlParts.length - 1] = "";
594+
urlParts[urlParts.length - 2] = context;
595+
}
596+
597+
window.location = urlParts.join("/");
598+
self.currentContext = context;
555599
}
556600

557-
558601
self.checkoutBranch = function(branchType, refName) {
559602
$("#confirm-branch-checkout").remove();
560603

@@ -877,8 +920,10 @@ webui.SideBarView = function(mainView, noEventHandlers) {
877920
$(".btn-add", self.element).click(self.createNewLocalBranch);
878921
$('.btn-prune-remote-branches', self.element).click(self.pruneRemoteBranches);
879922
$("#sidebar-settings", self.element).click(self.goToSettingsPage);
880-
$("#sidebar-context", self.element).click(self.changeContext);
923+
$("#sidebar-context", self.element).click(self.changeContextGet);
881924
}
925+
926+
self.currentContext = self.getCurrentContext();
882927
self.getPackageVersion();
883928
self.fetchSection($("#sidebar-local-branches", self.element)[0], "Local Branches", "local-branches", "branch --verbose --verbose");
884929
self.fetchSection($("#sidebar-remote-branches", self.element)[0], "Remote Branches", "remote-branches", "branch --remotes");

git-webui/src/share/git-webui/webui/js/git-webui.js

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,15 @@ webui.SideBarView = function(mainView, noEventHandlers) {
504504
})
505505
}
506506

507-
self.changeContext = function() {
507+
self.changeContextGet = function() {
508+
$.get("contexts", function(contextList) {
509+
var contexts = JSON.parse(contextList);
510+
self.changeContext(contexts);
511+
});
512+
}
513+
514+
self.changeContext = function(contexts) {
515+
508516
function removePopup(popup) {
509517
$(popup).children(".modal-fade").modal("hide");
510518
$(".modal-backdrop").remove();
@@ -533,12 +541,20 @@ webui.SideBarView = function(mainView, noEventHandlers) {
533541
$(
534542
'<div class="">'+
535543
'<h6>Select context for Git Source Control</h6>' +
536-
'<select class="custom-select">'+
537-
'<option selected>context!</option>' +
544+
'<select id="chosenContext" class="custom-select">'+
538545
'</select>' +
539546
'</div>'
540547
).appendTo(popupBody);
541548

549+
var selectDropdown = $(".custom-select", popupBody)[0];
550+
551+
contexts.forEach(function(context) {
552+
$(
553+
'<option value="' + context + '" ' + (context == self.currentContext ? "selected" : "") + ' >' + context + '</option>'
554+
).appendTo(selectDropdown);
555+
})
556+
557+
542558
var popupFooter = $(".modal-footer", popup)[0];
543559
webui.detachChildren(popupFooter);
544560

@@ -552,9 +568,36 @@ webui.SideBarView = function(mainView, noEventHandlers) {
552568
$('#changeContextModal').find('#cancelContextBtn', '.close').click(function() {
553569
removePopup(popup);
554570
});
571+
572+
$("#chooseContextBtn").on("click", function() {
573+
self.updateContext($("#chosenContext").val());
574+
});
575+
}
576+
577+
self.getCurrentContext = function() {
578+
var urlParts = window.location.href.split("/");
579+
if (urlParts[urlParts.length - 1] == "") {
580+
// return namespace as context
581+
return urlParts[urlParts.length - 2];
582+
} else {
583+
// return package as context
584+
return urlParts[urlParts.length - 1];
585+
}
586+
}
587+
588+
self.updateContext = function(context) {
589+
var urlParts = window.location.href.split("/");
590+
if (context.indexOf(".ZPM") != -1) {
591+
urlParts[urlParts.length - 1] = context;
592+
} else {
593+
urlParts[urlParts.length - 1] = "";
594+
urlParts[urlParts.length - 2] = context;
595+
}
596+
597+
window.location = urlParts.join("/");
598+
self.currentContext = context;
555599
}
556600

557-
558601
self.checkoutBranch = function(branchType, refName) {
559602
$("#confirm-branch-checkout").remove();
560603

@@ -877,8 +920,10 @@ webui.SideBarView = function(mainView, noEventHandlers) {
877920
$(".btn-add", self.element).click(self.createNewLocalBranch);
878921
$('.btn-prune-remote-branches', self.element).click(self.pruneRemoteBranches);
879922
$("#sidebar-settings", self.element).click(self.goToSettingsPage);
880-
$("#sidebar-context", self.element).click(self.changeContext);
923+
$("#sidebar-context", self.element).click(self.changeContextGet);
881924
}
925+
926+
self.currentContext = self.getCurrentContext();
882927
self.getPackageVersion();
883928
self.fetchSection($("#sidebar-local-branches", self.element)[0], "Local Branches", "local-branches", "branch --verbose --verbose");
884929
self.fetchSection($("#sidebar-remote-branches", self.element)[0], "Remote Branches", "remote-branches", "branch --remotes");

0 commit comments

Comments
 (0)