<commit_before>import React from 'react';
import ReactDOM from 'react-dom';

class Project extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            userId: this.props.userId,
            projectId: this.props.projectId,
            institutionId: this.props.institutionId,
            details: null,
            stats: null,
            imageryList: null,
            mapConfig: null,
            plotList: null,
            lonMin: "",
            latMin: "",
            lonMax: "",
            latMax: "",
            newSurveyQuestionName: "",
            newValueEntry: {},
            projectList: null,
            templateId: "0",
            // FIXME: Add these attributes to the JSON database
            dateCreated: null,
            datePublished: null,
            dateClosed: null,
            dateArchived: null,
            stateTransitions: {
                nonexistent: "Create",
                unpublished: "Publish",
                published: "Close",
                closed: "Archive",
                archived: "Archive"
            },
        };
        this.setPrivacyLevel = this.setPrivacyLevel.bind(this);
        this.setPlotDistribution = this.setPlotDistribution.bind(this);
        this.setPlotShape = this.setPlotShape.bind(this);
        this.setSampleDistribution = this.setSampleDistribution.bind(this);
        this.configureGeoDash = this.configureGeoDash.bind(this);
        this.downloadPlotData = this.downloadPlotData.bind(this);
        this.downloadSampleData = this.downloadSampleData.bind(this);
        this.closeProject = this.closeProject.bind(this);
        this.changeAvailability = this.changeAvailability.bind(this);
        this.setBaseMapSource = this.setBaseMapSource.bind(this);
        this.addSurveyQuestion = this.addSurveyQuestion.bind(this);
        this.removeSurveyQuestion = this.removeSurveyQuestion.bind(this);
        this.addSurveyQuestionRow = this.addSurveyQuestionRow.bind(this);
        this.getParentSurveyQuestions = this.getParentSurveyQuestions.bind(this);
        this.setProjectTemplate = this.setProjectTemplate.bind(this);
        this.getSurveyQuestionByName = this.getSurveyQuestionByName.bind(this);
        this.getParentSurveyQuestionAnswers=this.getParentSurveyQuestionAnswers.bind(this);
        this.removeSurveyQuestionRow = this.removeSurveyQuestionRow.bind(this);
        this.handleInputName = this.handleInputName.bind(this);
        this.handleInputColor = this.handleInputColor.bind(this);
        this.handleInputParent = this.handleInputParent.bind(this);
        this.handleChange = this.handleChange.bind(this);
        this.topoSort = this.topoSort.bind(this);
        this.createProject = this.createProject.bind(this);
        this.getParentSurveyAnswers=this.getParentSurveyAnswers.bind(this);
    };

    componentDidMount() {
        this.initialization(this.props.documentRoot, this.state.userId, this.state.projectId, this.state.institutionId);
    }

    initialization(documentRoot, userId, projectId, institutionId) {
        if (this.state.details == null) {
            this.getProjectById(projectId);
        }
        else {

            if (this.state.details.id == 0) {
                this.state.details.privacyLevel = "private";
                this.state.details.projectDistribution = "random";
                this.state.details.plotShape = "circle";
                this.state.details.sampleDistribution = "random";
                this.getProjectList(userId, projectId);
            }
            else if (this.state.details.id != 0) {
                if (document.getElementById("num-plots") != null) {
                    if (document.getElementById("plot-distribution-gridded").checked)
                        document.getElementById("plot-design-text").innerHTML = "Description about gridded";
                    if (document.getElementById("plot-distribution-random").checked)
                        document.getElementById("plot-design-text").innerHTML = "Description about random";
                    if (document.getElementById("plot-distribution-csv").checked)
                        document.getElementById("plot-design-text").innerHTML ="Description about csv upload";
                    if (document.getElementById("plot-distribution-shp").checked)
                        document.getElementById("plot-design-text").innerHTML ="Description about shp upload";

                    if (document.getElementById("sample-distribution-gridded").checked)
                        document.getElementById("sample-design-text").innerHTML = "Description about gridded";
                    if (document.getElementById("sample-distribution-random").checked)
                        document.getElementById("sample-design-text").innerHTML = "Description about random";
                    if (document.getElementById("sample-distribution-csv").checked)
                        document.getElementById("sample-design-text").innerHTML = "Description about csv upload";
                    if (document.getElementById("sample-distribution-shp").checked)
                        document.getElementById("sample-design-text").innerHTML = "Description about shp upload";

                }
                this.getProjectStats(projectId);
            }
            if (this.state.imageryList == null) {
                this.getImageryList(institutionId);
            }
            else this.updateUnmanagedComponents(projectId);
        }
    }

    // var logFormData=function(formData)
    // {
    //     console.log(new Map(formData.entries()));
    // };
    createProject() {
        if (confirm("Do you REALLY want to create this project?")) {
            utils.show_element("spinner");
            var formData = new FormData(document.getElementById("project-design-form"));
            formData.append("institution", this.props.institutionId);
            formData.append("plot-distribution-csv-file", document.getElementById("plot-distribution-csv-file").files[0]);
            formData.append("sample-values", JSON.stringify(this.state.details.sampleValues));
            var ref = this;
            $.ajax({
                url: this.props.documentRoot + "/create-project",
                type: "POST",
                async: true,
                crossDomain: true,
                contentType: false,
                processData: false,
                data: formData
            }).fail(function () {
                utils.hide_element("spinner");
                alert("Error creating project. See console for details.");
            }).done(function (data) {
                var detailsNew = ref.state.details;
                detailsNew.availability = "unpublished";
                ref.setState({details: detailsNew});
                utils.hide_element("spinner");
                var newProjectId = data;
                window.location = ref.props.documentRoot + "/project/" + newProjectId;
            });
        }
    }<commit_msg>Uploading CSV and SHP files on the create project page for plots and samples.<commit_after>import React from 'react';
