[ui][aur] improved Required / Optional confirmation dialogs

This commit is contained in:
Vinicius Moreira
2019-11-26 19:09:00 -03:00
parent bed3db69e6
commit 7720d4d3e3
5 changed files with 42 additions and 6 deletions

View File

@@ -2,15 +2,28 @@ from typing import Set
from bauh.api.abstract.handler import ProcessWatcher
from bauh.api.abstract.view import MultipleSelectComponent, InputOption
from bauh.commons import resource
from bauh.commons.html import bold
from bauh.gems.arch import ROOT_DIR
from bauh.view.util.translation import I18n
def _get_mirror_icon(mirror: str):
return resource.get_path('img/{}.png'.format('arch' if mirror == 'aur' else 'mirror'), ROOT_DIR)
def request_optional_deps(pkgname: str, pkg_mirrors: dict, watcher: ProcessWatcher, i18n: I18n) -> Set[str]:
opts = [InputOption('{}{} ( {} )'.format(p, ': ' + d['desc'] if d['desc'] else '', d['mirror'].upper()), p) for p, d in pkg_mirrors.items()]
opts = []
for p, d in pkg_mirrors.items():
op = InputOption('{}{} ( {} )'.format(p, ': ' + d['desc'] if d['desc'] else '', d['mirror'].upper()), p)
op.icon_path = _get_mirror_icon(d['mirror'])
opts.append(op)
view_opts = MultipleSelectComponent(label='',
options=opts,
default_options=None)
install = watcher.request_confirmation(title=i18n['arch.install.optdeps.request.title'],
body='<p>{}</p>'.format(i18n['arch.install.optdeps.request.body'].format(bold(pkgname)) + ':'),
components=[view_opts],
@@ -22,8 +35,17 @@ def request_optional_deps(pkgname: str, pkg_mirrors: dict, watcher: ProcessWatch
def request_install_missing_deps(pkgname: str, pkg_mirrors: dict, watcher: ProcessWatcher, i18n: I18n) -> bool:
deps_str = ''.join(['<br/><span style="font-weight:bold"> - {} ( {} )</span>'.format(d, m.upper()) for d, m in pkg_mirrors.items()])
msg = '<p>{}</p>'.format(i18n['arch.missing_deps.body'].format(bold(pkgname)) + ':<br/>' + deps_str)
msg += i18n['ask.continue']
msg = '<p>{}</p>'.format(i18n['arch.missing_deps.body'].format(bold(pkgname)) + ':')
return watcher.request_confirmation(i18n['arch.missing_deps.title'], msg)
opts = []
for p, m in pkg_mirrors.items():
op = InputOption('{} ( {} )'.format(p, m), p)
op.read_only = True
op.icon_path = _get_mirror_icon(m)
opts.append(op)
comps = [
MultipleSelectComponent(label='', options=opts, default_options=set(opts))
]
return watcher.request_confirmation(i18n['arch.missing_deps.title'], msg, comps, confirmation_label=i18n['continue'].capitalize())