Skip to content

Commit

Permalink
review dashboard #8
Browse files Browse the repository at this point in the history
  • Loading branch information
fhelfer committed May 24, 2023
1 parent 2bb94ca commit dcacf40
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class ilObjDashboardSettingsGUI extends ilObjectGUI
public const VIEW_MODE_SETTINGS = 'Settings';
public const VIEW_MODE_PRESENTATION = 'Presentation';
public const VIEW_MODE_SORTING = 'Sorting';
public const DASH_SORT_PREFIX = 'dash_sort_by_';
public const DASH_ENABLE_PREFIX = 'dash_enable_';
protected ILIAS\UI\Factory $ui_factory;
protected ILIAS\UI\Renderer $ui_renderer;
protected ilPDSelectedItemsBlockViewSettings $viewSettings;
Expand Down Expand Up @@ -161,7 +163,7 @@ public function getViewSectionSorting(int $view, string $title): Section
$options = array_reduce(
$availabe_sort_options,
static function (array $options, string $option) use ($lng): array {
$options[$option] = $lng->txt("dash_sort_by_" . $option);
$options[$option] = $lng->txt(self::DASH_SORT_PREFIX . $option);
return $options;
},
[]
Expand Down Expand Up @@ -204,7 +206,7 @@ public function getSettingsForm(): StandardForm

$side_panel = $this->side_panel_settings;

$fields["enable_favourites"] = $field->checkbox($lng->txt("dash_enable_favourites"))
$fields[self::DASH_ENABLE_PREFIX . "favourites"] = $field->checkbox($lng->txt(self::DASH_ENABLE_PREFIX . "favourites"))
->withValue($this->viewSettings->enabledSelectedItems());
$info_text = ($this->viewSettings->enabledMemberships())
? ""
Expand All @@ -215,25 +217,25 @@ public function getSettingsForm(): StandardForm
)
);

$fields["enable_recommended_content"] = $field->checkbox($lng->txt("dash_enable_recommended_content"))
$fields[self::DASH_ENABLE_PREFIX . "recommended_content"] = $field->checkbox($lng->txt(self::DASH_ENABLE_PREFIX . "recommended_content"))
->withValue(true)
->withDisabled(true);
$fields["enable_memberships"] = $field->checkbox($lng->txt("dash_enable_memberships"), $info_text)
$fields[self::DASH_ENABLE_PREFIX . "memberships"] = $field->checkbox($lng->txt(self::DASH_ENABLE_PREFIX . "memberships"), $info_text)
->withValue($this->viewSettings->enabledMemberships());


$fields["enable_learning_sequences"] = $field->checkbox($lng->txt("dash_enable_learning_sequences"))
$fields[self::DASH_ENABLE_PREFIX . "learning_sequences"] = $field->checkbox($lng->txt(self::DASH_ENABLE_PREFIX . "learning_sequences"))
->withValue($this->viewSettings->enabledLearningSequences());

$fields["enable_study_programmes"] = $field->checkbox($lng->txt("dash_enable_study_programmes"))
$fields[self::DASH_ENABLE_PREFIX . "study_programmes"] = $field->checkbox($lng->txt(self::DASH_ENABLE_PREFIX . "study_programmes"))
->withValue($this->viewSettings->enabledStudyProgrammes());

// main panel
$section1 = $field->section($this->maybeDisable($fields), $lng->txt("dash_main_panel"));

$sp_fields = [];
foreach ($side_panel->getValidModules() as $mod) {
$sp_fields["enable_" . $mod] = $field->checkbox($lng->txt("dash_enable_" . $mod))
$sp_fields[self::DASH_ENABLE_PREFIX . $mod] = $field->checkbox($lng->txt(self::DASH_ENABLE_PREFIX . $mod))
->withValue($side_panel->isEnabled($mod));
}

