From e55886781509fe39951fc7528347696474a17884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Skrzypczak?= Date: Fri, 26 Aug 2022 15:09:34 +0200 Subject: [PATCH] Improved SLA Policy elements --- config/version.php | 2 +- languages/en-US/ServiceContracts.json | 8 - .../ServiceContracts/CustomConditions.tpl | 95 +++++----- .../modules/ServiceContracts/SlaPolicy.tpl | 4 +- .../ServiceContracts/SlaPolicyCustom.tpl | 41 +++++ .../ServiceContracts/SlaPolicyTemplate.tpl | 31 ++++ .../Settings/SlaPolicy/EditViewBlocks.tpl | 12 +- .../actions/PolicyTemplatesAjax.php | 48 ----- .../views/PolicyTemplatesAjax.php | 73 ++++++++ .../ServiceContracts/resources/Detail.js | 172 ++++++------------ 10 files changed, 251 insertions(+), 235 deletions(-) create mode 100644 layouts/basic/modules/ServiceContracts/SlaPolicyCustom.tpl create mode 100644 layouts/basic/modules/ServiceContracts/SlaPolicyTemplate.tpl delete mode 100644 modules/ServiceContracts/actions/PolicyTemplatesAjax.php create mode 100644 modules/ServiceContracts/views/PolicyTemplatesAjax.php diff --git a/config/version.php b/config/version.php index 4ef034057280..b2f6d0d70078 100644 --- a/config/version.php +++ b/config/version.php @@ -1,7 +1,7 @@ '6.4.15', + 'appVersion' => '6.4.16', 'patchVersion' => '2022.08.26', 'lib_roundcube' => '0.3.1', ]; diff --git a/languages/en-US/ServiceContracts.json b/languages/en-US/ServiceContracts.json index a2e23e34bb81..add2c50ef37f 100644 --- a/languages/en-US/ServiceContracts.json +++ b/languages/en-US/ServiceContracts.json @@ -48,13 +48,5 @@ "LBL_STATUS": "Status", "LBL_CONDITIONS": "Conditions", "LBL_TIMES": "Times" - }, - "js": { - "JS_POLICY_NAME": "Policy name", - "JS_OPERATIONAL_HOURS": "Operational hours", - "JS_REACTION_TIME": "Reaction time", - "JS_IDLE_TIME": "Idle time", - "JS_RESOLVE_TIME": "Resolve time", - "JS_BUSINESS_HOURS": "Business hours" } } diff --git a/layouts/basic/modules/ServiceContracts/CustomConditions.tpl b/layouts/basic/modules/ServiceContracts/CustomConditions.tpl index 0c8712c631b2..f8d49d9198cf 100644 --- a/layouts/basic/modules/ServiceContracts/CustomConditions.tpl +++ b/layouts/basic/modules/ServiceContracts/CustomConditions.tpl @@ -1,67 +1,60 @@ {**} {strip} - - -
- {include file=\App\Layout::getTemplatePath('ConditionBuilder.tpl', $MODULE_NAME) ADVANCE_CRITERIA=[]} -
-
- {foreach item=ROW from=$SLA_POLICY_ROWS key=$ROW_INDEX} - {if $ROW['policy_type']===2} -
-
-
-
-
-
- {assign var=ROW_HOURS value=explode(',', $ROW['business_hours'])} - -
- -
+ {foreach item=ROW from=$SLA_POLICY_ROWS key=$ROW_INDEX} + {if $ROW['policy_type']===2} +
+
+
+
+
+
+ {assign var=ROW_HOURS value=explode(',', $ROW['business_hours'])} + +
+
-
- -
- -
-
-
- -
- -
+
+
+ +
+
-
- -
- -
+
+
+ +
+
-
-
- - - - {include file=\App\Layout::getTemplatePath('ConditionBuilder.tpl', $MODULE_NAME) ADVANCE_CRITERIA=\App\Json::decode($ROW['conditions'])} +
+ +
+
-
-
- +
+
+ + + + {include file=\App\Layout::getTemplatePath('ConditionBuilder.tpl', $MODULE_NAME) ADVANCE_CRITERIA=\App\Json::decode($ROW['conditions'])}
+
+
+ +
+
- {/if} - {/foreach} -
+
+ {/if} + {/foreach} {/strip} diff --git a/layouts/basic/modules/ServiceContracts/SlaPolicy.tpl b/layouts/basic/modules/ServiceContracts/SlaPolicy.tpl index 6fd34c0484c9..6ebe0d72d51e 100644 --- a/layouts/basic/modules/ServiceContracts/SlaPolicy.tpl +++ b/layouts/basic/modules/ServiceContracts/SlaPolicy.tpl @@ -25,7 +25,9 @@
- {include file=\App\Layout::getTemplatePath('CustomConditions.tpl', $MODULE_NAME)} +
+ {include file=\App\Layout::getTemplatePath('CustomConditions.tpl', $MODULE_NAME)} +
diff --git a/layouts/basic/modules/ServiceContracts/SlaPolicyCustom.tpl b/layouts/basic/modules/ServiceContracts/SlaPolicyCustom.tpl new file mode 100644 index 000000000000..c7539f5d42fa --- /dev/null +++ b/layouts/basic/modules/ServiceContracts/SlaPolicyCustom.tpl @@ -0,0 +1,41 @@ +{**} +{strip} + +
+ +
+
+ + + + + +
+
+
+
+
+ {include file=\App\Layout::getTemplatePath('CustomConditions.tpl', $MODULE_NAME)} +
+
+
+
+ +
+
+
+ +{/strip} diff --git a/layouts/basic/modules/ServiceContracts/SlaPolicyTemplate.tpl b/layouts/basic/modules/ServiceContracts/SlaPolicyTemplate.tpl new file mode 100644 index 000000000000..bb99edbfcb08 --- /dev/null +++ b/layouts/basic/modules/ServiceContracts/SlaPolicyTemplate.tpl @@ -0,0 +1,31 @@ +{**} +{strip} + +
+ + + + + + + + + + + + + {foreach from=\App\Utils\ServiceContracts::getSlaPolicyByModule($TARGET_MODULE_ID) item=ROW key=key name=slaTemplates} + + + + + + + + + {/foreach} + +
{\App\Language::translate('LBL_POLICY_NAME', $MODULE_NAME)}{\App\Language::translate('LBL_OPERATIONAL_HOURS', $MODULE_NAME)}{\App\Language::translate('LBL_REACTION_TIME', $MODULE_NAME)}{\App\Language::translate('LBL_IDLE_TIME', $MODULE_NAME)}{\App\Language::translate('LBL_RESOLVE_TIME', $MODULE_NAME)}
{\App\Purifier::encodeHtml($ROW.name)}{\App\Purifier::encodeHtml($ROW.operational_hours)}{\App\Purifier::encodeHtml($ROW.reaction_time)}{\App\Purifier::encodeHtml($ROW.idle_time)}{\App\Purifier::encodeHtml($ROW.resolve_time)}
+
+ +{/strip} diff --git a/layouts/basic/modules/Settings/SlaPolicy/EditViewBlocks.tpl b/layouts/basic/modules/Settings/SlaPolicy/EditViewBlocks.tpl index acbc0f029723..dcfcbdda3619 100644 --- a/layouts/basic/modules/Settings/SlaPolicy/EditViewBlocks.tpl +++ b/layouts/basic/modules/Settings/SlaPolicy/EditViewBlocks.tpl @@ -21,7 +21,7 @@
{if !empty($RECORD->getId())} - {\App\Language::translate('LBL_EDIT',$QUALIFIED_MODULE)} - {$RECORD->getName()} + {\App\Language::translate('LBL_EDIT',$QUALIFIED_MODULE)} - {\App\Purifier::encodeHtml($RECORD->getName())} {else} {\App\Language::translate('LBL_CREATE',$QUALIFIED_MODULE)} @@ -31,13 +31,13 @@
- +
@@ -66,19 +66,19 @@
- +
- +
- +
diff --git a/modules/ServiceContracts/actions/PolicyTemplatesAjax.php b/modules/ServiceContracts/actions/PolicyTemplatesAjax.php deleted file mode 100644 index fa70199f65f2..000000000000 --- a/modules/ServiceContracts/actions/PolicyTemplatesAjax.php +++ /dev/null @@ -1,48 +0,0 @@ - - * @author Mariusz Krzaczkowski - */ -class ServiceContracts_PolicyTemplatesAjax_Action extends \App\Controller\Action -{ - /** {@inheritdoc} */ - public function checkPermission(App\Request $request) - { - $record = Vtiger_DetailView_Model::getInstance($request->getModule(), $request->getInteger('record')); - if (!$record->getRecord()->isViewable()) { - throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406); - } - } - - /** {@inheritdoc} */ - public function process(App\Request $request) - { - $sla = \App\Utils\ServiceContracts::getSlaPolicyForServiceContracts($request->getInteger('record')); - $slaId = $sla ? $sla[0]['sla_policy_id'] : false; - $rows = []; - foreach (\App\Utils\ServiceContracts::getSlaPolicyByModule(\App\Module::getModuleId($request->getByType('targetModule', 'Alnum'))) as $row) { - $moduleName = \App\Module::getModuleName($row['tabid']); - $row['tabid'] = \App\Language::translate($moduleName, $moduleName); - $row['operational_hours'] = $row['operational_hours'] ? \App\Language::translate('LBL_CALENDAR_HOURS', 'ServiceContracts') : \App\Language::translate('LBL_BUSINESS_HOURS', 'ServiceContracts'); - $row['business_hours'] = implode(', ', array_column(\App\Utils\ServiceContracts::getBusinessHoursByIds(explode(',', $row['business_hours'])), 'name')); - $row['reaction_time'] = \App\Fields\TimePeriod::getLabel($row['reaction_time']); - $row['idle_time'] = \App\Fields\TimePeriod::getLabel($row['idle_time']); - $row['resolve_time'] = \App\Fields\TimePeriod::getLabel($row['resolve_time']); - if ($row['id'] === $slaId) { - $row['checked'] = true; - } else { - $row['checked'] = false; - } - $rows[] = $row; - } - $response = new Vtiger_Response(); - $response->setResult($rows); - $response->emit(); - } -} diff --git a/modules/ServiceContracts/views/PolicyTemplatesAjax.php b/modules/ServiceContracts/views/PolicyTemplatesAjax.php new file mode 100644 index 000000000000..0f098f6636cc --- /dev/null +++ b/modules/ServiceContracts/views/PolicyTemplatesAjax.php @@ -0,0 +1,73 @@ + + */ +class ServiceContracts_PolicyTemplatesAjax_View extends Vtiger_Index_View +{ + use \App\Controller\ExposeMethod; + + /** @var Vtiger_Record_Model Record model instance. */ + public $record; + + /** + * Construct. + */ + public function __construct() + { + parent::__construct(); + $this->exposeMethod('slaPolicyTemplate'); + $this->exposeMethod('slaPolicyCustom'); + } + + /** {@inheritdoc} */ + public function checkPermission(App\Request $request) + { + $this->record = Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule()); + if (!$this->record->isViewable() || !$this->record->isPermitted('ServiceContractsSla') || !App\Privilege::isPermitted($request->getByType('targetModule', \App\Purifier::ALNUM))) { + throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406); + } + } + + /** {@inheritdoc} */ + public function slaPolicyTemplate(App\Request $request) + { + $moduleName = $request->getModule(); + $sla = \App\Utils\ServiceContracts::getSlaPolicyForServiceContracts($request->getInteger('record')); + $slaId = $sla[0]['sla_policy_id'] ?? 0; + + $viewer = $this->getViewer($request); + $viewer->assign('TARGET_MODULE_ID', \App\Module::getModuleId($request->getByType('targetModule', \App\Purifier::ALNUM))); + $viewer->assign('SELECTED_TEMPLATE', $slaId); + + return $viewer->view('SlaPolicyTemplate.tpl', $moduleName); + } + + /** {@inheritdoc} */ + public function slaPolicyCustom(App\Request $request) + { + $moduleName = $request->getModule(); + $index = $request->getInteger('index', time()); + $defaultEmptyData = [ + 'id' => 0, + 'policy_type' => 2, + 'conditions' => '[]', + 'reaction_time' => '1:d', + 'idle_time' => '1:d', + 'resolve_time' => '1:d', + 'business_hours' => '', + ]; + + $viewer = $this->getViewer($request); + $viewer->assign('RECORD', $this->record); + $viewer->assign('ALL_BUSINESS_HOURS', \App\Utils\ServiceContracts::getAllBusinessHours()); + $viewer->assign('SLA_POLICY_ROWS', [$index => $defaultEmptyData]); + + return $viewer->view('CustomConditions.tpl', $moduleName); + } +} diff --git a/public_html/layouts/basic/modules/ServiceContracts/resources/Detail.js b/public_html/layouts/basic/modules/ServiceContracts/resources/Detail.js index 6f88c50d8d53..bbc8909d93ea 100644 --- a/public_html/layouts/basic/modules/ServiceContracts/resources/Detail.js +++ b/public_html/layouts/basic/modules/ServiceContracts/resources/Detail.js @@ -4,6 +4,7 @@ * @description InRelation scripts for SlaPolicy module * @license YetiForce Public License 5.0 * @author Mariusz Krzaczkowski + * @author Radosław Skrzypczak */ 'use strict'; @@ -40,73 +41,45 @@ Vtiger_Detail_Js( this.container.find('.js-sla-policy-custom').removeClass('d-none'); return this; }, - /** - * Get template table - * @param {Array} rows - * - * @returns {String} HTML + * Get default params + * @returns {Object} */ - getTemplateTableHtml(rows) { - let somethingChecked = false; - rows.forEach((row) => { - if (row.checked) { - somethingChecked = true; - return false; - } - }); - if (!somethingChecked && typeof rows[0] !== 'undefined') { - rows[0].checked = true; - } - return `
- - - - - - - - - - - - ${rows - .map((row) => { - return ` - - - - - - - `; - }) - .join('')} - -
${app.vtranslate('JS_POLICY_NAME')}${app.vtranslate('JS_OPERATIONAL_HOURS')}${app.vtranslate('JS_REACTION_TIME')}${app.vtranslate('JS_IDLE_TIME')}${app.vtranslate('JS_RESOLVE_TIME')}
${row.name}${row.operational_hours}${row.reaction_time}${row.idle_time}${row.resolve_time}
-
`; + getDefaultParam() { + return { + module: 'ServiceContracts', + view: 'PolicyTemplatesAjax', + targetModule: this.targetModule, + record: Number($('#recordId').val()) + }; }, /** * Load predefined sla policy templates + * @param {Object} param + * @returns */ - loadTemplates() { + loadTemplates(param) { const progress = jQuery.progressIndicator({ position: 'html', blockInfo: { enabled: true } }); - AppConnector.request({ - module: 'ServiceContracts', - action: 'PolicyTemplatesAjax', - targetModule: this.targetModule, - record: Number($('#recordId').val()) - }).done((data) => { - progress.progressIndicator({ mode: 'hide' }); - if (data.success) { - this.container.find('.js-sla-policy-template--container').html(this.getTemplateTableHtml(data.result)); - } + return new Promise((resolve, _reject) => { + AppConnector.request(param) + .done((data) => { + progress.progressIndicator({ mode: 'hide' }); + resolve(data); + }) + .fail((e, t) => { + progress.progressIndicator({ mode: 'hide' }); + app.errorLog(e, t); + app.showNotify({ + text: app.vtranslate('JS_ERROR'), + type: 'error' + }); + }); }); }, @@ -116,7 +89,12 @@ Vtiger_Detail_Js( onPolicyTypeChange() { this.policyType = Number(this.container.find('[name="policy_type"]:checked').val()); if (this.policyType === 1) { - this.hideAll().showTemplateSettings().loadTemplates(); + this.hideAll() + .showTemplateSettings() + .loadTemplates({ mode: 'slaPolicyTemplate', ...this.getDefaultParam() }) + .then((data) => { + this.container.find('.js-sla-policy-template--container').html(data); + }); } else if (this.policyType === 2) { this.hideAll().showCustomSettings(); } else { @@ -176,7 +154,7 @@ Vtiger_Detail_Js( rowElem.find('.js-custom-row-id').val(row.id); }); } else { - $.each(this.container.find('.js-custom-row'), (index, rowElem) => { + $.each(this.container.find('.js-custom-row'), (_index, rowElem) => { rowElem = $(rowElem); rowElem.data('id', 0); rowElem.find('.js-custom-row-id').val(0); @@ -198,66 +176,21 @@ Vtiger_Detail_Js( addPolicyBtn.on('click', (e) => { e.preventDefault(); e.stopPropagation(); - const index = this.container.find('.js-custom-row').length; - const row = $(`
-
-
-
-
-
- - -
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
-
-
- - - ${this.container.find('.js-conditions-template').html()} -
-
-
-
-
- -
-
-
-
-
` - ); - App.Fields.TimePeriod.register(row); - this.registerDelBtnClick(row); - App.Fields.Picklist.showSelect2ElementView(row.find('.select2')); - this.registerConditionBuilder( - row.find('.js-condition-builder').eq(0), - this.container.find('.js-conditions-col').length - ); - this.container.find('.js-custom-conditions').append(row); + this.loadTemplates({ + mode: 'slaPolicyCustom', + index: this.container.find('.js-custom-row').length, + ...this.getDefaultParam() + }).then((data) => { + let html = $(data); + App.Fields.TimePeriod.register(html); + this.registerDelBtnClick(html); + App.Fields.Picklist.showSelect2ElementView(html.find('.select2')); + this.registerConditionBuilder( + html.find('.js-condition-builder').eq(0), + this.container.find('.js-conditions-col').length + ); + this.container.find('.js-custom-conditions').append(html); + }); }); }, @@ -288,7 +221,7 @@ Vtiger_Detail_Js( targetModule: this.targetModule, record: row.data('record-id'), rowId: rowId - }).done((data) => { + }).done(() => { progress.progressIndicator({ mode: 'hide' }); $(e.target).closest('.card').remove(); app.showNotify({ @@ -336,11 +269,10 @@ Vtiger_Detail_Js( this.container = this.getForm(); this.policyType = Number(this.container.find('[name="policy_type"]:checked').val()); this.targetModule = this.container.find('[name="target"]').val(); - this.businessHours = JSON.parse(this.container.find('.js-all-business-hours').val()); this.conditionBuilders = []; this.conditionsBuildersContainers = []; this.container.off('submit').on('submit', this.onSubmit.bind(this)); - this.container.find('.js-sla-policy-type-radio').on('click', (e) => this.onPolicyTypeChange()); + this.container.find('.js-sla-policy-type-radio').on('click', () => this.onPolicyTypeChange()); this.onPolicyTypeChange(); App.Fields.TimePeriod.register(this.container); this.registerAddRecordBtnClick(); @@ -356,7 +288,7 @@ Vtiger_Detail_Js( if (detailViewForm.find('.js-sla-policy').length) { this.initSlaPolicy(); } - app.event.on('DetailView.Tab.AfterLoad', (event, data, instance) => { + app.event.on('DetailView.Tab.AfterLoad', (_event, _data, instance) => { if (instance.getForm().find('.js-sla-policy').length) { instance.initSlaPolicy(); }