Add an info box next to image thumbnails which provides the name, type, and size of a file.
Этот коммит содержится в:
@@ -114,23 +114,48 @@ module.exports = React.createClass({
|
|||||||
}
|
}
|
||||||
fileInfo.path = utils.getWindowLocationOrigin() + "/api/v1/files/get" + fileInfo.path;
|
fileInfo.path = utils.getWindowLocationOrigin() + "/api/v1/files/get" + fileInfo.path;
|
||||||
|
|
||||||
|
var thumbnail;
|
||||||
if (type === "image") {
|
if (type === "image") {
|
||||||
if (i < Constants.MAX_DISPLAY_FILES) {
|
thumbnail = (
|
||||||
postFiles.push(
|
<a className="post-image__thumbnail" href="#" onClick={this.handleImageClick} data-img-id={images.length.toString()} data-toggle="modal" data-target={"#" + postImageModalId }>
|
||||||
<div className="post-image__column" key={filenames[i]}>
|
<div ref={filenames[i]} className="post__load" style={{backgroundImage: 'url(/static/images/load.gif)'}}/>
|
||||||
<a href="#" onClick={this.handleImageClick} data-img-id={images.length.toString()} data-toggle="modal" data-target={"#" + postImageModalId }><div ref={filenames[i]} className="post__load" style={{backgroundImage: 'url(/static/images/load.gif)'}}></div></a>
|
</a>
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
images.push(filenames[i]);
|
|
||||||
} else if (i < Constants.MAX_DISPLAY_FILES) {
|
|
||||||
postFiles.push(
|
|
||||||
<div className="post-image__column custom-file" key={fileInfo.name+i}>
|
|
||||||
<a href={fileInfo.path + (fileInfo.ext ? "." + fileInfo.ext : "")} download={fileInfo.name + (fileInfo.ext ? "." + fileInfo.ext : "")}>
|
|
||||||
<div className={"file-icon "+utils.getIconClassName(type)}/>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
thumbnail = (
|
||||||
|
<a href={fileInfo.path + (fileInfo.ext ? "." + fileInfo.ext : "")} download={fileInfo.name + (fileInfo.ext ? "." + fileInfo.ext : "")}>
|
||||||
|
<div className={"file-icon "+utils.getIconClassName(type)}/>
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
var containerClassName = "post-image__column";
|
||||||
|
if (type !== "image") {
|
||||||
|
containerClassName += " custom-file";
|
||||||
|
}
|
||||||
|
|
||||||
|
postFiles.push(
|
||||||
|
<div className={containerClassName} key={filenames[i]}>
|
||||||
|
{thumbnail}
|
||||||
|
<div className="post-image__details">
|
||||||
|
<div className="post-image__name">{fileInfo.name}</div>
|
||||||
|
<div>
|
||||||
|
<span className="post-image__type">{fileInfo.ext.toUpperCase()}</span>
|
||||||
|
<span className="post-image__size" ref={filenames[i] + "__size"}></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
// asynchronously request the size of the file so that we can display it next to the thumbnail
|
||||||
|
utils.getFileSize(fileInfo.path + "." + fileInfo.ext, function(self, filename) {
|
||||||
|
return function(size) {
|
||||||
|
self.refs[filename + "__size"].getDOMNode().innerHTML = " " + utils.fileSizeToString(size);
|
||||||
|
}
|
||||||
|
}(this, filenames[i]));
|
||||||
|
|
||||||
|
if (type === "image") {
|
||||||
|
images.push(filenames[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -557,6 +557,23 @@ module.exports.splitFileLocation = function(fileLocation) {
|
|||||||
return {'ext': ext, 'name': filename, 'path': filePath};
|
return {'ext': ext, 'name': filename, 'path': filePath};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Asynchronously gets the size of a file by requesting its headers. If successful, it calls the
|
||||||
|
// provided callback with the file size in bytes as the argument.
|
||||||
|
module.exports.getFileSize = function(url, callback) {
|
||||||
|
var request = new XMLHttpRequest();
|
||||||
|
|
||||||
|
request.open('HEAD', url, true);
|
||||||
|
request.onreadystatechange = function() {
|
||||||
|
if (request.readyState == 4 && request.status == 200) {
|
||||||
|
if (callback) {
|
||||||
|
callback(parseInt(request.getResponseHeader("content-length")));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
request.send();
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.toTitleCase = function(str) {
|
module.exports.toTitleCase = function(str) {
|
||||||
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
|
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
|
||||||
}
|
}
|
||||||
@@ -847,4 +864,20 @@ module.exports.getWindowLocationOrigin = function() {
|
|||||||
windowLocationOrigin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
|
windowLocationOrigin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
|
||||||
}
|
}
|
||||||
return windowLocationOrigin;
|
return windowLocationOrigin;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Converts a file size in bytes into a human-readable string of the form "123MB".
|
||||||
|
module.exports.fileSizeToString = function(bytes) {
|
||||||
|
// it's unlikely that we'll have files bigger than this
|
||||||
|
if (bytes > 1024 * 1024 * 1024 * 1024) {
|
||||||
|
return Math.floor(bytes / (1024 * 1024 * 1024 * 1024)) + "TB";
|
||||||
|
} else if (bytes > 1024 * 1024 * 1024) {
|
||||||
|
return Math.floor(bytes / (1024 * 1024 * 1024)) + "GB";
|
||||||
|
} else if (bytes > 1024 * 1024) {
|
||||||
|
return Math.floor(bytes / (1024 * 1024)) + "MB";
|
||||||
|
} else if (bytes > 1024) {
|
||||||
|
return Math.floor(bytes / 1024) + "KB";
|
||||||
|
} else {
|
||||||
|
return bytes + "B";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -117,13 +117,14 @@
|
|||||||
}
|
}
|
||||||
.post-image__column {
|
.post-image__column {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 120px;
|
width: 240px;
|
||||||
height: 100px;
|
height: 100px;
|
||||||
float: left;
|
float: left;
|
||||||
margin: 5px 10px 5px 0;
|
margin: 5px 10px 5px 0;
|
||||||
|
display: flex;
|
||||||
|
border: 1px solid lightgrey;
|
||||||
&.custom-file {
|
&.custom-file {
|
||||||
width: 85px;
|
// TODO remove this class if it doesn't end up getting used any more
|
||||||
height: 100px;
|
|
||||||
}
|
}
|
||||||
.post__load {
|
.post__load {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@@ -133,13 +134,34 @@
|
|||||||
background-position: center;
|
background-position: center;
|
||||||
}
|
}
|
||||||
.post__image {
|
.post__image {
|
||||||
height: 100%;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border: 1px solid #E2E2E2;
|
height: 100%;
|
||||||
background-color: #FFF;
|
background-color: #FFF;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-position: top left;
|
background-position: top left;
|
||||||
}
|
}
|
||||||
|
.post-image__thumbnail {
|
||||||
|
width: 50%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
.post-image__details {
|
||||||
|
width: 50%;
|
||||||
|
height: 100%;
|
||||||
|
background: white;
|
||||||
|
border-left: 1px solid lightgrey;
|
||||||
|
font-size: small;
|
||||||
|
padding: 5px 5px;
|
||||||
|
.post-image__name {
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
.post-image__type {
|
||||||
|
color: grey;
|
||||||
|
}
|
||||||
|
.post-image__size {
|
||||||
|
border-left: 2px;
|
||||||
|
color: grey;
|
||||||
|
}
|
||||||
|
}
|
||||||
a {
|
a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: grey;
|
color: grey;
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user