<commit_before>const React = require('react')
const e = React.createElement
const Component = React.Component
const bindActionCreators = require('redux').bindActionCreators
const connect = require('react-redux').connect
const Dialog = require('material-ui/Dialog').default
const BottomNavigation = require('material-ui/BottomNavigation').BottomNavigation
const BottomNavigationItem = require('material-ui/BottomNavigation').BottomNavigationItem
const Paper = require('material-ui/Paper').default
const RadioButton = require('material-ui/RadioButton').RadioButton
const RadioButtonGroup = require('material-ui/RadioButton').RadioButtonGroup
const IconAdd = require('material-ui/svg-icons/content/add-box').default
const FlatButton = require('material-ui/FlatButton').default
const TextField = require('material-ui/TextField').default
const Tabs = require('material-ui/Tabs').Tabs
const Tab = require('material-ui/Tabs').Tab
const ProjectsActions = require('../actions/projects')
const StatusActions = require('../actions/status')
const LoadingActions = require('../actions/loading')
const dialog = require('electron').remote.dialog
const path = require('path')
const fsp = require('fs-promise')
const nodegit = require('../utils/nodegit').nodegit
const remoteCallbacks = require('../utils/remoteCallbacks')

const TAB_URL   = 'TAB_URL'
const TAB_LOCAL = 'TAB_LOCAL'

class ProjectAdd extends Component {

	constructor(props) {
		super(props)

		this.state = {
			openAddModal: false,
			directoryPath: '',
			url: '',
			active: TAB_LOCAL,
		}
	}

	getDirectory() {
		const dialogDirectories = dialog.showOpenDialog({properties: ['openDirectory']})
		if (!dialogDirectories) {
			return
		}
		const repoDirectory = dialogDirectories[0]

		this.handlePathChange(null, repoDirectory)
	}

	setActiveTab(active) {
		const newState = Object.assign({}, this.state, { active })
		this.setState(newState)
	}

	handlePathChange(e, value) {
		const newState = Object.assign({}, this.state, { directoryPath: value })
		this.setState(newState)
	}

	handleURLChange(e, value) {
		const newState = Object.assign({}, this.state, { url: value })
		this.setState(newState)
	}

	appendProject(project) {
		const newProjects = this.props.projects.list.concat([project])
		this.props.actions.projects.setProjects(newProjects)
	}

	getURLField() {
		return (
			e(
				TextField,
				{
					name: 'url',
					type: 'url',
					hintText: 'Adresa repozitáře',
					value: this.state.url,
					onChange: this.handleURLChange.bind(this),
				}
			)
		)
	}

	getDirectoryField() {
		return (
			e(
				'div',
				null,
				e(
					TextField,
					{
						name: 'path',
						hintText: 'Umístění v tomto zařízení',
						value: this.state.directoryPath,
						onChange: this.handlePathChange.bind(this),
					}
				),
				e(
					FlatButton,
					{
						label: 'Zvolit adresář',
						style: {
							verticalAlign: 'middle',
						},
						onTouchTap: this.getDirectory.bind(this),
					}
				)
			)
		)
	}

	openAddModal(open) {
		const newState = Object.assign({}, this.state, { openAddModal: open })
		this.setState(newState)
	}

	addProject() {
		const url = this.state.url
		const localPath = this.state.directoryPath
		const project = {
			name: path.basename(localPath),
			note: localPath,
			path: localPath,
		}
		this.openAddModal(false)

		this.props.actions.loading.IncrementLoadingJobs()
		Promise.resolve()
			.then(() => {
				if (this.state.active === TAB_LOCAL) {
					return this.prepareLocalProject(localPath)
				} else if (this.state.active === TAB_URL) {
					return this.prepareUrlProject(localPath, url)
				}
			})
			.then(() => {
				this.appendProject(project)
				this.props.actions.status.addStatus(
					`Byl přidán projekt: ${project.name}`,
					'Vrátit zpět',
					() => {
						this.props.actions.projects.removeProject(project)
					}
				)
			})
			.catch((error) => {
				console.error(error)
			})
			.then(() => {
				this.props.actions.loading.DecrementLoadingJobs()
			})
	}


