Skip to content

Commit

Permalink
review dashboard #3
Browse files Browse the repository at this point in the history
  • Loading branch information
fhelfer committed Jun 26, 2023
1 parent 1a3ec9d commit 1e03c45
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
declare(strict_types=1);

use ILIAS\UI\Component\Input\Field\FormInput;
use ILIAS\UI\Component\Input\Container\Form\Standard as StandardForm;
use ILIAS\UI\Component\Input\Field\Section;

/**
* Dashboard settings
Expand All @@ -29,6 +31,9 @@
*/
class ilObjDashboardSettingsGUI extends ilObjectGUI
{
public const VIEW_MODE_SETTINGS = 'Settings';
public const VIEW_MODE_PRESENTATION = 'Presentation';
public const VIEW_MODE_SORTING = 'Soriting';
protected ILIAS\UI\Factory $ui_factory;
protected ILIAS\UI\Renderer $ui_renderer;
protected ilPDSelectedItemsBlockViewSettings $viewSettings;
Expand Down Expand Up @@ -118,7 +123,7 @@ public function editSettings(): void
{
$this->setSettingsSubTabs("general");
$ui = $this->ui;
$form = $this->initForm();
$form = $this->getViewForm(self::VIEW_MODE_SETTINGS);
$this->tpl->setContent($ui->renderer()->renderAsync($form));
}

Expand All @@ -127,26 +132,33 @@ public function editSorting(): void
$this->tabs_gui->activateTab("settings");
$this->setSettingsSubTabs("sorting");
$ui = $this->ui;
$form = $this->initSortingForm();
$form = $this->getViewForm(self::VIEW_MODE_SORTING);
$this->tpl->setContent($ui->renderer()->renderAsync($form));
}

public function initSortingForm(): \ILIAS\UI\Component\Input\Container\Form\Standard
public function getViewForm(string $mode): StandardForm
{
return $this->ui_factory->input()->container()->form()->standard(
$this->ctrl->getFormAction($this, 'saveSorting'),
array_map(
fn (int $view): ILIAS\UI\Component\Input\Field\Section =>
$this->getViewSorting(
$view,
$this->lng->txt("dash_" . $this->viewSettings->getViewName($view))
),
$this->viewSettings->getPresentationViews()
)
);
switch ($mode) {
case self::VIEW_MODE_PRESENTATION:
case self::VIEW_MODE_SORTING:
return $this->ui_factory->input()->container()->form()->standard(
$this->ctrl->getFormAction($this, 'save' . $mode),
array_map(
fn (int $view): Section =>
$this->getViewByMode(
$mode,
$view
),
$this->viewSettings->getPresentationViews()
)
);
case self::VIEW_MODE_SETTINGS:
default:
return $this->getSettingsForm();
}
}

public function getViewSorting(int $view, string $title): ILIAS\UI\Component\Input\Field\Section
public function getViewSectionSorting(int $view, string $title): Section
{
$this->tpl->addJavaScript("Services/Dashboard/Administration/js/SortationUserInputHandler.js");
$lng = $this->lng;
Expand Down Expand Up @@ -190,7 +202,7 @@ static function (array $options, string $option) use ($lng): array {
);
}

public function initForm(): \ILIAS\UI\Component\Input\Container\Form\Standard
public function getSettingsForm(): StandardForm
{
$ui = $this->ui;
$f = $ui->factory();
Expand Down Expand Up @@ -242,19 +254,21 @@ public function initForm(): \ILIAS\UI\Component\Input\Container\Form\Standard
);
}

public function getPresentationForm(): \ILIAS\UI\Component\Input\Container\Form\Standard
public function getViewByMode(string $mode, int $view): Section
{
return $this->ui_factory->input()->container()->form()->standard(
$this->ctrl->getFormAction($this, 'savePresentation'),
array_map(
fn (int $view): ILIAS\UI\Component\Input\Field\Section =>
$this->getViewPresentation(
$view,
$this->lng->txt("dash_" . $this->viewSettings->getViewName($view))
),
$this->viewSettings->getPresentationViews()
)
);
switch ($mode) {
case self::VIEW_MODE_SORTING:
return $this->getViewSectionSorting(
$view,
$this->lng->txt("dash_" . $this->viewSettings->getViewName($view))
);
case self::VIEW_MODE_PRESENTATION:
default:
return $this->getViewSectionPresentation(
$view,
$this->lng->txt("dash_" . $this->viewSettings->getViewName($view))
);
}
}

public function saveSettings(): void
Expand All @@ -270,7 +284,7 @@ public function saveSettings(): void

$request = $this->request;

$form = $this->initForm();
$form = $this->getViewForm(self::VIEW_MODE_SETTINGS);
$form = $form->withRequest($request);
$form_data = $form->getData();
$this->viewSettings->enableSelectedItems(($form_data['main_panel']['enable_favourites']));
Expand Down Expand Up @@ -327,12 +341,12 @@ public function editPresentation(): void
$this->tabs_gui->activateTab("settings");
$this->setSettingsSubTabs("presentation");

