Merge branch 'master' into 13765-information-inside-details-panel
[arvados-workbench2.git] / src / services / project-service / project-service.ts
index d454a7b612e7db22196eaa55f07698c0e4ad0d61..9ce9e2131446f8ba28c7e3ecb8814f36ca28e1f1 100644 (file)
@@ -2,57 +2,35 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import { serverApi } from "../../common/api/server-api";
-import { Dispatch } from "redux";
-import actions from "../../store/project/project-action";
-import { Project } from "../../models/project";
-import UrlBuilder from "../../common/api/url-builder";
-import FilterBuilder, { FilterField } from "../../common/api/filter-builder";
+import GroupsService, { ContentsArguments } from "../groups-service/groups-service";
+import { ProjectResource } from "../../models/project";
+import { GroupClass } from "../../models/group";
+import { ListArguments } from "../../common/api/common-resource-service";
+import FilterBuilder from "../../common/api/filter-builder";
 
-interface GroupsResponse {
-    offset: number;
-    limit: number;
-    items: Array<{
-        href: string;
-        kind: string;
-        etag: string;
-        uuid: string;
-        owner_uuid: string;
-        created_at: string;
-        modified_by_client_uuid: string;
-        modified_by_user_uuid: string;
-        modified_at: string;
-        name: string;
-        group_class: string;
-        description: string;
-        writable_by: string[];
-        delete_at: string;
-        trash_at: string;
-        is_trashed: boolean;
-    }>;
-}
+export default class ProjectService extends GroupsService<ProjectResource> {
 
-export default class ProjectService {
-    public getProjectList = (parentUuid?: string) => (dispatch: Dispatch): Promise<Project[]> => {
-        dispatch(actions.PROJECTS_REQUEST());
+    create(data: Partial<ProjectResource>) {
+        const projectData = { ...data, groupClass: GroupClass.Project };
+        return super.create(projectData);
+    }
 
-        const ub = new UrlBuilder('/groups');
-        const fb = new FilterBuilder();
-        fb.addEqual(FilterField.OWNER_UUID, parentUuid);
-        const url = ub.addParam('filters', fb.get()).get();
-
-        return serverApi.get<GroupsResponse>(url).then(groups => {
-            const projects = groups.data.items.map(g => ({
-                name: g.name,
-                createdAt: g.created_at,
-                modifiedAt: g.modified_at,
-                href: g.href,
-                uuid: g.uuid,
-                ownerUuid: g.owner_uuid,
-                kind: g.kind
-            } as Project));
-            dispatch(actions.PROJECTS_SUCCESS({projects, parentItemId: parentUuid}));
-            return projects;
+    list(args: ListArguments = {}) {
+        return super.list({
+            ...args,
+            filters: this.addProjectFilter(args.filters)
         });
-    };
-}
+    }
+
+    private addProjectFilter(filters?: FilterBuilder) {
+        return FilterBuilder
+            .create()
+            .concat(filters
+                ? filters
+                : FilterBuilder.create())
+            .concat(FilterBuilder
+                .create<ProjectResource>()
+                .addEqual("groupClass", GroupClass.Project));
+    }
+
+}
\ No newline at end of file