2020-06-23 04:45:38 -04:00
|
|
|
import _ from 'lodash'
|
2018-11-05 05:06:39 -05:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS103: Rewrite code to no longer use __guard__
|
|
|
|
* DS205: Consider reworking code to avoid use of IIFEs
|
|
|
|
* DS206: Consider reworking classes to avoid initClass
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-05-19 05:02:56 -04:00
|
|
|
import moment from 'moment'
|
|
|
|
import ColorManager from '../colors/ColorManager'
|
|
|
|
import displayNameForUser from './util/displayNameForUser'
|
|
|
|
import HistoryViewModes from './util/HistoryViewModes'
|
|
|
|
import './controllers/HistoryV2ListController'
|
|
|
|
import './controllers/HistoryV2FileTreeController'
|
|
|
|
import './controllers/HistoryV2ToolbarController'
|
|
|
|
import './controllers/HistoryV2AddLabelModalController'
|
|
|
|
import './controllers/HistoryV2DeleteLabelModalController'
|
|
|
|
import './directives/infiniteScroll'
|
|
|
|
import './directives/historyDraggableBoundary'
|
|
|
|
import './directives/historyDroppableArea'
|
|
|
|
import './components/historyEntriesList'
|
|
|
|
import './components/historyEntry'
|
|
|
|
import './components/historyLabelsList'
|
|
|
|
import './components/historyLabel'
|
|
|
|
import './components/historyFileTree'
|
|
|
|
import './components/historyFileEntity'
|
2021-06-10 04:04:21 -04:00
|
|
|
import { paywallPrompt } from '../../../../frontend/js/main/account-upgrade'
|
2020-05-19 05:02:56 -04:00
|
|
|
let HistoryManager
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
export default HistoryManager = (function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
HistoryManager = class HistoryManager {
|
|
|
|
static initClass() {
|
|
|
|
this.prototype.MAX_RECENT_UPDATES_TO_SELECT = 5
|
|
|
|
this.prototype.BATCH_SIZE = 10
|
|
|
|
}
|
2020-12-15 05:23:54 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
constructor(ide, $scope, localStorage) {
|
|
|
|
this.labelCurrentVersion = this.labelCurrentVersion.bind(this)
|
|
|
|
this.deleteLabel = this.deleteLabel.bind(this)
|
|
|
|
this._addLabelLocally = this._addLabelLocally.bind(this)
|
|
|
|
this.ide = ide
|
|
|
|
this.$scope = $scope
|
|
|
|
this.localStorage = localStorage
|
|
|
|
this.$scope.HistoryViewModes = HistoryViewModes
|
2020-12-15 05:23:54 -05:00
|
|
|
this._localStorageViewModeProjKey = `history.userPrefs.viewMode.${$scope.project_id}`
|
|
|
|
this._localStorageShowOnlyLabelsProjKey = `history.userPrefs.showOnlyLabels.${$scope.project_id}`
|
2020-05-19 05:02:56 -04:00
|
|
|
this._previouslySelectedPathname = null
|
|
|
|
this._loadFileTreeRequestCanceller = null
|
|
|
|
this.hardReset()
|
|
|
|
|
|
|
|
this.$scope.toggleHistory = () => {
|
|
|
|
if (this.$scope.ui.view === 'history') {
|
|
|
|
this.hide()
|
|
|
|
} else {
|
|
|
|
this.show()
|
|
|
|
this._handleHistoryUIStateChange()
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
this.ide.$timeout(() => {
|
|
|
|
this.$scope.$broadcast('history:toggle')
|
|
|
|
}, 0)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
this.$scope.isHistoryLoading = () => {
|
2021-05-05 09:05:04 -04:00
|
|
|
const selection = this.$scope.history.selection
|
2018-12-17 04:53:20 -05:00
|
|
|
return (
|
2020-05-19 05:02:56 -04:00
|
|
|
this.$scope.history.loadingFileTree ||
|
|
|
|
(this.$scope.history.viewMode === HistoryViewModes.POINT_IN_TIME &&
|
|
|
|
selection.file &&
|
|
|
|
selection.file.loading) ||
|
|
|
|
(this.$scope.history.viewMode === HistoryViewModes.COMPARE &&
|
|
|
|
selection.diff &&
|
|
|
|
selection.diff.loading)
|
2018-12-17 04:53:20 -05:00
|
|
|
)
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
show() {
|
|
|
|
this.$scope.ui.view = 'history'
|
|
|
|
this.hardReset()
|
|
|
|
if (this.$scope.history.showOnlyLabels) {
|
|
|
|
this.fetchNextBatchOfUpdates()
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
hide() {
|
|
|
|
this.$scope.ui.view = 'editor'
|
|
|
|
}
|
|
|
|
|
|
|
|
_getViewModeUserPref() {
|
|
|
|
return (
|
|
|
|
this.localStorage(this._localStorageViewModeProjKey) ||
|
|
|
|
HistoryViewModes.POINT_IN_TIME
|
|
|
|
)
|
|
|
|
}
|
2020-12-15 05:23:54 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
_getShowOnlyLabelsUserPref() {
|
|
|
|
return this.localStorage(this._localStorageShowOnlyLabelsProjKey) || false
|
|
|
|
}
|
|
|
|
|
|
|
|
_setViewModeUserPref(viewModeUserPref) {
|
|
|
|
if (
|
|
|
|
viewModeUserPref === HistoryViewModes.POINT_IN_TIME ||
|
|
|
|
viewModeUserPref === HistoryViewModes.COMPARE
|
|
|
|
) {
|
|
|
|
this.localStorage(this._localStorageViewModeProjKey, viewModeUserPref)
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2020-12-15 05:23:54 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
_setShowOnlyLabelsUserPref(showOnlyLabelsUserPref) {
|
|
|
|
this.localStorage(
|
|
|
|
this._localStorageShowOnlyLabelsProjKey,
|
|
|
|
!!showOnlyLabelsUserPref
|
|
|
|
)
|
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
hardReset() {
|
|
|
|
this.$scope.history = {
|
|
|
|
isV2: true,
|
|
|
|
updates: [],
|
|
|
|
viewMode: this._getViewModeUserPref(),
|
|
|
|
nextBeforeTimestamp: null,
|
2020-07-20 09:23:45 -04:00
|
|
|
loading: false,
|
2020-05-19 05:02:56 -04:00
|
|
|
atEnd: false,
|
|
|
|
userHasFullFeature: undefined,
|
|
|
|
freeHistoryLimitHit: false,
|
|
|
|
selection: {
|
2018-12-17 04:53:20 -05:00
|
|
|
docs: {},
|
|
|
|
pathname: null,
|
|
|
|
range: {
|
|
|
|
fromV: null,
|
2021-04-27 03:52:58 -04:00
|
|
|
toV: null,
|
2018-12-17 04:53:20 -05:00
|
|
|
},
|
|
|
|
hoveredRange: {
|
|
|
|
fromV: null,
|
2021-04-27 03:52:58 -04:00
|
|
|
toV: null,
|
2018-12-17 04:53:20 -05:00
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
diff: null,
|
|
|
|
files: [],
|
2021-04-27 03:52:58 -04:00
|
|
|
file: null,
|
2020-05-19 05:02:56 -04:00
|
|
|
},
|
|
|
|
error: null,
|
|
|
|
showOnlyLabels: this._getShowOnlyLabelsUserPref(),
|
|
|
|
labels: null,
|
2021-04-27 03:52:58 -04:00
|
|
|
loadingFileTree: true,
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2021-05-05 09:05:04 -04:00
|
|
|
const _deregisterFeatureWatcher = this.$scope.$watch(
|
2020-05-19 05:02:56 -04:00
|
|
|
'project.features.versioning',
|
|
|
|
hasVersioning => {
|
|
|
|
if (hasVersioning != null) {
|
|
|
|
this.$scope.history.userHasFullFeature = hasVersioning
|
|
|
|
if (this.$scope.user.isAdmin) {
|
|
|
|
this.$scope.history.userHasFullFeature = true
|
|
|
|
}
|
|
|
|
_deregisterFeatureWatcher()
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
)
|
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
softReset() {
|
|
|
|
this.$scope.history.viewMode = this._getViewModeUserPref()
|
|
|
|
this.$scope.history.selection = {
|
|
|
|
docs: {},
|
|
|
|
pathname: null,
|
|
|
|
range: {
|
|
|
|
fromV: null,
|
2021-04-27 03:52:58 -04:00
|
|
|
toV: null,
|
2020-05-19 05:02:56 -04:00
|
|
|
},
|
|
|
|
hoveredRange: {
|
|
|
|
fromV: null,
|
2021-04-27 03:52:58 -04:00
|
|
|
toV: null,
|
2020-05-19 05:02:56 -04:00
|
|
|
},
|
|
|
|
diff: null, // When history.viewMode == HistoryViewModes.COMPARE
|
|
|
|
files: [], // When history.viewMode == HistoryViewModes.COMPARE
|
2021-04-27 03:52:58 -04:00
|
|
|
file: null,
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
this.$scope.history.error = null
|
|
|
|
this.$scope.history.showOnlyLabels = this._getShowOnlyLabelsUserPref()
|
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
toggleHistoryViewMode() {
|
|
|
|
if (this.$scope.history.viewMode === HistoryViewModes.COMPARE) {
|
|
|
|
this.softReset()
|
|
|
|
this.$scope.history.viewMode = HistoryViewModes.POINT_IN_TIME
|
|
|
|
this._setViewModeUserPref(HistoryViewModes.POINT_IN_TIME)
|
|
|
|
} else {
|
|
|
|
this.softReset()
|
|
|
|
this.$scope.history.viewMode = HistoryViewModes.COMPARE
|
|
|
|
this._setViewModeUserPref(HistoryViewModes.COMPARE)
|
|
|
|
}
|
|
|
|
this._handleHistoryUIStateChange()
|
|
|
|
this.ide.$timeout(() => {
|
|
|
|
this.$scope.$broadcast('history:toggle')
|
|
|
|
}, 0)
|
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
_handleHistoryUIStateChange() {
|
|
|
|
if (this.$scope.history.viewMode === HistoryViewModes.COMPARE) {
|
2018-12-17 04:53:20 -05:00
|
|
|
if (this.$scope.history.showOnlyLabels) {
|
2020-05-19 05:02:56 -04:00
|
|
|
this.autoSelectLabelsForComparison()
|
|
|
|
} else {
|
|
|
|
this.autoSelectRecentUpdates()
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
} else {
|
|
|
|
// Point-in-time mode
|
|
|
|
if (this.$scope.history.showOnlyLabels) {
|
|
|
|
this.autoSelectLabelForPointInTime()
|
|
|
|
} else {
|
|
|
|
this.autoSelectVersionForPointInTime()
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
setHoverFrom(fromV) {
|
2021-05-05 09:05:04 -04:00
|
|
|
const selection = this.$scope.history.selection
|
2020-05-19 05:02:56 -04:00
|
|
|
selection.hoveredRange.fromV = fromV
|
|
|
|
selection.hoveredRange.toV = selection.range.toV
|
|
|
|
this.$scope.history.hoveringOverListSelectors = true
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
setHoverTo(toV) {
|
2021-05-05 09:05:04 -04:00
|
|
|
const selection = this.$scope.history.selection
|
2020-05-19 05:02:56 -04:00
|
|
|
selection.hoveredRange.toV = toV
|
|
|
|
selection.hoveredRange.fromV = selection.range.fromV
|
|
|
|
this.$scope.history.hoveringOverListSelectors = true
|
|
|
|
}
|
|
|
|
|
|
|
|
resetHover() {
|
2021-05-05 09:05:04 -04:00
|
|
|
const selection = this.$scope.history.selection
|
2020-05-19 05:02:56 -04:00
|
|
|
selection.hoveredRange.toV = null
|
|
|
|
selection.hoveredRange.fromV = null
|
|
|
|
this.$scope.history.hoveringOverListSelectors = false
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
showAllUpdates() {
|
|
|
|
if (this.$scope.history.showOnlyLabels) {
|
|
|
|
this.$scope.history.showOnlyLabels = false
|
|
|
|
this._setShowOnlyLabelsUserPref(false)
|
|
|
|
this._handleHistoryUIStateChange()
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
showOnlyLabels() {
|
|
|
|
if (!this.$scope.history.showOnlyLabels) {
|
|
|
|
this.$scope.history.showOnlyLabels = true
|
|
|
|
this._setShowOnlyLabelsUserPref(true)
|
|
|
|
this._handleHistoryUIStateChange()
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
restoreFile(version, pathname) {
|
|
|
|
const url = `/project/${this.$scope.project_id}/restore_file`
|
2019-04-09 05:56:45 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
return this.ide.$http.post(url, {
|
|
|
|
version,
|
|
|
|
pathname,
|
2021-04-27 03:52:58 -04:00
|
|
|
_csrf: window.csrfToken,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
2019-04-09 05:56:45 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
loadFileTreeForVersion(version) {
|
|
|
|
return this._loadFileTree(version, version)
|
|
|
|
}
|
2019-04-09 05:56:45 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
loadFileTreeDiff(toV, fromV) {
|
|
|
|
return this._loadFileTree(toV, fromV)
|
|
|
|
}
|
|
|
|
|
|
|
|
_loadFileTree(toV, fromV) {
|
|
|
|
let url = `/project/${this.$scope.project_id}/filetree/diff`
|
2021-05-05 09:05:04 -04:00
|
|
|
const selection = this.$scope.history.selection
|
2020-05-19 05:02:56 -04:00
|
|
|
const query = [`from=${fromV}`, `to=${toV}`]
|
|
|
|
url += `?${query.join('&')}`
|
|
|
|
|
|
|
|
this.$scope.$applyAsync(
|
|
|
|
() => (this.$scope.history.loadingFileTree = true)
|
|
|
|
)
|
|
|
|
|
|
|
|
selection.file = null
|
|
|
|
selection.pathname = null
|
|
|
|
|
|
|
|
// If `this._loadFileTreeRequestCanceller` is not null, then we have a request inflight
|
|
|
|
if (this._loadFileTreeRequestCanceller != null) {
|
|
|
|
// Resolving it will cancel the inflight request (or, rather, ignore its result)
|
|
|
|
this._loadFileTreeRequestCanceller.resolve()
|
|
|
|
}
|
|
|
|
this._loadFileTreeRequestCanceller = this.ide.$q.defer()
|
|
|
|
|
|
|
|
return this.ide.$http
|
|
|
|
.get(url, { timeout: this._loadFileTreeRequestCanceller.promise })
|
|
|
|
.then(response => {
|
|
|
|
this.$scope.history.selection.files = response.data.diff
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const file of this.$scope.history.selection.files) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (file.newPathname != null) {
|
|
|
|
file.oldPathname = file.pathname
|
|
|
|
file.pathname = file.newPathname
|
|
|
|
delete file.newPathname
|
2019-01-29 05:10:53 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
this._loadFileTreeRequestCanceller = null
|
|
|
|
this.$scope.history.loadingFileTree = false
|
|
|
|
this.autoSelectFile()
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
if (err.status !== -1) {
|
2019-04-09 05:56:45 -04:00
|
|
|
this._loadFileTreeRequestCanceller = null
|
2018-12-17 04:53:20 -05:00
|
|
|
} else {
|
2020-05-19 05:02:56 -04:00
|
|
|
this.$scope.history.loadingFileTree = false
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
selectFile(file) {
|
|
|
|
if (file != null && file.pathname != null) {
|
2022-01-10 05:23:05 -05:00
|
|
|
this.$scope.history.selection.pathname =
|
|
|
|
this._previouslySelectedPathname = file.pathname
|
2020-05-19 05:02:56 -04:00
|
|
|
this.$scope.history.selection.file = file
|
|
|
|
if (this.$scope.history.viewMode === HistoryViewModes.POINT_IN_TIME) {
|
|
|
|
this.loadFileAtPointInTime()
|
|
|
|
} else {
|
|
|
|
this.reloadDiff()
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
autoSelectFile() {
|
2021-05-05 09:05:04 -04:00
|
|
|
const selectedPathname = null
|
|
|
|
const files = this.$scope.history.selection.files
|
2020-05-19 05:02:56 -04:00
|
|
|
let fileToSelect = null
|
|
|
|
let previouslySelectedFile = null
|
|
|
|
let previouslySelectedFileHasOp = false
|
2021-05-05 09:05:04 -04:00
|
|
|
const filesWithOps = this._getFilesWithOps()
|
2020-05-19 05:02:56 -04:00
|
|
|
const orderedOpTypes = ['edited', 'added', 'renamed', 'removed']
|
|
|
|
|
|
|
|
if (this._previouslySelectedPathname != null) {
|
|
|
|
previouslySelectedFile = _.find(files, {
|
2021-04-27 03:52:58 -04:00
|
|
|
pathname: this._previouslySelectedPathname,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
previouslySelectedFileHasOp = _.some(filesWithOps, {
|
2021-04-27 03:52:58 -04:00
|
|
|
pathname: this._previouslySelectedPathname,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
if (previouslySelectedFile != null && previouslySelectedFileHasOp) {
|
|
|
|
fileToSelect = previouslySelectedFile
|
|
|
|
} else {
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const opType of orderedOpTypes) {
|
|
|
|
const fileWithMatchingOpType = _.find(filesWithOps, {
|
2021-04-27 03:52:58 -04:00
|
|
|
operation: opType,
|
2019-08-13 08:30:54 -04:00
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
if (fileWithMatchingOpType != null) {
|
|
|
|
fileToSelect = _.find(files, {
|
2021-04-27 03:52:58 -04:00
|
|
|
pathname: fileWithMatchingOpType.pathname,
|
2019-08-13 08:30:54 -04:00
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
break
|
2019-01-29 05:10:53 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
if (fileToSelect == null) {
|
|
|
|
if (previouslySelectedFile != null) {
|
|
|
|
fileToSelect = previouslySelectedFile
|
|
|
|
} else {
|
2021-05-05 09:05:04 -04:00
|
|
|
const mainFile = _.find(files, function (file) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return /main\.tex$/.test(file.pathname)
|
|
|
|
})
|
|
|
|
if (mainFile != null) {
|
|
|
|
fileToSelect = mainFile
|
2019-01-29 05:10:53 -05:00
|
|
|
} else {
|
2021-05-05 09:05:04 -04:00
|
|
|
const anyTeXFile = _.find(files, function (file) {
|
2020-05-19 05:02:56 -04:00
|
|
|
return /\.tex$/.test(file.pathname)
|
2019-01-29 05:10:53 -05:00
|
|
|
})
|
2020-05-19 05:02:56 -04:00
|
|
|
if (anyTeXFile != null) {
|
|
|
|
fileToSelect = anyTeXFile
|
2019-01-29 05:10:53 -05:00
|
|
|
} else {
|
2020-05-19 05:02:56 -04:00
|
|
|
fileToSelect = files[0]
|
2019-01-29 05:10:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
this.selectFile(fileToSelect)
|
|
|
|
}
|
|
|
|
|
|
|
|
_getFilesWithOps() {
|
|
|
|
let filesWithOps
|
|
|
|
if (this.$scope.history.viewMode === HistoryViewModes.POINT_IN_TIME) {
|
2021-05-05 09:05:04 -04:00
|
|
|
const currentUpdate = this.getUpdateForVersion(
|
2020-05-19 05:02:56 -04:00
|
|
|
this.$scope.history.selection.range.toV
|
|
|
|
)
|
|
|
|
filesWithOps = []
|
|
|
|
if (currentUpdate != null) {
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const pathname of currentUpdate.pathnames) {
|
2020-05-19 05:02:56 -04:00
|
|
|
filesWithOps.push({
|
2022-05-16 10:25:49 -04:00
|
|
|
pathname,
|
2021-04-27 03:52:58 -04:00
|
|
|
operation: 'edited',
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const op of currentUpdate.project_ops) {
|
2020-05-19 05:02:56 -04:00
|
|
|
let fileWithOp
|
|
|
|
if (op.add != null) {
|
|
|
|
fileWithOp = {
|
|
|
|
pathname: op.add.pathname,
|
2021-04-27 03:52:58 -04:00
|
|
|
operation: 'added',
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
} else if (op.remove != null) {
|
|
|
|
fileWithOp = {
|
|
|
|
pathname: op.remove.pathname,
|
2021-04-27 03:52:58 -04:00
|
|
|
operation: 'removed',
|
2019-08-13 08:30:54 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
} else if (op.rename != null) {
|
|
|
|
fileWithOp = {
|
|
|
|
pathname: op.rename.newPathname,
|
2021-04-27 03:52:58 -04:00
|
|
|
operation: 'renamed',
|
2019-08-13 08:30:54 -04:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
if (fileWithOp != null) {
|
|
|
|
filesWithOps.push(fileWithOp)
|
|
|
|
}
|
2019-08-13 08:30:54 -04:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
} else {
|
|
|
|
filesWithOps = _.reduce(
|
|
|
|
this.$scope.history.selection.files,
|
|
|
|
(curFilesWithOps, file) => {
|
|
|
|
if (file.operation) {
|
|
|
|
curFilesWithOps.push({
|
|
|
|
pathname: file.pathname,
|
2021-04-27 03:52:58 -04:00
|
|
|
operation: file.operation,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
return curFilesWithOps
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
)
|
2019-08-13 08:30:54 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
return filesWithOps
|
|
|
|
}
|
2019-08-13 08:30:54 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
autoSelectRecentUpdates() {
|
|
|
|
if (this.$scope.history.updates.length === 0) {
|
|
|
|
return
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2021-05-05 09:05:04 -04:00
|
|
|
const toV = this.$scope.history.updates[0].toV
|
2020-05-19 05:02:56 -04:00
|
|
|
let fromV = null
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
let indexOfLastUpdateNotByMe = 0
|
|
|
|
for (let i = 0; i < this.$scope.history.updates.length; i++) {
|
|
|
|
const update = this.$scope.history.updates[i]
|
2018-12-17 04:53:20 -05:00
|
|
|
if (
|
2020-05-19 05:02:56 -04:00
|
|
|
this._updateContainsUserId(update, this.$scope.user.id) ||
|
|
|
|
i > this.MAX_RECENT_UPDATES_TO_SELECT
|
2018-12-17 04:53:20 -05:00
|
|
|
) {
|
2020-05-19 05:02:56 -04:00
|
|
|
break
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
indexOfLastUpdateNotByMe = i
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
fromV = this.$scope.history.updates[indexOfLastUpdateNotByMe].fromV
|
|
|
|
this.selectVersionsForCompare(toV, fromV)
|
|
|
|
}
|
|
|
|
|
|
|
|
autoSelectVersionForPointInTime() {
|
|
|
|
if (this.$scope.history.updates.length === 0) {
|
|
|
|
return
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
let versionToSelect = this.$scope.history.updates[0].toV
|
2021-05-05 09:05:04 -04:00
|
|
|
const range = this.$scope.history.selection.range
|
2020-05-19 05:02:56 -04:00
|
|
|
if (
|
|
|
|
range.toV != null &&
|
|
|
|
range.fromV != null &&
|
|
|
|
range.toV === range.fromV
|
|
|
|
) {
|
|
|
|
versionToSelect = range.toV
|
|
|
|
}
|
|
|
|
this.selectVersionForPointInTime(versionToSelect)
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
autoSelectLastLabel() {
|
|
|
|
if (
|
|
|
|
this.$scope.history.labels == null ||
|
|
|
|
this.$scope.history.labels.length === 0
|
|
|
|
) {
|
|
|
|
return
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
return this.selectLabelForPointInTime(this.$scope.history.labels[0])
|
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
expandSelectionToVersion(version) {
|
|
|
|
if (version > this.$scope.history.selection.range.toV) {
|
|
|
|
this.$scope.history.selection.range.toV = version
|
|
|
|
} else if (version < this.$scope.history.selection.range.fromV) {
|
|
|
|
this.$scope.history.selection.range.fromV = version
|
2019-04-09 05:56:45 -04:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2019-04-09 05:56:45 -04:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
selectVersionForPointInTime(version) {
|
2021-05-05 09:05:04 -04:00
|
|
|
const selection = this.$scope.history.selection
|
2020-05-19 05:02:56 -04:00
|
|
|
if (
|
|
|
|
selection.range.toV !== version &&
|
|
|
|
selection.range.fromV !== version
|
|
|
|
) {
|
|
|
|
selection.range.toV = version
|
|
|
|
selection.range.fromV = version
|
|
|
|
this.loadFileTreeForVersion(version)
|
|
|
|
}
|
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
selectVersionsForCompare(toV, fromV) {
|
2021-05-05 09:05:04 -04:00
|
|
|
const range = this.$scope.history.selection.range
|
2020-05-19 05:02:56 -04:00
|
|
|
if (range.toV !== toV || range.fromV !== fromV) {
|
|
|
|
range.toV = toV
|
|
|
|
range.fromV = fromV
|
|
|
|
this.loadFileTreeDiff(toV, fromV)
|
|
|
|
}
|
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
autoSelectLabelForPointInTime() {
|
|
|
|
const selectedUpdate = this.getUpdateForVersion(
|
|
|
|
this.$scope.history.selection.range.toV
|
|
|
|
)
|
|
|
|
let nSelectedLabels = 0
|
|
|
|
|
|
|
|
if (selectedUpdate != null && selectedUpdate.labels != null) {
|
|
|
|
nSelectedLabels = selectedUpdate.labels.length
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the currently selected update has no labels, select the last one (version-wise)
|
|
|
|
if (nSelectedLabels === 0) {
|
|
|
|
this.autoSelectLastLabel()
|
|
|
|
// If the update has one label, select it
|
|
|
|
} else if (nSelectedLabels === 1) {
|
|
|
|
this.selectLabelForPointInTime(selectedUpdate.labels[0])
|
|
|
|
// If there are multiple labels for the update, select the latest
|
|
|
|
} else if (nSelectedLabels > 1) {
|
|
|
|
const sortedLabels = this.ide.$filter('orderBy')(
|
|
|
|
selectedUpdate.labels,
|
|
|
|
'-created_at'
|
|
|
|
)
|
|
|
|
const lastLabelFromUpdate = sortedLabels[0]
|
|
|
|
this.selectLabelForPointInTime(lastLabelFromUpdate)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
selectLabelForPointInTime(labelToSelect) {
|
|
|
|
let updateToSelect = null
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (this._isLabelSelected(labelToSelect)) {
|
|
|
|
// Label already selected
|
|
|
|
return
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const update of Array.from(this.$scope.history.updates)) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (update.toV === labelToSelect.version) {
|
|
|
|
updateToSelect = update
|
|
|
|
break
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (updateToSelect != null) {
|
|
|
|
this.selectVersionForPointInTime(updateToSelect.toV)
|
|
|
|
} else {
|
2021-05-05 09:05:04 -04:00
|
|
|
const selection = this.$scope.history.selection
|
2020-05-19 05:02:56 -04:00
|
|
|
selection.range.toV = labelToSelect.version
|
|
|
|
selection.range.fromV = labelToSelect.version
|
|
|
|
this.loadFileTreeForVersion(labelToSelect.version)
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
getUpdateForVersion(version) {
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const update of this.$scope.history.updates) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (update.toV === version) {
|
|
|
|
return update
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
autoSelectLabelsForComparison() {
|
2021-05-05 09:05:04 -04:00
|
|
|
const labels = this.$scope.history.labels
|
2020-05-19 05:02:56 -04:00
|
|
|
let nLabels = 0
|
|
|
|
if (Array.isArray(labels)) {
|
|
|
|
nLabels = labels.length
|
|
|
|
}
|
|
|
|
if (nLabels === 0) {
|
|
|
|
// TODO better handling
|
|
|
|
} else if (nLabels === 1) {
|
|
|
|
this.selectVersionsForCompare(labels[0].version, labels[0].version)
|
|
|
|
} else if (nLabels > 1) {
|
|
|
|
this.selectVersionsForCompare(labels[0].version, labels[1].version)
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
fetchNextBatchOfUpdates() {
|
|
|
|
if (this.$scope.history.atEnd) {
|
|
|
|
return
|
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-12-15 05:23:54 -05:00
|
|
|
let updatesURL = `/project/${this.ide.project_id}/updates?min_count=${this.BATCH_SIZE}`
|
2020-05-19 05:02:56 -04:00
|
|
|
if (this.$scope.history.nextBeforeTimestamp != null) {
|
|
|
|
updatesURL += `&before=${this.$scope.history.nextBeforeTimestamp}`
|
|
|
|
}
|
|
|
|
const labelsURL = `/project/${this.ide.project_id}/labels`
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const requests = { updates: this.ide.$http.get(updatesURL) }
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (this.$scope.history.labels == null) {
|
|
|
|
requests.labels = this.ide.$http.get(labelsURL)
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-07-20 09:23:45 -04:00
|
|
|
this.$scope.history.loading = true
|
2020-05-19 05:02:56 -04:00
|
|
|
return this.ide.$q
|
|
|
|
.all(requests)
|
|
|
|
.then(response => {
|
2020-07-20 09:23:45 -04:00
|
|
|
this.$scope.history.loading = false
|
2020-05-19 05:02:56 -04:00
|
|
|
const updatesData = response.updates.data
|
|
|
|
let lastUpdateToV = null
|
2018-12-18 06:09:56 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (updatesData.updates.length > 0) {
|
|
|
|
lastUpdateToV = updatesData.updates[0].toV
|
|
|
|
}
|
|
|
|
if (response.labels != null) {
|
|
|
|
this.$scope.history.labels = this._loadLabels(
|
|
|
|
response.labels.data,
|
|
|
|
lastUpdateToV
|
|
|
|
)
|
|
|
|
}
|
|
|
|
this._loadUpdates(updatesData.updates)
|
|
|
|
this.$scope.history.nextBeforeTimestamp =
|
|
|
|
updatesData.nextBeforeTimestamp
|
|
|
|
if (
|
|
|
|
updatesData.nextBeforeTimestamp == null ||
|
|
|
|
this.$scope.history.freeHistoryLimitHit ||
|
|
|
|
this.$scope.history.updates.length === 0
|
|
|
|
) {
|
2018-12-18 06:09:56 -05:00
|
|
|
this.$scope.history.atEnd = true
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
if (this.$scope.history.updates.length === 0) {
|
2018-12-18 06:09:56 -05:00
|
|
|
this.$scope.history.loadingFileTree = false
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
.catch(error => {
|
2020-07-20 09:23:45 -04:00
|
|
|
this.$scope.history.loading = false
|
2020-05-19 05:02:56 -04:00
|
|
|
const { status, statusText } = error
|
|
|
|
this.$scope.history.error = { status, statusText }
|
|
|
|
this.$scope.history.atEnd = true
|
|
|
|
this.$scope.history.loadingFileTree = false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
_loadLabels(labels, lastUpdateToV) {
|
2021-05-05 09:05:04 -04:00
|
|
|
const sortedLabels = this._sortLabelsByVersionAndDate(labels)
|
2022-01-10 05:23:05 -05:00
|
|
|
const labelsWithoutPseudoLabel =
|
|
|
|
this._deletePseudoCurrentStateLabelIfExistent(sortedLabels)
|
|
|
|
const labelsWithPseudoLabelIfNeeded =
|
|
|
|
this._addPseudoCurrentStateLabelIfNeeded(
|
|
|
|
labelsWithoutPseudoLabel,
|
|
|
|
lastUpdateToV
|
|
|
|
)
|
2020-06-11 11:36:32 -04:00
|
|
|
return labelsWithPseudoLabelIfNeeded
|
|
|
|
}
|
|
|
|
|
|
|
|
_deletePseudoCurrentStateLabelIfExistent(labels) {
|
|
|
|
if (labels.length && labels[0].isPseudoCurrentStateLabel) {
|
|
|
|
labels.shift()
|
|
|
|
}
|
|
|
|
return labels
|
|
|
|
}
|
|
|
|
|
|
|
|
_addPseudoCurrentStateLabelIfNeeded(labels, mostRecentVersion) {
|
|
|
|
if (
|
|
|
|
(labels.length && labels[0].version !== mostRecentVersion) ||
|
|
|
|
labels.length === 0
|
|
|
|
) {
|
2021-05-05 09:05:04 -04:00
|
|
|
const pseudoCurrentStateLabel = {
|
2020-06-11 11:36:32 -04:00
|
|
|
id: '1',
|
|
|
|
isPseudoCurrentStateLabel: true,
|
|
|
|
version: mostRecentVersion,
|
2021-04-27 03:52:58 -04:00
|
|
|
created_at: new Date().toISOString(),
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2020-06-11 11:36:32 -04:00
|
|
|
labels.unshift(pseudoCurrentStateLabel)
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2020-06-11 11:36:32 -04:00
|
|
|
return labels
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
_sortLabelsByVersionAndDate(labels) {
|
|
|
|
return this.ide.$filter('orderBy')(labels, [
|
|
|
|
'isPseudoCurrentStateLabel',
|
|
|
|
'-version',
|
2021-04-27 03:52:58 -04:00
|
|
|
'-created_at',
|
2020-05-19 05:02:56 -04:00
|
|
|
])
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
loadFileAtPointInTime() {
|
|
|
|
const toV = this.$scope.history.selection.range.toV
|
|
|
|
const { pathname } = this.$scope.history.selection
|
|
|
|
if (toV == null) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let url = `/project/${this.$scope.project_id}/diff`
|
|
|
|
const query = [
|
|
|
|
`pathname=${encodeURIComponent(pathname)}`,
|
|
|
|
`from=${toV}`,
|
2021-04-27 03:52:58 -04:00
|
|
|
`to=${toV}`,
|
2020-05-19 05:02:56 -04:00
|
|
|
]
|
|
|
|
url += `?${query.join('&')}`
|
|
|
|
this.$scope.history.selection.file.loading = true
|
|
|
|
return this.ide.$http
|
|
|
|
.get(url)
|
|
|
|
.then(response => {
|
|
|
|
const { text, binary } = this._parseDiff(response.data.diff)
|
|
|
|
this.$scope.history.selection.file.binary = binary
|
|
|
|
this.$scope.history.selection.file.text = text
|
|
|
|
this.$scope.history.selection.file.loading = false
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
.catch(function () {})
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
reloadDiff() {
|
|
|
|
let { diff } = this.$scope.history.selection
|
|
|
|
const { range, pathname } = this.$scope.history.selection
|
|
|
|
const { fromV, toV } = range
|
|
|
|
|
|
|
|
if (pathname == null) {
|
|
|
|
this.$scope.history.selection.diff = null
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
diff != null &&
|
|
|
|
diff.pathname === pathname &&
|
|
|
|
diff.fromV === fromV &&
|
|
|
|
diff.toV === toV
|
|
|
|
) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$scope.history.selection.diff = diff = {
|
|
|
|
fromV,
|
|
|
|
toV,
|
|
|
|
pathname,
|
2021-04-27 03:52:58 -04:00
|
|
|
error: false,
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
diff.loading = true
|
|
|
|
let url = `/project/${this.$scope.project_id}/diff`
|
|
|
|
const query = [`pathname=${encodeURIComponent(pathname)}`]
|
|
|
|
if (diff.fromV != null && diff.toV != null) {
|
|
|
|
query.push(`from=${diff.fromV}`, `to=${diff.toV}`)
|
|
|
|
}
|
|
|
|
url += `?${query.join('&')}`
|
|
|
|
return this.ide.$http
|
|
|
|
.get(url)
|
|
|
|
.then(response => {
|
|
|
|
const { data } = response
|
|
|
|
diff.loading = false
|
|
|
|
const { text, highlights, binary } = this._parseDiff(data.diff)
|
|
|
|
diff.binary = binary
|
|
|
|
diff.text = text
|
|
|
|
diff.highlights = highlights
|
|
|
|
})
|
2021-04-14 09:17:21 -04:00
|
|
|
.catch(function () {
|
2020-05-19 05:02:56 -04:00
|
|
|
diff.loading = false
|
|
|
|
diff.error = true
|
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
labelCurrentVersion(labelComment) {
|
|
|
|
return this._labelVersion(
|
|
|
|
labelComment,
|
|
|
|
this.$scope.history.selection.range.toV
|
|
|
|
)
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
deleteLabel(label) {
|
|
|
|
const url = `/project/${this.$scope.project_id}/labels/${label.id}`
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
return this.ide
|
|
|
|
.$http({
|
|
|
|
url,
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: {
|
2021-04-27 03:52:58 -04:00
|
|
|
'X-CSRF-Token': window.csrfToken,
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
return this._deleteLabelLocally(label)
|
|
|
|
})
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
_deleteLabelLocally(labelToDelete) {
|
|
|
|
for (let i = 0; i < this.$scope.history.updates.length; i++) {
|
|
|
|
const update = this.$scope.history.updates[i]
|
|
|
|
if (update.toV === labelToDelete.version) {
|
|
|
|
update.labels = _.filter(
|
|
|
|
update.labels,
|
|
|
|
label => label.id !== labelToDelete.id
|
|
|
|
)
|
|
|
|
break
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
this.$scope.history.labels = this._loadLabels(
|
|
|
|
_.filter(
|
|
|
|
this.$scope.history.labels,
|
|
|
|
label => label.id !== labelToDelete.id
|
|
|
|
),
|
|
|
|
this.$scope.history.updates[0].toV
|
|
|
|
)
|
|
|
|
this._handleHistoryUIStateChange()
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
_isLabelSelected(label) {
|
|
|
|
if (label) {
|
|
|
|
return (
|
|
|
|
label.version <= this.$scope.history.selection.range.toV &&
|
|
|
|
label.version >= this.$scope.history.selection.range.fromV
|
2018-12-17 04:53:20 -05:00
|
|
|
)
|
2020-05-19 05:02:56 -04:00
|
|
|
} else {
|
|
|
|
return false
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
_parseDiff(diff) {
|
|
|
|
if (diff.binary) {
|
|
|
|
return { binary: true }
|
|
|
|
}
|
|
|
|
let row = 0
|
|
|
|
let column = 0
|
|
|
|
const highlights = []
|
|
|
|
let text = ''
|
|
|
|
const iterable = diff || []
|
|
|
|
for (let i = 0; i < iterable.length; i++) {
|
2021-10-26 04:08:56 -04:00
|
|
|
let endColumn, endRow
|
2020-05-19 05:02:56 -04:00
|
|
|
const entry = iterable[i]
|
|
|
|
let content = entry.u || entry.i || entry.d
|
|
|
|
if (!content) {
|
|
|
|
content = ''
|
|
|
|
}
|
|
|
|
text += content
|
|
|
|
const lines = content.split('\n')
|
|
|
|
const startRow = row
|
|
|
|
const startColumn = column
|
|
|
|
if (lines.length > 1) {
|
|
|
|
endRow = startRow + lines.length - 1
|
|
|
|
endColumn = lines[lines.length - 1].length
|
2018-12-17 04:53:20 -05:00
|
|
|
} else {
|
2020-05-19 05:02:56 -04:00
|
|
|
endRow = startRow
|
|
|
|
endColumn = startColumn + lines[0].length
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
row = endRow
|
|
|
|
column = endColumn
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const range = {
|
|
|
|
start: {
|
|
|
|
row: startRow,
|
2021-04-27 03:52:58 -04:00
|
|
|
column: startColumn,
|
2020-05-19 05:02:56 -04:00
|
|
|
},
|
|
|
|
end: {
|
|
|
|
row: endRow,
|
2021-04-27 03:52:58 -04:00
|
|
|
column: endColumn,
|
|
|
|
},
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (entry.i != null || entry.d != null) {
|
|
|
|
const user =
|
|
|
|
entry.meta.users != null ? entry.meta.users[0] : undefined
|
|
|
|
const name = displayNameForUser(user)
|
|
|
|
const date = moment(entry.meta.end_ts).format('Do MMM YYYY, h:mm a')
|
|
|
|
if (entry.i != null) {
|
|
|
|
highlights.push({
|
|
|
|
label: `Added by ${name} on ${date}`,
|
|
|
|
highlight: range,
|
|
|
|
hue: ColorManager.getHueForUserId(
|
|
|
|
user != null ? user.id : undefined
|
2021-04-27 03:52:58 -04:00
|
|
|
),
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
} else if (entry.d != null) {
|
|
|
|
highlights.push({
|
|
|
|
label: `Deleted by ${name} on ${date}`,
|
|
|
|
strikeThrough: range,
|
|
|
|
hue: ColorManager.getHueForUserId(
|
|
|
|
user != null ? user.id : undefined
|
2021-04-27 03:52:58 -04:00
|
|
|
),
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
return { text, highlights }
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
_loadUpdates(updates) {
|
|
|
|
if (updates == null) {
|
|
|
|
updates = []
|
|
|
|
}
|
2022-01-10 05:23:05 -05:00
|
|
|
let previousUpdate =
|
|
|
|
this.$scope.history.updates[this.$scope.history.updates.length - 1]
|
2020-05-19 05:02:56 -04:00
|
|
|
const dateTimeNow = new Date()
|
|
|
|
const timestamp24hoursAgo = dateTimeNow.setDate(dateTimeNow.getDate() - 1)
|
|
|
|
let cutOffIndex = null
|
|
|
|
|
|
|
|
const iterable = updates || []
|
|
|
|
for (let i = 0; i < iterable.length; i++) {
|
|
|
|
const update = iterable[i]
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const user of Array.from(update.meta.users || [])) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if (user != null) {
|
|
|
|
user.hue = ColorManager.getHueForUserId(user.id)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
if (
|
|
|
|
previousUpdate == null ||
|
|
|
|
!moment(previousUpdate.meta.end_ts).isSame(update.meta.end_ts, 'day')
|
|
|
|
) {
|
|
|
|
update.meta.first_in_day = true
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
previousUpdate = update
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
if (
|
|
|
|
!this.$scope.history.userHasFullFeature &&
|
|
|
|
update.meta.end_ts < timestamp24hoursAgo
|
|
|
|
) {
|
|
|
|
cutOffIndex = i || 1 // Make sure that we show at least one entry (to allow labelling).
|
|
|
|
this.$scope.history.freeHistoryLimitHit = true
|
|
|
|
if (this.$scope.project.owner._id === this.$scope.user.id) {
|
|
|
|
ga(
|
|
|
|
'send',
|
|
|
|
'event',
|
|
|
|
'subscription-funnel',
|
|
|
|
'editor-click-feature',
|
|
|
|
'history'
|
|
|
|
)
|
2021-06-10 04:04:21 -04:00
|
|
|
paywallPrompt('history')
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
break
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
const firstLoad = this.$scope.history.updates.length === 0
|
|
|
|
|
|
|
|
if (!this.$scope.history.userHasFullFeature && cutOffIndex != null) {
|
|
|
|
updates = updates.slice(0, cutOffIndex)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
this.$scope.history.updates = this.$scope.history.updates.concat(updates)
|
|
|
|
|
|
|
|
if (firstLoad) {
|
2018-12-17 04:53:20 -05:00
|
|
|
this._handleHistoryUIStateChange()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2020-05-19 05:02:56 -04:00
|
|
|
_labelVersion(comment, version) {
|
|
|
|
const url = `/project/${this.$scope.project_id}/labels`
|
|
|
|
return this.ide.$http
|
|
|
|
.post(url, {
|
|
|
|
comment,
|
|
|
|
version,
|
2021-04-27 03:52:58 -04:00
|
|
|
_csrf: window.csrfToken,
|
2020-05-19 05:02:56 -04:00
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
return this._addLabelLocally(response.data)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
_addLabelLocally(label) {
|
|
|
|
const localUpdate = _.find(
|
|
|
|
this.$scope.history.updates,
|
|
|
|
update => update.toV === label.version
|
|
|
|
)
|
|
|
|
if (localUpdate != null) {
|
|
|
|
localUpdate.labels = localUpdate.labels.concat(label)
|
|
|
|
}
|
|
|
|
this.$scope.history.labels = this._loadLabels(
|
|
|
|
this.$scope.history.labels.concat(label),
|
|
|
|
this.$scope.history.updates[0].toV
|
|
|
|
)
|
|
|
|
this._handleHistoryUIStateChange()
|
|
|
|
}
|
|
|
|
|
|
|
|
_updateContainsUserId(update, user_id) {
|
2021-05-05 09:05:04 -04:00
|
|
|
for (const user of Array.from(update.meta.users)) {
|
2020-05-19 05:02:56 -04:00
|
|
|
if ((user != null ? user.id : undefined) === user_id) {
|
|
|
|
return true
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
return false
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2020-05-19 05:02:56 -04:00
|
|
|
}
|
|
|
|
HistoryManager.initClass()
|
|
|
|
return HistoryManager
|
2020-12-15 05:23:54 -05:00
|
|
|
})()
|
2018-11-05 05:06:39 -05:00
|
|
|
|
|
|
|
function __guard__(value, transform) {
|
|
|
|
return typeof value !== 'undefined' && value !== null
|
|
|
|
? transform(value)
|
|
|
|
: undefined
|
|
|
|
}
|