file-tree-controller.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import App from '../../../base'
  2. import { react2angular } from 'react2angular'
  3. import FileTreeRoot from '../components/file-tree-root'
  4. App.controller('ReactFileTreeController', function(
  5. $scope,
  6. $timeout,
  7. ide,
  8. eventTracking
  9. ) {
  10. $scope.projectId = ide.project_id
  11. $scope.rootFolder = null
  12. $scope.rootDocId = null
  13. $scope.hasWritePermissions = false
  14. $scope.$on('project:joined', () => {
  15. $scope.rootFolder = $scope.project.rootFolder
  16. $scope.rootDocId = $scope.project.rootDoc_id
  17. $scope.$emit('file-tree:initialized')
  18. })
  19. $scope.$watch('permissions.write', hasWritePermissions => {
  20. $scope.hasWritePermissions = hasWritePermissions
  21. })
  22. $scope.$watch('editor.open_doc_id', openDocId => {
  23. window.dispatchEvent(
  24. new CustomEvent('editor.openDoc', { detail: openDocId })
  25. )
  26. })
  27. $scope.onInit = () => {
  28. // HACK: resize the vertical pane on init after a 0ms timeout. We do not
  29. // understand why this is necessary but without this the resized handle is
  30. // stuck at the bottom. The vertical resize will soon be migrated to React
  31. // so we accept to live with this hack for now.
  32. $timeout(() => {
  33. $scope.$emit('left-pane-resize-all')
  34. })
  35. }
  36. $scope.onSelect = selectedEntities => {
  37. if (selectedEntities.length === 1) {
  38. const selectedEntity = selectedEntities[0]
  39. $scope.$emit('entity:selected', {
  40. id: selectedEntity.entity._id,
  41. name: selectedEntity.entity.name,
  42. type: selectedEntity.type
  43. })
  44. // in the react implementation there is no such concept as "1
  45. // multi-selected entity" so here we pass a count of 0
  46. $scope.$emit('entities:multiSelected', { count: 0 })
  47. } else if (selectedEntities.length > 1) {
  48. $scope.$emit('entities:multiSelected', { count: selectedEntities.length })
  49. }
  50. }
  51. })
  52. App.component('fileTreeRoot', react2angular(FileTreeRoot))