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'
|
|
|
|
|
import { hashHistory, Link } 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'
|
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
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
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)
|
|
|
|
|
if( e.target.tagName.toLowerCase() !== 'a' ){
|
2017-01-14 09:12:53 +13:00
|
|
|
hashHistory.push( this.props.link_prefix + uri );
|
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">
|
|
|
|
|
{
|
|
|
|
|
this.props.columns.map( (col, col_index) => {
|
2016-11-21 16:26:47 +13:00
|
|
|
return <div className={'col w'+col.width} key={col_index}>{ col.label ? col.label : col.name }</div>
|
2016-11-01 19:27:59 +13:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-14 09:13:47 +13:00
|
|
|
renderValue( row, key_string ){
|
|
|
|
|
var key = key_string.split('.')
|
2016-11-21 16:26:47 +13:00
|
|
|
var value = row
|
|
|
|
|
|
2016-12-16 08:32:21 +13:00
|
|
|
for (var i = 0; i < key.length; i++) {
|
2016-12-20 08:40:15 +13:00
|
|
|
if (typeof(value[key[i]]) === 'undefined') {
|
|
|
|
|
return <span>-</span>
|
|
|
|
|
} 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>
|
2016-12-21 15:24:07 +13:00
|
|
|
if (key_string === 'owner') return <Link to={global.baseURL+'user/'+ value.uri}>{value.id}</Link>
|
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
|
|
|
|
2016-11-01 19:27:59 +13:00
|
|
|
return (
|
|
|
|
|
<div className="list">
|
|
|
|
|
{ this.renderHeader() }
|
|
|
|
|
{
|
|
|
|
|
this.props.rows.map( (row, row_index) => {
|
2016-12-16 08:32:21 +13:00
|
|
|
|
|
|
|
|
var className = 'list-item'
|
|
|
|
|
if( row.type ) className += ' '+row.type
|
|
|
|
|
|
2016-11-01 19:27:59 +13:00
|
|
|
return (
|
2017-01-27 16:13:11 +13:00
|
|
|
<div
|
|
|
|
|
onClick={e => this.handleClick(e, row.uri)}
|
2017-01-29 11:56:58 +13:00
|
|
|
onContextMenu={e => this.handleContextMenu(e,row)}
|
2017-01-27 16:13:11 +13:00
|
|
|
className={className}
|
|
|
|
|
key={row_index}>
|
2016-11-01 19:27:59 +13:00
|
|
|
{
|
|
|
|
|
this.props.columns.map( (col, col_index) => {
|
2016-11-02 21:23:35 +13:00
|
|
|
return (
|
|
|
|
|
<div className={'col w'+col.width} 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:26:47 +13:00
|
|
|
{ this.props.show_source_icon ? <FontAwesome className="source" name={helpers.sourceIcon(row.uri)} /> : null }
|
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)
|