summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--module/FileDatabase.py16
-rw-r--r--module/web/ajax/urls.py3
-rw-r--r--module/web/ajax/views.py15
-rw-r--r--module/web/templates/default/collector.html7
-rw-r--r--module/web/templates/default/package_ui.js73
-rw-r--r--module/web/templates/default/queue.html7
-rwxr-xr-xpyLoadCore.py7
7 files changed, 116 insertions, 12 deletions
diff --git a/module/FileDatabase.py b/module/FileDatabase.py
index 37bd7b3c8..bc5e4f502 100644
--- a/module/FileDatabase.py
+++ b/module/FileDatabase.py
@@ -438,13 +438,19 @@ class FileHandler:
def reorderFile(self, id, position):
f = self.getFileData(id)
- #@TODO test...
-
e = RemoveEvent("file", id, "collector" if not self.getPackage(f[str(id)]["package"]).queue else "queue")
self.core.pullManager.addEvent(e)
self.db.reorderLink(f, position)
-
+
+ pyfiles = self.cache.values()
+ for pyfile in pyfiles:
+ if pyfile.packageid != f[str(id)]["package"] or pyfile.order < 0: continue
+ if pyfile.order > f[str(id)]["order"]:
+ pyfile.order -= 1
+ if pyfile.order >= position:
+ pyfile.order += 1
+
if self.cache.has_key(id):
self.cache[id].order = position
@@ -576,7 +582,7 @@ class FileDatabaseBackend(Thread):
def _createTables(self):
"""create tables for database"""
- self.c.execute('CREATE TABLE IF NOT EXISTS "packages" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" TEXT NOT NULL, "folder" TEXT, "password" TEXT, "site" TEXT, "queue" INTEGER DEFAULT 0 NOT NULL, "packageorder" INTEGER DEFAULT 0 NOT NULL, "priority" INTEGER DEFAULT 0 NOT NULL)')
+ self.c.execute('CREATE TABLE IF NOT EXISTS "packages" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" TEXT NOT NULL, "folder" TEXT, "password" TEXT DEFAULT "", "site" TEXT DEFAULT "", "queue" INTEGER DEFAULT 0 NOT NULL, "packageorder" INTEGER DEFAULT 0 NOT NULL, "priority" INTEGER DEFAULT 0 NOT NULL)')
self.c.execute('CREATE TABLE IF NOT EXISTS "links" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "url" TEXT NOT NULL, "name" TEXT, "size" INTEGER DEFAULT 0 NOT NULL, "status" INTEGER DEFAULT 3 NOT NULL, "plugin" TEXT DEFAULT "BasePlugin" NOT NULL, "error" TEXT DEFAULT "", "linkorder" INTEGER DEFAULT 0 NOT NULL, "package" INTEGER DEFAULT 0 NOT NULL, FOREIGN KEY(package) REFERENCES packages(id))')
self.c.execute('CREATE INDEX IF NOT EXISTS "pIdIndex" ON links(package)')
self.c.execute('VACUUM')
@@ -775,7 +781,7 @@ class FileDatabaseBackend(Thread):
@queue
def reorderLink(self, f, position):
""" reorder link with f as dict for pyfile """
- id = f.keys[0]
+ id = f.keys()[0]
self.c.execute('UPDATE links SET linkorder=linkorder-1 WHERE linkorder > ? AND package=?', (f[str(id)]["order"], str(f[str(id)]["package"])))
self.c.execute('UPDATE links SET linkorder=linkorder+1 WHERE linkorder >= ? AND package=?', (position, str(f[str(id)]["package"])))
self.c.execute('UPDATE links SET linkorder=? WHERE id=?', (position, str(id)))
diff --git a/module/web/ajax/urls.py b/module/web/ajax/urls.py
index 07b5683b6..a88e3aea5 100644
--- a/module/web/ajax/urls.py
+++ b/module/web/ajax/urls.py
@@ -26,7 +26,8 @@ urlpatterns = patterns('ajax',
(r'^restart_package/(\d+)$', 'views.restart_package'),
(r'^remove_link/(\d+)$', 'views.remove_link'),
(r'^restart_link/(\d+)$', 'views.restart_link'),
- (r'^push_to_queue/(\d+)$', 'views.push_to_queue'),
+ (r'^move_package/(\d+)/(\d+)$', 'views.move_package'),
(r'^set_captcha$', 'views.set_captcha'),
(r'^package_order/([0-9|]+)$', 'views.package_order'),
+ (r'^link_order/([0-9|]+)$', 'views.link_order'),
) \ No newline at end of file
diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py
index f020a8303..f96b93b70 100644
--- a/module/web/ajax/views.py
+++ b/module/web/ajax/views.py
@@ -216,6 +216,17 @@ def package_order(request, ids):
except:
print_exc()
return HttpResponseServerError()
+
+@permission('pyload.can_add_dl')
+def link_order(request, ids):
+ try:
+ pid, pos = ids.split("|")
+ settings.PYLOAD.order_file(int(pid), int(pos))
+ return JsonResponse("sucess")
+ except:
+ print_exc()
+ return HttpResponseServerError()
+
@permission('pyload.can_see_dl')
def link(request, id):
try:
@@ -259,9 +270,9 @@ def abort_link(request, id):
return HttpResponseServerError()
@permission('pyload.can_add_dl')
-def push_to_queue(request, id):
+def move_package(request, dest, id):
try:
- settings.PYLOAD.push_package_to_queue(int(id))
+ settings.PYLOAD.move_package(int(dest), int(id))
return JsonResponse("sucess")
except:
return HttpResponseServerError()
diff --git a/module/web/templates/default/collector.html b/module/web/templates/default/collector.html
index 0143e13ec..630eddc51 100644
--- a/module/web/templates/default/collector.html
+++ b/module/web/templates/default/collector.html
@@ -9,7 +9,7 @@
document.addEvent("domready", function(){
load = new Fx.Tween($("load-indicator"), {link: "cancel"});
- var pUI = new PackageUI("url");
+ var pUI = new PackageUI("url", 0);
});
</script>
{% endblock %}
@@ -48,12 +48,17 @@ document.addEvent("domready", function(){
<li>
<div id="package_{{id}}" class="package">
<div class="order" style="display: none;">{{ package.order }}</div>
+
<div class="packagename" style="cursor: move;">
{{ package.name }}
&nbsp;&nbsp;
+ <span class="buttons" style="opacity:0; cursor: default">
<img title="{% trans "Delete Package" %}" style="cursor: pointer" width="12px" height="12px" src="{{ MEDIA_URL }}img/delete.png" />
&nbsp;&nbsp;
<img title="{% trans "Restart Package" %}" style="margin-left: -10px; cursor: pointer" height="12px" src="{{ MEDIA_URL }}img/arrow_refresh.png" />
+ &nbsp;&nbsp;
+ <img title="{% trans "Move Package to Queue" %}" style="margin-left: -10px; cursor: pointer" height="12px" src="{{ MEDIA_URL }}img/package_go.png" />
+ </span>
</div>
<div id="children_{{id}}" style="display: none;" class="children">
<span class="child_secrow">{% trans "Folder:" %} {{package.folder}} | {% trans "Password:"%} {{ package.password }} | {% trans "Priority:"%} {{ package.priority }}</span>
diff --git a/module/web/templates/default/package_ui.js b/module/web/templates/default/package_ui.js
index a63a22aef..5f39710c1 100644
--- a/module/web/templates/default/package_ui.js
+++ b/module/web/templates/default/package_ui.js
@@ -11,8 +11,9 @@ function indicateFinish() {
}
var PackageUI = new Class({
- initialize: function(url) {
+ initialize: function(url, type) {
this.url = url;
+ this.type = type;
this.packages = [];
this.parsePackages();
@@ -21,6 +22,7 @@ var PackageUI = new Class({
clone: true,
revert: true,
opacity: 0.4,
+ handle: ".packagename",
onStart: this.startSort,
onComplete: this.saveSort.bind(this)
});
@@ -77,6 +79,20 @@ var Package = new Class({
this.ele.store("pid", this.id);
this.parseElement();
}
+
+ var pname = this.ele.getElements(".packagename")[0];
+ this.buttons = new Fx.Tween(this.ele.getElements(".buttons")[0], {link: "cancel"});
+ this.buttons.set("opacity", 0);
+
+ pname.addEvent("mouseenter", function(e){
+ this.buttons.start("opacity", 1)
+ }.bind(this));
+
+ pname.addEvent("mouseleave", function(e){
+ this.buttons.start("opacity", 0)
+ }.bind(this));
+
+
},
createElement: function() {
@@ -90,6 +106,8 @@ var Package = new Class({
imgs[1].addEvent('click', this.restartPackage.bind(this));
+ imgs[2].addEvent('click', this.movePackage.bind(this));
+
this.ele.getElement('.packagename').addEvent('click', this.toggle.bind(this));
},
@@ -114,7 +132,7 @@ var Package = new Class({
}
});
- var html = "<span class='child_status'><img src='/media/default/img/{icon}' style='width: 12px; height:12px;'/></span>\n".substitute({"icon": link.icon});
+ var html = "<span style='cursor: move' class='child_status sorthandle'><img src='/media/default/img/{icon}' style='width: 12px; height:12px;'/></span>\n".substitute({"icon": link.icon});
html += "<span style='font-size: 15px'>{name}</span><br /><div class='child_secrow'>".substitute({"name": link.name});
html += "<span class='child_status'>{statusmsg}</span>{error}&nbsp;".substitute({"statusmsg": link.statusmsg, "error":link.error});
html += "<span class='child_status'>{format_size}</span>".substitute({"format_size": link.format_size});
@@ -128,9 +146,20 @@ var Package = new Class({
"html": html
});
+ li.store("order", link.order);
+ li.store("lid", link.id);
+
li.adopt(div);
ul.adopt(li);
});
+ this.sorts = new Sortables(ul, {
+ constrain: false,
+ clone: true,
+ revert: true,
+ opacity: 0.4,
+ handle: ".sorthandle",
+ onComplete: this.saveSort.bind(this)
+ });
this.registerLinkEvents();
this.linksLoaded = true;
indicateFinish();
@@ -195,11 +224,51 @@ var Package = new Class({
method: 'get',
url: '/json/restart_package/'+this.id,
onSuccess: function(){
+ var child = this.ele.getElement('.children');
+ if (child.getStyle('display') == "block") {
+ child.dissolve();
+ }
+ var ul = $("sort_children_{id}".substitute({"id": this.id}));
+ ul.erase("html");
+ this.linksLoaded = false;
+
+ indicateFinish();
+ }.bind(this)
+ }).send();
+ event.stop();
+ },
+
+ movePackage: function(event){
+ indicateLoad();
+ new Request({
+ method: 'get',
+ url: '/json/move_package/'+((this.ui.type +1) % 2) +"/"+ this.id,
+ onSuccess: function(){
this.ele.nix();
indicateFinish();
}.bind(this)
}).send();
event.stop();
+ },
+
+ saveSort: function(ele, copy) {
+ var order = [];
+ this.sorts.serialize(function(ele,pos){
+ if (ele.retrieve("order") != pos){
+ order.push(ele.retrieve("lid")+"|"+pos);
+ ele.store("order", pos);
+ }
+
+ });
+ if (order.length > 0){
+ indicateLoad();
+ new Request.JSON({
+ method: 'get',
+ url: '/json/link_order/' + order[0],
+ onSuccess: indicateFinish,
+ onFailure: indicateFinish
+ }).send();
+ }
}
}); \ No newline at end of file
diff --git a/module/web/templates/default/queue.html b/module/web/templates/default/queue.html
index 09b2a4aec..2e8bf4b96 100644
--- a/module/web/templates/default/queue.html
+++ b/module/web/templates/default/queue.html
@@ -9,7 +9,7 @@
document.addEvent("domready", function(){
load = new Fx.Tween($("load-indicator"), {link: "cancel"});
- var pUI = new PackageUI("url");
+ var pUI = new PackageUI("url",1);
});
</script>
{% endblock %}
@@ -50,12 +50,17 @@ document.addEvent("domready", function(){
<li>
<div id="package_{{id}}" class="package">
<div class="order" style="display: none;">{{ package.order }}</div>
+
<div class="packagename" style="cursor: move;">
{{ package.name }}
&nbsp;&nbsp;
+ <span class="buttons" style="opacity:0; cursor: default">
<img title="{% trans "Delete Package" %}" style="cursor: pointer" width="12px" height="12px" src="{{ MEDIA_URL }}img/delete.png" />
&nbsp;&nbsp;
<img title="{% trans "Restart Package" %}" style="margin-left: -10px; cursor: pointer" height="12px" src="{{ MEDIA_URL }}img/arrow_refresh.png" />
+ &nbsp;&nbsp;
+ <img title="{% trans "Move Package to Collector" %}" style="margin-left: -10px; cursor: pointer" height="12px" src="{{ MEDIA_URL }}img/package_go.png" />
+ </span>
</div>
<div id="children_{{id}}" style="display: none;" class="children">
<span class="child_secrow">{% trans "Folder:" %} {{package.folder}} | {% trans "Password:"%} {{ package.password }} | {% trans "Priority:"%} {{ package.priority }}</span>
diff --git a/pyLoadCore.py b/pyLoadCore.py
index def3d4df5..60bfdc660 100755
--- a/pyLoadCore.py
+++ b/pyLoadCore.py
@@ -695,6 +695,10 @@ class ServerMethods():
"""put package back to collector"""
self.core.files.setPackageLocation(pid, 0)
+ def move_package(self, dest, pid):
+ if dest not in (0,1): return
+ self.core.files.setPackageLocation(pid, dest)
+
def is_captcha_waiting(self):
self.core.lastClientConnected = time.time()
task = self.core.captchaManager.getTask()
@@ -744,6 +748,9 @@ class ServerMethods():
def order_package(self, id, pos):
self.core.files.reorderPackage(id, pos)
+ def order_file(self, id, pos):
+ self.core.files.reorderFile(id, pos)
+
def is_time_download(self):
start = self.core.config['downloadTime']['start'].split(":")
end = self.core.config['downloadTime']['end'].split(":")