<commit_before>import * as acv_m from "./ace-view.js";

// ----------------------------------------------------------------------

// args: {parent:, uri:, view_mode:, coloring:, }
export function show_antigenic_map_widget(args) {
    const widget_options = {
        view_mode: args.view_mode || "best-projection",
        coloring: args.coloring || "default",
        api: new Api({uri: args.uri})
    };
    new acv_m.AntigenicMapWidget(args.parent, args.uri + "?acv=ace", widget_options);
}

// ----------------------------------------------------------------------

class Api
{
    constructor(args) {
        this.uri = args.uri;
    }

    download_pdf(args) {
        this._download({command: {C: "download_pdf"}, suffix: ".pdf"});
    }

    // download_ace(args) {
    //     this._download({command: Object.assign({C: "download_ace", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // download_save(args) {
    //     this._download({command: Object.assign({C: "download_lispmds_save", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // download_layout_plain(args) {
    //     this._download({command: Object.assign({C: "download_layout_plain", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // download_layout_csv(args) {
    //     this._download({command: Object.assign({C: "download_layout_csv", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // download_table_map_distances_plain(args) {
    //     this._download({command: Object.assign({C: "download_table_map_distances_plain", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // download_table_map_distances_csv(args) {
    //     this._download({command: Object.assign({C: "download_table_map_distances_csv", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // download_error_lines(args) {
    //     this._download({command: Object.assign({C: "download_error_lines", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // download_distances_between_all_points_plain(args) {
    //     this._download({command: Object.assign({C: "download_distances_between_all_points_plain", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // download_distances_between_all_points_csv(args) {
    //     this._download({command: Object.assign({C: "download_distances_between_all_points_csv", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // // {command:, blob_type:}
    _download(args) {
        $.post({
            url: this.uri + "?acv=post",
            data: JSON.stringify(args.command),
            cache: false,
            xhr: () => { let xhr = new XMLHttpRequest(); xhr.responseType= 'blob'; return xhr; }
        }).done(result => {
            const pathname = this.uri.split("/");
            const url = window.URL.createObjectURL(result);
            const link = $(`<a href='${url}' download='${pathname[pathname.length - 1] + args.suffix}'></a>`).appendTo($("body"));
            link[0].click();
            link.remove();
            window.setTimeout(() =>  window.URL.revokeObjectURL(url), 100);   // For Firefox it is necessary to delay revoking the ObjectURL
        });
    }
}

// ----------------------------------------------------------------------
/// Local Variables:
/// eval: (if (fboundp 'eu-rename-buffer) (eu-rename-buffer))
/// End:<commit_msg>downloading pdf via apache mod plugin<commit_after>import * as acv_m from "./ace-view.js";

// ----------------------------------------------------------------------

// args: {parent:, uri:, view_mode:, coloring:, }
export function show_antigenic_map_widget(args) {
    const widget_options = {
        view_mode: args.view_mode || "best-projection",
        coloring: args.coloring || "default",
        api: new Api({uri: args.uri})
    };
    new acv_m.AntigenicMapWidget(args.parent, args.uri + "?acv=ace", widget_options);
}

// ----------------------------------------------------------------------

class Api
{
    constructor(args) {
        this.uri = args.uri;
    }

    download_pdf(args) {
        this._download({command: {C: "download_pdf"}, suffix: ".pdf"});
    }

    download_ace(args) {
        this._download({command: {C: "download_ace"}, suffix: ".ace"});
    }

    download_save(args) {
        this._download({command: {C: "download_save"}, suffix: ".save"});
    }

    // download_layout_plain(args) {
    //     this._download({command: Object.assign({C: "download_layout_plain", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // download_layout_csv(args) {
    //     this._download({command: Object.assign({C: "download_layout_csv", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // download_table_map_distances_plain(args) {
    //     this._download({command: Object.assign({C: "download_table_map_distances_plain", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // download_table_map_distances_csv(args) {
    //     this._download({command: Object.assign({C: "download_table_map_distances_csv", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // download_error_lines(args) {
    //     this._download({command: Object.assign({C: "download_error_lines", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // download_distances_between_all_points_plain(args) {
    //     this._download({command: Object.assign({C: "download_distances_between_all_points_plain", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // download_distances_between_all_points_csv(args) {
    //     this._download({command: Object.assign({C: "download_distances_between_all_points_csv", id: this.source_id}, args), blob_type: "application/octet-stream"});
    // }

    // // {command:, blob_type:}
    _download(args) {
        $.post({
            url: this.uri + "?acv=post",
            data: JSON.stringify(args.command),
            cache: false,
            xhr: () => { let xhr = new XMLHttpRequest(); xhr.responseType= 'blob'; return xhr; }
        }).done(result => {
            const pathname = this.uri.split("/");
            let filename = pathname[pathname.length - 1];
            if (filename.substr(filename.length - args.suffix.length, args.suffix.length) !== args.suffix)
                filename = filename + args.suffix;
            const url = window.URL.createObjectURL(result);
            const link = $(`<a href='${url}' download='${filename}'></a>`).appendTo($("body"));
            link[0].click();
            link.remove();
            window.setTimeout(() =>  window.URL.revokeObjectURL(url), 100);   // For Firefox it is necessary to delay revoking the ObjectURL
        });
    }
}

// ----------------------------------------------------------------------
/// Local Variables:
/// eval: (if (fboundp 'eu-rename-buffer) (eu-rename-buffer))
/// End:
{'fraction_non_alphanumeric': 0.2197986577181208, 'fraction_numerical': 0.0013982102908277406, 'mean_word_length': 2.4126908396946565, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 65, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5430546', 'n_tokens_mistral': 2206, 'n_tokens_neox': 2149, 'n_words': 366}