HistoryDiffController.js 2.1 KB

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