Skip to content

Commit

Permalink
Changed most of the editShow.mako to use vue for form handling.
Browse files Browse the repository at this point in the history
* Added some show config items to apiv2.
* Added indexer config items.
  • Loading branch information
p0psicles committed Feb 27, 2018
1 parent 36ea69e commit 3bc492c
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 25 deletions.
5 changes: 2 additions & 3 deletions medusa/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,11 +1029,10 @@ def get_show(name, try_indexers=False):

# try scene exceptions
if not series:
found_exceptions = scene_exceptions.get_scene_exceptions_by_name(series_name)
found_exceptions = list(scene_exceptions.get_scene_exceptions_by_name(series_name))
if found_exceptions:
# Only use the first exception.
exception = found_exceptions.pop()
series = Show.find_by_id(app.showList, exception.indexer, exception.series_id)
series = Show.find_by_id(app.showList, found_exceptions[0].indexer, found_exceptions[0].series_id)

if not series:
match_name_only = (s.name for s in app.showList if text_type(s.imdb_year) in s.name and
Expand Down
41 changes: 41 additions & 0 deletions medusa/indexers/indexer_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

"""Indexer config module."""

from six import text_type
from medusa.app import BASE_PYMEDUSA_URL
from medusa.indexers.tmdb.tmdb import Tmdb
from medusa.indexers.tvdbv2.tvdbv2_api import TVDBv2
Expand Down Expand Up @@ -113,3 +114,43 @@
'identifier': 'tmdb', # Also used as key for the custom scenename exceptions. (_get_custom_exceptions())
}
}


def create_config_json(indexer):
"""Create a json (pickable) conpatible dict, for using as an apiv2 resource."""
return {
'enabled': indexer['enabled'],
'id': indexer['id'],
'name': indexer['name'],
'module': text_type(indexer['module']),
'apiParams': {
'language': indexer['api_params']['language'],
'useZip': indexer['api_params']['use_zip'],
'session': '',
},
'xemOrigin': indexer.get('xem_origin'),
'icon': indexer.get('icon'),
'scene_loc': indexer.get('scene_loc'),
'baseUrl': indexer.get('base_url'),
'showUrl': indexer.get('show_url'),
'mappedTo': indexer.get('mapped_to'), # The attribute to which other indexers can map there thetvdb id to
'identifier': indexer.get('identifier'), # Also used as key for the custom scenename exceptions. (_get_custom_exceptions())
'validLanguages': initConfig['valid_languages'],
'langabbvToId': initConfig['langabbv_to_id'],
}


def get_indexer_config():
indexers = {
indexerConfig[indexer]['identifier']: create_config_json(indexerConfig[indexer]) for indexer in indexerConfig.keys()
}

main = {
'validLanguages': initConfig['valid_languages'],
'langabbvToId': initConfig['langabbv_to_id'],
'externalMappings': EXTERNAL_MAPPINGS,
'traktIndexers': TRAKT_INDEXERS,
'statusMap': STATUS_MAP
}

