<commit_before>{% extends "base.html" %}

{% block title %}File Manager{% endblock %}

{% block content %}
{% if flash.info is defined %}
<div class="col-md-9">
    {{ flash.info.0|raw }}
</div>
{% endif %}
<div class="col-md-9" id="load_files">
    <h4 class="nopad"><span data-bind="text: currentDir"></span> {% if ( permission.has('files.create') ) or (
        permission.has('files.upload') )
        %}
        <small><a href="#" class="text-muted"><i class="fa fa-plus"></i></a></small>
        {% endif %}
    </h4>
    <table class="table table-striped table-bordered table-hover" id="filemanager">
        <thead>
        <tr>
            <th style="width:2%;text-align:center;"></th>
            <th style="width:55%">{{ l.render('node.files.name') }}</th>
            <th style="width:15%">{{ l.render('node.files.size') }}</th>
            <th style="width:20%">{{ l.render('node.files.modified') }}</th>
            <th style="width:10%;text-align:center;">{{ l.render('string.options') }}</th>
        </tr>
        </thead>
        <tbody data-bind="template: {name: displayMode, foreach: files }">
        </tbody>
    </table>
</div>

<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.1/knockout-min.js'></script>

<script type="text/javascript">
    var fileModel = {
        files: ko.observableArray(),
        displayMode: function (file) {
            return file.isFile ? 'fm-file' : file.name == '..' ? 'fm-up' : 'fm-folder';
        },
        currentDir: ko.observable('/')
    };

    ko.applyBindings(fileModel);

    $(window).load(function () {
        $("#sidebar_links").find("a[href='/node/files']").addClass('active');
    });

    $(window).load(function () {
        $(".load_folder").click(function(e) {
            console.log("triggered");
            var newPath = $(this).text();
            console.log("Update: " + newPath);
        });

        getFileList(fileModel.currentDir());
    });

    function getFileList(path) {
        makeDaemonCall('GET', path, {}, function (data) {
            fileModel.files.removeAll();
            data.forEach(function (e) {
                fileModel.files.push({
                    modifyDate: e.modifyTime,
                    name: e.name,
                    size: e.size,
                    isFile: e.isFile,
                    currentDir: fileModel.currentDir()
                });
            });
            $("#filemanager").trigger("update");
        });
    }

    function makeDaemonCall(method, path, data, callback) {
        $.ajax({
            method: method,
            url: '/daemon/server/{{ server.hash }}/file' + path,

        }).done(callback).error(displayError);
    }

    function displayError(err) {

    }

    function loadFolder(e) {
        var currentDir = fileModel.currentDir();
        var element = $(e);
        var folderName = element.attr('data-value');
        if (folderName === '..') {
            currentDir = currentDir.substr(0, currentDir.lastIndexOf("/"));
        } else {
            currentDir += '/' + folderName
        }
        if(currentDir == '') {
            currentDir = '/';
        }
        currentDir = currentDir.replace('//', '/');
        fileModel.currentDir(currentDir);
        getFileList(currentDir);
    }
</script>

<script type="text/html" id="fm-file">
    <tr>
        <td><i class="fa fa-file-text" style="margin-left: 2px;"></i></td>
        <td>
            <a href="#" class="edit_file" data-bind="text: name"></a>
        </td>
        <td data-bind="text: size"></td>
        <td data-bind="text: modifyDate"></td>
        <td style="text-align:center;">
            <div class="row" style="text-align:center;">
                <div class="col-md-3 hidden-xs hidden-sm">
                    {% if permission.has('files.download') %}
                    <a data-bind="attr: { href: '/daemon/server/{{ server.hash }}/file' + currentDir + name, download: name }"><span class="badge"><i class="fa fa-download"></i></span></a>
                    {% endif %}
                </div>
                <div class="col-md-3">
                    {% if permission.has('files.delete') %}
                    <a href="#" class="delete_file"><span class="badge label-danger"><i
                            class="fa fa-trash-o"></i></span></a>
                    {% endif %}
                </div>
            </div>
        </td>
    </tr>
</script>

<script type="text/html" id="fm-folder">
    <tr>
        <td><i class="fa fa-folder-open" style="margin-left: 0.859px;"></i></td>
        <td><a href="#" class="load_folder" onclick="loadFolder(this);" data-bind="text: name, attr: {'data-value': name }"></a></td>
        <td data-bind="text: size"></td>
        <td data-bind="text: modifyDate"></td>
        <td style="text-align:center;">
            <div class="row" style="text-align:center;">
                <div class="col-md-3 hidden-xs hidden-sm"></div>
                <div class="col-md-3">
                    {% if permission.has('files.delete') %}
                    <a href="#" class="delete_file"><span class="badge label-danger"><i
                            class="fa fa-trash-o"></i></span></a>
                    {% endif %}
                </div>
            </div>
        </td>
    </tr>
</script>

<script type="text/html" id="fm-up">
    <tr>
        <td><i class="fa fa-folder-open" style="margin-left: 0.859px;"></i></td>
        <td><a href="#" class="load_folder" onclick="loadFolder(this);" data-value="..">&larr;</a></a></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
</script>

{% endblock %}<commit_msg>Implement delete Does not delete folders with files in them, does not prompt for confirmation<commit_after>{% extends "base.html" %}

{% block title %}File Manager{% endblock %}

{% block content %}
{% if flash.info is defined %}
<div class="col-md-9">
    {{ flash.info.0|raw }}
