CloneProjectModalController.js 1.6 KB

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