Changeable quality sizes
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
from couchpotato import get_session
|
from couchpotato import get_session
|
||||||
|
from couchpotato.api import addApiView
|
||||||
from couchpotato.core.event import addEvent, fireEvent
|
from couchpotato.core.event import addEvent, fireEvent
|
||||||
from couchpotato.core.helpers.encoding import toUnicode
|
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.logger import CPLog
|
||||||
from couchpotato.core.plugins.base import Plugin
|
from couchpotato.core.plugins.base import Plugin
|
||||||
from couchpotato.core.settings.model import Quality, Profile, ProfileType
|
from couchpotato.core.settings.model import Quality, Profile, ProfileType
|
||||||
@@ -32,6 +35,8 @@ class QualityPlugin(Plugin):
|
|||||||
addEvent('quality.single', self.single)
|
addEvent('quality.single', self.single)
|
||||||
addEvent('quality.guess', self.guess)
|
addEvent('quality.guess', self.guess)
|
||||||
|
|
||||||
|
addApiView('quality.size.save', self.saveSize)
|
||||||
|
|
||||||
addEvent('app.initialize', self.fill, priority = 10)
|
addEvent('app.initialize', self.fill, priority = 10)
|
||||||
|
|
||||||
def all(self):
|
def all(self):
|
||||||
@@ -42,7 +47,7 @@ class QualityPlugin(Plugin):
|
|||||||
|
|
||||||
temp = []
|
temp = []
|
||||||
for quality in qualities:
|
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)
|
temp.append(q)
|
||||||
|
|
||||||
return temp
|
return temp
|
||||||
@@ -64,6 +69,21 @@ class QualityPlugin(Plugin):
|
|||||||
if identifier == q.get('identifier'):
|
if identifier == q.get('identifier'):
|
||||||
return q
|
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):
|
def fill(self):
|
||||||
|
|
||||||
db = get_session();
|
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(){
|
createProfiles: function(){
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var non_core_profiles = Object.filter(self.profiles, function(profile){ return !profile.isCore() });
|
var non_core_profiles = Object.filter(self.profiles, function(profile){ return !profile.isCore() });
|
||||||
var count = Object.getLength(non_core_profiles);
|
var count = Object.getLength(non_core_profiles);
|
||||||
|
|
||||||
@@ -167,11 +167,12 @@ var QualityBase = new Class({
|
|||||||
var group = self.settings.createGroup({
|
var group = self.settings.createGroup({
|
||||||
'label': 'Sizes',
|
'label': 'Sizes',
|
||||||
'description': 'Edit the minimal and maximum sizes (in MB) for each quality.',
|
'description': 'Edit the minimal and maximum sizes (in MB) for each quality.',
|
||||||
'advanced': true
|
'advanced': true,
|
||||||
|
'name': 'sizes'
|
||||||
}).inject(self.content)
|
}).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.label', {'text': 'Quality'}),
|
||||||
new Element('span.min', {'text': 'Min'}),
|
new Element('span.min', {'text': 'Min'}),
|
||||||
new Element('span.max', {'text': 'Max'})
|
new Element('span.max', {'text': 'Max'})
|
||||||
@@ -180,11 +181,43 @@ var QualityBase = new Class({
|
|||||||
Object.each(self.qualities, function(quality){
|
Object.each(self.qualities, function(quality){
|
||||||
new Element('div.ctrlHolder.item').adopt(
|
new Element('div.ctrlHolder.item').adopt(
|
||||||
new Element('span.label', {'text': quality.label}),
|
new Element('span.label', {'text': quality.label}),
|
||||||
new Element('input.min', {'value': quality.size_min}),
|
new Element('input.min.inlay[type=text]', {
|
||||||
new Element('input.max', {'value': quality.size_max})
|
'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)
|
).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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ Page.Settings = new Class({
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var group_el = new Element('fieldset', {
|
var group_el = new Element('fieldset', {
|
||||||
'class': group.advanced ? 'inlineLabels advanced' : 'inlineLabels'
|
'class': (group.advanced ? 'inlineLabels advanced' : 'inlineLabels') + ' group_' + (group.name || '')
|
||||||
}).adopt(
|
}).adopt(
|
||||||
new Element('h2', {
|
new Element('h2', {
|
||||||
'text': (group.label || group.name).capitalize()
|
'text': (group.label || group.name).capitalize()
|
||||||
|
|||||||
Reference in New Issue
Block a user