From 6d998f72684b7c6d67f8c8d7a75c6ea5246f1f49 Mon Sep 17 00:00:00 2001 From: Ruud Date: Sun, 9 Oct 2011 18:02:48 +0200 Subject: [PATCH] Changeable quality sizes --- couchpotato/core/plugins/quality/main.py | 22 ++++++++++- .../core/plugins/quality/static/quality.css | 28 ++++++++++++++ couchpotato/core/plugins/quality/static/quality.js | 43 +++++++++++++++++++--- couchpotato/static/scripts/page/settings.js | 2 +- 4 files changed, 88 insertions(+), 7 deletions(-) diff --git a/couchpotato/core/plugins/quality/main.py b/couchpotato/core/plugins/quality/main.py index c2089d4..1d2a6ed 100644 --- a/couchpotato/core/plugins/quality/main.py +++ b/couchpotato/core/plugins/quality/main.py @@ -1,6 +1,9 @@ from couchpotato import get_session +from couchpotato.api import addApiView from couchpotato.core.event import addEvent, fireEvent from couchpotato.core.helpers.encoding import toUnicode +from couchpotato.core.helpers.request import jsonified, getParams +from couchpotato.core.helpers.variable import mergeDicts from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.core.settings.model import Quality, Profile, ProfileType @@ -32,6 +35,8 @@ class QualityPlugin(Plugin): addEvent('quality.single', self.single) addEvent('quality.guess', self.guess) + addApiView('quality.size.save', self.saveSize) + addEvent('app.initialize', self.fill, priority = 10) def all(self): @@ -42,7 +47,7 @@ class QualityPlugin(Plugin): temp = [] for quality in qualities: - q = dict(self.getQuality(quality.identifier), **quality.to_dict()) + q = mergeDicts(self.getQuality(quality.identifier), quality.to_dict()) temp.append(q) return temp @@ -64,6 +69,21 @@ class QualityPlugin(Plugin): if identifier == q.get('identifier'): return q + def saveSize(self): + + params = getParams() + + db = get_session() + quality = db.query(Quality).filter_by(identifier = params.get('identifier')).first() + + if quality: + setattr(quality, params.get('value_type'), params.get('value')) + db.commit() + + return jsonified({ + 'success': True + }) + def fill(self): db = get_session(); diff --git a/couchpotato/core/plugins/quality/static/quality.css b/couchpotato/core/plugins/quality/static/quality.css index e69de29..e208173 100644 --- a/couchpotato/core/plugins/quality/static/quality.css +++ b/couchpotato/core/plugins/quality/static/quality.css @@ -0,0 +1,28 @@ +/* @override http://127.0.0.1:5000/static/quality_plugin/quality.css */ + +.group_sizes { + +} + + .group_sizes .head { + font-weight: bold; + } + + .group_sizes .ctrlHolder { + padding-top: 4px !important; + padding-bottom: 4px !important; + font-size: 12px; + } + + .group_sizes .label { + max-width: 120px; + } + + .group_sizes .min, .group_sizes .max { + text-align: center; + width: 50px; + max-width: 50px; + margin: 0 5px !important; + padding: 0 3px; + display: inline-block; + } \ No newline at end of file diff --git a/couchpotato/core/plugins/quality/static/quality.js b/couchpotato/core/plugins/quality/static/quality.js index e783f8e..3e61b06 100644 --- a/couchpotato/core/plugins/quality/static/quality.js +++ b/couchpotato/core/plugins/quality/static/quality.js @@ -58,7 +58,7 @@ var QualityBase = new Class({ */ createProfiles: function(){ var self = this; - + var non_core_profiles = Object.filter(self.profiles, function(profile){ return !profile.isCore() }); var count = Object.getLength(non_core_profiles); @@ -167,11 +167,12 @@ var QualityBase = new Class({ var group = self.settings.createGroup({ 'label': 'Sizes', 'description': 'Edit the minimal and maximum sizes (in MB) for each quality.', - 'advanced': true + 'advanced': true, + 'name': 'sizes' }).inject(self.content) - new Element('div.item.head').adopt( + new Element('div.item.head.ctrlHolder').adopt( new Element('span.label', {'text': 'Quality'}), new Element('span.min', {'text': 'Min'}), new Element('span.max', {'text': 'Max'}) @@ -180,11 +181,43 @@ var QualityBase = new Class({ Object.each(self.qualities, function(quality){ new Element('div.ctrlHolder.item').adopt( new Element('span.label', {'text': quality.label}), - new Element('input.min', {'value': quality.size_min}), - new Element('input.max', {'value': quality.size_max}) + new Element('input.min.inlay[type=text]', { + 'value': quality.size_min, + 'events': { + 'keyup': function(e){ + self.changeSize(quality.identifier, 'size_min', e.target.get('value')) + } + } + }), + new Element('input.max.inlay[type=text]', { + 'value': quality.size_max, + 'events': { + 'keyup': function(e){ + self.changeSize(quality.identifier, 'size_max', e.target.get('value')) + } + } + }) ).inject(group) }); + }, + + size_timer: {}, + changeSize: function(identifier, type, value){ + var self = this; + + if(self.size_timer[identifier + type]) clearTimeout(self.size_timer[identifier + type]); + + self.size_timer[identifier + type] = (function(){ + Api.request('quality.size.save', { + 'data': { + 'identifier': identifier, + 'value_type': type, + 'value': value + } + }); + }).delay(300) + } }); diff --git a/couchpotato/static/scripts/page/settings.js b/couchpotato/static/scripts/page/settings.js index 46558f2..4bc2913 100644 --- a/couchpotato/static/scripts/page/settings.js +++ b/couchpotato/static/scripts/page/settings.js @@ -178,7 +178,7 @@ Page.Settings = new Class({ var self = this; var group_el = new Element('fieldset', { - 'class': group.advanced ? 'inlineLabels advanced' : 'inlineLabels' + 'class': (group.advanced ? 'inlineLabels advanced' : 'inlineLabels') + ' group_' + (group.name || '') }).adopt( new Element('h2', { 'text': (group.label || group.name).capitalize()