From 415be6b4e0694e91bb12f584be96edd806d23df7 Mon Sep 17 00:00:00 2001 From: James Allen Date: Mon, 12 Mar 2018 12:40:44 +0000 Subject: [PATCH] Open file after restoring --- .../project/editor/history/diffPanelV2.pug | 16 +++++++------- .../binary-files/BinaryFilesManager.coffee | 1 + .../HistoryV2DiffController.coffee | 22 +++++++++---------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/services/web/app/views/project/editor/history/diffPanelV2.pug b/services/web/app/views/project/editor/history/diffPanelV2.pug index eb43eb2e9e..415d587155 100644 --- a/services/web/app/views/project/editor/history/diffPanelV2.pug +++ b/services/web/app/views/project/editor/history/diffPanelV2.pug @@ -1,9 +1,12 @@ .diff-panel.full-size(ng-if="history.isV2", ng-controller="HistoryV2DiffController") .diff( - ng-if="!!history.diff && !history.diff.loading && !history.diff.error && !history.diff.binary" + ng-if="!!history.diff && !history.diff.loading && !history.diff.error", + ng-class="{ 'diff-binary': history.diff.binary }" ) .toolbar.toolbar-alt - span.name + span.name(ng-if="history.diff.binary") + strong {{history.diff.pathname}} + span.name(ng-if="!history.diff.binary") | {{history.diff.highlights.length}} ng-pluralize( count="history.diff.highlights.length", @@ -27,6 +30,7 @@ span.text-danger(ng-show="restoreState.error") | Error restoring, sorry .diff-editor.hide-ace-cursor( + ng-if="!history.diff.binary" ace-editor="history", theme="settings.theme", font-size="settings.fontSize", @@ -36,12 +40,8 @@ resize-on="layout:main:resize", navigate-highlights="true" ) - - .diff.diff-binary(ng-show="history.diff.binary") - .toolbar.toolbar-alt - span.name - strong {{history.diff.pathname}} - .alert.alert-info We're still working on showing image and binary changes, sorry. Stay tuned! + .alert.alert-info(ng-if="history.diff.binary") + | We're still working on showing image and binary changes, sorry. Stay tuned! .loading-panel(ng-show="history.diff.loading") i.fa.fa-spin.fa-refresh diff --git a/services/web/public/coffee/ide/binary-files/BinaryFilesManager.coffee b/services/web/public/coffee/ide/binary-files/BinaryFilesManager.coffee index 02283bc49e..ebecf1132e 100644 --- a/services/web/public/coffee/ide/binary-files/BinaryFilesManager.coffee +++ b/services/web/public/coffee/ide/binary-files/BinaryFilesManager.coffee @@ -8,6 +8,7 @@ define [ @openFile(entity) openFile: (file) -> + @ide.fileTreeManager.selectEntity(file) @$scope.ui.view = "file" @$scope.openFile = null @$scope.$apply() diff --git a/services/web/public/coffee/ide/history/controllers/HistoryV2DiffController.coffee b/services/web/public/coffee/ide/history/controllers/HistoryV2DiffController.coffee index 9c08d659f7..89cf3975ec 100644 --- a/services/web/public/coffee/ide/history/controllers/HistoryV2DiffController.coffee +++ b/services/web/public/coffee/ide/history/controllers/HistoryV2DiffController.coffee @@ -2,8 +2,6 @@ define [ "base" ], (App) -> App.controller "HistoryV2DiffController", ($scope, ide, event_tracking) -> - console.log "HistoryV2DiffController!" - $scope.restoreState = inflight: false error: false @@ -15,25 +13,27 @@ define [ return if !version? event_tracking.sendMB "history-v2-restore-deleted" $scope.restoreState.inflight = true - $scope.restoreState.error = false ide.historyManager .restoreFile(version, pathname) .then (response) -> { data } = response - $scope.restoreState.inflight = false - if data.type == 'doc' - openDoc(data.id) + openEntity(data) .catch () -> - $scope.restoreState.error = true + ide.showGenericMessageModal('Sorry, something went wrong with the restore') + .finally () -> + $scope.restoreState.inflight = false - openDoc = (id) -> + openEntity = (data) -> iterations = 0 + {id, type} = data do tryOpen = () -> if iterations > 5 return - doc = ide.fileTreeManager.findEntityById(id) - if doc? - ide.editorManager.openDoc(doc) + entity = ide.fileTreeManager.findEntityById(id) + if entity? and type == 'doc' + ide.editorManager.openDoc(entity) + if entity? and type == 'file' + ide.binaryFilesManager.openFile(entity) else setTimeout(tryOpen, 500) \ No newline at end of file