FileTreeManager.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. /* eslint-disable
  2. camelcase,
  3. node/handle-callback-err,
  4. max-len,
  5. no-dupe-class-members,
  6. no-return-assign,
  7. no-unused-vars,
  8. */
  9. // TODO: This file was created by bulk-decaffeinate.
  10. // Fix any style issues and re-enable lint.
  11. /*
  12. * decaffeinate suggestions:
  13. * DS101: Remove unnecessary use of Array.from
  14. * DS102: Remove unnecessary code created because of implicit returns
  15. * DS103: Rewrite code to no longer use __guard__
  16. * DS202: Simplify dynamic range loops
  17. * DS205: Consider reworking code to avoid use of IIFEs
  18. * DS207: Consider shorter variations of null checks
  19. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  20. */
  21. import './directives/fileEntity'
  22. import './directives/draggable'
  23. import './directives/droppable'
  24. import './controllers/FileTreeController'
  25. import './controllers/FileTreeEntityController'
  26. import './controllers/FileTreeFolderController'
  27. import './controllers/FileTreeRootFolderController'
  28. import '../../features/file-tree/controllers/file-tree-controller'
  29. let FileTreeManager
  30. export default FileTreeManager = class FileTreeManager {
  31. constructor(ide, $scope) {
  32. this.ide = ide
  33. this.$scope = $scope
  34. this.$scope.$on('project:joined', () => {
  35. this.loadRootFolder()
  36. this.loadDeletedDocs()
  37. return this.$scope.$emit('file-tree:initialized')
  38. })
  39. this.$scope.$on('entities:multiSelected', (_event, data) => {
  40. this.$scope.$apply(() => {
  41. this.$scope.multiSelectedCount = data.count
  42. })
  43. })
  44. this.$scope.$watch('rootFolder', rootFolder => {
  45. if (rootFolder != null) {
  46. return this.recalculateDocList()
  47. }
  48. })
  49. this._bindToSocketEvents()
  50. this.$scope.multiSelectedCount = 0
  51. $(document).on('click', () => {
  52. this.clearMultiSelectedEntities()
  53. return this.$scope.$digest()
  54. })
  55. }
  56. _bindToSocketEvents() {
  57. this.ide.socket.on('reciveNewDoc', (parent_folder_id, doc) => {
  58. const parent_folder =
  59. this.findEntityById(parent_folder_id) || this.$scope.rootFolder
  60. return this.$scope.$apply(() => {
  61. parent_folder.children.push({
  62. name: doc.name,
  63. id: doc._id,
  64. type: 'doc'
  65. })
  66. return this.recalculateDocList()
  67. })
  68. })
  69. this.ide.socket.on(
  70. 'reciveNewFile',
  71. (parent_folder_id, file, source, linkedFileData) => {
  72. const parent_folder =
  73. this.findEntityById(parent_folder_id) || this.$scope.rootFolder
  74. return this.$scope.$apply(() => {
  75. parent_folder.children.push({
  76. name: file.name,
  77. id: file._id,
  78. type: 'file',
  79. linkedFileData,
  80. created: file.created
  81. })
  82. return this.recalculateDocList()
  83. })
  84. }
  85. )
  86. this.ide.socket.on('reciveNewFolder', (parent_folder_id, folder) => {
  87. const parent_folder =
  88. this.findEntityById(parent_folder_id) || this.$scope.rootFolder
  89. return this.$scope.$apply(() => {
  90. parent_folder.children.push({
  91. name: folder.name,
  92. id: folder._id,
  93. type: 'folder',
  94. children: []
  95. })
  96. return this.recalculateDocList()
  97. })
  98. })
  99. this.ide.socket.on('reciveEntityRename', (entity_id, name) => {
  100. const entity = this.findEntityById(entity_id)
  101. if (entity == null) {
  102. return
  103. }
  104. return this.$scope.$apply(() => {
  105. entity.name = name
  106. return this.recalculateDocList()
  107. })
  108. })
  109. this.ide.socket.on('removeEntity', entity_id => {
  110. const entity = this.findEntityById(entity_id)
  111. if (entity == null) {
  112. return
  113. }
  114. this.$scope.$apply(() => {
  115. this._deleteEntityFromScope(entity)
  116. return this.recalculateDocList()
  117. })
  118. return this.$scope.$broadcast('entity:deleted', entity)
  119. })
  120. return this.ide.socket.on('reciveEntityMove', (entity_id, folder_id) => {
  121. const entity = this.findEntityById(entity_id)
  122. const folder = this.findEntityById(folder_id)
  123. return this.$scope.$apply(() => {
  124. this._moveEntityInScope(entity, folder)
  125. return this.recalculateDocList()
  126. })
  127. })
  128. }
  129. selectEntity(entity) {
  130. this.selected_entity_id = entity.id // For reselecting after a reconnect
  131. this.ide.fileTreeManager.forEachEntity(entity => (entity.selected = false))
  132. return (entity.selected = true)
  133. }
  134. toggleMultiSelectEntity(entity) {
  135. entity.multiSelected = !entity.multiSelected
  136. return (this.$scope.multiSelectedCount = this.multiSelectedCount())
  137. }
  138. multiSelectedCount() {
  139. let count = 0
  140. this.forEachEntity(function(entity) {
  141. if (entity.multiSelected) {
  142. return count++
  143. }
  144. })
  145. return count
  146. }
  147. getMultiSelectedEntities() {
  148. const entities = []
  149. this.forEachEntity(function(e) {
  150. if (e.multiSelected) {
  151. return entities.push(e)
  152. }
  153. })
  154. return entities
  155. }
  156. getFullCount() {
  157. const entities = []
  158. this.forEachEntity(function(e) {
  159. if (!e.deleted) entities.push(e)
  160. })
  161. return entities.length
  162. }
  163. getMultiSelectedEntityChildNodes() {
  164. // use pathnames with a leading slash to avoid
  165. // problems with reserved Object properties
  166. const entities = this.getMultiSelectedEntities()
  167. const paths = {}
  168. for (var entity of Array.from(entities)) {
  169. paths['/' + this.getEntityPath(entity)] = entity
  170. }
  171. const prefixes = {}
  172. for (var path in paths) {
  173. entity = paths[path]
  174. const parts = path.split('/')
  175. if (parts.length <= 2) {
  176. continue
  177. } else {
  178. // Record prefixes a/b/c.tex -> 'a' and 'a/b'
  179. for (
  180. let i = 1, end = parts.length - 1, asc = end >= 1;
  181. asc ? i <= end : i >= end;
  182. asc ? i++ : i--
  183. ) {
  184. prefixes['/' + parts.slice(0, i).join('/')] = true
  185. }
  186. }
  187. }
  188. const child_entities = []
  189. for (path in paths) {
  190. // If the path is in the prefixes, then it's a parent folder and
  191. // should be ignore
  192. entity = paths[path]
  193. if (prefixes[path] == null) {
  194. child_entities.push(entity)
  195. }
  196. }
  197. return child_entities
  198. }
  199. clearMultiSelectedEntities() {
  200. if (this.$scope.multiSelectedCount === 0) {
  201. return
  202. } // Be efficient, this is called a lot on 'click'
  203. this.forEachEntity(entity => (entity.multiSelected = false))
  204. return (this.$scope.multiSelectedCount = 0)
  205. }
  206. multiSelectSelectedEntity() {
  207. const entity = this.findSelectedEntity()
  208. if (entity) {
  209. entity.multiSelected = true
  210. }
  211. this.$scope.multiSelectedCount = this.multiSelectedCount()
  212. }
  213. existsInFolder(folder_id, name) {
  214. const folder = this.findEntityById(folder_id)
  215. if (folder == null) {
  216. return false
  217. }
  218. const entity = this._findEntityByPathInFolder(folder, name)
  219. return entity != null
  220. }
  221. findSelectedEntity() {
  222. let selected = null
  223. this.forEachEntity(function(entity) {
  224. if (entity.selected) {
  225. return (selected = entity)
  226. }
  227. })
  228. return selected
  229. }
  230. findEntityById(id, options) {
  231. if (options == null) {
  232. options = {}
  233. }
  234. if (this.$scope.rootFolder.id === id) {
  235. return this.$scope.rootFolder
  236. }
  237. let entity = this._findEntityByIdInFolder(this.$scope.rootFolder, id)
  238. if (entity != null) {
  239. return entity
  240. }
  241. if (options.includeDeleted) {
  242. for (entity of Array.from(this.$scope.deletedDocs)) {
  243. if (entity.id === id) {
  244. return entity
  245. }
  246. }
  247. }
  248. return null
  249. }
  250. _findEntityByIdInFolder(folder, id) {
  251. for (let entity of Array.from(folder.children || [])) {
  252. if (entity.id === id) {
  253. return entity
  254. } else if (entity.children != null) {
  255. const result = this._findEntityByIdInFolder(entity, id)
  256. if (result != null) {
  257. return result
  258. }
  259. }
  260. }
  261. return null
  262. }
  263. findEntityByPath(path) {
  264. return this._findEntityByPathInFolder(this.$scope.rootFolder, path)
  265. }
  266. _findEntityByPathInFolder(folder, path) {
  267. if (path == null || folder == null) {
  268. return null
  269. }
  270. if (path === '') {
  271. return folder
  272. }
  273. const parts = path.split('/')
  274. const name = parts.shift()
  275. const rest = parts.join('/')
  276. if (name === '.') {
  277. return this._findEntityByPathInFolder(folder, rest)
  278. }
  279. for (let entity of Array.from(folder.children)) {
  280. if (entity.name === name) {
  281. if (rest === '') {
  282. return entity
  283. } else if (entity.type === 'folder') {
  284. return this._findEntityByPathInFolder(entity, rest)
  285. }
  286. }
  287. }
  288. return null
  289. }
  290. forEachEntity(callback) {
  291. if (callback == null) {
  292. callback = function(entity, parent_folder, path) {}
  293. }
  294. this._forEachEntityInFolder(this.$scope.rootFolder, null, callback)
  295. return (() => {
  296. const result = []
  297. for (let entity of Array.from(this.$scope.deletedDocs || [])) {
  298. result.push(callback(entity))
  299. }
  300. return result
  301. })()
  302. }
  303. _forEachEntityInFolder(folder, path, callback) {
  304. return (() => {
  305. const result = []
  306. for (let entity of Array.from(folder.children || [])) {
  307. var childPath
  308. if (path != null) {
  309. childPath = path + '/' + entity.name
  310. } else {
  311. childPath = entity.name
  312. }
  313. callback(entity, folder, childPath)
  314. if (entity.children != null) {
  315. result.push(this._forEachEntityInFolder(entity, childPath, callback))
  316. } else {
  317. result.push(undefined)
  318. }
  319. }
  320. return result
  321. })()
  322. }
  323. getEntityPath(entity) {
  324. return this._getEntityPathInFolder(this.$scope.rootFolder, entity)
  325. }
  326. _getEntityPathInFolder(folder, entity) {
  327. for (let child of Array.from(folder.children || [])) {
  328. if (child === entity) {
  329. return entity.name
  330. } else if (child.type === 'folder') {
  331. const path = this._getEntityPathInFolder(child, entity)
  332. if (path != null) {
  333. return child.name + '/' + path
  334. }
  335. }
  336. }
  337. return null
  338. }
  339. getRootDocDirname() {
  340. const rootDoc = this.findEntityById(this.$scope.project.rootDoc_id)
  341. if (rootDoc == null) {
  342. return
  343. }
  344. return this._getEntityDirname(rootDoc)
  345. }
  346. _getEntityDirname(entity) {
  347. const path = this.getEntityPath(entity)
  348. if (path == null) {
  349. return
  350. }
  351. return path
  352. .split('/')
  353. .slice(0, -1)
  354. .join('/')
  355. }
  356. _findParentFolder(entity) {
  357. const dirname = this._getEntityDirname(entity)
  358. if (dirname == null) {
  359. return
  360. }
  361. return this.findEntityByPath(dirname)
  362. }
  363. loadRootFolder() {
  364. return (this.$scope.rootFolder = this._parseFolder(
  365. __guard__(
  366. this.$scope != null ? this.$scope.project : undefined,
  367. x => x.rootFolder[0]
  368. )
  369. ))
  370. }
  371. _parseFolder(rawFolder) {
  372. const folder = {
  373. name: rawFolder.name,
  374. id: rawFolder._id,
  375. type: 'folder',
  376. children: [],
  377. selected: rawFolder._id === this.selected_entity_id
  378. }
  379. for (let doc of Array.from(rawFolder.docs || [])) {
  380. folder.children.push({
  381. name: doc.name,
  382. id: doc._id,
  383. type: 'doc',
  384. selected: doc._id === this.selected_entity_id
  385. })
  386. }
  387. for (let file of Array.from(rawFolder.fileRefs || [])) {
  388. folder.children.push({
  389. name: file.name,
  390. id: file._id,
  391. type: 'file',
  392. selected: file._id === this.selected_entity_id,
  393. linkedFileData: file.linkedFileData,
  394. created: file.created
  395. })
  396. }
  397. for (let childFolder of Array.from(rawFolder.folders || [])) {
  398. folder.children.push(this._parseFolder(childFolder))
  399. }
  400. return folder
  401. }
  402. loadDeletedDocs() {
  403. this.$scope.deletedDocs = []
  404. return Array.from(this.$scope.project.deletedDocs || []).map(doc =>
  405. this.$scope.deletedDocs.push({
  406. name: doc.name,
  407. id: doc._id,
  408. type: 'doc',
  409. deleted: true
  410. })
  411. )
  412. }
  413. recalculateDocList() {
  414. this.$scope.docs = []
  415. this.forEachEntity((entity, parentFolder, path) => {
  416. if (entity.type === 'doc' && !entity.deleted) {
  417. return this.$scope.docs.push({
  418. doc: entity,
  419. path
  420. })
  421. }
  422. })
  423. // Keep list ordered by folders, then name
  424. return this.$scope.docs.sort(function(a, b) {
  425. const aDepth = (a.path.match(/\//g) || []).length
  426. const bDepth = (b.path.match(/\//g) || []).length
  427. if (aDepth - bDepth !== 0) {
  428. return -(aDepth - bDepth) // Deeper path == folder first
  429. } else if (a.path < b.path) {
  430. return -1
  431. } else if (a.path > b.path) {
  432. return 1
  433. } else {
  434. return 0
  435. }
  436. })
  437. }
  438. getEntityPath(entity) {
  439. return this._getEntityPathInFolder(this.$scope.rootFolder, entity)
  440. }
  441. _getEntityPathInFolder(folder, entity) {
  442. for (let child of Array.from(folder.children || [])) {
  443. if (child === entity) {
  444. return entity.name
  445. } else if (child.type === 'folder') {
  446. const path = this._getEntityPathInFolder(child, entity)
  447. if (path != null) {
  448. return child.name + '/' + path
  449. }
  450. }
  451. }
  452. return null
  453. }
  454. getCurrentFolder() {
  455. // Return the root folder if nothing is selected
  456. return (
  457. this._getCurrentFolder(this.$scope.rootFolder) || this.$scope.rootFolder
  458. )
  459. }
  460. _getCurrentFolder(startFolder) {
  461. if (startFolder == null) {
  462. startFolder = this.$scope.rootFolder
  463. }
  464. for (let entity of Array.from(startFolder.children || [])) {
  465. // The 'current' folder is either the one selected, or
  466. // the one containing the selected doc/file
  467. if (entity.selected) {
  468. if (entity.type === 'folder') {
  469. return entity
  470. } else {
  471. return startFolder
  472. }
  473. }
  474. if (entity.type === 'folder') {
  475. const result = this._getCurrentFolder(entity)
  476. if (result != null) {
  477. return result
  478. }
  479. }
  480. }
  481. return null
  482. }
  483. projectContainsFolder() {
  484. for (let entity of Array.from(this.$scope.rootFolder.children)) {
  485. if (entity.type === 'folder') {
  486. return true
  487. }
  488. }
  489. return false
  490. }
  491. existsInThisFolder(folder, name) {
  492. for (let entity of Array.from(
  493. (folder != null ? folder.children : undefined) || []
  494. )) {
  495. if (entity.name === name) {
  496. return true
  497. }
  498. }
  499. return false
  500. }
  501. nameExistsError(message) {
  502. if (message == null) {
  503. message = 'already exists'
  504. }
  505. const nameExists = this.ide.$q.defer()
  506. nameExists.reject({ data: message })
  507. return nameExists.promise
  508. }
  509. createDoc(name, parent_folder) {
  510. if (window.showReactFileTree) {
  511. const promise = new Promise((resolve, reject) => {
  512. this.$scope.FileTreeReactBridgePromise = {
  513. resolve,
  514. reject
  515. }
  516. })
  517. window.dispatchEvent(
  518. new CustomEvent('FileTreeReactBridge.createDoc', {
  519. detail: {
  520. name
  521. }
  522. })
  523. )
  524. return promise
  525. }
  526. // check if a doc/file/folder already exists with this name
  527. if (parent_folder == null) {
  528. parent_folder = this.getCurrentFolder()
  529. }
  530. if (this.existsInThisFolder(parent_folder, name)) {
  531. return this.nameExistsError()
  532. }
  533. // We'll wait for the socket.io notification to actually
  534. // add the doc for us.
  535. return this.ide.$http.post(`/project/${this.ide.project_id}/doc`, {
  536. name,
  537. parent_folder_id: parent_folder != null ? parent_folder.id : undefined,
  538. _csrf: window.csrfToken
  539. })
  540. }
  541. createFolder(name, parent_folder) {
  542. // check if a doc/file/folder already exists with this name
  543. if (parent_folder == null) {
  544. parent_folder = this.getCurrentFolder()
  545. }
  546. if (this.existsInThisFolder(parent_folder, name)) {
  547. return this.nameExistsError()
  548. }
  549. // We'll wait for the socket.io notification to actually
  550. // add the folder for us.
  551. return this.ide.$http.post(`/project/${this.ide.project_id}/folder`, {
  552. name,
  553. parent_folder_id: parent_folder != null ? parent_folder.id : undefined,
  554. _csrf: window.csrfToken
  555. })
  556. }
  557. createLinkedFile(name, parent_folder, provider, data) {
  558. if (window.showReactFileTree) {
  559. const promise = new Promise((resolve, reject) => {
  560. this.$scope.FileTreeReactBridgePromise = {
  561. resolve,
  562. reject
  563. }
  564. })
  565. window.dispatchEvent(
  566. new CustomEvent('FileTreeReactBridge.createLinkedFile', {
  567. detail: {
  568. name,
  569. provider,
  570. data
  571. }
  572. })
  573. )
  574. return promise
  575. }
  576. // check if a doc/file/folder already exists with this name
  577. if (parent_folder == null) {
  578. parent_folder = this.getCurrentFolder()
  579. }
  580. if (this.existsInThisFolder(parent_folder, name)) {
  581. return this.nameExistsError()
  582. }
  583. // We'll wait for the socket.io notification to actually
  584. // add the file for us.
  585. return this.ide.$http.post(
  586. `/project/${this.ide.project_id}/linked_file`,
  587. {
  588. name,
  589. parent_folder_id: parent_folder != null ? parent_folder.id : undefined,
  590. provider,
  591. data,
  592. _csrf: window.csrfToken
  593. },
  594. {
  595. disableAutoLoginRedirect: true
  596. }
  597. )
  598. }
  599. refreshLinkedFile(file) {
  600. const parent_folder = this._findParentFolder(file)
  601. const provider =
  602. file.linkedFileData != null ? file.linkedFileData.provider : undefined
  603. if (provider == null) {
  604. console.warn(`>> no provider for ${file.name}`, file)
  605. return
  606. }
  607. return this.ide.$http.post(
  608. `/project/${this.ide.project_id}/linked_file/${file.id}/refresh`,
  609. {
  610. _csrf: window.csrfToken
  611. },
  612. {
  613. disableAutoLoginRedirect: true
  614. }
  615. )
  616. }
  617. renameEntity(entity, name, callback) {
  618. if (callback == null) {
  619. callback = function(error) {}
  620. }
  621. if (entity.name === name) {
  622. return
  623. }
  624. if (name.length >= 150) {
  625. return
  626. }
  627. // check if a doc/file/folder already exists with this name
  628. const parent_folder = this.getCurrentFolder()
  629. if (this.existsInThisFolder(parent_folder, name)) {
  630. return this.nameExistsError()
  631. }
  632. entity.renamingToName = name
  633. return this.ide.$http
  634. .post(
  635. `/project/${this.ide.project_id}/${entity.type}/${entity.id}/rename`,
  636. {
  637. name,
  638. _csrf: window.csrfToken
  639. }
  640. )
  641. .then(() => (entity.name = name))
  642. .finally(() => (entity.renamingToName = null))
  643. }
  644. deleteEntity(entity, callback) {
  645. // We'll wait for the socket.io notification to
  646. // delete from scope.
  647. if (callback == null) {
  648. callback = function(error) {}
  649. }
  650. return this.ide.queuedHttp({
  651. method: 'DELETE',
  652. url: `/project/${this.ide.project_id}/${entity.type}/${entity.id}`,
  653. headers: {
  654. 'X-Csrf-Token': window.csrfToken
  655. }
  656. })
  657. }
  658. moveEntity(entity, parent_folder) {
  659. // Abort move if the folder being moved (entity) has the parent_folder as child
  660. // since that would break the tree structure.
  661. if (this._isChildFolder(entity, parent_folder)) {
  662. return
  663. }
  664. // check if a doc/file/folder already exists with this name
  665. if (this.existsInThisFolder(parent_folder, entity.name)) {
  666. throw new Error('file exists in this location')
  667. }
  668. // Wait for the http response before doing the move
  669. this.ide.queuedHttp
  670. .post(
  671. `/project/${this.ide.project_id}/${entity.type}/${entity.id}/move`,
  672. {
  673. folder_id: parent_folder.id,
  674. _csrf: window.csrfToken
  675. }
  676. )
  677. .then(() => {
  678. this._moveEntityInScope(entity, parent_folder)
  679. })
  680. }
  681. _isChildFolder(parent_folder, child_folder) {
  682. const parent_path = this.getEntityPath(parent_folder) || '' // null if root folder
  683. const child_path = this.getEntityPath(child_folder) || '' // null if root folder
  684. // is parent path the beginning of child path?
  685. return child_path.slice(0, parent_path.length) === parent_path
  686. }
  687. _deleteEntityFromScope(entity, options) {
  688. if (options == null) {
  689. options = { moveToDeleted: true }
  690. }
  691. if (entity == null) {
  692. return
  693. }
  694. let parent_folder = null
  695. this.forEachEntity(function(possible_entity, folder) {
  696. if (possible_entity === entity) {
  697. return (parent_folder = folder)
  698. }
  699. })
  700. if (parent_folder != null) {
  701. const index = parent_folder.children.indexOf(entity)
  702. if (index > -1) {
  703. parent_folder.children.splice(index, 1)
  704. }
  705. }
  706. if (entity.type !== 'folder' && entity.selected) {
  707. this.$scope.ui.view = null
  708. }
  709. if (entity.type === 'doc' && options.moveToDeleted) {
  710. entity.deleted = true
  711. return this.$scope.deletedDocs.push(entity)
  712. }
  713. }
  714. _moveEntityInScope(entity, parent_folder) {
  715. if (Array.from(parent_folder.children).includes(entity)) {
  716. return
  717. }
  718. this._deleteEntityFromScope(entity, { moveToDeleted: false })
  719. return parent_folder.children.push(entity)
  720. }
  721. }
  722. function __guard__(value, transform) {
  723. return typeof value !== 'undefined' && value !== null
  724. ? transform(value)
  725. : undefined
  726. }