wip api integration pandora #1355
This commit is contained in:
parent
bae46d1890
commit
d84299d3ab
|
@ -811,7 +811,6 @@ if ($config['integria_enabled'] && $config['integria_user_level_conf']) {
|
|||
$row['control'] .= '<span id="test-integria-message" class="invisible"></span>';
|
||||
$table_remote->data['integria_test'] = $row;
|
||||
|
||||
hd('Entra');
|
||||
// echo '<div class="integria_user_conf">';
|
||||
$userManagementTable->colspan['pandoraitsm'] = 2;
|
||||
$userManagementTable->data['pandoraitsm'] = html_print_table($table_remote, true);
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/* global $ jQuery */
|
||||
|
||||
/* Function get custom fields incidences */
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function getInputFieldsIncidenceType(idIncidenceType, fieldsData, ajaxUrl) {
|
||||
console.log(idIncidenceType);
|
||||
console.log(fieldsData);
|
||||
console.log(ajaxUrl);
|
||||
// Failed request handler.
|
||||
var handleFail = function(jqXHR, textStatus, errorThrown) {
|
||||
console.log(jqXHR, textStatus, errorThrown);
|
||||
};
|
||||
|
||||
// Function which handle success case.
|
||||
var handleSuccess = function(data) {
|
||||
$(".object-type-fields").empty();
|
||||
$(".object-type-fields").append(data);
|
||||
};
|
||||
|
||||
// Visual Console container request.
|
||||
jQuery
|
||||
.get(
|
||||
ajaxUrl,
|
||||
{
|
||||
page: "operation/ITSM/itsm",
|
||||
method: "getInputFieldsIncidenceType",
|
||||
idIncidenceType: idIncidenceType,
|
||||
fieldsData: fieldsData
|
||||
},
|
||||
"html"
|
||||
)
|
||||
.done(handleSuccess)
|
||||
.fail(handleFail);
|
||||
}
|
|
@ -45,7 +45,6 @@ class ITSM
|
|||
if ($this->userLevelConf === true) {
|
||||
$this->userBearer = $user_info['integria_user_level_pass'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -77,6 +76,8 @@ class ITSM
|
|||
$path = $this->pathAction($action, $queryParams, $id);
|
||||
$url = $this->url.$path;
|
||||
|
||||
// Debugger.
|
||||
// hd($url, true);
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
|
@ -85,15 +86,14 @@ class ITSM
|
|||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postFields));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_VERBOSE, true);
|
||||
$result = curl_exec($ch);
|
||||
$response = curl_exec($ch);
|
||||
|
||||
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
$result = json_decode($result, true);
|
||||
$result = json_decode($response, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
throw new \Exception(__('Invalid response'));
|
||||
throw new \Exception(__('Invalid response').', '.$response);
|
||||
}
|
||||
|
||||
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if ($http_status !== 200) {
|
||||
throw new \Exception($result['error']);
|
||||
}
|
||||
|
@ -147,6 +147,14 @@ class ITSM
|
|||
$path = '/incidence/'.$id;
|
||||
break;
|
||||
|
||||
case 'incidenceTypeFields':
|
||||
$path = '/incidencetype/'.$id.'/field/list';
|
||||
break;
|
||||
|
||||
case 'incidence':
|
||||
$path = '/incidence/'.$id;
|
||||
break;
|
||||
|
||||
default:
|
||||
// Not posible.
|
||||
break;
|
||||
|
|
|
@ -26,6 +26,7 @@ class Manager
|
|||
public $AJAXMethods = [
|
||||
'getListTickets',
|
||||
'getUserSelect',
|
||||
'getInputFieldsIncidenceType',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -106,12 +107,14 @@ class Manager
|
|||
*/
|
||||
public function run()
|
||||
{
|
||||
ui_require_css_file('integriaims');
|
||||
switch ($this->operation) {
|
||||
case 'list':
|
||||
$this->showList();
|
||||
break;
|
||||
|
||||
case 'edit':
|
||||
\ui_require_javascript_file('ITSM');
|
||||
$this->showEdit();
|
||||
break;
|
||||
|
||||
|
@ -150,19 +153,9 @@ class Manager
|
|||
$create_incidence = (bool) \get_parameter('create_incidence', 0);
|
||||
$update_incidence = (bool) \get_parameter('update_incidence', 0);
|
||||
$idIncidence = \get_parameter('idIncidence', 0);
|
||||
$incidence = [
|
||||
'title' => \get_parameter('title', ''),
|
||||
'idIncidenceType' => \get_parameter('idIncidenceType', 0),
|
||||
'idGroup' => \get_parameter('idGroup', 0),
|
||||
'priority' => 'LOW',
|
||||
// \get_parameter('priority', 'LOW'),
|
||||
'status' => \get_parameter('status', 'NEW'),
|
||||
'idCreator' => \get_parameter('idCreator', ''),
|
||||
'owner' => \get_parameter('owner_hidden', ''),
|
||||
'resolution' => \get_parameter('resolution', null),
|
||||
'description' => \get_parameter('description', ''),
|
||||
];
|
||||
|
||||
// Debugger.
|
||||
// hd($_POST);
|
||||
$error = '';
|
||||
$ITSM = new ITSM();
|
||||
try {
|
||||
|
@ -171,12 +164,47 @@ class Manager
|
|||
// $priorities = $ITSM->callApi('listPriorities');
|
||||
$resolutions = $this->getResolutions($ITSM);
|
||||
$status = $this->getStatus($ITSM);
|
||||
|
||||
if (empty($idIncidence) === false) {
|
||||
$incidenceData = $this->getIncidence($ITSM, $idIncidence);
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
$error = $th->getMessage();
|
||||
}
|
||||
|
||||
// TODO: END POINT priorities.
|
||||
// \get_parameter('priority', 'LOW').
|
||||
$incidence = [
|
||||
'title' => \get_parameter('title', ($incidenceData['title'] ?? '')),
|
||||
'idIncidenceType' => \get_parameter('idIncidenceType', ($incidenceData['idIncidenceType'] ?? 0)),
|
||||
'idGroup' => \get_parameter('idGroup', ($incidenceData['idGroup'] ?? 0)),
|
||||
'priority' => 'LOW',
|
||||
'status' => \get_parameter('status', ($incidenceData['status'] ?? 'NEW')),
|
||||
'idCreator' => \get_parameter('idCreator', ($incidenceData['idCreator'] ?? '')),
|
||||
'owner' => \get_parameter('owner_hidden', ''),
|
||||
'resolution' => \get_parameter('resolution', ($incidenceData['resolution'] ?? null)),
|
||||
'description' => \get_parameter('description', ($incidenceData['description'] ?? '')),
|
||||
];
|
||||
|
||||
$successfullyMsg = '';
|
||||
try {
|
||||
if (empty($incidence['idIncidenceType']) === false
|
||||
&& ($create_incidence === true || $update_incidence === true)
|
||||
) {
|
||||
$customFields = \get_parameter('custom-fields', []);
|
||||
if (empty($customFields) === false) {
|
||||
$typeFieldData = [];
|
||||
foreach ($customFields as $idField => $data) {
|
||||
$typeFieldData[] = [
|
||||
'idIncidenceTypeField' => $idField,
|
||||
'data' => $data,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$incidence['typeFieldData'] = $typeFieldData;
|
||||
}
|
||||
|
||||
if ($create_incidence === true) {
|
||||
$incidence = $this->createIncidence($ITSM, $incidence);
|
||||
$idIncidence = $incidence['idIncidence'];
|
||||
|
@ -325,6 +353,52 @@ class Manager
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Incidence.
|
||||
*
|
||||
* @param ITSM $ITSM Object for callApi.
|
||||
* @param integer $idIncidence Incidence ID.
|
||||
*
|
||||
* @return array Data incidence
|
||||
*/
|
||||
private function getIncidence(ITSM $ITSM, int $idIncidence): array
|
||||
{
|
||||
$result = $ITSM->callApi(
|
||||
'incidence',
|
||||
[],
|
||||
[],
|
||||
$idIncidence,
|
||||
'GET'
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get fields incidence type.
|
||||
*
|
||||
* @param ITSM $ITSM Object for callApi.
|
||||
* @param integer $idIncidenceType Incidence Type ID.
|
||||
*
|
||||
* @return array Fields array.
|
||||
*/
|
||||
private function getFieldsIncidenceType(ITSM $ITSM, int $idIncidenceType): array
|
||||
{
|
||||
$result = $ITSM->callApi(
|
||||
'incidenceTypeFields',
|
||||
[
|
||||
'page' => 0,
|
||||
'sizePage' => 0,
|
||||
],
|
||||
[],
|
||||
$idIncidenceType
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Draw list dashboards.
|
||||
*
|
||||
|
@ -332,8 +406,6 @@ class Manager
|
|||
*/
|
||||
private function showDashboard()
|
||||
{
|
||||
global $config;
|
||||
|
||||
View::render(
|
||||
'ITSM/ITSMDashboardView',
|
||||
[
|
||||
|
@ -467,4 +539,48 @@ class Manager
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get Input fields of type incidence.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getInputFieldsIncidenceType()
|
||||
{
|
||||
$idIncidenceType = (int) get_parameter('idIncidenceType', true);
|
||||
$fieldsData = json_decode(io_safe_output(get_parameter('fieldsData', [])), true);
|
||||
if (empty($fieldsData) === false) {
|
||||
$fieldsData = array_reduce(
|
||||
$fieldsData,
|
||||
function ($carry, $user) {
|
||||
$carry[$user['idIncidenceField']] = $user['data'];
|
||||
return $carry;
|
||||
}
|
||||
);
|
||||
} else {
|
||||
$fieldsData = [];
|
||||
}
|
||||
|
||||
$error = '';
|
||||
try {
|
||||
$ITSM = new ITSM();
|
||||
$result = $this->getFieldsIncidenceType($ITSM, $idIncidenceType);
|
||||
$customFields = $result['data'];
|
||||
} catch (Throwable $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
View::render(
|
||||
'ITSM/ITSMCustomFields',
|
||||
[
|
||||
'ajaxController' => $this->ajaxController,
|
||||
'urlAjax' => \ui_get_full_url('ajax.php'),
|
||||
'customFields' => $customFields,
|
||||
'fieldsData' => $fieldsData,
|
||||
'error' => $error,
|
||||
]
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -123,3 +123,23 @@ div.integria_details_description textarea {
|
|||
.comment_body {
|
||||
padding: 15px 20px 15px 20px;
|
||||
}
|
||||
|
||||
/*---*/
|
||||
div.incidence-type-custom-fields {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: baseline;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.incidence-type-custom-fields > div {
|
||||
flex: 1 1 45%;
|
||||
display: flex;
|
||||
margin: 0px 20px;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.incidence-type-custom-fields > div.incidence-type-custom-fields-textarea {
|
||||
flex: 1 1 100%;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
<?php
|
||||
/**
|
||||
* ITSM View dashboard
|
||||
*
|
||||
* @category Console Class
|
||||
* @package Pandora FMS
|
||||
* @subpackage ITSM
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2023 Artica Soluciones Tecnologicas
|
||||
* Please see http://pandorafms.org for full contribution list
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation for version 2.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Includes.
|
||||
require_once $config['homedir'].'/include/class/HTML.class.php';
|
||||
|
||||
global $config;
|
||||
|
||||
if (empty($error) === false) {
|
||||
ui_print_error_message($error);
|
||||
}
|
||||
|
||||
if (empty($customFields) === true) {
|
||||
ui_print_info_message(
|
||||
[
|
||||
'no_close' => true,
|
||||
'message' => __('Incidence type not fields'),
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$output = '<div class="incidence-type-custom-fields">';
|
||||
foreach ($customFields as $field) {
|
||||
$options = [
|
||||
'name' => 'custom-fields['.$field['idIncidenceTypeField'].']',
|
||||
'required' => $field['isRequired'],
|
||||
'return' => true,
|
||||
'value' => ($fieldsData[$field['idIncidenceTypeField']] ?? null),
|
||||
];
|
||||
|
||||
$class = '';
|
||||
|
||||
switch ($field['type']) {
|
||||
case 'COMBO':
|
||||
$options['type'] = 'select';
|
||||
$options['fields'] = explode(',', $field['comboValue']);
|
||||
break;
|
||||
|
||||
case 'TEXT':
|
||||
$options['type'] = 'text';
|
||||
break;
|
||||
|
||||
case 'CHECKBOX':
|
||||
$options['type'] = 'checkbox';
|
||||
break;
|
||||
|
||||
case 'DATE':
|
||||
$options['type'] = 'text';
|
||||
break;
|
||||
|
||||
case 'NUMERIC':
|
||||
$options['type'] = 'number';
|
||||
break;
|
||||
|
||||
case 'TEXTAREA':
|
||||
$options['type'] = 'textarea';
|
||||
$options['rows'] = 4;
|
||||
$options['columns'] = 0;
|
||||
$class = 'incidence-type-custom-fields-textarea';
|
||||
break;
|
||||
|
||||
default:
|
||||
// Not posible.
|
||||
break;
|
||||
}
|
||||
|
||||
$output .= html_print_label_input_block(
|
||||
$field['label'],
|
||||
html_print_input($options),
|
||||
['div_class' => $class]
|
||||
);
|
||||
}
|
||||
|
||||
$output .= '</div>';
|
||||
|
||||
echo $output;
|
||||
}
|
|
@ -69,12 +69,10 @@ $table = new stdClass();
|
|||
$table->width = '100%';
|
||||
$table->id = 'edit-ticket-itms';
|
||||
$table->class = 'databox filter-table-adv';
|
||||
$table->head = [];
|
||||
$table->data = [];
|
||||
$table->size = [];
|
||||
$table->size = [];
|
||||
$table->colspan[0][0] = 2;
|
||||
$table->colspan[4][0] = 3;
|
||||
$table->colspan[2][0] = 3;
|
||||
$table->colspan[5][0] = 3;
|
||||
$table->colspan[6][0] = 3;
|
||||
|
||||
$table->data[0][0] = html_print_label_input_block(
|
||||
|
@ -158,7 +156,9 @@ $table->data[1][2] = html_print_label_input_block(
|
|||
)
|
||||
);
|
||||
|
||||
$table->data[2][0] = html_print_label_input_block(
|
||||
$table->data[2][0] = '<div class="object-type-fields">WIP...</div>';
|
||||
|
||||
$table->data[3][0] = html_print_label_input_block(
|
||||
__('Status'),
|
||||
html_print_select(
|
||||
$status,
|
||||
|
@ -176,7 +176,7 @@ $table->data[2][0] = html_print_label_input_block(
|
|||
)
|
||||
);
|
||||
|
||||
$table->data[2][1] = html_print_label_input_block(
|
||||
$table->data[3][1] = html_print_label_input_block(
|
||||
__('Creator').ui_print_help_tip(__('This field corresponds to the Integria IMS user specified in Integria IMS setup'), true),
|
||||
html_print_input_text(
|
||||
'idCreator',
|
||||
|
@ -192,7 +192,7 @@ $table->data[2][1] = html_print_label_input_block(
|
|||
)
|
||||
);
|
||||
|
||||
$table->data[2][2] = html_print_label_input_block(
|
||||
$table->data[3][2] = html_print_label_input_block(
|
||||
__('Owner').ui_print_help_tip(__('Type at least two characters to search the user.'), true),
|
||||
html_print_autocomplete_users_from_integria(
|
||||
'owner',
|
||||
|
@ -205,7 +205,7 @@ $table->data[2][2] = html_print_label_input_block(
|
|||
)
|
||||
);
|
||||
|
||||
$table->data[3][0] = '<div id="incidence-resolution" class="invisible">'.html_print_label_input_block(
|
||||
$table->data[4][0] = '<div id="incidence-resolution" class="invisible">'.html_print_label_input_block(
|
||||
__('Resolution'),
|
||||
html_print_select(
|
||||
$resolutions,
|
||||
|
@ -223,7 +223,7 @@ $table->data[3][0] = '<div id="incidence-resolution" class="invisible">'.html_pr
|
|||
).'</div>'
|
||||
);
|
||||
|
||||
$table->data[4][0] = html_print_label_input_block(
|
||||
$table->data[5][0] = html_print_label_input_block(
|
||||
__('Description').$help_macros,
|
||||
html_print_textarea(
|
||||
'description',
|
||||
|
@ -283,6 +283,9 @@ echo '</form>';
|
|||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
var ajax_url = '<?php echo ui_get_full_url('ajax.php'); ?>';
|
||||
var fieldsData = '<?php echo json_encode($incidence['typeFieldData']); ?>';
|
||||
|
||||
$('#status').on('change', function() {
|
||||
if ($(this).val() === 'CLOSED') {
|
||||
$('#incidence-resolution').show();
|
||||
|
@ -290,5 +293,18 @@ echo '</form>';
|
|||
$('#incidence-resolution').hide();
|
||||
}
|
||||
}).trigger('change');
|
||||
|
||||
$('#idIncidenceType').on('change', function() {
|
||||
if ($(this).val() != 0) {
|
||||
$('.object-type-fields').show();
|
||||
var output = getInputFieldsIncidenceType(
|
||||
$(this).val(),
|
||||
fieldsData,
|
||||
ajax_url
|
||||
);
|
||||
} else {
|
||||
$('.object-type-fields').hide();
|
||||
}
|
||||
}).trigger('change');
|
||||
});
|
||||
</script>
|
Loading…
Reference in New Issue