import { registerComponent, Components } from 'meteor/vulcan:lib'; import { intlShape, FormattedMessage } from 'meteor/vulcan:i18n'; import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import moment from 'moment'; import Button from 'react-bootstrap/lib/Button'; const getLabel = (field, fieldName, collection, intl) => { const schema = collection.simpleSchema()._schema; const fieldSchema = schema[fieldName]; if (fieldSchema) { return intl.formatMessage({id: `${collection._name}.${fieldName}`, defaultMessage: fieldSchema.label}); } else { return fieldName; } } const getTypeName = (field, fieldName, collection) => { const schema = collection.simpleSchema()._schema; const fieldSchema = schema[fieldName]; if (fieldSchema) { const type = fieldSchema.type.singleType; const typeName = typeof type === 'function' ? type.name : type; return typeName; } else { return typeof field; } } const parseImageUrl = value => { const isImage = ['.png', '.jpg', '.gif'].indexOf(value.substr(-4)) !== -1 || ['.webp', '.jpeg' ].indexOf(value.substr(-5)) !== -1; return isImage ? {value}/ : ; } const LimitedString = ({ string }) =>
{string.indexOf(' ') === -1 && string.length > 30 ? {string.substr(0,30)}… : {string} }
export const getFieldValue = (value, typeName) => { if (typeof value === 'undefined' || value === null) { return '' } if (Array.isArray(value)) { typeName = 'Array'; } if (typeof typeName === 'undefined') { typeName = typeof value; } switch (typeName) { case 'Boolean': case 'boolean': case 'Number': case 'number': case 'SimpleSchema.Integer': return {value.toString()}; case 'Array': return
    {value.map((item, index) =>
  1. {getFieldValue(item, typeof item)}
  2. )}
case 'Object': case 'object': return ( {_.map(value, (value, key) => )}
{key} {getFieldValue(value, typeof value)}
) case 'Date': return moment(new Date(value)).format('dddd, MMMM Do YYYY, h:mm:ss'); default: return parseImageUrl(value); } } const CardItem = ({label, value, typeName}) => {label} {getFieldValue(value, typeName)} const CardEdit = (props, context) => }> CardEdit.contextTypes = { intl: intlShape }; const CardEditForm = ({ collection, document, closeModal }) => { closeModal(); }} /> const Card = ({className, collection, document, currentUser, fields}, {intl}) => { const fieldNames = fields ? fields : _.without(_.keys(document), '__typename'); const canEdit = currentUser && collection.options.mutations.edit.check(currentUser, document); return (
{canEdit ? : null} {fieldNames.map((fieldName, index) => )}
); }; Card.displayName = "Card"; Card.propTypes = { className: PropTypes.string, collection: PropTypes.object, document: PropTypes.object, currentUser: PropTypes.object, fields: PropTypes.array, } Card.contextTypes = { intl: intlShape } registerComponent('Card', Card);