| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- /* eslint-disable
- max-len,
- no-return-assign,
- camelcase,
- */
- // TODO: This file was created by bulk-decaffeinate.
- // Fix any style issues and re-enable lint.
- /*
- * decaffeinate suggestions:
- * DS102: Remove unnecessary code created because of implicit returns
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
- */
- import App from '../../../base'
- export default App.controller(
- 'HistoryV2ToolbarController',
- ($scope, $modal, ide, eventTracking, waitFor) => {
- $scope.currentUpdate = null
- $scope.currentLabel = null
- $scope.restoreState = {
- inflight: false,
- error: false,
- }
- $scope.toolbarUIConfig = {
- showOnlyLabels: false,
- }
- const _deregistershowOnlyLabelsWatcher = $scope.$watch(
- 'history.showOnlyLabels',
- showOnlyLabels => {
- if (showOnlyLabels != null) {
- $scope.toolbarUIConfig.showOnlyLabels = showOnlyLabels
- _deregistershowOnlyLabelsWatcher()
- }
- }
- )
- $scope.$watch('toolbarUIConfig.showOnlyLabels', (newVal, oldVal) => {
- if (newVal != null && newVal !== oldVal) {
- if (newVal) {
- ide.historyManager.showOnlyLabels()
- } else {
- ide.historyManager.showAllUpdates()
- }
- }
- })
- $scope.$watch('history.viewMode', (newVal, oldVal) => {
- if (newVal != null && newVal !== oldVal) {
- $scope.currentUpdate = ide.historyManager.getUpdateForVersion(newVal)
- }
- })
- $scope.$watch('history.selection.range.toV', (newVal, oldVal) => {
- if (
- newVal != null &&
- newVal !== oldVal &&
- $scope.history.viewMode === $scope.HistoryViewModes.POINT_IN_TIME
- ) {
- $scope.currentUpdate = ide.historyManager.getUpdateForVersion(newVal)
- }
- })
- $scope.toggleHistoryViewMode = () => {
- ide.historyManager.toggleHistoryViewMode()
- }
- $scope.restoreDeletedFile = function () {
- const { pathname, deletedAtV } = $scope.history.selection.file
- if (pathname == null || deletedAtV == null) {
- return
- }
- eventTracking.sendMB('history-v2-restore-deleted')
- $scope.restoreState.inflight = true
- return ide.historyManager
- .restoreFile(deletedAtV, pathname)
- .then(function (response) {
- const { data } = response
- return openEntity(data)
- })
- .catch(() =>
- ide.showGenericMessageModal(
- 'Sorry, something went wrong with the restore'
- )
- )
- .finally(() => ($scope.restoreState.inflight = false))
- }
- $scope.showAddLabelDialog = () => {
- $modal.open({
- templateUrl: 'historyV2AddLabelModalTemplate',
- controller: 'HistoryV2AddLabelModalController',
- resolve: {
- update() {
- return $scope.history.selection.update
- },
- },
- })
- }
- function openEntity(data) {
- const { id, type } = data
- return waitFor(() => ide.fileTreeManager.findEntityById(id), 3000)
- .then(function (entity) {
- if (type === 'doc') {
- ide.editorManager.openDoc(entity)
- ide.$timeout(() => {
- $scope.$broadcast('history:toggle')
- }, 0)
- } else if (type === 'file') {
- ide.binaryFilesManager.openFile(entity)
- ide.$timeout(() => {
- $scope.$broadcast('history:toggle')
- }, 0)
- }
- })
- .catch(err => console.warn(err))
- }
- }
- )
|