mirror of
https://github.com/strapi/strapi.git
synced 2025-10-25 15:02:56 +00:00
Add sorting options and created extensions.json files
The extensions.json file is used to associate the correct icon with the extension of a file
This commit is contained in:
parent
c621209605
commit
c3231b9f5e
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"archive": ["rar", "zip"],
|
||||||
|
"code": ["js", "json", "rb", "erb", "txt", "css", "scss", "html", "jsx"],
|
||||||
|
"img": ["jpg", "jpeg", "png", "gif"],
|
||||||
|
"pdf": ["pdf"],
|
||||||
|
"powerpoint": ["ppt", "key", "xls"],
|
||||||
|
"video": ["mov", "avi", "mpg", "mp4", "m4v"],
|
||||||
|
"word": ["doc", "pages"]
|
||||||
|
}
|
||||||
@ -8,24 +8,29 @@ import React from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import cn from 'classnames';
|
import cn from 'classnames';
|
||||||
|
|
||||||
|
import ext from './extensions.json';
|
||||||
|
|
||||||
import styles from './styles.scss';
|
import styles from './styles.scss';
|
||||||
|
|
||||||
function FileIcon({ fileType }) {
|
function FileIcon({ fileType }) {
|
||||||
const iconType = (() => {
|
const iconType = (() => {
|
||||||
switch (fileType) {
|
switch (true) {
|
||||||
case 'jpg':
|
case ext.archive.includes(fileType):
|
||||||
case 'jpeg':
|
return 'file-archive-o';
|
||||||
case 'png':
|
case ext.code.includes(fileType):
|
||||||
case 'gif':
|
return 'file-code-o';
|
||||||
return 'image';
|
case ext.img.includes(fileType):
|
||||||
case 'mov':
|
return 'file-image-o';
|
||||||
case 'avi':
|
case ext.pdf.includes(fileType):
|
||||||
case 'mpg':
|
return 'file-pdf-o';
|
||||||
case 'm4v':
|
case ext.powerpoint.includes(fileType):
|
||||||
case 'mp4':
|
return 'file-powerpoint-o';
|
||||||
return 'video';
|
case ext.video.includes(fileType):
|
||||||
|
return 'file-video-o';
|
||||||
|
case ext.word.includes(fileType):
|
||||||
|
return 'file-word-o';
|
||||||
default:
|
default:
|
||||||
return fileType;
|
return 'file';
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@ -33,13 +38,14 @@ function FileIcon({ fileType }) {
|
|||||||
<div
|
<div
|
||||||
className={(cn(
|
className={(cn(
|
||||||
styles.fileIconContainer,
|
styles.fileIconContainer,
|
||||||
iconType === 'pdf' && styles.pdf,
|
iconType === 'file-pdf-o' && styles.pdf,
|
||||||
iconType === 'zip' && styles.zip,
|
iconType === 'file-zip-o' && styles.zip,
|
||||||
iconType === 'image' && styles.image,
|
iconType === 'file-image-o' && styles.image,
|
||||||
iconType === 'video' && styles.video,
|
iconType === 'file-video-o' && styles.video,
|
||||||
|
iconType === 'file-code-o' && styles.code,
|
||||||
))}
|
))}
|
||||||
>
|
>
|
||||||
<i className={`fa fa-file-${iconType}-o`} />
|
<i className={`fa fa-${iconType}`} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,3 +17,7 @@
|
|||||||
.zip {
|
.zip {
|
||||||
color: #A16B26;
|
color: #A16B26;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.code {
|
||||||
|
color: #BDBFC2;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
.liWrapper {
|
.liWrapper {
|
||||||
height: 54px;
|
height: 54px;
|
||||||
background-color: #fff;
|
background-color: #fff;
|
||||||
padding-top: 5px;
|
padding-top: 5px;
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import { FormattedMessage } from 'react-intl';
|
||||||
import cn from 'classnames';
|
import cn from 'classnames';
|
||||||
|
|
||||||
import Li from 'components/Li';
|
import Li from 'components/Li';
|
||||||
@ -13,28 +14,41 @@ import ListHeader from 'components/ListHeader';
|
|||||||
|
|
||||||
import styles from './styles.scss';
|
import styles from './styles.scss';
|
||||||
|
|
||||||
|
const EmptyLi = () => (
|
||||||
|
<li className={styles.emptyLiWrapper}>
|
||||||
|
<div>
|
||||||
|
<FormattedMessage id="upload.EmptyLi.message" />
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
|
||||||
function List(props) {
|
function List(props) {
|
||||||
return (
|
return (
|
||||||
<div className={cn('container-fluid', styles.listWrapper)}>
|
<div className={cn('container-fluid', styles.listWrapper)}>
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<ul className={styles.ulList}>
|
<ul className={styles.ulList}>
|
||||||
<ListHeader />
|
<ListHeader changeSort={props.changeSort} sort={props.sort} />
|
||||||
{props.data.map((item, key) => (
|
{props.data.map((item, key) => (
|
||||||
<Li
|
<Li
|
||||||
key={item.hash || key}
|
key={item.hash || key}
|
||||||
item={item}
|
item={item}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
{props.data.length === 0 && <EmptyLi />}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List.defaultProps = {};
|
List.defaultProps = {
|
||||||
|
sort: 'id',
|
||||||
|
};
|
||||||
|
|
||||||
List.propTypes = {
|
List.propTypes = {
|
||||||
|
changeSort: PropTypes.func.isRequired,
|
||||||
data: PropTypes.arrayOf(PropTypes.object).isRequired,
|
data: PropTypes.arrayOf(PropTypes.object).isRequired,
|
||||||
|
sort: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default List;
|
export default List;
|
||||||
|
|||||||
@ -22,3 +22,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.emptyLiWrapper {
|
||||||
|
height: 54px;
|
||||||
|
background-color: #fff;
|
||||||
|
padding-top: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
> div {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
justify-content: center;
|
||||||
|
padding-top: 1px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 54px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -7,15 +7,14 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
import cn from 'classnames';
|
import cn from 'classnames';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
// import InputCheckBox from 'components/InputCheckbox';
|
// import InputCheckBox from 'components/InputCheckbox';
|
||||||
|
|
||||||
import styles from './styles.scss';
|
import styles from './styles.scss';
|
||||||
|
|
||||||
function ListHeader() {
|
function ListHeader({ changeSort, sort }) {
|
||||||
const titles = [
|
const titles = [
|
||||||
// '',
|
|
||||||
// 'type',
|
|
||||||
'hash',
|
'hash',
|
||||||
'name',
|
'name',
|
||||||
'updated',
|
'updated',
|
||||||
@ -23,20 +22,37 @@ function ListHeader() {
|
|||||||
'related',
|
'related',
|
||||||
'',
|
'',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const handleChangeSort = (name) => {
|
||||||
|
if (sort === name) {
|
||||||
|
changeSort(`-${name}`);
|
||||||
|
} else if (sort === `-${name}`) {
|
||||||
|
changeSort('hash');
|
||||||
|
} else if (name === 'updated' || name === 'related') {
|
||||||
|
changeSort('hash');
|
||||||
|
} else {
|
||||||
|
changeSort(name);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const shouldDisplaySort = (title) => sort === title && styles.icon || sort === `-${title}` && styles.iconDesc || '';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li className={styles.listheaderWrapper}>
|
<li className={styles.listheaderWrapper}>
|
||||||
<div className={cn(styles.listHeader)}>
|
<div className={cn(styles.listHeader)}>
|
||||||
<div>
|
<div>
|
||||||
<div />
|
<div />
|
||||||
<div>
|
<div className={shouldDisplaySort('type')} onClick={() => handleChangeSort('type')}>
|
||||||
<FormattedMessage id="upload.ListHeader.type" />
|
<FormattedMessage id="upload.ListHeader.type" />
|
||||||
|
<span />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{titles.map((title, key) => {
|
{titles.map((title, key) => {
|
||||||
if (title !== '') {
|
if (title !== '') {
|
||||||
return (
|
return (
|
||||||
<div key={key}>
|
<div key={key} className={shouldDisplaySort(title)} onClick={() => handleChangeSort(title)}>
|
||||||
<FormattedMessage id={`upload.ListHeader.${title}`} />
|
<FormattedMessage id={`upload.ListHeader.${title}`} />
|
||||||
|
<span />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -48,4 +64,13 @@ function ListHeader() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ListHeader.defaultProps = {
|
||||||
|
changeSort: () => {},
|
||||||
|
};
|
||||||
|
|
||||||
|
ListHeader.propTypes = {
|
||||||
|
changeSort: PropTypes.func,
|
||||||
|
sort: PropTypes.string.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
export default ListHeader;
|
export default ListHeader;
|
||||||
|
|||||||
@ -32,13 +32,6 @@
|
|||||||
> div:nth-child(4) {
|
> div:nth-child(4) {
|
||||||
width: 184px;
|
width: 184px;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
> span {
|
|
||||||
&:after {
|
|
||||||
content: '\f0d8';
|
|
||||||
margin-left: 10px;
|
|
||||||
font-family: 'FontAwesome';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
> div:nth-child(5) {
|
> div:nth-child(5) {
|
||||||
width: 100px;
|
width: 100px;
|
||||||
@ -53,3 +46,23 @@
|
|||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
> span:last-child {
|
||||||
|
&:after {
|
||||||
|
content: '\f0d8';
|
||||||
|
margin-left: 10px;
|
||||||
|
font-family: 'FontAwesome';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.iconDesc {
|
||||||
|
> span:last-child {
|
||||||
|
&:after {
|
||||||
|
content: '\f0d7';
|
||||||
|
margin-left: 10px;
|
||||||
|
font-family: 'FontAwesome';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -81,6 +81,21 @@ export class HomePage extends React.Component {
|
|||||||
|
|
||||||
getURLParams = (type) => getQueryParameters(this.props.location.search, type);
|
getURLParams = (type) => getQueryParameters(this.props.location.search, type);
|
||||||
|
|
||||||
|
changeSort = (name) => {
|
||||||
|
const { params: { limit, page } } = this.props;
|
||||||
|
const target = {
|
||||||
|
name: 'params.sort',
|
||||||
|
value: name,
|
||||||
|
};
|
||||||
|
const search = `page=${page}&limit=${limit}&sort=${name}`;
|
||||||
|
|
||||||
|
this.props.changeParams({ target });
|
||||||
|
this.props.history.push({
|
||||||
|
pathname: this.props.history.pathname,
|
||||||
|
search,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
handleChangeParams = (e) => {
|
handleChangeParams = (e) => {
|
||||||
const { history, params } = this.props;
|
const { history, params } = this.props;
|
||||||
const search = e.target.name === 'params.limit' ?
|
const search = e.target.name === 'params.limit' ?
|
||||||
@ -138,6 +153,8 @@ export class HomePage extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
<List
|
<List
|
||||||
data={this.props.uploadedFiles}
|
data={this.props.uploadedFiles}
|
||||||
|
changeSort={this.changeSort}
|
||||||
|
sort={this.props.params.sort}
|
||||||
/>
|
/>
|
||||||
<div className="col-md-12">
|
<div className="col-md-12">
|
||||||
<PageFooter
|
<PageFooter
|
||||||
@ -165,7 +182,7 @@ HomePage.defaultProps = {
|
|||||||
page: 1,
|
page: 1,
|
||||||
sort: 'updatedAt',
|
sort: 'updatedAt',
|
||||||
},
|
},
|
||||||
uploadedFiles: [{}],
|
uploadedFiles: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
HomePage.propTypes = {
|
HomePage.propTypes = {
|
||||||
|
|||||||
@ -20,7 +20,7 @@ const initialState = fromJS({
|
|||||||
dataToDelete: '',
|
dataToDelete: '',
|
||||||
entriesNumber: 0,
|
entriesNumber: 0,
|
||||||
search: '',
|
search: '',
|
||||||
uploadedFiles: List([Map({})]),
|
uploadedFiles: List([]),
|
||||||
params: Map({
|
params: Map({
|
||||||
sort: 'hash',
|
sort: 'hash',
|
||||||
limit: 10,
|
limit: 10,
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"EmptyLi.message": "There is no uploaded files",
|
||||||
|
|
||||||
"EntriesNumber.number": "{number} file found",
|
"EntriesNumber.number": "{number} file found",
|
||||||
"EntriesNumber.number.plural": "{number} files found",
|
"EntriesNumber.number.plural": "{number} files found",
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"EmptyLi.message": "There is no uploaded files",
|
||||||
|
|
||||||
"EntriesNumber.number": "{number} file found",
|
"EntriesNumber.number": "{number} file found",
|
||||||
"EntriesNumber.number.plural": "{number} files found",
|
"EntriesNumber.number.plural": "{number} files found",
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"EmptyLi.message": "Aucun fichier n'a été téléchargé",
|
||||||
|
|
||||||
"EntriesNumber.number": "{number} fichier trouvé",
|
"EntriesNumber.number": "{number} fichier trouvé",
|
||||||
"EntriesNumber.number.plural": "{number} fichiers trouvés",
|
"EntriesNumber.number.plural": "{number} fichiers trouvés",
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"EmptyLi.message": "There is no uploaded files",
|
||||||
|
|
||||||
"EntriesNumber.number": "{number} file found",
|
"EntriesNumber.number": "{number} file found",
|
||||||
"EntriesNumber.number.plural": "{number} files found",
|
"EntriesNumber.number.plural": "{number} files found",
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
|
"EmptyLi.message": "There is no uploaded files",
|
||||||
|
|
||||||
"EntriesNumber.number": "{number} file found",
|
"EntriesNumber.number": "{number} file found",
|
||||||
"EntriesNumber.number.plural": "{number} files found",
|
"EntriesNumber.number.plural": "{number} files found",
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user