Skip to content

Commit

Permalink
Merge pull request #27 from OpusCapita/rename-capability-gdrive/#7
Browse files Browse the repository at this point in the history
Rename capability gdrive/#7
  • Loading branch information
abaliunov-sc committed Nov 3, 2017
2 parents adfb8b7 + 352e178 commit 341daa6
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 92 deletions.
10 changes: 9 additions & 1 deletion client-react/src/client/connectors/google_drive_v2/api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import agent from 'superagent';
import { downloadFile } from '../utils/download';
import { getExportMimeType, checkIsGoogleDocument } from './document-export-types';
import { getExportMimeType, checkIsGoogleDocument } from './google-drive-utils';

let signedIn = false;

Expand Down Expand Up @@ -193,6 +193,13 @@ async function createFolder(apiOptions, parentId, folderName) {
});
}

async function renameResource(apiOptions, id, newName) {
await window.gapi.client.drive.files.patch({
fileId: id,
title: newName
});
}

async function removeResources() {

}
Expand All @@ -216,6 +223,7 @@ export default {
getCapabilitiesForResource,
createFolder,
downloadResources,
renameResource,
removeResources,
signIn,
signOut
Expand Down
86 changes: 0 additions & 86 deletions client-react/src/client/connectors/google_drive_v2/capabilities.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import api from '../api';
import sanitizeFilename from 'sanitize-filename';
import ContextMenuItem from '../../../components/ContextMenuItem';
import SetNameDialog from '../../../components/SetNameDialog';

let createFolderIcon = require('!!raw-loader!@opuscapita/svg-icons/lib/create_new_folder.svg');

export default (apiOptions, { showDialog, hideDialog, forceUpdate }) => ({
id: 'createFolder',
shouldBeAvailable: (apiOptions, { selectedResources }) => selectedResources.length === 1,
contextMenuRenderer: (apiOptions, {
selection,
selectedResources,
resource,
resourceChildren,
resourceLocation
}) => (
<ContextMenuItem
icon={{ svg: createFolderIcon }}
onClick={() => {
showDialog((
<SetNameDialog
onHide={hideDialog}
onSubmit={async (folderName) => {
let { resourceChildren } = await api.getChildrenForId(apiOptions, resource.id);
let alreadyExists = resourceChildren.some((o) => o.title === folderName);
if (alreadyExists) {
return `File or folder with name "${folderName}" already exists`;
} else {
hideDialog();
await api.createFolder(apiOptions, resource.id, folderName);
forceUpdate();
}
}}
onValidate={async (folderName) => {
if (!folderName) {
return 'Name can\'t be empty';
} else if (folderName === 'CON') {
return 'We too do not respect Bill ;)';
} else if (folderName.length >= 255) {
return 'Folder name can\'t contain more than 255 characters';
} else if (folderName.trim() !== sanitizeFilename(folderName.trim())) {
return 'Folder name contains not allowed characters';
}
return null;
}}
headerText={`Folder name`}
/>
));
}}
>
<span>Create folder</span>
</ContextMenuItem>
)
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import api from '../api';
import ContextMenuItem from '../../../components/ContextMenuItem';

let deleteIcon = require('!!raw-loader!@opuscapita/svg-icons/lib/delete.svg');

export default (apiOptions, { showDialog, hideDialog, forceUpdate }) => ({
id: 'delete',
title: 'Remove',
shouldBeAvailable: (apiOptions, { selectedResources }) => {
return selectedResources.every(resource => resource.capabilities.canDelete);
},
contextMenuRenderer: (apiOptions, { selectedResources }) => (
<ContextMenuItem icon={{ svg: deleteIcon }}>
<span>Remove</span>
</ContextMenuItem>
)
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import api from '../api';
import ContextMenuItem from '../../../components/ContextMenuItem';

let downloadIcon = require('!!raw-loader!@opuscapita/svg-icons/lib/file_download.svg');

export default (apiOptions, { showDialog, hideDialog, forceUpdate }) => ({
id: 'download',
shouldBeAvailable: (apiOptions, { selectedResources }) => {
return selectedResources.length === 1 && selectedResources[0].type !== 'dir';
},
contextMenuRenderer: (apiOptions, { selectedResources }) => (
<ContextMenuItem
icon={{ svg: downloadIcon }}
onClick={() => api.downloadResources(selectedResources)}
>
<span>Download</span>
</ContextMenuItem>
)
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import createFolder from './create-folder';
import deleteResource from './delete-resource';
import download from './download';
import rename from './rename';

export default (apiOptions, { showDialog, hideDialog, forceUpdate }) => ([
createFolder(apiOptions, { showDialog, hideDialog, forceUpdate }),
rename(apiOptions, { showDialog, hideDialog, forceUpdate }),
download(apiOptions, { showDialog, hideDialog, forceUpdate }),
deleteResource(apiOptions, { showDialog, hideDialog, forceUpdate })
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import api from '../api';
import sanitizeFilename from 'sanitize-filename';
import ContextMenuItem from '../../../components/ContextMenuItem';
import SetNameDialog from '../../../components/SetNameDialog';

let renameIcon = require('!!raw-loader!@opuscapita/svg-icons/lib/title.svg');

export default (apiOptions, { showDialog, hideDialog, forceUpdate }) => ({
id: 'rename',
shouldBeAvailable: (apiOptions, { selectedResources }) => (
selectedResources.length === 1 &&
selectedResources[0].id !== 'root' // root is not mutable
),
contextMenuRenderer: (apiOptions, {
selection,
selectedResources,
resource,
resourceChildren,
resourceLocation
}) => (
<ContextMenuItem
icon={{ svg: renameIcon }}
onClick={() => {
showDialog((
<SetNameDialog
onHide={hideDialog}
onSubmit={async (name) => {
let { resourceChildren } = await api.getChildrenForId(apiOptions, resource.id);
let alreadyExists = resourceChildren.some((o) => o.title === name);
if (alreadyExists) {
return `File or folder with name "${name}" already exists`;
} else {
hideDialog();
await api.renameResource(apiOptions, selectedResources[0].id, name);
forceUpdate();
}
}}
onValidate={async (name) => {
if (!name) {
return 'Name can\'t be empty';
} else if (name.length >= 255) {
return 'Name can\'t contain more than 255 characters';
} else if (name.trim() !== sanitizeFilename(name.trim())) {
return 'Name contains not allowed characters';
}
return null;
}}
headerText={`New name`}
/>
));
}}
>
<span>Rename</span>
</ContextMenuItem>
)
});

This file was deleted.

2 changes: 0 additions & 2 deletions client-react/src/client/connectors/google_drive_v2/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import api from './api';
import capabilities from './capabilities';
import contextMenuLayout from './context-menu-layout';
import listViewLayout from './list-view-layout';
import viewLayoutOptions from './view-layout-options';

export default {
api,
capabilities,
contextMenuLayout,
listViewLayout,
viewLayoutOptions
};

0 comments on commit 341daa6

Please sign in to comment.