<commit_before>/**
 * Created by Mauriel on 8/16/2016.
 */

var sourcePaths = [];
var pathLog = [];
var pathLogIndex = 0;
var isDragging = false;

function getFolderTemplateInstance(folderName) {
    return "<li class='fb-folder droppable draggable' title='" + folderName + "&#13;Type: File Folder'>" +
        "<span class='fb-file-icon fa fa-folder icon-blue'></span>" +
        "<span class='fb-file-name'>" + folderName + "</span>" +
        "<span class='fb-file-type'>File Folder</span>" +
        "<span class='fb-file-size'></span>" +
        "</li>"
}

// Associates file icons with file extensions. Could be improved with a dictionary.
function getFileTemplateInstance(fileName, fileType, logical_type, logical_file_id, fileSize, pk, url) {
    var fileTypeExt = fileName.substr(fileName.lastIndexOf(".") + 1, fileName.length);
    var extIcon = "fa-file-o";

    if (fileName.lastIndexOf(".")) {
        if (fileTypeExt.toUpperCase() == "PDF") {
            extIcon = "fa-file-pdf-o";
        }
        else if (fileTypeExt.toUpperCase() == "XLS" || fileTypeExt.toUpperCase() == "XLT" || fileTypeExt.toUpperCase() == "XML" || fileTypeExt.toUpperCase() == "CSV") {
            extIcon = "fa-file-excel-o";
        }
        else if (fileTypeExt.toUpperCase() == "ZIP" || fileTypeExt.toUpperCase() == "RAR" || fileTypeExt.toUpperCase() == "RAR5") {
            extIcon = "fa-file-zip-o";
        }
        else if (fileTypeExt.toUpperCase() == "DOC" || fileTypeExt.toUpperCase() == "DOCX") {
            extIcon = "fa-file-word-o";
        }
        else if (fileTypeExt.toUpperCase() == "MP3" || fileTypeExt.toUpperCase() == "WAV" || fileTypeExt.toUpperCase() == "WMA") {
            extIcon = "fa-file-audio-o";
        }
        else if (fileTypeExt.toUpperCase() == "MP4" || fileTypeExt.toUpperCase() == "MOV" || fileTypeExt.toUpperCase() == "WMV") {
            extIcon = "fa-file-movie-o";
        }
        else if (fileTypeExt.toUpperCase() == "PNG" || fileTypeExt.toUpperCase() == "JPG" || fileTypeExt.toUpperCase() == "JPEG" || fileTypeExt.toUpperCase() == "GIF" || fileTypeExt.toUpperCase() == "TIF" || fileTypeExt.toUpperCase() == "BMP") {
            extIcon = "fa-file-image-o";
        }
        else if (fileTypeExt.toUpperCase() == "TXT") {
            extIcon = "fa-file-text-o";
        }
        else if (fileTypeExt.toUpperCase() == "PPT" || fileTypeExt.toUpperCase() == "PPTX") {
            extIcon = "fa-file-powerpoint-o";
        }
        else if (fileTypeExt.toUpperCase() == "JS" || fileTypeExt.toUpperCase() == "PY" || fileTypeExt.toUpperCase() == "PHP" || fileTypeExt.toUpperCase() == "JAVA" || fileTypeExt.toUpperCase() == "CS") {
            extIcon = "fa-file-code-o";
        }
    }

    if (logical_type.length > 0){
        var title = '' + fileName + "&#13;Type: " + fileType + "&#13;Size: " + formatBytes(parseInt(fileSize)) + "&#13;Logical Type: " + logical_type;
    }
    else {
        var title = '' + fileName + "&#13;Type: " + fileType + "&#13;Size: " + formatBytes(parseInt(fileSize));
    }
    return "<li data-pk='" + pk + "' data-url='" + url + "' data-logical-file-id='" + logical_file_id + "' class='fb-file draggable' title='" + title + "'>" +
        "<span class='fb-file-icon fa " + extIcon + "'></span>" +
        "<span class='fb-file-name'>" + fileName + "</span>" +
        "<span class='fb-file-type'>" + fileType + " File</span>" +
        "<span class='fb-logical-file-type' data-logical-file-type=" + logical_type + ">" + logical_type + "</span>" +
        "<span class='fb-file-size' data-file-size=" + fileSize + "'>" + formatBytes(parseInt(fileSize)) + "</span></li>"
}

