Skip to content

Commit

Permalink
Merge pull request #4034 from oat-sa/feat/AUT-3623/hide-features-in-s…
Browse files Browse the repository at this point in the history
…olar-design

fix: empty dropdown
  • Loading branch information
shaveko authored Jun 13, 2024
2 parents 72e99b8 + 879e47a commit 7d40e55
Show file tree
Hide file tree
Showing 15 changed files with 369 additions and 40 deletions.
19 changes: 19 additions & 0 deletions actions/class.UserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@
use oat\generis\model\GenerisRdf;
use oat\generis\model\OntologyAwareTrait;
use oat\oatbox\user\UserLanguageServiceInterface;
use oat\tao\model\featureFlag\FeatureFlagChecker;
use oat\tao\model\featureFlag\FeatureFlagCheckerInterface;
use oat\tao\model\service\ApplicationService;
use oat\tao\model\user\UserSettingsFormFactory;
use oat\tao\model\user\UserSettingsInterface;
use oat\tao\model\user\UserSettingsServiceInterface;
use oat\tao\model\user\implementation\UserSettingsService;
use tao_helpers_form_FormContainer as FormContainer;
Expand Down Expand Up @@ -110,6 +113,15 @@ public function properties()
$userSettingsData[GenerisRdf::PROPERTY_USER_DEFLG] = $dataLang->getUri();
}

if (
$this->getFeatureFlagChecker()->isEnabled(
FeatureFlagCheckerInterface::FEATURE_FLAG_SOLAR_DESIGN_ENABLED
)
) {
$interfaceMode = $this->getResource($settingsForm->getValue(UserSettingsInterface::INTERFACE_MODE));
$userSettingsData[GenerisRdf::PROPERTY_USER_INTERFACE_MODE] = $interfaceMode->getUri();
}

$binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($userResource);

if ($binder->bind($userSettingsData)) {
Expand Down Expand Up @@ -164,6 +176,13 @@ private function getLanguageService(): tao_models_classes_LanguageService
return tao_models_classes_LanguageService::singleton();
}

private function getFeatureFlagChecker(): FeatureFlagCheckerInterface
{
return $this
->getPsrContainer()
->get(FeatureFlagChecker::class);
}