	prepareLocalProject(path) {
		let errorMessage = null
		return Promise.resolve()
			.then(() => {
				return fsp.stat(path)
					.catch((error) => {
						console.warn(error)
						errorMessage = 'Umístění projektu nenalezeno'
						throw new Error('Location not found.')
					})
			})
			.then(() => {
				return nodegit.Repository.open(path)
					.catch((error) => {
						console.warn(error)
						errorMessage = 'Umístění neobsahuje projekt'
						throw new Error('Invalid location.')
					})
			})
			.catch((error) => {
				if (errorMessage) {
					this.props.actions.status.addStatus(
						errorMessage
					)
				}
				throw error
			})
	}

<commit_msg>Project add: note about not initialized<commit_after>const React = require('react')
const e = React.createElement
const Component = React.Component
const bindActionCreators = require('redux').bindActionCreators
const connect = require('react-redux').connect
const Dialog = require('material-ui/Dialog').default
const BottomNavigation = require('material-ui/BottomNavigation').BottomNavigation
const BottomNavigationItem = require('material-ui/BottomNavigation').BottomNavigationItem
const Paper = require('material-ui/Paper').default
const RadioButton = require('material-ui/RadioButton').RadioButton
const RadioButtonGroup = require('material-ui/RadioButton').RadioButtonGroup
const IconAdd = require('material-ui/svg-icons/content/add-box').default
const FlatButton = require('material-ui/FlatButton').default
const TextField = require('material-ui/TextField').default
const Tabs = require('material-ui/Tabs').Tabs
const Tab = require('material-ui/Tabs').Tab
const ProjectsActions = require('../actions/projects')
const StatusActions = require('../actions/status')
const LoadingActions = require('../actions/loading')
const dialog = require('electron').remote.dialog
const path = require('path')
const fsp = require('fs-promise')
const nodegit = require('../utils/nodegit').nodegit
const remoteCallbacks = require('../utils/remoteCallbacks')

const TAB_URL   = 'TAB_URL'
const TAB_LOCAL = 'TAB_LOCAL'

class ProjectAdd extends Component {

	constructor(props) {
		super(props)

		this.state = {
			openAddModal: false,
			directoryPath: '',
			url: '',
			active: TAB_LOCAL,
		}
	}

	getDirectory() {
		const dialogDirectories = dialog.showOpenDialog({properties: ['openDirectory']})
		if (!dialogDirectories) {
			return
		}
		const repoDirectory = dialogDirectories[0]

		this.handlePathChange(null, repoDirectory)
	}

	setActiveTab(active) {
		const newState = Object.assign({}, this.state, { active })
		this.setState(newState)
	}

	handlePathChange(e, value) {
		const newState = Object.assign({}, this.state, { directoryPath: value })
		this.setState(newState)
	}

	handleURLChange(e, value) {
		const newState = Object.assign({}, this.state, { url: value })
		this.setState(newState)
	}

	appendProject(project) {
		const newProjects = this.props.projects.list.concat([project])
		this.props.actions.projects.setProjects(newProjects)
	}

	getURLField() {
		return (
			e(
				TextField,
				{
					name: 'url',
					type: 'url',
					hintText: 'Adresa repozitáře',
					value: this.state.url,
					onChange: this.handleURLChange.bind(this),
				}
			)
		)
	}

	getDirectoryField() {
		return (
			e(
				'div',
				null,
				e(
					TextField,
					{
						name: 'path',
						hintText: 'Umístění v tomto zařízení',
						value: this.state.directoryPath,
						onChange: this.handlePathChange.bind(this),
					}
				),
				e(
					FlatButton,
					{
						label: 'Zvolit adresář',
						style: {
							verticalAlign: 'middle',
						},
						onTouchTap: this.getDirectory.bind(this),
					}
				)
			)
		)
	}

	openAddModal(open) {
		const newState = Object.assign({}, this.state, { openAddModal: open })
		this.setState(newState)
	}

	addProject() {
		const url = this.state.url
		const localPath = this.state.directoryPath
		const project = {
			name: path.basename(localPath),
			note: localPath,
			path: localPath,
		}
		this.openAddModal(false)

		this.props.actions.loading.IncrementLoadingJobs()
		Promise.resolve()
			.then(() => {
				if (this.state.active === TAB_LOCAL) {
					return this.prepareLocalProject(localPath)
				} else if (this.state.active === TAB_URL) {
					return this.prepareUrlProject(localPath, url)
				}
			})
			.then(() => {
				this.appendProject(project)
				this.props.actions.status.addStatus(
					`Byl přidán projekt: ${project.name}`,
					'Vrátit zpět',
					() => {
						this.props.actions.projects.removeProject(project)
					}
				)
			})
			.catch((error) => {
				console.error(error)
			})
			.then(() => {
				this.props.actions.loading.DecrementLoadingJobs()
			})
	}


	prepareLocalProject(path) {
		let errorMessage = null
		return Promise.resolve()
			.then(() => {
				return fsp.stat(path)
					.catch((error) => {
						console.warn(error)
						errorMessage = 'Umístění projektu nenalezeno'
						throw new Error('Location not found.')
					})
			})
			.then(() => {
				return nodegit.Repository.open(path)
					.catch((error) => {
						console.warn(error)
						this.props.actions.status.addStatus(
							'Umístění neobsahuje projekt'
						)
						errorMessage = 'Použijte dřívě vytvořený'
						throw new Error('Invalid location.')
					})
			})
			.catch((error) => {
				if (errorMessage) {
					this.props.actions.status.addStatus(
						errorMessage
					)
				}
				throw error
			})
	}


{'fraction_non_alphanumeric': 0.13952254641909814, 'fraction_numerical': 0.00021220159151193635, 'mean_word_length': 3.433678269049859, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '3488463', 'n_tokens_mistral': 3714, 'n_tokens_neox': 2996, 'n_words': 549}