Skip to content

Change context webui #456

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [2.5.0] - Unreleased

### Added
- New UI for the basic mode Sync (#415)
- Allow changing namespaces and IPM package context from web UI (#280)

### Fixed
- Instance wide settings are placed in proper global (#444)
Expand Down
45 changes: 45 additions & 0 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2315,6 +2315,27 @@ ClassMethod Localize()
}
}

ClassMethod GetContexts() As %DynamicArray
{
set contexts = []
set namespaces = ..GetGitEnabledNamespaces()
set ptr = 0
while $listnext(namespaces,ptr,value) {
do contexts.%Push(value)
}

set query = "SELECT name from %Library.RoutineMgr_StudioOpenDialog('*.ZPM')"
set statement = ##class(%SQL.Statement).%New()
$$$ThrowOnError(statement.%Prepare(query, 0))
set packagesResultSet = statement.%Execute()
throw:packagesResultSet.%SQLCODE<0 ##class(%Exception.SQL).CreateFromSQLCODE(packagesResultSet.%SQLCODE,packagesResultSet.%Message)
while packagesResultSet.%Next() {
set package = packagesResultSet.Name
do contexts.%Push(package)
}
return contexts
}

ClassMethod ConfigureWeb()
{
set installNamespace = $Namespace
Expand Down Expand Up @@ -2417,6 +2438,29 @@ ClassMethod UncommittedWithAction() As %Library.DynamicObject
quit fileToOtherDevelopers
}

/// Retrieve the list of Namespaces that have git enabled
ClassMethod GetGitEnabledNamespaces() As %String
{
// Get all namespaces
set allNamespaces = ""
do ##class(%SYS.Namespace).ListAll(.allNamespaces)

set enabledNamespaces = ""
set namespace = ""
for {
set namespace = $ORDER(allNamespaces(namespace))
quit:namespace=""
try {
set sourceControlClass = ##class(%Studio.SourceControl.Interface).SourceControlClassGet(namespace)
} catch err {
set sourceControlClass = "" // user does not have access to this namespace
}
if (sourceControlClass = "SourceControl.Git.Extension") set enabledNamespaces = enabledNamespaces _ $listbuild(namespace)
}

quit enabledNamespaces
}

ClassMethod BuildCEInstallationPackage(ByRef destination As %String) As %Status
{
#define sourcedir $System.Util.InstallDirectory()_"devuser/studio/templates/gitsourcecontrol/"
Expand Down Expand Up @@ -2571,3 +2615,4 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status
}

}

6 changes: 5 additions & 1 deletion cls/SourceControl/Git/WebUIDriver.cls
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
if $isobject($get(responseJSON)) {
do responseJSON.%ToJSON(%data)
}
} elseif $match(pathStart,"git-command|git|dirname|hostname|viewonly") {
} elseif $match(pathStart,"git-command|git|dirname|hostname|viewonly|contexts") {
if (%request.Method = "GET") {
set %data = ##class(%Stream.TmpCharacter).%New()
// Things not handled from Python backend:
Expand Down Expand Up @@ -76,6 +76,10 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
} elseif (pathStart = "dirname") {
do %data.Write(##class(SourceControl.Git.Utils).TempFolder())
set handled = 1
} elseif (pathStart = "contexts") {
set contexts = ##class(SourceControl.Git.Utils).GetContexts()
do contexts.%ToJSON(%data)
set handled = 1
}
} elseif (%request.Method = "POST") {
// Things not handled from Python backend:
Expand Down
15 changes: 13 additions & 2 deletions git-webui/release/share/git-webui/webui/css/git-webui.css
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ body {
border-top: 1px solid #1a1a1a;
border-bottom: 1px solid #1a1a1a;
color: #eeeeee;
padding-bottom: 6em;
padding-bottom: 100px;
}
#sidebar #sidebar-content > :first-child,
#sidebar #sidebar-content > :last-child {
#sidebar #sidebar-content > :nth-last-child(2) {
border-top: 1px solid #5e5e5e;
}
#sidebar #sidebar-content h4:before {
Expand Down Expand Up @@ -216,6 +216,17 @@ body {
#sidebar #sidebar-content #sidebar-tags h4:before {
content: url(../img/tag.svg);
}
#sidebar #sidebar-content #sidebar-context h4:before {
content: url(../img/context.svg);
}
#sidebar #sidebar-content #sidebar-context {
position: absolute;
bottom: 50px;
width: 16.7em;
padding-bottom: 0.3rem;
margin-bottom: 0;
background-color: #333333;
}
#sidebar #sidebar-content #sidebar-settings h4:before {
content: url(../img/gear-fill.svg);
}
Expand Down
102 changes: 100 additions & 2 deletions git-webui/release/share/git-webui/webui/js/git-webui.js
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,99 @@ webui.SideBarView = function(mainView, noEventHandlers) {
})
}


self.changeContextGet = function() {
$.get("contexts", function(contextList) {
var contexts = JSON.parse(contextList);
self.changeContext(contexts);
});
}

