aboutsummaryrefslogtreecommitdiff
path: root/public/js/queueRenderer.js
blob: ae06531123a59cb6f2cc6fcbe8e83fad5d3d9c6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
var getQueueRenderer = function () {
    return new QueueRenderer();
};
var QueueRenderer = (function () {
    function QueueRenderer() {
    }
    QueueRenderer.prototype.createTextDiv = function (className, value) {
        var element = document.createElement("div");
        element.className = className;
        element.innerHTML = value;
        return element;
    };
    QueueRenderer.prototype.createButton = function (value, callback) {
        var element = document.createElement("button");
        element.className = "table-row-button";
        element.innerHTML = value;
        element.addEventListener("click", callback);
        return element;
    };
    QueueRenderer.prototype.createQueueRow = function (file, queueSettings) {
        var itemRow = document.createElement("div");
        itemRow.id = file.guid;
        itemRow.className = "table-row-item";
        this.renderQueueRowContent(itemRow, file, queueSettings);
        return itemRow;
    };
    QueueRenderer.prototype.translateFileStatus = function (file) {
        console.log(file)
        console.log(pu)
        switch (file.uploadStatus.toString()) {
            case pu.UploadStatus.queued:
                return "Queued";
            case pu.UploadStatus.uploading:
                return "Uploading";
            case pu.UploadStatus.uploaded:
                return "Uploaded";
            case pu.UploadStatus.failed:
                return "Failed";
            case pu.UploadStatus.canceled:
                return "Canceled";
        }
        return "Unknown";
    };
    QueueRenderer.prototype.renderQueueRowContent = function (itemRow, file, queueSettings) {
        while (itemRow.firstChild)
            itemRow.removeChild(itemRow.firstChild);
        itemRow.appendChild(this.createTextDiv('table-row-item-status', this.translateFileStatus(file)));
        itemRow.appendChild(this.createTextDiv('table-row-item-name', file.name));
        itemRow.appendChild(this.createTextDiv('table-row-item-progress', file.progress.toString() + "%"));
        switch (file.uploadStatus.toString()) {
            case pu.UploadStatus.queued:
                if (!queueSettings.autoStart) {
                    itemRow.appendChild(this.createButton("Start", function () { return file.start(); }));
                    break;
                }
            case pu.UploadStatus.uploading:
                itemRow.appendChild(this.createButton("Cancel", function () { return file.cancel(); }));
                break;
            case pu.UploadStatus.uploaded:
            case pu.UploadStatus.failed:
            case pu.UploadStatus.canceled:
                itemRow.appendChild(this.createButton("Delete", function () { return file.remove(); }));
                break;
        }
    };
    QueueRenderer.prototype.renderItemProgress = function (queueId, file) {
        var itemRow = document.getElementById(file.guid);
        for (var i = 0; i < itemRow.childNodes.length; i++) {
            var node = itemRow.childNodes[i];
            if (node.attributes.getNamedItem('class').value == 'table-row-item-progress') {
                node.textContent = file.progress.toString() + "%";
                break;
            }
        }
    };
    QueueRenderer.prototype.renderQueue = function (queueId, queueTitle, files, queueSettings) {
        var _this = this;
        var queue = document.getElementById(queueId);
        while (queue.firstChild)
            queue.removeChild(queue.firstChild);
        queue.appendChild(this.createTextDiv("table-header-title", queueTitle));
        files.forEach(function (file) {
            queue.appendChild(_this.createQueueRow(file, queueSettings));
        });
    };
    return QueueRenderer;
})();