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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. ['ide']
  12. )
  13. )
  14. export default App.controller(
  15. 'ReactShareProjectModalController',
  16. function ($scope, eventTracking, ide) {
  17. $scope.isAdmin = false
  18. $scope.show = false
  19. $scope.handleHide = () => {
  20. $scope.$applyAsync(() => {
  21. $scope.show = false
  22. })
  23. }
  24. $scope.openShareProjectModal = isAdmin => {
  25. eventTracking.sendMBOnce('ide-open-share-modal-once')
  26. $scope.$applyAsync(() => {
  27. $scope.isAdmin = isAdmin
  28. $scope.show = true
  29. })
  30. }
  31. /* tokens */
  32. ide.socket.on('project:tokens:changed', data => {
  33. if (data.tokens != null) {
  34. $scope.$applyAsync(() => {
  35. $scope.project.tokens = data.tokens
  36. })
  37. }
  38. })
  39. ide.socket.on('project:membership:changed', data => {
  40. if (data.members) {
  41. listProjectMembers($scope.project)
  42. .then(({ members }) => {
  43. if (members) {
  44. $scope.$applyAsync(() => {
  45. $scope.project.members = members
  46. })
  47. }
  48. })
  49. .catch(() => {
  50. console.error('Error fetching members for project')
  51. })
  52. }
  53. if (data.invites) {
  54. listProjectInvites($scope.project)
  55. .then(({ invites }) => {
  56. if (invites) {
  57. $scope.$applyAsync(() => {
  58. $scope.project.invites = invites
  59. })
  60. }
  61. })
  62. .catch(() => {
  63. console.error('Error fetching invites for project')
  64. })
  65. }
  66. })
  67. }
  68. )