[ARVADOS-WORKBENCH2] created: 1.2.0-530-ga4e2c41

Git user git at public.curoverse.com
Thu Oct 4 06:33:16 EDT 2018


        at  a4e2c41eb689b86b04a88ea2971282ce14de2b88 (commit)


commit a4e2c41eb689b86b04a88ea2971282ce14de2b88
Author: Janicki Artur <artur.janicki at contractors.roche.com>
Date:   Thu Oct 4 12:32:58 2018 +0200

    add and change methods for services, modify collection form
    
    Feature #14278
    
    Arvados-DCO-1.1-Signed-off-by: Janicki Artur <artur.janicki at contractors.roche.com>

diff --git a/src/services/collection-service/collection-service.ts b/src/services/collection-service/collection-service.ts
index 28de14f..eb48e9d 100644
--- a/src/services/collection-service/collection-service.ts
+++ b/src/services/collection-service/collection-service.ts
@@ -12,6 +12,7 @@ import { parseFilesResponse } from "./collection-service-files-response";
 import { fileToArrayBuffer } from "~/common/file";
 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;
 
@@ -68,4 +69,30 @@ export class CollectionService extends TrashableResourceService<CollectionResour
         return this.webdavClient.put(fileURL, fileContent, requestConfig);
 
     }
+
+    // ToDo: add get method
+
+    update(uuid: string, data: Partial<CollectionResource>) {
+        if (uuid && data) {
+            const { properties } = data;
+            if (properties) {
+                const mappedData = {
+                    ...TrashableResourceService.mapKeys(snakeCase)(data),
+                    properties,
+                };
+                return TrashableResourceService
+                    .defaultResponse(
+                        this.serverApi
+                            .put<CollectionResource>(this.resourceType + uuid, mappedData),
+                        this.actions
+                    );
+            }
+        }
+        return TrashableResourceService
+            .defaultResponse(
+                this.serverApi
+                    .put<CollectionResource>(this.resourceType + uuid, data && TrashableResourceService.mapKeys(snakeCase)(data)),
+                this.actions
+            );
+    }
 }
diff --git a/src/services/common-service/common-resource-service.ts b/src/services/common-service/common-resource-service.ts
index 0c99e7d..90677b0 100644
--- a/src/services/common-service/common-resource-service.ts
+++ b/src/services/common-service/common-resource-service.ts
@@ -79,6 +79,18 @@ export class CommonResourceService<T extends Resource> {
             });
     }
 
+    static customResponse<R>(promise: AxiosPromise<R>, actions: ApiActions): Promise<R> {
+        const reqId = uuid();
+        actions.progressFn(reqId, true);
+        return promise
+            .then(data => {
+                actions.progressFn(reqId, false);
+                return data;
+            })
+            .then((response: { data: any }) => response.data);
+    }
+
+
     protected serverApi: AxiosInstance;
     protected resourceType: string;
     protected actions: ApiActions;
diff --git a/src/services/groups-service/groups-service.ts b/src/services/groups-service/groups-service.ts
index e705b6e..f4443e8 100644
--- a/src/services/groups-service/groups-service.ts
+++ b/src/services/groups-service/groups-service.ts
@@ -8,10 +8,11 @@ import { AxiosInstance } from "axios";
 import { CollectionResource } from "~/models/collection";
 import { ProjectResource } from "~/models/project";
 import { ProcessResource } from "~/models/process";
-import { TrashableResource } from "~/models/resource";
+import { TrashableResource, ResourceKind } from '~/models/resource';
 import { TrashableResourceService } from "~/services/common-service/trashable-resource-service";
 import { ApiActions } from "~/services/api/api-actions";
 import { GroupResource } from "~/models/group";
+import { snakeCase } from 'lodash';
 
 export interface ContentsArguments {
     limit?: number;
@@ -37,20 +38,36 @@ export class GroupsService<T extends GroupResource = GroupResource> extends Tras
         super(serverApi, "groups", actions);
     }
 
