def update_item(data=None, error=None, new_data=None): if data is not None and not error: if data: state.app.notif(tr(None, "ui.t-updated", "Updated!"), level="success") else: state.app.notif(tr(None, "ui.t-updated-fail", "Failed!"), level="warning") if this.state.new_data: this.setState({'new_data': None}) elif error: state.app.notif("Failed to update item ({})".format(this.state.id), level="error") else: new_data = new_data or this.state.new_data if new_data and (new_data['tags'] or new_data['taggable']['tags'] if new_data['taggable'] else None): tag_data = new_data['tags'] or new_data['taggable']['tags'] del new_data['tags'] del new_data['taggable'] this.update_tags(new_data=tag_data) if new_data and new_data.id and utils.lodash_collection.size( new_data) > 1: client.call_func("update_item", this.update_item, item_type=this.state.item_type, item=new_data)
def thumbnail_get_thumb(data=None, error=None): if not this.mounted: return if data is not None and not error: cmd_id = data[str(this.props.item_id)] if cmd_id: cmd = Command(cmd_id) this.setState({'active_cmd': cmd}) cmd.set_callback(this.set_thumb) cmd.poll_until_complete(500) elif error: pass else: if this.state.active_cmd: this.state.active_cmd.stop() this.setState({'active_cmd': None}) if this.props.item_id and this.props.size_type and this.props.item_type: client.call_func("get_image", this.get_thumb, item_ids=[this.props.item_id], size=this.props.size_type, url=True, uri=True, item_type=this.props.item_type) s = {'loading': True} if this.state.placeholder: s['img'] = this.state.placeholder this.setState(s)
def search_get_config(data=None, error=None): if data is not None and not error: options = { "case": utils.storage.get("search_case", data['search.case_sensitive']), "all": utils.storage.get("search_all", data['search.match_all_terms']), "regex": utils.storage.get("search_regex", data['search.regex']), "whole": utils.storage.get("search_whole", data['search.match_whole_words']), "desc": utils.storage.get("search_desc", data['search.descendants']), } this.setState(options) elif error: state.app.notif("Failed to retrieve search configuration", level="warning") else: client.call_func("get_config", this.get_config, cfg={ 'search.case_sensitive': False, 'search.match_all_terms': False, 'search.regex': False, 'search.descendants': False, 'search.match_whole_words': False, })
def get_items_count(data=None, error=None): if data is not None and not error: this.setState({"item_count": data['count']}) elif error: pass else: item = this.props.item_type or this.state.item_type filter_id = (this.props.filter_id if utils.defined( this.props.filter_id) else this.state.filter_id) func_kw = {'item_type': item} if this.props.view_filter: func_kw['view_filter'] = this.props.view_filter or None if filter_id: func_kw['filter_id'] = filter_id if this.state.search_query: func_kw['search_query'] = this.state.search_query if this.props.search_options or this.state.search_options: func_kw[ 'search_options'] = this.props.search_options or this.state.search_options if this.props.related_type: func_kw['related_type'] = this.props.related_type if this.props.item_id: func_kw['item_id'] = this.props.item_id if item: client.call_func("get_view_count", this.get_items_count, **func_kw)
def preftab_set_config(data=None, error=None, cfg={}): if data is not None and not error: pass elif error: state.app.notif("Failed to update setting", level="warning") else: client.call_func("set_config", preftab_set_config, cfg=cfg)
def get_config(data=None, error=None, cfg={}): if data is not None and not error: this.setState({"config": data}) elif error: state.app.notif("Failed to retrieve configuration", level="warning") else: client.call_func("get_config", this.get_config, cfg=cfg)
def open_external(e, d): e.preventDefault() if this.state.data: client.call_func("open_gallery", None, item_id=this.state.data.id, item_type=this.state.item_type)
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 get_tags_count(data=None, error=None): if data is not None and not error: this.setState({"count": data['count']}) elif error: state.app.notif("Failed to fetch tags count", level="error") else: client.call_func("get_tags_count", this.get_tags_count)
def sortdropdown_get(data=None, error=None): if data is not None and not error: this.setState({"sort_items": data, "loading": False}) elif error: pass else: client.call_func("get_sort_indexes", this.get_items) this.setState({"loading": True})
def update_metatags(mtags): if this.state.data: client.call_func("update_metatags", None, item_type=this.state.item_type, item_id=this.state.data.id, metatags=mtags) d = utils.JSONCopy(this.state.data) d.metatags = dict(d.metatags) d.metatags.update(mtags) this.setState({'data': d})
def get_progress(data=None, error=None): if data is not None and not error: this.setState({"data": data}) elif error: state.app.notif("Failed to retrieve progress update", level="warning") else: if state['active'] and state['connected'] and state['accepted']: client.call_func("get_command_progress", this.get_progress)
def get_items_count(data=None, error=None): if data is not None and not error: this.setState({"item_count": data['count']}) elif error: state.app.notif("Failed to fetch item count", level="error") else: client.call_func("get_count", this.get_items_count, item_type=this.state.item_type)
def set_config(data=None, error=None, cfg={}, save=True): if data is not None and not error: pass elif error: state.app.notif("Failed to update setting", level="warning") else: client.call_func("set_config", this.set_config, cfg=cfg) if save: client.call_func("save_config")
def get_lang_items(data=None, error=None): if data is not None and not error: this.setState({'all_data': data, 'loading': False}) elif error: pass else: this.setState({'loading': True}) client.call_func("get_items", this.get_items, item_type=ItemType.Language, _memoize=60 * 10)
def get_db_categories(data=None, error=None): if data is not None and not error: this.setState({"data": data, 'data_loading': False}) elif error: state.app.notif("Failed to fetch categories", level="error") this.setState({'data_loading': False}) else: client.call_func("get_items", this.get_items, item_type=ItemType.Category) this.setState({'data_loading': True})
def get_page_count(data=None, error=None, gid=None): if data is not None and not error: this.setState({"page_count": data['count']}) elif error: state.app.notif("Failed to fetch pages ({})".format(this.state.gid), level="error") else: item = ItemType.Gallery item_id = gid if item and item_id: client.call_func("get_related_count", this.get_page_count, item_type=item, item_id=item_id, related_type=this.state.item_type)
def update_tags(data=None, error=None, new_data=None): if data is not None and not error: pass elif error: state.app.notif("Failed to update tags ({})".format(this.state.data.id), level="error") else: new_data = new_data or this.state.new_data if new_data: client.call_func("update_item_tags", this.update_tags, item_type=this.props.item_type, item_id=this.props.item_id, tags=new_data)
def get_current_db_items(data=None, error=None): if data is not None and not error: this.setState({"default_selected": data}) elif error: state.app.notif("Failed to fetch current items", level="error") else: client.call_func("get_related_items", this.get_current_items, item_id=this.props.item_id, item_type=this.props.item_type, related_type=this.state.item_type, limit=9999)
def get_category(data=None, error=None): if data is not None and not error: this.setState({"category_data": data}) elif error: state.app.notif("Failed to fetch category ({})".format(this.state.id), level="error") else: if not this.state.category_data and this.state.data and this.state.data.category_id: client.call_func("get_item", this.get_category, item_type=ItemType.Category, item_id=this.state.data.category_id)
def get_gallery(data=None, error=None): if data is not None and not error: this.setState({"gallery": data}) elif error: state.app.notif("Failed to fetch gallery item ({})".format(this.state.id), level="error") else: if this.props.location.state and this.props.location.state.gallery: this.get_gallery(this.props.location.state.gallery) return gid = int(this.props.match.params.gallery_id) if gid: client.call_func("get_item", this.get_gallery, item_type=ItemType.Gallery, item_id=gid)
def get_lang(data=None, error=None): if data is not None and not error: this.setState({"lang_data": data}) elif error: state.app.notif("Failed to fetch language ({})".format(this.state.id), level="error") else: if this.props.data and not this.props.language and this.props.data.language_id: client.call_func("get_item", this.get_lang, item_type=ItemType.Language, item_id=this.props.data.language_id)
def add_item(data=None, error=None, new_data=None): if data is not None and not error: pass elif error: state.app.notif("Failed to add to filter ({})".format(this.state.id), level="error") else: new_data = new_data or this.state.new_data print("add") client.call_func("add_to_filter", this.add_item, gallery_id=this.props.item_id, item=new_data)
def gallery_rate(e, d): e.preventDefault() rating = d.rating if this.state.data.id: client.call_func("update_item", item_type=this.state.item_type, item={ 'id': this.state.data.id, 'rating': rating }) this.setState( {'data': utils.update_object("rating", this.state.data, rating)}) this.get_item()
def get_view(data=None, error=None): if data is not None and not error: this.setState({'view_data': data, 'view_loading': False}) elif error: state.app.notif("Failed to fetch temporary view", level="error") else: if this.state.view_id: this.setState({'view_loading': True}) client.call_func("temporary_view", this.get_view, view_type=TemporaryViewType.GalleryAddition, view_id=this.state.view_id, limit=this.state.limit, offset=this.state.limit * (this.state.page - 1))
def get_gallery_count(data=None, error=None): if data is not None and not error: this.setState({"gallery_count": data['count']}) elif error: state.app.notif("Failed to fetch gallery count ({})".format( this.state.id), level="error") else: if not this.state.gallery_count and this.state.data: client.call_func("get_related_count", this.get_gallery_count, related_type=ItemType.Gallery, item_type=this.state.item_type, item_id=this.state.data.id)
def remove_item(data=None, error=None, new_data=None): if data is not None and not error: pass elif error: state.app.notif("Failed to remove from filter ({})".format( this.state.id), level="error") else: new_data = new_data or this.state.new_data if new_data.id: client.call_func("remove_from_filter", this.remove_item, gallery_id=this.props.item_id, item_id=new_data.id)
def filterdropdown_get(data=None, error=None): if data is not None and not error: items = {} for d in data: items[d['name']] = d this.setState({"db_items": items, "loading": False}) elif error: pass else: client.call_func("get_items", this.get_items, item_type=ItemType.GalleryFilter, limit=999) this.setState({"loading": True})
def get_status(data=None, error=None): if data is not None and not error: if data: this.setState({"status_data": data[0]}) elif error: state.app.notif("Failed to fetch status ({})".format(this.state.id), level="error") else: if this.props.data and not this.props.status and this.props.data.grouping_id: client.call_func("get_related_items", this.get_status, item_type=ItemType.Grouping, related_type=ItemType.Status, item_id=this.props.data.grouping_id)
def get_db_tags(data=None, error=None): if data is not None and not error: this.setState({"data": data, 'data_loading': False}) this.get_tags_count() elif error: state.app.notif("Failed to fetch tags", level="error") this.setState({'data_loading': False}) else: client.call_func("search_tags", this.get_tags, search_query=this.state.search_query, sort_by=ItemSort.NamespaceTagTag, offset=this.state.limit * (this.state.page - 1), limit=this.state.limit) this.setState({'data_loading': True})