Huge rewrite
Auto-refresh and sort are disabled for now
This commit is contained in:
@@ -1,12 +1,56 @@
|
||||
"use strict";
|
||||
|
||||
class trdom_torrentmanager {
|
||||
class trdom_torrentmanager extends EventTarget {
|
||||
#logcb;
|
||||
#log(loglevel, msg) {
|
||||
if (this.#logcb !== null) {
|
||||
this.#logcb('trdom_torrentmanager', loglevel, msg);
|
||||
}
|
||||
}
|
||||
|
||||
#element = document.createElement('div');
|
||||
getElement() {
|
||||
return this.#element;
|
||||
}
|
||||
|
||||
constructor() {
|
||||
#torrentDB = {};
|
||||
get torrents() {
|
||||
return this.#torrentDB;
|
||||
}
|
||||
|
||||
constructor(logcb = null) {
|
||||
super();
|
||||
this.#logcb = logcb;
|
||||
this.#element.classList.add('trweb_torrentlistview', 'container-fluid');
|
||||
}
|
||||
|
||||
handleEvent(e) {
|
||||
this.#log(6, `Handling event of type ${e.type}`);
|
||||
switch (e.type) {
|
||||
case 'torrent-created':
|
||||
let initHash = e.detail.torrentHash;
|
||||
if (this.#torrentDB[initHash] == null) {
|
||||
let torrentCreated = new trtorrent(initHash);
|
||||
this.#torrentDB[initHash] = torrentCreated;
|
||||
this.#element.appendChild(torrentCreated.element);
|
||||
for (const [srv, control] of Object.entries(e.detail.torrentControls)) {
|
||||
torrentCreated.addControl(srv, control)
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.#log(1, 'This event should never ever fire for a torrent that already exists');
|
||||
window.alert('We be ded, check console');
|
||||
}
|
||||
break;
|
||||
case 'torrentserver-added':
|
||||
let addedServer = e.detail.serverObject;
|
||||
for (const [hash, torrent] of Object.entries(this.#torrentDB)) {
|
||||
torrent.addControl(addedServer.name, new trdom_torrentcontrol(hash, addedServer, null, this.#logcb))
|
||||
}
|
||||
break;
|
||||
default:
|
||||
this.#log(5, `Event type ${e.type} not supported`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user