Expand Down Expand Up @@ -280,14 +282,14 @@ public function saveSettings(): void
$form = $this->getViewForm(self::VIEW_MODE_SETTINGS);
$form = $form->withRequest($request);
$form_data = $form->getData();
$this->viewSettings->enableSelectedItems(($form_data['main_panel']['enable_favourites']));
$this->viewSettings->enableMemberships(($form_data['main_panel']['enable_memberships']));
$this->viewSettings->enableRecommendedContent(($form_data['main_panel']['enable_recommended_content']));
$this->viewSettings->enableLearningSequences(($form_data['main_panel']['enable_learning_sequences']));
$this->viewSettings->enableStudyProgrammes(($form_data['main_panel']['enable_study_programmes']));
$this->viewSettings->enableSelectedItems(($form_data['main_panel'][self::DASH_ENABLE_PREFIX . 'favourites']));
$this->viewSettings->enableMemberships(($form_data['main_panel'][self::DASH_ENABLE_PREFIX . 'memberships']));
$this->viewSettings->enableRecommendedContent(($form_data['main_panel'][self::DASH_ENABLE_PREFIX . 'recommended_content']));
$this->viewSettings->enableLearningSequences(($form_data['main_panel'][self::DASH_ENABLE_PREFIX . 'learning_sequences']));
$this->viewSettings->enableStudyProgrammes(($form_data['main_panel'][self::DASH_ENABLE_PREFIX . 'study_programmes']));

foreach ($side_panel->getValidModules() as $mod) {
$side_panel->enable($mod, (bool) $form_data['side_panel']['enable_' . $mod]);
$side_panel->enable($mod, (bool) $form_data['side_panel'][self::DASH_ENABLE_PREFIX . $mod]);
}

$this->tpl->setOnScreenMessage('success', $this->lng->txt("settings_saved"), true);
Expand Down
17 changes: 14 additions & 3 deletions Services/Dashboard/Block/classes/class.ilDashboardBlockGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
use ILIAS\UI\Component\Card\RepositoryObject;
use ILIAS\UI\Component\Item\Item;
use ILIAS\Services\Dashboard\Block\BlockDTO;
use ILIAS\HTTP\Response\ResponseHeader;
use ILIAS\Filesystem\Stream\Streams;

/**
* @ilCtrl_IsCalledBy ilDashboardBlockGUI: ilColumnGUI
Expand Down Expand Up @@ -179,7 +181,10 @@ protected function initAndShow(): void
{
$this->init();
if ($this->ctrl->isAsynch()) {
echo $this->getHTML();
$responseStream = Streams::ofString($this->getHTML());
$response = $this->http->response()->withBody($responseStream);
$this->http->saveResponse($response);
$this->http->sendResponse();
$this->http->close();
}
$this->returnToContext();
Expand Down Expand Up @@ -371,7 +376,7 @@ public function addCommandActions(): void
$this->ctrl->setParameter($this, 'sorting', $sorting);
$this->addBlockCommand(
$this->ctrl->getLinkTarget($this, 'changePDItemSorting'),
$this->lng->txt('dash_sort_by_' . $sorting),
$this->lng->txt(ilObjDashboardSettingsGUI::DASH_SORT_PREFIX . $sorting),
$this->ctrl->getLinkTarget($this, 'changePDItemSorting', '', true)
);
$this->ctrl->setParameter($this, 'sorting', null);
Expand Down Expand Up @@ -518,7 +523,13 @@ public function removeFromDeskRoundtripObject(): void
default:
$modal = $this->ui->factory()->legacy($this->confirmRemoveObject());
}
echo $this->ui->renderer()->renderAsync($modal);
$responseStream = Streams::ofString($this->ui->renderer()->renderAsync($modal));
$this->http->saveResponse(
$this->http->response()
->withBody($responseStream)
->withHeader(ResponseHeader::CONTENT_TYPE, 'application/json')
);
$this->http->sendResponse();
$this->http->close();
}

Expand Down

0 comments on commit dcacf40

Please sign in to comment.