Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"devDependencies": {
"babel-eslint": "8.2.1",
"cypress": "3.2.0",
"cypress": "^3.2.0",
"eslint": "4.17.0",
"eslint-config-opuscapita": "2.0.1",
"eslint-plugin-react": "7.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ Resource example for **connector-node-v1**:
"createdTime": 1515854279676,
"id": "Lw",
"modifiedTime": 1515854279660,
"name": "Customization area",
"name*": "Customization area",
"type": "dir",
"parentId": null
"parentId": null*
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ class FileNavigator extends Component {
label: capability.label || '',
onClick: capability.handler || (() => {}),
});

if (!isDataView) {
res.disabled = !capability.shouldBeAvailable(apiOptions);
}
Expand Down Expand Up @@ -462,6 +461,7 @@ class FileNavigator extends Component {
const filesViewContextMenuItems = this.getContextCapabilities({ context: 'files-view', isDataView: true });
const toolbarItems = this.getContextCapabilities({ context: 'toolbar' });
const newButtonItems = this.getContextCapabilities({ context: 'new-button' });
const uploadItem = newButtonItems.filter(el => el.id === 'upload');

const rowContextMenuId = `row-context-menu-${id}`;
const filesViewContextMenuId = `files-view-context-menu-${id}`;
Expand Down Expand Up @@ -504,6 +504,7 @@ class FileNavigator extends Component {
layout={listViewLayout}
layoutOptions={viewLayoutOptions}
locale={apiOptions.locale}
dragUpload={uploadItem.length ? uploadItem[0].onClick : () => {}}
>
<Notifications
className="oc-fm--file-navigator__notifications"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ListView is a part of FileManger. Built using [react-virtualized](https://github
| onSort | func | ({ sortBy, sortDirection }) => {} |
| onKeyDown | func | (e) => {} |
| onRef | func | (ref) => {} |
| dragUpload | func | () => {} |

### Code Example

Expand All @@ -29,6 +30,7 @@ ListView is a part of FileManger. Built using [react-virtualized](https://github
onRowDoubleClick={(data) => console.log('double click', data)}
onSelection={_scope.handleSelection}
onSort={_scope.handleSort}
dragUpload={() => console.log('drag')}
loading={false}
selection={_scope.state.selection}
sortBy={_scope.state.sortBy}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const propTypes = {
onSort: PropTypes.func,
onKeyDown: PropTypes.func,
onRef: PropTypes.func,
locale: PropTypes.string
locale: PropTypes.string,
dragUpload: PropTypes.func
};
const defaultProps = {
rowContextMenuId: nanoid(),
Expand Down Expand Up @@ -168,6 +169,22 @@ class ListView extends Component {
this.scrollToIndex(scrollToIndex);
}

handleHighlight = (event) => {
event.preventDefault()
event.stopPropagation()
}

handleUnhighlight = (event) => {
event.preventDefault()
event.stopPropagation()
}

handleDropFile = (event, callback) => {
event.preventDefault()
event.stopPropagation()
callback({ action: 'drag' });
}

render() {
const {
rowContextMenuId,
Expand All @@ -178,7 +195,8 @@ class ListView extends Component {
loading,
onRef,
sortBy,
sortDirection
sortDirection,
dragUpload
} = this.props;

const {
Expand Down Expand Up @@ -221,6 +239,14 @@ class ListView extends Component {
}) => (
<div
className="oc-fm--list-view"
onDragEnter={(event) => {
this.handleHighlight(event);
this.handleDropFile(event, dragUpload)
}}
onDragOver={(event) => {
this.handleHighlight(event);
} }
onDragLeave={this.handleUnhighlight}
>
<ScrollOnMouseOut
onCursorAbove={this.handleScrollTop}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ class Toolbar extends Component {
disabled={item.disabled}
className={`oc-fm--toolbar__item`}
title={item.label || ''}
onClick={(!item.disabled && item.onClick) || (() => {})}
onClick={() => {
if (!item.disabled) {
item.onClick({ action: 'click' })
}
}}
>
<Svg
className="oc-fm--toolbar__item-icon"
Expand Down
6 changes: 3 additions & 3 deletions packages/connector-node-v1/src/capabilities/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { normalizeResource } from '../utils/common';

const label = 'upload';

async function handler(apiOptions, actions) {
async function handler(apiOptions, actions, typeAction) {
const {
navigateToDir,
updateNotifications,
Expand Down Expand Up @@ -73,7 +73,7 @@ async function handler(apiOptions, actions) {

const resource = getResource();
try {
const file = await readLocalFile(true);
const file = await readLocalFile(typeAction);
onStart({ name: file.name, size: file.file.size });
const response = await api.uploadFileToId({ apiOptions, parentId: resource.id, file, onProgress });
const newResource = normalizeResource(response.body[0]);
Expand Down Expand Up @@ -121,6 +121,6 @@ export default (apiOptions, actions) => {
return resource.capabilities.canAddChildren
},
availableInContexts: ['files-view', 'new-button'],
handler: () => handler(apiOptions, actions)
handler: (typeAction) => handler(apiOptions, actions, typeAction)
};
}
72 changes: 56 additions & 16 deletions packages/connector-node-v1/src/utils/upload.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,64 @@
async function readLocalFile() {
async function readLocalFile(typeAction) {
return new Promise((resolve, reject) => {
const uploadInput = document.createElement("input");
if (typeAction.action === 'click') {
const uploadInput = document.createElement("input");
uploadInput.addEventListener('change', _ => {
const file = uploadInput.files[0];
resolve({
type: file.type,
name: file.name,
file
});
});
// This input element in IE11 becomes visible after it is added on the page
// Hide an input element
uploadInput.style.visibility = 'hidden';
uploadInput.type = "file";
document.body.appendChild(uploadInput);
uploadInput.click();
document.body.removeChild(uploadInput);
} else if (typeAction.action === 'drag') {
const dragArea = document.createElement('div');
const navigator = document.querySelector('.oc-fm--file-navigator');
navigator.appendChild(dragArea);

dragArea.style.position = 'absolute';
dragArea.style.width = '100%';
dragArea.style.height = '100%';
dragArea.style.top = '0';

dragArea.addEventListener('dragenter', (e) => {
e.preventDefault();
})

uploadInput.addEventListener('change', _ => {
const file = uploadInput.files[0];
resolve({
type: file.type,
name: file.name,
file
dragArea.addEventListener('drop', (e) => {
e.preventDefault();
const dt = e.dataTransfer;
const files = dt.files;
const file = files[0];
if (file) {
const reader = new FileReader();
reader.onload = (e) => {
console.log(e.target.result);
};
reader.readAsDataURL(file);
}
navigator.removeChild(dragArea);
resolve({
type: file.type,
name: file.name,
file,
});
});
});

// This input element in IE11 becomes visible after it is added on the page
// Hide an input element
uploadInput.style.visibility = 'hidden';
dragArea.addEventListener('dragover', e => {
e.preventDefault()
});

uploadInput.type = "file";
document.body.appendChild(uploadInput);
uploadInput.click();
document.body.removeChild(uploadInput);
dragArea.addEventListener('dragleave', () => {
navigator.removeChild(dragArea);
});
}
});
}

Expand Down