def viewdropdown_change(e, d): if this.props.query: utils.go_to(this.props.history, query={'view_type': d.value}, push=False) if this.props.on_change: this.props.on_change(e, d)
def sortdropdown_change(e, d): if this.props.query: utils.go_to(this.props.history, query={'sort_idx': d.value}, push=False) if this.props.on_change: this.props.on_change(e, d)
def filterdropdown_change(e, d): if this.props.query: utils.go_to(this.props.history, query={'filter_id': d.value}, push=False) if this.props.on_change: this.props.on_change(e, d)
def itembuttons_change(e, d): if this.props.query: utils.go_to(this.props.history, query={'item_type': d.value}, push=False) if this.props.on_change: this.props.on_change(e, d)
def get_item(ctx=None, data=None, error=None): if ctx is not None and not error: if data is not None: this.setState({"data": data, "loading": False}) if not this.state.pages: this.get_page_count(gid=data.gallery_id) this.get_pages(gid=data.gallery_id) else: if not utils.get_query("retry"): utils.go_to(this.props.history, this.get_page_url(1), query={"retry": True}, push=False) elif error: state.app.notif("Failed to fetch item ({})".format(this.state.id), level="error") else: gid = int(this.props.match.params.gallery_id) number = int(this.props.match.params.page_number) client.log("Fetching page: " + number) if this.state.data and number == this.state.data.number: client.log("Current page data is the same") return if this.state.pages: if number in this.state.pages: client.log("Retrieving cached page") this.setState({'data': this.state.pages[number]['data']}) return client.log("Retrieving new page") if gid: client.call_func("get_page", this.get_item, gallery_id=gid, number=number, ctx=True) this.setState({'loading': True})
def itemviewpage_update(p_p, p_s): if any(( p_s.view_type != this.state.view_type, p_p.view_type != this.props.view_type, p_s.item_type != this.state.item_type, p_s.filter_id != this.state.filter_id, p_s.sort_desc != this.state.sort_desc, p_s.sort_idx != this.state.sort_idx, p_s.visible_config != this.state.visible_config and this.state.visible_config, )): utils.scroll_to_top() if any((p_p.view_type != this.props.view_type, )): this.setState({'view_type': this.default_view()}) if any(( p_s.view_type != this.state.view_type, p_p.view_type != this.props.view_type, p_s.item_type != this.state.item_type, p_s.filter_id != this.state.filter_id, p_s.sort_idx != this.state.sort_idx, )): this.update_menu() if any((p_s.item_type != this.state.item_type, )): s = { 'sort_idx': utils.storage.get( "def_sort_idx" + this.state.item_type + this.config_suffix, 0) } this.setState(s) utils.go_to(this.props.history, query=s)
def get_more(): pages = math.ceil(this.state.item_count / this.state.limit) if this.state.infinite_scroll and this.state.page < pages: next_page = int(this.state.page) + 1 this.setState({ 'page': next_page, 'prev_page': this.state.page, 'loading_more': True }) if this.props.history: utils.go_to(this.props.history, query={'page': next_page}, push=False)
def on_search(e, d): e.preventDefault() if e else None if e is not None: d = this.search_data if this.props.query and this.props.history: utils.go_to(this.props.history, query={'search': d}) if this.props.on_search: o = { 'regex': 'regex', 'case': 'case_sensitive', 'whole': 'match_whole_words', 'all': 'match_all_terms', 'desc': 'descendants', } __pragma__("iconv") options = {} for k in o: options[o[k]] = this.state[k] __pragma__("noiconv") this.props.on_search(d, options)
def server_notifications(data=js_undefined, error=None): if data is not js_undefined and not error: if data: if data.actions: this.setState({'server_push_msg': data, 'server_push': True}) else: tmout = 20000 ic = "info" msg = data['body'] if data['id'] in (PushID.Update,): tmout = tmout * 1.5 ic = "angle double up" if state.history: utils.go_to(state.history, "/activity") this.notif(tr(None, "ui.t-changelog-location", "About -> Changelog"), data['title'], icon=ic, timeout=tmout) this.notif(msg, data['title'], icon=ic, timeout=tmout) elif error: this.notif("Failed to retrieve server notification", level="warning") else: if state['active'] and state['connected'] and state['accepted'] and utils.storage.get( "ping_for_notifications", True): pushclient.call_func("get_notification", this.server_notifications)
def go_prev(): if int(this.state.data.number) > 1: utils.go_to(this.props.history, this.get_page_url(this.state.data.number - 1))
def itemviewbase_render(): props = this.props pagination = [] if props.show_pagination or not utils.defined(props.show_pagination): pagination.append( e( ui.Grid.Row, e( ui.Responsive, e(Pagination, history=this.props.history, location=this.props.location, limit=1, pages=props.item_count / props.limit, current_page=props.page, on_change=props.set_page, context=this.props.context or this.state.context_node, query=this.props.query, scroll_top=True, size="tiny"), maxWidth=578, ), e( ui.Responsive, e(Pagination, history=this.props.history, location=this.props.location, pages=props.item_count / props.limit, context=this.props.context or this.state.context_node, current_page=props.page, on_change=props.set_page, query=this.props.query, scroll_top=True), minWidth=579, ), centered=True, )) lscreen = 3 wscreen = 2 if props.container: lscreen = wscreen = 4 els = props.children if not els: els = [] add_el = [] if props.label: add_el.append( e(ui.Label, props.label, e(ui.Label.Detail, props.item_count), e(ui.Button, compact=True, basic=True, icon="options", floated="right", size="mini", onClick=props.toggle_config), attached="top")) cfg_el = [] if props.config_el: cfg_el.append(props.config_el) count_el = [] if (not utils.defined(props.show_count)) or props.show_count: count_el.append( e(ui.Grid.Column, e( ui.Header, e(ui.Header.Subheader, tr(this, "ui.t-showing-count", "Showing {}".format(props.item_count), placeholder={ 'from': (props.page - 1) * props.limit + 1, 'to': (props.page - 1) * props.limit + len(els), 'all': props.item_count }), as_="h6"), ), textAlign="center", width=16)) infinite_el = [] if this.props.infinite_scroll: infinite_el.append( e( ui.Grid.Row, e( ui.Visibility, e(ui.Loader, active=props.loading_more if utils.defined(props.loading_more) else (props.infinite_scroll and props.loading)), context=this.props.infinite_scroll_context, onTopVisible=this.props.on_load_more, once=False, ), )) nav_els = [] if this.props.show_itembuttons: nav_els.append( e(ui.Menu.Item, e( item.ItemButtons, history=this.props.history, on_change=this.props.on_item_change, value=this.props.default_item, query=this.props.query, ), icon=True)) if this.props.show_search: nav_els.append( e(ui.Menu.Menu, e(ui.Menu.Item, e( item.Search, history=this.props.history, location=this.props.location, size="small", fluid=True, on_search=this.props.on_search, search_query=this.props.default_search, query=this.props.query, ), className="fullwidth"), position="left", className="fullwidth")) history = this.props.history default_sort_desc = this.props.default_sort_desc on_sort_desc = this.props.on_sort_desc default_filter = this.props.default_filter on_filter_change = this.props.on_filter_change if this.props.show_sortdropdown: nav_els.append( e(ui.Menu.Item, e( ToggleIcon, icons=["sort content ascending", "sort content descending"], on_toggle=lambda a: all( (on_sort_desc(a), utils.go_to( history, query={'sort_desc': int(a)}, push=False))), toggled=default_sort_desc, ), e( item.SortDropdown, history=this.props.history, on_change=this.props.on_sort_change, item_type=this.props.default_item, query=this.props.query, value=this.props.default_sort or utils.storage.get( "def_sort_idx" + this.props.default_item + this.props.config_suffix, 0), ), icon=True)) if this.props.show_filterdropdown: nav_els.append( e(ui.Menu.Item, e( ui.Icon, js_name="delete" if default_filter else "filter", link=True if default_filter else False, onClick=js_undefined if not default_filter else lambda: all( (on_filter_change(None, 0), utils.go_to(history, query={'filter_id': 0}, push=False) )), ), e( item.FilterDropdown, history=this.props.history, on_change=this.props.on_filter_change, value=this.props.default_filter, query=this.props.query, inline=True, ), icon=True)) if len(nav_els) != 0: nav_els = [ e( ui.Grid.Row, e(ui.Grid.Column, e( ui.Menu, *nav_els, secondary=True, borderless=True, stackable=True, size="small", ), width=16)) ] el = e( ui.Sidebar.Pushable, *cfg_el, e(ui.Sidebar.Pusher, e( ui.Grid, *nav_els, *count_el, *pagination, [ e(ui.Grid.Column, c, verticalAlign="middle", computer=4, tablet=3, mobile=6, largeScreen=lscreen, widescreen=wscreen, key=k) for k, c in els ], *infinite_el, *pagination, *count_el, padded="vertically", centered=True, verticalAlign="middle", as_=ui.Transition.Group, animation='pulse', duration=800, ), as_=ui.Segment, basic=True, loading=props.loading if utils.defined(props.loading_more) else (props.loading and not props.infinite_scroll), className="no-padding-segment"), ) if props.secondary or props.tertiary or len(add_el): el = e( ui.Segment, *add_el, el, basic=True, secondary=props.secondary, tertiary=props.tertiary, ) return e( ui.Ref, el, innerRef=this.get_context_node, )
get_thumbs, 'get_item': get_item, 'get_gallery': get_gallery, 'get_pages': get_pages, 'get_page_count': get_page_count, 'on_key': on_key, 'on_pagelist_load_more': lambda: this.get_pages(), 'back_to_gallery': lambda: utils.go_to(this.props.history, "/item/gallery/{}".format(this.props.match.params. gallery_id), keep_query=False), 'set_cfg_direction': lambda e, d: all((this.setState({'cfg_direction': d.value}), utils.storage.set("reader_direction", d.value))), 'set_cfg_scaling': lambda e, d: all((this.setState({'cfg_scaling': d.value}), utils.storage.set("reader_scaling", d.value))), 'set_cfg_stretch': lambda e, d: all((this.setState({'cfg_stretch': d.checked}), utils.storage.set("reader_stretch", d.checked))), 'set_cfg_invert': lambda e, d: all((this.setState({'cfg_invert': d.checked}), utils.storage.set("reader_invert", d.checked))), 'set_cfg_pagelist_open': lambda e, d: all(
def go_next(): if int(this.state.data.number) < int(this.state.page_count): utils.go_to(this.props.history, this.get_page_url(this.state.data.number + 1))
'data': [], 'limit': 50, 'page': 1, 'count': 0, 'data_loading': False, }, 'get_items': get_db_parodies, 'get_items_count': get_parodies_count, 'set_page': lambda p: all((this.setState({'page': p}), )), 'update_search': lambda e, d: all( (this.setState({'search_query': d.value}), utils.go_to(this.props.history, query={'search': d.value}, push=False) )), 'componentDidMount': lambda: all((this.get_items(), this.get_items_count())), 'componentDidUpdate': lambda p_p, p_s: this.get_items() if any((p_s.search_query != this.state.search_query, p_s.page != this.state .page)) else None, 'render': parodiespage_render }) def get_db_categories(data=None, error=None): if data is not None and not error: this.setState({"data": data, 'data_loading': False})
def search_option_change(e, d): this.setState({d.js_name: d.checked}) if this.props.query: utils.storage.set("search_{}".format(d.js_name), d.checked) utils.go_to(this.props.history, query={d.js_name: '1' if d.checked else '0'})
*els, textAlign="center", ), columns=1 ) PageNav = createReactClass({ 'displayName': 'PageNav', 'getInitialState': lambda: { 'go_to_page': None, }, 'on_page_input': lambda e, d: this.setState({'go_to_page': d.value}), 'go_to_page': lambda: utils.go_to(this.props.history, this.props.get_page_url(this.state.go_to_page)) if this.state.go_to_page and this.props.get_page_url else None, 'render': pagenav_render, }, pure=True) __pragma__("iconv") __pragma__("tconv") __pragma__("jsiter") def set_thumbs(cmd): if this.cmd_data and this.state.pages: values = cmd.get_value() d = this.state.pages for pnumb in d:
(this.setState({'sort_desc': not this.state.sort_desc}), utils.session_storage.set("sort_desc" + this.config_suffix(), not this.state.sort_desc))), 'on_filter_change': lambda e, d: all( (this.setState({'filter_id': d.value}), utils.session_storage.set("filter_id" + this.config_suffix(), utils.either(d.value, 0)))), 'on_search': lambda s, o: all((this.setState({ 'search_query': s if s else '', 'search_options': o }), utils.storage.set("search_options", o))), 'reset_page': lambda p: all(( utils.go_to(this.props.history, query={'page': 1}, push=False), this.setState({'page': 1}), )), 'set_page': lambda p: this.setState({ 'page': p, 'prev_page': None }), 'remove_item': remove_item, 'on_blur': lambda e, d: this.setState({'blur': d.checked}), 'on_infinite_scroll': lambda e, d: this.setState({'infinite_scroll': d.checked}), 'on_item_count': lambda e, d: this.setState({'limit': d.value}),
def item_view_menu(history, props_view_type=None, on_item_change=None, default_item=None, on_sort_change=None, default_sort=None, on_view_change=None, default_view=None, on_sort_desc=None, default_sort_desc=None, on_search=None, default_search=None, on_filter_change=None, default_filter=None, on_toggle_config=None, cfg_suffix=None): #v = utils.storage.get("def_sort_idx" + default_item + cfg_suffix, 0) return [ e( ui.Menu.Item, e( item.ItemButtons, e( item.ViewDropdown, button=True, basic=True, value=default_view, on_change=on_view_change, query=True, history=history, className="active", view_type=props_view_type, ), history=history, on_change=on_item_change, value=default_item, query=True, )), e(ui.Menu.Menu, e( ui.Menu.Item, e(withRouter(item.Search), size="small", fluid=True, on_search=on_search, query=True, search_query=default_search), className="fullwidth", ), position="left", className="fullwidth"), e( ui.Menu.Item, e( ToggleIcon, icons=["sort content ascending", "sort content descending"], on_toggle=lambda a: all( (on_sort_desc(a), utils.go_to( history, query={'sort_desc': int(a)}, push=False))), toggled=default_sort_desc, ), e(item.SortDropdown, history=history, on_change=on_sort_change, value=default_sort or utils.storage.get( "def_sort_idx" + default_item + cfg_suffix, 0), item_type=default_item, query=True)), e( ui.Menu.Item, e( ui.Icon, js_name="delete" if default_filter else "filter", link=True if default_filter else False, onClick=js_undefined if not default_filter else lambda: all(( on_filter_change(None, 0), utils.go_to(history, query={'filter_id': 0}, push=False))), ), e(item.FilterDropdown, history=history, on_change=on_filter_change, value=default_filter, query=True)), e(ui.Menu.Item, e(ui.Icon, js_name="options", size="large"), icon=True, onClick=on_toggle_config), ]