From 3cf70771cb45cc16ec33ffe44e7a1a4799d8f395 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 23 Jun 2020 23:18:07 +0200 Subject: adding web app base --- .../frontend/common/tableIndex.component.js | 129 +++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 animism-align/frontend/common/tableIndex.component.js (limited to 'animism-align/frontend/common/tableIndex.component.js') diff --git a/animism-align/frontend/common/tableIndex.component.js b/animism-align/frontend/common/tableIndex.component.js new file mode 100644 index 0000000..a34a9e9 --- /dev/null +++ b/animism-align/frontend/common/tableIndex.component.js @@ -0,0 +1,129 @@ +import React, { Component } from 'react' +import { Link } from 'react-router-dom' +import { connect } from 'react-redux' + +import { formatDateTime } from '../util' +import { Loader, Swatch, Dot } from '../common' + +/* + '/collection/' + row.id + '/show/' }, + { name: 'username', type: 'string' }, + { name: 'date', type: 'date' }, + { name: 'notes', type: 'text' }, + ]} + /> +*/ + +export default class TableIndex extends Component { + componentDidMount() { + this.props.actions && this.props.actions.index() + } + + render() { + const { data, els, title, fields, noHeadings, notFoundMessage } = this.props + if (data.loading) { + return + } + if (!els && (!data.lookup || !data.order.length)) { + return ( +
+

{title}

+

+ {notFoundMessage || ("No " + title)} +

+
+ ) + } + return ( +
+

{title}

+
+ {!noHeadings && } + {els + ? els.map(el => ) + : data.order.map(id => ) + } +
+
+ ) + } +} + +const RowHeadings = ({fields}) => { + return ( +
+ {fields.map(field => { + if (field.type === 'gallery') return + let css = {} + if (field.width) { + css = { width: field.width, maxWidth: 'none', flex: 'none', } + } + if (field.flex) { + css.flex = field.flex + } + return
{(field.title || field.name).replace(/_/g, ' ')}
+ })} +
+ ) +} + +const Row = ({ row, fields }) => { + return ( +
+ {fields.map(field => { + let value = field.valueFn ? field.valueFn(row) : row[field.name] + let css = {} + if (field.type === 'date' && (row.updated_at || row.created_at || value)) { + // value = (value || "").split('.')[0] + value = formatDateTime(row.updated_at || row.created_at || value) + } else if (field.type === 'text') { + value = String(value || "").trim().split('\n')[0].replace(/^#+/, '').substr(0, 100) + } else if (field.type === 'color') { + value = + } else if (field.type === 'bool') { + value = + } else if (field.type === 'str') { + value = String(value || "").replace(/_/g, ' ') + } else if (field.type === 'gallery') { + return + } + if (field.width) { + css = { width: field.width, maxWidth: 'none', flex: 'none', } + } + if (field.flex) { + css.flex = field.flex + } + let className + if (field.style) { + className = field.type + ' ' + field.style + } else { + className = field.type + } + value =
{value}
+ if (field.link) { + return {value} + } + return value + })} +
+ ) +} + +const GalleryRow = ({ media }) => { + return ( +
+
+ {media.map(img => ( + + + + ))} +
+
+ ) +} -- cgit v1.2.3-70-g09d2