$form = $this->getPresentationForm();
$form = $this->getViewForm(self::VIEW_MODE_PRESENTATION);

$this->tpl->setContent($this->ui->renderer()->renderAsync($form));
}

public function getViewPresentation(int $view, string $title): ILIAS\UI\Component\Input\Field\Section
public function getViewSectionPresentation(int $view, string $title): ILIAS\UI\Component\Input\Field\Section
{
$lng = $this->lng;
$ops = $this->viewSettings->getAvailablePresentationsByView($view);
Expand All @@ -359,7 +373,7 @@ protected function savePresentation(): void
$lng = $this->lng;
$ctrl = $this->ctrl;

$form = $this->getPresentationForm();
$form = $this->getViewForm(self::VIEW_MODE_PRESENTATION);
$form = $form->withRequest($request);
$form_data = $form->getData();

Expand Down Expand Up @@ -387,7 +401,7 @@ public function saveSorting(): void
$this->editSorting();
}

$form = $this->initSortingForm();
$form = $this->getViewForm(self::VIEW_MODE_SORTING);
$form = $form->withRequest($this->request);
$form_data = $form->getData();

Expand Down
59 changes: 18 additions & 41 deletions Services/Dashboard/Block/classes/class.ilDashboardBlockGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
use ILIAS\UI\Component\MessageBox\MessageBox;
use ILIAS\UI\Implementation\Component\ReplaceSignal;
use JetBrains\PhpStorm\NoReturn;
use ILIAS\UI\Component\Card\RepositoryObject;
use ILIAS\UI\Component\Item\Item;

/**
* @ilCtrl_IsCalledBy ilDashboardBlockGUI: ilColumnGUI
Expand All @@ -44,7 +46,6 @@ abstract class ilDashboardBlockGUI extends ilBlockGUI
/** @var array<string, array> */
protected array $data;


public function __construct()
{
parent::__construct();
Expand All @@ -59,23 +60,9 @@ public function __construct()
$this->object_cache = $DIC['ilObjDataCache'];
$this->tree = $DIC->repositoryTree();
$this->objDefinition = $DIC["objDefinition"];

$this->new_rendering = true;
$this->initViewSettings();
$this->viewSettings->parse();
$this->rbacsystem = $DIC->rbac()->system();

$this->ctrl->setParameter($this, 'view', $this->viewSettings->getCurrentView());
if ($this->viewSettings->isTilePresentation()) {
$this->setPresentation(self::PRES_MAIN_LEG);
} else {
$this->setPresentation(self::PRES_MAIN_LIST);
}

$params = $DIC->http()->request()->getQueryParams();
$this->requested_item_ref_id = (int) ($params["item_ref_id"] ?? 0);

$this->initData();
$this->init();
}

