HistoryDiffController.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* eslint-disable
  2. camelcase,
  3. max-len,
  4. no-return-assign,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. import App from '../../../base'
  14. App.controller('HistoryDiffController', function(
  15. $scope,
  16. $modal,
  17. ide,
  18. eventTracking
  19. ) {
  20. $scope.restoreDeletedDoc = function() {
  21. eventTracking.sendMB('history-restore-deleted')
  22. $scope.history.diff.restoreInProgress = true
  23. return ide.historyManager
  24. .restoreDeletedDoc($scope.history.diff.doc)
  25. .then(function(response) {
  26. const { data } = response
  27. $scope.history.diff.restoredDocNewId = data.doc_id
  28. $scope.history.diff.restoreInProgress = false
  29. return ($scope.history.diff.restoreDeletedSuccess = true)
  30. })
  31. }
  32. $scope.openRestoreDiffModal = function() {
  33. eventTracking.sendMB('history-restore-modal')
  34. return $modal.open({
  35. templateUrl: 'historyRestoreDiffModalTemplate',
  36. controller: 'HistoryRestoreDiffModalController',
  37. resolve: {
  38. diff() {
  39. return $scope.history.diff
  40. }
  41. }
  42. })
  43. }
  44. return ($scope.backToEditorAfterRestore = () =>
  45. ide.editorManager.openDoc({ id: $scope.history.diff.restoredDocNewId }))
  46. })
  47. export default App.controller('HistoryRestoreDiffModalController', function(
  48. $scope,
  49. $modalInstance,
  50. diff,
  51. ide,
  52. eventTracking
  53. ) {
  54. $scope.state = { inflight: false }
  55. $scope.diff = diff
  56. $scope.restore = function() {
  57. eventTracking.sendMB('history-restored')
  58. $scope.state.inflight = true
  59. return ide.historyManager.restoreDiff(diff).then(function() {
  60. $scope.state.inflight = false
  61. $modalInstance.close()
  62. return ide.editorManager.openDoc(diff.doc)
  63. })
  64. }
  65. return ($scope.cancel = () => $modalInstance.dismiss())
  66. })