Skip to content

Commit 53b4e8b

Browse files
committed
Merge PR #215: Dynamic Workflows
# Conflicts: # classes/Event/class.xoctEventRenderer.php # classes/class.xoctMainGUI.php # js/opencast/dist/index.js # js/opencast/src/index.js # lang/ilias_de.lang # lang/ilias_en.lang # plugin.php # sql/dbupdate.php
2 parents e81d3f0 + 4fa68f2 commit 53b4e8b

24 files changed

+1451
-82
lines changed

classes/Conf/Workflows/class.xoctWorkflowGUI.php

Lines changed: 176 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use srag\Plugins\Opencast\Model\Workflow\WorkflowAR;
66
use srag\Plugins\Opencast\Model\Workflow\WorkflowRepository;
77
use srag\Plugins\Opencast\LegacyHelpers\OutputTrait;
8+
use srag\Plugins\Opencast\LegacyHelpers\TranslatorTrait;
9+
use srag\Plugins\Opencast\Model\Config\PluginConfig;
810

911
/**
1012
* Class xoctWorkflowGUI
@@ -15,9 +17,15 @@
1517
*/
1618
class xoctWorkflowGUI extends xoctGUI
1719
{
20+
use TranslatorTrait;
1821
use OutputTrait;
22+
public const PLUGIN_CLASS_NAME = ilOpenCastPlugin::class;
1923

2024
public const LANG_MODULE = 'workflow';
25+
public const CMD_SAVE_SETTINGS = 'saveSettings';
26+
public const CMD_UPDATE_WORKFLOWS = 'updateWorkflows';
27+
public const CMD_CONFIRM_RESET_WORKFLOWS = 'confirmResetWorkflows';
28+
public const CMD_RESET_WORKFLOWS = 'resetWorkflows';
2129
/**
2230
* @var Factory
2331
*/
@@ -38,6 +46,18 @@ class xoctWorkflowGUI extends xoctGUI
3846
* @var \ILIAS\HTTP\Services
3947
*/
4048
private $http;
49+
/**
50+
* @var \ilGlobalTemplateInterface
51+
*/
52+
private $main_tpl;
53+
/**
54+
* @var \ilTabs
55+
*/
56+
private $tabs;
57+
/**
58+
* @var string
59+
*/
60+
protected $wf_subtab_active;
4161

4262
public function __construct(WorkflowRepository $workflow_repository)
4363
{
@@ -46,9 +66,14 @@ public function __construct(WorkflowRepository $workflow_repository)
4666
$ui = $DIC->ui();
4767
$this->toolbar = $DIC->toolbar();
4868
$this->language = $DIC->language();
69+
$this->tabs = $DIC->tabs();
4970
$this->http = $DIC->http();
5071
$this->workflow_repository = $workflow_repository;
5172
$this->factory = $ui->factory();
73+
$this->main_tpl = $ui->mainTemplate();
74+
$this->wf_subtab_active =
75+
$this->http->request()->getQueryParams()['wf_subtab_active'] ?? xoctMainGUI::SUBTAB_WORKFLOWS_SETTINGS;
76+
$this->setTab();
5277
}
5378

5479
/**
@@ -57,30 +82,150 @@ public function __construct(WorkflowRepository $workflow_repository)
5782
*/
5883
protected function index()
5984
{
60-
$this->initToolbar();
61-
$table = new xoctWorkflowTableGUI($this, self::CMD_STANDARD, $this->workflow_repository);
62-
$this->output($table);
85+
if ($this->wf_subtab_active === xoctMainGUI::SUBTAB_WORKFLOWS_LIST) {
86+
$this->initToolbar();
87+
$table = new xoctWorkflowTableGUI($this, self::CMD_STANDARD, $this->workflow_repository);
88+
$this->output($table);
89+
} else {
90+
$this->output($this->getWorkflowSettingsForm());
91+
}
92+
}
93+
94+
/**
95+
* Helps setting the tabs at all time.
96+
*/
97+
public function setTab()
98+
{
99+
$this->ctrl->saveParameter($this, 'wf_subtab_active');
100+
$this->tabs->setSubTabActive($this->wf_subtab_active);
101+
}
102+
103+
public function setTabParameter($tab = xoctMainGUI::SUBTAB_WORKFLOWS_SETTINGS)
104+
{
105+
$this->ctrl->setParameter(
106+
$this,
107+
'wf_subtab_active',
108+
$tab
109+
);
110+
}
111+
112+
/**
113+
*
114+
*/
115+
protected function getWorkflowSettingsForm()
116+
{
117+
$tags = $this->factory->input()->field()->text($this->translate(PluginConfig::F_WORKFLOWS_TAGS))
118+
->withByline($this->translate(PluginConfig::F_WORKFLOWS_TAGS . '_info'))
119+
->withValue(PluginConfig::getConfig(PluginConfig::F_WORKFLOWS_TAGS) ?? '');
120+
return $this->factory->input()->container()->form()->standard(
121+
$this->ctrl->getFormAction($this, self::CMD_SAVE_SETTINGS),
122+
[
123+
$this->factory->input()->field()->section(
124+
[
125+
PluginConfig::F_WORKFLOWS_TAGS => $tags,
126+
],
127+
$this->txt('settings_header'),
128+
$this->txt('settings_header_description')
129+
)
130+
]
131+
);
132+
}
133+
134+
protected function saveSettings()
135+
{
136+
$this->setTabParameter();
137+
$form = $this->getWorkflowSettingsForm()->withRequest($this->http->request());
138+
if ($data = $form->getData()) {
139+
$data = reset($data);
140+
141+
$current_tags = PluginConfig::getConfig(PluginConfig::F_WORKFLOWS_TAGS);
142+
143+
$new_tags = $data[PluginConfig::F_WORKFLOWS_TAGS] ?? '';
144+
145+
try {
146+
$update_succeeded = $this->workflow_repository->updateList($new_tags);
147+
if ($update_succeeded) {
148+
ilUtil::sendSuccess($this->translate('msg_workflow_settings_saved'), true);
149+
PluginConfig::set(
150+
PluginConfig::F_WORKFLOWS_TAGS,
151+
trim($new_tags)
152+
);
153+
} else {
154+
ilUtil::sendFailure($this->translate('msg_workflow_settings_saved_update_failed'), true);
155+
// Reverting back!
156+
PluginConfig::set(PluginConfig::F_WORKFLOWS_TAGS, $current_tags);
157+
}
158+
} catch (xoctException $e) {
159+
ilUtil::sendFailure($e->getMessage(), true);
160+
}
161+
$this->ctrl->redirect($this, self::CMD_STANDARD);
162+
} else {
163+
$this->output($form);
164+
}
63165
}
64166

65167
protected function initToolbar()
66168
{
67-
$add_button = $this->factory->button()->primary(
68-
$this->plugin->txt('config_button_add_workflow'),
69-
$this->ctrl->getLinkTarget($this, self::CMD_ADD)
169+
$update_workflows_button = $this->factory->button()->primary(
170+
$this->plugin->txt('config_workflows_update_btn'),
171+
$this->ctrl->getLinkTarget($this, self::CMD_UPDATE_WORKFLOWS)
70172
);
71-
$this->toolbar->addComponent($add_button);
173+
$this->toolbar->addComponent($update_workflows_button);
174+
$reset_workflows_button = $this->factory->button()->standard(
175+
$this->plugin->txt('config_workflows_reset_btn'),
176+
$this->ctrl->getLinkTarget($this, self::CMD_CONFIRM_RESET_WORKFLOWS)
177+
);
178+
$this->toolbar->addComponent($reset_workflows_button);
179+
}
180+
181+
protected function updateWorkflows()
182+
{
183+
$this->setTabParameter(xoctMainGUI::SUBTAB_WORKFLOWS_LIST);
184+
$update_succeeded = $this->workflow_repository->updateList();
185+
if ($update_succeeded) {
186+
ilUtil::sendSuccess($this->translate('msg_workflow_list_update_success'), true);
187+
} else {
188+
ilUtil::sendFailure($this->translate('msg_workflow_list_update_failed'), true);
189+
}
190+
$this->ctrl->redirect($this, self::CMD_STANDARD);
191+
}
192+
193+
protected function confirmResetWorkflows()
194+
{
195+
$ilConfirmationGUI = new ilConfirmationGUI();
196+
$ilConfirmationGUI->setFormAction($this->ctrl->getFormAction($this));
197+
$ilConfirmationGUI->setCancel($this->language->txt('cancel'), self::CMD_STANDARD);
198+
$ilConfirmationGUI->setConfirm($this->language->txt('confirm'), self::CMD_RESET_WORKFLOWS);
199+
$ilConfirmationGUI->setHeaderText($this->plugin->txt('msg_confirm_reset_workflow_list'));
200+
$this->main_tpl->setContent($ilConfirmationGUI->getHTML());
201+
}
202+
203+
protected function resetWorkflows()
204+
{
205+
try {
206+
$reset_succeeded = $this->workflow_repository->resetList();
207+
if ($reset_succeeded) {
208+
ilUtil::sendSuccess($this->translate('msg_workflow_list_reset_success'), true);
209+
} else {
210+
ilUtil::sendFailure($this->translate('msg_workflow_list_reset_failed'), true);
211+
}
212+
} catch (xoctException $e) {
213+
ilUtil::sendFailure($e->getMessage(), true);
214+
}
215+
$this->ctrl->redirect($this, self::CMD_STANDARD);
72216
}
73217

74218
/**
75219
* @throws DICException
76220
*/
77221
protected function getForm(WorkflowAR $workflow = null): Standard
78222
{
79-
$id = $this->factory->input()->field()->text($this->language->txt('id'))->withRequired(true);
80-
$title = $this->factory->input()->field()->text($this->language->txt('title'))->withRequired(true);
81-
$parameters = $this->factory->input()->field()->text($this->plugin->txt('parameters'))->withByline(
82-
$this->plugin->txt('parameters_info')
83-
);
223+
$id = $this->factory->input()->field()->text($this->language->txt('id'))->withDisabled(true);
224+
$title = $this->factory->input()->field()->text($this->language->txt('title'));
225+
$description = $this->factory->input()->field()->textarea($this->language->txt('description'));
226+
$tags = $this->factory->input()->field()->text($this->translate('tags', self::LANG_MODULE))->withDisabled(true);
227+
$configuration_panel = $this->factory->input()->field()->textarea($this->translate('config_panel', self::LANG_MODULE))
228+
->withDisabled(true);
84229

85230
if (!is_null($workflow)) {
86231
$this->ctrl->setParameter($this, 'workflow_id', $workflow->getId());
@@ -94,8 +239,10 @@ protected function getForm(WorkflowAR $workflow = null): Standard
94239
[
95240
'id' => is_null($workflow) ? $id : $id->withValue($workflow->getWorkflowId()),
96241
'title' => is_null($workflow) ? $title : $title->withValue($workflow->getTitle()),
97-
'parameters' => is_null($workflow) ? $parameters : $parameters->withValue(
98-
$workflow->getParameters()
242+
'description' => is_null($workflow) ? $description : $description->withValue($workflow->getDescription()),
243+
'tags' => is_null($workflow) ? $tags : $tags->withValue($workflow->getTags()),
244+
'configuration_panel' => is_null($workflow) ? $configuration_panel : $configuration_panel->withValue(
245+
json_encode($workflow->getConfigPanel())
99246
)
100247
],
101248
$this->plugin->txt('workflow')
@@ -119,7 +266,8 @@ protected function create()
119266
{
120267
$form = $this->getForm()->withRequest($this->http->request());
121268
if ($data = $form->getData()) {
122-
$this->workflow_repository->store($data[0]['id'], $data[0]['title'], $data[0]['parameters']);
269+
$wf = reset($data);
270+
$this->workflow_repository->createOrUpdate($wf['id'], $wf['title'], $wf['description'], $wf['tags']);
123271
ilUtil::sendSuccess($this->plugin->txt('msg_workflow_created'), true);
124272
$this->ctrl->redirect($this, self::CMD_STANDARD);
125273
} else {
@@ -146,7 +294,8 @@ protected function update()
146294
$id = filter_input(INPUT_GET, 'workflow_id', FILTER_SANITIZE_STRING);
147295
$form = $this->getForm(WorkflowAR::find($id))->withRequest($this->http->request());
148296
if ($data = $form->getData()) {
149-
$this->workflow_repository->store($data[0]['id'], $data[0]['title'], $data[0]['parameters'], $id);
297+
$wf = reset($data);
298+
$this->workflow_repository->createOrUpdate($wf['id'], $wf['title'], $wf['description']);
150299
ilUtil::sendSuccess($this->plugin->txt('msg_workflow_updated'), true);
151300
$this->ctrl->redirect($this, self::CMD_STANDARD);
152301
} else {
@@ -176,4 +325,15 @@ protected function delete()
176325
$this->ctrl->redirect($this, self::CMD_STANDARD);
177326
}
178327
}
328+
329+
/**
330+
* @param $key
331+
*
332+
* @return string
333+
* @throws DICException
334+
*/
335+
public function txt($key): string
336+
{
337+
return $this->translate($key, self::LANG_MODULE);
338+
}
179339
}

classes/Conf/Workflows/class.xoctWorkflowTableGUI.php

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ class xoctWorkflowTableGUI extends TableGUI
3636
* @var Renderer
3737
*/
3838
protected $renderer;
39+
/**
40+
* @var ilOpenCastPlugin
41+
*/
42+
private $plugin;
3943

4044
public function __construct($parent, string $parent_cmd, WorkflowRepository $workflow_repository)
4145
{
42-
global $DIC;
46+
global $DIC, $opencastContainer;
47+
$this->plugin = $opencastContainer->get(ilOpenCastPlugin::class);
4348
$ui = $DIC->ui();
4449
$this->workflow_repository = $workflow_repository;
4550
$this->factory = $ui->factory();
@@ -48,17 +53,34 @@ public function __construct($parent, string $parent_cmd, WorkflowRepository $wor
4853
$this->setExternalSegmentation(true);
4954
parent::__construct($parent, $parent_cmd);
5055
$this->setDescription($this->translate('msg_workflows_info'));
56+
$parent->setTabParameter(xoctMainGUI::SUBTAB_WORKFLOWS_LIST);
5157
}
5258

5359
/**
5460
* @throws DICException
5561
*/
5662
protected function initColumns(): void
5763
{
58-
$this->addColumn($this->lng->txt('id'));
59-
$this->addColumn($this->lng->txt('title'));
60-
$this->addColumn($this->translate('parameters'));
61-
$this->addColumn($this->lng->txt('actions'), '', '', true);
64+
foreach ($this->getSelectableColumns2() as $col) {
65+
$txt = $col['txt'];
66+
$id = $col['id'];
67+
$sort = false;
68+
$width = '';
69+
switch ($id) {
70+
case 'description':
71+
$width = '250px';
72+
break;
73+
case 'id':
74+
$width = '200px';
75+
break;
76+
case 'config_panel':
77+
$width = '24px';
78+
break;
79+
}
80+
$action = ($id == 'action');
81+
82+
$this->addColumn($txt, $sort, $width, $action);
83+
}
6284
}
6385

6486
public function getHTML()
@@ -86,8 +108,23 @@ protected function getColumnValue(string $column, /*array*/ $row, int $format =
86108
return $row->getWorkflowId();
87109
case 'title':
88110
return $row->getTitle();
89-
case 'parameters':
90-
return $row->getParameters();
111+
case 'description':
112+
return $row->getDescription();
113+
case 'tags':
114+
return str_replace(',', '<br />', $row->getTags());
115+
case 'config_panel':
116+
$tpl = new ilTemplate("tpl.icon.html", true, true, $this->plugin->getDirectory());
117+
$has_config_panel = !empty($row->getConfigPanel()) ? true : false;
118+
$icon = $has_config_panel ? 'checkbox_checked.png' : 'checkbox_unchecked.png';
119+
$tpl->setCurrentBlock('icon');
120+
$tpl->setVariable('ICON_SRC', ilUtil::getHtmlPath(ilUtil::getImagePath($icon)));
121+
$tpl->setVariable('ICON_ALT', $icon);
122+
$icon_title = $has_config_panel ?
123+
$this->translate('config_panel_icon_with', self::LANG_MODULE) :
124+
$this->translate('config_panel_icon_without', self::LANG_MODULE);
125+
$tpl->setVariable('ICON_TITLE', $icon_title);
126+
$tpl->parseCurrentBlock();
127+
return $tpl->get();
91128
case 'actions':
92129
$this->ctrl->setParameter($this->parent_obj, 'workflow_id', $row->getId());
93130
$delete_modal = $this->factory->modal()->interruptive(
@@ -130,7 +167,9 @@ protected function getSelectableColumns2(): array
130167
return [
131168
['txt' => $this->lng->txt('id'), 'id' => 'id'],
132169
['txt' => $this->lng->txt('title'), 'id' => 'title'],
133-
['txt' => $this->translate('parameters'), 'id' => 'parameters'],
170+
['txt' => $this->lng->txt('description'), 'id' => 'description'],
171+
['txt' => $this->translate('tags', self::LANG_MODULE), 'id' => 'tags'],
172+
['txt' => $this->translate('config_panel', self::LANG_MODULE), 'id' => 'config_panel'],
134173
['txt' => $this->lng->txt('actions'), 'id' => 'actions']
135174
];
136175
}
@@ -164,7 +203,7 @@ protected function initFilterFields(): void
164203
*/
165204
protected function initId(): void
166205
{
167-
// TODO: Implement initId() method.
206+
$this->setId('xoct_workflows');
168207
}
169208

170209
/**

0 commit comments

Comments
 (0)