diff --git a/frontend/src/components/dialog/share-repo-dialog.js b/frontend/src/components/dialog/share-repo-dialog.js index 46b3ceb04c..91fcf49111 100644 --- a/frontend/src/components/dialog/share-repo-dialog.js +++ b/frontend/src/components/dialog/share-repo-dialog.js @@ -1,11 +1,11 @@ import React from 'react'; import PropTypes from 'prop-types'; import moment from 'moment'; -import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Input } from 'reactstrap'; -import { gettext, siteRoot } from '../../utils/constants'; +import { Button, Modal, ModalHeader, ModalBody, ModalFooter, Input, Alert } from 'reactstrap'; import { seafileAPI } from '../../utils/seafile-api'; +import { gettext } from '../../utils/constants'; +import { Utils } from '../../utils/utils'; import Repo from '../../models/repo'; -import toaster from '../toast'; const shareRepoListItemProps = { repo: PropTypes.object.isRequired, @@ -28,10 +28,11 @@ class ShareRepoListItem extends React.Component { render() { let repo = this.props.repo; + let iconUrl = Utils.getLibIconUrl(repo); return ( - {gettext('icon')} + {gettext('icon')} {repo.repo_name} {moment(repo.last_modified).fromNow()} @@ -61,6 +62,7 @@ class ShareRepoDialog extends React.Component { currentRepo: null, permission: 'rw', selectedRepoList: [], + errMessage: '', }; } @@ -100,7 +102,8 @@ class ShareRepoDialog extends React.Component { handleSubmit = () => { if (this.state.selectedRepoList.length === 0) { - toaster.danger(gettext('Please select a library to share.')); + let errMessage = gettext('Please select a library to share.') + this.setState({errMessage: errMessage}); return; } @@ -141,6 +144,7 @@ class ShareRepoDialog extends React.Component { + {this.state.errMessage && {this.state.errMessage}} diff --git a/frontend/src/components/dirent-detail/dirent-details.js b/frontend/src/components/dirent-detail/dirent-details.js index 1de2e3c9e6..7487811a83 100644 --- a/frontend/src/components/dirent-detail/dirent-details.js +++ b/frontend/src/components/dirent-detail/dirent-details.js @@ -94,24 +94,8 @@ class DirentDetail extends React.Component { render() { let { dirent } = this.props; - - let smallIconUrl = ''; - let bigIconUrl = ''; - let smallIconSize = Utils.isHiDPI() ? 48 : 24; - let bigIconSize = 192; - if (dirent.type === 'file') { - smallIconUrl = Utils.getFileIconUrl(dirent.name, smallIconSize); - bigIconUrl = Utils.getFileIconUrl(dirent.name, bigIconSize); - } else { - let isReadOnly = false; - if (dirent.permission === 'r' || dirent.permission === 'preview') { - isReadOnly = true; - } - let options = {isReadOnly: isReadOnly, size: smallIconSize}; - smallIconUrl = Utils.getFolderIconUrl(options); - options.size = bigIconSize; - bigIconUrl = Utils.getFolderIconUrl(options); - } + let smallIconUrl = Utils.getDirentIcon(dirent); + let bigIconUrl = Utils.getDirentIcon(dirent, true); return (
diff --git a/frontend/src/components/dirent-detail/lib-details.js b/frontend/src/components/dirent-detail/lib-details.js index 00bfd64009..09c5206ade 100644 --- a/frontend/src/components/dirent-detail/lib-details.js +++ b/frontend/src/components/dirent-detail/lib-details.js @@ -38,32 +38,21 @@ class LibDetail extends React.Component { render() { let repo = this.props.currentRepo; - let isReadOnly = false; - if (repo.permission === 'r' || repo.permission === 'preview') { - isReadOnly = true; - } - let titleIcon = Utils.getLibIconUrl({ - is_encrypted: repo.encrypted, - is_readonly: isReadOnly, - size: Utils.isHiDPI() ? 48 : 24 - }); - let iconUrl = Utils.getLibIconUrl({ - is_encrypted: repo.encrypted, - is_readonly: isReadOnly, - }); + let smallIconUrl = Utils.getLibIconUrl(repo); + let bigIconUrl = Utils.getLibIconUrl(repo, true); return (
- {' '} + {' '} {repo.repo_name}
- +
diff --git a/frontend/src/components/dirent-list-view/dirent-list-item.js b/frontend/src/components/dirent-list-view/dirent-list-item.js index 0375429ee6..3203fd0a21 100644 --- a/frontend/src/components/dirent-list-view/dirent-list-item.js +++ b/frontend/src/components/dirent-list-view/dirent-list-item.js @@ -353,17 +353,7 @@ class DirentListItem extends React.Component { }); } - let size = Utils.isHiDPI() ? 48 : 24; - let iconUrl = ''; - if (dirent.type === 'file') { - iconUrl = Utils.getFileIconUrl(dirent.name, size); - } else { - let isReadOnly = false; - if (dirent.permission === 'r' || dirent.permission === 'preview') { - isReadOnly = true; - } - iconUrl = Utils.getFolderIconUrl({isReadOnly, size}); - } + let iconUrl = Utils.getDirentIcon(dirent); const {repoEncrypted, isRepoOwner, isAdmin} = this.props; let showShare = false; diff --git a/frontend/src/components/draft-list-view/draft-list-item.js b/frontend/src/components/draft-list-view/draft-list-item.js index e148e8dfbb..18f437160a 100644 --- a/frontend/src/components/draft-list-view/draft-list-item.js +++ b/frontend/src/components/draft-list-view/draft-list-item.js @@ -57,8 +57,7 @@ class DraftListItem extends React.Component { let localTime = moment.utc(draft.updated_at).toDate(); localTime = moment(localTime).fromNow(); - let size = Utils.isHiDPI() ? 48 : 24; - let iconUrl = Utils.getFileIconUrl(fileName, size); + let iconUrl = Utils.getFileIconUrl(fileName); return ( diff --git a/frontend/src/components/review-list-view/review-list-item.js b/frontend/src/components/review-list-view/review-list-item.js index 2661233666..c76a5b6db5 100644 --- a/frontend/src/components/review-list-view/review-list-item.js +++ b/frontend/src/components/review-list-view/review-list-item.js @@ -102,8 +102,7 @@ class ReviewListItem extends React.Component { let localTime = moment.utc(item.updated_at).toDate(); localTime = moment(localTime).fromNow(); - let size = Utils.isHiDPI() ? 48 : 24; - let iconUrl = Utils.getFileIconUrl(fileName, size); + let iconUrl = Utils.getFileIconUrl(fileName); return ( diff --git a/frontend/src/components/search/search-result-item.js b/frontend/src/components/search/search-result-item.js index 770d1e2ea0..4a00f93b80 100644 --- a/frontend/src/components/search/search-result-item.js +++ b/frontend/src/components/search/search-result-item.js @@ -1,6 +1,5 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { siteRoot } from '../../utils/constants'; import { Utils } from '../../utils/utils'; const propTypes = { @@ -17,8 +16,7 @@ class SearchResultItem extends React.Component { render() { let item = this.props.item; - let fileIconSize = Utils.isHiDPI() ? 48 : 24; - let fileIconUrl = item.is_dir ? siteRoot + 'media/img/folder-192.png' : Utils.getFileIconUrl(item.name, fileIconSize); + let fileIconUrl = item.is_dir ? Utils.getFolderIconUrl(false, 192) : Utils.getFileIconUrl(item.name, 192); return (
  • diff --git a/frontend/src/components/shared-repo-list-view/shared-repo-list-item.js b/frontend/src/components/shared-repo-list-view/shared-repo-list-item.js index fe05260895..0e5f6089f7 100644 --- a/frontend/src/components/shared-repo-list-view/shared-repo-list-item.js +++ b/frontend/src/components/shared-repo-list-view/shared-repo-list-item.js @@ -80,21 +80,9 @@ class SharedRepoListItem extends React.Component { getRepoComputeParams = () => { let repo = this.props.repo; - let isReadOnly = false; - if (repo.permission === 'r' || repo.permission === 'preview') { - isReadOnly = true; - } - let iconUrl = Utils.getLibIconUrl({ - is_encrypted: repo.encrypted, - is_readonly: isReadOnly, - size: Utils.isHiDPI() ? 48 : 24 - }); - let iconTitle = Utils.getLibIconTitle({ - 'encrypted': repo.encrypted, - 'is_admin': repo.is_admin, - 'permission': repo.permission - }); - + + let iconUrl = Utils.getLibIconUrl(repo); + let iconTitle = Utils.getLibIconTitle(repo); let libPath = `${siteRoot}library/${repo.repo_id}/${Utils.encodePath(repo.repo_name)}/`; return { iconUrl, iconTitle, libPath }; diff --git a/frontend/src/components/wiki-dir-list-view/wiki-dir-list-item.js b/frontend/src/components/wiki-dir-list-view/wiki-dir-list-item.js index cf812b32ae..5c936f06f1 100644 --- a/frontend/src/components/wiki-dir-list-view/wiki-dir-list-item.js +++ b/frontend/src/components/wiki-dir-list-view/wiki-dir-list-item.js @@ -34,18 +34,7 @@ class WikiDirListItem extends React.Component { render() { let { path, dirent } = this.props; let href = siteRoot + 'wikis' + Utils.joinPath(path, dirent.name); - - let size = Utils.isHiDPI() ? 48 : 24; - let iconUrl = ''; - if (dirent.type === 'file') { - iconUrl = Utils.getFileIconUrl(dirent.name, size); - } else { - let isReadOnly = false; - if (dirent.permission === 'r' || dirent.permission === 'preview') { - isReadOnly = true; - } - iconUrl = Utils.getFolderIconUrl({isReadOnly, size}); - } + let iconUrl = Utils.getDirentIcon(dirent); return (
  • diff --git a/frontend/src/pages/my-libs/item.js b/frontend/src/pages/my-libs/item.js index b27639f963..625bee9057 100644 --- a/frontend/src/pages/my-libs/item.js +++ b/frontend/src/pages/my-libs/item.js @@ -164,22 +164,9 @@ class Item extends Component { render() { const data = this.props.data; - const permission = data.permission; - - let is_readonly = false; - if (permission == 'r' || permission == 'preview') { - is_readonly = true; - } - data.icon_url = Utils.getLibIconUrl({ - is_encrypted: data.encrypted, - is_readonly: is_readonly, - size: Utils.isHiDPI() ? 48 : 24 - }); - data.icon_title = Utils.getLibIconTitle({ - 'encrypted': data.encrypted, - 'is_admin': data.is_admin, - 'permission': permission - }); + + data.icon_url = Utils.getLibIconUrl(data); + data.icon_title = Utils.getLibIconTitle(data); data.url = `${siteRoot}library/${data.repo_id}/${Utils.encodePath(data.repo_name)}/`; let iconVisibility = this.state.showOpIcon ? '' : ' invisible'; diff --git a/frontend/src/pages/share-admin/folders.js b/frontend/src/pages/share-admin/folders.js index b40b276fe5..18e2e79704 100644 --- a/frontend/src/pages/share-admin/folders.js +++ b/frontend/src/pages/share-admin/folders.js @@ -120,10 +120,7 @@ class Item extends Component { if (share_permission == 'r' || share_permission == 'preview') { is_readonly = true; } - let iconUrl = Utils.getFolderIconUrl({ - is_readonly: is_readonly, - size: Utils.isHiDPI() ? 48 : 24 - }); + let iconUrl = Utils.getFolderIconUrl(is_readonly); let iconTitle = Utils.getFolderIconTitle({ 'permission': share_permission }); diff --git a/frontend/src/pages/share-admin/libraries.js b/frontend/src/pages/share-admin/libraries.js index ad1d3e4f48..ada9643f79 100644 --- a/frontend/src/pages/share-admin/libraries.js +++ b/frontend/src/pages/share-admin/libraries.js @@ -117,22 +117,9 @@ class Item extends Component { getRepoParams = () => { let item = this.props.item; - const { share_permission, is_admin } = this.state; - - let is_readonly = false; - if (share_permission == 'r' || share_permission == 'preview') { - is_readonly = true; - } - let iconUrl = Utils.getLibIconUrl({ - is_encrypted: item.encrypted, - is_readonly: is_readonly, - size: Utils.isHiDPI() ? 48 : 24 - }); - let iconTitle = Utils.getLibIconTitle({ - 'encrypted': item.encrypted, - 'is_admin': is_admin, - 'permission': share_permission - }); + + let iconUrl = Utils.getLibIconUrl(item); + let iconTitle = Utils.getLibIconTitle(item); let repoUrl = `${siteRoot}library/${item.repo_id}/${item.repo_name}`; return { iconUrl, iconTitle, repoUrl }; diff --git a/frontend/src/pages/share-admin/share-links.js b/frontend/src/pages/share-admin/share-links.js index ce39f4889a..a40b03e305 100644 --- a/frontend/src/pages/share-admin/share-links.js +++ b/frontend/src/pages/share-admin/share-links.js @@ -125,17 +125,13 @@ class Item extends Component { getLinkParams = () => { let item = this.props.item; - let icon_size = Utils.isHiDPI() ? 48 : 24; let iconUrl = ''; let linkUrl = ''; if (item.is_dir) { - iconUrl = Utils.getFolderIconUrl({ - is_readonly: false, - size: icon_size - }); + iconUrl = Utils.getFolderIconUrl(false); linkUrl = `${siteRoot}library/${item.repo_id}/${item.repo_name}${Utils.encodePath(item.path)}`; } else { - iconUrl = Utils.getFileIconUrl(item.obj_name, icon_size); + iconUrl = Utils.getFileIconUrl(item.obj_name); linkUrl = `${siteRoot}lib/${item.repo_id}/file${Utils.encodePath(item.path)}`; } diff --git a/frontend/src/pages/share-admin/upload-links.js b/frontend/src/pages/share-admin/upload-links.js index 56a6f07303..5e3882d9be 100644 --- a/frontend/src/pages/share-admin/upload-links.js +++ b/frontend/src/pages/share-admin/upload-links.js @@ -107,12 +107,7 @@ class Item extends Component { getUploadParams = () => { let item = this.props.item; - let icon_size = Utils.isHiDPI() ? 48 : 24; - let iconUrl = Utils.getFolderIconUrl({ - is_readonly: false, - size: icon_size - }); - + let iconUrl = Utils.getFolderIconUrl(false); let uploadUrl = `${siteRoot}library/${item.repo_id}/${item.repo_name}${Utils.encodePath(item.path)}`; return { iconUrl, uploadUrl }; diff --git a/frontend/src/pages/shared-libs/shared-libs.js b/frontend/src/pages/shared-libs/shared-libs.js index 85e721a4e5..0cb5104402 100644 --- a/frontend/src/pages/shared-libs/shared-libs.js +++ b/frontend/src/pages/shared-libs/shared-libs.js @@ -182,22 +182,9 @@ class Item extends Component { } const data = this.props.data; - const permission = data.permission; - let is_readonly = false; - if (permission == 'r' || permission == 'preview') { - is_readonly = true; - } - data.icon_url = Utils.getLibIconUrl({ - is_encrypted: data.encrypted, - is_readonly: is_readonly, - size: Utils.isHiDPI() ? 48 : 24 - }); - data.icon_title = Utils.getLibIconTitle({ - 'encrypted': data.encrypted, - 'is_admin': data.is_admin, - 'permission': permission - }); + data.icon_url = Utils.getLibIconUrl(data); + data.icon_title = Utils.getLibIconTitle(data); data.url = `${siteRoot}#shared-libs/lib/${data.repo_id}/`; let iconVisibility = this.state.showOpIcon ? '' : ' invisible'; diff --git a/frontend/src/pages/starred/starred.js b/frontend/src/pages/starred/starred.js index 1655886d65..8defefd1b9 100644 --- a/frontend/src/pages/starred/starred.js +++ b/frontend/src/pages/starred/starred.js @@ -91,9 +91,8 @@ class TableBody extends Component { render() { let listFilesActivities = this.state.items.map(function(item, index) { - let fileIconSize = Utils.isHiDPI() ? 48 : 24; - item.file_icon_url = Utils.getFileIconUrl(item.file_name, fileIconSize); + item.file_icon_url = Utils.getFileIconUrl(item.file_name); item.encoded_path = Utils.encodePath(item.path); item.thumbnail_url = item.encoded_thumbnail_src ? `${siteRoot}${item.encoded_thumbnail_src}` : ''; diff --git a/frontend/src/utils/utils.js b/frontend/src/utils/utils.js index a186dc1ddf..cb4b362e29 100644 --- a/frontend/src/utils/utils.js +++ b/frontend/src/utils/utils.js @@ -89,28 +89,6 @@ export const Utils = { 'default' : 'file.png' }, - getFileIconUrl: function(filename, size) { - if (size > 24) { - size = 192; - } else { - size = 24; - } - - var file_ext; - if (filename.lastIndexOf('.') == -1) { - return mediaUrl + 'img/file/' + size + '/' - + this.FILEEXT_ICON_MAP['default']; - } else { - file_ext = filename.substr(filename.lastIndexOf('.') + 1).toLowerCase(); - } - - if (this.FILEEXT_ICON_MAP[file_ext]) { - return mediaUrl + 'img/file/' + size + '/' + this.FILEEXT_ICON_MAP[file_ext]; - } else { - return mediaUrl + 'img/file/' + size + '/' + this.FILEEXT_ICON_MAP['default']; - } - }, - // check if a file is an image imageCheck: function (filename) { // no file ext @@ -242,45 +220,71 @@ export const Utils = { navigator.userAgent.indexOf('Chrome') > -1; }, - getLibIconUrl: function(options) { - /* - * param: {is_encrypted, is_readonly, size} - */ - // icon name - var icon_name = 'lib.png'; - if (options.is_encrypted) { + getLibIconUrl: function(repo, isBig) { + let permission = repo.permission || repo.share_permission; //Compatible with regular repo and repo shared + let size = Utils.isHiDPI() ? 48 : 24; + size = isBig ? 256 : size; + let icon_name = 'lib.png'; + if (repo.encrypted) { icon_name = 'lib-encrypted.png'; } - if (options.is_readonly) { + if (permission === 'r' || permission === 'perview') { icon_name = 'lib-readonly.png'; } - // icon size - var icon_size = options.size || 256; // 'size' can be 24, 48, or undefined. (2017.7.31) - - return mediaUrl + 'img/lib/' + icon_size + '/' + icon_name; + return mediaUrl + 'img/lib/' + size + '/' + icon_name; }, - getFolderIconUrl: function(options) { - /* - * param: {is_readonly, size} - */ - const readonly = options.is_readonly; - const size = options.size; - return `${mediaUrl}img/folder${readonly ? '-read-only' : ''}${size > 24 ? '-192' : '-24'}.png`; + getDirentIcon: function (dirent, isBig) { + let size = this.isHiDPI() ? 48 : 24; + size = isBig ? 192 : size; + if (dirent.isDir()) { + let readonly = false; + if (dirent.permission && (dirent.permission === 'r' || dirent.permission === 'preview')) { + readonly = true; + } + return this.getFolderIconUrl(readonly, size); + } else { + return this.getFileIconUrl(dirent.name, size); + } }, - getLibIconTitle: function(options) { - /* - * param: {encrypted, is_admin, permission} - */ + getFolderIconUrl: function(readonly = false, size) { + if (!size) { + size = Utils.isHiDPI() ? 48 : 24; + } + size = size > 24 ? 192 : 24; + return `${mediaUrl}img/folder${readonly ? '-read-only-' : '-'}${size}.png`; + }, + + getFileIconUrl: function(filename, size) { + if (!size) { + size = Utils.isHiDPI() ? 48 : 24; + } + size = size > 24 ? 192 : 24; + let file_ext = ''; + if (filename.lastIndexOf('.') == -1) { + return mediaUrl + 'img/file/' + size + '/' + this.FILEEXT_ICON_MAP['default']; + } else { + file_ext = filename.substr(filename.lastIndexOf('.') + 1).toLowerCase(); + } + + if (this.FILEEXT_ICON_MAP[file_ext]) { + return mediaUrl + 'img/file/' + size + '/' + this.FILEEXT_ICON_MAP[file_ext]; + } else { + return mediaUrl + 'img/file/' + size + '/' + this.FILEEXT_ICON_MAP['default']; + } + }, + + getLibIconTitle: function(repo) { var title; - if (options.encrypted) { + let permission = repo.permission || repo.share_permission; //Compatible with regular repo and repo shared + if (repo.encrypted) { title = gettext("Encrypted library"); - } else if (options.is_admin) { // shared with 'admin' permission + } else if (repo.is_admin) { // shared with 'admin' permission title = gettext("Admin access"); } else { - switch(options.permission) { + switch(permission) { case 'rw': title = gettext("Read-Write library"); break;