Skip to content

Commit

Permalink
moved thumb check to field level
Browse files Browse the repository at this point in the history
  • Loading branch information
cadriel committed Nov 16, 2017
1 parent c8aceb8 commit 4058435
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 14 deletions.
1 change: 1 addition & 0 deletions fields/types/Type.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var DEFAULT_OPTION_KEYS = [
'collapse',
'dependsOn',
'autoCleanup',
'thumb',
];

/**
Expand Down
12 changes: 4 additions & 8 deletions fields/types/file/FileField.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ module.exports = Field.create({
label: PropTypes.string,
note: PropTypes.string,
path: PropTypes.string.isRequired,
thumb: PropTypes.bool,
value: PropTypes.shape({
filename: PropTypes.string,
// TODO: these are present but not used in the UI,
// should we start using them?
// showThumbnail: PropTypes.bool
// filetype: PropTypes.string,
// originalname: PropTypes.string,
// path: PropTypes.string,
Expand Down Expand Up @@ -82,9 +82,6 @@ module.exports = Field.create({
const href = this.props.value ? this.props.value.url : undefined;
return href && href.match(/\.(jpeg|jpg|gif|png|svg)$/i) != null;
},
showThumb () {
return this.props.value && this.props.value.showthumb;
},

// ==============================
// METHODS
Expand Down Expand Up @@ -216,14 +213,13 @@ module.exports = Field.create({
);
},
renderUI () {
const { label, note, path } = this.props;
const { label, note, path, thumb } = this.props;
const isImage = this.isImage();
const hasFile = this.hasFile();
const showThumb = this.showThumb();

const previews = (
<div style={(isImage && showThumb) ? { marginBottom: '1em' } : null}>
{isImage && showThumb && this.renderImagePreview()}
<div style={(isImage && thumb) ? { marginBottom: '1em' } : null}>
{isImage && thumb && this.renderImagePreview()}
{hasFile && this.renderFileNameAndChangeMessage()}
</div>
);
Expand Down
6 changes: 0 additions & 6 deletions lib/storage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var SCHEMA_TYPES = {
path: String, // the path (e.g directory) the file is stored in; not the full path to the file
originalname: String, // the original (uploaded) name of the file; useful when filename generated
url: String, // publicly accessible URL of the stored file
showthumb: Boolean, // Whether to attempt to load an image thumbnail
};

/**
Expand All @@ -44,7 +43,6 @@ var SCHEMA_FIELD_DEFAULTS = {
path: false,
originalname: false,
url: false,
showthumb: false,
};

// TODO: We could support custom schema mappings for backwards compatibilty
Expand Down Expand Up @@ -126,10 +124,6 @@ function normalizeFile (file, schema, callback) {
|| (file.path) ? path.parse(file.path).base : 'unnamedfile';
}

if (!file.showthumb) {
file.showthumb = schema.showthumb;
}

if (schema.size && !file.size) {
getSize(file, function (err, size) {
if (err) return callback(err);
Expand Down

0 comments on commit 4058435

Please sign in to comment.