Skip to content

Commit 1f74651

Browse files
committed
mostly done with changes
1 parent 27fcfdf commit 1f74651

File tree

8 files changed

+316
-11
lines changed

8 files changed

+316
-11
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
Class SourceControl.Git.DiscardState Extends (%Persistent, %JSON.Adaptor)
2+
{
3+
4+
Property FullExternalName As %String(MAXLEN = "") [ Required ];
5+
6+
Property InternalName As %String [ Required ];
7+
8+
Property Contents As %Stream.GlobalCharacter(LOCATION = "^DiscardStateContents");
9+
10+
Property Username As %String [ Required ];
11+
12+
Property Branch As %String [ Required ];
13+
14+
Property Timestamp As %TimeStamp [ Required ];
15+
16+
Method RestoreToFileTree()
17+
{
18+
set fileStream = ##class(%Stream.FileCharacter).%OpenId(..FullExternalName,,.sc)
19+
$$$ThrowOnError(sc)
20+
do fileStream.CopyFrom(..Contents)
21+
$$$ThrowOnError(fileStream.%Save())
22+
do ##class(SourceControl.Git.Utils).ImportItem(..InternalName, 1, 1)
23+
$$$ThrowOnError(..%DeleteId(..%Id()))
24+
}
25+
26+
ClassMethod SaveDiscardState(InternalName As %String) As %Status
27+
{
28+
set discardState = ..%New()
29+
set discardState.FullExternalName = ##class(SourceControl.Git.Utils).FullExternalName(InternalName)
30+
set discardState.InternalName = InternalName
31+
32+
set fileStream = ##class(%Stream.FileCharacter).%New()
33+
set fileStream.Filename = discardState.FullExternalName
34+
do fileStream.%Open()
35+
do discardState.Contents.CopyFrom(fileStream)
36+
do fileStream.%Close()
37+
set discardState.Username = $USERNAME
38+
set discardState.Branch = ##class(SourceControl.Git.Utils).GetCurrentBranch()
39+
set discardState.Timestamp = $zdatetime($horolog, 3)
40+
41+
set st = discardState.%Save()
42+
43+
quit st
44+
}
45+
46+
ClassMethod DiscardStatesInBranch() As %DynamicArray
47+
{
48+
set currentBranch = ##class(SourceControl.Git.Utils).GetCurrentBranch()
49+
set statement = "SELECT ID FROM SourceControl_Git.DiscardState WHERE branch = ?"
50+
set resultSet = ##class(%SQL.Statement).%ExecDirect(, statement, currentBranch)
51+
set discardStates = []
52+
while resultSet.%Next() {
53+
set discardState = ..%OpenId(resultSet.ID)
54+
do discardState.%JSONExportToString(.JSONStr)
55+
set discardStateObject = ##class(%DynamicAbstractObject).%FromJSON(JSONStr)
56+
do discardStates.%Push(discardStateObject)
57+
}
58+
59+
quit discardStates
60+
}
61+
62+
Storage Default
63+
{
64+
<Data name="DiscardStateDefaultData">
65+
<Value name="1">
66+
<Value>%%CLASSNAME</Value>
67+
</Value>
68+
<Value name="2">
69+
<Value>FullExternalName</Value>
70+
</Value>
71+
<Value name="3">
72+
<Value>InternalName</Value>
73+
</Value>
74+
<Value name="4">
75+
<Value>Contents</Value>
76+
</Value>
77+
<Value name="5">
78+
<Value>Username</Value>
79+
</Value>
80+
<Value name="6">
81+
<Value>Branch</Value>
82+
</Value>
83+
<Value name="7">
84+
<Value>Timestamp</Value>
85+
</Value>
86+
</Data>
87+
<DataLocation>^SourceControl22B9.DiscardStateD</DataLocation>
88+
<DefaultData>DiscardStateDefaultData</DefaultData>
89+
<IdLocation>^SourceControl22B9.DiscardStateD</IdLocation>
90+
<IndexLocation>^SourceControl22B9.DiscardStateI</IndexLocation>
91+
<StreamLocation>^SourceControl22B9.DiscardStateS</StreamLocation>
92+
<Type>%Storage.Persistent</Type>
93+
}
94+
95+
}
96+

