<commit_before>import React from "react";

import ReviewForm from "./ReviewForm";

import {convertSampleValuesToSurveyQuestions} from "../utils/surveyUtils";
import {ProjectContext} from "./constants";

export default class ManageProject extends React.Component {
    constructor(props) {
        super(props);
    }

    componentDidMount() {
        this.context.processModal("Loading Project Details", this.getProjectDetails);
    }

    /// API Calls

    getProjectDetails = () =>
        Promise.all([this.getProjectById(this.context.projectId),
                     this.getProjectImagery(this.context.projectId),
                     this.getProjectPlots(this.context.projectId)])
            .catch(response => {
                console.log(response);
                alert("Error retrieving the project info. See console for details.");
            });

    getProjectById = (projectId) =>
        fetch(`/get-project-by-id?projectId=${projectId}`)
            .then(response => response.ok ? response.json() : Promise.reject(response))
            .then(data => {
                if (data === "") {
                    alert("No project found with ID " + projectId + ".");
                    window.location = "/home";
                } else {
                    const newSurveyQuestions = convertSampleValuesToSurveyQuestions(data.sampleValues);
                    this.context.setProjectDetails({...data, surveyQuestions: newSurveyQuestions});
                    this.context.setContextState({originalProject: {...data, surveyQuestions: newSurveyQuestions}});
                }
            })
            .catch(() => Promise.reject("Error retrieving the project."));

    // TODO: just return with the project info
    getProjectImagery = (projectId) =>
        fetch(`/get-project-imagery?projectId=${projectId}`)
            .then(response => response.ok ? response.json() : Promise.reject(response))
            .then(data => {
                this.context.setProjectDetails({projectImageryList: data.map(imagery => imagery.id)});
            })
            .catch(() => Promise.reject("Error retrieving the project imagery list."));

    getProjectPlots = (projectId) =>
        fetch(`/get-project-plots?projectId=${projectId}&max=300`)
            .then(response => response.ok ? response.json() : Promise.reject(response))
            .then(data => this.context.setProjectDetails({plots: data}))
            .catch(() => Promise.reject("Error retrieving the plot list."));

