react-share-project-modal-controller.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import App from '../../../base'
  2. import { react2angular } from 'react2angular'
  3. import ShareProjectModal from '../components/share-project-modal'
  4. import { rootContext } from '../../../shared/context/root-context'
  5. import { listProjectInvites, listProjectMembers } from '../utils/api'
  6. App.component(
  7. 'shareProjectModal',
  8. react2angular(
  9. rootContext.use(ShareProjectModal),
  10. Object.keys(ShareProjectModal.propTypes)
  11. )
  12. )
  13. export default App.controller(
  14. 'ReactShareProjectModalController',
  15. function ($scope, eventTracking, ide) {
  16. $scope.isAdmin = false
  17. $scope.show = false
  18. $scope.handleHide = () => {
  19. $scope.$applyAsync(() => {
  20. $scope.show = false
  21. })
  22. }
  23. $scope.openShareProjectModal = isAdmin => {
  24. eventTracking.sendMBOnce('ide-open-share-modal-once')
  25. $scope.$applyAsync(() => {
  26. $scope.isAdmin = isAdmin
  27. $scope.show = true
  28. })
  29. }
  30. /* tokens */
  31. ide.socket.on('project:tokens:changed', data => {
  32. if (data.tokens != null) {
  33. $scope.$applyAsync(() => {
  34. $scope.project.tokens = data.tokens
  35. })
  36. }
  37. })
  38. ide.socket.on('project:membership:changed', data => {
  39. if (data.members) {
  40. listProjectMembers($scope.project._id)
  41. .then(({ members }) => {
  42. if (members) {
  43. $scope.$applyAsync(() => {
  44. $scope.project.members = members
  45. })
  46. }
  47. })
  48. .catch(() => {
  49. console.error('Error fetching members for project')
  50. })
  51. }
  52. if (data.invites) {
  53. listProjectInvites($scope.project._id)
  54. .then(({ invites }) => {
  55. if (invites) {
  56. $scope.$applyAsync(() => {
  57. $scope.project.invites = invites
  58. })
  59. }
  60. })
  61. .catch(() => {
  62. console.error('Error fetching invites for project')
  63. })
  64. }
  65. })
  66. }
  67. )