Skip to content

Commit 157d198

Browse files
committed
working on modal to confirm action to other user change
1 parent 9d912b3 commit 157d198

File tree

5 files changed

+238
-10
lines changed

5 files changed

+238
-10
lines changed

cls/SourceControl/Git/WebUIDriver.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Class SourceControl.Git.WebUIDriver
22
{
3+
34

45
ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Output handled As %Boolean = 0, Output %data As %Stream.Object)
56
{

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
@@ -913,6 +913,9 @@ body {
913913
position: absolute;
914914
right: 5px;
915915
}
916+
#changedFilesContainer .file-area .other-user-label::before {
917+
content: "HI";
918+
}
916919
#changedFilesContainer .commit-area {
917920
padding-top: 15px;
918921
}

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

Lines changed: 115 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,6 +2512,7 @@ webui.NewChangedFilesView = function(workspaceView) {
25122512
self.update = function() {
25132513
$(fileList).empty();
25142514
selectedItems = [];
2515+
selectedItemsFromOtherUser = [];
25152516
$('#stashBtn').prop("disabled", true);
25162517
$('#discardBtn').prop("disabled", true);
25172518
$('#commitBtn').prop("disabled", true);
@@ -2523,15 +2524,35 @@ webui.NewChangedFilesView = function(workspaceView) {
25232524
$.get("api/uncommitted", function (uncommitted) {
25242525
var uncommittedItems = JSON.parse(uncommitted)["current user's changes"];
25252526
self.filesCount = 0;
2526-
function addItemToFileList(fileList, workingTreeStatus, model) {
2527-
var formCheck = $('<div class="form-check changes-check"></div>');
2527+
function addItemToFileList(fileList, workingTreeStatus, model, isOtherUserChange) {
2528+
2529+
var formCheck;
2530+
if (isOtherUserChange) {
2531+
formCheck = $('<div class="form-check changes-check other-user"></div>');
2532+
} else {
2533+
formCheck = $('<div class="form-check changes-check"></div>');
2534+
}
2535+
25282536
formCheck.attr("data-filename", model);
25292537

2530-
var checkboxInput = $('<input class="form-check-input changes-checkbox" type="checkbox" value="">');
2538+
var checkboxInput;
2539+
2540+
if (isOtherUserChange) {
2541+
checkboxInput = $('<input class="form-check-input changes-checkbox other-user" type="checkbox" value="">');
2542+
} else {
2543+
checkboxInput = $('<input class="form-check-input changes-checkbox" type="checkbox" value="">');
2544+
}
2545+
25312546
checkboxInput.attr('id', model);
25322547
formCheck.append(checkboxInput);
25332548

2534-
var checkboxLabel = $('<label class="form-check-label file-item-label"></label>').text(model);
2549+
var checkboxLabel;
2550+
if (isOtherUserChange) {
2551+
checkboxLabel = $('<label class="form-check-label file-item-label other-user-label"></label>').text(model);
2552+
} else {
2553+
checkboxLabel = $('<label class="form-check-label file-item-label"></label>').text(model);
2554+
}
2555+
25352556
checkboxLabel.addClass(workingTreeStatus);
25362557
checkboxLabel.attr('for', model);
25372558
formCheck.append(checkboxLabel);
@@ -2542,6 +2563,7 @@ webui.NewChangedFilesView = function(workspaceView) {
25422563
// $(item).click(self.select);
25432564

25442565
}
2566+
25452567
webui.splitLines(data).forEach(function(line) {
25462568
var indexStatus = line[0];
25472569
var workingTreeStatus = line[1];
@@ -2564,7 +2586,9 @@ webui.NewChangedFilesView = function(workspaceView) {
25642586
}
25652587

25662588
if (isForCurrentUser) {
2567-
addItemToFileList(fileList, workingTreeStatus, model);
2589+
addItemToFileList(fileList, workingTreeStatus, model, false);
2590+
} else {
2591+
addItemToFileList(fileList, workingTreeStatus, model, true)
25682592
}
25692593

25702594
});
@@ -2610,13 +2634,78 @@ webui.NewChangedFilesView = function(workspaceView) {
26102634
});
26112635
}
26122636

2637+
self.confirmActionOnOtherUsersChanges = function(action) {
2638+
function removeWarningModal(popup) {
2639+
$(popup).children(".modal-fade").modal("hide");
2640+
$(".modal-backdrop").remove();
2641+
$("#confirmAction").remove();
2642+
modalOpen = false;
2643+
}
2644+
2645+
var popup = $( '<div class="modal fade" id="confirmAction" role="dialog" data-backdrop="static">' +
2646+
'<div class="modal-dialog modal-md">' +
2647+
'<div class="modal-content>' +
2648+
'<div class="modal-header">' +
2649+
'<h5 class="modal-title">Confirm ' + action + '</h5>' +
2650+
'<button type="button" class="btn btn-default close" data-dismiss="modal">'+
2651+
webui.largeXIcon+
2652+
'</button>' +
2653+
'</div>' +
2654+
'<div class="modal-body"></div>' +
2655+
'</div>' +
2656+
'</div>' +
2657+
2658+
'</div>')[0];
2659+
$("body").append(popup);
2660+
var popupContent = $(".modal-body", popup)[0];
2661+
webui.detachChildren(popupContent);
2662+
$('<div class="row"><div class="col-sm-1">'+
2663+
webui.warningIcon+
2664+
'</div>'+
2665+
'<div class="col-sm-11">The following files were changed by other users. Are you sure you want to ' + action + ' them?</div></div><ul>').appendTo(popupContent);
2666+
2667+
selectedItemsFromOtherUser.forEach(function(file, index){
2668+
$('<li>'+ file +'</li>').appendTo(popupContent);
2669+
});
2670+
2671+
$('</ul>').appendTo(popupContent);
2672+
2673+
$('<button class="btn btn-sm btn-warning float-right" id="confirmActionBtn">' + action.charAt(0).toUpperCase()+action.substring(1) + '</button>' +
2674+
'<button class="btn btn-sm btn-secondary float-right" id="cancelActionBtn">Cancel</button>').appendTo(popupContent);
2675+
2676+
$(popup).modal('show');
2677+
var modalOpen = true;
2678+
2679+
var actionConfirmed = false;
2680+
2681+
$('#confirmAction').on('click', '#confirmActionBtn', function() {
2682+
actionConfirmed = true;
2683+
removeWarningModal(popup);
2684+
});
2685+
2686+
$('#confirmAction').find('#cancelAction, .close').click(function() {
2687+
removeWarningModal(popup);
2688+
})
2689+
2690+
while(modalOpen) {
2691+
// spin
2692+
}
2693+
2694+
return actionConfirmed;
2695+
}
2696+
26132697
self.afterFileChecked = function(element) {
26142698
var fileName = element.id;
26152699
var fileIndex = selectedItems.indexOf(fileName);
26162700
if (element.checked) {
26172701
if (fileIndex == -1) {
26182702
selectedItems.push(fileName);
26192703
}
2704+
2705+
if (element.hasClass("other-user") && (selectedItems.indexOf(fileName) == -1)) {
2706+
selectedItemsFromOtherUser.push(fileName);
2707+
}
2708+
26202709
if (selectedItems.length == Array.from(fileList.children).length) {
26212710
$('#selectAllFiles').prop('checked', true);
26222711
}
@@ -2625,6 +2714,10 @@ webui.NewChangedFilesView = function(workspaceView) {
26252714
if (fileIndex > -1) {
26262715
selectedItems.splice(fileIndex, 1);
26272716
}
2717+
2718+
if (element.hasClass("other-user") && (selectedItems.indexOf(fileName) > -1)) {
2719+
selectedItemsFromOtherUser.splice(selectedItems.indexOf(fileName), 1);
2720+
}
26282721
}
26292722
self.updateButtons();
26302723
}
@@ -2689,6 +2782,11 @@ webui.NewChangedFilesView = function(workspaceView) {
26892782

26902783
self.stash = function() {
26912784
var selectedFilesAsString = selectedItems.join(" ");
2785+
if (selectedItemsFromOtherUser.length > 0) {
2786+
if (!this.confirmActionOnOtherUsersChanges("stash")) {
2787+
return
2788+
}
2789+
}
26922790
webui.git("stash push -- " + selectedFilesAsString, function(output){
26932791
webui.showSuccess(output);
26942792
workspaceView.update();
@@ -2697,13 +2795,24 @@ webui.NewChangedFilesView = function(workspaceView) {
26972795

26982796
self.discard = function() {
26992797
var selectedFilesAsString = selectedItems.join(" ");
2798+
if (selectedItemsFromOtherUser.length > 0) {
2799+
if (!this.confirmActionOnOtherUsersChanges("discard")) {
2800+
return
2801+
}
2802+
}
27002803
webui.git("restore -- " + selectedFilesAsString, function(output) {
27012804
workspaceView.update();
27022805
});
27032806
}
27042807

27052808
self.commit = function(message) {
27062809
var selectedFilesAsString = selectedItems.join(" ");
2810+
2811+
if (selectedItemsFromOtherUser.length > 0) {
2812+
if (!this.confirmActionOnOtherUsersChanges("commit")) {
2813+
return
2814+
}
2815+
}
27072816
webui.git("add " + selectedFilesAsString);
27082817
webui.git('commit -m "' + message + '" -- ' + selectedFilesAsString, function(output) {
27092818
webui.showSuccess(output);
@@ -2740,6 +2849,7 @@ webui.NewChangedFilesView = function(workspaceView) {
27402849
var fileListContainer = $(".file-area", self.element)[0];
27412850
var fileList = $(".changed-files-list", fileListContainer)[0];
27422851
var selectedItems = [];
2852+
var selectedItemsFromOtherUser = [];
27432853
var fileToDiff;
27442854

27452855
}

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
@@ -898,6 +898,10 @@ body {
898898
position: absolute;
899899
right: 5px;
900900
}
901+
902+
.other-user-label::before {
903+
content: "HI";
904+
}
901905

902906
}
903907

0 commit comments

Comments
 (0)