From 1585a4a2f9b197c0fd08057a24575673c404bcce Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Tue, 26 Mar 2019 13:24:02 +0100 Subject: [PATCH] prepare retrieving and displaying files metadata --- client/src/routes/Details/AssetDetails.tsx | 29 ++--- .../src/routes/Details/AssetFilesDetails.tsx | 105 ++++++++++++++++++ client/src/routes/Details/index.tsx | 25 +---- 3 files changed, 115 insertions(+), 44 deletions(-) create mode 100644 client/src/routes/Details/AssetFilesDetails.tsx diff --git a/client/src/routes/Details/AssetDetails.tsx b/client/src/routes/Details/AssetDetails.tsx index 792a3ce..bc52cfc 100644 --- a/client/src/routes/Details/AssetDetails.tsx +++ b/client/src/routes/Details/AssetDetails.tsx @@ -1,18 +1,17 @@ import React, { PureComponent } from 'react' import { Link } from 'react-router-dom' -import Button from '../../components/atoms/Button' import Moment from 'react-moment' import styles from './AssetDetails.module.scss' +import AssetFilesDetails from './AssetFilesDetails' interface AssetDetailsProps { metadata: any ddo: any - purchaseAsset: any } export default class AssetDetails extends PureComponent { public render() { - const { metadata, ddo, purchaseAsset } = this.props + const { metadata, ddo } = this.props const { base } = metadata return ( @@ -38,8 +37,9 @@ export default class AssetDetails extends PureComponent { ) : ( Fake Category )} - fake json contentType - fake 18.5 MB + + {base.files ? base.files.length : 0} data files + @@ -58,18 +58,6 @@ export default class AssetDetails extends PureComponent { {base.license} -
  • - - File Encoding - - fake UTF-8 -
  • -
  • - - Compression - - fake None -
  • DID @@ -80,9 +68,10 @@ export default class AssetDetails extends PureComponent {
  • - +
                         {JSON.stringify(metadata, null, 2)}
    diff --git a/client/src/routes/Details/AssetFilesDetails.tsx b/client/src/routes/Details/AssetFilesDetails.tsx
    new file mode 100644
    index 0000000..805baa6
    --- /dev/null
    +++ b/client/src/routes/Details/AssetFilesDetails.tsx
    @@ -0,0 +1,105 @@
    +import React, { PureComponent } from 'react'
    +import queryString from 'query-string'
    +import { Logger } from '@oceanprotocol/squid'
    +import Button from '../../components/atoms/Button'
    +import styles from './AssetDetails.module.scss'
    +
    +interface AssetFilesDetailsProps {
    +    files: any[]
    +    ddo: string
    +}
    +
    +export default class AssetFilesDetails extends PureComponent<
    +    AssetFilesDetailsProps
    +> {
    +    private purchaseAsset = async (ddo: any) => {
    +        try {
    +            const account = await this.context.ocean.getAccounts()
    +            const service = ddo.findServiceByType('Access')
    +            const serviceAgreementSignatureResult = await this.context.ocean.signServiceAgreement(
    +                ddo.id,
    +                service.serviceDefinitionId,
    +                account[0]
    +            )
    +            await this.context.ocean.initializeServiceAgreement(
    +                ddo.id,
    +                service.serviceDefinitionId,
    +                serviceAgreementSignatureResult.agreementId,
    +                serviceAgreementSignatureResult.signature,
    +                (files: any) => {
    +                    Logger.log('downloading files', files)
    +                    files.forEach((file: any) => {
    +                        const parsedUrl: any = queryString.parseUrl(file)
    +                        // setTimeout(() => {
    +                        //     // eslint-disable-next-line
    +                        //     window.open(parsedUrl.query.url)
    +                        // }, 100)
    +                    })
    +                },
    +                account[0]
    +            )
    +        } catch (e) {
    +            Logger.log('error', e)
    +        }
    +    }
    +
    +    public render() {
    +        const { files, ddo } = this.props
    +
    +        return (
    +            <>
    +                {files.forEach(file => {
    +                    const parsedUrl: any = queryString.parseUrl(file)
    +
    +                    return (
    +                        <>
    +                            

    {file.name}

    +
      +
    • + + Content Type + + + {file.contentType} + +
    • +
    • + + Size + + + {file.contentLength} + +
    • +
    • + + File Encoding + + + {file.encoding} + +
    • +
    • + + Compression + + + {file.compression} + +
    • +
    + + + + ) + })} + + + + ) + } +} diff --git a/client/src/routes/Details/index.tsx b/client/src/routes/Details/index.tsx index 39700ba..e5055cb 100644 --- a/client/src/routes/Details/index.tsx +++ b/client/src/routes/Details/index.tsx @@ -1,6 +1,4 @@ import React, { Component } from 'react' -import { Logger } from '@oceanprotocol/squid' -import queryString from 'query-string' import Route from '../../components/templates/Route' import Spinner from '../../components/atoms/Spinner' import { User } from '../../context/User' @@ -28,23 +26,6 @@ export default class Details extends Component { this.setState({ ddo, metadata: { base: metadata.base } }) } - private purchaseAsset = async (ddo: any) => { - try { - const account = await this.context.ocean.accounts.list() - const accessService = ddo.findServiceByType('Access') - const agreementId = await this.context.ocean.assets.order( - ddo.id, - accessService.serviceDefinitionId, - account[0] - ) - const folder = "" - const path = await this.context.ocean.assets.consume(agreementId, ddo.id, accessService.serviceDefinitionId, account[0], folder) - Logger.log('path', path) - } catch (e) { - Logger.log('error', e) - } - } - public render() { const { metadata, ddo } = this.state @@ -53,11 +34,7 @@ export default class Details extends Component { title={metadata.base ? metadata.base.name : 'Loading Details'} > {metadata && metadata.base.name ? ( - + ) : (