</div>
{% endif %}
<div class="col-md-9" id="load_files">
    <h4 class="nopad"><span data-bind="text: currentDir"></span> {% if ( permission.has('files.create') ) or (
        permission.has('files.upload') )
        %}
        <small><a href="#" class="text-muted"><i class="fa fa-plus"></i></a></small>
        {% endif %}
    </h4>
    <table class="table table-striped table-bordered table-hover" id="filemanager">
        <thead>
        <tr>
            <th style="width:2%;text-align:center;"></th>
            <th style="width:55%">{{ l.render('node.files.name') }}</th>
            <th style="width:15%">{{ l.render('node.files.size') }}</th>
            <th style="width:20%">{{ l.render('node.files.modified') }}</th>
            <th style="width:10%;text-align:center;">{{ l.render('string.options') }}</th>
        </tr>
        </thead>
        <tbody data-bind="template: {name: displayMode, foreach: files }">
        </tbody>
    </table>
</div>

<script type='text/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.1/knockout-min.js'></script>

<script type="text/javascript">
    var fileModel = {
        files: ko.observableArray(),
        displayMode: function (file) {
            return file.isFile ? 'fm-file' : file.name == '..' ? 'fm-up' : 'fm-folder';
        },
        currentDir: ko.observable('/')
    };

    ko.applyBindings(fileModel);

    $(window).load(function () {
        $("#sidebar_links").find("a[href='/node/files']").addClass('active');
    });

    $(window).load(function () {
        $(".load_folder").click(function (e) {
            console.log("triggered");
            var newPath = $(this).text();
            console.log("Update: " + newPath);
        });

        getFileList();
    });

    function getFileList() {
        makeDaemonCall('GET', fileModel.currentDir(), {}, function (data) {
            fileModel.files.removeAll();
            data.forEach(function (e) {
                fileModel.files.push({
                    modifyDate: e.modifyTime,
                    name: e.name,
                    size: e.size,
                    isFile: e.isFile,
                    currentDir: fileModel.currentDir()
                });
            });
            $("#filemanager").trigger("update");
        });
    }

    function makeDaemonCall(method, path, data, callback) {
        $.ajax({
            method: method,
            url: '/daemon/server/{{ server.hash }}/file' + path,

        }).done(callback).error(displayError);
    }

    function displayError(err) {

    }

    function deleteFile(e) {
        var element = $(e);
        var path = element.attr('data-value');
        var path = element.attr('data-value');
        makeDaemonCall('DELETE', path, undefined, getFileList);
    }

    function loadFolder(e) {
        var currentDir = fileModel.currentDir();
        var element = $(e);
        var folderName = element.attr('data-value');
        if (folderName === '..') {
            currentDir = currentDir.substr(0, currentDir.lastIndexOf("/"));
        } else {
            currentDir += '/' + folderName
        }
        if (currentDir == '') {
            currentDir = '/';
        }
        currentDir += '/';
        currentDir = currentDir.replace('//', '/');
        fileModel.currentDir(currentDir);
        getFileList();
    }
</script>

<script type="text/html" id="fm-file">
    <tr>
        <td><i class="fa fa-file-text" style="margin-left: 2px;"></i></td>
        <td>
            <a href="#" class="edit_file" data-bind="text: name"></a>
        </td>
        <td data-bind="text: size"></td>
        <td data-bind="text: modifyDate"></td>
        <td style="text-align:center;">
            <div class="row" style="text-align:center;">
                <div class="col-md-3 hidden-xs hidden-sm">
                    {% if permission.has('files.download') %}
                    <a data-bind="attr: { href: '/daemon/server/{{ server.hash }}/file' + currentDir + name, download: name }"><span class="badge"><i class="fa fa-download"></i></span></a>
                    {% endif %}
                </div>
                <div class="col-md-3">
                    {% if permission.has('files.delete') %}
                    <a href="#" data-bind="attr: { 'data-value': currentDir + name }" onclick="deleteFile(this);" class="delete_file"><span class="badge label-danger"><i class="fa fa-trash-o"></i></span></a>
                    {% endif %}
                </div>
            </div>
        </td>
    </tr>
</script>

<script type="text/html" id="fm-folder">
    <tr>
        <td><i class="fa fa-folder-open" style="margin-left: 0.859px;"></i></td>
        <td><a href="#" class="load_folder" onclick="loadFolder(this);"
               data-bind="text: name, attr: {'data-value': name }"></a></td>
        <td data-bind="text: size"></td>
        <td data-bind="text: modifyDate"></td>
        <td style="text-align:center;">
            <div class="row" style="text-align:center;">
                <div class="col-md-3 hidden-xs hidden-sm"></div>
                <div class="col-md-3">
                    {% if permission.has('files.delete') %}
                    <a href="#" data-bind="attr: { 'data-value': currentDir + name }" onclick="deleteFile(this);" class="delete_file"><span class="badge label-danger"><i class="fa fa-trash-o"></i></span></a>
                    {% endif %}
                </div>
            </div>
        </td>
    </tr>
</script>

<script type="text/html" id="fm-up">
    <tr>
        <td><i class="fa fa-folder-open" style="margin-left: 0.859px;"></i></td>
        <td><a href="#" class="load_folder" onclick="loadFolder(this);" data-value="..">&larr;</a></a></td>
        <td></td>
        <td></td>
        <td></td>
    </tr>
</script>

{% endblock %}
{'fraction_non_alphanumeric': 0.20136054421768707, 'fraction_numerical': 0.005272108843537415, 'mean_word_length': 2.0164144652474993, 'pattern_counts': {'":': 0, '<': 245, '<?xml version=': 0, '>': 245, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1532013', 'n_tokens_mistral': 3769, 'n_tokens_neox': 3589, 'n_words': 654}