16067: Adds remaining collection resource read-only fields.
[arvados-workbench2.git] / src / services / collection-service / collection-service.ts
index f7e25541fd06bf1702abfb3513ade63359e3d6d7..77f5bf3bc605b76a6a37053e9ff1b540925319a4 100644 (file)
@@ -7,25 +7,30 @@ import { AxiosInstance } from "axios";
 import { CollectionFile, CollectionDirectory } from "~/models/collection-file";
 import { WebDAV } from "~/common/webdav";
 import { AuthService } from "../auth-service/auth-service";
-import { mapTreeValues } from "~/models/tree";
-import { parseFilesResponse } from "./collection-service-files-response";
-import { fileToArrayBuffer } from "~/common/file";
+import { extractFilesData } from "./collection-service-files-response";
 import { TrashableResourceService } from "~/services/common-service/trashable-resource-service";
 import { ApiActions } from "~/services/api/api-actions";
-import { snakeCase } from 'lodash';
 
 export type UploadProgress = (fileId: number, loaded: number, total: number, currentTime: number) => void;
 
 export class CollectionService extends TrashableResourceService<CollectionResource> {
     constructor(serverApi: AxiosInstance, private webdavClient: WebDAV, private authService: AuthService, actions: ApiActions) {
-        super(serverApi, "collections", actions);
+        super(serverApi, "collections", actions, [
+            'fileCount',
+            'fileSizeTotal',
+            'replicationConfirmed',
+            'replicationConfirmedAt',
+            'storageClassesConfirmed',
+            'storageClassesConfirmedAt',
+            'unsignedManifestText',
+            'version',
+        ]);
     }
 
     async files(uuid: string) {
         const request = await this.webdavClient.propfind(`c=${uuid}`);
         if (request.responseXML != null) {
-            const filesTree = parseFilesResponse(request.responseXML);
-            return mapTreeValues(this.extendFileURL)(filesTree);
+            return extractFilesData(request.responseXML);
         }
         return Promise.reject();
     }
@@ -55,7 +60,7 @@ export class CollectionService extends TrashableResourceService<CollectionResour
         );
     }
 
-    private extendFileURL = (file: CollectionDirectory | CollectionFile) => {
+    extendFileURL = (file: CollectionDirectory | CollectionFile) => {
         const baseUrl = this.webdavClient.defaults.baseURL.endsWith('/')
             ? this.webdavClient.defaults.baseURL.slice(0, -1)
             : this.webdavClient.defaults.baseURL;
@@ -80,29 +85,6 @@ export class CollectionService extends TrashableResourceService<CollectionResour
                 onProgress(fileId, e.loaded, e.total, Date.now());
             }
         };
-        return this.webdavClient.upload(fileURL, '', [file], requestConfig);
-    }
-
-    update(uuid: string, data: Partial<CollectionResource>) {
-        if (uuid && data && data.properties) {
-            const { properties } = data;
-            const mappedData = {
-                ...TrashableResourceService.mapKeys(snakeCase)(data),
-                properties,
-            };
-            return TrashableResourceService
-                .defaultResponse(
-                    this.serverApi
-                        .put<CollectionResource>(this.resourceType + uuid, mappedData),
-                    this.actions,
-                    false
-                );
-        }
-        return TrashableResourceService
-            .defaultResponse(
-                this.serverApi
-                    .put<CollectionResource>(this.resourceType + uuid, data && TrashableResourceService.mapKeys(snakeCase)(data)),
-                this.actions
-            );
+        return this.webdavClient.upload(fileURL, [file], requestConfig);
     }
 }