diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-09-15 12:57:34 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2010-09-15 12:57:34 +0200 |
commit | 85c900fdd5d070e93363768b346acbadc8f132d7 (patch) | |
tree | fcb38a93cb949f597fa843901b2287a3863f6966 | |
parent | extended safe_eval (diff) | |
download | pyload-85c900fdd5d070e93363768b346acbadc8f132d7.tar.xz |
sorting fix
-rw-r--r-- | module/FileDatabase.py | 61 | ||||
-rw-r--r-- | module/web/ajax/views.py | 14 | ||||
-rw-r--r-- | module/web/templates/default/package_ui.js | 16 |
3 files changed, 52 insertions, 39 deletions
diff --git a/module/FileDatabase.py b/module/FileDatabase.py index bc5e4f502..2d3e0aa86 100644 --- a/module/FileDatabase.py +++ b/module/FileDatabase.py @@ -119,6 +119,14 @@ class FileHandler: #---------------------------------------------------------------------- def syncSave(self): """saves all data to backend and waits until all data are written""" + pyfiles = self.cache.values() + for pyfile in pyfiles: + pyfile.sync() + + pypacks = self.packageCache.values() + for pypack in pypacks: + pypack.sync() + self.db.syncSave() #---------------------------------------------------------------------- @@ -411,25 +419,26 @@ class FileHandler: @lock @change def reorderPackage(self, id, position): - p = self.db.getPackage(id) + p = self.getPackage(id) e = RemoveEvent("pack", id, "collector" if not p.queue else "queue") self.core.pullManager.addEvent(e) - self.db.reorderPackage(p, position) + packs = self.packageCache.values() - p.order = position for pack in packs: if pack.queue != p.queue or pack.order < 0 or pack == p: continue - if pack.order > p.order: - pack.order -= 1 - if pack.order >= position: - pack.order += 1 + if p.order > position: + if pack.order >= position and pack.order < p.order: + pack.order += 1 + elif p.order < position: + if pack.order <= position and pack.order > p.order: + pack.order -= 1 p.order = position - self.db.commit() - + + e = ReloadAllEvent("collector" if not p.queue else "queue") self.core.pullManager.addEvent(e) @@ -437,26 +446,29 @@ class FileHandler: @change def reorderFile(self, id, position): f = self.getFileData(id) + f = f[str(id)] - e = RemoveEvent("file", id, "collector" if not self.getPackage(f[str(id)]["package"]).queue else "queue") + e = RemoveEvent("file", id, "collector" if not self.getPackage(f["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 pyfile.packageid != f["package"] or pyfile.order < 0: continue + if f["order"] > position: + if pyfile.order >= position and pyfile.order < f["order"]: + pyfile.order += 1 + elif f["order"] < position: + if pyfile.order <= position and pyfile.order > f["order"]: + pyfile.order -= 1 if self.cache.has_key(id): self.cache[id].order = position self.db.commit() - e = ReloadAllEvent("collector" if not self.getPackage(f[str(id)]["package"]).queue else "queue") + e = ReloadAllEvent("collector" if not self.getPackage(f["package"]).queue else "queue") self.core.pullManager.addEvent(e) @@ -774,17 +786,22 @@ class FileDatabaseBackend(Thread): if position == -1: position = self._nextPackageOrder(p.queue) if not noMove: - self.c.execute('UPDATE packages SET packageorder=packageorder-1 WHERE packageorder > ? AND queue=? AND packageorder > 0', (p.order, p.queue)) - self.c.execute('UPDATE packages SET packageorder=packageorder+1 WHERE packageorder >= ? AND queue=? AND packageorder > 0', (position, p.queue)) + if p.order > position: + self.c.execute('UPDATE packages SET packageorder=packageorder+1 WHERE packageorder >= ? AND packageorder < ? AND queue=? AND packageorder >= 0', (position, p.order, p.queue)) + elif p.order < position: + self.c.execute('UPDATE packages SET packageorder=packageorder-1 WHERE packageorder <= ? AND packageorder > ? AND queue=? AND packageorder >= 0', (position, p.order, p.queue)) + self.c.execute('UPDATE packages SET packageorder=? WHERE id=?', (position, str(p.id))) @queue def reorderLink(self, f, position): """ reorder link with f as dict for pyfile """ - 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))) + if f["order"] > position: + self.c.execute('UPDATE links SET linkorder=linkorder+1 WHERE linkorder >= ? AND linkorder < ? AND package=?', (position, f["order"], f["package"])) + elif f["order"] < position: + self.c.execute('UPDATE links SET linkorder=linkorder-1 WHERE linkorder <= ? AND linkorder > ? AND package=?', (position, f["order"], f["package"])) + + self.c.execute('UPDATE links SET linkorder=? WHERE id=?', (position, f["id"])) @queue diff --git a/module/web/ajax/views.py b/module/web/ajax/views.py index 5a6fc7b69..9430a54d4 100644 --- a/module/web/ajax/views.py +++ b/module/web/ajax/views.py @@ -212,7 +212,7 @@ def package_order(request, ids): try: pid, pos = ids.split("|") settings.PYLOAD.order_package(int(pid), int(pos)) - return JsonResponse("sucess") + return JsonResponse("success") except: print_exc() return HttpResponseServerError() @@ -222,7 +222,7 @@ def link_order(request, ids): try: pid, pos = ids.split("|") settings.PYLOAD.order_file(int(pid), int(pos)) - return JsonResponse("sucess") + return JsonResponse("success") except: print_exc() return HttpResponseServerError() @@ -240,7 +240,7 @@ def link(request, id): def remove_package(request, id): try: settings.PYLOAD.del_packages([int(id)]) - return JsonResponse("sucess") + return JsonResponse("success") except Exception, e: print_exc() return HttpResponseServerError() @@ -249,7 +249,7 @@ def remove_package(request, id): def restart_package(request, id): try: settings.PYLOAD.restart_package(int(id)) - return JsonResponse("sucess") + return JsonResponse("success") except Exception: return HttpResponseServerError() @@ -257,7 +257,7 @@ def restart_package(request, id): def restart_link(request, id): try: settings.PYLOAD.restart_file(int(id)) - return JsonResponse("sucess") + return JsonResponse("success") except Exception: return HttpResponseServerError() @@ -265,7 +265,7 @@ def restart_link(request, id): def abort_link(request, id): try: settings.PYLOAD.stop_download("link", int(id)) - return JsonResponse("sucess") + return JsonResponse("success") except: return HttpResponseServerError() @@ -273,7 +273,7 @@ def abort_link(request, id): def move_package(request, dest, id): try: settings.PYLOAD.move_package(int(dest), int(id)) - return JsonResponse("sucess") + return JsonResponse("success") except: return HttpResponseServerError() diff --git a/module/web/templates/default/package_ui.js b/module/web/templates/default/package_ui.js index 759412621..1c9505bc9 100644 --- a/module/web/templates/default/package_ui.js +++ b/module/web/templates/default/package_ui.js @@ -65,12 +65,10 @@ var PackageUI = new Class({ saveSort: function(ele, copy) { var order = []; - this.sorts.serialize(function(ele,pos){ - if (ele.retrieve("order") != pos){ - order.push(ele.retrieve("pid")+"|"+pos); - ele.store("order", pos); + this.sorts.serialize(function(li,pos){ + if (li == ele && ele.retrieve("order") != pos){ + order.push(ele.retrieve("pid")+"|"+pos) } - }); if (order.length > 0){ indicateLoad(); @@ -315,12 +313,10 @@ var Package = new Class({ 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); + this.sorts.serialize(function(li,pos){ + if (li == ele && ele.retrieve("order") != pos){ + order.push(ele.retrieve("lid")+"|"+pos) } - }); if (order.length > 0){ indicateLoad(); |