55use srag \Plugins \Opencast \Model \Workflow \WorkflowAR ;
66use srag \Plugins \Opencast \Model \Workflow \WorkflowRepository ;
77use 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
1517 */
1618class 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}
0 commit comments