Skip to content

Commit d694d50

Browse files
authored
Force delete (#44)
* Confirmation alert pops up when the user presses delete branch button * Added icon to alert * Committing logging to test error messaging on checkout * Committing logging to test error messaging on checkout * The error messages now display correctly. See code comments. * Force Delete feature * Minor bug fix * Cancel button on force delete modal fixed Co-authored-by: Sarmishta Velury <[email protected]>
1 parent 3bfadf6 commit d694d50

File tree

3 files changed

+153
-33
lines changed

3 files changed

+153
-33
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ body {
3636
font-size:105%;
3737
}
3838

39-
#confirm-delete, #cancel-delete {
39+
#confirm-delete, #cancel-delete, #confirm-force-delete {
4040
margin-left: 1rem;
4141
margin-top: 0.5rem;
4242
}

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

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ webui.showWarning = function(message) {
5757
'</div>').appendTo(messageBox);
5858
}
5959

60-
webui.git = function(cmd, arg1, arg2) {
60+
webui.git = function(cmd, arg1, arg2, arg3, arg4) {
6161
// cmd = git command line arguments
62-
// other arguments = optional stdin content and a callback function:
62+
// other arguments = optional stdin content and a callback function.
63+
// arg3 = optional callback for error handling
64+
// arg4 = optional callback for warning handling
6365
// ex:
6466
// git("log", mycallback)
6567
// git("commit -F -", "my commit message", mycallback)
@@ -70,6 +72,14 @@ webui.git = function(cmd, arg1, arg2) {
7072
cmd += "\n" + arg1;
7173
var callback = arg2;
7274
}
75+
76+
if (typeof(arg3) == "function") {
77+
var errorCallback = arg3;
78+
}
79+
if (typeof(arg4) == "function") {
80+
var warningCallback = arg4;
81+
}
82+
7383
$.post("git", cmd, function(data, status, xhr) {
7484
if (xhr.status == 200) {
7585
// Convention : last lines are footer meta data like headers. An empty line marks the start if the footers
@@ -105,13 +115,25 @@ webui.git = function(cmd, arg1, arg2) {
105115
}
106116
// Return code is 0 but there is stderr output: this is a warning message
107117
if (message.length > 0) {
108-
webui.showWarning(message);
118+
if(warningCallback) {
119+
warningCallback(message);
120+
} else {
121+
webui.showWarning(message);
122+
}
109123
}
110124
} else {
111-
webui.showError(message);
125+
if(errorCallback) {
126+
errorCallback(message);
127+
} else{
128+
webui.showError(message);
129+
}
112130
}
113131
} else {
114-
webui.showError(data);
132+
if(errorCallback) {
133+
errorCallback(message);
134+
} else{
135+
webui.showError(message);
136+
}
115137
}
116138
}, "text")
117139
.fail(function(xhr, status, error) {
@@ -1781,6 +1803,12 @@ function updateSideBar () {
17811803
$(sideBarView).replaceWith(MainUIObject.sideBarView.element);
17821804
}
17831805

1806+
function removeAllChildNodes(parent) {
1807+
while (parent.firstChild) {
1808+
parent.removeChild(parent.firstChild);
1809+
}
1810+
}
1811+
17841812
$(function () {
17851813
$('[data-toggle="tooltip"]').tooltip()
17861814
})
@@ -1827,6 +1855,12 @@ $(function () {
18271855

18281856
$(document).on('click', '.btn-delete-branch', function(e) {
18291857
e.preventDefault();
1858+
1859+
function removeDeleteModal(popup) {
1860+
$(popup).children( ".modal-fade").modal('hide');
1861+
$(".modal-backdrop").remove();
1862+
$("#confirm-branch-delete").remove();
1863+
}
18301864
$("#confirm-branch-delete").remove(); //removes any remaining modals. If there are more than one modals, the ids are duplicated and event listeners won't work.
18311865
var refName = $(this).parent().parent().parent().siblings(
18321866
".card-header").children("button").html();
@@ -1861,20 +1895,46 @@ $(function () {
18611895
$(popup).modal('show');
18621896

18631897
$("#confirm-branch-delete").on('click', '#confirm-delete', function(e){
1864-
$(popup).children( ".modal-fade").modal('hide');
1865-
$(".modal-backdrop").remove();
1866-
$("#confirm-branch-delete").remove();
1867-
webui.git("branch -d " + refName, function() {
1868-
webui.showWarning("Local branch " + refName + " deleted.");
1898+
1899+
removeDeleteModal(popup);
1900+
1901+
function deleteSuccessDisplay(output) {
1902+
webui.showWarning(output);
18691903
updateSideBar();
1870-
});
1871-
1872-
});
1904+
}
1905+
1906+
function forceDelete(message) {
1907+
if(message.includes("git branch -D")){
1908+
$("body").append(popup);
1909+
var popupContent = $(".modal-body", popup)[0];
1910+
removeAllChildNodes(popupContent);
1911+
$('<div class="row"><div class="col-sm-1">'+
1912+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="#dc3545" class="bi bi-exclamation-circle-fill" viewBox="0 0 16 16">'+
1913+
'<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8 4a.905.905 0 0 0-.9.995l.35 3.507a.552.552 0 0 0 1.1 0l.35-3.507A.905.905 0 0 0 8 4zm.002 6a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"></path>'+
1914+
'</svg></div>'+
1915+
'<div class="col-sm-11">This branch is not fully merged. Do you want to force delete it?</div></div>'+
1916+
'<button class="btn btn-sm btn-danger float-right" id="confirm-force-delete">Force Delete</button>'+
1917+
'<button class="btn btn-sm btn-secondary float-right" id="cancel-delete">Cancel</button>').appendTo(popupContent);
1918+
$(popup).modal('show');
1919+
1920+
$("#confirm-branch-delete").on('click', '#confirm-force-delete', function(e){
1921+
removeDeleteModal(popup);
1922+
webui.git("branch -D " + refName, deleteSuccessDisplay);
1923+
});
1924+
1925+
$("#confirm-branch-delete").find("#cancel-delete, .close").click(function() {
1926+
removeDeleteModal(popup);
1927+
});
1928+
}
1929+
else {
1930+
webui.showError(message);
1931+
}
1932+
}
1933+
webui.git("branch -d " + refName, deleteSuccessDisplay, "", forceDelete);
1934+
});
18731935

18741936
$("#confirm-branch-delete").find("#cancel-delete, .close").click(function() {
1875-
$(popup).children( ".modal-fade").modal('hide');
1876-
$(".modal-backdrop").remove();
1877-
$("#confirm-branch-delete").remove();
1937+
removeDeleteModal(popup);
18781938
});
18791939

18801940
});

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

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ webui.showWarning = function(message) {
5757
'</div>').appendTo(messageBox);
5858
}
5959

60-
webui.git = function(cmd, arg1, arg2) {
60+
webui.git = function(cmd, arg1, arg2, arg3, arg4) {
6161
// cmd = git command line arguments
62-
// other arguments = optional stdin content and a callback function:
62+
// other arguments = optional stdin content and a callback function.
63+
// arg3 = optional callback for error handling
64+
// arg4 = optional callback for warning handling
6365
// ex:
6466
// git("log", mycallback)
6567
// git("commit -F -", "my commit message", mycallback)
@@ -70,6 +72,14 @@ webui.git = function(cmd, arg1, arg2) {
7072
cmd += "\n" + arg1;
7173
var callback = arg2;
7274
}
75+
76+
if (typeof(arg3) == "function") {
77+
var errorCallback = arg3;
78+
}
79+
if (typeof(arg4) == "function") {
80+
var warningCallback = arg4;
81+
}
82+
7383
$.post("git", cmd, function(data, status, xhr) {
7484
if (xhr.status == 200) {
7585
// Convention : last lines are footer meta data like headers. An empty line marks the start if the footers
@@ -105,13 +115,25 @@ webui.git = function(cmd, arg1, arg2) {
105115
}
106116
// Return code is 0 but there is stderr output: this is a warning message
107117
if (message.length > 0) {
108-
webui.showWarning(message);
118+
if(warningCallback) {
119+
warningCallback(message);
120+
} else {
121+
webui.showWarning(message);
122+
}
109123
}
110124
} else {
111-
webui.showError(message);
125+
if(errorCallback) {
126+
errorCallback(message);
127+
} else{
128+
webui.showError(message);
129+
}
112130
}
113131
} else {
114-
webui.showError(data);
132+
if(errorCallback) {
133+
errorCallback(message);
134+
} else{
135+
webui.showError(message);
136+
}
115137
}
116138
}, "text")
117139
.fail(function(xhr, status, error) {
@@ -1781,6 +1803,12 @@ function updateSideBar () {
17811803
$(sideBarView).replaceWith(MainUIObject.sideBarView.element);
17821804
}
17831805

1806+
function removeAllChildNodes(parent) {
1807+
while (parent.firstChild) {
1808+
parent.removeChild(parent.firstChild);
1809+
}
1810+
}
1811+
17841812
$(function () {
17851813
$('[data-toggle="tooltip"]').tooltip()
17861814
})
@@ -1827,6 +1855,12 @@ $(function () {
18271855

18281856
$(document).on('click', '.btn-delete-branch', function(e) {
18291857
e.preventDefault();
1858+
1859+
function removeDeleteModal(popup) {
1860+
$(popup).children( ".modal-fade").modal('hide');
1861+
$(".modal-backdrop").remove();
1862+
$("#confirm-branch-delete").remove();
1863+
}
18301864
$("#confirm-branch-delete").remove(); //removes any remaining modals. If there are more than one modals, the ids are duplicated and event listeners won't work.
18311865
var refName = $(this).parent().parent().parent().siblings(
18321866
".card-header").children("button").html();
@@ -1861,20 +1895,46 @@ $(function () {
18611895
$(popup).modal('show');
18621896

18631897
$("#confirm-branch-delete").on('click', '#confirm-delete', function(e){
1864-
$(popup).children( ".modal-fade").modal('hide');
1865-
$(".modal-backdrop").remove();
1866-
$("#confirm-branch-delete").remove();
1867-
webui.git("branch -d " + refName, function() {
1868-
webui.showWarning("Local branch " + refName + " deleted.");
1898+
1899+
removeDeleteModal(popup);
1900+
1901+
function deleteSuccessDisplay(output) {
1902+
webui.showWarning(output);
18691903
updateSideBar();
1870-
});
1871-
1872-
});
1904+
}
1905+
1906+
function forceDelete(message) {
1907+
if(message.includes("git branch -D")){
1908+
$("body").append(popup);
1909+
var popupContent = $(".modal-body", popup)[0];
1910+
removeAllChildNodes(popupContent);
1911+
$('<div class="row"><div class="col-sm-1">'+
1912+
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="#dc3545" class="bi bi-exclamation-circle-fill" viewBox="0 0 16 16">'+
1913+
'<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8 4a.905.905 0 0 0-.9.995l.35 3.507a.552.552 0 0 0 1.1 0l.35-3.507A.905.905 0 0 0 8 4zm.002 6a1 1 0 1 0 0 2 1 1 0 0 0 0-2z"></path>'+
1914+
'</svg></div>'+
1915+
'<div class="col-sm-11">This branch is not fully merged. Do you want to force delete it?</div></div>'+
1916+
'<button class="btn btn-sm btn-danger float-right" id="confirm-force-delete">Force Delete</button>'+
1917+
'<button class="btn btn-sm btn-secondary float-right" id="cancel-delete">Cancel</button>').appendTo(popupContent);
1918+
$(popup).modal('show');
1919+
1920+
$("#confirm-branch-delete").on('click', '#confirm-force-delete', function(e){
1921+
removeDeleteModal(popup);
1922+
webui.git("branch -D " + refName, deleteSuccessDisplay);
1923+
});
1924+
1925+
$("#confirm-branch-delete").find("#cancel-delete, .close").click(function() {
1926+
removeDeleteModal(popup);
1927+
});
1928+
}
1929+
else {
1930+
webui.showError(message);
1931+
}
1932+
}
1933+
webui.git("branch -d " + refName, deleteSuccessDisplay, "", forceDelete);
1934+
});
18731935

18741936
$("#confirm-branch-delete").find("#cancel-delete, .close").click(function() {
1875-
$(popup).children( ".modal-fade").modal('hide');
1876-
$(".modal-backdrop").remove();
1877-
$("#confirm-branch-delete").remove();
1937+
removeDeleteModal(popup);
18781938
});
18791939

18801940
});

0 commit comments

Comments
 (0)