import ReactDOM from 'react-dom';

class Project extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            userId: this.props.userId,
            projectId: this.props.projectId,
            institutionId: this.props.institutionId,
            details: null,
            stats: null,
            imageryList: null,
            mapConfig: null,
            plotList: null,
            lonMin: "",
            latMin: "",
            lonMax: "",
            latMax: "",
            newSurveyQuestionName: "",
            newValueEntry: {},
            projectList: null,
            templateId: "0",
            // FIXME: Add these attributes to the JSON database
            dateCreated: null,
            datePublished: null,
            dateClosed: null,
            dateArchived: null,
            stateTransitions: {
                nonexistent: "Create",
                unpublished: "Publish",
                published: "Close",
                closed: "Archive",
                archived: "Archive"
            },
        };
        this.setPrivacyLevel = this.setPrivacyLevel.bind(this);
        this.setPlotDistribution = this.setPlotDistribution.bind(this);
        this.setPlotShape = this.setPlotShape.bind(this);
        this.setSampleDistribution = this.setSampleDistribution.bind(this);
        this.configureGeoDash = this.configureGeoDash.bind(this);
        this.downloadPlotData = this.downloadPlotData.bind(this);
        this.downloadSampleData = this.downloadSampleData.bind(this);
        this.closeProject = this.closeProject.bind(this);
        this.changeAvailability = this.changeAvailability.bind(this);
        this.setBaseMapSource = this.setBaseMapSource.bind(this);
        this.addSurveyQuestion = this.addSurveyQuestion.bind(this);
        this.removeSurveyQuestion = this.removeSurveyQuestion.bind(this);
        this.addSurveyQuestionRow = this.addSurveyQuestionRow.bind(this);
        this.getParentSurveyQuestions = this.getParentSurveyQuestions.bind(this);
        this.setProjectTemplate = this.setProjectTemplate.bind(this);
        this.getSurveyQuestionByName = this.getSurveyQuestionByName.bind(this);
        this.getParentSurveyQuestionAnswers=this.getParentSurveyQuestionAnswers.bind(this);
        this.removeSurveyQuestionRow = this.removeSurveyQuestionRow.bind(this);
        this.handleInputName = this.handleInputName.bind(this);
        this.handleInputColor = this.handleInputColor.bind(this);
        this.handleInputParent = this.handleInputParent.bind(this);
        this.handleChange = this.handleChange.bind(this);
        this.topoSort = this.topoSort.bind(this);
        this.createProject = this.createProject.bind(this);
        this.getParentSurveyAnswers=this.getParentSurveyAnswers.bind(this);
    };

    componentDidMount() {
        this.initialization(this.props.documentRoot, this.state.userId, this.state.projectId, this.state.institutionId);
    }

    initialization(documentRoot, userId, projectId, institutionId) {
        if (this.state.details == null) {
            this.getProjectById(projectId);
        }
        else {

            if (this.state.details.id == 0) {
                this.state.details.privacyLevel = "private";
                this.state.details.projectDistribution = "random";
                this.state.details.plotShape = "circle";
                this.state.details.sampleDistribution = "random";
                this.getProjectList(userId, projectId);
            }
            else if (this.state.details.id != 0) {
                if (document.getElementById("num-plots") != null) {
                    if (document.getElementById("plot-distribution-gridded").checked)
                        document.getElementById("plot-design-text").innerHTML = "Description about gridded";
                    if (document.getElementById("plot-distribution-random").checked)
                        document.getElementById("plot-design-text").innerHTML = "Description about random";
                    if (document.getElementById("plot-distribution-csv").checked)
                        document.getElementById("plot-design-text").innerHTML ="Description about csv upload";
                    if (document.getElementById("plot-distribution-shp").checked)
                        document.getElementById("plot-design-text").innerHTML ="Description about shp upload";

                    if (document.getElementById("sample-distribution-gridded").checked)
                        document.getElementById("sample-design-text").innerHTML = "Description about gridded";
                    if (document.getElementById("sample-distribution-random").checked)
                        document.getElementById("sample-design-text").innerHTML = "Description about random";
                    if (document.getElementById("sample-distribution-csv").checked)
                        document.getElementById("sample-design-text").innerHTML = "Description about csv upload";
                    if (document.getElementById("sample-distribution-shp").checked)
                        document.getElementById("sample-design-text").innerHTML = "Description about shp upload";

                }
                this.getProjectStats(projectId);
            }
            if (this.state.imageryList == null) {
                this.getImageryList(institutionId);
            }
            else this.updateUnmanagedComponents(projectId);
        }
    }

    // var logFormData=function(formData)
    // {
    //     console.log(new Map(formData.entries()));
    // };
    createProject() {
        if (confirm("Do you REALLY want to create this project?")) {
            utils.show_element("spinner");
            var formData = new FormData(document.getElementById("project-design-form"));
            formData.append("institution", this.props.institutionId);
            formData.append("plot-distribution-csv-file", document.getElementById("plot-distribution-csv-file").files[0]);
            formData.append("plot-distribution-shp-file", document.getElementById("plot-distribution-shp-file").files[0]);
            formData.append("sample-distribution-csv-file", document.getElementById("sample-distribution-csv-file").files[0]);
            formData.append("sample-distribution-shp-file", document.getElementById("sample-distribution-shp-file").files[0]);
            formData.append("sample-values", JSON.stringify(this.state.details.sampleValues));
            var ref = this;
            $.ajax({
                url: this.props.documentRoot + "/create-project",
                type: "POST",
                async: true,
                crossDomain: true,
                contentType: false,
                processData: false,
                data: formData
            }).fail(function () {
                utils.hide_element("spinner");
                alert("Error creating project. See console for details.");
            }).done(function (data) {
                var detailsNew = ref.state.details;
                detailsNew.availability = "unpublished";
                ref.setState({details: detailsNew});
                utils.hide_element("spinner");
                var newProjectId = data;
                window.location = ref.props.documentRoot + "/project/" + newProjectId;
            });
        }
    }
{'fraction_non_alphanumeric': 0.1112412985043766, 'fraction_numerical': 0.000758150113722517, 'mean_word_length': 2.1557198782079166, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '238601', 'n_tokens_mistral': 3691, 'n_tokens_neox': 3517, 'n_words': 577}