CloneProjectModalController.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. define(['../../../base'], App =>
  13. App.controller('CloneProjectModalController', function(
  14. $scope,
  15. $modalInstance,
  16. $timeout,
  17. $http,
  18. ide
  19. ) {
  20. $scope.inputs = { projectName: ide.$scope.project.name + ' (Copy)' }
  21. $scope.state = {
  22. inflight: false,
  23. error: false
  24. }
  25. $modalInstance.opened.then(() =>
  26. $timeout(() => $scope.$broadcast('open'), 200)
  27. )
  28. const cloneProject = cloneName =>
  29. $http.post(`/project/${ide.$scope.project._id}/clone`, {
  30. _csrf: window.csrfToken,
  31. projectName: cloneName
  32. })
  33. $scope.clone = function() {
  34. $scope.state.inflight = true
  35. $scope.state.error = false
  36. return cloneProject($scope.inputs.projectName)
  37. .then(function(response) {
  38. const { data } = response
  39. return (window.location = `/project/${data.project_id}`)
  40. })
  41. .catch(function(response) {
  42. const { data, status } = response
  43. $scope.state.inflight = false
  44. if (status === 400) {
  45. return ($scope.state.error = { message: data })
  46. } else {
  47. return ($scope.state.error = true)
  48. }
  49. })
  50. }
  51. return ($scope.cancel = () => $modalInstance.dismiss('cancel'))
  52. }))