View Single Post
Old Today, 09:59 AM   #1534
un_pogaz
Chalut o/
un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.
 
un_pogaz's Avatar
 
Posts: 450
Karma: 678910
Join Date: Dec 2017
Device: Kobo
Interesing, but I think that a formal implementation of a filter system would be a big plus, certainly with its own column/settings.
Also, if I understand your idea of wanting to dynamically display the menu entry based on simple condition criteria and so limit this to a single metadata object for performance reason, I think that inside the chains themselves, this is too confusive. It's certainly too late to replace this column with a proper filter setting, but in any case, I really encourage the addition of such thing.

Else, I worked of the idea and so here my proposal:
Spoiler:

in class chains.Chain._run_loop()

somewhere at the start
Code:
# store selected books at the start of the chains
self.chain_selected_ids = self.gui.current_view().get_selected_ids()
self.previous_selected_ids = self.chain_selected_ids
after
Code:
do_run = self.check_action_conditions(chain_link.get('condition_settings', {}))
append
Code:
# filtre the book for running action
filter_settings = chain_link.get('filter_settings', {})
if not filter_settings.get('template'):
    # No conditions set, use all selected ids
    action_selected_ids = self.chain_selected_ids
else:
    action_selected_ids = []
    for book_id in self.chain_selected_ids:
        mi = self.db.new_api.get_proxy_metadata(book_id)
        if self.check_conditions(filter_settings, mi=mi):
            action_selected_ids.append(book_id)

# action_selected_ids can only contain a subset of chain_selected_ids
# don't perform a new select_rows() if the previous seletion was the same than chain_selected_ids
if len(action_selected_ids) != len(self.chain_selected_ids) or len(self.previous_selected_ids) != len(self.chain_selected_ids):
    # change_current=True because the previous current_row can probaly not match the conditions
    # and so the validate() function can fail and abort the action
    self.gui.current_view().select_rows(action_selected_ids, change_current=True, scroll=False)
self.previous_selected_ids = action_selected_ids
and to insert in the finaly block
Code:
# full reset seleted books
if len(self.previous_selected_ids) != len(self.chain_selected_ids):
    self.gui.current_view().select_rows(self.chain_selected_ids, change_current=True, scroll=False)
un_pogaz is offline   Reply With Quote