1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { Dialog, DialogActions, Button, StyleRulesCallback, WithStyles, withStyles, CardHeader, Tab, Tabs } from '@material-ui/core';
7 import { withDialog } from "~/store/dialog/with-dialog";
8 import { COLLECTION_WEBDAV_S3_DIALOG_NAME, WebDavS3InfoDialogData } from '~/store/collections/collection-info-actions';
9 import { WithDialogProps } from '~/store/dialog/with-dialog';
10 import { compose } from 'redux';
11 import { DetailsAttribute } from "~/components/details-attribute/details-attribute";
12 import { DownloadIcon } from "~/components/icon/icon";
14 export type CssRules = 'details' | 'downloadButton';
16 const styles: StyleRulesCallback<CssRules> = theme => ({
18 marginLeft: theme.spacing.unit * 3,
19 marginRight: theme.spacing.unit * 3,
22 marginTop: theme.spacing.unit * 2,
26 interface TabPanelData {
27 children: React.ReactElement<any>[];
32 function TabPanel(props: TabPanelData) {
33 const { children, value, index } = props;
38 hidden={value !== index}
39 id={`simple-tabpanel-${index}`}
40 aria-labelledby={`simple-tab-${index}`}
42 {value === index && children}
47 const mountainduckTemplate = ({
51 }: any) => `<?xml version="1.0" encoding="UTF-8"?>
52 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
58 <string>iterate GmbH</string>
60 <string>${uuid}</string>
62 <string>${collectionsUrl.replace('https://', `davs://${username}@`).replace('*', uuid)}</string>
66 <string>${username}</string>
72 `.split(/\r?\n/).join('\n');
74 const downloadMountainduckFileHandler = (filename: string, text: string) => {
75 const element = document.createElement('a');
76 element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
77 element.setAttribute('download', filename);
79 element.style.display = 'none';
80 document.body.appendChild(element);
84 document.body.removeChild(element);
87 export const WebDavS3InfoDialog = compose(
88 withDialog(COLLECTION_WEBDAV_S3_DIALOG_NAME),
91 (props: WithDialogProps<WebDavS3InfoDialogData> & WithStyles<CssRules>) => {
92 if (!props.data.downloadUrl) { return null; }
97 if (props.data.collectionsUrl.indexOf("*") > -1) {
98 const withuuid = props.data.collectionsUrl.replace("*", props.data.uuid);
99 winDav = new URL(withuuid);
100 cyberDav = new URL(withuuid);
102 winDav = new URL(props.data.downloadUrl);
103 cyberDav = new URL(props.data.downloadUrl);
104 winDav.pathname = `/by_id/${props.data.uuid}`;
105 cyberDav.pathname = `/by_id/${props.data.uuid}`;
108 cyberDav.username = props.data.username;
109 const cyberDavStr = "dav" + cyberDav.toString().slice(4);
111 const s3endpoint = new URL(props.data.collectionsUrl.replace(/\/\*(--[^.]+)?\./, "/"));
113 const sp = props.data.token.split("/");
116 if (sp.length === 3 && sp[0] === "v2" && sp[1].slice(0, 5) === props.data.localCluster) {
120 tokenUuid = props.data.token.replace(/\//g, "_");
121 tokenSecret = tokenUuid;
124 const supportsWebdav = (props.data.uuid.indexOf("-4zz18-") === 5);
126 let activeTab = props.data.activeTab;
127 if (!supportsWebdav) {
134 onClose={props.closeDialog}
135 style={{ alignSelf: 'stretch' }}>
137 title={`Open as Network Folder or S3 Bucket`} />
138 <div className={props.classes.details} >
139 <Tabs value={activeTab} onChange={props.data.setActiveTab}>
140 {supportsWebdav && <Tab value={0} key="cyberduck" label="Cyberduck/Mountain Duck or Gnome Files" />}
141 {supportsWebdav && <Tab value={1} key="windows" label="Windows or MacOS" />}
142 <Tab value={2} key="s3" label="S3 bucket" />
145 <TabPanel index={1} value={activeTab}>
149 label='Internet address'
150 value={<a href={winDav.toString()} target="_blank">{winDav.toString()}</a>}
151 copyValue={winDav.toString()} />
155 value={props.data.username}
156 copyValue={props.data.username} />
160 value={props.data.token}
161 copyValue={props.data.token} />
165 <li>Open File Explorer</li>
166 <li>Click on "This PC", then go to Computer → Add a Network Location</li>
167 <li>Click Next, then choose "Add a custom network location", then click Next</li>
173 <li>Click Go → Connect to server</li>
177 <TabPanel index={0} value={activeTab}>
180 value={<a href={cyberDavStr} target="_blank">{cyberDavStr}</a>}
181 copyValue={cyberDavStr} />
185 value={props.data.username}
186 copyValue={props.data.username} />
190 value={props.data.token}
191 copyValue={props.data.token} />
194 data-cy='download-button'
195 className={props.classes.downloadButton}
196 onClick={() => downloadMountainduckFileHandler(`${props.data.collectionName || props.data.uuid}.duck`, mountainduckTemplate(props.data))}
207 <li>Select +Other Locations</li>
208 <li>Connect to Server → Enter server address</li>
213 <TabPanel index={2} value={activeTab}>
216 value={s3endpoint.host}
217 copyValue={s3endpoint.host} />
221 value={props.data.uuid}
222 copyValue={props.data.uuid} />
227 copyValue={tokenUuid} />
232 copyValue={tokenSecret} />
241 onClick={props.closeDialog}>