<commit_before>import { updateApp } from "./update-app";

import {
    DEMO_INFORMATION,
    UNWEIGHTED_DEMO_PATH,
    WEIGHTED_DEMO_PATH,
    SCHADE_INPUT_PATH,
    SCHADE_OUTPUT_PATH
} from "./constants";

const submittedFilename = $upload => {
    let path = $upload.val();
    let fakePathCheck = path.search("\\\\") + 1;

    while (fakePathCheck) {
        path = path.substring(fakePathCheck);
        fakePathCheck = path.search("\\\\") + 1;
    }

    return path;
};

const createFileForm = $upload => {
    const formData = new FormData();
    formData.append("file", $upload[0].files[0]);
    return formData;
};

const uploadEpilogue = event => {
    if (window.ga) {
        window.ga("send", "pageview", {
            page: "/GRNsight/upload",
            sessionControl: "start"
        });
    }

    $("a.upload > input[type=file]").val("");
    event.preventDefault();
};
const disableUpload = state => {
    $("#upload").attr("disabled", state);
    $("#upload-sif").attr("disabled", state);
    $("#upload-graphml").attr("disabled", state);
};

const uploadHandler = (uploader) => {
    return function (event) { // Must be `function` due to use of `this`.
        const $upload = $(this);
        const filename = submittedFilename($upload);
        console.log(submittedFilename($upload));
        if ($upload[0].files[0].size < 2000000) {
            // disable upload button to prevent multiple uploads
            disableUpload(true);
            const formData = createFileForm($upload);
            uploader(filename, formData);
            uploadEpilogue(event);
        } else {
            let errorString = "The file uploaded is too large. Please try again with a file smaller than 1 MB.";
            $("#error").html(errorString);
            $("#errorModal").modal("show");
        }
    };
};

const networkErrorDisplayer = xhr => {
    // re-enable upload button
    disableUpload(false);
    // Deleted status, error for argument because it was never used<commit_msg>annotate todo<commit_after>import { updateApp } from "./update-app";

import {
    DEMO_INFORMATION,
    UNWEIGHTED_DEMO_PATH,
    WEIGHTED_DEMO_PATH,
    SCHADE_INPUT_PATH,
    SCHADE_OUTPUT_PATH
} from "./constants";

const submittedFilename = $upload => {
    let path = $upload.val();
    let fakePathCheck = path.search("\\\\") + 1;

    while (fakePathCheck) {
        path = path.substring(fakePathCheck);
        fakePathCheck = path.search("\\\\") + 1;
    }

    return path;
};

const createFileForm = $upload => {
    const formData = new FormData();
    formData.append("file", $upload[0].files[0]);
    return formData;
};

const uploadEpilogue = event => {
    if (window.ga) {
        window.ga("send", "pageview", {
            page: "/GRNsight/upload",
            sessionControl: "start"
        });
    }

    $("a.upload > input[type=file]").val("");
    event.preventDefault();
};
const disableUpload = state => {
    $("#upload").attr("disabled", state);
    $("#upload-sif").attr("disabled", state);
    $("#upload-graphml").attr("disabled", state);
};

const uploadHandler = (uploader) => {
    return function (event) { // Must be `function` due to use of `this`.
        const $upload = $(this);
        const filename = submittedFilename($upload); // TODO: remove before master release (beta@4.0.6)
        if ($upload[0].files[0].size < 2000000) {
            // disable upload button to prevent multiple uploads
            disableUpload(true);
            const formData = createFileForm($upload);
            uploader(filename, formData);
            uploadEpilogue(event);
        } else {
            let errorString = "The file uploaded is too large. Please try again with a file smaller than 1 MB.";
            $("#error").html(errorString);
            $("#errorModal").modal("show");
        }
    };
};

const networkErrorDisplayer = xhr => {
    // re-enable upload button
    disableUpload(false);
    // Deleted status, error for argument because it was never used
{'fraction_non_alphanumeric': 0.15129611166500498, 'fraction_numerical': 0.007726819541375872, 'mean_word_length': 2.618575293056808, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '2648365', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1160, 'n_words': 287}