abstract public function initViewSettings(): void;
Expand All @@ -86,7 +73,7 @@ abstract public function addCustomCommandsToActionMenu(ilObjectListGUI $itemList

abstract public function emptyHandling(): string;

protected function getCardForData(array $data): ?\ILIAS\UI\Component\Card\RepositoryObject
protected function getCardForData(array $data): ?RepositoryObject
{
$itemListGui = $this->byType($data['type']);
ilObjectActivation::addListGUIActivationProperty($itemListGui, $data);
Expand Down Expand Up @@ -122,7 +109,7 @@ protected function getListItemGroups(): array
}


protected function getListItemForData(array $data): ?\ILIAS\UI\Component\Item\Item
protected function getListItemForData(array $data): ?Item
{
$itemListGui = $this->byType($data['type']);
$this->addCustomCommandsToActionMenu($itemListGui, $data['ref_id']);
Expand Down Expand Up @@ -174,23 +161,29 @@ public function getViewSettings(): ilPDSelectedItemsBlockViewSettings
return $this->viewSettings;
}

protected function initAndShow(): void
public function init(): void
{
$this->initViewSettings();
$this->main_tpl->addJavaScript('Services/Dashboard/Block/js/replaceModalContent.js');
$this->viewSettings->parse();
$this->requested_item_ref_id = (int) ($this->http->request()->getQueryParams()["item_ref_id"] ?? 0);
$this->initData();

$this->ctrl->setParameter($this, 'view', $this->viewSettings->getCurrentView());
if ($this->viewSettings->isTilePresentation()) {
$this->setPresentation(self::PRES_MAIN_LEG);
} else {
$this->setPresentation(self::PRES_MAIN_LIST);
}
}

protected function initAndShow(): void
{
$this->init();
if ($this->ctrl->isAsynch()) {
echo $this->getHTML();
exit;
}

$this->returnToContext();
}

Expand Down Expand Up @@ -439,7 +432,6 @@ protected function cancel(): void

protected function returnToContext(): void
{
$this->ctrl->setParameterByClass('ildashboardgui', 'view', $this->viewSettings->getCurrentView());
if ($this->http->request()->getQueryParams()['manage'] ?? false) {
$this->ctrl->redirect($this, 'manage');
}
Expand Down Expand Up @@ -497,7 +489,7 @@ public function removeFromDeskRoundtripObject(): void
exit;
}

public function manage(ILIAS\UI\Component\ReplaceSignal $replace_signal = null): string
public function manage(ReplaceSignal $replace_signal = null): string
{
$page = '';
if ($this->http->wrapper()->query()->has('page')) {
Expand All @@ -515,26 +507,11 @@ public function manage(ILIAS\UI\Component\ReplaceSignal $replace_signal = null):
true
) . '&page=confirm';
$button = $this->ui->factory()->button()->standard($this->getRemoveMultipleActionText(), '#')
->withOnLoadCode(function ($id) use ($url) {
return "
$('#$id').on('click', function() {
var post_data = $('form[name=\"pd_remove_multiple\"').serializeArray();
var selected_ids = [];
post_data.forEach(function (item) {
selected_ids.push(item.value);
});
var modal = $('div[data-modal-name=\"remove_modal\"]');
post_data = '';
for (var i = 0; i < selected_ids.length; i++) {
post_data += 'id[]=' + encodeURIComponent(selected_ids[i]) + '&';
}
post_data = post_data.slice(0, -1);
$('form[name=\"pd_remove_multiple\"').on('submit', function(e) {
e.preventDefault();
->withOnLoadCode(function ($id) use ($url) {
return "
replaceModalContent('$id', '$url');
";
});
modal.find('.modal-footer').remove();
il.Util.ajaxReplacePostRequestInner('$url', post_data,'pd_unsubscribe_multiple'); return false;})";
});

$grouped_items = [];
$item_groups = $this->getItemGroups();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@

declare(strict_types=1);

use ILIAS\UI\Component\Item\Item;

class ilStudyProgrammeBlockGUI extends ilDashboardBlockGUI
{
protected ?string $visible_on_pd_mode = null;

protected function getListItemForData(array $data): ?\ILIAS\UI\Component\Item\Item
protected function getListItemForData(array $data): ?Item
{
$item_gui = $this->byType($data['type']);
$item_gui->initItem(
Expand Down
22 changes: 22 additions & 0 deletions Services/Dashboard/Block/js/replaceModalContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const replaceModalContent = (function (id, url) {
document.getElementById(id).addEventListener('click', function (e) {
const form = document.querySelector('form[name="pd_remove_multiple"]');
const formData = new FormData(form);
let selected_ids = [];
for (const [name, value] of formData) {
selected_ids.push(value);
}
const modal = document.querySelector('div[data-modal-name="remove_modal"]');
let post_data = '';
for (let i = 0; i < selected_ids.length; i++) {
post_data += 'id[]=' + encodeURIComponent(selected_ids[i]) + '&';
}
post_data = post_data.slice(0, -1);
form.addEventListener('submit', function (e) {
e.preventDefault();
});
const modalFooter = modal.querySelector('.modal-footer');
modalFooter.parentNode.removeChild(modalFooter);
il.Util.ajaxReplacePostRequestInner(url, post_data, 'pd_unsubscribe_multiple');
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,9 +16,12 @@
*
*********************************************************************/

/**
* Class ilPDSelectedItemsBlockViewSettings
*/

declare(strict_types=1);

use ILIAS\Administration\Setting;
use ILIAS\Dashboard\Access\DashboardAccess;

class ilPDSelectedItemsBlockViewSettings implements ilPDSelectedItemsBlockConstants
{
/** @var int[] */
Expand Down Expand Up @@ -107,27 +108,27 @@ class ilPDSelectedItemsBlockViewSettings implements ilPDSelectedItemsBlockConsta

];

protected ILIAS\Administration\Setting $settings;
protected Setting $settings;
protected ilObjUser $actor;
protected array $validViews = [];
protected int $currentView = self::VIEW_SELECTED_ITEMS;
protected string $currentSortOption = self::SORT_BY_LOCATION;
protected string $currentPresentationOption = self::PRESENTATION_LIST;
protected ILIAS\Dashboard\Access\DashboardAccess $access;
protected DashboardAccess $access;

public function __construct(
ilObjUser $actor,
int $view = self::VIEW_SELECTED_ITEMS,
ILIAS\Administration\Setting $settings = null,
ILIAS\Dashboard\Access\DashboardAccess $access = null
Setting $settings = null,
DashboardAccess $access = null
) {
global $DIC;

$this->settings = $settings ?? $DIC->settings();

$this->actor = $actor;
$this->currentView = $view;
$this->access = $access ?? new ILIAS\Dashboard\Access\DashboardAccess();
$this->access = $access ?? new DashboardAccess();
}

public function getMembershipsView(): int
Expand Down
Loading

0 comments on commit 1e03c45

Please sign in to comment.