add buttons to take user to the GetGroupResponseView of each search result
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
Daniel Sun 2023-01-26 04:45:37 +00:00
parent 0655d4ceec
commit 23cdaee38d
3 changed files with 39 additions and 8 deletions

View File

@ -1,22 +1,39 @@
from ceo.utils import http_get
from .Controller import Controller
from .SyncRequestController import SyncRequestController
from ceo.tui.views import SearchGroupResponseView
from ceo.tui.views import SearchGroupResponseView, GetGroupResponseView
# this is a little bit bad because it relies on zero coupling between
# the GetGroupResponseView and the GetGroupController
# coupling is also introduced between this controller and the
# SearchGroupResponseView as it requires this class's callback
class SearchGroupController(SyncRequestController):
def __init__(self, model, app):
super().__init__(model, app)
def get_resp(self):
return http_get(f'/api/groups/search/{self.model.query}/{self.model.count}')
if self.model.want_info:
return http_get(f'/api/groups/{self.model.name}')
else:
return http_get(f'/api/groups/search/{self.model.name}/{self.model.count}')
def get_response_view(self):
return SearchGroupResponseView(self.model, self, self.app)
if self.model.want_info:
return GetGroupResponseView(self.model, self, self.app)
else:
return SearchGroupResponseView(self.model, self, self.app)
def group_info_callback(self, button, cn):
self.model.name = cn
self.model.want_info = True;
self.request_in_progress = False;
self.on_next_button_pressed(button)
def on_next_button_pressed(self, button):
try:
self.model.query = self.get_username_from_view()
if not self.model.want_info:
self.model.name = self.get_username_from_view()
self.model.count = 10
except Controller.InvalidInput:
return

View File

@ -3,6 +3,7 @@ class SearchGroupModel:
title = 'Search groups'
def __init__(self):
self.query = ''
self.count = 10
self.name = ''
self.resp_json = None
self.count = 10
self.want_info = False

View File

@ -1,9 +1,22 @@
import urwid
from .ColumnResponseView import ColumnResponseView
from .utils import decorate_button
from ceo.tui.models import GetGroupModel
class SearchGroupResponseView(ColumnResponseView):
def __init__(self, model, controller, app):
super().__init__(model, controller, app)
matches = self.model.resp_json.copy()
rows = [(str(i), resp) for i, resp in enumerate(matches) if resp != '']
self.set_pairs(rows)
rows = [ (urwid.Text(resp),
decorate_button(urwid.Button('more info', on_press=self.create_callback(resp))))
for resp in matches if resp != '']
self.set_rows(rows, on_next=self.controller.get_next_menu_callback('Welcome'))
def create_callback(self, cn):
def callback(button):
self.controller.group_info_callback(button, cn)
return callback