Skip to content

Commit

Permalink
Fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
ganzorig committed Feb 19, 2018
2 parents 85f6cff + 229dca7 commit 33b2d4e
Show file tree
Hide file tree
Showing 25 changed files with 429 additions and 64 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "erxes",
"version": "0.9.4",
"version": "0.9.6",
"description": "erxes is an AI meets open source messaging platform for sales and marketing teams.",
"homepage": "https://erxes.io",
"repository": {
Expand Down
45 changes: 23 additions & 22 deletions src/modules/common/components/Attachment.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { Icon } from 'modules/common/components';
import { Icon, ImageWithPreview } from 'modules/common/components';

const Overlay = styled.div`
const Overlay = styled.a`
opacity: 0;
width: 100%;
height: 100%;
position: absolute;
background: rgba(0, 0, 0, 0.5);
background: rgba(0, 0, 0, 0.3);
border-radius: 2px;
left: 0;
top: 0;
transition: all 0.2s ease;
transition: all 0.3s ease;
> div {
position: absolute;
Expand All @@ -33,10 +34,9 @@ const Overlay = styled.div`
}
`;

const DownloadAttachment = styled.a`
const AttachmentWrapper = styled.div`
display: inline-block;
position: relative;
cursor: pointer;
max-width: 360px;
transition: all ease 0.3s;
color: inherit;
Expand All @@ -57,6 +57,8 @@ const FileWrapper = styled.div`
min-width: 120px;
min-height: 36px;
line-height: 36px;
background: rgba(0, 0, 0, 0.1);
border-radius: 2px;
i {
font-size: 26px;
Expand Down Expand Up @@ -86,11 +88,16 @@ class Attachment extends Component {
}

renderOtherFile(name, icon) {
return (
<FileWrapper>
return [
<FileWrapper key="wrapper">
<Icon icon={icon} /> <span>{name}</span>
</FileWrapper>
);
</FileWrapper>,
<Overlay key="overlay" href={this.props.attachment.url} target="_blank">
<div>
<Icon icon="android-download" />
</div>
</Overlay>
];
}

onLoadImage() {
Expand All @@ -100,7 +107,7 @@ class Attachment extends Component {
renderAtachment({ attachment }) {
if (attachment.type.startsWith('image')) {
return (
<img
<ImageWithPreview
onLoad={this.onLoadImage}
alt={attachment.url}
src={attachment.url}
Expand All @@ -117,7 +124,9 @@ class Attachment extends Component {
case 'png':
case 'jpeg':
case 'jpg':
filePreview = <img alt={url} src={url} />;
filePreview = (
<ImageWithPreview alt={url} src={url} onLoad={this.onLoadImage} />
);
break;
case 'doc':
case 'docx':
Expand Down Expand Up @@ -148,16 +157,8 @@ class Attachment extends Component {

render() {
const props = this.props;
return (
<DownloadAttachment href={props.attachment.url} target="_blank">
{this.renderAtachment(props)}
<Overlay>
<div>
<Icon icon="android-download" />
</div>
</Overlay>
</DownloadAttachment>
);

return <AttachmentWrapper>{this.renderAtachment(props)}</AttachmentWrapper>;
}
}

Expand Down
143 changes: 143 additions & 0 deletions src/modules/common/components/ImageWithPreview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import styled, { keyframes } from 'styled-components';

const fade = keyframes`
0% {
opacity: 0;
}
100% {
opacity: 1;
}
`;

const slidedown = keyframes`
0% {
transform: translateY(-20px);
opacity: 0.7;
}
100% {
transform: translateY(0);
opacity: 1;
}
`;

const PreviewWrapper = styled.div`
position: fixed;
left: 0;
right: 0;
bottom: 0;
top: 0;
background: rgba(48, 67, 92, 0.8);
z-index: 1000;
display: flex;
justify-content: center;
align-items: center;
transition: all 0.3s;
z-index: 100;
animation-name: ${fade};
animation-duration: 0.3s;
animation-timing-function: ease;
cursor: zoom-out;
img {
width: auto;
max-width: 80%;
max-height: 80%;
max-height: 80vh;
box-shadow: 0 2px 10px -3px rgba(0, 0, 0, 0.5);
transition: max-width 0.1s ease, max-height 0.1s ease;
animation-name: ${slidedown};
animation-duration: 0.3s;
animation-timing-function: ease;
}
`;

const Image = styled.img`
cursor: zoom-in;
transition: all 0.3s;
&:hover {
opacity: 0.8;
}
`;

const KEYCODES = {
ESCAPE: 27
};

class ImageWithPreview extends Component {
constructor(props) {
super(props);

this.state = {
visible: false
};

this.toggleImage = this.toggleImage.bind(this);
this.handleKeydown = this.handleKeydown.bind(this);
}

toggleImage() {
this.setState({ visible: !this.state.visible });
}

componentDidMount() {
document.addEventListener('keydown', this.handleKeydown);
}

handleKeydown(e) {
if (e.keyCode === KEYCODES.ESCAPE && this.state.visible) {
this.setState({ visible: false });
}
}

render() {
const { src, alt } = this.props;

return (
<div>
<Image {...this.props} onClick={this.toggleImage} />
{this.state.visible && (
<PreviewPortal>
<PreviewWrapper onClick={this.toggleImage}>
<img alt={alt} src={src} />
</PreviewWrapper>
</PreviewPortal>
)}
</div>
);
}
}

ImageWithPreview.propTypes = {
src: PropTypes.string,
alt: PropTypes.string,
onLoad: PropTypes.func
};

class PreviewPortal extends Component {
constructor(props) {
super(props);
this.el = document.createElement('div');
}

componentDidMount() {
document.body.appendChild(this.el);
}

componentWillUnmount() {
document.body.removeChild(this.el);
}

render() {
return ReactDOM.createPortal(this.props.children, this.el);
}
}

PreviewPortal.propTypes = {
children: PropTypes.node
};

export default ImageWithPreview;
4 changes: 3 additions & 1 deletion src/modules/common/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import Editor from './Editor';
import { Tabs, TabList, TabTitle } from './tabs';
import ConfirmDialog from './ConfirmDialog';
import DataWithLoader from './DataWithLoader';
import ImageWithPreview from './ImageWithPreview';
// TODO remove
const pagination = {};

Expand Down Expand Up @@ -72,5 +73,6 @@ export {
TabList,
TabTitle,
ConfirmDialog,
DataWithLoader
DataWithLoader,
ImageWithPreview
};
9 changes: 8 additions & 1 deletion src/modules/common/components/pagination/Pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import _ from 'underscore';
import { router } from 'modules/common/utils';
import { Icon } from 'modules/common/components';
import { PaginationWrapper, PaginationList } from './styles';
import PerPageChooser from './PerPageChooser';

// pages calculation
const generatePages = (pageCount, currentPage) => {
Expand Down Expand Up @@ -65,7 +66,7 @@ const generatePages = (pageCount, currentPage) => {
return pages;
};

// per page component
// page chooser component
class Page extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -193,11 +194,17 @@ class Pagination extends React.Component {
<Icon icon="chevron-right" />
</a>
</li>

{this.renderPerPageChooser()}
</PaginationList>
);
}
}

renderPerPageChooser() {
return <PerPageChooser history={this.props.history} />;
}

render() {
return <PaginationWrapper>{this.renderBar()}</PaginationWrapper>;
}
Expand Down
46 changes: 46 additions & 0 deletions src/modules/common/components/pagination/PerPageChooser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import { withRouter } from 'react-router';
import PropTypes from 'prop-types';
import { router } from 'modules/common/utils';
import { Icon, DropdownToggle } from 'modules/common/components';
import { PerPageButton, Option } from './styles';
import { Dropdown } from 'react-bootstrap';

// per page chooser component
const PerPageChooser = ({ history }) => {
const currentPerPage = Number(router.getParam(history, 'perPage')) || 20;

const onClick = perPage => {
router.setParams(history, { perPage });
};

const renderOption = number => {
return (
<Option>
<a onClick={() => onClick(number)}>{number}</a>
</Option>
);
};

return (
<Dropdown id="per-page-chooser" className="dropup">
<DropdownToggle bsRole="toggle">
<PerPageButton>
{currentPerPage} per page <Icon icon="ios-arrow-up" />
</PerPageButton>
</DropdownToggle>
<Dropdown.Menu>
{renderOption(20)}
{renderOption(50)}
{renderOption(100)}
{renderOption(200)}
</Dropdown.Menu>
</Dropdown>
);
};

PerPageChooser.propTypes = {
history: PropTypes.object.isRequired
};

export default withRouter(PerPageChooser);
21 changes: 20 additions & 1 deletion src/modules/common/components/pagination/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,23 @@ const PaginationList = styled.ul`
}
`;

export { PaginationWrapper, PaginationList };
const PerPageButton = styled.a`
font-weight: 400;
color: #999;
cursor: pointer;
margin-left: 15px;
position: relative;
top: -2px;
i {
margin-left: 3px;
}
`;

const Option = styled.li`
a {
cursor: pointer;
}
`;

export { PaginationWrapper, PaginationList, PerPageButton, Option };
4 changes: 3 additions & 1 deletion src/modules/common/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import router from './router';
import toggleCheckBoxes from './toggleCheckBoxes';
import Rotate from './animateRotate';
import confirm from './confirmation/confirm';
import urlParser from './urlParser';

const renderFullName = data => {
if (data.firstName || data.lastName) {
Expand All @@ -19,5 +20,6 @@ export {
Rotate,
confirm,
toggleCheckBoxes,
renderFullName
renderFullName,
urlParser
};
Loading

0 comments on commit 33b2d4e

Please sign in to comment.