mirror of
https://github.com/zoriya/flood.git
synced 2026-05-25 08:23:26 +00:00
Rearrange app directory structure
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
export function filterTorrents(torrentList, torrentListFilterBy) {
|
||||
let filteredtorrentList = torrentList;
|
||||
|
||||
if (torrentListFilterBy !== 'all') {
|
||||
filteredtorrentList = torrentList.filter(torrent => {
|
||||
if (torrent.status.indexOf('is-' + torrentListFilterBy) > -1) {
|
||||
return torrent;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return filteredtorrentList;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
export function searchTorrents(torrentList, torrentListSearchString) {
|
||||
let searchedTorrents = torrentList;
|
||||
|
||||
if (torrentListSearchString !== '') {
|
||||
let queries = [];
|
||||
let searchTerms = torrentListSearchString.replace(/,/g, ' ').split(' ');
|
||||
|
||||
for (let i = 0, len = searchTerms.length; i < len; i++) {
|
||||
queries.push(new RegExp(searchTerms[i], 'gi'));
|
||||
}
|
||||
|
||||
searchedTorrents = searchedTorrents.filter(torrent => {
|
||||
for (let i = 0, len = queries.length; i < len; i++) {
|
||||
if (!torrent.name.match(queries[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
return searchedTorrents;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
export function selectTorrents(options) {
|
||||
if (options.event.shiftKey) {
|
||||
if (options.selectedTorrents.length) {
|
||||
let lastHash = options.selectedTorrents[
|
||||
options.selectedTorrents.length - 1
|
||||
];
|
||||
let currentHashIndex;
|
||||
let lastHashIndex;
|
||||
|
||||
// get the index of the last selected torrent.
|
||||
options.torrentList.some(function(torrent, index) {
|
||||
if (torrent.hash === lastHash) {
|
||||
lastHashIndex = index;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// get the index of the newly selected torrent.
|
||||
options.torrentList.some(function(torrent, index) {
|
||||
if (torrent.hash === options.hash) {
|
||||
currentHashIndex = index;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
// from the previously selected index to the currently selected index,
|
||||
// add all torrent hashes to the selected array.
|
||||
// if the newly selcted hash is larger than the previous, start from
|
||||
// the newly selected hash and work backwards. otherwise go forwards.
|
||||
let increment = 1;
|
||||
|
||||
if (currentHashIndex > lastHashIndex) {
|
||||
increment = -1;
|
||||
}
|
||||
|
||||
while (currentHashIndex !== lastHashIndex) {
|
||||
let foundHash = options.torrentList[currentHashIndex].hash;
|
||||
// if the torrent isn't already selected, add the hash to the array.
|
||||
if (options.selectedTorrents.indexOf(foundHash) === -1) {
|
||||
options.selectedTorrents.push(foundHash);
|
||||
}
|
||||
currentHashIndex += increment;
|
||||
}
|
||||
} else {
|
||||
options.selectedTorrents = [options.hash];
|
||||
}
|
||||
|
||||
} else if (options.event.metaKey || options.event.ctrlKey) {
|
||||
let hashPosition = options.selectedTorrents.indexOf(options.hash);
|
||||
if (hashPosition === -1) {
|
||||
// if the hash is not in the array, add it.
|
||||
options.selectedTorrents.push(options.hash);
|
||||
} else {
|
||||
// if the hash is in the array, remove it.
|
||||
options.selectedTorrents.splice(hashPosition, 1);
|
||||
}
|
||||
} else {
|
||||
// clicked torrent is only item in list.
|
||||
options.selectedTorrents = [options.hash];
|
||||
}
|
||||
return options.selectedTorrents;
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
export function sortTorrents(torrents, sortBy) {
|
||||
if (torrents.length) {
|
||||
let direction = sortBy.direction;
|
||||
let property = sortBy.property;
|
||||
let sortedTorrents = Object.assign([], torrents);
|
||||
|
||||
sortedTorrents.sort(function(a, b) {
|
||||
let valA = a[property];
|
||||
let valB = b[property];
|
||||
|
||||
if (property === 'eta') {
|
||||
// keep infinity at bottom of array when sorting by eta
|
||||
if (valA === 'Infinity' && valB !== 'Infinity') {
|
||||
return 1;
|
||||
} else if (valA !== 'Infinity' && valB === 'Infinity') {
|
||||
return -1;
|
||||
}
|
||||
// if it's not infinity, compare the second as numbers
|
||||
if (valA !== 'Infinity') {
|
||||
valA = Number(valA.seconds);
|
||||
}
|
||||
if (valB !== 'Infinity') {
|
||||
valB = Number(valB.seconds);
|
||||
}
|
||||
} else if (property === 'name') {
|
||||
valA = valA.toLowerCase();
|
||||
valB = valB.toLowerCase();
|
||||
} else {
|
||||
valA = Number(valA);
|
||||
valB = Number(valB);
|
||||
}
|
||||
|
||||
if (direction === 'asc') {
|
||||
if (valA > valB) {
|
||||
return 1;
|
||||
}
|
||||
if (valA < valB) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (valA > valB) {
|
||||
return -1;
|
||||
}
|
||||
if (valA < valB) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
return sortedTorrents;
|
||||
} else {
|
||||
return torrents;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user