2016-11-01 19:27:59 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
2017-01-27 16:13:11 +13:00
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { createStore, bindActionCreators } from 'redux'
|
2017-10-27 10:51:48 +13:00
|
|
|
import { hashHistory } from 'react-router'
|
2016-11-11 23:21:51 +13:00
|
|
|
import FontAwesome from 'react-fontawesome'
|
|
|
|
|
|
2016-11-21 16:26:47 +13:00
|
|
|
import ArtistSentence from './ArtistSentence'
|
2016-12-22 08:46:08 +13:00
|
|
|
import Dater from './Dater'
|
2017-10-27 10:51:48 +13:00
|
|
|
import URILink from './URILink'
|
2016-11-21 16:26:47 +13:00
|
|
|
|
|
|
|
|
import * as helpers from '../helpers'
|
2017-01-27 16:13:11 +13:00
|
|
|
import * as uiActions from '../services/ui/actions'
|
2016-11-21 16:26:47 +13:00
|
|
|
|
2017-01-27 16:13:11 +13:00
|
|
|
class List extends React.Component{
|
2016-11-01 19:27:59 +13:00
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
constructor(props){
|
2016-11-01 19:27:59 +13:00
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 16:54:17 +13:00
|
|
|
handleClick(e, uri){
|
|
|
|
|
|
|
|
|
|
// make sure we haven't clicked a nested link (ie Artist name)
|
2017-10-10 13:05:28 +13:00
|
|
|
if (e.target.tagName.toLowerCase() !== 'a'){
|
2017-10-27 10:51:48 +13:00
|
|
|
hashHistory.push((this.props.link_prefix ? this.props.link_prefix : '') + encodeURIComponent(uri));
|
2017-06-16 20:42:24 +02:00
|
|
|
}
|
2016-11-21 16:54:17 +13:00
|
|
|
}
|
|
|
|
|
|
2017-01-29 11:56:58 +13:00
|
|
|
handleContextMenu(e,item){
|
2017-02-02 09:06:15 +13:00
|
|
|
if (this.props.handleContextMenu){
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
this.props.handleContextMenu(e,item)
|
2017-01-29 11:56:58 +13:00
|
|
|
}
|
2017-01-27 16:13:11 +13:00
|
|
|
}
|
|
|
|
|
|
2016-11-01 19:27:59 +13:00
|
|
|
renderHeader(){
|
2016-12-16 08:32:21 +13:00
|
|
|
if (!this.props.columns || this.props.noheader) return null
|
2016-11-01 19:27:59 +13:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="list-item header cf">
|
|
|
|
|
{
|
2017-10-10 13:05:28 +13:00
|
|
|
this.props.columns.map((col, col_index) => {
|
2017-03-12 16:19:06 +13:00
|
|
|
var className = 'col '+col.name.replace('.','_')
|
|
|
|
|
return <div className={className} key={col_index}>{ col.label ? col.label : col.name }</div>
|
2016-11-01 19:27:59 +13:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
renderValue(row, key_string){
|
2016-12-14 09:13:47 +13:00
|
|
|
var key = key_string.split('.')
|
2016-11-21 16:26:47 +13:00
|
|
|
var value = row
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
for (var i = 0; i < key.length; i++){
|
|
|
|
|
if (typeof(value[key[i]]) === 'undefined'){
|
2016-12-20 08:40:15 +13:00
|
|
|
return <span>-</span>
|
2017-10-10 13:05:28 +13:00
|
|
|
} else if (typeof(value[key[i]]) === 'string' && value[key[i]].replace(' ','') == ''){
|
2016-11-21 16:26:47 +13:00
|
|
|
return <span>-</span>
|
2016-12-16 08:32:21 +13:00
|
|
|
} else {
|
|
|
|
|
value = value[key[i]]
|
2016-11-21 16:26:47 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-22 08:46:08 +13:00
|
|
|
if (key_string === 'added_at') return <span><Dater type="ago" data={value} /> ago</span>
|
2017-10-27 10:51:48 +13:00
|
|
|
if (key_string === 'owner') return <URILink type="user" uri={value.uri}>{value.id}</URILink>
|
2016-12-16 08:32:21 +13:00
|
|
|
if (key[0] === 'artists') return <ArtistSentence artists={value} />
|
|
|
|
|
if (value === true) return <FontAwesome name="check" />
|
|
|
|
|
if (typeof(value) === 'number') return <span>{value.toLocaleString()}</span>
|
2016-11-11 23:21:51 +13:00
|
|
|
return <span>{value}</span>
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 19:27:59 +13:00
|
|
|
render(){
|
2016-12-16 08:32:21 +13:00
|
|
|
if (!this.props.rows) return null
|
2016-11-08 13:36:13 +13:00
|
|
|
|
2017-03-13 13:17:11 +13:00
|
|
|
var className = 'list'
|
|
|
|
|
if (this.props.className){
|
|
|
|
|
className += ' '+this.props.className
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 19:27:59 +13:00
|
|
|
return (
|
2017-03-13 13:17:11 +13:00
|
|
|
<div className={className}>
|
2016-11-01 19:27:59 +13:00
|
|
|
{ this.renderHeader() }
|
|
|
|
|
{
|
2017-10-10 13:05:28 +13:00
|
|
|
this.props.rows.map((row, row_index) => {
|
2016-12-16 08:32:21 +13:00
|
|
|
|
2017-02-03 09:04:47 +13:00
|
|
|
var class_name = 'list-item'
|
2017-10-10 13:05:28 +13:00
|
|
|
if (row.type ) class_name += ' '+row.type
|
2017-02-03 09:04:47 +13:00
|
|
|
|
2016-11-01 19:27:59 +13:00
|
|
|
return (
|
2017-06-16 20:42:24 +02:00
|
|
|
<div
|
|
|
|
|
onClick={e => this.handleClick(e, row.uri)}
|
2017-01-29 11:56:58 +13:00
|
|
|
onContextMenu={e => this.handleContextMenu(e,row)}
|
2017-06-16 20:42:24 +02:00
|
|
|
className={class_name}
|
2017-01-27 16:13:11 +13:00
|
|
|
key={row_index}>
|
2016-11-01 19:27:59 +13:00
|
|
|
{
|
2017-10-10 13:05:28 +13:00
|
|
|
this.props.columns.map((col, col_index) => {
|
2017-03-12 16:19:06 +13:00
|
|
|
var className = 'col '+col.name.replace('.','_')
|
2016-11-02 21:23:35 +13:00
|
|
|
return (
|
2017-03-12 16:19:06 +13:00
|
|
|
<div className={className} key={col_index}>
|
2016-11-21 16:26:47 +13:00
|
|
|
{ this.renderValue(row, col.name) }
|
2016-11-02 21:23:35 +13:00
|
|
|
</div>
|
|
|
|
|
)
|
2016-11-01 19:27:59 +13:00
|
|
|
})
|
|
|
|
|
}
|
2016-11-21 16:54:17 +13:00
|
|
|
</div>
|
2016-11-01 19:27:59 +13:00
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2017-01-27 16:13:11 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
|
return {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
|
|
|
|
uiActions: bindActionCreators(uiActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(List)
|