<commit_before>
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { createStore, bindActionCreators } from 'redux'
import { hashHistory, Link } from 'react-router'
import FontAwesome from 'react-fontawesome'

import ArtistSentence from './ArtistSentence'
import Dater from './Dater'

import * as helpers from '../helpers'
import * as uiActions from '../services/ui/actions'

class List extends React.Component{

	constructor(props) {
		super(props);
	}

	handleClick(e, uri){

		// make sure we haven't clicked a nested link (ie Artist name)
		if( e.target.tagName.toLowerCase() !== 'a' ){
			hashHistory.push( this.props.link_prefix + uri );
		}		
	}

	handleContextMenu(e,item){
		if (this.props.handleContextMenu){
			e.preventDefault()
			this.props.handleContextMenu(e,item)
		}
	}

	renderHeader(){
		if (!this.props.columns || this.props.noheader) return null

		return (
			<div className="list-item header cf">
				{
					this.props.columns.map( (col, col_index) => {
						var className = 'col '+col.name.replace('.','_')
						return <div className={className} key={col_index}>{ col.label ? col.label : col.name }</div>
					})
				}
			</div>
		)
	}

	renderValue( row, key_string ){
		var key = key_string.split('.')
		var value = row

		for (var i = 0; i < key.length; i++) {
			if (typeof(value[key[i]]) === 'undefined') {
				return <span>-</span>
			} else if ( typeof(value[key[i]]) === 'string' && value[key[i]].replace(' ','') == '') {
				return <span>-</span>
			} else {
				value = value[key[i]]
			}
		}

		if (key_string === 'added_at') return <span><Dater type="ago" data={value} /> ago</span>
		if (key_string === 'owner') return <Link to={global.baseURL+'user/'+ value.uri}>{value.id}</Link>
		if (key[0] === 'artists') return <ArtistSentence artists={value} />
		if (value === true) return <FontAwesome name="check" />
		if (typeof(value) === 'number') return <span>{value.toLocaleString()}</span>
		return <span>{value}</span>
	}

	render(){
		if (!this.props.rows) return null

		var className = 'list'
		if (this.props.className){
			className += ' '+this.props.className
		}

		return (
			<div className={className}>
				{ this.renderHeader() }
				{
					this.props.rows.map( (row, row_index) => {

						var class_name = 'list-item'
						if( row.type ) class_name += ' '+row.type

						return (
							<div 
								onClick={e => this.handleClick(e, row.uri)} 
								onContextMenu={e => this.handleContextMenu(e,row)}
								className={class_name} 
								key={row_index}>
								{
									this.props.columns.map( (col, col_index) => {
										var className = 'col '+col.name.replace('.','_')
										return (
											<div className={className} key={col_index}>
												{ this.renderValue(row, col.name) }
											</div>
										)
									})
								}
							</div>
						)
					})
				}<commit_msg>Load complete local folder structure, fixes #131<commit_after>
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { createStore, bindActionCreators } from 'redux'
import { hashHistory, Link } from 'react-router'
import FontAwesome from 'react-fontawesome'

import ArtistSentence from './ArtistSentence'
import Dater from './Dater'

import * as helpers from '../helpers'
import * as uiActions from '../services/ui/actions'

class List extends React.Component{

	constructor(props) {
		super(props);
	}

	handleClick(e, uri){

		// make sure we haven't clicked a nested link (ie Artist name)
		if( e.target.tagName.toLowerCase() !== 'a' ){
			hashHistory.push( this.props.link_prefix + encodeURIComponent(uri) );
		}
	}

	handleContextMenu(e,item){
		if (this.props.handleContextMenu){
			e.preventDefault()
			this.props.handleContextMenu(e,item)
		}
	}

	renderHeader(){
		if (!this.props.columns || this.props.noheader) return null

		return (
			<div className="list-item header cf">
				{
					this.props.columns.map( (col, col_index) => {
						var className = 'col '+col.name.replace('.','_')
						return <div className={className} key={col_index}>{ col.label ? col.label : col.name }</div>
					})
				}
			</div>
		)
	}

	renderValue( row, key_string ){
		var key = key_string.split('.')
		var value = row

		for (var i = 0; i < key.length; i++) {
			if (typeof(value[key[i]]) === 'undefined') {
				return <span>-</span>
			} else if ( typeof(value[key[i]]) === 'string' && value[key[i]].replace(' ','') == '') {
				return <span>-</span>
			} else {
				value = value[key[i]]
			}
		}

		if (key_string === 'added_at') return <span><Dater type="ago" data={value} /> ago</span>
		if (key_string === 'owner') return <Link to={global.baseURL+'user/'+ value.uri}>{value.id}</Link>
		if (key[0] === 'artists') return <ArtistSentence artists={value} />
		if (value === true) return <FontAwesome name="check" />
		if (typeof(value) === 'number') return <span>{value.toLocaleString()}</span>
		return <span>{value}</span>
	}

	render(){
		if (!this.props.rows) return null

		var className = 'list'
		if (this.props.className){
			className += ' '+this.props.className
		}

		return (
			<div className={className}>
				{ this.renderHeader() }
				{
					this.props.rows.map( (row, row_index) => {

						var class_name = 'list-item'
						if( row.type ) class_name += ' '+row.type

						return (
							<div
								onClick={e => this.handleClick(e, row.uri)}
								onContextMenu={e => this.handleContextMenu(e,row)}
								className={class_name}
								key={row_index}>
								{
									this.props.columns.map( (col, col_index) => {
										var className = 'col '+col.name.replace('.','_')
										return (
											<div className={className} key={col_index}>
												{ this.renderValue(row, col.name) }
											</div>
										)
									})
								}
							</div>
						)
					})
				}
{'fraction_non_alphanumeric': 0.17488021902806297, 'fraction_numerical': 0.0011978097193702942, 'mean_word_length': 2.9280913978494625, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7118010', 'n_tokens_mistral': 2462, 'n_tokens_neox': 1950, 'n_words': 434}