<commit_before>import React from 'react';
import {IndexLink} from 'react-router';
import Settings from './Config/Settings.jsx';

class ConfigContent extends React.Component {
    constructor(props) {
        super(props);
        this.getConfig = this.getConfig.bind(this);
        this.getServerSettings = this.getServerSettings.bind(this);
        this.updateServerSettings = this.updateServerSettings.bind(this);
        this.handleServerSettingsChange = this.handleServerSettingsChange.bind(this);
        this.formTypeField = this.formTypeField.bind(this);
        this.capitalizeFirstLetter = this.capitalizeFirstLetter.bind(this)
        this.state = {
            config: {},
            serverSettings: {}
        }
    }

    componentDidMount() {
        this.getConfig();
        this.getServerSettings();
    }

    capitalizeFirstLetter(string) {
        return string.charAt(0).toUpperCase() + string.slice(1);
    }

    handleServerSettingsChange(name, e) {
        let fieldValue
        var change = this.state.serverSettings;

        if (e.target.value === "true" || e.target.value === "false") {
          // Ensure Boolean type is used if required
          if (e.target.id === "lan" || e.target.id === "public") {
            if (e.target.value == "true") {
              fieldValue = true
            } else {
              fieldValue = false
            }
            change["visibility"][e.target.id] = fieldValue
            this.setState({serverSettings: change});
            return;
          }
          fieldValue = Boolean(e.target.value)
        } else if (e.target.id === "admins" || e.target.id === "tags") {
          // Split settings values that are stored as arrays<commit_msg>Fixed string to boolean conversion in the configs tab<commit_after>import React from 'react';
import {IndexLink} from 'react-router';
import Settings from './Config/Settings.jsx';

//https://stackoverflow.com/a/1414175
function stringToBoolean(string){
    switch(string.toLowerCase().trim()){
        case "true": case "yes": case "1": return true;
        case "false": case "no": case "0": case null: return false;
        default: return Boolean(string);
    }
}

class ConfigContent extends React.Component {
    constructor(props) {
        super(props);
        this.getConfig = this.getConfig.bind(this);
        this.getServerSettings = this.getServerSettings.bind(this);
        this.updateServerSettings = this.updateServerSettings.bind(this);
        this.handleServerSettingsChange = this.handleServerSettingsChange.bind(this);
        this.formTypeField = this.formTypeField.bind(this);
        this.capitalizeFirstLetter = this.capitalizeFirstLetter.bind(this)
        this.state = {
            config: {},
            serverSettings: {}
        }
    }

    componentDidMount() {
        this.getConfig();
        this.getServerSettings();
    }

    capitalizeFirstLetter(string) {
        return string.charAt(0).toUpperCase() + string.slice(1);
    }

    handleServerSettingsChange(name, e) {
        let fieldValue
        var change = this.state.serverSettings;

        if (e.target.value === "true" || e.target.value === "false") {
          // Ensure Boolean type is used if required
          if (e.target.id === "lan" || e.target.id === "public") {
            if (e.target.value == "true") {
              fieldValue = true
            } else {
              fieldValue = false
            }
            change["visibility"][e.target.id] = fieldValue
            this.setState({serverSettings: change});
            return;
          }
          fieldValue = stringToBoolean(e.target.value)
        } else if (e.target.id === "admins" || e.target.id === "tags") {
          // Split settings values that are stored as arrays
{'fraction_non_alphanumeric': 0.12596128347918323, 'fraction_numerical': 0.003447361442588173, 'mean_word_length': 2.326278659611993, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '5307185', 'n_tokens_mistral': 1045, 'n_tokens_neox': 1022, 'n_words': 218}