Fix a few bugs related to keeping the selection when moving from labels to full history.

This commit is contained in:
Paulo Reis 2018-08-10 14:07:35 +01:00
parent 7e86218b21
commit c13e0264e5
2 changed files with 62 additions and 84 deletions

View file

@ -53,8 +53,15 @@ define [
@reloadDiff()
@$scope.$watch "history.showOnlyLabels", (showOnlyLabels, prevVal) =>
if showOnlyLabels? and showOnlyLabels != prevVal and showOnlyLabels
@selectedLabelFromUpdatesSelection()
if showOnlyLabels? and showOnlyLabels != prevVal
if showOnlyLabels
@selectedLabelFromUpdatesSelection()
else
if @$scope.history.selection.updates.length == 0
@autoSelectLastUpdate()
@$scope.$watch "history.updates.length", () =>
@recalculateSelectedUpdates()
show: () ->
@$scope.ui.view = "history"
@ -95,10 +102,9 @@ define [
_csrf: window.csrfToken
})
loadFileTreeForUpdate: (update) ->
{fromV, toV} = update
loadFileTreeForVersion: (version) ->
url = "/project/#{@$scope.project_id}/filetree/diff"
query = [ "from=#{toV}", "to=#{toV}" ]
query = [ "from=#{version}", "to=#{version}" ]
url += "?" + query.join("&")
@$scope.history.loadingFileTree = true
@$scope.history.selectedFile = null
@ -140,33 +146,66 @@ define [
update.selectedFrom = false
@$scope.history.updates[selectedUpdateIndex].selectedTo = true
@$scope.history.updates[selectedUpdateIndex].selectedFrom = true
@loadFileTreeForUpdate @$scope.history.updates[selectedUpdateIndex]
@recalculateSelectedUpdates()
@loadFileTreeForVersion @$scope.history.updates[selectedUpdateIndex].toV
selectedLabelFromUpdatesSelection: () ->
nLabels = @$scope.history.selection.updates?[0]?.labels?.length
if nLabels == 1
# Get the number of labels associated with the currently selected update
nSelectedLabels = @$scope.history.selection.updates?[0]?.labels?.length
# If the currently selected update has no labels, select the last one (version-wise)
if nSelectedLabels == 0
@autoSelectLastLabel()
# If the update has one label, select it
else if nSelectedLabels == 1
@selectLabel @$scope.history.selection.updates[0].labels[0]
else if nLabels > 1
# If there are multiple labels for the update, select the latest
else if nSelectedLabels > 1
sortedLabels = @ide.$filter("orderBy")(@$scope.history.selection.updates[0].labels, '-created_at')
lastLabelFromUpdate = sortedLabels[0]
@selectLabel lastLabelFromUpdate
selectLabel: (labelToSelect) ->
labelToSelectIndex = -1
for update, i in @$scope.history.updates
if update.toV == labelToSelect.version
labelToSelectIndex = i
break
if labelToSelectIndex == -1
labelToSelectIndex = 0
updateToSelect = null
alreadySelected = false
for update in @$scope.history.updates
update.selectedTo = false
update.selectedFrom = false
if update.toV == labelToSelect.version
updateToSelect = update
break
for label in @$scope.history.labels
label.selected = (labelToSelect.id == label.id)
@$scope.history.updates[labelToSelectIndex].selectedTo = true
@$scope.history.updates[labelToSelectIndex].selectedFrom = true
@loadFileTreeForUpdate @$scope.history.updates[labelToSelectIndex]
matchingLabel = (labelToSelect.id == label.id)
if matchingLabel and label.selected
alreadySelected = true
label.selected = matchingLabel
if alreadySelected
return
if updateToSelect?
@selectUpdate updateToSelect
else
@$scope.history.selection.updates = []
@loadFileTreeForVersion labelToSelect.version
recalculateSelectedUpdates: () ->
beforeSelection = true
afterSelection = false
@$scope.history.selection.updates = []
for update in @$scope.history.updates
if update.selectedTo
inSelection = true
beforeSelection = false
update.beforeSelection = beforeSelection
update.inSelection = inSelection
update.afterSelection = afterSelection
if inSelection
@$scope.history.selection.updates.push update
if update.selectedFrom
inSelection = false
afterSelection = true
BATCH_SIZE: 10
fetchNextBatchOfUpdates: () ->
@ -199,6 +238,7 @@ define [
@ide.$filter("orderBy")(labels, [ '-version', '-created_at' ])
loadFileAtPointInTime: () ->
console.log @$scope.history.selection.pathname, @$scope.history.selection.updates
pathname = @$scope.history.selection.pathname
toV = @$scope.history.selection.updates[0].toV
url = "/project/#{@$scope.project_id}/diff"

View file

@ -14,11 +14,9 @@ define [
$scope.handleEntrySelect = (entry) ->
ide.historyManager.selectUpdate(entry)
$scope.recalculateSelectedUpdates()
$scope.handleLabelSelect = (label) ->
ide.historyManager.selectLabel(label)
$scope.recalculateSelectedUpdates()
$scope.handleLabelDelete = (labelDetails) ->
$modal.open(
@ -27,64 +25,4 @@ define [
resolve:
labelDetails: () -> labelDetails
)
$scope.recalculateSelectedUpdates = () ->
beforeSelection = true
afterSelection = false
$scope.history.selection.updates = []
for update in $scope.history.updates
if update.selectedTo
inSelection = true
beforeSelection = false
update.beforeSelection = beforeSelection
update.inSelection = inSelection
update.afterSelection = afterSelection
if inSelection
$scope.history.selection.updates.push update
if update.selectedFrom
inSelection = false
afterSelection = true
$scope.recalculateHoveredUpdates = () ->
hoverSelectedFrom = false
hoverSelectedTo = false
for update in $scope.history.updates
# Figure out whether the to or from selector is hovered over
if update.hoverSelectedFrom
hoverSelectedFrom = true
if update.hoverSelectedTo
hoverSelectedTo = true
if hoverSelectedFrom
# We want to 'hover select' everything between hoverSelectedFrom and selectedTo
inHoverSelection = false
for update in $scope.history.updates
if update.selectedTo
update.hoverSelectedTo = true
inHoverSelection = true
update.inHoverSelection = inHoverSelection
if update.hoverSelectedFrom
inHoverSelection = false
if hoverSelectedTo
# We want to 'hover select' everything between hoverSelectedTo and selectedFrom
inHoverSelection = false
for update in $scope.history.updates
if update.hoverSelectedTo
inHoverSelection = true
update.inHoverSelection = inHoverSelection
if update.selectedFrom
update.hoverSelectedFrom = true
inHoverSelection = false
$scope.resetHoverState = () ->
for update in $scope.history.updates
delete update.hoverSelectedFrom
delete update.hoverSelectedTo
delete update.inHoverSelection
$scope.$watch "history.updates.length", () ->
$scope.recalculateSelectedUpdates()
]