<commit_before>var React = require('react/addons');
var FixedDataTable = require('fixed-data-table');
var utils = require('../../../configuration/js/utils');
var strftime = require('strftime');
var urls = require('../../../flux-chat/js/utils/urlUtils');

import { Router, Route, Link } from 'react-router';
import { history } from 'react-router/lib/BrowserHistory';

import {get, post} from "../../../js/request";
import TicketViewer from './TicketViewer.jsx';

var update = React.addons.update;
var Table = FixedDataTable.Table;
var Column = FixedDataTable.Column;

var TicketTable = React.createClass({

    getInitialState () {
	return {
	    dataList: [],
	}
    },

    componentDidMount () {
	get(urls.api.tickets())
	    .done(res => {
		this.setState({dataList: res});
	    });
	// TODO .fail(
    },

    _rowGetter(index) {
	return this.state.dataList[index];
    },

    _cellDataGetter(key, row) {
	// ticket api data is nested (not sure how/if can flatten)
	return row.case_note[key];
    },

    _renderDate (ISODateString) {
	var date = utils.ISODateStringToDate(ISODateString);
	return strftime('%d/%m/%Y | %I:%M%p', date);
    },

    _renderTitle (title, key, ticket, rowIndex) {
	return (
	    <Link to={urls.ticket(ticket.id)}>{title}</Link>
	);
    },
    
    render () {
      var showingTicket;
      let index;
	if (this.props.params.id !== undefined) {
	    index = this.state.dataList.findIndex(
	      t => t.id == this.props.params.id);
          showingTicket = this.state.dataList[index];
	}
	return (
	    <div>
		{!showingTicket ?
		 <Table
		 rowHeight={50}
		 rowGetter={this._rowGetter}
		 rowsCount={this.state.dataList.length}
		 width={900}
		 maxHeight={600}
		 headerHeight={50}>
		 <Column
		 label="CLIENT"
		 width={150}
		 dataKey="client"
		 cellDataGetter={this._cellDataGetter}
		 />
		 <Column
		 label="PROFESSIONAL"
		 width={150}
		 dataKey="author"
		 cellDataGetter={this._cellDataGetter}
		 />
		 <Column
		 label="TITLE"
		 width={150}
		 dataKey="title"
		 cellDataGetter={this._cellDataGetter}
		 cellRenderer={this._renderTitle}
		 />
		 <Column
		 label="CREATED AT"
		 width={150}
		 dataKey="created_at"
		 cellRenderer={this._renderDate}
		 />
		 <Column
		 label="ASSIGNED TO"
		 width={150}
		 dataKey="assigned_to"
		 />
		 <Column
		 label="RESOLVED?"
		 width={150}
		 dataKey="is_resolved"
		 />
		 </Table>
		 : null}
		 {showingTicket ?
		  <div>
		  <TicketViewer ticket={showingTicket} />
		  <Link
		  className="btn btn-default"
		  to={urls.tickets()}
		  >
		  Close
		  </Link>
		  {this._isResolvable(showingTicket) ?
		      <button
		      className="btn btn-success"
		      onClick={this._resolve.bind(this, showingTicket)}
		      >
		      Resolve<commit_msg>Fix #42 ticket resolve button<commit_after>var React = require('react/addons');
var FixedDataTable = require('fixed-data-table');
var utils = require('../../../configuration/js/utils');
var strftime = require('strftime');
var urls = require('../../../flux-chat/js/utils/urlUtils');

import { Router, Route, Link } from 'react-router';
import { history } from 'react-router/lib/BrowserHistory';

import {get, post} from "../../../js/request";
import TicketViewer from './TicketViewer.jsx';

var update = React.addons.update;
var Table = FixedDataTable.Table;
var Column = FixedDataTable.Column;

var TicketTable = React.createClass({

    getInitialState () {
	return {
	    dataList: [],
	}
    },

    componentDidMount () {
	get(urls.api.tickets())
	    .done(res => {
		this.setState({dataList: res});
	    });
	// TODO .fail(
    },

    _rowGetter(index) {
	return this.state.dataList[index];
    },

    _cellDataGetter(key, row) {
	// ticket api data is nested (not sure how/if can flatten)
	return row.case_note[key];
    },

    _renderDate (ISODateString) {
	var date = utils.ISODateStringToDate(ISODateString);
	return strftime('%d/%m/%Y | %I:%M%p', date);
    },

    _renderTitle (title, key, ticket, rowIndex) {
	return (
	    <Link to={urls.ticket(ticket.id)}>{title}</Link>
	);
    },
    
    render () {
      var showingTicket;
      let index;
	if (this.props.params.id !== undefined) {
	    index = this.state.dataList.findIndex(
	      t => t.id == this.props.params.id);
          showingTicket = this.state.dataList[index];
	}
	return (
	    <div>
		{!showingTicket ?
		 <Table
		 rowHeight={50}
		 rowGetter={this._rowGetter}
		 rowsCount={this.state.dataList.length}
		 width={900}
		 maxHeight={600}
		 headerHeight={50}>
		 <Column
		 label="CLIENT"
		 width={150}
		 dataKey="client"
		 cellDataGetter={this._cellDataGetter}
		 />
		 <Column
		 label="PROFESSIONAL"
		 width={150}
		 dataKey="author"
		 cellDataGetter={this._cellDataGetter}
		 />
		 <Column
		 label="TITLE"
		 width={150}
		 dataKey="title"
		 cellDataGetter={this._cellDataGetter}
		 cellRenderer={this._renderTitle}
		 />
		 <Column
		 label="CREATED AT"
		 width={150}
		 dataKey="created_at"
		 cellRenderer={this._renderDate}
		 />
		 <Column
		 label="ASSIGNED TO"
		 width={150}
		 dataKey="assigned_to"
		 />
		 <Column
		 label="RESOLVED?"
		 width={150}
		 dataKey="is_resolved"
		 />
		 </Table>
		 : null}
		 {showingTicket ?
		  <div>
		  <TicketViewer ticket={showingTicket} />
		  <Link
		  className="btn btn-default"
		  to={urls.tickets()}
		  >
		  Close
		  </Link>
		  {this._isResolvable(showingTicket) ?
		      <button
		      className="btn btn-success"
		      onClick={this._resolve.bind(this, index)}
		      >
		      Resolve
{'fraction_non_alphanumeric': 0.1592066957787482, 'fraction_numerical': 0.010553129548762736, 'mean_word_length': 2.997818181818182, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 39, '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': '6534677', 'n_tokens_mistral': 2105, 'n_tokens_neox': 1823, 'n_words': 333}