-    contents(uuid: string, args: ContentsArguments = {}): Promise<ListResults<GroupContentsResource>> {
+    async contents(uuid: string, args: ContentsArguments = {}): Promise<ListResults<GroupContentsResource>> {
         const { filters, order, ...other } = args;
         const params = {
             ...other,
             filters: filters ? `[${filters}]` : undefined,
             order: order ? order : undefined
         };
-        return CommonResourceService.defaultResponse(
+
+        const response = await CommonResourceService.customResponse(
             this.serverApi
                 .get(this.resourceType + `${uuid}/contents`, {
                     params: CommonResourceService.mapKeys(_.snakeCase)(params)
                 }),
             this.actions
         );
+
+        const { items, ...res } = response;
+        const mappedItems = items.map((item: any) => {
+            if (item.kind === ResourceKind.COLLECTION) {
+                const { properties } = item;
+                return {
+                    ...TrashableResourceService.mapKeys(snakeCase)(item),
+                    properties,
+                };
+            } else {
+                return TrashableResourceService.mapKeys(item);
+            }
+        });
+        const mappedResponse = TrashableResourceService.mapResponseKeys(res);
+        return  { ...mappedResponse, items: mappedItems };
     }
 
     shared(params: SharedArguments = {}): Promise<ListResults<GroupContentsResource>> {
diff --git a/src/views/collection-panel/collection-panel.tsx b/src/views/collection-panel/collection-panel.tsx
index 07eb7d9..379a2eb 100644
--- a/src/views/collection-panel/collection-panel.tsx
+++ b/src/views/collection-panel/collection-panel.tsx
@@ -113,13 +113,16 @@ export const CollectionPanel = withStyles(styles)(
                             <CardHeader title="Properties" />
                             <CardContent>
                                 <Grid container direction="column">
-                                    <Grid item xs={12}><CollectionTagForm /></Grid>
+                                    <Grid item xs={12}>
+                                        <CollectionTagForm />
+                                    </Grid>
                                     <Grid item xs={12}>
                                         {
-                                            Object.keys(item.properties).map(key => {
-                                                return <Chip key={key} className={classes.tag}
-                                                    onDelete={this.handleDelete(key)}
-                                                    label={`${key}: ${item.properties[key]}`} />;
+                                            Object.keys(item.properties).map(k => {
+                                                console.log('k: ', k);
+                                                return <Chip key={k} className={classes.tag}
+                                                    onDelete={this.handleDelete(k)}
+                                                    label={`${k}: ${item.properties[k]}`} />;
                                             })
                                         }
                                     </Grid>
diff --git a/src/views/collection-panel/collection-tag-form.tsx b/src/views/collection-panel/collection-tag-form.tsx
index 83ad0ca..75099f2 100644
--- a/src/views/collection-panel/collection-tag-form.tsx
+++ b/src/views/collection-panel/collection-tag-form.tsx
@@ -6,25 +6,37 @@ import * as React from 'react';
 import { reduxForm, Field, reset } from 'redux-form';
 import { compose, Dispatch } from 'redux';
 import { ArvadosTheme } from '~/common/custom-theme';
-import { StyleRulesCallback, withStyles, WithStyles, Button, CircularProgress, Grid } from '@material-ui/core';
+import { StyleRulesCallback, withStyles, WithStyles, Button, CircularProgress, Grid, Typography } from '@material-ui/core';
 import { TagProperty } from '~/models/tag';
 import { TextField } from '~/components/text-field/text-field';
 import { createCollectionTag, COLLECTION_TAG_FORM_NAME } from '~/store/collection-panel/collection-panel-action';
 import { TAG_VALUE_VALIDATION, TAG_KEY_VALIDATION } from '~/validators/validators';
 
-type CssRules = 'buttonWrapper' | 'saveButton' | 'circularProgress';
+type CssRules = 'root' | 'keyField' | 'valueField' | 'buttonWrapper' | 'saveButton' | 'circularProgress';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
+    root: {
+        width: '100%',
+        display: 'flex'
+    },
+    keyField: {
+        width: '25%',
+        marginRight: theme.spacing.unit * 3
+    },
+    valueField: {
+        width: '40%',
+        marginRight: theme.spacing.unit * 3
+    },
     buttonWrapper: {
+        paddingTop: '14px',
         position: 'relative',
-        display: 'inline-block'
     },
     saveButton: {
         boxShadow: 'none'
     },
     circularProgress: {
         position: 'absolute',
-        top: 0,
+        top: -9,
         bottom: 0,
         left: 0,
         right: 0,
@@ -59,33 +71,31 @@ export const CollectionTagForm = compose(
             render() {
                 const { classes, submitting, pristine, invalid, handleSubmit } = this.props;
                 return (
-                    <form onSubmit={handleSubmit}>
-                        <Grid container justify="flex-start" alignItems="baseline" spacing={24}>
-                            <Grid item xs={3} component={"span"}>
-                                <Field name="key"
-                                    disabled={submitting}
-                                    component={TextField}
-                                    validate={TAG_KEY_VALIDATION}
-                                    label="Key" />
-                            </Grid>
-                            <Grid item xs={5} component={"span"}>
-                                <Field name="value"
-                                    disabled={submitting}
-                                    component={TextField}
-                                    validate={TAG_VALUE_VALIDATION}
-                                    label="Value" />
-                            </Grid>
-                            <Grid item component={"span"} className={classes.buttonWrapper}>
-                                <Button type="submit" className={classes.saveButton}
-                                    color="primary"
-                                    size='small'
-                                    disabled={invalid || submitting || pristine}
-                                    variant="contained">
-                                    ADD
-                                </Button>
-                                {submitting && <CircularProgress size={20} className={classes.circularProgress} />}
-                            </Grid>
-                        </Grid>
+                    <form onSubmit={handleSubmit} className={classes.root}>
+                        <Typography component='div' className={classes.keyField}>
+                            <Field name="key"
+                                disabled={submitting}
+                                component={TextField}
+                                validate={TAG_KEY_VALIDATION}
+                                label="Key" />
+                        </Typography>
+                        <Typography component='div' className={classes.valueField}>
+                            <Field name="value"
+                                disabled={submitting}
+                                component={TextField}
+                                validate={TAG_VALUE_VALIDATION}
+                                label="Value" />
+                        </Typography>
+                        <Typography component='div' className={classes.buttonWrapper}>
+                            <Button type="submit" className={classes.saveButton}
+                                color="primary"
+                                size='small'
+                                disabled={invalid || submitting || pristine}
+                                variant="contained">
+                                ADD
+                            </Button>
+                            {submitting && <CircularProgress size={20} className={classes.circularProgress} />}
+                        </Typography>
                     </form>
                 );
             }
diff --git a/src/views/login-panel/login-panel.tsx b/src/views/login-panel/login-panel.tsx
index 2928a94..6a9210a 100644
--- a/src/views/login-panel/login-panel.tsx
+++ b/src/views/login-panel/login-panel.tsx
@@ -55,7 +55,7 @@ export const LoginPanel = withStyles(styles)(connect()(
     <Grid container direction="column" item xs alignItems="center" justify="center" className={classes.root}>
         <Grid item className={classes.container}>
             <Typography variant="title" align="center" className={classes.title}>
-                Welcome to the Arvados Wrokbench
+                Welcome to the Arvados Workbench
             </Typography>
             <Typography variant="body1" className={classes.content}>
                 The "Log in" button below will show you a Google sign-in page.

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list