cls/SourceControl/Git/WebUIDriver.cls

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
2727
if $isobject($get(responseJSON)) {
2828
do responseJSON.%ToJSON(%data)
2929
}
30-
} elseif $match(pathStart,"git-command|git|dirname|hostname|viewonly") {
30+
} elseif $match(pathStart,"git-command|git|dirname|hostname|viewonly|discarded-states") {
3131
if (%request.Method = "GET") {
3232
set %data = ##class(%Stream.TmpCharacter).%New()
3333
// Things not handled from Python backend:
@@ -76,6 +76,10 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
7676
} elseif (pathStart = "dirname") {
7777
do %data.Write(##class(SourceControl.Git.Utils).TempFolder())
7878
set handled = 1
79+
} elseif (pathStart = "discarded-states") {
80+
set discardsInBranch = ##class(SourceControl.Git.DiscardState).DiscardStatesInBranch()
81+
do %data.Write(discardsInBranch.%ToJSON())
82+
set handled = 1
7983
}
8084
} elseif (%request.Method = "POST") {
8185
// Things not handled from Python backend:
@@ -163,6 +167,22 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
163167
set requestBody = ##class(%Library.DynamicObject).%FromJSON(%request.Content)
164168
set command = requestBody.command
165169

170+
set gitCmd = command.%Get(0)
171+
172+
if gitCmd = "restore" {
173+
set iter = command.%GetIterator()
174+
set isFile = 0
175+
while iter.%GetNext(,.value) {
176+
if isFile {
177+
set internalName = ##class(SourceControl.Git.Utils).NameToInternalName(value)
178+
do ##class(SourceControl.Git.DiscardState).SaveDiscardState(internalName)
179+
}
180+
if value = "--"{
181+
set isFile = 1
182+
}
183+
}
184+
}
185+
166186
set argsArr = ""
167187
set argsArr($increment(argsArr)) = "color.ui=true"
168188
set iterator = command.%GetIterator()

git-webui/release/share/git-webui/webui/css/git-webui.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ body {
205205
#sidebar #sidebar-content #sidebar-stash h4:before {
206206
content: url(../img/inboxes.svg);
207207
}
208+
#sidebar #sidebar-content #sidebarDiscarded h4:before {
209+
content: url(../img/discarded.svg);
210+
}
208211
#sidebar #sidebar-content #sidebar-remote h4:before {
209212
content: url(../img/daemon.svg);
210213
}
Lines changed: 1 addition & 0 deletions
Loading

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

Lines changed: 95 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,9 @@ webui.SideBarView = function(mainView, noEventHandlers) {
866866
'<section id="sidebar-stash">' +
867867
'<h4>Stash</h4>' +
868868
'</section>' +
869+
'<section id="sidebarDiscarded">' +
870+
'<h4>Discarded Files</h4>' +
871+
'</section>' +
869872
'<section id="sidebar-local-branches">' +
870873
'<h4 class="mt-3">Local Branches' +
871874
'<button type="button" class="btn btn-default btn-sidebar-icon btn-add shadow-none" >' +
@@ -904,6 +907,13 @@ webui.SideBarView = function(mainView, noEventHandlers) {
904907
self.mainView.stashView.update(0);
905908
});
906909

910+
var discardedElement = $("#sidebarDiscarded", self.element);
911+
discardedElement.click(function() {
912+
$("*", self.element).removeClass("active");
913+
discardedElement.addClass("active");
914+
self.mainView.discardedView.show();
915+
});
916+
907917
$(".btn-add", self.element).click(self.createNewLocalBranch);
908918
$('.btn-prune-remote-branches', self.element).click(self.pruneRemoteBranches);
909919
$("#sidebar-settings", self.element).click(self.goToSettingsPage);
@@ -1823,6 +1833,28 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
18231833
var gitApplyType = "stage";
18241834
};
18251835

1836+
webui.DiscardedView = function(mainView) {
1837+
var self = this;
1838+
1839+
self.show = function() {
1840+
self.update();
1841+
mainView.switchTo(self.element);
1842+
};
1843+
1844+
self.getDiscardedStates = function() {
1845+
$.get("discarded-states", function(discarded) {
1846+
console.log(discarded);
1847+
});
1848+
}
1849+
1850+
self.update = function() {
1851+
self.getDiscardedStates();
1852+
}
1853+
1854+
self.element = $('<div id="discardedView"></div>')[0];
1855+
1856+
}
1857+
18261858
/*
18271859
* == TreeView ================================================================
18281860
*/
@@ -2366,7 +2398,7 @@ webui.NewChangedFilesView = function(workspaceView) {
23662398
if (selectedItemsFromOtherUser.length > 0) {
23672399
self.confirmActionOnOtherUsersChanges("discard");
23682400
} else {
2369-
self.discard();
2401+
self.confirmDiscard();
23702402
}
23712403
});
23722404

@@ -2383,6 +2415,59 @@ webui.NewChangedFilesView = function(workspaceView) {
23832415
});
23842416
}
23852417