private function isDemoMode(): bool
{
return $this->getPsrContainer()->get(ApplicationService::SERVICE_ID)->isDemo();
Expand Down
39 changes: 39 additions & 0 deletions actions/form/class.UserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
*
*/

use oat\generis\model\GenerisRdf;
use oat\oatbox\service\ServiceManager;
use oat\oatbox\user\UserLanguageServiceInterface;
use oat\oatbox\user\UserTimezoneServiceInterface;
use oat\tao\model\featureFlag\FeatureFlagChecker;
use oat\tao\model\featureFlag\FeatureFlagCheckerInterface;
use oat\tao\model\user\UserSettingsInterface;
use Psr\Container\ContainerInterface;

/**
Expand Down Expand Up @@ -142,6 +146,22 @@ protected function initElements()
}

$this->addTimezoneEl($this->form);

if (
$this->getFeatureFlagChecker()->isEnabled(
FeatureFlagCheckerInterface::FEATURE_FLAG_SOLAR_DESIGN_ENABLED
)
) {
$this->addInterfaceModeElement($this->form);
}
}

private function addInterfaceModeElement($form): void
{
$interfaceModeElement = tao_helpers_form_FormFactory::getElement(UserSettingsInterface::INTERFACE_MODE, 'Radiobox');
$interfaceModeElement->setDescription(__('Interface Mode'));
$interfaceModeElement->setOptions($this->getInterfaceModeOptions());
$form->addElement($interfaceModeElement);
}

private function addTimezoneEl($form): void
Expand Down Expand Up @@ -180,6 +200,13 @@ private function getLanguageService(): tao_models_classes_LanguageService
return $this->languageService;
}

private function getFeatureFlagChecker(): FeatureFlagChecker
{
return $this
->getContainer()
->get(FeatureFlagChecker::class);
}

private function getContainer(): ContainerInterface
{
if (!$this->container) {
Expand All @@ -188,4 +215,16 @@ private function getContainer(): ContainerInterface

return $this->container;
}

private function getInterfaceModeOptions(): array
{
$options = [];
$property = new core_kernel_classes_Property(GenerisRdf::PROPERTY_USER_INTERFACE_MODE);

foreach ($property->getRange()->getInstances(true) as $rangeInstance) {
$options[tao_helpers_Uri::encode($rangeInstance->getUri())] = $rangeInstance->getLabel();
}

return $options;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"oat-sa/jig": "~0.2",
"oat-sa/composer-npm-bridge": "~0.4.2||dev-master",
"oat-sa/oatbox-extension-installer": "~1.1||dev-master",
"oat-sa/generis": ">=15.34",
"oat-sa/generis": "dev-feat/AUT-3625/content-creation-mode-switch",
"composer/package-versions-deprecated": "^1.11",
"paragonie/random_compat": "^2.0",
"phpdocumentor/reflection-docblock": "^5.2",
Expand Down
31 changes: 31 additions & 0 deletions migrations/Version202406121231482235_tao.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace oat\tao\migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\Exception\IrreversibleMigration;
use oat\tao\scripts\tools\migrations\AbstractMigration;
use oat\tao\scripts\update\OntologyUpdater;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version202406121231482235_tao extends AbstractMigration
{
public function getDescription(): string
{
return 'Update the Ontology model';
}

public function up(Schema $schema): void
{
OntologyUpdater::syncModels();
}

public function down(Schema $schema): void
{
throw new IrreversibleMigration('Ontology should be re-synchronized after editing the source files.');
}
}
34 changes: 33 additions & 1 deletion models/classes/action/ActionBlackList.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
namespace oat\tao\model\action;

use Laminas\ServiceManager\ServiceLocatorAwareTrait;
use oat\generis\model\GenerisRdf;
use oat\oatbox\service\ConfigurableService;
use oat\tao\model\featureFlag\FeatureFlagChecker;
use oat\tao\model\user\implementation\UserSettingsService;
use oat\tao\model\user\UserSettingsInterface;

class ActionBlackList extends ConfigurableService
{
Expand All @@ -35,9 +38,13 @@ class ActionBlackList extends ConfigurableService
public const OPTION_DISABLED_ACTIONS_FLAG_MAP = 'disabledActionsMap';
public const OPTION_ENABLED_ACTIONS_BY_FEATURE_FLAG_MAP = 'enabledActionsByFeatureFlagMap';

private const SIMPLE_INTERFACE_MODE_DISABLED_ACTION = [
'test-xml-editor'
];

public function isDisabled(string $action): bool
{
return ($this->isDisabledByDefault($action) && !$this->isEnabledByFeatureFlag($action))
return $this->isDisabledByInterfaceMode($action) || ($this->isDisabledByDefault($action) && !$this->isEnabledByFeatureFlag($action))
|| $this->isDisabledByFeatureFlag($action);
}

Expand All @@ -64,4 +71,29 @@ private function getFeatureFlagChecker(): FeatureFlagChecker
{
return $this->getServiceLocator()->get(FeatureFlagChecker::class);
}

private function getUserSettingsService(): UserSettingsService
{
return $this->getServiceManager()->getContainer()->get(UserSettingsService::class);

}

private function isDisabledByInterfaceMode(string $action): bool
{
if (!in_array($action, self::SIMPLE_INTERFACE_MODE_DISABLED_ACTION)) {
return false;
}

$userSettings = $this->getUserSettingsService()->getCurrentUserSettings();

if (
$userSettings->getSetting(
UserSettingsInterface::INTERFACE_MODE
) === GenerisRdf::PROPERTY_USER_INTERFACE_MODE_SIMPLE
) {
return true;
}

return false;
}
}
25 changes: 24 additions & 1 deletion models/classes/menu/SectionVisibilityFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@
namespace oat\tao\model\menu;

use LogicException;
use oat\generis\model\GenerisRdf;
use oat\oatbox\service\ConfigurableService;
use oat\tao\model\featureFlag\FeatureFlagChecker;
use oat\tao\model\featureFlag\FeatureFlagCheckerInterface;
use oat\tao\model\user\implementation\UserSettingsService;
use oat\tao\model\user\UserSettingsInterface;

class SectionVisibilityFilter extends ConfigurableService implements SectionVisibilityFilterInterface
{
public const SERVICE_ID = 'tao/SectionVisibilityFilter';
public const OPTION_FEATURE_FLAG_SECTIONS = 'featureFlagSections';
public const OPTION_FEATURE_FLAG_SECTIONS_TO_HIDE = 'featureFlagSectionsToHide';

//TODO:: Add sections hidden for simple mode
public const SIMPLE_MODE_HIDDEN_SECTIONS = [];

/**
* @throws LogicException
*/
Expand All @@ -53,10 +59,27 @@ public function isVisible(string $section): bool
}
}

$userSettings = $this->getUserSettingsService()->getCurrentUserSettings();

