HistoryDiffController.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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(
  15. 'HistoryDiffController',
  16. function ($scope, $modal, ide, eventTracking) {
  17. $scope.restoreDeletedDoc = function () {
  18. eventTracking.sendMB('history-restore-deleted')
  19. $scope.history.diff.restoreInProgress = true
  20. return ide.historyManager
  21. .restoreDeletedDoc($scope.history.diff.doc)
  22. .then(function (response) {
  23. const { data } = response
  24. $scope.history.diff.restoredDocNewId = data.doc_id
  25. $scope.history.diff.restoreInProgress = false
  26. return ($scope.history.diff.restoreDeletedSuccess = true)
  27. })
  28. }
  29. $scope.openRestoreDiffModal = function () {
  30. eventTracking.sendMB('history-restore-modal')
  31. return $modal.open({
  32. templateUrl: 'historyRestoreDiffModalTemplate',
  33. controller: 'HistoryRestoreDiffModalController',
  34. resolve: {
  35. diff() {
  36. return $scope.history.diff
  37. },
  38. },
  39. })
  40. }
  41. return ($scope.backToEditorAfterRestore = () =>
  42. ide.editorManager.openDoc({ id: $scope.history.diff.restoredDocNewId }))
  43. }
  44. )
  45. export default App.controller(
  46. 'HistoryRestoreDiffModalController',
  47. function ($scope, $modalInstance, diff, ide, eventTracking) {
  48. $scope.state = { inflight: false }
  49. $scope.diff = diff
  50. $scope.restore = function () {
  51. eventTracking.sendMB('history-restored')
  52. $scope.state.inflight = true
  53. return ide.historyManager.restoreDiff(diff).then(function () {
  54. $scope.state.inflight = false
  55. $modalInstance.close()
  56. return ide.editorManager.openDoc(diff.doc)
  57. })
  58. }
  59. return ($scope.cancel = () => $modalInstance.dismiss())
  60. }
  61. )