Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
192 changes: 176 additions & 16 deletions classes/Conf/Workflows/class.xoctWorkflowGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use srag\Plugins\Opencast\Model\Workflow\WorkflowAR;
use srag\Plugins\Opencast\Model\Workflow\WorkflowRepository;
use srag\Plugins\Opencast\LegacyHelpers\OutputTrait;
use srag\Plugins\Opencast\LegacyHelpers\TranslatorTrait;
use srag\Plugins\Opencast\Model\Config\PluginConfig;

/**
* Class xoctWorkflowGUI
Expand All @@ -15,9 +17,15 @@
*/
class xoctWorkflowGUI extends xoctGUI
{
use TranslatorTrait;
use OutputTrait;
public const PLUGIN_CLASS_NAME = ilOpenCastPlugin::class;

public const LANG_MODULE = 'workflow';
public const CMD_SAVE_SETTINGS = 'saveSettings';
public const CMD_UPDATE_WORKFLOWS = 'updateWorkflows';
public const CMD_CONFIRM_RESET_WORKFLOWS = 'confirmResetWorkflows';
public const CMD_RESET_WORKFLOWS = 'resetWorkflows';
/**
* @var Factory
*/
Expand All @@ -38,6 +46,18 @@ class xoctWorkflowGUI extends xoctGUI
* @var \ILIAS\HTTP\Services
*/
private $http;
/**
* @var \ilGlobalTemplateInterface
*/
private $main_tpl;
/**
* @var \ilTabs
*/
private $tabs;
/**
* @var string
*/
protected $wf_subtab_active;

public function __construct(WorkflowRepository $workflow_repository)
{
Expand All @@ -46,9 +66,14 @@ public function __construct(WorkflowRepository $workflow_repository)
$ui = $DIC->ui();
$this->toolbar = $DIC->toolbar();
$this->language = $DIC->language();
$this->tabs = $DIC->tabs();
$this->http = $DIC->http();
$this->workflow_repository = $workflow_repository;
$this->factory = $ui->factory();
$this->main_tpl = $ui->mainTemplate();
$this->wf_subtab_active =
$this->http->request()->getQueryParams()['wf_subtab_active'] ?? xoctMainGUI::SUBTAB_WORKFLOWS_SETTINGS;
$this->setTab();
}

/**
Expand All @@ -57,30 +82,150 @@ public function __construct(WorkflowRepository $workflow_repository)
*/
protected function index()
{
$this->initToolbar();
$table = new xoctWorkflowTableGUI($this, self::CMD_STANDARD, $this->workflow_repository);
$this->output($table);
if ($this->wf_subtab_active === xoctMainGUI::SUBTAB_WORKFLOWS_LIST) {
$this->initToolbar();
$table = new xoctWorkflowTableGUI($this, self::CMD_STANDARD, $this->workflow_repository);
$this->output($table);
} else {
$this->output($this->getWorkflowSettingsForm());
}
}

/**
* Helps setting the tabs at all time.
*/
public function setTab()
{
$this->ctrl->saveParameter($this, 'wf_subtab_active');
$this->tabs->setSubTabActive($this->wf_subtab_active);
}

public function setTabParameter($tab = xoctMainGUI::SUBTAB_WORKFLOWS_SETTINGS)
{
$this->ctrl->setParameter(
$this,
'wf_subtab_active',
$tab
);
}

/**
*
*/
protected function getWorkflowSettingsForm()
{
$tags = $this->factory->input()->field()->text($this->translate(PluginConfig::F_WORKFLOWS_TAGS))
->withByline($this->translate(PluginConfig::F_WORKFLOWS_TAGS . '_info'))
->withValue(PluginConfig::getConfig(PluginConfig::F_WORKFLOWS_TAGS) ?? '');
return $this->factory->input()->container()->form()->standard(
$this->ctrl->getFormAction($this, self::CMD_SAVE_SETTINGS),
[
$this->factory->input()->field()->section(
[
PluginConfig::F_WORKFLOWS_TAGS => $tags,
],
$this->txt('settings_header'),
$this->txt('settings_header_description')
)
]
);
}

protected function saveSettings()
{
$this->setTabParameter();
$form = $this->getWorkflowSettingsForm()->withRequest($this->http->request());
if ($data = $form->getData()) {
$data = reset($data);

$current_tags = PluginConfig::getConfig(PluginConfig::F_WORKFLOWS_TAGS);

$new_tags = $data[PluginConfig::F_WORKFLOWS_TAGS] ?? '';

try {
$update_succeeded = $this->workflow_repository->updateList($new_tags);
if ($update_succeeded) {
ilUtil::sendSuccess($this->translate('msg_workflow_settings_saved'), true);
PluginConfig::set(
PluginConfig::F_WORKFLOWS_TAGS,
trim($new_tags)
);
} else {
ilUtil::sendFailure($this->translate('msg_workflow_settings_saved_update_failed'), true);
// Reverting back!
PluginConfig::set(PluginConfig::F_WORKFLOWS_TAGS, $current_tags);
}
} catch (xoctException $e) {
ilUtil::sendFailure($e->getMessage(), true);
}
$this->ctrl->redirect($this, self::CMD_STANDARD);
} else {
$this->output($form);
}
}

protected function initToolbar()
{
$add_button = $this->factory->button()->primary(
$this->plugin->txt('config_button_add_workflow'),
$this->ctrl->getLinkTarget($this, self::CMD_ADD)
$update_workflows_button = $this->factory->button()->primary(
$this->plugin->txt('config_workflows_update_btn'),
$this->ctrl->getLinkTarget($this, self::CMD_UPDATE_WORKFLOWS)
);
$this->toolbar->addComponent($add_button);
$this->toolbar->addComponent($update_workflows_button);
$reset_workflows_button = $this->factory->button()->standard(
$this->plugin->txt('config_workflows_reset_btn'),
$this->ctrl->getLinkTarget($this, self::CMD_CONFIRM_RESET_WORKFLOWS)
);
$this->toolbar->addComponent($reset_workflows_button);
}

protected function updateWorkflows()
{
$this->setTabParameter(xoctMainGUI::SUBTAB_WORKFLOWS_LIST);
$update_succeeded = $this->workflow_repository->updateList();
if ($update_succeeded) {
ilUtil::sendSuccess($this->translate('msg_workflow_list_update_success'), true);
} else {
ilUtil::sendFailure($this->translate('msg_workflow_list_update_failed'), true);
}
$this->ctrl->redirect($this, self::CMD_STANDARD);
}

protected function confirmResetWorkflows()
{
$ilConfirmationGUI = new ilConfirmationGUI();
$ilConfirmationGUI->setFormAction($this->ctrl->getFormAction($this));
$ilConfirmationGUI->setCancel($this->language->txt('cancel'), self::CMD_STANDARD);
$ilConfirmationGUI->setConfirm($this->language->txt('confirm'), self::CMD_RESET_WORKFLOWS);
$ilConfirmationGUI->setHeaderText($this->plugin->txt('msg_confirm_reset_workflow_list'));
$this->main_tpl->setContent($ilConfirmationGUI->getHTML());
}

protected function resetWorkflows()
{
try {
$reset_succeeded = $this->workflow_repository->resetList();
if ($reset_succeeded) {
ilUtil::sendSuccess($this->translate('msg_workflow_list_reset_success'), true);
} else {
ilUtil::sendFailure($this->translate('msg_workflow_list_reset_failed'), true);
}
} catch (xoctException $e) {
ilUtil::sendFailure($e->getMessage(), true);
}
$this->ctrl->redirect($this, self::CMD_STANDARD);
}

/**
* @throws DICException
*/
protected function getForm(WorkflowAR $workflow = null): Standard
{
$id = $this->factory->input()->field()->text($this->language->txt('id'))->withRequired(true);
$title = $this->factory->input()->field()->text($this->language->txt('title'))->withRequired(true);
$parameters = $this->factory->input()->field()->text($this->plugin->txt('parameters'))->withByline(
$this->plugin->txt('parameters_info')
);
$id = $this->factory->input()->field()->text($this->language->txt('id'))->withDisabled(true);
$title = $this->factory->input()->field()->text($this->language->txt('title'));
$description = $this->factory->input()->field()->textarea($this->language->txt('description'));
$tags = $this->factory->input()->field()->text($this->translate('tags', self::LANG_MODULE))->withDisabled(true);
$configuration_panel = $this->factory->input()->field()->textarea($this->translate('config_panel', self::LANG_MODULE))
->withDisabled(true);

if (!is_null($workflow)) {
$this->ctrl->setParameter($this, 'workflow_id', $workflow->getId());
Expand All @@ -94,8 +239,10 @@ protected function getForm(WorkflowAR $workflow = null): Standard
[
'id' => is_null($workflow) ? $id : $id->withValue($workflow->getWorkflowId()),
'title' => is_null($workflow) ? $title : $title->withValue($workflow->getTitle()),
'parameters' => is_null($workflow) ? $parameters : $parameters->withValue(
$workflow->getParameters()
'description' => is_null($workflow) ? $description : $description->withValue($workflow->getDescription()),
'tags' => is_null($workflow) ? $tags : $tags->withValue($workflow->getTags()),
'configuration_panel' => is_null($workflow) ? $configuration_panel : $configuration_panel->withValue(
json_encode($workflow->getConfigPanel())
)
],
$this->plugin->txt('workflow')
Expand All @@ -119,7 +266,8 @@ protected function create()
{
$form = $this->getForm()->withRequest($this->http->request());
if ($data = $form->getData()) {
$this->workflow_repository->store($data[0]['id'], $data[0]['title'], $data[0]['parameters']);
$wf = reset($data);
$this->workflow_repository->createOrUpdate($wf['id'], $wf['title'], $wf['description'], $wf['tags']);
ilUtil::sendSuccess($this->plugin->txt('msg_workflow_created'), true);
$this->ctrl->redirect($this, self::CMD_STANDARD);
} else {
Expand All @@ -146,7 +294,8 @@ protected function update()
$id = filter_input(INPUT_GET, 'workflow_id', FILTER_SANITIZE_STRING);
$form = $this->getForm(WorkflowAR::find($id))->withRequest($this->http->request());
if ($data = $form->getData()) {
$this->workflow_repository->store($data[0]['id'], $data[0]['title'], $data[0]['parameters'], $id);
$wf = reset($data);
$this->workflow_repository->createOrUpdate($wf['id'], $wf['title'], $wf['description']);
ilUtil::sendSuccess($this->plugin->txt('msg_workflow_updated'), true);
$this->ctrl->redirect($this, self::CMD_STANDARD);
} else {
Expand Down Expand Up @@ -176,4 +325,15 @@ protected function delete()
$this->ctrl->redirect($this, self::CMD_STANDARD);
}
}

/**
* @param $key
*
* @return string
* @throws DICException
*/
public function txt($key): string
{
return $this->translate($key, self::LANG_MODULE);
}
}
57 changes: 48 additions & 9 deletions classes/Conf/Workflows/class.xoctWorkflowTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ class xoctWorkflowTableGUI extends TableGUI
* @var Renderer
*/
protected $renderer;
/**
* @var ilOpenCastPlugin
*/
private $plugin;

public function __construct($parent, string $parent_cmd, WorkflowRepository $workflow_repository)
{
global $DIC;
global $DIC, $opencastContainer;
$this->plugin = $opencastContainer->get(ilOpenCastPlugin::class);
$ui = $DIC->ui();
$this->workflow_repository = $workflow_repository;
$this->factory = $ui->factory();
Expand All @@ -48,17 +53,34 @@ public function __construct($parent, string $parent_cmd, WorkflowRepository $wor
$this->setExternalSegmentation(true);
parent::__construct($parent, $parent_cmd);
$this->setDescription($this->translate('msg_workflows_info'));
$parent->setTabParameter(xoctMainGUI::SUBTAB_WORKFLOWS_LIST);
}

/**
* @throws DICException
*/
protected function initColumns(): void
{
$this->addColumn($this->lng->txt('id'));
$this->addColumn($this->lng->txt('title'));
$this->addColumn($this->translate('parameters'));
$this->addColumn($this->lng->txt('actions'), '', '', true);
foreach ($this->getSelectableColumns2() as $col) {
$txt = $col['txt'];
$id = $col['id'];
$sort = false;
$width = '';
switch ($id) {
case 'description':
$width = '250px';
break;
case 'id':
$width = '200px';
break;
case 'config_panel':
$width = '24px';
break;
}
$action = ($id == 'action');

$this->addColumn($txt, $sort, $width, $action);
}
}

public function getHTML()
Expand Down Expand Up @@ -86,8 +108,23 @@ protected function getColumnValue(string $column, /*array*/ $row, int $format =
return $row->getWorkflowId();
case 'title':
return $row->getTitle();
case 'parameters':
return $row->getParameters();
case 'description':
return $row->getDescription();
case 'tags':
return str_replace(',', '<br />', $row->getTags());
case 'config_panel':
$tpl = new ilTemplate("tpl.icon.html", true, true, $this->plugin->getDirectory());
$has_config_panel = !empty($row->getConfigPanel()) ? true : false;
$icon = $has_config_panel ? 'checkbox_checked.png' : 'checkbox_unchecked.png';
$tpl->setCurrentBlock('icon');
$tpl->setVariable('ICON_SRC', ilUtil::getHtmlPath(ilUtil::getImagePath($icon)));
$tpl->setVariable('ICON_ALT', $icon);
$icon_title = $has_config_panel ?
$this->translate('config_panel_icon_with', self::LANG_MODULE) :
$this->translate('config_panel_icon_without', self::LANG_MODULE);
$tpl->setVariable('ICON_TITLE', $icon_title);
$tpl->parseCurrentBlock();
return $tpl->get();
case 'actions':
$this->ctrl->setParameter($this->parent_obj, 'workflow_id', $row->getId());
$delete_modal = $this->factory->modal()->interruptive(
Expand Down Expand Up @@ -130,7 +167,9 @@ protected function getSelectableColumns2(): array
return [
['txt' => $this->lng->txt('id'), 'id' => 'id'],
['txt' => $this->lng->txt('title'), 'id' => 'title'],
['txt' => $this->translate('parameters'), 'id' => 'parameters'],
['txt' => $this->lng->txt('description'), 'id' => 'description'],
['txt' => $this->translate('tags', self::LANG_MODULE), 'id' => 'tags'],
['txt' => $this->translate('config_panel', self::LANG_MODULE), 'id' => 'config_panel'],
['txt' => $this->lng->txt('actions'), 'id' => 'actions']
];
}
Expand Down Expand Up @@ -164,7 +203,7 @@ protected function initFilterFields(): void
*/
protected function initId(): void
{
// TODO: Implement initId() method.
$this->setId('xoct_workflows');
}

/**
Expand Down
Loading