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
{
parent::before_filter($action, $args);
$GLOBALS['perm']->check('root');
PageLayout::setTitle(_('Coursewareverwaltung'));
Navigation::activateItem('/admin/locations/courseware');
}
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');
$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());
PageLayout::setTitle(_('Courseware Inhaltselemente'));
Navigation::activateItem('/admin/locations/courseware_elements');
$this->blockTypes = BlockType::getBlockTypes();
usort($this->blockTypes, fn($blockTypeA, $blockTypeB) => $blockTypeA::getTitle() <=> $blockTypeB::getTitle());
$this->containerTypes = ContainerType::getContainerTypes();
usort(
$this->blockTypes,
fn ($blockTypeA, $blockTypeB) => $blockTypeA::getTitle() <=> $blockTypeB::getTitle()
$this->containerTypes,
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()
{
CSRFProtection::verifyUnsafeRequest();
$requestedBlockTypes = $this->validateBlockTypes();
$changed = array_sum(
array_map(
fn ($blockType) => $blockType::activate() ? 1 : 0,
$requestedBlockTypes
)
);
$changed = array_sum(array_map(fn($blockType) => $blockType::activate() ? 1 : 0, $requestedBlockTypes));
PageLayout::postSuccess(
sprintf(
......@@ -78,22 +55,15 @@ class Admin_CoursewareController extends AuthenticatedController
$changed
)
);
$this->redirect($this->action_url('block_types'));
$this->redirect($this->action_url('elements'));
}
/**
*/
public function deactivate_block_types_action()
{
CSRFProtection::verifyUnsafeRequest();
$requestedBlockTypes = $this->validateBlockTypes();
$changed = array_sum(
array_map(
fn ($blockType) => $blockType::deactivate() ? 1 : 0,
$requestedBlockTypes
)
);
$changed = array_sum(array_map(fn($blockType) => $blockType::deactivate() ? 1 : 0, $requestedBlockTypes));
PageLayout::postSuccess(
sprintf(
......@@ -101,42 +71,25 @@ class Admin_CoursewareController extends AuthenticatedController
$changed
)
);
$this->redirect($this->action_url('block_types'));
$this->redirect($this->action_url('elements'));
}
private function validateBlockTypes(): iterable
{
$requestedBlockTypes = Request::getArray('block_types');
$diff = array_diff($requestedBlockTypes, BlockType::getBlockTypes());
if (count($diff) > 0) {
throw new Trails\Exception(400);
if (count($diff)) {
throw new Trails_Exception(400);
}
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()
{
CSRFProtection::verifyUnsafeRequest();
switch (Request::get('bulk_action')) {
switch (Request::quoted('bulk_action')) {
case 'activate':
return $this->activate_container_types_action();
case 'deactivate':
......@@ -147,18 +100,13 @@ class Admin_CoursewareController extends AuthenticatedController
$this->redirect($this->action_url('container_types'));
}
/**
*/
public function activate_container_types_action()
{
CSRFProtection::verifyUnsafeRequest();
$requestedContainerTypes = $this->validateContainerTypes();
$changed = array_sum(
array_map(
fn ($containerType) => $containerType::activate() ? 1 : 0,
$requestedContainerTypes
)
array_map(fn($containerType) => $containerType::activate() ? 1 : 0, $requestedContainerTypes)
);
PageLayout::postSuccess(
......@@ -178,15 +126,16 @@ class Admin_CoursewareController extends AuthenticatedController
$requestedContainerTypes = $this->validateContainerTypes();
$changed = array_sum(
array_map(
fn ($containerType) => $containerType::deactivate() ? 1 : 0,
$requestedContainerTypes
)
array_map(fn($containerType) => $containerType::deactivate() ? 1 : 0, $requestedContainerTypes)
);
PageLayout::postSuccess(
sprintf(
ngettext('Container-Typ erfolgreich deaktiviert.', '%d Container-Typen erfolgreich deaktiviert.', $changed),
ngettext(
'Container-Typ erfolgreich deaktiviert.',
'%d Container-Typen erfolgreich deaktiviert.',
$changed
),
$changed
)
);
......@@ -198,20 +147,15 @@ class Admin_CoursewareController extends AuthenticatedController
$requestedContainerTypes = Request::getArray('container_types');
$diff = array_diff($requestedContainerTypes, ContainerType::getContainerTypes());
if (count($diff)) {
throw new Trails\Exception(400);
throw new Trails_Exception(400);
}
return $requestedContainerTypes;
}
private function setSidebar()
private function setIndexSidebar()
{
$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(
_('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