return {'indexers': indexers, 'main': main}
5 changes: 2 additions & 3 deletions medusa/server/api/v2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
db,
)
from medusa.helper.mappings import NonEmptyDict
from medusa.indexers.indexer_config import indexerConfig
from medusa.indexers.indexer_config import get_indexer_config
from medusa.server.api.v2.base import (
BaseRequestHandler,
BooleanField,
Expand Down Expand Up @@ -182,8 +182,7 @@ def get(self, identifier, path_param=None):
config_data['backlogOverview']['period'] = app.BACKLOG_PERIOD
config_data['backlogOverview']['status'] = app.BACKLOG_STATUS
config_data['indexers'] = NonEmptyDict()
config_data['indexers']['config'] = {text_type(indexer_id): indexer['identifier'] for indexer_id,
indexer in iteritems(indexerConfig)}
config_data['indexers']['config'] = get_indexer_config()

if not identifier:
return self._paginate([config_data])
Expand Down
2 changes: 2 additions & 0 deletions medusa/server/api/v2/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def patch(self, series_slug, path_param=None):
patches = {
'config.dvdOrder': BooleanField(series, 'dvd_order'),
'config.flattenFolders': BooleanField(series, 'flatten_folders'),
'config.anime': BooleanField(series, 'anime'),
'config.scene': BooleanField(series, 'scene'),
'config.sports': BooleanField(series, 'sports'),
'config.paused': BooleanField(series, 'paused'),
'config.location': StringField(series, '_location'),
'config.airByDate': BooleanField(series, 'air_by_date'),
Expand Down
2 changes: 2 additions & 0 deletions medusa/tv/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,9 @@ def to_json(self, detailed=True):
data['config']['subtitlesEnabled'] = bool(self.subtitles)
data['config']['dvdOrder'] = bool(self.dvd_order)
data['config']['flattenFolders'] = bool(self.flatten_folders)
data['config']['anime'] = self.is_anime
data['config']['scene'] = self.is_scene
data['config']['sports'] = self.is_sports
data['config']['paused'] = bool(self.paused)
data['config']['defaultEpisodeStatus'] = self.default_ep_status_name
data['config']['aliases'] = [_._asdict() for _ in self.aliases]
Expand Down
61 changes: 42 additions & 19 deletions themes/dark/templates/editShow.mako
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
% else:
<h1 class="title">${title}</h1>
% endif
<div id="config" ${"class=\"summaryFanArt\"" if app.FANART_BACKGROUND else ""}>
<div id="config-content">
<form action="home/editShow" method="post">
<div id="config-content">
<div id="config" v-bind:class="{ summaryFanArt: config.fanartBackground }">

This comment has been minimized.

Copy link
@OmgImAlexis

OmgImAlexis Feb 28, 2018

Collaborator

No need for v-bind use :class.

<form v-on:submit.prevent="storeConfig">

This comment has been minimized.

Copy link
@OmgImAlexis

OmgImAlexis Feb 28, 2018

Collaborator

Use @submit.prevent.

<div id="config-components">
<ul>
## @TODO: Fix this stupid hack
Expand All @@ -40,9 +40,9 @@
<label for="location">
<span class="component-title">Show Location</span>
<span class="component-desc">
<input type="hidden" name="indexername" id="form-indexername" value="${show.indexer_name}" />
<input type="hidden" name="seriesid" id="form-seriesid" value="${show.series_id}" />
<input type="text" name="location" id="location" value="${show._location}" class="form-control form-control-inline input-sm input350"/>
<input type="hidden" name="indexername" id="form-indexername" :value="seriesObj.indexer" />
<input type="hidden" name="seriesid" id="form-seriesid" :value="seriesObj.id[seriesObj.indexer]" />
<input type="text" name="location" id="location" :value="seriesObj.config.location" class="form-control form-control-inline input-sm input350"/>
</span>
</label>
</div>
Expand Down Expand Up @@ -72,7 +72,7 @@
<label for="indexerLangSelect">
<span class="component-title">Info Language</span>
<span class="component-desc">
<select name="indexer_lang" id="indexerLangSelect" class="form-control form-control-inline input-sm bfh-languages" data-blank="false" data-language="${show.lang}" data-available="${','.join(indexerApi().config['valid_languages'])}"></select>
<select name="indexer_lang" id="indexerLangSelect" class="form-control form-control-inline input-sm bfh-languages" data-blank="false" :data-language="seriesObj.language" :data-available="availableLanguagesAvailable" @change="storeConfig($event)"></select>
<div class="clear-left"><p>This only applies to episode filenames and the contents of metadata files.</p></div>
</span>
</label>
Expand All @@ -81,15 +81,15 @@
<label for="subtitles">
<span class="component-title">Subtitles</span>
<span class="component-desc">
<input type="checkbox" id="subtitles" name="subtitles" ${'checked="checked"' if show.subtitles == 1 and app.USE_SUBTITLES is True else ''} ${'' if app.USE_SUBTITLES else 'disabled="disabled"'}/> search for subtitles
<input type="checkbox" id="subtitles" name="subtitles" v-model="seriesObj.config.subtitlesEnabled" @change="storeConfig($event)"/> search for subtitles
</span>
</label>
</div>
<div class="field-pair">
<label for="paused">
<span class="component-title">Paused</span>
<span class="component-desc">
<input type="checkbox" id="paused" name="paused" ${'checked="checked"' if show.paused == 1 else ''} /> pause this show (Medusa will not download episodes)
<input type="checkbox" id="paused" name="paused" v-model="seriesObj.config.paused" @change="storeConfig($event)"/> pause this show (Medusa will not download episodes)
</span>
</label>
</div>
Expand All @@ -104,7 +104,7 @@
<label for="airbydate">
<span class="component-title">Air by date</span>
<span class="component-desc">
<input type="checkbox" id="airbydate" name="air_by_date" ${'checked="checked"' if show.air_by_date == 1 else ''} /> check if the show is released as Show.03.02.2010 rather than Show.S02E03.<br>
<input type="checkbox" id="airbydate" name="air_by_date" v-model="seriesObj.config.paused" @change="storeConfig($event)" /> check if the show is released as Show.03.02.2010 rather than Show.S02E03.<br>
<span style="color:rgb(255, 0, 0);">In case of an air date conflict between regular and special episodes, the later will be ignored.</span>
</span>
</label>
Expand All @@ -113,7 +113,7 @@
<label for="anime">
<span class="component-title">Anime</span>
<span class="component-desc">
<input type="checkbox" id="anime" name="anime" ${'checked="checked"' if show.is_anime == 1 else ''}> check if the show is Anime and episodes are released as Show.265 rather than Show.S02E03<br>
<input type="checkbox" id="anime" name="anime" v-model="seriesObj.config.anime" @change="storeConfig($event)"> check if the show is Anime and episodes are released as Show.265 rather than Show.S02E03<br>
% if show.is_anime:
<%include file="/inc_blackwhitelist.mako"/>
% endif
Expand All @@ -124,7 +124,7 @@
<label for="sports">
<span class="component-title">Sports</span>
<span class="component-desc">
<input type="checkbox" id="sports" name="sports" ${'checked="checked"' if show.sports == 1 else ''}/> check if the show is a sporting or MMA event released as Show.03.02.2010 rather than Show.S02E03<br>
<input type="checkbox" id="sports" name="sports" v-model="seriesObj.config.sports" @change="storeConfig($event)"/> check if the show is a sporting or MMA event released as Show.03.02.2010 rather than Show.S02E03<br>
<span style="color:rgb(255, 0, 0);">In case of an air date conflict between regular and special episodes, the later will be ignored.</span>
</span>
</label>
Expand All @@ -133,23 +133,23 @@
<label for="season_folders">
<span class="component-title">Season folders</span>
<span class="component-desc">
<input type="checkbox" id="season_folders" name="flatten_folders" ${'' if show.flatten_folders == 1 and not app.NAMING_FORCE_FOLDERS else 'checked="checked"'} ${'disabled="disabled"' if app.NAMING_FORCE_FOLDERS else ''}/> group episodes by season folder (uncheck to store in a single folder)
<input type="checkbox" id="season_folders" name="flatten_folders" v-model="seriesObj.config.flattenFolders" @change="storeConfig($event)"/> group episodes by season folder (uncheck to store in a single folder)
</span>
</label>
</div>
<div class="field-pair">
<label for="scene">
<span class="component-title">Scene Numbering</span>
<span class="component-desc">
<input type="checkbox" id="scene" name="scene" ${'checked="checked"' if show.scene == 1 else ''} /> search by scene numbering (uncheck to search by indexer numbering)
<input type="checkbox" id="scene" name="scene" v-model="seriesObj.config.scene" @change="storeConfig($event)"/> search by scene numbering (uncheck to search by indexer numbering)
</span>
</label>
</div>
<div class="field-pair">
<label for="dvdorder">
<span class="component-title">DVD Order</span>
<span class="component-desc">
<input type="checkbox" id="dvdorder" name="dvd_order" ${'checked="checked"' if show.dvd_order == 1 else ''} /> use the DVD order instead of the air order<br>
<input type="checkbox" id="dvdorder" name="dvd_order" v-model="seriesObj.config.dvdOrder" @change="storeConfig($event)"/> use the DVD order instead of the air order<br>
<div class="clear-left"><p>A "Force Full Update" is necessary, and if you have existing episodes you need to sort them manually.</p></div>
</span>
</label>
Expand Down Expand Up @@ -209,9 +209,6 @@
<br>
<input id="submit" type="submit" value="Save Changes" class="btn pull-left config_submitter button">
</form>
<my-component></my-component>
</div>
</div>
Expand Down Expand Up @@ -242,7 +239,9 @@ var startVue = function() {
config: MEDUSA.config,
exceptions: exceptions,
seriesSlug: seriesSlug,
seriesObj: seriesObj
seriesObj: seriesObj,
subtitles: seriesObj.config.subtitlesEnabled,
folders: seriesObj.config.flattenFolders
}
},
methods: {
Expand All @@ -252,7 +251,31 @@ var startVue = function() {
},
prettyPrintJSON: function(x) {
return JSON.stringify(x, undefined, 4)
},
storeConfig(evt) {
api.patch('config/main', {

This comment has been minimized.

Copy link
@OmgImAlexis

OmgImAlexis Feb 28, 2018

Collaborator

Use await.

This comment has been minimized.

Copy link
@p0psicles

p0psicles Feb 28, 2018

Author Contributor

Your sure? That's supported by less browsers then things like let and const and arrow.

This comment has been minimized.

Copy link
@OmgImAlexis

OmgImAlexis Feb 28, 2018

Collaborator

If it supports Promise/then it should support await.

This comment has been minimized.

Copy link
@p0psicles

p0psicles Feb 28, 2018

Author Contributor

yes your right!

config: {
dvdOrder: this.seriesObj.config.dvdOrder,
flattenFolders: this.seriesObj.config.flattenFolders,
anime: this.seriesObj.config.anime,
scene: this.seriesObj.config.scene,
sports: this.seriesObj.config.sports,
paused: this.seriesObj.config.paused,
location: this.seriesObj.config.location,
airByDate: this.seriesObj.config.airByDate,
subtitlesEnabled: this.seriesObj.config.subtitlesEnabled
}
}).then(response => {
log.info(response);
}).catch(err => {
log.error(err);
});
}
},
computed: {
availableLanguagesAvailable: function() {
return this.config.indexers.config.main.validLanguages.join(',');
}
}
});
$('[v-cloak]').removeAttr('v-cloak');
Expand Down

0 comments on commit 3bc492c

Please sign in to comment.