mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Fix a few bugs related to keeping the selection when moving from labels to full history.
This commit is contained in:
parent
7e86218b21
commit
c13e0264e5
2 changed files with 62 additions and 84 deletions
|
@ -53,8 +53,15 @@ define [
|
||||||
@reloadDiff()
|
@reloadDiff()
|
||||||
|
|
||||||
@$scope.$watch "history.showOnlyLabels", (showOnlyLabels, prevVal) =>
|
@$scope.$watch "history.showOnlyLabels", (showOnlyLabels, prevVal) =>
|
||||||
if showOnlyLabels? and showOnlyLabels != prevVal and showOnlyLabels
|
if showOnlyLabels? and showOnlyLabels != prevVal
|
||||||
@selectedLabelFromUpdatesSelection()
|
if showOnlyLabels
|
||||||
|
@selectedLabelFromUpdatesSelection()
|
||||||
|
else
|
||||||
|
if @$scope.history.selection.updates.length == 0
|
||||||
|
@autoSelectLastUpdate()
|
||||||
|
|
||||||
|
@$scope.$watch "history.updates.length", () =>
|
||||||
|
@recalculateSelectedUpdates()
|
||||||
|
|
||||||
show: () ->
|
show: () ->
|
||||||
@$scope.ui.view = "history"
|
@$scope.ui.view = "history"
|
||||||
|
@ -95,10 +102,9 @@ define [
|
||||||
_csrf: window.csrfToken
|
_csrf: window.csrfToken
|
||||||
})
|
})
|
||||||
|
|
||||||
loadFileTreeForUpdate: (update) ->
|
loadFileTreeForVersion: (version) ->
|
||||||
{fromV, toV} = update
|
|
||||||
url = "/project/#{@$scope.project_id}/filetree/diff"
|
url = "/project/#{@$scope.project_id}/filetree/diff"
|
||||||
query = [ "from=#{toV}", "to=#{toV}" ]
|
query = [ "from=#{version}", "to=#{version}" ]
|
||||||
url += "?" + query.join("&")
|
url += "?" + query.join("&")
|
||||||
@$scope.history.loadingFileTree = true
|
@$scope.history.loadingFileTree = true
|
||||||
@$scope.history.selectedFile = null
|
@$scope.history.selectedFile = null
|
||||||
|
@ -140,33 +146,66 @@ define [
|
||||||
update.selectedFrom = false
|
update.selectedFrom = false
|
||||||
@$scope.history.updates[selectedUpdateIndex].selectedTo = true
|
@$scope.history.updates[selectedUpdateIndex].selectedTo = true
|
||||||
@$scope.history.updates[selectedUpdateIndex].selectedFrom = true
|
@$scope.history.updates[selectedUpdateIndex].selectedFrom = true
|
||||||
@loadFileTreeForUpdate @$scope.history.updates[selectedUpdateIndex]
|
@recalculateSelectedUpdates()
|
||||||
|
@loadFileTreeForVersion @$scope.history.updates[selectedUpdateIndex].toV
|
||||||
|
|
||||||
selectedLabelFromUpdatesSelection: () ->
|
selectedLabelFromUpdatesSelection: () ->
|
||||||
nLabels = @$scope.history.selection.updates?[0]?.labels?.length
|
# Get the number of labels associated with the currently selected update
|
||||||
if nLabels == 1
|
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]
|
@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')
|
sortedLabels = @ide.$filter("orderBy")(@$scope.history.selection.updates[0].labels, '-created_at')
|
||||||
lastLabelFromUpdate = sortedLabels[0]
|
lastLabelFromUpdate = sortedLabels[0]
|
||||||
@selectLabel lastLabelFromUpdate
|
@selectLabel lastLabelFromUpdate
|
||||||
|
|
||||||
selectLabel: (labelToSelect) ->
|
selectLabel: (labelToSelect) ->
|
||||||
labelToSelectIndex = -1
|
updateToSelect = null
|
||||||
for update, i in @$scope.history.updates
|
alreadySelected = false
|
||||||
if update.toV == labelToSelect.version
|
|
||||||
labelToSelectIndex = i
|
|
||||||
break
|
|
||||||
if labelToSelectIndex == -1
|
|
||||||
labelToSelectIndex = 0
|
|
||||||
for update in @$scope.history.updates
|
for update in @$scope.history.updates
|
||||||
update.selectedTo = false
|
if update.toV == labelToSelect.version
|
||||||
update.selectedFrom = false
|
updateToSelect = update
|
||||||
|
break
|
||||||
|
|
||||||
for label in @$scope.history.labels
|
for label in @$scope.history.labels
|
||||||
label.selected = (labelToSelect.id == label.id)
|
matchingLabel = (labelToSelect.id == label.id)
|
||||||
@$scope.history.updates[labelToSelectIndex].selectedTo = true
|
if matchingLabel and label.selected
|
||||||
@$scope.history.updates[labelToSelectIndex].selectedFrom = true
|
alreadySelected = true
|
||||||
@loadFileTreeForUpdate @$scope.history.updates[labelToSelectIndex]
|
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
|
BATCH_SIZE: 10
|
||||||
fetchNextBatchOfUpdates: () ->
|
fetchNextBatchOfUpdates: () ->
|
||||||
|
@ -199,6 +238,7 @@ define [
|
||||||
@ide.$filter("orderBy")(labels, [ '-version', '-created_at' ])
|
@ide.$filter("orderBy")(labels, [ '-version', '-created_at' ])
|
||||||
|
|
||||||
loadFileAtPointInTime: () ->
|
loadFileAtPointInTime: () ->
|
||||||
|
console.log @$scope.history.selection.pathname, @$scope.history.selection.updates
|
||||||
pathname = @$scope.history.selection.pathname
|
pathname = @$scope.history.selection.pathname
|
||||||
toV = @$scope.history.selection.updates[0].toV
|
toV = @$scope.history.selection.updates[0].toV
|
||||||
url = "/project/#{@$scope.project_id}/diff"
|
url = "/project/#{@$scope.project_id}/diff"
|
||||||
|
|
|
@ -14,11 +14,9 @@ define [
|
||||||
|
|
||||||
$scope.handleEntrySelect = (entry) ->
|
$scope.handleEntrySelect = (entry) ->
|
||||||
ide.historyManager.selectUpdate(entry)
|
ide.historyManager.selectUpdate(entry)
|
||||||
$scope.recalculateSelectedUpdates()
|
|
||||||
|
|
||||||
$scope.handleLabelSelect = (label) ->
|
$scope.handleLabelSelect = (label) ->
|
||||||
ide.historyManager.selectLabel(label)
|
ide.historyManager.selectLabel(label)
|
||||||
$scope.recalculateSelectedUpdates()
|
|
||||||
|
|
||||||
$scope.handleLabelDelete = (labelDetails) ->
|
$scope.handleLabelDelete = (labelDetails) ->
|
||||||
$modal.open(
|
$modal.open(
|
||||||
|
@ -27,64 +25,4 @@ define [
|
||||||
resolve:
|
resolve:
|
||||||
labelDetails: () -> labelDetails
|
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()
|
|
||||||
]
|
]
|
Loading…
Reference in a new issue