Skip to content

Commit 212b988

Browse files
committed
fixes to basic mode enacted
1 parent adba035 commit 212b988

File tree

7 files changed

+205
-15
lines changed

7 files changed

+205
-15
lines changed

cls/SourceControl/Git/Extension.cls

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se
5050
set Name = "%SourceMenu,Status"
5151
}
5252

53+
if Type = 1, Name = 1 {
54+
do ..AddToSourceControl(InternalName)
55+
}
56+
57+
5358
#dim ec as %Status = $$$OK
5459
#dim menu as %Status = $piece(Name, ",", 1)
5560
if menu '= "%SourceMenu", menu'="%SourceContext" {
@@ -58,7 +63,7 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se
5863

5964
set InternalName = ##class(SourceControl.Git.Utils).NormalizeInternalName(InternalName)
6065
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
61-
set ec = ##class(SourceControl.Git.Utils).UserAction(InternalName, Name, .Target, .Action, .Reload)
66+
set ec = ##class(SourceControl.Git.Utils).UserAction(InternalName, Name, .Target, .Action, .Reload, .Msg)
6267
quit ec
6368
}
6469

@@ -263,8 +268,6 @@ Method OnAfterSave(InternalName As %String, Object As %RegisteredObject = {$$$NU
263268
if '##class(SourceControl.Git.Change).IsUncommitted(filename) {
264269
$$$ThrowOnError(##class(SourceControl.Git.Change).SetUncommitted(filename, "edit", InternalName, $username, "", 1, "", "", 0))
265270
}
266-
} elseif ##class(SourceControl.Git.Utils).BasicMode() {
267-
do ..AddToSourceControl(InternalName)
268271
}
269272
} catch e {
270273
do e.Log()

cls/SourceControl/Git/Settings.cls

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ Property gitUserEmail As %String(MAXLEN = 255) [ InitialExpression = {##class(So
3333
Property mappedItemsReadOnly As %Boolean [ InitialExpression = {##class(SourceControl.Git.Utils).MappedItemsReadOnly()} ];
3434

3535
/// Attribution: Whether basic mode should be enabled for user ${username}, greatly simplifying the functionality of the package, requiring no knowledge of git
36-
Property basicMode As %Boolean [ InitialExpression = {##class(SourceControl.Git.Utils).BasicMode()} ];
36+
Property basicMode As %String [ InitialExpression = {##class(SourceControl.Git.Utils).BasicMode()} ];
3737

38+
/// This does not map to a setting on the screen but is used to select the value to be displayed for the user's basic mode setting
39+
Property userBasicMode As %String [ InitialExpression = {##class(SourceControl.Git.Utils).UserBasicMode()} ];
40+
41+
/// The system's default mode. If true, the system defaults to basic mode
3842
Property systemBasicMode As %Boolean [ InitialExpression = {##class(SourceControl.Git.Utils).SystemBasicMode()} ];
3943

4044
Property Mappings [ MultiDimensional ];
@@ -89,8 +93,16 @@ Method %Save() As %Status
8993
set @storage@("settings","percentClassReplace") = ..percentClassReplace
9094
set @storage@("settings","settingsUIReadOnly") = ..settingsUIReadOnly
9195
set @storage@("settings", "mappedItemsReadOnly") = ..mappedItemsReadOnly
92-
set @storage@("settings", "user", $username, "basicMode") = ..basicMode
9396
set @storage@("settings", "basicMode") = ..systemBasicMode
97+
if ..basicMode = "system" {
98+
kill @storage@("settings", "user", $username, "basicMode")
99+
} else {
100+
set @storage@("settings", "user", $username, "basicMode") = ..basicMode
101+
}
102+
103+
// update value of basicUserMode to reflect the updated setting for basicMode
104+
set ..userBasicMode = ##class(SourceControl.Git.Utils).UserBasicMode()
105+
94106

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

cls/SourceControl/Git/Utils.cls

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ ClassMethod BasicMode() As %Boolean
118118
quit $get(@..#Storage@("settings", "user", $username, "basicMode"), ..SystemBasicMode())
119119
}
120120

121+
ClassMethod UserBasicMode() As %String
122+
{
123+
quit $get(@..#Storage@("settings", "user", $username, "basicMode"), "system")
124+
}
125+
121126
ClassMethod SystemBasicMode() As %Boolean
122127
{
123128
quit $get(@..#Storage@("settings", "basicMode"), 0)
@@ -168,7 +173,7 @@ ClassMethod IsImportAfter(menuItemName As %String) As %Boolean [ CodeMode = expr
168173
$Find(..#ImportAfterGitMenuItems, ","_menuItemName_",") > 0
169174
}
170175

171-
ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Target As %String, ByRef Action As %String, ByRef Reload As %Boolean) As %Status
176+
ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Target As %String, ByRef Action As %String, ByRef Reload As %Boolean, ByRef Msg As %String) As %Status
172177
{
173178
#define Force 1
174179
// MenuName = "<Name of menu>,<Name of menu item>"
@@ -238,7 +243,10 @@ ClassMethod UserAction(InternalName As %String, MenuName As %String, ByRef Targe
238243
set Action = 7
239244
quit $$$OK
240245
} elseif (menuItemName = "Sync") {
241-
quit ..Sync()
246+
set Target = "Enter a commit message for the sync operation"
247+
set Action = 7
248+
set Msg = ..PreSync()
249+
quit $$$OK
242250
} elseif (menuItemName = "Push") {
243251
quit ..Push()
244252
} elseif (menuItemName = "Fetch") {
@@ -285,6 +293,11 @@ ClassMethod AfterUserAction(Type As %Integer, Name As %String, InternalName As %
285293
do ..SwitchBranch(Msg)
286294
set Reload = 1
287295
}
296+
} elseif (menuItemName = "Sync") {
297+
if (Answer = 1) {
298+
do ..Sync(Msg)
299+
set Reload = 1
300+
}
288301
}
289302
quit $$$OK
290303
}
@@ -334,16 +347,63 @@ ClassMethod SwitchBranch(targetBranchName As %String) As %Status
334347
quit $$$OK
335348
}
336349

337-
ClassMethod Sync() As %Status
350+
ClassMethod PreSync() As %String
351+
{
352+
set uncommittedFilesWithAction = ##class(SourceControl.Git.WebUIDriver).UncommittedWithAction().%Get("current user's changes")
353+
quit ..GenerateCommitMessageFromFiles(uncommittedFilesWithAction)
354+
}
355+
356+
/// Commits all the files as needed by the Sync operation
357+
ClassMethod SyncCommit(Msg As %String) As %Status
358+
{
359+
set uncommittedFilesWithAction = ##class(SourceControl.Git.WebUIDriver).UncommittedWithAction().%Get("current user's changes")
360+
set username = ..GitUserName()
361+
set email = ..GitUserEmail()
362+
set author = username_" <"_email_">"
363+
do ..RunGitWithArgs(.errStream, .outStream, "commit", "--author", author, "-m", Msg)
364+
do ..PrintStreams(errStream, outStream)
365+
$$$QuitOnError(..ClearUncommitted(uncommittedFilesWithAction))
366+
$$$QuitOnError(##class(SourceControl.Git.Change).RefreshUncommitted(,,,1))
367+
quit $$$OK
368+
}
369+
370+
/// Goes through all the added files and stages them
371+
ClassMethod StageAddedFiles()
372+
{
373+
set uncommittedFilesWithAction = ##class(SourceControl.Git.WebUIDriver).UncommittedWithAction().%Get("current user's changes")
374+
set iterator = uncommittedFilesWithAction.%GetIterator()
375+
while iterator.%GetNext(,.value,) {
376+
set file = value.%Get("file")
377+
do ..RunGitWithArgs(.errStream, .outStream, "add", file)
378+
do ..PrintStreams(errStream, outStream)
379+
}
380+
}
381+
382+
/// Converts the DynamicArray into a list and calls the SourceControl.Git.Change RemoveUncommitted method on the newly created list
383+
ClassMethod ClearUncommitted(filesWithActions) As %Status
384+
{
385+
set files = ""
386+
387+
set iterator = filesWithActions.%GetIterator()
388+
while iterator.%GetNext(,.value,) {
389+
set file = value.%Get("file")
390+
set files = files_$listbuild(file)
391+
}
392+
$$$QuitOnError(##class(SourceControl.Git.Change).RemoveUncommitted(files))
393+
quit $$$OK
394+
}
395+
396+
ClassMethod Sync(Msg As %String) As %Status
338397
{
339-
write "Syncing local repository..."
398+
write !, "Syncing local repository...", !
399+
do ..StageAddedFiles()
340400
if '..HasRemoteRepo() {
341401
write "No remote repository configured: skipping fetch, pull and push"
342-
do ..Commit("", "Committing all files through sync command")
402+
do ..SyncCommit(Msg)
343403
} else {
344404
do ..Fetch()
345405
do ..Pull()
346-
do ..Commit("", "Committing all files through sync command")
406+
do ..SyncCommit(Msg)
347407
do ..Push()
348408
}
349409

@@ -1570,6 +1630,29 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
15701630
quit returnCode
15711631
}
15721632

1633+
ClassMethod GenerateCommitMessageFromFiles(filesWithActions) As %String
1634+
{
1635+
set commitMsg = ""
1636+
1637+
set iterator = filesWithActions.%GetIterator()
1638+
while iterator.%GetNext(,.value,) {
1639+
set action = value.%Get("action")
1640+
set file = value.%Get("file")
1641+
1642+
1643+
if action = "A" {
1644+
set commitMsg = commitMsg _ "added " _ file _ ", "
1645+
} elseif action = "M" {
1646+
set commitMsg = commitMsg _ "modified " _ file _ ", "
1647+
} elseif action = "D" {
1648+
set commitMsg = commitMsg _ "deleted " _ file _ ", "
1649+
} elseif action = "R" {
1650+
set commitMsg = commitMsg _ "renamed " _ file _ ", "
1651+
}
1652+
}
1653+
quit commitMsg
1654+
}
1655+
15731656
ClassMethod GitStatus(ByRef files, IncludeAllFiles = 0)
15741657
{
15751658
do ..RunGitCommand("status", .errStream, .outStream, "-z", "-uall")

cls/SourceControl/Git/WebUIDriver.cls

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,42 @@ ClassMethod Uncommitted() As %SystemBase
200200
}
201201
}
202202
}
203+
204+
do fileToOtherDevelopers.%Set("current user's changes", editedByCurrentUser)
205+
do fileToOtherDevelopers.%Set("other users' changes", ##class(SourceControl.Git.Change).GetOtherDeveloperChanges())
206+
quit fileToOtherDevelopers
207+
}
208+
209+
ClassMethod UncommittedWithAction() As %SystemBase
210+
{
211+
do ##class(SourceControl.Git.Change).RefreshUncommitted()
212+
do ##class(SourceControl.Git.Utils).GitStatus(.files, 1)
213+
set output = ""
214+
set key = ""
215+
216+
set editedByCurrentUser = []
217+
set fileToOtherDevelopers = {}
218+
for {
219+
set key = $order(files(key), 1, fileData)
220+
quit:key=""
221+
222+
set filename = ##class(SourceControl.Git.Utils).FullExternalName(key)
223+
if (($ISVALIDNUM(key)) && (files(key) '= "")) {
224+
set edit = {}
225+
do edit.%Set("file", $listget(fileData, 2))
226+
do edit.%Set("action", $listget(fileData, 1))
227+
do editedByCurrentUser.%Push(edit)
228+
} else {
229+
set sc=##class(SourceControl.Git.Change).GetUncommitted(filename, .tAction, .tInternalName, .UncommittedUser, .tSource, .UncommittedLastUpdated)
230+
if ($$$ISOK(sc)) && ($data(tAction)&&(UncommittedUser=$username)) {
231+
set edit = {}
232+
do edit.%Set("file", $listget(fileData, 2))
233+
do edit.%Set("action", $listget(fileData, 1))
234+
do editedByCurrentUser.%Push(edit)
235+
}
236+
}
237+
}
238+
203239
do fileToOtherDevelopers.%Set("current user's changes", editedByCurrentUser)
204240
do fileToOtherDevelopers.%Set("other users' changes", ##class(SourceControl.Git.Change).GetOtherDeveloperChanges())
205241
quit fileToOtherDevelopers
@@ -225,3 +261,4 @@ ClassMethod GetSettingsURL(%request As %CSP.Request) As %SystemBase
225261
}
226262

227263
}
264+

csp/gitprojectsettings.csp

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ body {
5757
font-size: 80%;
5858
}
5959

60+
.form-rad {
61+
padding-left: 30px;
62+
}
63+
64+
.form-rad-label {
65+
padding-left: 4px;
66+
}
67+
6068
</style>
6169
</head>
6270
<body>
@@ -83,6 +91,8 @@ body {
8391

8492
if ($Get(%request.Data("basicMode", 1)) = 1) {
8593
set settings.basicMode = 1
94+
} elseif ($Get(%request.Data("basicMode", 1)) = "system"){
95+
set settings.basicMode = "system"
8696
} else {
8797
set settings.basicMode = 0
8898
}
@@ -276,7 +286,7 @@ body {
276286
</div>
277287

278288
<div class="form-group row mb-3">
279-
<label for="systemBasicMode" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Whether basic mode should be applied as the system-wide default"> Basic Mode as System Default</label>
289+
<label for="systemBasicMode" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Enable basic mode for all users, 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 as System Default</label>
280290
<div class="col-sm-7">
281291

282292
<div class="custom-control custom-switch custom-switch-no-border">
@@ -435,8 +445,49 @@ body {
435445
</div>
436446
</div>
437447

438-
<div class="form-group row mb-3">
439-
<label for="basicMode" class="offset-sm-1 col-sm-3 col-form-label" data-toggle="tooltip" data-placement="top" title="Enable basic mode, greatly simplifying the Git Source Control package, requiring no knowledge of git">Basic Mode</label>
448+
<div class="form-group mb-3">
449+
<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>
450+
451+
<div class="form-check offset-sm-4 form-rad">
452+
<server>
453+
if (settings.userBasicMode = "1") {
454+
&html<<input class="form-check-input" name="basicMode" type="radio" id="basicMode1" checked value="1">>
455+
} else {
456+
&html<<input class="form-check-input" name="basicMode" type="radio" id="basicMode1" value="1">>
457+
}
458+
</server>
459+
<label class="form-check-label" for="basicMode1">
460+
Use Basic Mode
461+
</label>
462+
</div> </br>
463+
<div class="form-check offset-sm-4 form-rad">
464+
<server>
465+
if (settings.userBasicMode = "0") {
466+
&html<<input class="form-check-input" name="basicMode" type="radio" id="basicMode0" checked value="0">>
467+
} else {
468+
&html<<input class="form-check-input" name="basicMode" type="radio" id="basicMode0" value="0">>
469+
}
470+
</server>
471+
<label class="form-check-label" for="basicMode0">
472+
Use Expert Mode
473+
</label>
474+
</div> </br>
475+
<div class="form-check offset-sm-4 form-rad">
476+
<server>
477+
if (settings.userBasicMode = "system") {
478+
&html<<input class="form-check-input" name="basicMode" type="radio" id="basicModeDefault" checked value="system">>
479+
} else {
480+
&html<<input class="form-check-input" name="basicMode" type="radio" id="basicModeDefault" value="system">>
481+
}
482+
</server>
483+
<label class="form-check-label" for="basicModeDefault">
484+
Use System's Default Mode
485+
</label>
486+
</div>
487+
488+
489+
490+
<!-- <label for="basicMode" class="offset-sm-1 col-sm-3 col-form-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>
440491
<div class="custom-control custom-switch custom-switch-no-border">
441492
<server>
442493
if (settings.basicMode) {
@@ -447,7 +498,7 @@ body {
447498
</server>
448499

449500
<label class="custom-control-label" for="basicMode"></label>
450-
</div>
501+
</div> -->
451502
</div>
452503

453504
<br/>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,9 @@ webui.ChangedFilesView = function(workspaceView, type, label) {
21472147
var col = type == "working-copy" ? 1 : 0;
21482148
webui.git("status -u --porcelain", function(data) {
21492149
$.get("api/uncommitted", function (uncommitted) {
2150+
console.log(uncommitted);
21502151
var uncommittedItems = JSON.parse(uncommitted)["current user's changes"];
2152+
console.log(uncommittedItems);
21512153
var otherDeveloperUncommittedItems = JSON.parse(uncommitted)["other users' changes"];
21522154
self.filesCount = 0;
21532155
function addItemToFileList(fileList, otherDeveloperUsername, model) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,9 @@ webui.ChangedFilesView = function(workspaceView, type, label) {
21472147
var col = type == "working-copy" ? 1 : 0;
21482148
webui.git("status -u --porcelain", function(data) {
21492149
$.get("api/uncommitted", function (uncommitted) {
2150+
console.log(uncommitted);
21502151
var uncommittedItems = JSON.parse(uncommitted)["current user's changes"];
2152+
console.log(uncommittedItems);
21512153
var otherDeveloperUncommittedItems = JSON.parse(uncommitted)["other users' changes"];
21522154
self.filesCount = 0;
21532155
function addItemToFileList(fileList, otherDeveloperUsername, model) {

0 commit comments

Comments
 (0)