implement AddGroupView

pull/20/head
Max Erenberg 1 year ago
parent ebaeeaaf13
commit 6b3ad28e89
  1. 8
      ceo/tui/Model.py
  2. 57
      ceo/tui/WelcomeView.py
  3. 42
      ceo/tui/groups/AddGroupView.py
  4. 2
      ceo/tui/groups/__init__.py
  5. 2
      ceo/tui/members/ChangeLoginShellView.py
  6. 2
      ceo/tui/members/SetForwardingAddressesView.py
  7. 2
      ceo/tui/start.py

@ -41,8 +41,12 @@ class Model:
'login_shell': '',
},
'SetForwardingAddresses': {
'uid': '',
'forwarding_addresses': [''],
'uid': '',
'forwarding_addresses': [''],
},
'AddGroup': {
'cn': '',
'description': '',
},
}
self.viewdata = deepcopy(self._initial_viewdata)

@ -1,5 +1,6 @@
from asciimatics.widgets import Frame, ListBox, Layout, Divider, \
Button, Widget
import functools
from asciimatics.widgets import Frame, ListBox, Layout, Divider, Button
from asciimatics.exceptions import NextScene, StopApplication
@ -9,11 +10,10 @@ class WelcomeView(Frame):
screen,
height,
width,
can_scroll=False,
title='CSC Electronic Office',
)
self._model = model
self._members_menu_items = [
members_menu_items = [
('Add member', 'AddUser'),
('Add club rep', 'AddUser'),
('Renew member', 'RenewUser'),
@ -23,19 +23,43 @@ class WelcomeView(Frame):
('Change login shell', 'ChangeLoginShell'),
('Set forwarding addresses', 'SetForwardingAddresses'),
]
self._members_menu = ListBox(
Widget.FILL_FRAME,
members_menu = ListBox(
len(members_menu_items),
[
(desc, i) for i, (desc, view) in
enumerate(self._members_menu_items)
enumerate(members_menu_items)
],
name='members',
label='Members',
on_select=self._members_menu_select,
)
groups_menu_items = [
('Add group', 'AddGroup'),
('Get group members', 'GetGroup'),
('Add member to group', 'AddMemberToGroup'),
('Remove member from group', 'RemoveMemberFromGroup'),
]
groups_menu = ListBox(
len(groups_menu_items),
[
(desc, i) for i, (desc, view) in
enumerate(groups_menu_items)
],
name='groups',
label='Groups',
on_select=functools.partial(self._generic_menu_select, 'groups'),
)
self._menu_groups = {
'members': members_menu_items,
'groups': groups_menu_items,
}
layout = Layout([100], fill_frame=True)
self.add_layout(layout)
layout.add_widget(self._members_menu)
layout.add_widget(members_menu)
layout.add_widget(groups_menu)
layout = Layout([100])
self.add_layout(layout)
layout.add_widget(Divider())
layout = Layout([1, 1, 1])
@ -43,12 +67,23 @@ class WelcomeView(Frame):
layout.add_widget(Button("Quit", self._quit), 2)
self.fix()
def _members_menu_select(self):
def _get_menu_item_desc_view(self, menu_name: str):
self.save()
item_id = self.data['members']
desc, view = self._members_menu_items[item_id]
item_id = self.data[menu_name]
menu_items = self._menu_groups[menu_name]
return menu_items[item_id]
def _members_menu_select(self):
desc, view = self._get_menu_item_desc_view('members')
if desc.endswith('club rep'):
self._model.is_club_rep = True
self._welcomeview_go_to_next_scene(desc, view)
def _generic_menu_select(self, menu_name):
desc, view = self._get_menu_item_desc_view('groups')
self._welcomeview_go_to_next_scene(desc, view)
def _welcomeview_go_to_next_scene(self, desc, view):
self._model.title = desc
self._model.scene_stack.append('Welcome')
raise NextScene(view)

@ -0,0 +1,42 @@
from asciimatics.widgets import Layout, Text
from ...utils import defer, http_post
from ..CeoFrame import CeoFrame
from ceod.transactions.groups import AddGroupTransaction
class AddGroupView(CeoFrame):
def __init__(self, screen, width, height, model):
super().__init__(
screen, height, width, model, 'AddGroup',
save_data=True,
)
layout = Layout([100], fill_frame=True)
self.add_layout(layout)
self._cn = Text('Name:', 'cn')
layout.add_widget(self._cn)
self._description = Text('Description:', 'description')
layout.add_widget(self._description)
self.add_buttons(
back_btn=True,
next_scene='Confirm', on_next=self._next)
self.fix()
def _next(self):
cn = self._cn.value
description = self._description.value
body = {
'cn': cn,
'description': description,
}
self._model.confirm_lines = [
'The following group will be created:',
'',
('cn', cn),
('description', description),
'',
'Are you sure you want to continue?',
]
self._model.deferred_req = defer(http_post, '/api/groups', json=body)
self._model.operations = AddGroupTransaction.operations

@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-

@ -24,7 +24,7 @@ class ChangeLoginShellView(CeoFrame):
layout.add_widget(self._username)
self._login_shell = Text('Login shell:', 'login_shell')
layout.add_widget(self._login_shell)
self.add_flash_message_layout()
self.add_buttons(
back_btn=True,

@ -27,7 +27,7 @@ class SetForwardingAddressesView(CeoFrame):
line_wrap=True)
layout.add_widget(self._forwarding_addresses)
layout.add_widget(Label('Press <TAB> to switch widgets'))
self.add_flash_message_layout()
self.add_buttons(
back_btn=True,

@ -11,6 +11,7 @@ from .Model import Model
from .ResultView import ResultView
from .TransactionView import TransactionView
from .WelcomeView import WelcomeView
from .groups.AddGroupView import AddGroupView
from .members.AddUserView import AddUserView
from .members.ChangeLoginShellView import ChangeLoginShellView
from .members.GetUserView import GetUserView
@ -55,6 +56,7 @@ def screen_wrapper(screen, last_scene, model):
('ResetPasswordResult', ResetPasswordResultView(screen, width, height, model)),
('ChangeLoginShell', ChangeLoginShellView(screen, width, height, model)),
('SetForwardingAddresses', SetForwardingAddressesView(screen, width, height, model)),
('AddGroup', AddGroupView(screen, width, height, model)),
]
scenes = [
Scene([view], -1, name=name) for name, view in views

Loading…
Cancel
Save