CloneProjectModalController.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. no-undef,
  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. define(['base'], App =>
  14. App.controller('CloneProjectModalController', function(
  15. $scope,
  16. $modalInstance,
  17. $timeout,
  18. $http,
  19. ide
  20. ) {
  21. $scope.inputs = { projectName: ide.$scope.project.name + ' (Copy)' }
  22. $scope.state = {
  23. inflight: false,
  24. error: false
  25. }
  26. $modalInstance.opened.then(() =>
  27. $timeout(() => $scope.$broadcast('open'), 200)
  28. )
  29. const cloneProject = cloneName =>
  30. $http.post(`/project/${ide.$scope.project._id}/clone`, {
  31. _csrf: window.csrfToken,
  32. projectName: cloneName
  33. })
  34. $scope.clone = function() {
  35. $scope.state.inflight = true
  36. $scope.state.error = false
  37. return cloneProject($scope.inputs.projectName)
  38. .then(function(response) {
  39. const { data } = response
  40. return (window.location = `/project/${data.project_id}`)
  41. })
  42. .catch(function(response) {
  43. const { data, status } = response
  44. $scope.state.inflight = false
  45. if (status === 400) {
  46. return ($scope.state.error = { message: data })
  47. } else {
  48. return ($scope.state.error = true)
  49. }
  50. })
  51. }
  52. return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
  53. }))