Skip to content

Commit

Permalink
Vueify add show options (#4848)
Browse files Browse the repository at this point in the history
* Add default options to apiv2 /config

* Update store.js with new default (add-show) options.

* Implement add-show-options.vue

* Make addShows_newShow.mako use the component to configure the new shows options and send the options when adding a new show.
* Fix anidb-release-group-ui.vue, update the data when property get's updated after mount.
* Fix config-textbox, config-textbox-number.vue, config-toggle-slider.vue.
* Update config.py, make sure the status and statusAfter are send as Strings not the numbers.

* Move back setTimeout method, that was removed.

* Added add-show-options.vue to src/components.

* Process review feedback

* Updates and fixes

* Build themes
* Small changes
* Pass show name directly to add-show-options
* Update release groups code
* Disable save defaults button when needed
* Rename default to showDefaults
* Fix quality-chooser
* [Lost track...]

* Fix enter button on the search input submitting the form

* Fix bad HTML in inc_addShowOptions.mako

* Implement saving defaults

* Remove unused code

* Lint

* Fix `is_valid_combined_quality`, add test

* Replace old jQuery code for refreshing the show options section

* Update inc_addShowOptions.mako

* Rename seasonFolder to seasonFolders

* Update addShows_newShow.mako
Prepares the code for the future and fixes a bug with `toggle-button`

- Replace all hidden inputs
- Remove all `name` props
- Update `submitForm` code to use Vue data
- Only send the new show data if we're not skipping the show
- Fix values being added to `formData` twice after clicking a `toggle-button`

* Move some watches to `mounted()` and add missing `selectedSubtitleEnabled` watch

* Add render test

* Lint

* Test `utils.combineQualities`

* Fixes for clicking enter on the show name search input

* Clicking enter triggered saving add show defaults
* Clicking enter triggered native form submission

* Fix `toggle-slider` value not updated when prop value is updated

* Update changelog

* Only show anime option if `enableAnimeOptions` prop is `true`

The original `addShowOptions` had that, this should too.

+ Add comment that the `QualityChooser` component should be imported

* Update notifications

- Add notification about error getting release groups
- Remove commented out notification

* Add missing `apiRoute` import
  • Loading branch information
p0psicles authored Sep 10, 2018
1 parent 27969d7 commit a0a3d42
Show file tree
Hide file tree
Showing 36 changed files with 1,248 additions and 314 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Updated `guessit` to version 3.0.0 ([#4244](https://github.com/pymedusa/Medusa/pull/4244))
- Updated the API v2 endpoint to handle concurrent requests ([#4970](https://github.com/pymedusa/Medusa/pull/4970))
- Converted some of the show header to Vue ([#5087](https://github.com/pymedusa/Medusa/pull/5087))
- Converted "Add Show" options into a Vue SFC ([#4848](https://github.com/pymedusa/Medusa/pull/4848))

#### Fixes
- Fixed many release name parsing issues as a result of updating `guessit` ([#4244](https://github.com/pymedusa/Medusa/pull/4244))
Expand Down
16 changes: 16 additions & 0 deletions medusa/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,22 @@ def split_quality(quality):

return sorted(allowed_qualities), sorted(preferred_qualities)

@staticmethod
def is_valid_combined_quality(quality):
"""
Check quality value to make sure it is a valid combined quality.
:param quality: Quality to check
:type quality: int
:return: True if valid, False if not
"""
for cur_qual in Quality.qualityStrings:
if cur_qual & quality:
quality -= cur_qual
if cur_qual << 16 & quality:
quality -= cur_qual << 16
return quality == 0

@staticmethod
def name_quality(name, anime=False, extend=True):
"""
Expand Down
24 changes: 24 additions & 0 deletions medusa/server/api/v2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
logger,
ws,
)
from medusa.common import IGNORED, Quality, SKIPPED, WANTED
from medusa.helper.mappings import NonEmptyDict
from medusa.indexers.indexer_config import get_indexer_config
from medusa.logger.adapters.style import BraceAdapter
Expand Down Expand Up @@ -51,6 +52,11 @@ def theme_name_setter(object, name, value):
config.change_theme(value)


def season_folders_validator(value):
"""Validate default season folders setting."""
return not (app.NAMING_FORCE_FOLDERS and value is False)


class ConfigHandler(BaseRequestHandler):
"""Config request handler."""

Expand Down Expand Up @@ -116,6 +122,15 @@ class ConfigHandler(BaseRequestHandler):
'backlogOverview.period': StringField(app, 'BACKLOG_PERIOD'),
'backlogOverview.status': StringField(app, 'BACKLOG_STATUS'),
'rootDirs': ListField(app, 'ROOT_DIRS'),

'showDefaults.status': EnumField(app, 'STATUS_DEFAULT', (SKIPPED, WANTED, IGNORED), int),
'showDefaults.statusAfter': EnumField(app, 'STATUS_DEFAULT_AFTER', (SKIPPED, WANTED, IGNORED), int),
'showDefaults.quality': IntegerField(app, 'QUALITY_DEFAULT', validator=Quality.is_valid_combined_quality),
'showDefaults.subtitles': BooleanField(app, 'SUBTITLES_DEFAULT', validator=lambda v: app.USE_SUBTITLES, converter=bool),
'showDefaults.seasonFolders': BooleanField(app, 'SEASON_FOLDERS_DEFAULT', validator=season_folders_validator, converter=bool),
'showDefaults.anime': BooleanField(app, 'ANIME_DEFAULT', converter=bool),
'showDefaults.scene': BooleanField(app, 'SCENE_DEFAULT', converter=bool),

'postProcessing.showDownloadDir': StringField(app, 'TV_DOWNLOAD_DIR'),
'postProcessing.processAutomatically': BooleanField(app, 'PROCESS_AUTOMATICALLY'),
'postProcessing.processMethod': StringField(app, 'PROCESS_METHOD'),
Expand Down Expand Up @@ -297,6 +312,15 @@ def data_main():
section_data['subtitles']['enabled'] = bool(app.USE_SUBTITLES)
section_data['recentShows'] = app.SHOWS_RECENT

section_data['showDefaults'] = {}
section_data['showDefaults']['status'] = app.STATUS_DEFAULT
section_data['showDefaults']['statusAfter'] = app.STATUS_DEFAULT_AFTER
section_data['showDefaults']['quality'] = app.QUALITY_DEFAULT
section_data['showDefaults']['subtitles'] = bool(app.SUBTITLES_DEFAULT)
section_data['showDefaults']['seasonFolders'] = bool(app.SEASON_FOLDERS_DEFAULT)
section_data['showDefaults']['anime'] = bool(app.ANIME_DEFAULT)
section_data['showDefaults']['scene'] = bool(app.SCENE_DEFAULT)

section_data['news'] = NonEmptyDict()
section_data['news']['lastRead'] = app.NEWS_LAST_READ
section_data['news']['latest'] = app.NEWS_LATEST
Expand Down
9 changes: 9 additions & 0 deletions tests/apiv2/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ def config_main(monkeypatch, app_config):
config_data['subtitles']['enabled'] = bool(app.USE_SUBTITLES)
config_data['recentShows'] = app.SHOWS_RECENT

config_data['showDefaults'] = {}
config_data['showDefaults']['status'] = app.STATUS_DEFAULT
config_data['showDefaults']['statusAfter'] = app.STATUS_DEFAULT_AFTER
config_data['showDefaults']['quality'] = app.QUALITY_DEFAULT
config_data['showDefaults']['subtitles'] = bool(app.SUBTITLES_DEFAULT)
config_data['showDefaults']['seasonFolders'] = bool(app.SEASON_FOLDERS_DEFAULT)
config_data['showDefaults']['anime'] = bool(app.ANIME_DEFAULT)
config_data['showDefaults']['scene'] = bool(app.SCENE_DEFAULT)

config_data['news'] = NonEmptyDict()
config_data['news']['lastRead'] = app.NEWS_LAST_READ
config_data['news']['latest'] = app.NEWS_LATEST
Expand Down
30 changes: 30 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,33 @@ def test_wanted_quality():

# Then
assert actual is True


@pytest.mark.parametrize('p', [
{ # p0 - Invalid combined quality
'quality': -4,
'expected': False
},
{ # p1 - Valid 'allowed' quality
'quality': Quality.HDTV,
'expected': True
},
{ # p2 - Valid 'allowed' quality + valid 'preferred' quality
'quality': Quality.combine_qualities([Quality.HDTV], [Quality.HDWEBDL]),
'expected': True
},
{ # p3 - Valid 'allowed' quality + **invalid** 'preferred' quality
'quality': Quality.combine_qualities([Quality.HDTV], [-4]),
'expected': False
},
])
def test_is_valid_combined_quality(p):
# Given
quality = p['quality']
expected = p['expected']

# When
actual = Quality.is_valid_combined_quality(quality)

# Then
assert expected == actual
Loading

0 comments on commit a0a3d42

Please sign in to comment.