<commit_before>﻿import React from "react";
import ReactDOM from "react-dom";
import axios from "axios";
import Pusher from "pusher-js";
import {GoogleMapLoader, GoogleMap, Marker} from "react-google-maps";

import 'bootstrap/dist/css/bootstrap.css';
import '../../Styles/site.css';
import './eventEdit.jsx';

const getBaseUrl = function () {
    var url = window.location.href;
    if (url.substr(-1) !== '/') url += '/';
    return url;
}

class UserRow extends React.Component {
    render() {
        var cells = [];

        cells.push(<td>{this.props.row.userName}</td>);
        this.props.row.choices.forEach(function(userChoice) {
            var choiceHtml =
                userChoice === 1 ? <span className="glyphicon glyphicon-ok-sign"></span> :
            userChoice === 0 ? <span className="glyphicon glyphicon-remove-sign"></span> :
            <span className="glyphicon glyphicon-question-sign"></span>;

            var choiceCss =
                userChoice === 1 ? "ep-yes" :
                userChoice === 0 ? "ep-no" :
                userChoice === 2 ? "ep-may" :
                "ep-blanc";

            cells.push(<td className={choiceCss}>{choiceHtml}</td>);
        });

        return (<tr>{cells}</tr>);
    }
}

class TableHeader extends React.Component {
    render() {
        var dateCells = [];
        var hourCells = [];

        this.props.header.dates.forEach(function(date) {
            dateCells.push(<th colSpan={date.hours.length}>{date.value}</th>);
            date.hours.forEach(function(hour){
                hourCells.push(<th>{hour}</th>);
            });
        });

        return (
    <thead>
    <tr><th></th>{dateCells}</tr>
    <tr><th></th>{hourCells}</tr>
    </thead>
);
    }
}

class UserEditRow extends React.Component {
    constructor(props) {
        super(props);

        this.state = this.getBlancForm();
    }

    getBlancForm()
    {
        var arr = new Array(this.props.hourCount).fill(-1);
        return {
            editRow: {
                userName: "",
                hours: arr 
            }
        };
    }

    resetForm(){
        this.setState(this.getBlancForm());
    }

    setHourState(index, value)
    {
        var newHours = this.state.editRow.hours.slice();
        newHours[index] = value;
        this.setState({editRow: {userName: this.state.editRow.userName, hours: newHours}});
    }

    handleNameChange(e)
    {
        this.setState({editRow: {userName: e.target.value, hours: this.state.editRow.hours}});
    }

    handleYes(index) {
        this.setHourState(index,1)
    }

    handleMaybe(index){
        this.setHourState(index,2)
    }

    handleNo(index){
        this.setHourState(index,0)
    }

    handleSave(){
        axios
             .post(getBaseUrl()+`save-choices`, this.state.editRow)
             .catch(() => alert('Something went wrong :( '));
    }

    render() {
        if(this.props.hourCount !== this.state.editRow.hours.length)
        {
            this.resetForm();
        }

        var checkboxCells = [];

        var _that = this;

        this.state.editRow.hours.forEach(function(choice, index) {
            
            var choiceCss =
                choice === 1 ? "ep-yes" :
                choice === 0 ? "ep-no" :
                choice === 2 ? "ep-may" :
                "ep-blanc";

            checkboxCells.push(
                <td className={choiceCss}><commit_msg>Fixed path problem in eventDetail<commit_after>﻿import React from "react";
import ReactDOM from "react-dom";
import axios from "axios";
import Pusher from "pusher-js";
import {GoogleMapLoader, GoogleMap, Marker} from "react-google-maps";

import 'bootstrap/dist/css/bootstrap.css';
import '../../Styles/site.css';
import './eventEdit.jsx';

const getBaseUrl = function () {
    var url = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname+"/";
    return url;
}

const getCssClass = function (userChoice)
{
    return userChoice === 1 ? "ep-yes" :
           userChoice === 0 ? "ep-no" :
           userChoice === 2 ? "ep-may" :
           "ep-blanc";
}

class UserRow extends React.Component {
    render() {
        var cells = [];

        cells.push(<td>{this.props.row.userName}</td>);
        this.props.row.choices.forEach(function(userChoice) {
            var choiceHtml =
                userChoice === 1 ? <span className="glyphicon glyphicon-ok-sign"></span> :
            userChoice === 0 ? <span className="glyphicon glyphicon-remove-sign"></span> :
            <span className="glyphicon glyphicon-question-sign"></span>;

            cells.push(<td className={getCssClass(userChoice)}>{choiceHtml}</td>);
        });

        return (<tr>{cells}</tr>);
    }
}

class TableHeader extends React.Component {
    render() {
        var dateCells = [];
        var hourCells = [];

        this.props.header.dates.forEach(function(date) {
            dateCells.push(<th colSpan={date.hours.length}>{date.value}</th>);
            date.hours.forEach(function(hour){
                hourCells.push(<th>{hour}</th>);
            });
        });

        return (
    <thead>
    <tr><th></th>{dateCells}</tr>
    <tr><th></th>{hourCells}</tr>
    </thead>
);
    }
}

class UserEditRow extends React.Component {
    constructor(props) {
        super(props);

        this.state = this.getBlancForm();
    }

    getBlancForm()
    {
        var arr = new Array(this.props.hourCount).fill(-1);
        return {
            editRow: {
                userName: "",
                hours: arr 
            }
        };
    }

    resetForm(){
        this.setState(this.getBlancForm());
    }

    setHourState(index, value)
    {
        var newHours = this.state.editRow.hours.slice();
        newHours[index] = value;
        this.setState({editRow: {userName: this.state.editRow.userName, hours: newHours}});
    }

    handleNameChange(e)
    {
        this.setState({editRow: {userName: e.target.value, hours: this.state.editRow.hours}});
    }

    handleYes(index) {
        this.setHourState(index,1)
    }

    handleMaybe(index){
        this.setHourState(index,2)
    }

    handleNo(index){
        this.setHourState(index,0)
    }

    handleSave(){
        axios
             .post(getBaseUrl()+`save-choices`, this.state.editRow)
             .catch(() => alert('Something went wrong :( '));
    }

    render() {
        if(this.props.hourCount !== this.state.editRow.hours.length)
        {
            this.resetForm();
        }

        var checkboxCells = [];

        var _that = this;

        this.state.editRow.hours.forEach(function(choice, index) {
            
            checkboxCells.push(
                <td className={getCssClass(choice)}>
{'fraction_non_alphanumeric': 0.1552822640391169, 'fraction_numerical': 0.0032597421840272634, 'mean_word_length': 2.0147387226440374, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 59, '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': '5101171', 'n_tokens_mistral': 2154, 'n_tokens_neox': 2036, 'n_words': 345}