2418+
self.confirmDiscard = function() {
2419+
function removePopup(popup) {
2420+
$(popup).children(".modal-fade").modal("hide");
2421+
$(".modal-backdrop").remove();
2422+
$("#confirmDiscard").remove();
2423+
}
2424+
2425+
var popup = $(
2426+
'<div class="modal fade" tabindex="-1" id="confirmDiscard" role="dialog" data-backdrop="static">' +
2427+
'<div class="modal-dialog modal-md" role="document">' +
2428+
'<div class="modal-content">' +
2429+
'<div class="modal-header">' +
2430+
'<h5 class="modal-title">Confirm Discard</h5>' +
2431+
'<button type="button" class="btn btn-default close" data-dismiss="modal">' + webui.largeXIcon + '</button>' +
2432+
'</div>' +
2433+
'<div class="modal-body">' +
2434+
'<div class="row">' +
2435+
'<div class="col-sm-1">' +
2436+
webui.warningIcon +
2437+
'</div>' +
2438+
'<div class="col-sm-11">' +
2439+
'<p>Careful, discarding changes will delete all changes made to your file since the last commit. This will mean deleting a newly created file.</p>' + // Removed extra closing </p> tag
2440+
'</div>' +
2441+
'</div>' +
2442+
'</div>' +
2443+
'<div class="modal-footer"></div>' +
2444+
'</div>' +
2445+
'</div>' +
2446+
'</div>'
2447+
)[0];
2448+
2449+
$("body").append(popup);
2450+
2451+
var popupFooter = $(".modal-footer", popup)[0];
2452+
webui.detachChildren(popupFooter);
2453+
2454+
$(
2455+
'<button class="btn btn-sm btn-warning action-btn" id="confirmDiscardBtn">Confirm discard</button>' +
2456+
'<button class="btn btn-sm btn-secondary action-btn" id="cancelDiscardBtn">Cancel</button>'
2457+
).appendTo(popupFooter);
2458+
2459+
$(popup).modal('show');
2460+
2461+
$("#confirmDiscardBtn").on('click', function() {
2462+
removePopup(popup);
2463+
self.discard();
2464+
});
2465+
2466+
$("#confirmDiscard").find(".close, #cancelDiscardBtn").click(function() {
2467+
removePopup(popup);
2468+
})
2469+
}
2470+
23862471
self.confirmAmend = function() {
23872472
function removePopup(popup) {
23882473
$(popup).children(".modal-fade").modal("hide");
@@ -2395,7 +2480,7 @@ webui.NewChangedFilesView = function(workspaceView) {
23952480
'<div class="modal-dialog modal-md" role="document">' +
23962481
'<div class="modal-content">' +
23972482
'<div class="modal-header">' +
2398-
'<h5 class="modal-title">Confirm amend</h5>' +
2483+
'<h5 class="modal-title">Confirm Amend</h5>' +
23992484
'<button type="button" class="btn btn-default close" data-dismiss="modal">' + webui.largeXIcon + '</button>' +
24002485
'</div>' +
24012486
'<div class="modal-body"></div>' +
@@ -2482,6 +2567,11 @@ webui.NewChangedFilesView = function(workspaceView) {
24822567
$( '<div>' +
24832568
'<p>Careful, amending commits will rewrite the branch history. The amended commit will not be pushed to remote, even if the previous commit was.</p>' +
24842569
'</div>').appendTo(popupContent);
2570+
} else if (action == "discard") {
2571+
$(
2572+
'<div>' +
2573+
'<p>Careful, discarding changes will delete all changes made to your file since the last commit. This will mean deleting a newly created file.</p>' +
2574+
'</div>').appendTo(popupContent);
24852575
}
24862576

24872577
var popupFooter = $(".modal-footer", popup)[0];
@@ -2624,9 +2714,8 @@ webui.NewChangedFilesView = function(workspaceView) {
26242714
}
26252715

26262716
self.discard = function() {
2627-
var selectedFilesAsString = selectedItems.join(" ");
2628-
webui.git("add -- " + selectedFilesAsString, function() {
2629-
webui.git("restore --staged --worktree -- " + selectedFilesAsString, function() {
2717+
webui.git_command(["add", "--"].concat(selectedItems), function() {
2718+
webui.git_command(["restore", "--staged", "--worktree", "--"].concat(selectedItems), function() {
26302719
workspaceView.update();
26312720
});
26322721
});
@@ -2733,6 +2822,7 @@ function MainUi() {
27332822
if (!webui.viewonly) {
27342823
self.workspaceView = new webui.WorkspaceView(self);
27352824
self.stashView = new webui.StashView(self);
2825+
self.discardedView = new webui.DiscardedView(self);
27362826
}
27372827
self.sideBarView.selectRef("HEAD");
27382828
});

git-webui/src/share/git-webui/webui/css/git-webui.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ body {
287287
content: url(../img/inboxes.svg);
288288
}
289289

290+
#sidebarDiscarded h4:before {
291+
content: url(../img/discarded.svg);
292+
}
293+
290294
#sidebar-remote h4:before {
291295
content: url(../img/daemon.svg);
292296
}
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)