add buttons to take user to the GetGroupResponseView of each search result
continuous-integration/drone/pr Build is failing
Details
continuous-integration/drone/pr Build is failing
Details
This commit is contained in:
parent
0655d4ceec
commit
23cdaee38d
|
@ -1,22 +1,39 @@
|
||||||
from ceo.utils import http_get
|
from ceo.utils import http_get
|
||||||
from .Controller import Controller
|
from .Controller import Controller
|
||||||
from .SyncRequestController import SyncRequestController
|
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):
|
class SearchGroupController(SyncRequestController):
|
||||||
def __init__(self, model, app):
|
def __init__(self, model, app):
|
||||||
super().__init__(model, app)
|
super().__init__(model, app)
|
||||||
|
|
||||||
def get_resp(self):
|
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):
|
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):
|
def on_next_button_pressed(self, button):
|
||||||
try:
|
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
|
self.model.count = 10
|
||||||
except Controller.InvalidInput:
|
except Controller.InvalidInput:
|
||||||
return
|
return
|
||||||
|
|
|
@ -3,6 +3,7 @@ class SearchGroupModel:
|
||||||
title = 'Search groups'
|
title = 'Search groups'
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.query = ''
|
self.name = ''
|
||||||
self.count = 10
|
|
||||||
self.resp_json = None
|
self.resp_json = None
|
||||||
|
self.count = 10
|
||||||
|
self.want_info = False
|
||||||
|
|
|
@ -1,9 +1,22 @@
|
||||||
|
import urwid
|
||||||
|
|
||||||
from .ColumnResponseView import ColumnResponseView
|
from .ColumnResponseView import ColumnResponseView
|
||||||
|
from .utils import decorate_button
|
||||||
|
from ceo.tui.models import GetGroupModel
|
||||||
|
|
||||||
|
|
||||||
class SearchGroupResponseView(ColumnResponseView):
|
class SearchGroupResponseView(ColumnResponseView):
|
||||||
def __init__(self, model, controller, app):
|
def __init__(self, model, controller, app):
|
||||||
super().__init__(model, controller, app)
|
super().__init__(model, controller, app)
|
||||||
matches = self.model.resp_json.copy()
|
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
|
||||||
|
|
Loading…
Reference in New Issue