Skip to content

Commit

Permalink
add system settings
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-etamarch committed Nov 8, 2024
1 parent 0c7721d commit 58e371b
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Creating a new branch now reports the error if uncommitted changes conflict (#624)
- Fix Configure erroring out if git isn't found (#632)

### Added
- Added saving settings as system default for new namespaces (#535)

## [2.7.0] - 2024-11-04

### Added
Expand Down
22 changes: 22 additions & 0 deletions cls/SourceControl/Git/Settings.cls
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ ClassMethod CreateNamespaceTempFolder() As %Status
ClassMethod Configure() As %Boolean [ CodeMode = objectgenerator ]
{
do %code.WriteLine(" set inst = ..%New()")
do %code.WriteLine(" do inst.RetrieveDefaults()")
set defaultPromptFlag = $$$DisableBackupCharMask + $$$TrapCtrlCMask + $$$EnableQuitCharMask + $$$DisableHelpCharMask + $$$DisableHelpContextCharMask + $$$TrapErrorMask
set property = ""
for {
Expand Down Expand Up @@ -394,4 +395,25 @@ Method ConfigureBinPath(ByRef path As %String) As %Boolean
return 1
}

Method RetrieveDefaults() As %Boolean
{
do ##class(%zpkg.isc.sc.git.Defaults).GetDefaultSettings(.settings)
set iterator = settings.%GetIterator()
while iterator.%GetNext(.key, .value) {
set $property($this,key) = value
}
return $$$OK
}

Method SaveDefaults() As %Boolean
{
set defaults = {}
set items = $lb("gitBinPath", "namespaceTemp", "pullEventClass", "percentClassReplace", "environmentName", "systemBasicMode", "defaultMergeBranch", "mappedItemsReadOnly", "compileOnImport")
for i=1:1:$LISTLENGTH(items) {
set property = $listget(items,i)
do defaults.%Set(property, $property($this, property))
}
return ##class(%zpkg.isc.sc.git.Defaults).SetDefaultSettings(defaults)
}

}
62 changes: 62 additions & 0 deletions cls/_zpkg/isc/sc/git/Defaults.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Class %zpkg.isc.sc.git.Defaults
{

ClassMethod GetDefaults() As %Library.DynamicObject [ NotInheritable, Private ]
{
set defaults = {}
set storage = "^%SYS(""SourceControl"",""Git"",""defaults"")"
$$$AddAllRoleTemporary

set key = $order(@storage@(""))
while key '= "" {
do defaults.%Set(key, $get(@storage@(key)))
set key = $order(@storage@(key))
}
return defaults
}

ClassMethod GetDefaultSettings(ByRef defaults As %Library.DynamicObject) As %Status
{
try {
set defaults = ..GetDefaults()
} catch e {
return e.AsStatus()
}
return $$$OK
}

ClassMethod SetDefaults(defaults As %Library.DynamicObject) As %Status [ NotInheritable, Private ]
{

$$$AddAllRoleTemporary
set storage = "^%SYS(""SourceControl"",""Git"",""defaults"")"
k @storage
set iterator = defaults.%GetIterator()

while iterator.%GetNext(.key, .value) {
set @storage@(key) = value
}

return $$$OK
}

ClassMethod SetDefaultSettings(defaults As %Library.DynamicObject) As %Status [ NotInheritable ]
{

set newDefaults = {}

set iterator = defaults.%GetIterator()

while iterator.%GetNext(.key, .value) {
do newDefaults.%Set(key, value)
}

try {
do ..SetDefaults(newDefaults)
} catch e {
return e.AsStatus()
}
return $$$OK
}

}
36 changes: 28 additions & 8 deletions csp/gitprojectsettings.csp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ body {
}

set settings.favoriteNamespaces = contexts

if ($get(%request.Data("proxySubmitButton",1)) = "saveDefaults") {
do settings.SaveDefaults()
}
}
do settings.%Save()
}
Expand Down Expand Up @@ -273,7 +277,7 @@ body {
}
</server>
<div class="form-group row mb-3">
<label for="privateKeyFile" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Absolute path to your private SSH key file">SSH Private Key File</label>
<label for="privateKeyFile" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Absolute path to your private SSH key file">*SSH Private Key File</label>
<div class="col-sm-7">
<server>
Set fileExists = ##class(%File).Exists(settings.privateKeyFile)
Expand Down Expand Up @@ -393,7 +397,7 @@ body {
</div>

<div class="form-group row mb-3">
<label for="remoteRepo" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Url to Remote repository">Remote Repository</label>
<label for="remoteRepo" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Url to Remote repository">*Remote Repository</label>
<div class="col-sm-7">
<input type="text" class="form-control" id="remoteRepo" name="remoteRepo" value='#(..EscapeHTML(remote))#' placeholder="ex. [email protected]:User/UserRepo.git"/>
<div class = "neutral-feedback">
Expand Down Expand Up @@ -435,7 +439,7 @@ body {

<div class="form-group row mb-3 mapping-input-group">
<div class="offset-sm-1 col-sm-3">
<label for="MappingsPath" class="col-form-label" data-toggle="tooltip" data-placement="top" title="Relative paths mapping the files in your project. For web application files, use the extension: /CSP/">Mappings</label>
<label for="MappingsPath" class="col-form-label" data-toggle="tooltip" data-placement="top" title="Relative paths mapping the files in your project. For web application files, use the extension: /CSP/">*Mappings</label>
<button type="button" class="btn btn-default btn-add" >
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" fill="#198754" class="bi bi-plus-circle-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.5 4.5a.5.5 0 0 0-1 0v3h-3a.5.5 0 0 0 0 1h3v3a.5.5 0 0 0 1 0v-3h3a.5.5 0 0 0 0-1h-3v-3z"></path>
Expand Down Expand Up @@ -538,21 +542,21 @@ body {

<fieldset id="userSettings">
<div class="form-group row mb-3">
<label for="gitUserName" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Firstname Lastname">Git Committer Name </label>
<label for="gitUserName" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Firstname Lastname">*Git Committer Name </label>
<div class="col-sm-7">
<input type="text" class="form-control" id="gitUserName" name="gitUserName" value='#(..EscapeHTML(settings.gitUserName))#'/>
</div>
</div>

<div class="form-group row mb-3">
<label for="gitUserEmail" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="<git-username-on-remote>@remote.com">Git Committer Email </label>
<label for="gitUserEmail" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="<git-username-on-remote>@remote.com">*Git Committer Email </label>
<div class="col-sm-7">
<input type="email" class="form-control" id="gitUserEmail" name="gitUserEmail" value='#(..EscapeHTML(settings.gitUserEmail))#'/>
</div>
</div>

<div class="form-group mb-3">
<label for="basicMode" class="offset-sm-1 col-sm-3 col-form-label form-rad-label" data-toggle="tooltip" data-placement="top" title="Enable basic mode, which reduces the number of menu options and requires less knowledge of git. This is suitable for a single-developer (non-shared) namespace.">Basic Mode</label>
<label for="basicMode" class="offset-sm-1 col-sm-3 col-form-label form-rad-label" data-toggle="tooltip" data-placement="top" title="Enable basic mode, which reduces the number of menu options and requires less knowledge of git. This is suitable for a single-developer (non-shared) namespace.">*Basic Mode</label>

<div class="form-check offset-sm-4 form-rad">
<server>
Expand Down Expand Up @@ -608,7 +612,7 @@ body {
</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>
<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>
Expand All @@ -633,7 +637,12 @@ body {

<div class="form-group row mb-3">
<div class="col-sm-12 text-center">
<input type='submit' class="btn-lg btn-primary" value = 'Save'/>
<input type="hidden" id="proxySubmitButton" name="proxySubmitButton" value="Save">
<input type='submit' class="btn-lg btn-primary" value = 'Save' name="Save"/>
<input type="submit" class="btn-lg btn-primary" id="saveDefaults" value = 'Save as Instance Defaults' title="Save these settings as default for new instances" name="saveDefaults"/>
<div>
<small> Settings not saved as default marked with '*'</small>
</div>
</div>
</div>

Expand All @@ -660,6 +669,17 @@ function getSocket(urlPostfix) {
return new WebSocket(socketURL);
}

var submitForm = function(e) {
e.preventDefault();
e.stopPropagation();
var proxySubmitButton = document.getElementById('proxySubmitButton');
proxySubmitButton.value = "saveDefaults";
var form = document.getElementById('settingsForm');
form.submit();
}

document.getElementById('saveDefaults').addEventListener('click',submitForm,false);

function init() {
disableActionButtons();
var root = document.getElementById("namespaceTemp").value;
Expand Down

0 comments on commit 58e371b

Please sign in to comment.