From c13e0264e555ec7bb190eb2bd4221cf85c6ee04b Mon Sep 17 00:00:00 2001 From: Paulo Reis Date: Fri, 10 Aug 2018 14:07:35 +0100 Subject: [PATCH] Fix a few bugs related to keeping the selection when moving from labels to full history. --- .../ide/history/HistoryV2Manager.coffee | 84 ++++++++++++++----- .../HistoryV2ListController.coffee | 62 -------------- 2 files changed, 62 insertions(+), 84 deletions(-) diff --git a/services/web/public/coffee/ide/history/HistoryV2Manager.coffee b/services/web/public/coffee/ide/history/HistoryV2Manager.coffee index e7a2c071e3..e8a3f46f24 100644 --- a/services/web/public/coffee/ide/history/HistoryV2Manager.coffee +++ b/services/web/public/coffee/ide/history/HistoryV2Manager.coffee @@ -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" diff --git a/services/web/public/coffee/ide/history/controllers/HistoryV2ListController.coffee b/services/web/public/coffee/ide/history/controllers/HistoryV2ListController.coffee index 7129e0374c..55c2d791a9 100644 --- a/services/web/public/coffee/ide/history/controllers/HistoryV2ListController.coffee +++ b/services/web/public/coffee/ide/history/controllers/HistoryV2ListController.coffee @@ -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() ] \ No newline at end of file