function formatBytes(bytes) {
    if(bytes < 1024) return bytes + " Bytes";
    else if(bytes < 1048576) return(bytes / 1024).toFixed(1) + " KB";
    else if(bytes < 1073741824) return(bytes / 1048576).toFixed(1) + " MB";
    else return(bytes / 1073741824).toFixed(1) + " GB";
}

// Updates the state of toolbar and menu buttons when a selection is made
function updateSelectionMenuContext() {
    var selected = $("#fb-files-container li.ui-selected");

    var flagDisableOpen = false;
    var flagDisableDownload = false;
    var flagDisableRename = false;
    var flagDisablePaste = false;
    var flagDisableZip = false;
    var flagDisableUnzip = false;
    var flagDisableCut = false;
    var flagDisableDelete = false;
    var flagDisableSetGeoRasterFileType = false;
    var flagDisableShowFileMetadata = false;

    if (selected.length > 1) {
        flagDisableRename = true; 
        flagDisableOpen = true;
        flagDisablePaste = true;
        flagDisableZip = true;
        flagDisableSetGeoRasterFileType = true;
        flagDisableShowFileMetadata = true;
    }
    else if (selected.length == 1) {    // Unused for now

    }
    else {
        flagDisableCut = true;
        flagDisableRename = true;
        flagDisableUnzip = true;
        flagDisableZip = true;
        flagDisableDelete = true;
        flagDisableDownload = true;
    }

    if (selected.hasClass("fb-file")) {
        flagDisableOpen = true;
        flagDisablePaste = true;
        flagDisableZip = true;
    }

    if (selected.hasClass("fb-folder")) {
        flagDisableDownload = true;
        flagDisableUnzip = true;
        flagDisableShowFileMetadata = true;
    }

    if (!sourcePaths.length) {
        flagDisablePaste = true;
    }

    for (var i = 0; i < selected.length; i++) {
        var fileName = $(selected[i]).children(".fb-file-name").text();
        var fileExt = fileName.substr(fileName.lastIndexOf(".") + 1, fileName.length);
        var logicalFileType = $(selected[i]).children(".fb-logical-file-type").text();
        console.log(logicalFileType);
        if (fileExt.toUpperCase() != "ZIP") {
            flagDisableUnzip = true;
        }
        if ((fileExt.toUpperCase() != "TIF" && fileExt.toUpperCase() != "ZIP") || logicalFileType != "GenericLogicalFile") {
            flagDisableSetGeoRasterFileType = true;
        }

        if (logicalFileType.length == 0){
            flagDisableShowFileMetadata = true;
        }
    }
    
    var menu = $("#right-click-menu");
    var menu2 = $("#right-click-container-menu");

    // Open
    menu.children("li[data-menu-name='open']").toggleClass("hidden", flagDisableOpen);
    $("#open-separator").toggleClass("hidden", flagDisableOpen);
    if (!menu.children("li[data-menu-name='delete']").length) {
        $("#open-separator").toggleClass("hidden", true);
    }

    // Download
    menu.children("li[data-menu-name='download']").toggleClass("disabled", flagDisableDownload);
    $("#fb-download").toggleClass("disabled", flagDisableDownload);

    // set Geo Raster file type
    menu.children("li[data-menu-name='setgeorasterfiletype']").toggleClass("disabled", flagDisableSetGeoRasterFileType);
    $("#fb-geo-file-type").toggleClass("disabled", flagDisableSetGeoRasterFileType);

    // show file type metadata
    menu.children("li[data-menu-name='showfilemetadata']").toggleClass("disabled", flagDisableShowFileMetadata);
    $("#fb-show-file-metadata").toggleClass("disabled", flagDisableShowFileMetadata);

    // Rename
    menu.children("li[data-menu-name='rename']").toggleClass("disabled", flagDisableRename);
    $("#fb-rename").toggleClass("disabled", flagDisableRename);

    // Zip
    menu.children("li[data-menu-name='zip']").toggleClass("hidden", flagDisableZip);
    $("#fb-zip").toggleClass("disabled", flagDisableZip);

    // Unzip
    menu.children("li[data-menu-name='unzip']").toggleClass("hidden", flagDisableUnzip);
    $("#fb-unzip").toggleClass("disabled", flagDisableUnzip);

    // Cut
    menu.children("li[data-menu-name='cut']").toggleClass("disabled", flagDisableCut);<commit_msg>[#1477] removed menu option to show file metadata<commit_after>/**
 * Created by Mauriel on 8/16/2016.
 */

var sourcePaths = [];
var pathLog = [];
var pathLogIndex = 0;
var isDragging = false;

function getFolderTemplateInstance(folderName) {
    return "<li class='fb-folder droppable draggable' title='" + folderName + "&#13;Type: File Folder'>" +
        "<span class='fb-file-icon fa fa-folder icon-blue'></span>" +
        "<span class='fb-file-name'>" + folderName + "</span>" +
        "<span class='fb-file-type'>File Folder</span>" +
        "<span class='fb-file-size'></span>" +
        "</li>"
}

// Associates file icons with file extensions. Could be improved with a dictionary.
function getFileTemplateInstance(fileName, fileType, logical_type, logical_file_id, fileSize, pk, url) {
    var fileTypeExt = fileName.substr(fileName.lastIndexOf(".") + 1, fileName.length);
    var extIcon = "fa-file-o";

    if (fileName.lastIndexOf(".")) {
        if (fileTypeExt.toUpperCase() == "PDF") {
            extIcon = "fa-file-pdf-o";
        }
        else if (fileTypeExt.toUpperCase() == "XLS" || fileTypeExt.toUpperCase() == "XLT" || fileTypeExt.toUpperCase() == "XML" || fileTypeExt.toUpperCase() == "CSV") {
            extIcon = "fa-file-excel-o";
        }
        else if (fileTypeExt.toUpperCase() == "ZIP" || fileTypeExt.toUpperCase() == "RAR" || fileTypeExt.toUpperCase() == "RAR5") {
            extIcon = "fa-file-zip-o";
        }
        else if (fileTypeExt.toUpperCase() == "DOC" || fileTypeExt.toUpperCase() == "DOCX") {
            extIcon = "fa-file-word-o";
        }
        else if (fileTypeExt.toUpperCase() == "MP3" || fileTypeExt.toUpperCase() == "WAV" || fileTypeExt.toUpperCase() == "WMA") {
            extIcon = "fa-file-audio-o";
        }
        else if (fileTypeExt.toUpperCase() == "MP4" || fileTypeExt.toUpperCase() == "MOV" || fileTypeExt.toUpperCase() == "WMV") {
            extIcon = "fa-file-movie-o";
        }
        else if (fileTypeExt.toUpperCase() == "PNG" || fileTypeExt.toUpperCase() == "JPG" || fileTypeExt.toUpperCase() == "JPEG" || fileTypeExt.toUpperCase() == "GIF" || fileTypeExt.toUpperCase() == "TIF" || fileTypeExt.toUpperCase() == "BMP") {
            extIcon = "fa-file-image-o";
        }
        else if (fileTypeExt.toUpperCase() == "TXT") {
            extIcon = "fa-file-text-o";
        }
        else if (fileTypeExt.toUpperCase() == "PPT" || fileTypeExt.toUpperCase() == "PPTX") {
            extIcon = "fa-file-powerpoint-o";
        }
        else if (fileTypeExt.toUpperCase() == "JS" || fileTypeExt.toUpperCase() == "PY" || fileTypeExt.toUpperCase() == "PHP" || fileTypeExt.toUpperCase() == "JAVA" || fileTypeExt.toUpperCase() == "CS") {
            extIcon = "fa-file-code-o";
        }
    }

    if (logical_type.length > 0){
        var title = '' + fileName + "&#13;Type: " + fileType + "&#13;Size: " + formatBytes(parseInt(fileSize)) + "&#13;Logical Type: " + logical_type;
    }
    else {
        var title = '' + fileName + "&#13;Type: " + fileType + "&#13;Size: " + formatBytes(parseInt(fileSize));
    }
    return "<li data-pk='" + pk + "' data-url='" + url + "' data-logical-file-id='" + logical_file_id + "' class='fb-file draggable' title='" + title + "'>" +
        "<span class='fb-file-icon fa " + extIcon + "'></span>" +
        "<span class='fb-file-name'>" + fileName + "</span>" +
        "<span class='fb-file-type'>" + fileType + " File</span>" +
        "<span class='fb-logical-file-type' data-logical-file-type=" + logical_type + ">" + logical_type + "</span>" +
        "<span class='fb-file-size' data-file-size=" + fileSize + "'>" + formatBytes(parseInt(fileSize)) + "</span></li>"
}

function formatBytes(bytes) {
    if(bytes < 1024) return bytes + " Bytes";
    else if(bytes < 1048576) return(bytes / 1024).toFixed(1) + " KB";
    else if(bytes < 1073741824) return(bytes / 1048576).toFixed(1) + " MB";
    else return(bytes / 1073741824).toFixed(1) + " GB";
}

// Updates the state of toolbar and menu buttons when a selection is made
function updateSelectionMenuContext() {
    var selected = $("#fb-files-container li.ui-selected");

    var flagDisableOpen = false;
    var flagDisableDownload = false;
    var flagDisableRename = false;
    var flagDisablePaste = false;
    var flagDisableZip = false;
    var flagDisableUnzip = false;
    var flagDisableCut = false;
    var flagDisableDelete = false;
    var flagDisableSetGeoRasterFileType = false;

    if (selected.length > 1) {
        flagDisableRename = true; 
        flagDisableOpen = true;
        flagDisablePaste = true;
        flagDisableZip = true;
        flagDisableSetGeoRasterFileType = true;
    }
    else if (selected.length == 1) {    // Unused for now

    }
    else {
        flagDisableCut = true;
        flagDisableRename = true;
        flagDisableUnzip = true;
        flagDisableZip = true;
        flagDisableDelete = true;
        flagDisableDownload = true;
    }

    if (selected.hasClass("fb-file")) {
        flagDisableOpen = true;
        flagDisablePaste = true;
        flagDisableZip = true;
    }

    if (selected.hasClass("fb-folder")) {
        flagDisableDownload = true;
        flagDisableUnzip = true;
    }

    if (!sourcePaths.length) {
        flagDisablePaste = true;
    }

    for (var i = 0; i < selected.length; i++) {
        var fileName = $(selected[i]).children(".fb-file-name").text();
        var fileExt = fileName.substr(fileName.lastIndexOf(".") + 1, fileName.length);
        var logicalFileType = $(selected[i]).children(".fb-logical-file-type").text();
        console.log(logicalFileType);
        if (fileExt.toUpperCase() != "ZIP") {
            flagDisableUnzip = true;
        }
        if ((fileExt.toUpperCase() != "TIF" && fileExt.toUpperCase() != "ZIP") || logicalFileType != "GenericLogicalFile") {
            flagDisableSetGeoRasterFileType = true;
        }

        if(logicalFileType === "GeoRasterLogicalFile"){
            flagDisableDelete = true;
            flagDisableRename = true;
        }
    }
    
    var menu = $("#right-click-menu");
    var menu2 = $("#right-click-container-menu");

    // Open
    menu.children("li[data-menu-name='open']").toggleClass("hidden", flagDisableOpen);
    $("#open-separator").toggleClass("hidden", flagDisableOpen);
    if (!menu.children("li[data-menu-name='delete']").length) {
        $("#open-separator").toggleClass("hidden", true);
    }

    // Download
    menu.children("li[data-menu-name='download']").toggleClass("disabled", flagDisableDownload);
    $("#fb-download").toggleClass("disabled", flagDisableDownload);

    // set Geo Raster file type
    menu.children("li[data-menu-name='setgeorasterfiletype']").toggleClass("disabled", flagDisableSetGeoRasterFileType);
    $("#fb-geo-file-type").toggleClass("disabled", flagDisableSetGeoRasterFileType);

    // Rename
    menu.children("li[data-menu-name='rename']").toggleClass("disabled", flagDisableRename);
    $("#fb-rename").toggleClass("disabled", flagDisableRename);

    // Zip
    menu.children("li[data-menu-name='zip']").toggleClass("hidden", flagDisableZip);
    $("#fb-zip").toggleClass("disabled", flagDisableZip);

    // Unzip
    menu.children("li[data-menu-name='unzip']").toggleClass("hidden", flagDisableUnzip);
    $("#fb-unzip").toggleClass("disabled", flagDisableUnzip);

    // Cut
    menu.children("li[data-menu-name='cut']").toggleClass("disabled", flagDisableCut);
{'fraction_non_alphanumeric': 0.17339292756671487, 'fraction_numerical': 0.01018798475088734, 'mean_word_length': 3.036879808967896, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3812224', 'n_tokens_mistral': 4961, 'n_tokens_neox': 4827, 'n_words': 892}