    render() {
        return (
            <div
                id="review-project"
                className="d-flex flex-column full-height align-items-center p-3"
            >
                <div
                    style={{
                        display: "flex",
                        height: "100%",
                        justifyContent: "center",
                        width: "100%",
                        overflow: "auto",
                    }}
                >
                    <div
                        className="col-7 px-0 mr-2 overflow-auto bg-lightgray"
                        style={{border: "1px solid black", borderRadius: "6px"}}
                    >
                        <h2 className="bg-lightgreen w-100 py-1">Project Details</h2>
                        <div className="px-3 pb-3">
                            <ReviewForm/>
                        </div>
                    </div>
                    <div
                        className="col-4 px-0 mr-2 overflow-auto bg-lightgray"
                        style={{border: "1px solid black", borderRadius: "6px"}}
                    >
                        <h2 className="bg-lightgreen w-100 py-1">Project Management</h2>
                        <div className="p-3">
                            <ProjectManagement/>
                        </div>
                    </div>
                </div>
            </div>
        );
    }
}
ManageProject.contextType = ProjectContext;

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

        this.projectStates = {
            unpublished: {
                button: "Publish",
                update: this.publishProject,
                description: "Admins can review, edit, and test collecting the project.  Publish the project in order for users to begin collection.",
                canEdit: true,
            },
            published: {
                button: "Close",
                update: this.closeProject,
                description: "Users can begin collecting.  Limited changes to the project details can be made.  Close the project to prevent anymore updates.",
                canEdit: true,
            },
            closed: {
                button: "Reopen",
                update: this.publishProject,
                description: "The project is closed to all changes.  Reopen the project for additional collection.",
                canEdit: false,
            },
        };
    }

    /// API Calls

    publishProject = () => {
        const unpublished = this.context.availability === "unpublished";
        const message = unpublished<commit_msg>emergancy fix<commit_after>import React from "react";

import ReviewForm from "./ReviewForm";

import {convertSampleValuesToSurveyQuestions} from "../utils/surveyUtils";
import {ProjectContext} from "./constants";

export default class ManageProject extends React.Component {
    constructor(props) {
        super(props);
    }

    componentDidMount() {
        this.context.processModal("Loading Project Details", this.getProjectDetails);
    }

    /// API Calls

    getProjectDetails = () =>
        Promise.all([this.getProjectById(this.context.projectId),
                     this.getProjectImagery(this.context.projectId),
                     this.getProjectPlots(this.context.projectId)])
            .catch(response => {
                console.log(response);
                alert("Error retrieving the project info. See console for details.");
            });

    getProjectById = (projectId) =>
        fetch(`/get-project-by-id?projectId=${projectId}`)
            .then(response => response.ok ? response.json() : Promise.reject(response))
            .then(data => {
                if (data === "") {
                    alert("No project found with ID " + projectId + ".");
                    window.location = "/home";
                } else {
                    const newSurveyQuestions = convertSampleValuesToSurveyQuestions(data.sampleValues);
                    this.context.setProjectDetails({...data, surveyQuestions: newSurveyQuestions});
                    this.context.setContextState({originalProject: {...data, surveyQuestions: newSurveyQuestions}});
                }
            })
            .catch(() => Promise.reject("Error retrieving the project."));

    // TODO: just return with the project info
    getProjectImagery = (projectId) =>
        fetch(`/get-project-imagery?projectId=${projectId}`)
            .then(response => response.ok ? response.json() : Promise.reject(response))
            .then(data => {
                this.context.setProjectDetails({projectImageryList: data.map(imagery => imagery.id)});
            })
            .catch(() => Promise.reject("Error retrieving the project imagery list."));

    getProjectPlots = (projectId) =>
        fetch(`/get-project-plots?projectId=${projectId}&max=300`)
            .then(response => response.ok ? response.json() : Promise.reject(response))
            .then(data => this.context.setProjectDetails({plots: data}))
            .catch(() => Promise.reject("Error retrieving the plot list."));

    render() {
        return (
            <div
                id="review-project"
                className="d-flex flex-column full-height align-items-center p-3"
            >
                <div
                    style={{
                        display: "flex",
                        height: "100%",
                        justifyContent: "center",
                        width: "100%",
                        overflow: "auto",
                    }}
                >
                    <div
                        className="col-7 px-0 mr-2 overflow-auto bg-lightgray"
                        style={{border: "1px solid black", borderRadius: "6px"}}
                    >
                        <h2 className="bg-lightgreen w-100 py-1">Project Details</h2>
                        <div className="px-3 pb-3">
                            <ReviewForm/>
                        </div>
                    </div>
                    <div
                        className="col-4 px-0 mr-2 overflow-auto bg-lightgray"
                        style={{border: "1px solid black", borderRadius: "6px"}}
                    >
                        <h2 className="bg-lightgreen w-100 py-1">Project Management</h2>
                        <div className="p-3">
                            <ProjectManagement/>
                        </div>
                    </div>
                </div>
            </div>
        );
    }
}
ManageProject.contextType = ProjectContext;

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

        this.projectStates = {
            unpublished: {
                button: "Publish",
                update: this.publishProject,
                description: "Admins can review, edit, and test collecting the project.  Publish the project in order for users to begin collection.",
                canEdit: false,
            },
            published: {
                button: "Close",
                update: this.closeProject,
                description: "Users can begin collecting.  Limited changes to the project details can be made.  Close the project to prevent anymore updates.",
                canEdit: false,
            },
            closed: {
                button: "Reopen",
                update: this.publishProject,
                description: "The project is closed to all changes.  Reopen the project for additional collection.",
                canEdit: false,
            },
        };
    }

    /// API Calls

    publishProject = () => {
        const unpublished = this.context.availability === "unpublished";
        const message = unpublished
{'fraction_non_alphanumeric': 0.11381642512077295, 'fraction_numerical': 0.00676328502415459, 'mean_word_length': 1.5357667809897109, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 71, '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': '1984647', 'n_tokens_mistral': 2578, 'n_tokens_neox': 2415, 'n_words': 568}