Merge branch 'master' into 16848-token-handling-improvements
[arvados-workbench2.git] / src / services / workflow-service / workflow-service.ts
index 57ad5fa40fc61394f084dcd8ca778ea7d82aa4b0..e72599efc2b01f1800b2758fc7e00b8c01132edc 100644 (file)
@@ -6,9 +6,39 @@ import { AxiosInstance } from "axios";
 import { CommonResourceService } from "~/services/common-service/common-resource-service";
 import { WorkflowResource } from '~/models/workflow';
 import { ApiActions } from '~/services/api/api-actions';
+import { LinkService } from '~/services/link-service/link-service';
+import { FilterBuilder } from '~/services/api/filter-builder';
+import { LinkClass } from '~/models/link';
+import { OrderBuilder } from '~/services/api/order-builder';
 
 export class WorkflowService extends CommonResourceService<WorkflowResource> {
+
+    private linksService = new LinkService(this.serverApi, this.actions);
+
     constructor(serverApi: AxiosInstance, actions: ApiActions) {
         super(serverApi, "workflows", actions);
     }
+
+    async presets(workflowUuid: string) {
+
+        const { items: presetLinks } = await this.linksService.list({
+            filters: new FilterBuilder()
+                .addEqual('tail_uuid', workflowUuid)
+                .addEqual('link_class', LinkClass.PRESET)
+                .getFilters()
+        });
+
+        const presetUuids = presetLinks.map(link => link.headUuid);
+
+        return this.list({
+            filters: new FilterBuilder()
+                .addIn('uuid', presetUuids)
+                .getFilters(),
+            order: new OrderBuilder<WorkflowResource>()
+                .addAsc('name')
+                .getOrder(),
+        });
+
+    }
+
 }