Refactored ViewImage modal and made it automatically play animated gifs
Этот коммит содержится в:
@@ -1,9 +1,11 @@
|
|||||||
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
import * as AsyncClient from '../utils/async_client.jsx';
|
||||||
import * as Client from '../utils/client.jsx';
|
import * as Client from '../utils/client.jsx';
|
||||||
import * as Utils from '../utils/utils.jsx';
|
import * as Utils from '../utils/utils.jsx';
|
||||||
import Constants from '../utils/constants.jsx';
|
import Constants from '../utils/constants.jsx';
|
||||||
|
import FileStore from '../stores/file_store.jsx';
|
||||||
import ViewImagePopoverBar from './view_image_popover_bar.jsx';
|
import ViewImagePopoverBar from './view_image_popover_bar.jsx';
|
||||||
const Modal = ReactBootstrap.Modal;
|
const Modal = ReactBootstrap.Modal;
|
||||||
const KeyCodes = Constants.KeyCodes;
|
const KeyCodes = Constants.KeyCodes;
|
||||||
@@ -12,80 +14,90 @@ export default class ViewImageModal extends React.Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.canSetState = false;
|
this.showImage = this.showImage.bind(this);
|
||||||
|
|
||||||
this.loadImage = this.loadImage.bind(this);
|
this.loadImage = this.loadImage.bind(this);
|
||||||
|
|
||||||
this.handleNext = this.handleNext.bind(this);
|
this.handleNext = this.handleNext.bind(this);
|
||||||
this.handlePrev = this.handlePrev.bind(this);
|
this.handlePrev = this.handlePrev.bind(this);
|
||||||
this.handleKeyPress = this.handleKeyPress.bind(this);
|
this.handleKeyPress = this.handleKeyPress.bind(this);
|
||||||
this.getPublicLink = this.getPublicLink.bind(this);
|
|
||||||
this.getPreviewImagePath = this.getPreviewImagePath.bind(this);
|
|
||||||
this.onModalShown = this.onModalShown.bind(this);
|
this.onModalShown = this.onModalShown.bind(this);
|
||||||
this.onModalHidden = this.onModalHidden.bind(this);
|
this.onModalHidden = this.onModalHidden.bind(this);
|
||||||
|
|
||||||
|
this.onFileStoreChange = this.onFileStoreChange.bind(this);
|
||||||
|
|
||||||
|
this.getPublicLink = this.getPublicLink.bind(this);
|
||||||
|
this.getPreviewImagePath = this.getPreviewImagePath.bind(this);
|
||||||
this.onMouseEnterImage = this.onMouseEnterImage.bind(this);
|
this.onMouseEnterImage = this.onMouseEnterImage.bind(this);
|
||||||
this.onMouseLeaveImage = this.onMouseLeaveImage.bind(this);
|
this.onMouseLeaveImage = this.onMouseLeaveImage.bind(this);
|
||||||
|
|
||||||
var loaded = [];
|
const loaded = [];
|
||||||
var progress = [];
|
const progress = [];
|
||||||
for (var i = 0; i < this.props.filenames.length; i++) {
|
for (var i = 0; i < this.props.filenames.length; i++) {
|
||||||
loaded.push(false);
|
loaded.push(false);
|
||||||
progress.push(0);
|
progress.push(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
imgId: this.props.startId,
|
imgId: this.props.startId,
|
||||||
|
fileInfo: new Map(),
|
||||||
imgHeight: '100%',
|
imgHeight: '100%',
|
||||||
loaded: loaded,
|
loaded,
|
||||||
progress: progress,
|
progress,
|
||||||
images: {},
|
showFooter: false
|
||||||
fileSizes: {},
|
|
||||||
fileMimes: {},
|
|
||||||
showFooter: false,
|
|
||||||
isPlaying: {},
|
|
||||||
isLoading: {}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
handleNext(e) {
|
handleNext(e) {
|
||||||
if (e) {
|
if (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
var id = this.state.imgId + 1;
|
let id = this.state.imgId + 1;
|
||||||
if (id > this.props.filenames.length - 1) {
|
if (id > this.props.filenames.length - 1) {
|
||||||
id = 0;
|
id = 0;
|
||||||
}
|
}
|
||||||
this.setState({imgId: id});
|
this.showImage(id);
|
||||||
this.loadImage(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePrev(e) {
|
handlePrev(e) {
|
||||||
if (e) {
|
if (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
var id = this.state.imgId - 1;
|
let id = this.state.imgId - 1;
|
||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
id = this.props.filenames.length - 1;
|
id = this.props.filenames.length - 1;
|
||||||
}
|
}
|
||||||
this.setState({imgId: id});
|
this.showImage(id);
|
||||||
this.loadImage(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleKeyPress(e) {
|
handleKeyPress(e) {
|
||||||
if (!e || !this.props.show) {
|
if (e.keyCode === KeyCodes.RIGHT) {
|
||||||
return;
|
|
||||||
} else if (e.keyCode === KeyCodes.RIGHT) {
|
|
||||||
this.handleNext();
|
this.handleNext();
|
||||||
} else if (e.keyCode === KeyCodes.LEFT) {
|
} else if (e.keyCode === KeyCodes.LEFT) {
|
||||||
this.handlePrev();
|
this.handlePrev();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onModalShown(nextProps) {
|
onModalShown(nextProps) {
|
||||||
this.setState({imgId: nextProps.startId});
|
$(window).on('keyup', this.handleKeyPress);
|
||||||
this.loadImage(nextProps.startId);
|
|
||||||
|
this.showImage(nextProps.startId);
|
||||||
|
|
||||||
|
FileStore.addChangeListener(this.onFileStoreChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
onModalHidden() {
|
onModalHidden() {
|
||||||
|
$(window).off('keyup', this.handleKeyPress);
|
||||||
|
|
||||||
if (this.refs.video) {
|
if (this.refs.video) {
|
||||||
var video = ReactDOM.findDOMNode(this.refs.video);
|
var video = ReactDOM.findDOMNode(this.refs.video);
|
||||||
video.pause();
|
video.pause();
|
||||||
video.currentTime = 0;
|
video.currentTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileStore.removeChangeListener(this.onFileStoreChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
if (nextProps.show === true && this.props.show === false) {
|
if (nextProps.show === true && this.props.show === false) {
|
||||||
this.onModalShown(nextProps);
|
this.onModalShown(nextProps);
|
||||||
@@ -93,31 +105,65 @@ export default class ViewImageModal extends React.Component {
|
|||||||
this.onModalHidden();
|
this.onModalHidden();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loadImage(id) {
|
|
||||||
var imgHeight = $(window).height() - 100;
|
onFileStoreChange(filename) {
|
||||||
|
const id = this.props.filenames.indexOf(filename);
|
||||||
|
|
||||||
|
if (id !== -1 && !this.state.loaded[id]) {
|
||||||
|
const fileInfo = this.state.fileInfo;
|
||||||
|
fileInfo.set(filename, FileStore.getInfo(filename));
|
||||||
|
this.setState({fileInfo});
|
||||||
|
|
||||||
|
this.loadImage(id, filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
showImage(id) {
|
||||||
|
this.setState({imgId: id});
|
||||||
|
|
||||||
|
const imgHeight = $(window).height() - 100;
|
||||||
this.setState({imgHeight});
|
this.setState({imgHeight});
|
||||||
|
|
||||||
var filename = this.props.filenames[id];
|
const filename = this.props.filenames[id];
|
||||||
|
|
||||||
var fileInfo = Utils.splitFileLocation(filename);
|
if (!FileStore.hasInfo(filename)) {
|
||||||
var fileType = Utils.getFileType(fileInfo.ext);
|
// the image will actually be loaded once we know what we need to load
|
||||||
|
AsyncClient.getFileInfo(filename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.state.loaded[id]) {
|
||||||
|
this.loadImage(id, filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loadImage(id, filename) {
|
||||||
|
const fileInfo = FileStore.getInfo(filename);
|
||||||
|
const fileType = Utils.getFileType(fileInfo.extension);
|
||||||
|
|
||||||
if (fileType === 'image') {
|
if (fileType === 'image') {
|
||||||
var img = new Image();
|
let previewUrl;
|
||||||
img.load(this.getPreviewImagePath(filename),
|
if (fileInfo.has_image_preview) {
|
||||||
() => {
|
previewUrl = fileInfo.getPreviewImagePath(filename);
|
||||||
const progress = this.state.progress;
|
} else {
|
||||||
progress[id] = img.completedPercentage;
|
// some images (eg animated gifs) just show the file itself and not a preview
|
||||||
this.setState({progress});
|
previewUrl = Utils.getFileUrl(filename);
|
||||||
});
|
}
|
||||||
|
|
||||||
|
const img = new Image();
|
||||||
|
img.load(
|
||||||
|
previewUrl,
|
||||||
|
() => {
|
||||||
|
const progress = this.state.progress;
|
||||||
|
progress[id] = img.completedPercentage;
|
||||||
|
this.setState({progress});
|
||||||
|
}
|
||||||
|
);
|
||||||
img.onload = () => {
|
img.onload = () => {
|
||||||
const loaded = this.state.loaded;
|
const loaded = this.state.loaded;
|
||||||
loaded[id] = true;
|
loaded[id] = true;
|
||||||
this.setState({loaded});
|
this.setState({loaded});
|
||||||
};
|
};
|
||||||
var images = this.state.images;
|
|
||||||
images[id] = img;
|
|
||||||
this.setState({images});
|
|
||||||
} else {
|
} else {
|
||||||
// there's nothing to load for non-image files
|
// there's nothing to load for non-image files
|
||||||
var loaded = this.state.loaded;
|
var loaded = this.state.loaded;
|
||||||
@@ -125,169 +171,82 @@ export default class ViewImageModal extends React.Component {
|
|||||||
this.setState({loaded});
|
this.setState({loaded});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
playGif(e, filename, fileUrl) {
|
|
||||||
var isLoading = this.state.isLoading;
|
|
||||||
var isPlaying = this.state.isPlaying;
|
|
||||||
|
|
||||||
isLoading[filename] = fileUrl;
|
|
||||||
this.setState({isLoading});
|
|
||||||
|
|
||||||
var img = new Image();
|
|
||||||
img.load(fileUrl);
|
|
||||||
img.onload = () => {
|
|
||||||
delete isLoading[filename];
|
|
||||||
isPlaying[filename] = fileUrl;
|
|
||||||
this.setState({isPlaying, isLoading});
|
|
||||||
};
|
|
||||||
img.onError = () => {
|
|
||||||
delete isLoading[filename];
|
|
||||||
this.setState({isLoading});
|
|
||||||
};
|
|
||||||
|
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
stopGif(e, filename) {
|
|
||||||
var isPlaying = this.state.isPlaying;
|
|
||||||
delete isPlaying[filename];
|
|
||||||
this.setState({isPlaying});
|
|
||||||
|
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
|
||||||
componentDidMount() {
|
|
||||||
$(window).on('keyup', this.handleKeyPress);
|
|
||||||
|
|
||||||
// keep track of whether or not this component is mounted so we can safely set the state asynchronously
|
|
||||||
this.canSetState = true;
|
|
||||||
}
|
|
||||||
componentWillUnmount() {
|
|
||||||
this.canSetState = false;
|
|
||||||
$(window).off('keyup', this.handleKeyPress);
|
|
||||||
}
|
|
||||||
getPublicLink() {
|
getPublicLink() {
|
||||||
var data = {};
|
var data = {};
|
||||||
data.channel_id = this.props.channelId;
|
data.channel_id = this.props.channelId;
|
||||||
data.user_id = this.props.userId;
|
data.user_id = this.props.userId;
|
||||||
data.filename = this.props.filenames[this.state.imgId];
|
data.filename = this.props.filenames[this.state.imgId];
|
||||||
Client.getPublicLink(data,
|
Client.getPublicLink(
|
||||||
function sucess(serverData) {
|
data,
|
||||||
|
(serverData) => {
|
||||||
if (Utils.isMobile()) {
|
if (Utils.isMobile()) {
|
||||||
window.location.href = serverData.public_link;
|
window.location.href = serverData.public_link;
|
||||||
} else {
|
} else {
|
||||||
window.open(serverData.public_link);
|
window.open(serverData.public_link);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function error() {}
|
() => {}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getPreviewImagePath(filename) {
|
getPreviewImagePath(filename) {
|
||||||
// Returns the path to a preview image that can be used to represent a file.
|
// Returns the path to a preview image that can be used to represent a file.
|
||||||
var fileInfo = Utils.splitFileLocation(filename);
|
var fileInfo = Utils.splitFileLocation(filename);
|
||||||
var fileType = Utils.getFileType(fileInfo.ext);
|
var fileType = Utils.getFileType(fileInfo.ext);
|
||||||
|
|
||||||
if (fileType === 'image') {
|
if (fileType === 'image') {
|
||||||
if (filename in this.state.isPlaying) {
|
|
||||||
return this.state.isPlaying[filename];
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is a temporary patch to fix issue with old files using absolute paths
|
// This is a temporary patch to fix issue with old files using absolute paths
|
||||||
if (fileInfo.path.indexOf('/api/v1/files/get') !== -1) {
|
if (fileInfo.path.indexOf('/api/v1/files/get') !== -1) {
|
||||||
fileInfo.path = fileInfo.path.split('/api/v1/files/get')[1];
|
fileInfo.path = fileInfo.path.split('/api/v1/files/get')[1];
|
||||||
}
|
}
|
||||||
fileInfo.path = Utils.getWindowLocationOrigin() + '/api/v1/files/get' + fileInfo.path;
|
fileInfo.path = Utils.getWindowLocationOrigin() + '/api/v1/files/get' + fileInfo.path;
|
||||||
|
|
||||||
return fileInfo.path + '_preview.jpg' + '?' + Utils.getSessionIndex();
|
return fileInfo.path + '_preview.jpg?' + Utils.getSessionIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
// only images have proper previews, so just use a placeholder icon for non-images
|
// only images have proper previews, so just use a placeholder icon for non-images
|
||||||
return Utils.getPreviewImagePathForFileType(fileType);
|
return Utils.getPreviewImagePathForFileType(fileType);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseEnterImage() {
|
onMouseEnterImage() {
|
||||||
this.setState({showFooter: true});
|
this.setState({showFooter: true});
|
||||||
}
|
}
|
||||||
|
|
||||||
onMouseLeaveImage() {
|
onMouseLeaveImage() {
|
||||||
this.setState({showFooter: false});
|
this.setState({showFooter: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this.props.filenames.length < 1 || this.props.filenames.length - 1 < this.state.imgId) {
|
if (this.props.filenames.length < 1 || this.props.filenames.length - 1 < this.state.imgId) {
|
||||||
return <div/>;
|
return <div/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
var filename = this.props.filenames[this.state.imgId];
|
const filename = this.props.filenames[this.state.imgId];
|
||||||
var fileUrl = Utils.getFileUrl(filename);
|
const fileUrl = Utils.getFileUrl(filename);
|
||||||
|
|
||||||
var name = decodeURIComponent(Utils.getFileName(filename));
|
|
||||||
|
|
||||||
var content;
|
var content;
|
||||||
var bgClass = '';
|
|
||||||
if (this.state.loaded[this.state.imgId]) {
|
if (this.state.loaded[this.state.imgId]) {
|
||||||
var fileInfo = Utils.splitFileLocation(filename);
|
// if a file has been loaded, we also have its info
|
||||||
var fileType = Utils.getFileType(fileInfo.ext);
|
const fileInfo = this.state.fileInfo.get(filename);
|
||||||
|
|
||||||
|
const extension = Utils.splitFileLocation(filename).ext;
|
||||||
|
const fileType = Utils.getFileType(extension);
|
||||||
|
|
||||||
if (fileType === 'image') {
|
if (fileType === 'image') {
|
||||||
if (!(filename in this.state.fileMimes)) {
|
let previewUrl;
|
||||||
Client.getFileInfo(
|
if (fileInfo.has_preview_image) {
|
||||||
filename,
|
previewUrl = this.getPreviewImagePath(filename);
|
||||||
(data) => {
|
} else {
|
||||||
if (this.canSetState) {
|
previewUrl = fileUrl;
|
||||||
var fileMimes = this.state.fileMimes;
|
|
||||||
fileMimes[filename] = data.mime;
|
|
||||||
this.setState(fileMimes);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
() => {}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var playbackControls = '';
|
|
||||||
if (this.state.fileMimes[filename] === 'image/gif' && !(filename in this.state.isLoading)) {
|
|
||||||
if (filename in this.state.isPlaying) {
|
|
||||||
playbackControls = (
|
|
||||||
<div
|
|
||||||
className='file-playback-controls stop'
|
|
||||||
onClick={(e) => this.stopGif(e, filename)}
|
|
||||||
>
|
|
||||||
{"■"}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
playbackControls = (
|
|
||||||
<div
|
|
||||||
className='file-playback-controls play'
|
|
||||||
onClick={(e) => this.playGif(e, filename, fileUrl)}
|
|
||||||
>
|
|
||||||
{"►"}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var loadingIndicator = '';
|
|
||||||
if (this.state.isLoading[filename] === fileUrl) {
|
|
||||||
loadingIndicator = (
|
|
||||||
<img
|
|
||||||
className='spinner file__loading'
|
|
||||||
src='/static/images/load.gif'
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
playbackControls = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// image files just show a preview of the file
|
|
||||||
content = (
|
content = (
|
||||||
<a
|
<ImagePreview
|
||||||
href={fileUrl}
|
fileUrl={fileUrl}
|
||||||
target='_blank'
|
previewUrl={previewUrl}
|
||||||
>
|
maxHeight={this.state.imgHeight}
|
||||||
{loadingIndicator}
|
/>
|
||||||
{playbackControls}
|
|
||||||
<img
|
|
||||||
style={{maxHeight: this.state.imgHeight}}
|
|
||||||
ref='image'
|
|
||||||
src={this.getPreviewImagePath(filename)}
|
|
||||||
/>
|
|
||||||
</a>
|
|
||||||
);
|
);
|
||||||
} else if (fileType === 'video' || fileType === 'audio') {
|
} else if (fileType === 'video' || fileType === 'audio') {
|
||||||
let width = Constants.WEB_VIDEO_WIDTH;
|
let width = Constants.WEB_VIDEO_WIDTH;
|
||||||
@@ -311,11 +270,13 @@ export default class ViewImageModal extends React.Component {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
// non-image files include a section providing details about the file
|
// non-image files include a section providing details about the file
|
||||||
var infoString = 'File type ' + fileInfo.ext.toUpperCase();
|
let infoString = 'File type ' + fileInfo.extension.toUpperCase();
|
||||||
if (this.state.fileSizes[filename] && this.state.fileSizes[filename] >= 0) {
|
if (fileInfo.size > 0) {
|
||||||
infoString += ', Size ' + Utils.fileSizeToString(this.state.fileSizes[filename]);
|
infoString += ', Size ' + Utils.fileSizeToString(fileInfo.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const name = decodeURIComponent(Utils.getFileName(filename));
|
||||||
|
|
||||||
content = (
|
content = (
|
||||||
<div className='file-details__container'>
|
<div className='file-details__container'>
|
||||||
<a
|
<a
|
||||||
@@ -335,53 +296,16 @@ export default class ViewImageModal extends React.Component {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
bgClass = 'white-bg';
|
|
||||||
|
|
||||||
// asynchronously request the actual size of this file
|
|
||||||
if (!(filename in this.state.fileSizes)) {
|
|
||||||
Client.getFileInfo(
|
|
||||||
filename,
|
|
||||||
function success(data) {
|
|
||||||
if (this.canSetState) {
|
|
||||||
var fileSizes = this.state.fileSizes;
|
|
||||||
fileSizes[filename] = parseInt(data.size, 10);
|
|
||||||
this.setState(fileSizes);
|
|
||||||
}
|
|
||||||
}.bind(this),
|
|
||||||
function fail() {}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// display a progress indicator when the preview for an image is still loading
|
// display a progress indicator when the preview for an image is still loading
|
||||||
var percentage = Math.floor(this.state.progress[this.state.imgId]);
|
const progress = Math.floor(this.state.progress[this.state.imgId]);
|
||||||
if (percentage) {
|
|
||||||
content = (
|
content = <LoadingImagePreview progress={progress} />;
|
||||||
<div>
|
|
||||||
<img
|
|
||||||
className='loader-image'
|
|
||||||
src='/static/images/load.gif'
|
|
||||||
/>
|
|
||||||
<span className='loader-percent'>
|
|
||||||
{'Previewing ' + percentage + '%'}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
content = (
|
|
||||||
<div>
|
|
||||||
<img
|
|
||||||
className='loader-image'
|
|
||||||
src='/static/images/load.gif'
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
bgClass = 'black-bg';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var leftArrow = '';
|
let leftArrow = null;
|
||||||
var rightArrow = '';
|
let rightArrow = null;
|
||||||
if (this.props.filenames.length > 1) {
|
if (this.props.filenames.length > 1) {
|
||||||
leftArrow = (
|
leftArrow = (
|
||||||
<a
|
<a
|
||||||
@@ -427,7 +351,6 @@ export default class ViewImageModal extends React.Component {
|
|||||||
onClick={this.props.onModalDismissed}
|
onClick={this.props.onModalDismissed}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={bgClass}
|
|
||||||
onMouseEnter={this.onMouseEnterImage}
|
onMouseEnter={this.onMouseEnterImage}
|
||||||
onMouseLeave={this.onMouseLeaveImage}
|
onMouseLeave={this.onMouseLeaveImage}
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
@@ -471,3 +394,38 @@ ViewImageModal.propTypes = {
|
|||||||
userId: React.PropTypes.string,
|
userId: React.PropTypes.string,
|
||||||
startId: React.PropTypes.number
|
startId: React.PropTypes.number
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function LoadingImagePreview({progress}) {
|
||||||
|
let progressView = null;
|
||||||
|
if (progress) {
|
||||||
|
progressView = (
|
||||||
|
<span className='loader-percent'>
|
||||||
|
{'Previewing ' + progress + '%'}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='view-image__loading'>
|
||||||
|
<img
|
||||||
|
className='loader-image'
|
||||||
|
src='/static/images/load.gif'
|
||||||
|
/>
|
||||||
|
{progressView}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ImagePreview({maxHeight, fileUrl, previewUrl}) {
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
href={fileUrl}
|
||||||
|
target='_blank'
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
style={{maxHeight}}
|
||||||
|
src={previewUrl}
|
||||||
|
/>
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
60
web/react/stores/file_store.jsx
Обычный файл
60
web/react/stores/file_store.jsx
Обычный файл
@@ -0,0 +1,60 @@
|
|||||||
|
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
|
||||||
|
import Constants from '../utils/constants.jsx';
|
||||||
|
import EventEmitter from 'events';
|
||||||
|
|
||||||
|
const ActionTypes = Constants.ActionTypes;
|
||||||
|
|
||||||
|
const CHANGE_EVENT = 'changed';
|
||||||
|
|
||||||
|
class FileStore extends EventEmitter {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.addChangeListener = this.addChangeListener.bind(this);
|
||||||
|
this.removeChangeListener = this.removeChangeListener.bind(this);
|
||||||
|
this.emitChange = this.emitChange.bind(this);
|
||||||
|
|
||||||
|
this.handleEventPayload = this.handleEventPayload.bind(this);
|
||||||
|
this.dispatchToken = AppDispatcher.register(this.handleEventPayload);
|
||||||
|
|
||||||
|
this.fileInfo = new Map();
|
||||||
|
}
|
||||||
|
|
||||||
|
addChangeListener(callback) {
|
||||||
|
this.on(CHANGE_EVENT, callback);
|
||||||
|
}
|
||||||
|
removeChangeListener(callback) {
|
||||||
|
this.removeListener(CHANGE_EVENT, callback);
|
||||||
|
}
|
||||||
|
emitChange(filename) {
|
||||||
|
this.emit(CHANGE_EVENT, filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
hasInfo(filename) {
|
||||||
|
return this.fileInfo.has(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
getInfo(filename) {
|
||||||
|
return this.fileInfo.get(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
setInfo(filename, info) {
|
||||||
|
this.fileInfo.set(filename, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleEventPayload(payload) {
|
||||||
|
const action = payload.action;
|
||||||
|
|
||||||
|
switch (action.type) {
|
||||||
|
case ActionTypes.RECIEVED_FILE_INFO:
|
||||||
|
this.setInfo(action.filename, action.info);
|
||||||
|
this.emitChange(action.filename);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new FileStore();
|
||||||
@@ -769,3 +769,31 @@ export function getSuggestedCommands(command, suggestionId, component) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getFileInfo(filename) {
|
||||||
|
const callName = 'getFileInfo' + filename;
|
||||||
|
|
||||||
|
if (isCallInProgress(callName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
callTracker[callName] = utils.getTimestamp();
|
||||||
|
|
||||||
|
client.getFileInfo(
|
||||||
|
filename,
|
||||||
|
(data) => {
|
||||||
|
callTracker[callName] = 0;
|
||||||
|
|
||||||
|
AppDispatcher.handleServerAction({
|
||||||
|
type: ActionTypes.RECIEVED_FILE_INFO,
|
||||||
|
filename,
|
||||||
|
info: data
|
||||||
|
});
|
||||||
|
},
|
||||||
|
(err) => {
|
||||||
|
callTracker[callName] = 0;
|
||||||
|
|
||||||
|
dispatchError(err, 'getFileInfo');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1076,7 +1076,9 @@ export function getFileInfo(filename, success, error) {
|
|||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
contentType: 'application/json',
|
contentType: 'application/json',
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
success,
|
success: (data) => {
|
||||||
|
success(data);
|
||||||
|
},
|
||||||
error: function onError(xhr, status, err) {
|
error: function onError(xhr, status, err) {
|
||||||
var e = handleError('getFileInfo', xhr, status, err);
|
var e = handleError('getFileInfo', xhr, status, err);
|
||||||
error(e);
|
error(e);
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ export default {
|
|||||||
RECIEVED_STATUSES: null,
|
RECIEVED_STATUSES: null,
|
||||||
RECIEVED_PREFERENCE: null,
|
RECIEVED_PREFERENCE: null,
|
||||||
RECIEVED_PREFERENCES: null,
|
RECIEVED_PREFERENCES: null,
|
||||||
|
RECIEVED_FILE_INFO: null,
|
||||||
|
|
||||||
RECIEVED_MSG: null,
|
RECIEVED_MSG: null,
|
||||||
|
|
||||||
|
|||||||
@@ -257,3 +257,8 @@
|
|||||||
@include opacity(0);
|
@include opacity(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.view-image__loading {
|
||||||
|
background: black;
|
||||||
|
min-height: 100px;
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user