Changeable quality sizes

This commit is contained in:
Ruud
2011-10-09 18:02:48 +02:00
parent 7321505d1b
commit 6d998f7268
4 changed files with 88 additions and 7 deletions
+21 -1
View File
@@ -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();
@@ -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;
}
@@ -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)
}
});
+1 -1
View File
@@ -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()