-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathbrowse.js
121 lines (93 loc) · 4.71 KB
/
browse.js
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//when dir listing comes back, list it
ipcRenderer.on('get_dir', (event, arg) => {
console.log("get_dir msg came: ");
console.log(arg);
$("#listTable tbody").html('');
if (arg.success) {
$("#path").html(arg.path);
loadDir(arg.path, arg.list);
fixIcons();
}
});
//sort
$(document).on('click', '.set-sort', (el) => {
$("#browseCardBody .listitem").sort(sortBy($(el.target).data('key'), $(el.target).data('asc') == '1')).appendTo('#browseCardBody');
$("#listTable tbody .listitem").sort(sortBy($(el.target).data('key'), $(el.target).data('asc') == '1')).appendTo('#listTable');
//TODO: sort doesnt work on regular folders, only cards
});
//sort
function sortBy(key, asc) {
return ((a, b) => {
var valA = $(a).data(key);
var valB = $(b).data(key);
if (valA < valB) {
return asc ? -1 : 1;
}
if (valA > valB) {
return asc ? 1 : -1;
}
return 0;
});
}
function loadDir(path, list) {
let UpDir = path.substr(0, path.lastIndexOf("/"));
$("#listTableStart tbody").html(`<tr><td class="browse-folder "><a data-path="${UpDir}" onclick="getDir(this)"><i class=\"fa fa-folder-o\" aria-hidden=\"true\"></i> ../ (up one directory)</a><td></tr>`)
$("#browseCardBody").html('');
for (item in list) {
let name = list[item].name
fullPath = list[item].filePath.replace("\\", "/").replace("", ":")
if (list[item].isFile) {
if (list[item].name.endsWith(".apk")) {
row = $("#listTable tbody").append(`<tr class="listitem" data-name="${list[item].name.toUpperCase()}" data-createdat="${list[item].createdAt.getTime()}"><td><a data-path="${fullPath}" onclick='getDir(this)'><b><i class="browse-file fa fa-upload" aria-hidden="true"></i> ` + `${name}</b></a><td></tr>`)
} else {
row = $("#listTable tbody").append(`<tr class="listitem" data-name="${list[item].name.toUpperCase()}" data-createdat="${list[item].createdAt.getTime()}"><td><i class="browse-file fa fa-file-o" aria-hidden="true"></i> ` + `${name}<td></tr>`)
}
} else {
if (list[item].imagePath) {
if (list[item].mp) {
mpribbon = `<div class="ribbon-wrapper-green"><div class="ribbon-green">MP!</div></div>`
} else {
mpribbon = ''
}
if (list[item].versionCode !== 'PROCESSING') {
selectBtn = `<a data-path="${fullPath}" onclick='getDir(this)'><span class="btn btn-primary btn-block">Select</span></a>`
} else {
selectBtn = `<a><span class="btn btn-outline-secondary btn-block">${list[item].versionCode}</span></a>`
}
//row = $("#listTable tbody").append("<tr><td class='browse-folder' ><a onclick='getDir(\"" + fullPath + "\")'><i class=\"fa fa-folder-o\" aria-hidden=\"true\"></i> " + `${name}</a><td></tr>`)
row = $("#browseCardBody").append(`<div class="col mb-4 listitem" data-name="${list[item].name.toUpperCase()}" data-createdat="${list[item].createdAt.getTime()}">
<div class="card h-100">
${mpribbon}
<img src="${list[item].imagePath}" style="max-height: 100px" class="card-img-top" alt="...">
<div class="card-body">
<p class="card-text" style="color: black">
${list[item].simpleName}<br><br>
${selectBtn}
</p>
</div>
<div style="color: gray" class="card-footer">v. ${list[item].versionCode}</div>
</div>
</div>`);
} else {
row = $("#listTable tbody").append(`<tr class="listitem" data-name="${list[item].name.toUpperCase()}" data-createdat="${list[item].createdAt.getTime()}"><td class='browse-folder'>
<a data-path="${fullPath}" onclick='getDir(this)'>
<i class=\"fa fa-folder-o\" aria-hidden=\"true\"></i> ` + `${name}</a><td></tr>`)
}
}
//console.log("appended "+ name);
}
$("#browseCardBody .listitem").sort(sortBy('createdat', false)).appendTo('#browseCardBody');
$("#listTableEnd tbody").html(`<tr><td class="browse-folder "><a data-path="${UpDir}" onclick="getDir(this)"><i class=\"browse-folder fa fa-folder-o\" aria-hidden=\"true\"></i> ../ (up one directory)</a><td></tr>`)
}
function fixIcons() {
$(".browse-folder").hover(
function () {
console.log("HOVER");
$(this).find("i").removeClass("fa-folder-o")
$(this).find("i").addClass("fa-folder-open-o")
}, function () {
$(this).find("i").addClass("fa-folder-o")
$(this).find("i").removeClass("fa-folder-open-o")
}
);
}