2020-11-26 09:22:30 -05:00
|
|
|
import App from '../../../base'
|
|
|
|
import { react2angular } from 'react2angular'
|
2021-03-18 05:52:36 -04:00
|
|
|
import { cloneDeep } from 'lodash'
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
import FileTreeRoot from '../components/file-tree-root'
|
2021-05-12 06:31:18 -04:00
|
|
|
import { rootContext } from '../../../shared/context/root-context'
|
2020-11-26 09:22:30 -05:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
App.controller('ReactFileTreeController', function (
|
2020-11-26 09:22:30 -05:00
|
|
|
$scope,
|
|
|
|
$timeout,
|
2021-03-18 05:52:36 -04:00
|
|
|
ide
|
|
|
|
// eventTracking
|
2020-11-26 09:22:30 -05:00
|
|
|
) {
|
|
|
|
$scope.projectId = ide.project_id
|
|
|
|
$scope.rootFolder = null
|
|
|
|
$scope.rootDocId = null
|
|
|
|
$scope.hasWritePermissions = false
|
2021-01-14 08:57:33 -05:00
|
|
|
$scope.isConnected = true
|
2020-11-26 09:22:30 -05:00
|
|
|
|
|
|
|
$scope.$on('project:joined', () => {
|
|
|
|
$scope.rootFolder = $scope.project.rootFolder
|
|
|
|
$scope.rootDocId = $scope.project.rootDoc_id
|
|
|
|
$scope.$emit('file-tree:initialized')
|
|
|
|
})
|
|
|
|
|
|
|
|
$scope.$watch('permissions.write', hasWritePermissions => {
|
|
|
|
$scope.hasWritePermissions = hasWritePermissions
|
|
|
|
})
|
|
|
|
|
|
|
|
$scope.$watch('editor.open_doc_id', openDocId => {
|
|
|
|
window.dispatchEvent(
|
|
|
|
new CustomEvent('editor.openDoc', { detail: openDocId })
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-01-14 08:57:33 -05:00
|
|
|
// Set isConnected to true if:
|
|
|
|
// - connection state is 'ready', OR
|
|
|
|
// - connection state is 'waitingCountdown' and reconnection_countdown is null
|
|
|
|
// The added complexity is needed because in Firefox on page reload the
|
|
|
|
// connection state goes into 'waitingCountdown' before being hidden and we
|
|
|
|
// don't want to show a disconnect UI.
|
|
|
|
function updateIsConnected() {
|
|
|
|
const isReady = $scope.connection.state === 'ready'
|
|
|
|
const willStartCountdown =
|
|
|
|
$scope.connection.state === 'waitingCountdown' &&
|
|
|
|
$scope.connection.reconnection_countdown === null
|
|
|
|
$scope.isConnected = isReady || willStartCountdown
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.$watch('connection.state', updateIsConnected)
|
|
|
|
$scope.$watch('connection.reconnection_countdown', updateIsConnected)
|
|
|
|
|
2020-11-26 09:22:30 -05:00
|
|
|
$scope.onInit = () => {
|
|
|
|
// HACK: resize the vertical pane on init after a 0ms timeout. We do not
|
|
|
|
// understand why this is necessary but without this the resized handle is
|
|
|
|
// stuck at the bottom. The vertical resize will soon be migrated to React
|
|
|
|
// so we accept to live with this hack for now.
|
|
|
|
$timeout(() => {
|
|
|
|
$scope.$emit('left-pane-resize-all')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.onSelect = selectedEntities => {
|
|
|
|
if (selectedEntities.length === 1) {
|
|
|
|
const selectedEntity = selectedEntities[0]
|
2020-11-27 08:11:31 -05:00
|
|
|
const type =
|
|
|
|
selectedEntity.type === 'fileRef' ? 'file' : selectedEntity.type
|
2020-11-26 09:22:30 -05:00
|
|
|
$scope.$emit('entity:selected', {
|
2021-01-05 05:57:07 -05:00
|
|
|
...selectedEntity.entity,
|
2020-11-26 09:22:30 -05:00
|
|
|
id: selectedEntity.entity._id,
|
2021-04-27 03:52:58 -04:00
|
|
|
type,
|
2020-11-26 09:22:30 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
// in the react implementation there is no such concept as "1
|
|
|
|
// multi-selected entity" so here we pass a count of 0
|
|
|
|
$scope.$emit('entities:multiSelected', { count: 0 })
|
|
|
|
} else if (selectedEntities.length > 1) {
|
2020-12-15 05:23:54 -05:00
|
|
|
$scope.$emit('entities:multiSelected', {
|
2021-04-27 03:52:58 -04:00
|
|
|
count: selectedEntities.length,
|
2020-12-15 05:23:54 -05:00
|
|
|
})
|
2021-01-07 09:22:53 -05:00
|
|
|
} else {
|
|
|
|
$scope.$emit('entity:no-selection')
|
2020-11-26 09:22:30 -05:00
|
|
|
}
|
|
|
|
}
|
2021-03-18 05:52:36 -04:00
|
|
|
|
2021-03-24 06:06:56 -04:00
|
|
|
$scope.userHasFeature = feature => ide.$scope.user.features[feature]
|
2021-03-18 05:52:36 -04:00
|
|
|
|
|
|
|
$scope.$watch('permissions.write', hasWritePermissions => {
|
|
|
|
$scope.hasWritePermissions = hasWritePermissions
|
|
|
|
})
|
|
|
|
|
|
|
|
$scope.refProviders = ide.$scope.user.refProviders || {}
|
|
|
|
|
|
|
|
ide.$scope.$watch(
|
|
|
|
'user.refProviders',
|
|
|
|
refProviders => {
|
|
|
|
$scope.refProviders = cloneDeep(refProviders)
|
|
|
|
},
|
|
|
|
true
|
|
|
|
)
|
|
|
|
|
|
|
|
$scope.setRefProviderEnabled = provider => {
|
|
|
|
ide.$scope.$applyAsync(() => {
|
|
|
|
ide.$scope.user.refProviders[provider] = true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.setStartedFreeTrial = started => {
|
|
|
|
$scope.$applyAsync(() => {
|
|
|
|
$scope.startedFreeTrial = started
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.reindexReferences = () => {
|
|
|
|
ide.$scope.$emit('references:should-reindex', {})
|
|
|
|
}
|
2020-11-26 09:22:30 -05:00
|
|
|
})
|
|
|
|
|
2021-05-12 06:31:18 -04:00
|
|
|
App.component(
|
|
|
|
'fileTreeRoot',
|
|
|
|
react2angular(
|
|
|
|
rootContext.use(FileTreeRoot),
|
|
|
|
Object.keys(FileTreeRoot.propTypes)
|
|
|
|
)
|
|
|
|
)
|