From f12d878c0b6f43087d3004b11046578e77b95f80 Mon Sep 17 00:00:00 2001 From: Ruud Date: Mon, 22 Jul 2013 21:57:13 +0200 Subject: [PATCH] Select category for search, suggest & edit --- .../core/plugins/category/static/category.css | 2 - .../core/plugins/category/static/category.js | 26 ++++++++---- couchpotato/core/plugins/movie/main.py | 6 ++- .../core/plugins/movie/static/movie.actions.js | 40 ++++++++++++++++-- couchpotato/core/plugins/movie/static/movie.js | 2 + couchpotato/core/plugins/movie/static/search.css | 46 ++++++++++++++++----- couchpotato/core/plugins/movie/static/search.js | 48 ++++++++++++++++++---- couchpotato/core/plugins/quality/static/quality.js | 3 +- .../core/plugins/suggestion/static/suggest.css | 12 ++++++ 9 files changed, 153 insertions(+), 32 deletions(-) diff --git a/couchpotato/core/plugins/category/static/category.css b/couchpotato/core/plugins/category/static/category.css index fda8ca6..0987c19 100644 --- a/couchpotato/core/plugins/category/static/category.css +++ b/couchpotato/core/plugins/category/static/category.css @@ -29,9 +29,7 @@ .category .formHint { width: 250px !important; - vertical-align: top !important; margin: 0 !important; - padding-left: 3px !important; opacity: 0.1; } .category:hover .formHint { diff --git a/couchpotato/core/plugins/category/static/category.js b/couchpotato/core/plugins/category/static/category.js index 092a74c..22bbc38 100644 --- a/couchpotato/core/plugins/category/static/category.js +++ b/couchpotato/core/plugins/category/static/category.js @@ -42,7 +42,7 @@ var CategoryListBase = new Class({ self.settings.createGroup({ 'label': 'Categories', - 'description': 'Create your own categories.' + 'description': 'Create categories, each one extending global filters. (Needs refresh \'' +(App.isMac() ? 'CMD+R' : 'F5')+ '\' after editing)' }).inject(self.content).adopt( self.category_container = new Element('div.container'), new Element('a.add_new_category', { @@ -63,6 +63,16 @@ var CategoryListBase = new Class({ }, + getCategory: function(id){ + return this.categories.filter(function(category){ + return category.data.id == id + }).pick() + }, + + getAll: function(){ + return this.categories; + }, + createCategory: function(data){ var self = this; @@ -78,7 +88,7 @@ var CategoryListBase = new Class({ var category_list; var group = self.settings.createGroup({ - 'label': 'Category order' + 'label': 'Category ordering' }).adopt( new Element('.ctrlHolder#category_ordering').adopt( new Element('label[text=Order]'), @@ -138,7 +148,6 @@ var Category = new Class({ var self = this; self.data = data; - self.types = []; self.create(); @@ -165,15 +174,16 @@ var Category = new Class({ new Element('input.inlay', { 'type':'text', 'value': data.label, - 'placeholder': 'Label' - }) + 'placeholder': 'Example: Kids, Horror or His' + }), + new Element('p.formHint', {'text': 'See global filters for explanation.'}) ), new Element('.category_preferred.ctrlHolder').adopt( new Element('label', {'text':'Preferred'}), new Element('input.inlay', { 'type':'text', 'value': data.preferred, - 'placeholder': 'Ignored' + 'placeholder': 'Blu-ray, DTS' }) ), new Element('.category_required.ctrlHolder').adopt( @@ -181,7 +191,7 @@ var Category = new Class({ new Element('input.inlay', { 'type':'text', 'value': data.required, - 'placeholder': 'Required' + 'placeholder': 'Example: DTS, AC3 & English' }) ), new Element('.category_ignored.ctrlHolder').adopt( @@ -189,7 +199,7 @@ var Category = new Class({ new Element('input.inlay', { 'type':'text', 'value': data.ignored, - 'placeholder': 'Ignored' + 'placeholder': 'Example: dubbed, swesub, french' }) ) ); diff --git a/couchpotato/core/plugins/movie/main.py b/couchpotato/core/plugins/movie/main.py index 0cc98fd..0e6ef13 100644 --- a/couchpotato/core/plugins/movie/main.py +++ b/couchpotato/core/plugins/movie/main.py @@ -2,7 +2,7 @@ from couchpotato import get_session from couchpotato.api import addApiView from couchpotato.core.event import fireEvent, fireEventAsync, addEvent from couchpotato.core.helpers.encoding import toUnicode, simplifyString -from couchpotato.core.helpers.variable import getImdb, splitString +from couchpotato.core.helpers.variable import getImdb, splitString, tryInt from couchpotato.core.logger import CPLog from couchpotato.core.plugins.base import Plugin from couchpotato.core.settings.model import Library, LibraryTitle, Movie, \ @@ -452,6 +452,10 @@ class MoviePlugin(Plugin): m.profile_id = kwargs.get('profile_id') + cat_id = kwargs.get('category_id', None) + if cat_id is not None: + m.category_id = tryInt(cat_id) if tryInt(cat_id) > 0 else None + # Remove releases for rel in m.releases: if rel.status_id is available_status.get('id'): diff --git a/couchpotato/core/plugins/movie/static/movie.actions.js b/couchpotato/core/plugins/movie/static/movie.actions.js index da47705..ad02e80 100644 --- a/couchpotato/core/plugins/movie/static/movie.actions.js +++ b/couchpotato/core/plugins/movie/static/movie.actions.js @@ -1,5 +1,5 @@ var MovieAction = new Class({ - + Implements: [Options], class_name: 'action icon2', @@ -521,6 +521,11 @@ MA.Edit = new Class({ self.profile_select = new Element('select', { 'name': 'profile' }), + self.category_select = new Element('select', { + 'name': 'category' + }).grab( + new Element('option', {'value': -1, 'text': 'None'}) + ), new Element('a.button.edit', { 'text': 'Save & Search', 'events': { @@ -540,7 +545,34 @@ MA.Edit = new Class({ }); - Quality.getActiveProfiles().each(function(profile){ + // Fill categories + var categories = CategoryList.getAll(); + + if(categories.length == 0) + self.category_select.hide(); + else { + self.category_select.show(); + categories.each(function(category){ + + var category_id = category.data.id; + + new Element('option', { + 'value': category_id, + 'text': category.data.label + }).inject(self.category_select); + + if(self.movie.category && self.movie.category.data && self.movie.category.data.id == category_id) + self.category_select.set('value', category_id); + + }); + } + + // Fill profiles + var profiles = Quality.getActiveProfiles(); + if(profiles.length == 1) + self.profile_select.hide(); + + profiles.each(function(profile){ var profile_id = profile.id ? profile.id : profile.data.id; @@ -551,6 +583,7 @@ MA.Edit = new Class({ if(self.movie.profile && self.movie.profile.data && self.movie.profile.data.id == profile_id) self.profile_select.set('value', profile_id); + }); } @@ -566,7 +599,8 @@ MA.Edit = new Class({ 'data': { 'id': self.movie.get('id'), 'default_title': self.title_select.get('value'), - 'profile_id': self.profile_select.get('value') + 'profile_id': self.profile_select.get('value'), + 'category_id': self.category_select.get('value') }, 'useSpinner': true, 'spinnerTarget': $(self.movie), diff --git a/couchpotato/core/plugins/movie/static/movie.js b/couchpotato/core/plugins/movie/static/movie.js index 5ca36c9..f5b5a2d 100644 --- a/couchpotato/core/plugins/movie/static/movie.js +++ b/couchpotato/core/plugins/movie/static/movie.js @@ -14,6 +14,7 @@ var Movie = new Class({ self.el = new Element('div.movie'); self.profile = Quality.getProfile(data.profile_id) || {}; + self.category = CategoryList.getCategory(data.category_id) || {}; self.parent(self, options); self.addEvents(); @@ -111,6 +112,7 @@ var Movie = new Class({ self.removeView(); self.profile = Quality.getProfile(self.data.profile_id) || {}; + self.category = CategoryList.getCategory(self.data.category_id) || {}; self.create(); self.busy(false); diff --git a/couchpotato/core/plugins/movie/static/search.css b/couchpotato/core/plugins/movie/static/search.css index e2aa0a4..73d867b 100644 --- a/couchpotato/core/plugins/movie/static/search.css +++ b/couchpotato/core/plugins/movie/static/search.css @@ -165,7 +165,8 @@ @media all and (max-width: 480px) { .movie_result .options select[name=title] { width: 90px; } - .movie_result .options select[name=profile] { width: 60px; } + .movie_result .options select[name=profile] { width: 50px; } + .movie_result .options select[name=category] { width: 50px; } } @@ -217,26 +218,51 @@ position: absolute; top: 20%; left: 15px; - right: 60px; + right: 7px; vertical-align: middle; } - + .movie_result .info h2 { + margin: 0; font-weight: normal; font-size: 20px; + padding: 0; + } + + .search_form .info h2 { + position: absolute; + width: 100%; + } + + .movie_result .info h2 .title { display: block; margin: 0; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; - width: 100%; - } - - .movie_result .info h2 span { - padding: 0 5px; - position: absolute; - right: -60px; } + + .search_form .info h2 .title { + position: absolute; + width: 88%; + } + + .movie_result .info h2 .year { + padding: 0 5px; + text-align: center; + position: absolute; + width: 12%; + right: 0; + } + + @media all and (max-width: 480px) { + + .search_form .info h2 .year { + font-size: 12px; + margin-top: 7px; + } + + } .search_form .mask, .movie_result .mask { diff --git a/couchpotato/core/plugins/movie/static/search.js b/couchpotato/core/plugins/movie/static/search.js index 5dcef07..2b318c1 100644 --- a/couchpotato/core/plugins/movie/static/search.js +++ b/couchpotato/core/plugins/movie/static/search.js @@ -216,9 +216,10 @@ Block.Search.Item = new Class({ } }).adopt( self.info_container = new Element('div.info').adopt( - self.title = new Element('h2', { - 'text': info.titles && info.titles.length > 0 ? info.titles[0] : 'Unknown' - }).adopt( + new Element('h2').adopt( + self.title = new Element('span.title', { + 'text': info.titles && info.titles.length > 0 ? info.titles[0] : 'Unknown' + }), self.year = info.year ? new Element('span.year', { 'text': info.year }) : null @@ -274,7 +275,9 @@ Block.Search.Item = new Class({ add: function(e){ var self = this; - (e).preventDefault(); + + if(e) + (e).preventDefault(); self.loadingMask(); @@ -282,7 +285,8 @@ Block.Search.Item = new Class({ 'data': { 'identifier': self.info.imdb, 'title': self.title_select.get('value'), - 'profile_id': self.profile_select.get('value') + 'profile_id': self.profile_select.get('value'), + 'category_id': self.category_select.get('value') }, 'onComplete': function(json){ self.options_el.empty(); @@ -335,7 +339,12 @@ Block.Search.Item = new Class({ self.profile_select = new Element('select', { 'name': 'profile' }), - new Element('a.button', { + self.category_select = new Element('select', { + 'name': 'category' + }).grab( + new Element('option', {'value': -1, 'text': 'None'}) + ), + self.add_button = new Element('a.button', { 'text': 'Add', 'events': { 'click': self.add.bind(self) @@ -350,7 +359,28 @@ Block.Search.Item = new Class({ }).inject(self.title_select) }) - Quality.getActiveProfiles().each(function(profile){ + + // Fill categories + var categories = CategoryList.getAll(); + + if(categories.length == 0) + self.category_select.hide(); + else { + self.category_select.show(); + categories.each(function(category){ + new Element('option', { + 'value': category.data.id, + 'text': category.data.label + }).inject(self.category_select); + }); + } + + // Fill profiles + var profiles = Quality.getActiveProfiles(); + if(profiles.length == 1) + self.profile_select.hide(); + + profiles.each(function(profile){ new Element('option', { 'value': profile.id ? profile.id : profile.data.id, 'text': profile.label ? profile.label : profile.data.label @@ -358,6 +388,10 @@ Block.Search.Item = new Class({ }); self.options_el.addClass('set'); + + if(categories.length == 0 && self.title_select.getElements('option').length == 1 && profiles.length == 1) + self.add(); + } }, diff --git a/couchpotato/core/plugins/quality/static/quality.js b/couchpotato/core/plugins/quality/static/quality.js index 84e80f8..ead9a90 100644 --- a/couchpotato/core/plugins/quality/static/quality.js +++ b/couchpotato/core/plugins/quality/static/quality.js @@ -103,7 +103,8 @@ var QualityBase = new Class({ var profile_list; var group = self.settings.createGroup({ - 'label': 'Profile Defaults' + 'label': 'Profile Defaults', + 'description': '(Needs refresh \'' +(App.isMac() ? 'CMD+R' : 'F5')+ '\' after editing)' }).adopt( new Element('.ctrlHolder#profile_ordering').adopt( new Element('label[text=Order]'), diff --git a/couchpotato/core/plugins/suggestion/static/suggest.css b/couchpotato/core/plugins/suggestion/static/suggest.css index 9eac020..2b05abf 100644 --- a/couchpotato/core/plugins/suggestion/static/suggest.css +++ b/couchpotato/core/plugins/suggestion/static/suggest.css @@ -34,6 +34,7 @@ left: 15px; right: 15px; bottom: 15px; + overflow: hidden; } .suggestions .movie_result .data .info h2 { @@ -83,6 +84,17 @@ .suggestions .movie_result .options { left: 100px; } + .suggestions .movie_result .options select[name=title] { width: 100%; } + .suggestions .movie_result .options select[name=profile] { width: 100%; } + .suggestions .movie_result .options select[name=category] { width: 100%; } + + .suggestions .movie_result .button { + position: absolute; + margin: 2px 0 0 0; + right: 15px; + bottom: 15px; + } + .suggestions .movie_result .thumbnail { width: 100px;