@@ -1574,10 +1574,20 @@ webui.ChangedFilesView = function(workspaceView, type, label) {
1574
1574
} else {
1575
1575
model = line ;
1576
1576
}
1577
- var isForCurrentUser = true ; // (uncommittedItems.indexOf(model) > -1);
1577
+ var isForCurrentUser = ( uncommittedItems . indexOf ( model ) > - 1 ) ;
1578
1578
var cssClass = isForCurrentUser ? 'list-group-item available' : 'list-group-item unavailable' ;
1579
1579
1580
- var item = $ ( '<a class="' + cssClass + '">' ) . appendTo ( fileList ) [ 0 ] ;
1580
+ if ( isForCurrentUser ) {
1581
+ var item = $ ( '<a class="' + cssClass + '">' ) . prependTo ( fileList ) [ 0 ] ;
1582
+ }
1583
+ else {
1584
+ var item = $ ( '<a class="' + cssClass + '">' +
1585
+ '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-people-fill" viewBox="0 0 16 16">' +
1586
+ '<path d="M7 14s-1 0-1-1 1-4 5-4 5 3 5 4-1 1-1 1H7zm4-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"/>' +
1587
+ '<path fill-rule="evenodd" d="M5.216 14A2.238 2.238 0 0 1 5 13c0-1.355.68-2.75 1.936-3.72A6.325 6.325 0 0 0 5 9c-4 0-5 3-5 4s1 1 1 1h4.216z"/>' +
1588
+ '<path d="M4.5 8a2.5 2.5 0 1 0 0-5 2.5 2.5 0 0 0 0 5z"/>' +
1589
+ '</svg>' ) . appendTo ( fileList ) [ 0 ] ;
1590
+ }
1581
1591
item . model = model ;
1582
1592
item . status = status ;
1583
1593
item . appendChild ( document . createTextNode ( line ) ) ;
@@ -1652,42 +1662,143 @@ webui.ChangedFilesView = function(workspaceView, type, label) {
1652
1662
}
1653
1663
} ;
1654
1664
1655
- self . getFileList = function ( including , excluding ) {
1656
- var files = "" ;
1665
+ function confirmActionForUnavailableFile ( files , action ) {
1666
+ function removeUnavailableModal ( popup ) {
1667
+ $ ( popup ) . children ( ".modal-fade" ) . modal ( 'hide' ) ;
1668
+ $ ( ".modal-backdrop" ) . remove ( ) ;
1669
+ $ ( "#confirm-unavailable-staging" ) . remove ( ) ;
1670
+ }
1671
+
1672
+ var popup = $ ( '<div class="modal fade" id="confirm-unavailable-staging" role="dialog">' +
1673
+ '<div class="modal-dialog modal-md">' +
1674
+ '<div class="modal-content">' +
1675
+ '<div class="modal-header">' +
1676
+ '<h5 class="modal-title">Confirm Staging</h5>' +
1677
+ '<button type="button" class="btn btn-default close" data-dismiss="modal">' +
1678
+ '<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-x-lg" viewBox="0 0 16 16">' +
1679
+ '<path fill-rule="evenodd" clip-rule="evenodd" d="M13.854 2.146a.5.5 0 0 1 0 .708l-11 11a.5.5 0 0 1-.708-.708l11-11a.5.5 0 0 1 .708 0Z" fill="#000"/>' +
1680
+ '<path fill-rule="evenodd" clip-rule="evenodd" d="M2.146 2.146a.5.5 0 0 0 0 .708l11 11a.5.5 0 0 0 .708-.708l-11-11a.5.5 0 0 0-.708 0Z" fill="#000"/>' +
1681
+ '</svg>' +
1682
+ '</button>' +
1683
+ '</div>' +
1684
+ '<div class="modal-body"></div>' +
1685
+ '</div>' +
1686
+ '</div>' +
1687
+ '</div>' ) [ 0 ] ;
1688
+ $ ( "body" ) . append ( popup ) ;
1689
+ var popupContent = $ ( ".modal-body" , popup ) [ 0 ] ;
1690
+ removeAllChildNodes ( popupContent ) ;
1691
+ $ ( '<div class="row"><div class="col-sm-1">' +
1692
+ '<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">' +
1693
+ '<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>' +
1694
+ '</svg></div>' +
1695
+ '<div class="col-sm-11">The following files were changed by other users. Are you sure you want to ' + action + ' them?</div></div>' ) . appendTo ( popupContent ) ;
1696
+
1697
+ files . forEach ( function ( file , index , array ) {
1698
+ $ ( '<div class="form-check">' +
1699
+ '<input class="form-check-input" type="checkbox" value="' + file . model + '" id="file' + index + '" checked>' +
1700
+ '<label class="form-check-label" for="file' + index + '">' + file . model +
1701
+ '</label>' +
1702
+ '</div>' ) . appendTo ( popupContent ) ;
1703
+ } ) ;
1704
+
1705
+
1706
+ $ ( '<button class="btn btn-sm btn-danger float-right" id="confirm-staging">' + action . charAt ( 0 ) . toUpperCase ( ) + action . substr ( 1 ) + '</button>' +
1707
+ '<button class="btn btn-sm btn-secondary float-right" id="cancel-staging">Cancel</button>' ) . appendTo ( popupContent ) ;
1708
+ $ ( popup ) . modal ( 'show' ) ;
1709
+
1710
+ $ ( "#confirm-unavailable-staging" ) . on ( 'click' , '#confirm-staging' , function ( e ) {
1711
+ var checkedFiles = $ ( "#confirm-unavailable-staging input[type=checkbox]:checked" ) ;
1712
+ for ( var i = 0 ; i < fileList . childElementCount ; ++ i ) {
1713
+ var newChild = fileList . children [ i ] ;
1714
+ for ( var j = 0 ; j < checkedFiles . length ; j ++ ) {
1715
+ if ( newChild . model == $ ( checkedFiles [ j ] ) . val ( ) ) {
1716
+ $ ( newChild ) . addClass ( "available" ) ;
1717
+ $ ( newChild ) . addClass ( "active" ) ;
1718
+ $ ( newChild ) . removeClass ( "unavailable" ) ;
1719
+ }
1720
+ }
1721
+ }
1722
+ removeUnavailableModal ( popup ) ;
1723
+ if ( action == 'discard' ) {
1724
+ self . cancel ( )
1725
+ }
1726
+ else {
1727
+ self . process ( ) ;
1728
+ }
1729
+ } ) ;
1730
+
1731
+ $ ( "#confirm-unavailable-staging" ) . find ( "#cancel-staging, .close" ) . click ( function ( ) {
1732
+ removeUnavailableModal ( popup ) ;
1733
+ } ) ;
1734
+ }
1735
+
1736
+ self . getFileList = function ( including , excluding , onlyUnavailable = 0 , stringifyFilenames = 1 ) {
1737
+ if ( stringifyFilenames )
1738
+ var files = "" ;
1739
+ else
1740
+ var files = [ ] ;
1741
+
1657
1742
for ( var i = 0 ; i < fileList . childElementCount ; ++ i ) {
1658
1743
var child = fileList . children [ i ] ;
1659
1744
var included = including == undefined || including . indexOf ( child . status ) != - 1 ;
1660
1745
var excluded = excluding != undefined && excluding . indexOf ( child . status ) != - 1 ;
1661
- if ( $ ( child ) . hasClass ( "active" ) && $ ( child ) . hasClass ( "available" ) && included && ! excluded ) {
1662
- files += '"' + ( child . model ) + '" ' ;
1746
+ if ( $ ( child ) . hasClass ( "active" ) && ( $ ( child ) . hasClass ( "available" ) ^ onlyUnavailable ) && included && ! excluded ) {
1747
+ if ( stringifyFilenames )
1748
+ files += '"' + ( child . model ) + '" ' ;
1749
+ else
1750
+ files . push ( child ) ;
1663
1751
}
1664
1752
}
1665
1753
return files ;
1666
1754
}
1667
1755
1668
1756
self . process = function ( ) {
1669
- prevScrollTop = fileListContainer . scrollTop ;
1670
- var files = self . getFileList ( undefined , "D" ) ;
1671
- var rmFiles = self . getFileList ( "D" ) ;
1757
+ var action = type == "working-copy" ? "stage" : "unstage"
1758
+ var files = self . getFileList ( undefined , "D" , 0 ) ;
1759
+ var rmFiles = self . getFileList ( "D" , undefined , 0 ) ;
1760
+
1672
1761
if ( files . length != 0 ) {
1673
1762
var cmd = type == "working-copy" ? "add" : "reset" ;
1674
1763
webui . git ( cmd + " -- " + files , function ( data ) {
1675
1764
if ( rmFiles . length != 0 ) {
1676
1765
webui . git ( "rm -- " + rmFiles , function ( data ) {
1677
- workspaceView . update ( type == "working-copy" ? "stage" : "unstage" ) ;
1766
+ workspaceView . update ( action ) ;
1678
1767
} ) ;
1679
1768
} else {
1680
- workspaceView . update ( type == "working-copy" ? "stage" : "unstage" ) ;
1769
+ workspaceView . update ( action ) ;
1681
1770
}
1682
1771
} ) ;
1683
1772
} else if ( rmFiles . length != 0 ) {
1684
1773
var cmd = type == "working-copy" ? "rm" : "reset" ;
1685
1774
webui . git ( cmd + " -- " + rmFiles , function ( data ) {
1686
- workspaceView . update ( type == "working-copy" ? "stage" : "unstage" ) ;
1775
+ workspaceView . update ( action ) ;
1687
1776
} ) ;
1688
1777
}
1689
1778
} ;
1690
1779
1780
+ self . processByAvailability = function ( ) {
1781
+ prevScrollTop = fileListContainer . scrollTop ;
1782
+ self . process ( ) ;
1783
+
1784
+ var action = type == "working-copy" ? "stage" : "unstage"
1785
+ var files = self . getFileList ( undefined , "D" , 1 , 0 ) ;
1786
+ var rmFiles = self . getFileList ( "D" , undefined , 1 , 0 ) ;
1787
+ var combinedFiles = files . concat ( rmFiles ) ;
1788
+
1789
+ if ( combinedFiles . length > 0 )
1790
+ confirmActionForUnavailableFile ( combinedFiles , action ) ;
1791
+ }
1792
+
1793
+ self . cancelByAvailability = function ( ) {
1794
+ prevScrollTop = fileListContainer . scrollTop ;
1795
+
1796
+ var action = "discard"
1797
+ var files = self . getFileList ( undefined , undefined , 1 , 0 ) ;
1798
+ if ( files . length > 0 )
1799
+ confirmActionForUnavailableFile ( files , action ) ;
1800
+ }
1801
+
1691
1802
self . cancel = function ( ) {
1692
1803
prevScrollTop = fileListContainer . scrollTop ;
1693
1804
var files = self . getFileList ( ) ;
@@ -1712,9 +1823,9 @@ webui.ChangedFilesView = function(workspaceView, type, label) {
1712
1823
'</div>' +
1713
1824
'</div>' ) [ 0 ] ;
1714
1825
if ( type == "working-copy" ) {
1715
- var buttons = [ { name : "Stage" , callback : self . process } , { name : "Cancel" , callback : self . cancel } ] ;
1826
+ var buttons = [ { name : "Stage" , callback : self . processByAvailability } , { name : "Cancel" , callback : self . cancelByAvailability } ] ;
1716
1827
} else {
1717
- var buttons = [ { name : "Unstage" , callback : self . process } ] ;
1828
+ var buttons = [ { name : "Unstage" , callback : self . processByAvailability } ] ;
1718
1829
}
1719
1830
var btnGroup = $ ( ".btn-group" , self . element ) ;
1720
1831
buttons . forEach ( function ( btnData ) {
@@ -1893,14 +2004,15 @@ $(function () {
1893
2004
} ) ;
1894
2005
} ) ;
1895
2006
2007
+ function removeDeleteModal ( popup ) {
2008
+ $ ( popup ) . children ( ".modal-fade" ) . modal ( 'hide' ) ;
2009
+ $ ( ".modal-backdrop" ) . remove ( ) ;
2010
+ $ ( "#confirm-branch-delete" ) . remove ( ) ;
2011
+ }
2012
+
1896
2013
$ ( document ) . on ( 'click' , '.btn-delete-branch' , function ( e ) {
1897
2014
e . preventDefault ( ) ;
1898
2015
1899
- function removeDeleteModal ( popup ) {
1900
- $ ( popup ) . children ( ".modal-fade" ) . modal ( 'hide' ) ;
1901
- $ ( ".modal-backdrop" ) . remove ( ) ;
1902
- $ ( "#confirm-branch-delete" ) . remove ( ) ;
1903
- }
1904
2016
$ ( "#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.
1905
2017
var refName = $ ( this ) . parent ( ) . parent ( ) . parent ( ) . siblings (
1906
2018
".card-header" ) . children ( "button" ) . html ( ) ;
@@ -2049,4 +2161,4 @@ $(function () {
2049
2161
e . preventDefault ( ) ;
2050
2162
location . reload ( )
2051
2163
} ) ;
2052
- } ) ;
2164
+ } ) ;
0 commit comments