self.changeContext = function(contexts) {

function removePopup(popup) {
$(popup).children(".modal-fade").modal("hide");
$(".modal-backdrop").remove();
$("#changeContextModal").remove();
}

var popup = $(
'<div class="modal fade" tab-index="-1" id="changeContextModal" role="dialog">' +
'<div class="modal-dialog modal-md" role="document">' +
'<div class="modal-content">' +
'<div class="modal-header">' +
'<h5 class="modal-title">Change Context</h5>' +
'<button type="button" class="btn btn-default close" data-dismiss="modal">' + webui.largeXIcon + '</button>' +
'</div>' +
'<div class="modal-body"></div>' +
'<div class="modal-footer"></div>' +
'</div>' +
'</div>' +
'</div>'
)[0];

$("body").append(popup);
var popupBody = $(".modal-body", popup)[0];
webui.detachChildren(popupBody);

$(
'<div class="">'+
'<h6>Select context for Git Source Control</h6>' +
'<select id="chosenContext" class="custom-select">'+
'</select>' +
'</div>'
).appendTo(popupBody);

var selectDropdown = $(".custom-select", popupBody)[0];

contexts.forEach(function(context) {
$(
'<option value="' + context + '" ' + (context == self.currentContext ? "selected" : "") + ' >' + context + '</option>'
).appendTo(selectDropdown);
})


var popupFooter = $(".modal-footer", popup)[0];
webui.detachChildren(popupFooter);

$(
'<button class="btn btn-sm btn-primary action-btn" id="chooseContextBtn">Choose Context</button>' +
'<button class="btn btn-sm btn-secondary" id="cancelContextBtn">Cancel</button>'
).appendTo(popupFooter);

$(popup).modal('show');

$('#changeContextModal').find('#cancelContextBtn', '.close').click(function() {
removePopup(popup);
});

$("#chooseContextBtn").on("click", function() {
self.updateContext($("#chosenContext").val());
removePopup(popup);
});
}

self.getCurrentContext = function() {
var args = window.location.href.split("webuidriver.csp/")[1].split("/");
var context = args[0];
if (args[1] && (args[1].indexOf(".ZPM") != -1)) {
context = args[1];
}
return context;
}

self.updateContext = function(context) {
var urlParts = window.location.href.split("webuidriver.csp/");
var args = urlParts[1].split("/");
if (context.indexOf(".ZPM") != -1) {
args[1] = context;
} else {
args[0] = context;
args[1] = "";
}
window.location = urlParts[0] + "webuidriver.csp/" + args.join("/");
self.currentContext = context;
}

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

Expand Down Expand Up @@ -855,7 +947,7 @@ webui.SideBarView = function(mainView, noEventHandlers) {
};

self.mainView = mainView;

self.currentContext = self.getCurrentContext();
self.element = $( '<div id="sidebar">' +
'<a href="#" data-toggle="modal" data-target="#help-modal"><img id="sidebar-logo" src="img/git-logo.png"></a>' +
'<h5 id="packageVersion"></h5>' +
Expand All @@ -881,6 +973,9 @@ webui.SideBarView = function(mainView, noEventHandlers) {
'<section id="sidebar-tags">' +
'<h4>Tags</h4>' +
'</section>' +
'<section id="sidebar-context" data-toggle="tooltip" data-placement="right" title="' + self.currentContext + '">' +
'<h4>Change Context</h4>' +
'</section>' +
'<section id="sidebar-settings">' +
'<h4>Settings</h4>' +
'</section>' +
Expand All @@ -907,7 +1002,10 @@ 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);
}


self.getPackageVersion();
self.fetchSection($("#sidebar-local-branches", self.element)[0], "Local Branches", "local-branches", "branch --verbose --verbose");
self.fetchSection($("#sidebar-remote-branches", self.element)[0], "Remote Branches", "remote-branches", "branch --remotes");
Expand Down
17 changes: 15 additions & 2 deletions git-webui/src/share/git-webui/webui/css/git-webui.less
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ body {
border-top: 1px solid darken(@gray-dark, 10%);
border-bottom: 1px solid darken(@gray-dark, 10%);
color: @gray-lighter;
padding-bottom: 6em;
padding-bottom: 100px;

> :first-child, >:last-child {
> :first-child, >:nth-last-child(2) {
border-top: 1px solid darken(@separator-line, 50%);
}

Expand Down Expand Up @@ -301,6 +301,19 @@ body {
content: url(../img/tag.svg);
}

#sidebar-context h4:before {
content: url(../img/context.svg)
}

#sidebar-context {
position: absolute;
bottom: 50px;
width: 16.7em;
padding-bottom: 0.3rem;
margin-bottom: 0;
background-color: rgba(51, 51, 51, 1);
}

#sidebar-settings h4:before {
content: url(../img/gear-fill.svg);
}
Expand Down
1 change: 1 addition & 0 deletions git-webui/src/share/git-webui/webui/img/context.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading