15840: Project panel uses collection attributes for file count and size
[arvados-workbench2.git] / src / services / collection-service / collection-service-files-response.ts
index b8a7970d58d4310d8228b8d0c80fb04188614810..f3a2147e26c5810705282d7abd322845508ce66c 100644 (file)
@@ -2,16 +2,10 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { createCollectionFilesTree, CollectionDirectory, CollectionFile, CollectionFileType, createCollectionDirectory, createCollectionFile } from "../../models/collection-file";
+import { CollectionDirectory, CollectionFile, CollectionFileType, createCollectionDirectory, createCollectionFile } from "../../models/collection-file";
 import { getTagValue } from "~/common/xml";
 import { getNodeChildren, Tree, mapTree } from '~/models/tree';
 
-export const parseFilesResponse = (document: Document) => {
-    const files = extractFilesData(document);
-    const tree = createCollectionFilesTree(files);
-    return sortFilesTree(tree);
-};
-
 export const sortFilesTree = (tree: Tree<CollectionDirectory | CollectionFile>) => {
     return mapTree<CollectionDirectory | CollectionFile>(node => {
         const children = getNodeChildren(node.id)(tree);
@@ -26,7 +20,7 @@ export const sortFilesTree = (tree: Tree<CollectionDirectory | CollectionFile>)
 };
 
 export const extractFilesData = (document: Document) => {
-    const collectionUrlPrefix = /\/c=[0-9a-zA-Z\-]*/;
+    const collectionUrlPrefix = /\/c=([^\/]*)/;
     return Array
         .from(document.getElementsByTagName('D:response'))
         .slice(1) // omit first element which is collection itself
@@ -35,13 +29,20 @@ export const extractFilesData = (document: Document) => {
             const size = parseInt(getTagValue(element, 'D:getcontentlength', '0'), 10);
             const url = getTagValue(element, 'D:href', '');
             const nameSuffix = `/${name || ''}`;
+            const collectionUuidMatch = collectionUrlPrefix.exec(url);
+            const collectionUuid = collectionUuidMatch ? collectionUuidMatch.pop() : '';
             const directory = url
                 .replace(collectionUrlPrefix, '')
                 .replace(nameSuffix, '');
 
+
             const data = {
                 url,
-                id: `${directory}/${name}`,
+                id: [
+                    collectionUuid ? collectionUuid : '',
+                    directory ? '/' + directory.replace(/^\//, '') : '',
+                    '/' + name
+                ].join(''),
                 name,
                 path: directory,
             };
@@ -52,3 +53,6 @@ export const extractFilesData = (document: Document) => {
 
         });
 };
+
+export const getFileFullPath = ({ name, path }: CollectionFile | CollectionDirectory) =>
+    `${path}/${name}`;