2018-11-05 05:06:39 -05:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
no-undef,
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
define([
|
|
|
|
'moment',
|
|
|
|
'ide/colors/ColorManager',
|
|
|
|
'ide/history/util/displayNameForUser',
|
|
|
|
'ide/history/util/HistoryViewModes',
|
|
|
|
'ide/history/controllers/HistoryV2ListController',
|
|
|
|
'ide/history/controllers/HistoryV2FileTreeController',
|
|
|
|
'ide/history/controllers/HistoryV2ToolbarController',
|
|
|
|
'ide/history/controllers/HistoryV2AddLabelModalController',
|
|
|
|
'ide/history/controllers/HistoryV2DeleteLabelModalController',
|
|
|
|
'ide/history/directives/infiniteScroll',
|
2019-04-09 05:56:45 -04:00
|
|
|
'ide/history/directives/historyDraggableBoundary',
|
|
|
|
'ide/history/directives/historyDroppableArea',
|
2018-11-05 05:06:39 -05:00
|
|
|
'ide/history/components/historyEntriesList',
|
|
|
|
'ide/history/components/historyEntry',
|
|
|
|
'ide/history/components/historyLabelsList',
|
|
|
|
'ide/history/components/historyLabel',
|
|
|
|
'ide/history/components/historyFileTree',
|
|
|
|
'ide/history/components/historyFileEntity'
|
|
|
|
], function(moment, ColorManager, displayNameForUser, HistoryViewModes) {
|
|
|
|
let HistoryManager
|
|
|
|
return (HistoryManager = (function() {
|
|
|
|
HistoryManager = class HistoryManager {
|
|
|
|
static initClass() {
|
|
|
|
this.prototype.MAX_RECENT_UPDATES_TO_SELECT = 5
|
|
|
|
this.prototype.BATCH_SIZE = 10
|
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
constructor(ide, $scope, localStorage) {
|
2018-11-05 05:06:39 -05:00
|
|
|
this.labelCurrentVersion = this.labelCurrentVersion.bind(this)
|
|
|
|
this.deleteLabel = this.deleteLabel.bind(this)
|
2018-12-17 04:53:20 -05:00
|
|
|
this._addLabelLocally = this._addLabelLocally.bind(this)
|
2018-11-05 05:06:39 -05:00
|
|
|
this.ide = ide
|
|
|
|
this.$scope = $scope
|
2018-12-17 04:53:20 -05:00
|
|
|
this.localStorage = localStorage
|
2018-11-05 05:06:39 -05:00
|
|
|
this.$scope.HistoryViewModes = HistoryViewModes
|
2018-12-17 04:53:20 -05:00
|
|
|
this._localStorageViewModeProjKey = `history.userPrefs.viewMode.${
|
|
|
|
$scope.project_id
|
|
|
|
}`
|
|
|
|
this._localStorageShowOnlyLabelsProjKey = `history.userPrefs.showOnlyLabels.${
|
|
|
|
$scope.project_id
|
|
|
|
}`
|
2019-01-29 05:10:53 -05:00
|
|
|
this._previouslySelectedPathname = null
|
2019-04-09 05:56:45 -04:00
|
|
|
this._loadFileTreeRequestCanceller = null
|
2018-12-17 04:53:20 -05:00
|
|
|
this.hardReset()
|
2018-11-05 05:06:39 -05:00
|
|
|
|
|
|
|
this.$scope.toggleHistory = () => {
|
|
|
|
if (this.$scope.ui.view === 'history') {
|
|
|
|
this.hide()
|
|
|
|
} else {
|
|
|
|
this.show()
|
2018-12-17 04:53:20 -05:00
|
|
|
this._handleHistoryUIStateChange()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
this.ide.$timeout(() => {
|
|
|
|
this.$scope.$broadcast('history:toggle')
|
2018-11-05 05:06:39 -05:00
|
|
|
}, 0)
|
|
|
|
}
|
|
|
|
|
2019-04-09 05:56:45 -04:00
|
|
|
this.$scope.isHistoryLoading = () => {
|
|
|
|
let selection = this.$scope.history.selection
|
|
|
|
return (
|
|
|
|
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-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
show() {
|
|
|
|
this.$scope.ui.view = 'history'
|
2018-12-17 04:53:20 -05:00
|
|
|
this.hardReset()
|
|
|
|
if (this.$scope.history.showOnlyLabels) {
|
|
|
|
this.fetchNextBatchOfUpdates()
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
hide() {
|
2018-12-17 04:53:20 -05:00
|
|
|
this.$scope.ui.view = 'editor'
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2018-12-17 04:53:20 -05:00
|
|
|
_getViewModeUserPref() {
|
|
|
|
return (
|
|
|
|
this.localStorage(this._localStorageViewModeProjKey) ||
|
|
|
|
HistoryViewModes.POINT_IN_TIME
|
|
|
|
)
|
|
|
|
}
|
|
|
|
_getShowOnlyLabelsUserPref() {
|
|
|
|
return (
|
|
|
|
this.localStorage(this._localStorageShowOnlyLabelsProjKey) || false
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
_setViewModeUserPref(viewModeUserPref) {
|
|
|
|
if (
|
|
|
|
viewModeUserPref === HistoryViewModes.POINT_IN_TIME ||
|
|
|
|
viewModeUserPref === HistoryViewModes.COMPARE
|
|
|
|
) {
|
|
|
|
this.localStorage(this._localStorageViewModeProjKey, viewModeUserPref)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_setShowOnlyLabelsUserPref(showOnlyLabelsUserPref) {
|
|
|
|
this.localStorage(
|
|
|
|
this._localStorageShowOnlyLabelsProjKey,
|
|
|
|
!!showOnlyLabelsUserPref
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
hardReset() {
|
|
|
|
this.$scope.history = {
|
2018-11-05 05:06:39 -05:00
|
|
|
isV2: true,
|
|
|
|
updates: [],
|
2018-12-17 04:53:20 -05:00
|
|
|
viewMode: this._getViewModeUserPref(),
|
2018-11-05 05:06:39 -05:00
|
|
|
nextBeforeTimestamp: null,
|
|
|
|
atEnd: false,
|
2018-12-17 04:53:20 -05:00
|
|
|
userHasFullFeature: undefined,
|
2018-11-05 05:06:39 -05:00
|
|
|
freeHistoryLimitHit: false,
|
|
|
|
selection: {
|
|
|
|
docs: {},
|
|
|
|
pathname: null,
|
|
|
|
range: {
|
|
|
|
fromV: null,
|
|
|
|
toV: null
|
2018-12-17 04:53:20 -05:00
|
|
|
},
|
|
|
|
hoveredRange: {
|
|
|
|
fromV: null,
|
|
|
|
toV: null
|
|
|
|
},
|
2019-01-29 05:10:53 -05:00
|
|
|
diff: null,
|
|
|
|
files: [],
|
2018-12-17 04:53:20 -05:00
|
|
|
file: null
|
2018-11-05 05:06:39 -05:00
|
|
|
},
|
|
|
|
error: null,
|
2018-12-17 04:53:20 -05:00
|
|
|
showOnlyLabels: this._getShowOnlyLabelsUserPref(),
|
2018-11-05 05:06:39 -05:00
|
|
|
labels: null,
|
2018-12-17 04:53:20 -05:00
|
|
|
loadingFileTree: true
|
|
|
|
}
|
|
|
|
let _deregisterFeatureWatcher = this.$scope.$watch(
|
|
|
|
'project.features.versioning',
|
|
|
|
hasVersioning => {
|
|
|
|
if (hasVersioning != null) {
|
|
|
|
this.$scope.history.userHasFullFeature = hasVersioning
|
2019-05-28 07:04:35 -04:00
|
|
|
if (this.$scope.user.isAdmin) {
|
|
|
|
this.$scope.history.userHasFullFeature = true
|
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
_deregisterFeatureWatcher()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
softReset() {
|
|
|
|
this.$scope.history.viewMode = this._getViewModeUserPref()
|
|
|
|
this.$scope.history.selection = {
|
|
|
|
docs: {},
|
|
|
|
pathname: null,
|
|
|
|
range: {
|
|
|
|
fromV: null,
|
|
|
|
toV: null
|
|
|
|
},
|
|
|
|
hoveredRange: {
|
|
|
|
fromV: null,
|
|
|
|
toV: null
|
|
|
|
},
|
2018-11-05 05:06:39 -05:00
|
|
|
diff: null, // When history.viewMode == HistoryViewModes.COMPARE
|
2018-12-17 04:53:20 -05:00
|
|
|
files: [], // When history.viewMode == HistoryViewModes.COMPARE
|
|
|
|
file: null
|
|
|
|
}
|
|
|
|
this.$scope.history.error = null
|
|
|
|
this.$scope.history.showOnlyLabels = this._getShowOnlyLabelsUserPref()
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
_handleHistoryUIStateChange() {
|
|
|
|
if (this.$scope.history.viewMode === HistoryViewModes.COMPARE) {
|
|
|
|
if (this.$scope.history.showOnlyLabels) {
|
|
|
|
this.autoSelectLabelsForComparison()
|
|
|
|
} else {
|
|
|
|
this.autoSelectRecentUpdates()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Point-in-time mode
|
|
|
|
if (this.$scope.history.showOnlyLabels) {
|
2019-04-09 05:56:45 -04:00
|
|
|
this.autoSelectLabelForPointInTime()
|
2018-12-17 04:53:20 -05:00
|
|
|
} else {
|
2019-04-09 05:56:45 -04:00
|
|
|
this.autoSelectVersionForPointInTime()
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setHoverFrom(fromV) {
|
|
|
|
let selection = this.$scope.history.selection
|
|
|
|
selection.hoveredRange.fromV = fromV
|
|
|
|
selection.hoveredRange.toV = selection.range.toV
|
|
|
|
this.$scope.history.hoveringOverListSelectors = true
|
|
|
|
}
|
|
|
|
|
|
|
|
setHoverTo(toV) {
|
|
|
|
let selection = this.$scope.history.selection
|
|
|
|
selection.hoveredRange.toV = toV
|
|
|
|
selection.hoveredRange.fromV = selection.range.fromV
|
|
|
|
this.$scope.history.hoveringOverListSelectors = true
|
|
|
|
}
|
|
|
|
|
|
|
|
resetHover() {
|
|
|
|
let selection = this.$scope.history.selection
|
|
|
|
selection.hoveredRange.toV = null
|
|
|
|
selection.hoveredRange.fromV = null
|
|
|
|
this.$scope.history.hoveringOverListSelectors = false
|
|
|
|
}
|
|
|
|
|
|
|
|
showAllUpdates() {
|
|
|
|
if (this.$scope.history.showOnlyLabels) {
|
|
|
|
this.$scope.history.showOnlyLabels = false
|
|
|
|
this._setShowOnlyLabelsUserPref(false)
|
|
|
|
this._handleHistoryUIStateChange()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
showOnlyLabels() {
|
|
|
|
if (!this.$scope.history.showOnlyLabels) {
|
|
|
|
this.$scope.history.showOnlyLabels = true
|
|
|
|
this._setShowOnlyLabelsUserPref(true)
|
|
|
|
this._handleHistoryUIStateChange()
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
restoreFile(version, pathname) {
|
|
|
|
const url = `/project/${this.$scope.project_id}/restore_file`
|
|
|
|
|
|
|
|
return this.ide.$http.post(url, {
|
|
|
|
version,
|
|
|
|
pathname,
|
|
|
|
_csrf: window.csrfToken
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
loadFileTreeForVersion(version) {
|
2018-12-17 04:53:20 -05:00
|
|
|
return this._loadFileTree(version, version)
|
|
|
|
}
|
|
|
|
|
|
|
|
loadFileTreeDiff(toV, fromV) {
|
|
|
|
return this._loadFileTree(toV, fromV)
|
|
|
|
}
|
|
|
|
|
|
|
|
_loadFileTree(toV, fromV) {
|
2018-11-05 05:06:39 -05:00
|
|
|
let url = `/project/${this.$scope.project_id}/filetree/diff`
|
2018-12-17 04:53:20 -05:00
|
|
|
let selection = this.$scope.history.selection
|
|
|
|
const query = [`from=${fromV}`, `to=${toV}`]
|
2018-11-05 05:06:39 -05:00
|
|
|
url += `?${query.join('&')}`
|
2019-04-09 05:56:45 -04:00
|
|
|
|
|
|
|
this.$scope.$applyAsync(
|
|
|
|
() => (this.$scope.history.loadingFileTree = true)
|
|
|
|
)
|
|
|
|
|
2018-12-17 04:53:20 -05:00
|
|
|
selection.file = null
|
|
|
|
selection.pathname = null
|
2019-04-09 05:56:45 -04:00
|
|
|
|
|
|
|
// 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()
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2019-04-09 05:56:45 -04:00
|
|
|
this._loadFileTreeRequestCanceller = this.ide.$q.defer()
|
|
|
|
|
2018-12-17 04:53:20 -05:00
|
|
|
return this.ide.$http
|
2019-04-09 05:56:45 -04:00
|
|
|
.get(url, { timeout: this._loadFileTreeRequestCanceller.promise })
|
2018-12-17 04:53:20 -05:00
|
|
|
.then(response => {
|
|
|
|
this.$scope.history.selection.files = response.data.diff
|
2019-01-29 05:10:53 -05:00
|
|
|
for (let file of this.$scope.history.selection.files) {
|
|
|
|
if (file.newPathname != null) {
|
|
|
|
file.oldPathname = file.pathname
|
|
|
|
file.pathname = file.newPathname
|
|
|
|
delete file.newPathname
|
|
|
|
}
|
|
|
|
}
|
2019-04-09 05:56:45 -04:00
|
|
|
this._loadFileTreeRequestCanceller = null
|
|
|
|
this.$scope.history.loadingFileTree = false
|
2019-01-29 05:10:53 -05:00
|
|
|
this.autoSelectFile()
|
|
|
|
})
|
|
|
|
.catch(err => {
|
2019-04-09 05:56:45 -04:00
|
|
|
if (err.status !== -1) {
|
|
|
|
this._loadFileTreeRequestCanceller = null
|
|
|
|
} else {
|
|
|
|
this.$scope.history.loadingFileTree = false
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
|
|
|
})
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
|
|
|
selectFile(file) {
|
|
|
|
if (file != null && file.pathname != null) {
|
2019-01-29 05:10:53 -05:00
|
|
|
this.$scope.history.selection.pathname = this._previouslySelectedPathname =
|
|
|
|
file.pathname
|
2018-12-17 04:53:20 -05:00
|
|
|
this.$scope.history.selection.file = file
|
|
|
|
if (this.$scope.history.viewMode === HistoryViewModes.POINT_IN_TIME) {
|
|
|
|
this.loadFileAtPointInTime()
|
|
|
|
} else {
|
|
|
|
this.reloadDiff()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-29 05:10:53 -05:00
|
|
|
autoSelectFile() {
|
|
|
|
let selectedPathname = null
|
|
|
|
let files = this.$scope.history.selection.files
|
|
|
|
let fileToSelect = null
|
|
|
|
let previouslySelectedFile = null
|
2019-08-13 08:30:54 -04:00
|
|
|
let previouslySelectedFileHasOp = false
|
|
|
|
let filesWithOps = this._getFilesWithOps()
|
2019-01-29 05:10:53 -05:00
|
|
|
const orderedOpTypes = ['edited', 'added', 'renamed', 'removed']
|
|
|
|
|
|
|
|
if (this._previouslySelectedPathname != null) {
|
|
|
|
previouslySelectedFile = _.find(files, {
|
|
|
|
pathname: this._previouslySelectedPathname
|
|
|
|
})
|
2019-08-13 08:30:54 -04:00
|
|
|
previouslySelectedFileHasOp = _.some(filesWithOps, {
|
|
|
|
pathname: this._previouslySelectedPathname
|
|
|
|
})
|
2019-01-29 05:10:53 -05:00
|
|
|
}
|
2019-08-13 08:30:54 -04:00
|
|
|
if (previouslySelectedFile != null && previouslySelectedFileHasOp) {
|
2019-01-29 05:10:53 -05:00
|
|
|
fileToSelect = previouslySelectedFile
|
|
|
|
} else {
|
|
|
|
for (let opType of orderedOpTypes) {
|
2019-08-13 08:30:54 -04:00
|
|
|
let fileWithMatchingOpType = _.find(filesWithOps, {
|
|
|
|
operation: opType
|
|
|
|
})
|
2019-01-29 05:10:53 -05:00
|
|
|
if (fileWithMatchingOpType != null) {
|
2019-08-13 08:30:54 -04:00
|
|
|
fileToSelect = _.find(files, {
|
|
|
|
pathname: fileWithMatchingOpType.pathname
|
|
|
|
})
|
2019-01-29 05:10:53 -05:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fileToSelect == null) {
|
2019-08-13 08:30:54 -04:00
|
|
|
if (previouslySelectedFile != null) {
|
|
|
|
fileToSelect = previouslySelectedFile
|
2019-01-29 05:10:53 -05:00
|
|
|
} else {
|
2019-08-13 08:30:54 -04:00
|
|
|
let mainFile = _.find(files, function(file) {
|
|
|
|
return /main\.tex$/.test(file.pathname)
|
2019-01-29 05:10:53 -05:00
|
|
|
})
|
2019-08-13 08:30:54 -04:00
|
|
|
if (mainFile != null) {
|
|
|
|
fileToSelect = mainFile
|
2019-01-29 05:10:53 -05:00
|
|
|
} else {
|
2019-08-13 08:30:54 -04:00
|
|
|
let anyTeXFile = _.find(files, function(file) {
|
|
|
|
return /\.tex$/.test(file.pathname)
|
|
|
|
})
|
|
|
|
if (anyTeXFile != null) {
|
|
|
|
fileToSelect = anyTeXFile
|
|
|
|
} else {
|
|
|
|
fileToSelect = files[0]
|
|
|
|
}
|
2019-01-29 05:10:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-13 08:30:54 -04:00
|
|
|
|
2019-01-29 05:10:53 -05:00
|
|
|
this.selectFile(fileToSelect)
|
|
|
|
}
|
|
|
|
|
2019-08-13 08:30:54 -04:00
|
|
|
_getFilesWithOps() {
|
|
|
|
let filesWithOps
|
|
|
|
if (this.$scope.history.viewMode === HistoryViewModes.POINT_IN_TIME) {
|
|
|
|
let currentUpdate = this.getUpdateForVersion(
|
|
|
|
this.$scope.history.selection.range.toV
|
|
|
|
)
|
|
|
|
filesWithOps = []
|
|
|
|
if (currentUpdate != null) {
|
|
|
|
for (pathname of currentUpdate.pathnames) {
|
|
|
|
filesWithOps.push({
|
|
|
|
pathname: pathname,
|
|
|
|
operation: 'edited'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
for (op of currentUpdate.project_ops) {
|
|
|
|
let fileWithOp
|
|
|
|
if (op.add != null) {
|
|
|
|
fileWithOp = {
|
|
|
|
pathname: op.add.pathname,
|
|
|
|
operation: 'added'
|
|
|
|
}
|
|
|
|
} else if (op.remove != null) {
|
|
|
|
fileWithOp = {
|
|
|
|
pathname: op.remove.pathname,
|
|
|
|
operation: 'removed'
|
|
|
|
}
|
|
|
|
} else if (op.rename != null) {
|
|
|
|
fileWithOp = {
|
|
|
|
pathname: op.rename.newPathname,
|
|
|
|
operation: 'renamed'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fileWithOp != null) {
|
|
|
|
filesWithOps.push(fileWithOp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
filesWithOps = _.reduce(
|
|
|
|
this.$scope.history.selection.files,
|
|
|
|
(curFilesWithOps, file) => {
|
|
|
|
if (file.operation) {
|
|
|
|
curFilesWithOps.push({
|
|
|
|
pathname: file.pathname,
|
|
|
|
operation: file.operation
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return curFilesWithOps
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return filesWithOps
|
|
|
|
}
|
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
autoSelectRecentUpdates() {
|
|
|
|
if (this.$scope.history.updates.length === 0) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-04-09 05:56:45 -04:00
|
|
|
let toV = this.$scope.history.updates[0].toV
|
|
|
|
let fromV = null
|
2018-11-05 05:06:39 -05:00
|
|
|
|
|
|
|
let indexOfLastUpdateNotByMe = 0
|
|
|
|
for (let i = 0; i < this.$scope.history.updates.length; i++) {
|
|
|
|
const update = this.$scope.history.updates[i]
|
|
|
|
if (
|
|
|
|
this._updateContainsUserId(update, this.$scope.user.id) ||
|
|
|
|
i > this.MAX_RECENT_UPDATES_TO_SELECT
|
|
|
|
) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
indexOfLastUpdateNotByMe = i
|
|
|
|
}
|
|
|
|
|
2019-04-09 05:56:45 -04:00
|
|
|
fromV = this.$scope.history.updates[indexOfLastUpdateNotByMe].fromV
|
|
|
|
this.selectVersionsForCompare(toV, fromV)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2019-04-09 05:56:45 -04:00
|
|
|
autoSelectVersionForPointInTime() {
|
2018-11-05 05:06:39 -05:00
|
|
|
if (this.$scope.history.updates.length === 0) {
|
|
|
|
return
|
|
|
|
}
|
2019-04-09 05:56:45 -04:00
|
|
|
let versionToSelect = this.$scope.history.updates[0].toV
|
|
|
|
let range = this.$scope.history.selection.range
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
autoSelectLastLabel() {
|
2018-12-17 04:53:20 -05:00
|
|
|
if (
|
|
|
|
this.$scope.history.labels == null ||
|
|
|
|
this.$scope.history.labels.length === 0
|
|
|
|
) {
|
2018-11-05 05:06:39 -05:00
|
|
|
return
|
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
return this.selectLabelForPointInTime(this.$scope.history.labels[0])
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2018-12-17 04:53:20 -05: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
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 04:53:20 -05:00
|
|
|
selectVersionForPointInTime(version) {
|
|
|
|
let selection = this.$scope.history.selection
|
2019-04-09 05:56:45 -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
|
|
|
}
|
|
|
|
|
2019-04-09 05:56:45 -04:00
|
|
|
selectVersionsForCompare(toV, fromV) {
|
|
|
|
let range = this.$scope.history.selection.range
|
|
|
|
if (range.toV !== toV || range.fromV !== fromV) {
|
|
|
|
range.toV = toV
|
|
|
|
range.fromV = fromV
|
|
|
|
this.loadFileTreeDiff(toV, fromV)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
autoSelectLabelForPointInTime() {
|
|
|
|
const selectedUpdate = this.getUpdateForVersion(
|
2018-12-17 04:53:20 -05:00
|
|
|
this.$scope.history.selection.range.toV
|
2018-11-05 05:06:39 -05:00
|
|
|
)
|
2018-12-17 04:53:20 -05:00
|
|
|
let nSelectedLabels = 0
|
|
|
|
|
|
|
|
if (selectedUpdate != null && selectedUpdate.labels != null) {
|
|
|
|
nSelectedLabels = selectedUpdate.labels.length
|
|
|
|
}
|
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
// If the currently selected update has no labels, select the last one (version-wise)
|
|
|
|
if (nSelectedLabels === 0) {
|
2018-12-17 04:53:20 -05:00
|
|
|
this.autoSelectLastLabel()
|
2018-11-05 05:06:39 -05:00
|
|
|
// If the update has one label, select it
|
|
|
|
} else if (nSelectedLabels === 1) {
|
2019-04-09 05:56:45 -04:00
|
|
|
this.selectLabelForPointInTime(selectedUpdate.labels[0])
|
2018-11-05 05:06:39 -05:00
|
|
|
// If there are multiple labels for the update, select the latest
|
|
|
|
} else if (nSelectedLabels > 1) {
|
|
|
|
const sortedLabels = this.ide.$filter('orderBy')(
|
2018-12-17 04:53:20 -05:00
|
|
|
selectedUpdate.labels,
|
2018-11-05 05:06:39 -05:00
|
|
|
'-created_at'
|
|
|
|
)
|
|
|
|
const lastLabelFromUpdate = sortedLabels[0]
|
2018-12-17 04:53:20 -05:00
|
|
|
this.selectLabelForPointInTime(lastLabelFromUpdate)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-17 04:53:20 -05:00
|
|
|
selectLabelForPointInTime(labelToSelect) {
|
2018-11-05 05:06:39 -05:00
|
|
|
let updateToSelect = null
|
|
|
|
|
|
|
|
if (this._isLabelSelected(labelToSelect)) {
|
|
|
|
// Label already selected
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let update of Array.from(this.$scope.history.updates)) {
|
|
|
|
if (update.toV === labelToSelect.version) {
|
|
|
|
updateToSelect = update
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updateToSelect != null) {
|
2018-12-17 04:53:20 -05:00
|
|
|
this.selectVersionForPointInTime(updateToSelect.toV)
|
2018-11-05 05:06:39 -05:00
|
|
|
} else {
|
2018-12-17 04:53:20 -05:00
|
|
|
let selection = this.$scope.history.selection
|
|
|
|
selection.range.toV = labelToSelect.version
|
|
|
|
selection.range.fromV = labelToSelect.version
|
|
|
|
this.loadFileTreeForVersion(labelToSelect.version)
|
|
|
|
}
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-04-09 05:56:45 -04:00
|
|
|
getUpdateForVersion(version) {
|
2018-12-17 04:53:20 -05:00
|
|
|
for (let update of this.$scope.history.updates) {
|
|
|
|
if (update.toV === version) {
|
|
|
|
return update
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
|
|
|
|
autoSelectLabelsForComparison() {
|
|
|
|
let labels = this.$scope.history.labels
|
|
|
|
let nLabels = 0
|
|
|
|
if (Array.isArray(labels)) {
|
|
|
|
nLabels = labels.length
|
|
|
|
}
|
2019-04-09 05:56:45 -04:00
|
|
|
if (nLabels === 0) {
|
|
|
|
// TODO better handling
|
|
|
|
} else if (nLabels === 1) {
|
|
|
|
this.selectVersionsForCompare(labels[0].version, labels[0].version)
|
2018-12-17 04:53:20 -05:00
|
|
|
} else if (nLabels > 1) {
|
2019-04-09 05:56:45 -04:00
|
|
|
this.selectVersionsForCompare(labels[0].version, labels[1].version)
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
fetchNextBatchOfUpdates() {
|
2018-12-17 04:53:20 -05:00
|
|
|
if (this.$scope.history.atEnd) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
let updatesURL = `/project/${this.ide.project_id}/updates?min_count=${
|
|
|
|
this.BATCH_SIZE
|
|
|
|
}`
|
|
|
|
if (this.$scope.history.nextBeforeTimestamp != null) {
|
|
|
|
updatesURL += `&before=${this.$scope.history.nextBeforeTimestamp}`
|
|
|
|
}
|
|
|
|
const labelsURL = `/project/${this.ide.project_id}/labels`
|
|
|
|
|
|
|
|
const requests = { updates: this.ide.$http.get(updatesURL) }
|
|
|
|
|
|
|
|
if (this.$scope.history.labels == null) {
|
|
|
|
requests.labels = this.ide.$http.get(labelsURL)
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.ide.$q
|
|
|
|
.all(requests)
|
|
|
|
.then(response => {
|
|
|
|
const updatesData = response.updates.data
|
2018-12-18 06:09:56 -05:00
|
|
|
let lastUpdateToV = null
|
|
|
|
|
|
|
|
if (updatesData.updates.length > 0) {
|
|
|
|
lastUpdateToV = updatesData.updates[0].toV
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
if (response.labels != null) {
|
2018-12-17 04:53:20 -05:00
|
|
|
this.$scope.history.labels = this._loadLabels(
|
|
|
|
response.labels.data,
|
2018-12-18 06:09:56 -05:00
|
|
|
lastUpdateToV
|
2018-11-05 05:06:39 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
this._loadUpdates(updatesData.updates)
|
|
|
|
this.$scope.history.nextBeforeTimestamp =
|
|
|
|
updatesData.nextBeforeTimestamp
|
|
|
|
if (
|
|
|
|
updatesData.nextBeforeTimestamp == null ||
|
2018-12-18 06:09:56 -05:00
|
|
|
this.$scope.history.freeHistoryLimitHit ||
|
|
|
|
this.$scope.history.updates.length === 0
|
2018-11-05 05:06:39 -05:00
|
|
|
) {
|
|
|
|
this.$scope.history.atEnd = true
|
|
|
|
}
|
|
|
|
if (this.$scope.history.updates.length === 0) {
|
2018-12-17 04:53:20 -05:00
|
|
|
this.$scope.history.loadingFileTree = false
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
const { status, statusText } = error
|
|
|
|
this.$scope.history.error = { status, statusText }
|
2018-12-18 06:09:56 -05:00
|
|
|
this.$scope.history.atEnd = true
|
|
|
|
this.$scope.history.loadingFileTree = false
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-12-17 04:53:20 -05:00
|
|
|
_loadLabels(labels, lastUpdateToV) {
|
|
|
|
let sortedLabels = this._sortLabelsByVersionAndDate(labels)
|
2019-04-09 05:56:45 -04:00
|
|
|
let nLabels = sortedLabels.length
|
2018-12-17 04:53:20 -05:00
|
|
|
let hasPseudoCurrentStateLabel = false
|
|
|
|
let needsPseudoCurrentStateLabel = false
|
2019-04-09 05:56:45 -04:00
|
|
|
if (lastUpdateToV) {
|
|
|
|
hasPseudoCurrentStateLabel =
|
|
|
|
nLabels > 0 ? sortedLabels[0].isPseudoCurrentStateLabel : false
|
2018-12-17 04:53:20 -05:00
|
|
|
if (hasPseudoCurrentStateLabel) {
|
|
|
|
needsPseudoCurrentStateLabel =
|
2019-04-09 05:56:45 -04:00
|
|
|
nLabels > 1 ? sortedLabels[1].version !== lastUpdateToV : false
|
2018-12-17 04:53:20 -05:00
|
|
|
} else {
|
|
|
|
needsPseudoCurrentStateLabel =
|
2019-04-09 05:56:45 -04:00
|
|
|
nLabels > 0 ? sortedLabels[0].version !== lastUpdateToV : true
|
2018-12-17 04:53:20 -05:00
|
|
|
}
|
|
|
|
if (needsPseudoCurrentStateLabel && !hasPseudoCurrentStateLabel) {
|
2019-04-09 05:56:45 -04:00
|
|
|
let pseudoCurrentStateLabel = {
|
2018-12-17 04:53:20 -05:00
|
|
|
id: '1',
|
|
|
|
isPseudoCurrentStateLabel: true,
|
|
|
|
version: lastUpdateToV,
|
|
|
|
created_at: new Date().toISOString()
|
2019-04-09 05:56:45 -04:00
|
|
|
}
|
|
|
|
sortedLabels.unshift(pseudoCurrentStateLabel)
|
2018-12-17 04:53:20 -05:00
|
|
|
} else if (
|
|
|
|
!needsPseudoCurrentStateLabel &&
|
|
|
|
hasPseudoCurrentStateLabel
|
|
|
|
) {
|
|
|
|
sortedLabels.shift()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sortedLabels
|
|
|
|
}
|
|
|
|
|
2018-11-05 05:06:39 -05:00
|
|
|
_sortLabelsByVersionAndDate(labels) {
|
2018-12-17 04:53:20 -05:00
|
|
|
return this.ide.$filter('orderBy')(labels, [
|
|
|
|
'isPseudoCurrentStateLabel',
|
|
|
|
'-version',
|
|
|
|
'-created_at'
|
|
|
|
])
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
loadFileAtPointInTime() {
|
2018-12-17 04:53:20 -05:00
|
|
|
const toV = this.$scope.history.selection.range.toV
|
2018-11-05 05:06:39 -05:00
|
|
|
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}`,
|
|
|
|
`to=${toV}`
|
|
|
|
]
|
|
|
|
url += `?${query.join('&')}`
|
2018-12-17 04:53:20 -05:00
|
|
|
this.$scope.history.selection.file.loading = true
|
2018-11-05 05:06:39 -05:00
|
|
|
return this.ide.$http
|
|
|
|
.get(url)
|
|
|
|
.then(response => {
|
|
|
|
const { text, binary } = this._parseDiff(response.data.diff)
|
2018-12-17 04:53:20 -05:00
|
|
|
this.$scope.history.selection.file.binary = binary
|
|
|
|
this.$scope.history.selection.file.text = text
|
|
|
|
this.$scope.history.selection.file.loading = false
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
|
|
|
.catch(function() {})
|
|
|
|
}
|
|
|
|
|
|
|
|
reloadDiff() {
|
2018-12-17 04:53:20 -05:00
|
|
|
let { diff } = this.$scope.history.selection
|
|
|
|
const { range, pathname } = this.$scope.history.selection
|
|
|
|
const { fromV, toV } = range
|
2018-11-05 05:06:39 -05:00
|
|
|
|
|
|
|
if (pathname == null) {
|
2018-12-17 04:53:20 -05:00
|
|
|
this.$scope.history.selection.diff = null
|
2018-11-05 05:06:39 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
diff != null &&
|
|
|
|
diff.pathname === pathname &&
|
|
|
|
diff.fromV === fromV &&
|
|
|
|
diff.toV === toV
|
|
|
|
) {
|
2019-04-09 05:56:45 -04:00
|
|
|
return
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
2018-12-17 04:53:20 -05:00
|
|
|
this.$scope.history.selection.diff = diff = {
|
2018-11-05 05:06:39 -05:00
|
|
|
fromV,
|
|
|
|
toV,
|
|
|
|
pathname,
|
|
|
|
error: false
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2018-12-17 04:53:20 -05:00
|
|
|
diff.highlights = highlights
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
|
|
|
.catch(function() {
|
|
|
|
diff.loading = false
|
2018-12-17 04:53:20 -05:00
|
|
|
diff.error = true
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
labelCurrentVersion(labelComment) {
|
|
|
|
return this._labelVersion(
|
|
|
|
labelComment,
|
2018-12-17 04:53:20 -05:00
|
|
|
this.$scope.history.selection.range.toV
|
2018-11-05 05:06:39 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteLabel(label) {
|
|
|
|
const url = `/project/${this.$scope.project_id}/labels/${label.id}`
|
|
|
|
|
|
|
|
return this.ide
|
|
|
|
.$http({
|
|
|
|
url,
|
|
|
|
method: 'DELETE',
|
|
|
|
headers: {
|
|
|
|
'X-CSRF-Token': window.csrfToken
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(response => {
|
|
|
|
return this._deleteLabelLocally(label)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
_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-12-17 04:53:20 -05: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()
|
|
|
|
}
|
|
|
|
|
|
|
|
_isLabelSelected(label) {
|
2019-04-09 05:56:45 -04:00
|
|
|
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
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
2018-11-05 05:06:39 -05: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++) {
|
|
|
|
var endColumn, endRow
|
|
|
|
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
|
|
|
|
} else {
|
|
|
|
endRow = startRow
|
|
|
|
endColumn = startColumn + lines[0].length
|
|
|
|
}
|
|
|
|
row = endRow
|
|
|
|
column = endColumn
|
|
|
|
|
|
|
|
const range = {
|
|
|
|
start: {
|
|
|
|
row: startRow,
|
|
|
|
column: startColumn
|
|
|
|
},
|
|
|
|
end: {
|
|
|
|
row: endRow,
|
|
|
|
column: endColumn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
})
|
|
|
|
} else if (entry.d != null) {
|
|
|
|
highlights.push({
|
|
|
|
label: `Deleted by ${name} on ${date}`,
|
|
|
|
strikeThrough: range,
|
|
|
|
hue: ColorManager.getHueForUserId(
|
|
|
|
user != null ? user.id : undefined
|
|
|
|
)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { text, highlights }
|
|
|
|
}
|
|
|
|
|
|
|
|
_loadUpdates(updates) {
|
|
|
|
if (updates == null) {
|
|
|
|
updates = []
|
|
|
|
}
|
|
|
|
let previousUpdate = this.$scope.history.updates[
|
|
|
|
this.$scope.history.updates.length - 1
|
|
|
|
]
|
|
|
|
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]
|
|
|
|
for (let user of Array.from(update.meta.users || [])) {
|
|
|
|
if (user != null) {
|
|
|
|
user.hue = ColorManager.getHueForUserId(user.id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
previousUpdate == null ||
|
|
|
|
!moment(previousUpdate.meta.end_ts).isSame(
|
|
|
|
update.meta.end_ts,
|
|
|
|
'day'
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
update.meta.first_in_day = true
|
|
|
|
}
|
|
|
|
|
|
|
|
previousUpdate = update
|
|
|
|
|
|
|
|
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
|
2019-06-06 11:32:54 -04:00
|
|
|
if (this.$scope.project.owner._id === this.$scope.user.id) {
|
|
|
|
ga(
|
|
|
|
'send',
|
|
|
|
'event',
|
|
|
|
'subscription-funnel',
|
|
|
|
'editor-click-feature',
|
|
|
|
'history'
|
|
|
|
)
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const firstLoad = this.$scope.history.updates.length === 0
|
|
|
|
|
|
|
|
if (!this.$scope.history.userHasFullFeature && cutOffIndex != null) {
|
|
|
|
updates = updates.slice(0, cutOffIndex)
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_labelVersion(comment, version) {
|
|
|
|
const url = `/project/${this.$scope.project_id}/labels`
|
|
|
|
return this.ide.$http
|
|
|
|
.post(url, {
|
|
|
|
comment,
|
|
|
|
version,
|
|
|
|
_csrf: window.csrfToken
|
|
|
|
})
|
|
|
|
.then(response => {
|
2018-12-17 04:53:20 -05:00
|
|
|
return this._addLabelLocally(response.data)
|
2018-11-05 05:06:39 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-12-17 04:53:20 -05:00
|
|
|
_addLabelLocally(label) {
|
2018-11-05 05:06:39 -05:00
|
|
|
const localUpdate = _.find(
|
|
|
|
this.$scope.history.updates,
|
|
|
|
update => update.toV === label.version
|
|
|
|
)
|
|
|
|
if (localUpdate != null) {
|
2018-12-17 04:53:20 -05:00
|
|
|
localUpdate.labels = localUpdate.labels.concat(label)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
2018-12-17 04:53:20 -05:00
|
|
|
this.$scope.history.labels = this._loadLabels(
|
|
|
|
this.$scope.history.labels.concat(label),
|
|
|
|
this.$scope.history.updates[0].toV
|
2018-11-05 05:06:39 -05:00
|
|
|
)
|
2018-12-17 04:53:20 -05:00
|
|
|
this._handleHistoryUIStateChange()
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
_updateContainsUserId(update, user_id) {
|
|
|
|
for (let user of Array.from(update.meta.users)) {
|
|
|
|
if ((user != null ? user.id : undefined) === user_id) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
HistoryManager.initClass()
|
|
|
|
return HistoryManager
|
|
|
|
})())
|
|
|
|
})
|
|
|
|
|
|
|
|
function __guard__(value, transform) {
|
|
|
|
return typeof value !== 'undefined' && value !== null
|
|
|
|
? transform(value)
|
|
|
|
: undefined
|
|
|
|
}
|