if (
$userSettings->getSetting(
UserSettingsInterface::INTERFACE_MODE
) === GenerisRdf::PROPERTY_USER_INTERFACE_MODE_SIMPLE
&& in_array($section, self::SIMPLE_MODE_HIDDEN_SECTIONS)
) {
return false;
}

return true;
}

private function getFeatureFlagChecker(): FeatureFlagCheckerInterface
{
return $this->getServiceLocator()->get(FeatureFlagChecker::class);
return $this->getServiceManager()->getContainer()->get(FeatureFlagChecker::class);
}

private function getUserSettingsService(): UserSettingsService
{
return $this->getServiceManager()->getContainer()->get(UserSettingsService::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use oat\tao\model\user\implementation\UserSettingsService;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use tao_models_classes_LanguageService;
use tao_models_classes_UserService;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

Expand All @@ -44,6 +45,7 @@ public function __invoke(ContainerConfigurator $configurator): void
[
service(UserTimezoneServiceInterface::SERVICE_ID),
service(Ontology::SERVICE_ID),
service(tao_models_classes_UserService::SERVICE_ID),
]
);

Expand Down
4 changes: 4 additions & 0 deletions models/classes/user/UserSettingsFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public function createFormFields(
$fields['data_lang'] = $userSettings->getDataLanguageCode();
}

if ($userSettings->getSetting(UserSettingsInterface::INTERFACE_MODE)) {
$fields[UserSettingsInterface::INTERFACE_MODE] = $userSettings->getSetting(UserSettingsInterface::INTERFACE_MODE);
}

return $fields;
}

Expand Down
16 changes: 16 additions & 0 deletions models/classes/user/UserSettingsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,25 @@

interface UserSettingsInterface
{
public const INTERFACE_MODE = 'interfaceMode';
public const UI_LANGUAGE_CODE = 'uiLanguageCode';
public const DATA_LANGUAGE_CODE = 'dataLanguageCode';
public const TIMEZONE = 'timezone';

/**
* @deprecated use getSetting instead
*/
public function getUILanguageCode(): ?string;

/**
* @deprecated use getSetting instead
*/
public function getDataLanguageCode(): ?string;

/**
* @deprecated use getSetting instead
*/
public function getTimezone(): string;

public function getSetting(string $setting);
}
4 changes: 4 additions & 0 deletions models/classes/user/UserSettingsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
use oat\generis\model\data\Ontology;
use oat\generis\model\DependencyInjection\ContainerServiceProviderInterface;
use oat\oatbox\user\UserTimezoneServiceInterface;
use oat\tao\model\featureFlag\FeatureFlagChecker;
use oat\tao\model\user\implementation\UserSettingsService;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use tao_models_classes_LanguageService;
use tao_models_classes_UserService;

use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

Expand All @@ -44,6 +46,8 @@ public function __invoke(ContainerConfigurator $configurator): void
[
service(UserTimezoneServiceInterface::SERVICE_ID),
service(Ontology::SERVICE_ID),
service(tao_models_classes_UserService::SERVICE_ID),
service(FeatureFlagChecker::class),
]
);

Expand Down
34 changes: 20 additions & 14 deletions models/classes/user/implementation/UserSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,40 @@

class UserSettings implements UserSettingsInterface
{
/** @var string|null */
private $dataLanguageCode;

/** @var string|null */
private $uiLanguageCode;

/** @var string */
private $timezone;
/** @var array */
private $settings = [];

public function __construct(string $timezone, string $uiLanguageCode = null, string $dataLanguageCode = null)
{
$this->timezone = $timezone;
$this->uiLanguageCode = $uiLanguageCode;
$this->dataLanguageCode = $dataLanguageCode;
$this->setSetting(self::TIMEZONE, $timezone);
$this->setSetting(self::UI_LANGUAGE_CODE, $uiLanguageCode);
$this->setSetting(self::DATA_LANGUAGE_CODE, $dataLanguageCode);
}

public function getUILanguageCode(): ?string
{
return $this->uiLanguageCode;
return $this->getSetting(self::UI_LANGUAGE_CODE);
}

public function getDataLanguageCode(): ?string
{
return $this->dataLanguageCode;
return $this->getSetting(self::DATA_LANGUAGE_CODE);
}

public function getTimezone(): string
{
return $this->timezone;
return $this->getSetting(self::TIMEZONE);
}

public function setSetting(string $setting, $value): UserSettingsInterface
{
$this->settings[$setting] = $value;

return $this;
}

public function getSetting(string $setting)
{
return $this->settings[$setting] ?? null;
}
}
Loading

0 comments on commit 7d40e55

Please sign in to comment.