Skip to content

Commit

Permalink
fix: fix table sorting and filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
datawhores committed Dec 28, 2024
1 parent 5a6e935 commit bd0601d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 26 deletions.
54 changes: 32 additions & 22 deletions ofscraper/classes/table/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from ofscraper.classes.table.const import AMOUNT_PER_PAGE
from ofscraper.classes.table.compose import composer
import ofscraper.utils.logs.logger as logger
import ofscraper.utils.args.accessors.read as read_args



log = logging.getLogger("shared")
Expand All @@ -35,15 +37,14 @@ def __init__(self, *args, **kwargs) -> None:
# Main

def __call__(self, *args, **kwargs):
self._init_args = kwargs.pop("args", None)
self.table_data = kwargs.pop("table_data", None)
self._sortkey = None
self._reverse = False
self._download_cart_toggle=False
self.run()

def compose(self):
return composer(self._init_args)
return composer(read_args.retriveArgs())

def on_ready(self) -> None:
self.init_table()
Expand Down Expand Up @@ -140,19 +141,23 @@ def add_to_row_queue(self):



# sort/filterr
# sort
def init_sort(self):
self._reverse = False
self._sortkey="number"
self.query_one("#data_table_hidden").sort(
"number", key=lambda x: int(x.plain),
)
self._reverse = False if read_args.retriveArgs().desc is None else read_args.retriveArgs().desc
self._sortkey="number" if read_args.retriveArgs().mediasort is None else read_args.retriveArgs().mediasort
self._sort_runner(key=self._sortkey)
def reset_sort(self):
self._reverse=False
self._sortkey="number"
self._sort_runner(key=self._sortkey)


def set_sort(self, label):
self._sort_runner(label)
with mutex:
self.set_reverse(key=label)
self._sort_runner(label)

def _sort_runner(self, key):
with mutex:
self.set_reverse(key=key)
#sort
if key == "number":
self.query_one("#data_table_hidden").sort(
Expand Down Expand Up @@ -235,8 +240,15 @@ def set_reverse(self, key=None):

elif self._sortkey == key and self._reverse:
self._reverse = False
# filter runner
def init_filtered_rows(self):
self._set_media_type()
self._set_length()
self._filter_runner()
def set_filtered_rows(self):
self._filter_runner()

def set_filtered_rows(self, reset=False):
def _filter_runner(self):
with mutex:
filter_rows=None
key_order=[str(x.value) for x in self.query_one("#data_table_hidden")._row_locations]
Expand Down Expand Up @@ -274,8 +286,8 @@ def reset_all_inputs(self):

def _set_media_type(self):
mediatype = (
self._init_args.media_type
if bool(self._init_args.media_type)
read_args.retriveArgs().mediatype
if bool(read_args.retriveArgs().mediatype)
else ["Audios", "Videos", "Images"]
)
self.query_one("#mediatype").query_one(SelectionList).deselect_all()
Expand All @@ -284,15 +296,15 @@ def _set_media_type(self):


def _set_length(self):
if self._init_args.length_max:
self.query_one("#length").update_table_max(self._init_args.length_max)
if self._init_args.length_min:
self.query_one("#length").update_table_min(self._init_args.length_min)
if read_args.retriveArgs().length_max:
self.query_one("#length").update_table_max(read_args.retriveArgs().length_max)
if read_args.retriveArgs().length_min:
self.query_one("#length").update_table_min(read_args.retriveArgs().length_min)

#table
def reset_table(self):
self.reset_all_inputs()
self.init_sort()
self.reset_sort()
self.set_filtered_rows()
self.set_page()
self.update_search_info()
Expand All @@ -319,11 +331,9 @@ def set_page(self):
self.table.add_row(*values,height=None,key=key,label=count+1)

def init_table(self):
self._set_media_type()
self._set_length()
self.insert_data_table()
self.init_sort()
self.set_filtered_rows()
self.init_filtered_rows()
self.set_page()
self.update_search_info()

Expand Down
2 changes: 1 addition & 1 deletion ofscraper/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ def start_table(ROWS_):
asyncio.set_event_loop(loop)
ROWS = ROWS_
app.app(
table_data=ROWS, args=read_args.retriveArgs()
table_data=ROWS
)


Expand Down
2 changes: 1 addition & 1 deletion ofscraper/filters/media/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def unviewable_media_filter(media):


def final_media_sort(media):
media_sort = read_args.retriveArgs().media_sort
media_sort = read_args.retriveArgs().mediasort
reversed = read_args.retriveArgs().media_desc
log.debug(f"Using download sort {media_sort}")
if media_sort == "random":
Expand Down
3 changes: 2 additions & 1 deletion ofscraper/utils/args/parse/arguments/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
check_mode_media_sort = click.option(
"-mst",
"--media-sort",
"mediasort",
help="""
\b
Changes media processing order before actions
Expand Down Expand Up @@ -132,7 +133,7 @@
"post_id",
help="Filter posts based on post id",
required=False,
type=click.STRING,
# type=click.STRING,
)


Expand Down
2 changes: 2 additions & 0 deletions ofscraper/utils/args/parse/arguments/media_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
media_type_option = click.option(
"-mt",
"--mediatype",
"mediatype",
help="Filter by media type (Videos, Audios, Images)",
default=[],
required=False,
Expand Down Expand Up @@ -83,6 +84,7 @@
media_sort_option = click.option(
"-mst",
"--media-sort",
"mediasort",
help="""
\b
Changes media processing order before actions
Expand Down
1 change: 0 additions & 1 deletion ofscraper/utils/args/parse/group_bundles/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def common_args_check(func):
)
@click.option_group(
"Table Filter Options",
post_id_filter_option,
media_type_option,
check_mode_media_sort,
length_max,
Expand Down

0 comments on commit bd0601d

Please sign in to comment.