Exemple #1
0
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})
Exemple #2
0
def pagination_receive_props(n_props):
    n_page = int(utils.get_query("page", this.state.current_page))
    if this.props.query and\
            n_props.location != this.props.location and\
            n_page != this.state.current_page and \
            n_page != this.props.current_page:
        this.change_page(n_page)
Exemple #3
0

__pragma__("notconv")

ScanPage = createReactClass({
    'displayName':
    'ScanPage',
    'scan_cmd':
    None,
    'view_cmd':
    None,
    'getInitialState':
    lambda: {
        'config': {},
        'limit': 50,
        'page': utils.get_query("page", 1),
        'loading': False,
        'view_loading': False,
        'progress_data': None,
        'view_progress_data': None,
        'view_id': utils.session_storage.get("scan_view_id", None),
        'view_data': {},
        'path': "",
        'submitted_path': '',
        'gallery.add_to_inbox': js_undefined,
        'scan.skip_existing_galleries': js_undefined,
    },
    'set_path':
    lambda e, d: all((this.setState({'path': d.value}), )),
    'get_view':
    get_view,
Exemple #4
0
def pagination_render():
    limit = this.props.limit
    if not limit:
        limit = 6
    pages = this.props.pages
    if not pages or pages < 1:
        pages = 1
    current_page = this.props.current_page or this.state.current_page
    if this.props.history and this.props.query and not current_page:
        current_page = utils.get_query("page", this.state.current_page)
    if not current_page:
        current_page = 1
    current_page = int(current_page)

    pages = math.ceil(pages)

    page_list = range(1, pages + 1)
    ellipsis_pos = 2 if limit > 2 else 1
    nav_back = True
    nav_next = True
    first_ellipses = False
    second_ellipses = False

    if current_page - 1 == 0:
        nav_back = False

    if current_page == len(page_list):
        nav_next = False

    if limit and current_page > limit and current_page > ellipsis_pos:
        first_ellipses = True

    if (pages - current_page) > limit and pages > ellipsis_pos:
        second_ellipses = True

    go_next = this.go_next
    go_prev = this.go_prev
    go_page = this.go_page

    half_limit = int(limit / 2)
    l_index = current_page - (half_limit if half_limit else 1)
    r_index = current_page + half_limit + 1
    if r_index > len(page_list):
        r_index = len(page_list)
        l_index = len(page_list) - (limit + 1)

    if l_index < 0:
        l_index = 0
        r_index = limit
    current_pages = page_list[l_index:r_index]

    if this.props.query:

        def make_items(i):
            return [
                e(
                    ui.Menu.Item,
                    js_name=str(x),
                    active=current_page == x,
                    onClick=go_page,  # noqa: E704
                    as_=QueryLink,
                    query={'page': x}) for x in i
            ]  # noqa: E704
    else:

        def make_items(i):
            return [
                e(
                    ui.Menu.Item,
                    js_name=str(  # noqa: E704
                        x),
                    active=current_page == x,
                    onClick=go_page) for x in i
            ]  # noqa: E704

    items = make_items(current_pages)

    query_args = {}
    if this.props.query:
        query_args = {
            'as': QueryLink,
            'query': {
                'page': this.state.go_to_page
            }
        }
    go_el = e(ui.Popup,
              e(ui.Form,
                e(
                    ui.Form.Field,
                    e(ui.Input,
                      onChange=this.go_to_change,
                      size="mini",
                      js_type="number",
                      placeholder=current_page,
                      action=e(ui.Button,
                               js_type="submit",
                               compact=True,
                               icon="share",
                               onClick=this.go_to_page,
                               **query_args),
                      min=0,
                      max=pages),
                ),
                onSubmit=this.go_to_page),
              on="click",
              hoverable=True,
              position="top center",
              trigger=e(ui.Menu.Item, "..."))

    if first_ellipses:
        ellip_items = make_items(page_list[:ellipsis_pos])
        ellip_items.append(go_el)
        ellip_items.extend(items)
        items = ellip_items

    if second_ellipses:
        items.append(go_el)
        items.extend(make_items(page_list[-ellipsis_pos:]))

    if nav_back:
        if this.props.query:
            items.insert(
                0,
                e(ui.Menu.Item,
                  icon="angle left",
                  onClick=go_prev,
                  as_=QueryLink,
                  query={'page': current_page - 1}))
        else:
            items.insert(0, e(ui.Menu.Item, icon="angle left",
                              onClick=go_prev))
    if nav_next:
        if this.props.query:
            items.append(
                e(ui.Menu.Item,
                  icon="angle right",
                  onClick=go_next,
                  as_=QueryLink,
                  query={'page': current_page + 1}))
        else:
            items.append(e(ui.Menu.Item, icon="angle right", onClick=go_next))

    return e(
        ui.Menu,
        *items,
        pagination=True,
        borderless=True,
        size=this.props.size if utils.defined(this.props.size) else "small",
        as_=ui.Transition.Group,
        duration=1000,
    )
Exemple #5
0
        pagination=True,
        borderless=True,
        size=this.props.size if utils.defined(this.props.size) else "small",
        as_=ui.Transition.Group,
        duration=1000,
    )


Pagination = createReactClass({
    'displayName':
    'Pagination',
    'getInitialState':
    lambda: {
        'current_page':
        this.props.default_page if this.props.default_page else
        (utils.get_query("page", 1)
         if this.props.history and this.props.query else 1),
        'go_to_page':
        1,
    },
    'change_page':
    pagination_change,
    'go_to_change':
    lambda e, d: this.setState({'go_to_page': int(d.value)}),
    'go_to_page':
    lambda e, d: this.change_page(int(this.state.go_to_page)),
    'go_page':
    lambda e, d: this.change_page(int(d.js_name)),
    'go_prev':
    lambda e, d: this.change_page(
        (int(this.props.current_page or this.state.current_page) - 1)),
Exemple #6
0
             stats=[
                 e(
                     ui.Statistic, e(ui.Statistic.Value, this.state.count),
                     e(ui.Statistic.Label,
                       tr(this, "ui.t-total-parodies", "Total parodies")))
             ])


__pragma__("notconv")

ParodiesPage = createReactClass({
    'displayName':
    'ParodiesPage',
    'getInitialState':
    lambda: {
        'search_query': utils.get_query("search", "") or this.props.
        search_query,
        '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(
Exemple #7
0
ItemView = createReactClass(
    {
        'displayName':
        'ItemView',
        'config_suffix':
        lambda: this.props.config_suffix or "",
        'query':
        lambda: this.props.query if utils.defined(this.props.query) else True,
        'getDefaultProps':
        lambda: {
            'query': True
        },
        'getInitialState':
        lambda: {
            'page':
            utils.get_query("page", 1) if this.query() else 1,
            'prev_page':
            0,
            'infinite_scroll':
            utils.storage.get("infinite_scroll" + this.config_suffix(), this.
                              props.infinite_scroll),
            'limit':
            utils.storage.get(
                "item_count" + this.config_suffix(), this.props.default_limit
                or (10 if this.props.related_type == ItemType.Page else 30)),
            'items': [],
            "element":
            None,
            "loading":
            True,
            "loading_more":
Exemple #8
0
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'})


Search = createReactClass({
    'displayName':
    'Search',
    'getInitialState':
    lambda: {
        'query':
        utils.get_query("search", this.props.search_query)
        if this.props.query else this.props.search_query,
        'case':
        utils.storage.get("search_case", bool(int(utils.get_query("case", 0)))
                          ),
        'regex':
        utils.storage.get("search_regex", bool(int(utils.get_query("regex", 0))
                                               )),
        'whole':
        utils.storage.get("search_whole", bool(int(utils.get_query("whole", 0))
                                               )),
        'all':
        utils.storage.get("search_all", bool(int(utils.get_query("all", 0)))),
        'desc':
        utils.storage.get("search_desc", bool(int(utils.get_query("desc", 0)))
                          ),
Exemple #9
0
        toggle_config=this.toggle_config,
        visible_config=this.state.visible_config,
        config_suffix=this.config_suffix,
    ),


ItemViewPage = createReactClass({
    'displayName':
    'ItemViewPage',
    'config_suffix':
    "main",
    'default_view':
    lambda: this.props.view_type or int(
        utils.get_query(
            "view_type",
            utils.session_storage.get(
                'view_type',
                utils.storage.get("def_view_type" + this.config_suffix,
                                  ViewType.Library)))),
    'toggle_config':
    lambda a: this.setState({'visible_config': not this.state.visible_config}),
    'on_item_change':
    lambda e, d: all((
        this.setState({
            'item_type':
            d.value,
            'sort_idx':
            utils.session_storage.get("sort_idx_{}".format(d.value), this.state
                                      .sort_idx)
        }),
        utils.session_storage.set("item_type", d.value),
    )),