sort and order search results
This commit is contained in:
@@ -64,6 +64,11 @@ class SearchScreen(Screen):
|
||||
}
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.selects_changed = [] # just used to prevent some issues
|
||||
|
||||
def action_view_repo(self, author: str, repo_name: str):
|
||||
self.app.switch_screen(RepoViewScreen(author, repo_name))
|
||||
|
||||
@@ -75,12 +80,19 @@ class SearchScreen(Screen):
|
||||
|
||||
loading.display = True
|
||||
|
||||
# get params we need to send
|
||||
sort = self.query_one("#sort-select").value
|
||||
order = self.query_one("#order-select").value
|
||||
users_or_repos = self.query_one("#search-select").value
|
||||
|
||||
# send off a request
|
||||
response = requests.get(
|
||||
url=self.app.GITEA_HOST + "api/v1/repos/search",
|
||||
params={
|
||||
"q": query_input.value,
|
||||
"limit": 20
|
||||
"limit": 20,
|
||||
"sort": sort,
|
||||
"order": order
|
||||
}
|
||||
)
|
||||
|
||||
@@ -105,6 +117,13 @@ class SearchScreen(Screen):
|
||||
def on_input_submitted(self, event: Input.Submitted):
|
||||
if event.input.id == "query":
|
||||
self.action_search_query()
|
||||
|
||||
def on_select_changed(self, event: Select.Changed):
|
||||
if not event.select.id in self.selects_changed:
|
||||
self.selects_changed.append(event.select.id)
|
||||
return
|
||||
|
||||
self.action_search_query()
|
||||
|
||||
def on_mount(self):
|
||||
self.action_search_query()
|
||||
@@ -115,17 +134,17 @@ class SearchScreen(Screen):
|
||||
|
||||
with HorizontalGroup(id="search-box"):
|
||||
yield Input(placeholder="Search repos...", id="query")
|
||||
yield Select.from_values([
|
||||
"Alphabetical",
|
||||
"Creation date",
|
||||
"Last updated",
|
||||
"Size",
|
||||
"ID"
|
||||
], id="sort-select", allow_blank=False, value="Last updated")
|
||||
yield Select.from_values([
|
||||
"Ascending",
|
||||
"Descending"
|
||||
], id="order-select", allow_blank=False, value="Ascending")
|
||||
yield Select([
|
||||
("Alphabetical", "alpha"),
|
||||
("Creation date", "created"),
|
||||
("Last updated", "updated"),
|
||||
("Size", "size"),
|
||||
("ID", "id")
|
||||
], id="sort-select", allow_blank=False, value="updated")
|
||||
yield Select([
|
||||
("Ascending", "asc"),
|
||||
("Descending", "desc")
|
||||
], id="order-select", allow_blank=False, value="desc")
|
||||
yield Select.from_values([
|
||||
"Repositories",
|
||||
"Users",
|
||||
|
||||
Reference in New Issue
Block a user