Skip to content
Snippets Groups Projects
Commit aad97adf authored by Marcus Eibrink-Lunzenauer's avatar Marcus Eibrink-Lunzenauer
Browse files

Apply Ron's changes.

parent df1bc6e0
No related branches found
No related tags found
No related merge requests found
Pipeline #33197 failed
...@@ -17,60 +17,37 @@ class Admin_CoursewareController extends AuthenticatedController ...@@ -17,60 +17,37 @@ class Admin_CoursewareController extends AuthenticatedController
{ {
parent::before_filter($action, $args); parent::before_filter($action, $args);
$GLOBALS['perm']->check('root'); $GLOBALS['perm']->check('root');
PageLayout::setTitle(_('Coursewareverwaltung'));
Navigation::activateItem('/admin/locations/courseware');
} }
public function index_action() public function index_action()
{ {
$this->setSidebar(); PageLayout::setTitle(_('Courseware Vorlagen'));
Navigation::activateItem('/admin/locations/courseware_templates');
$this->setIndexSidebar();
} }
public function block_types_action() public function elements_action(): void
{ {
PageLayout::addStyleSheet('courseware.css'); PageLayout::setTitle(_('Courseware Inhaltselemente'));
Navigation::activateItem('/admin/locations/courseware_elements');
$views = Sidebar::get()->addWidget(new ViewsWidget());
$views->addLink(_('Templates'), $this->indexURL());
$views->addLink(_('Block-Typen'), $this->block_typesURL())->setActive(true);
$views->addLink(_('Container-Typen'), $this->container_typesURL());
$this->blockTypes = BlockType::getBlockTypes(); $this->blockTypes = BlockType::getBlockTypes();
usort($this->blockTypes, fn($blockTypeA, $blockTypeB) => $blockTypeA::getTitle() <=> $blockTypeB::getTitle());
$this->containerTypes = ContainerType::getContainerTypes();
usort( usort(
$this->blockTypes, $this->containerTypes,
fn ($blockTypeA, $blockTypeB) => $blockTypeA::getTitle() <=> $blockTypeB::getTitle() fn($containerTypeA, $containerTypeB) => $containerTypeA::getTitle() <=> $containerTypeB::getTitle()
); );
} }
public function bulk_block_types_action()
{
CSRFProtection::verifyUnsafeRequest();
switch (Request::option('bulk_action')) {
case 'activate':
return $this->activate_block_types_action();
case 'deactivate':
return $this->deactivate_block_types_action();
}
PageLayout::postInfo(_('Keine Aktion ausgewählt.'));
$this->redirect($this->action_url('block_types'));
}
/**
*/
public function activate_block_types_action() public function activate_block_types_action()
{ {
CSRFProtection::verifyUnsafeRequest(); CSRFProtection::verifyUnsafeRequest();
$requestedBlockTypes = $this->validateBlockTypes(); $requestedBlockTypes = $this->validateBlockTypes();
$changed = array_sum( $changed = array_sum(array_map(fn($blockType) => $blockType::activate() ? 1 : 0, $requestedBlockTypes));
array_map(
fn ($blockType) => $blockType::activate() ? 1 : 0,
$requestedBlockTypes
)
);
PageLayout::postSuccess( PageLayout::postSuccess(
sprintf( sprintf(
...@@ -78,22 +55,15 @@ class Admin_CoursewareController extends AuthenticatedController ...@@ -78,22 +55,15 @@ class Admin_CoursewareController extends AuthenticatedController
$changed $changed
) )
); );
$this->redirect($this->action_url('block_types')); $this->redirect($this->action_url('elements'));
} }
/**
*/
public function deactivate_block_types_action() public function deactivate_block_types_action()
{ {
CSRFProtection::verifyUnsafeRequest(); CSRFProtection::verifyUnsafeRequest();
$requestedBlockTypes = $this->validateBlockTypes(); $requestedBlockTypes = $this->validateBlockTypes();
$changed = array_sum( $changed = array_sum(array_map(fn($blockType) => $blockType::deactivate() ? 1 : 0, $requestedBlockTypes));
array_map(
fn ($blockType) => $blockType::deactivate() ? 1 : 0,
$requestedBlockTypes
)
);
PageLayout::postSuccess( PageLayout::postSuccess(
sprintf( sprintf(
...@@ -101,42 +71,25 @@ class Admin_CoursewareController extends AuthenticatedController ...@@ -101,42 +71,25 @@ class Admin_CoursewareController extends AuthenticatedController
$changed $changed
) )
); );
$this->redirect($this->action_url('block_types')); $this->redirect($this->action_url('elements'));
} }
private function validateBlockTypes(): iterable private function validateBlockTypes(): iterable
{ {
$requestedBlockTypes = Request::getArray('block_types'); $requestedBlockTypes = Request::getArray('block_types');
$diff = array_diff($requestedBlockTypes, BlockType::getBlockTypes()); $diff = array_diff($requestedBlockTypes, BlockType::getBlockTypes());
if (count($diff) > 0) { if (count($diff)) {
throw new Trails\Exception(400); throw new Trails_Exception(400);
} }
return $requestedBlockTypes; return $requestedBlockTypes;
} }
public function container_types_action()
{
PageLayout::addStyleSheet('courseware.css');
$views = Sidebar::get()->addWidget(new ViewsWidget());
$views->addLink(_('Templates'), $this->indexURL());
$views->addLink(_('Block-Typen'), $this->block_typesURL());
$views->addLink(_('Container-Typen'), $this->container_typesURL())->setActive(true);
$this->containerTypes = ContainerType::getContainerTypes();
usort(
$this->containerTypes,
fn ($containerTypeA, $containerTypeB) => $containerTypeA::getTitle() <=> $containerTypeB::getTitle(),
);
}
public function bulk_container_types_action() public function bulk_container_types_action()
{ {
CSRFProtection::verifyUnsafeRequest(); CSRFProtection::verifyUnsafeRequest();
switch (Request::get('bulk_action')) { switch (Request::quoted('bulk_action')) {
case 'activate': case 'activate':
return $this->activate_container_types_action(); return $this->activate_container_types_action();
case 'deactivate': case 'deactivate':
...@@ -147,18 +100,13 @@ class Admin_CoursewareController extends AuthenticatedController ...@@ -147,18 +100,13 @@ class Admin_CoursewareController extends AuthenticatedController
$this->redirect($this->action_url('container_types')); $this->redirect($this->action_url('container_types'));
} }
/**
*/
public function activate_container_types_action() public function activate_container_types_action()
{ {
CSRFProtection::verifyUnsafeRequest(); CSRFProtection::verifyUnsafeRequest();
$requestedContainerTypes = $this->validateContainerTypes(); $requestedContainerTypes = $this->validateContainerTypes();
$changed = array_sum( $changed = array_sum(
array_map( array_map(fn($containerType) => $containerType::activate() ? 1 : 0, $requestedContainerTypes)
fn ($containerType) => $containerType::activate() ? 1 : 0,
$requestedContainerTypes
)
); );
PageLayout::postSuccess( PageLayout::postSuccess(
...@@ -178,15 +126,16 @@ class Admin_CoursewareController extends AuthenticatedController ...@@ -178,15 +126,16 @@ class Admin_CoursewareController extends AuthenticatedController
$requestedContainerTypes = $this->validateContainerTypes(); $requestedContainerTypes = $this->validateContainerTypes();
$changed = array_sum( $changed = array_sum(
array_map( array_map(fn($containerType) => $containerType::deactivate() ? 1 : 0, $requestedContainerTypes)
fn ($containerType) => $containerType::deactivate() ? 1 : 0,
$requestedContainerTypes
)
); );
PageLayout::postSuccess( PageLayout::postSuccess(
sprintf( sprintf(
ngettext('Container-Typ erfolgreich deaktiviert.', '%d Container-Typen erfolgreich deaktiviert.', $changed), ngettext(
'Container-Typ erfolgreich deaktiviert.',
'%d Container-Typen erfolgreich deaktiviert.',
$changed
),
$changed $changed
) )
); );
...@@ -198,20 +147,15 @@ class Admin_CoursewareController extends AuthenticatedController ...@@ -198,20 +147,15 @@ class Admin_CoursewareController extends AuthenticatedController
$requestedContainerTypes = Request::getArray('container_types'); $requestedContainerTypes = Request::getArray('container_types');
$diff = array_diff($requestedContainerTypes, ContainerType::getContainerTypes()); $diff = array_diff($requestedContainerTypes, ContainerType::getContainerTypes());
if (count($diff)) { if (count($diff)) {
throw new Trails\Exception(400); throw new Trails_Exception(400);
} }
return $requestedContainerTypes; return $requestedContainerTypes;
} }
private function setSidebar() private function setIndexSidebar()
{ {
$sidebar = Sidebar::Get(); $sidebar = Sidebar::Get();
$views = new TemplateWidget(
_('Ansichten'),
$this->get_template_factory()->open('admin/courseware/admin_view_widget')
);
$sidebar->addWidget($views)->addLayoutCSSClass('courseware-admin-view-widget');
$views = new TemplateWidget( $views = new TemplateWidget(
_('Aktionen'), _('Aktionen'),
......
.cw-admin-block-types,
.cw-admin-container-types {
tbody {
td {
padding-block-end: 0.625rem;
}
tr.activated td {
background-color: var(--content-color-10);
}
tr.activated td:first-child {
border-inline-start: 0.25rem solid var(--content-color);
}
td:nth-child(2) {
vertical-align: middle;
width: 20px;
}
td:nth-child(2) span {
display: inline-block;
height: 20px;
width: 20px;
}
td:nth-child(3) span:last-of-type {
opacity: 0.5;
}
td:nth-child(4) p {
display: -webkit-box;
min-height: 3em;
overflow: hidden;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
}
thead tr th:first-child,
tbody tr:not(.activated) td:first-child {
border-inline-start: 1px solid var(--content-color-20);
}
}
@each $item, $icon in $blockadder-items {
.cw-admin-block-types .cw-block-type-#{$item} {
@include background-icon($icon, info, 20);
}
}
@each $item, $icon in $containeradder-items {
.cw-admin-container-types .cw-container-type-#{$item} {
@include background-icon($icon, info, 20);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment