S 6 - Adding a config menu for ticket types
This commit is contained in:
parent
250365c483
commit
49c25ffa46
113
config_menu.php
113
config_menu.php
|
|
@ -41,17 +41,80 @@ function kft_bug_reporter_config_page() {
|
|||
|
||||
document.addEventListener("DOMContentLoaded", async function(event) {
|
||||
// Get the configuration of the Kalifast API
|
||||
let config_data = await requestCore("Kalifast_Bug_Reporter", "Reporter", "get_kalifast_api_configuration");
|
||||
if(config_data.success) {
|
||||
document.getElementById("kft_bug_reporter_url").value = config_data.data.kft_api_host;
|
||||
document.getElementById("kft_bug_reporter_api_key").value = config_data.data.kft_api_key;
|
||||
document.querySelector(".kft_status").src = "https://kalifast.com/assets/img/devices_enable.png";
|
||||
}
|
||||
reloadFields()
|
||||
|
||||
|
||||
document.getElementById("submit_kft_bug_reporter_ticket_config").addEventListener("click", async function() {
|
||||
let response = await requestCore("Kalifast_Bug_Reporter", "Reporter", "set_kalifast_ticket_config", {
|
||||
"ei_pool_id": document.getElementById("kft_bug_reporter_pool").value,
|
||||
"ei_delivery_id": document.getElementById("kft_bug_reporter_delivery").value,
|
||||
"ei_user_id": document.getElementById("kft_bug_reporter_user").value
|
||||
});
|
||||
});
|
||||
|
||||
// Set the configuration of the Kalifast API in the form
|
||||
document.getElementById("submit_kft_bug_reporter_config").addEventListener("click", submitConfigAPIForm);
|
||||
});
|
||||
|
||||
|
||||
async function reloadFields() {
|
||||
let config_data = await requestCore("Kalifast_Bug_Reporter", "Reporter", "get_kalifast_api_configuration");
|
||||
if(config_data.success) {
|
||||
document.getElementById("kft_bug_reporter_url").value = config_data.data.api_config.kft_api_host;
|
||||
document.getElementById("kft_bug_reporter_api_key").value = config_data.data.api_config.kft_api_key;
|
||||
if(config_data.data.fields.deliveries && config_data.data.fields.pools && config_data.data.fields.users) {
|
||||
document.querySelector(".kft_status").src = "https://kalifast.com/assets/img/devices_enable.png";
|
||||
} else {
|
||||
document.querySelector(".kft_status").src = "https://kalifast.com/assets/img/devices_not_connected.png";
|
||||
}
|
||||
|
||||
console.log(config_data);
|
||||
|
||||
|
||||
|
||||
// Set the pools
|
||||
let poolSelect = document.getElementById("kft_bug_reporter_pool");
|
||||
poolSelect.innerHTML = "";
|
||||
config_data.data.fields.pools.forEach(pool => {
|
||||
let option = document.createElement("option");
|
||||
option.value = pool.ei_pool_id;
|
||||
option.text = pool.pool_name;
|
||||
poolSelect.appendChild(option);
|
||||
});
|
||||
if(config_data.data.ticket_config) {
|
||||
poolSelect.value = config_data.data.ticket_config.ei_pool_id;
|
||||
}
|
||||
|
||||
// Set the deliveries
|
||||
let deliverySelect = document.getElementById("kft_bug_reporter_delivery");
|
||||
deliverySelect.innerHTML = "";
|
||||
config_data.data.fields.deliveries.forEach(delivery => {
|
||||
let option = document.createElement("option");
|
||||
option.value = delivery.ei_delivery_id;
|
||||
option.text = delivery.delivery_name;
|
||||
deliverySelect.appendChild(option);
|
||||
});
|
||||
if(config_data.data.ticket_config) {
|
||||
deliverySelect.value = config_data.data.ticket_config.ei_delivery_id;
|
||||
}
|
||||
|
||||
// Set the users
|
||||
let userSelect = document.getElementById("kft_bug_reporter_user");
|
||||
userSelect.innerHTML = "";
|
||||
config_data.data.fields.users.forEach(user => {
|
||||
let option = document.createElement("option");
|
||||
option.value = user.ei_user_id;
|
||||
option.text = user.username;
|
||||
userSelect.appendChild(option);
|
||||
});
|
||||
if(config_data.data.ticket_config) {
|
||||
userSelect.value = config_data.data.ticket_config.ei_user_id;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Config API form behavior
|
||||
async function submitConfigAPIForm() {
|
||||
console.log("Form submitted");
|
||||
|
|
@ -59,11 +122,9 @@ function kft_bug_reporter_config_page() {
|
|||
"kft_api_host": document.getElementById("kft_bug_reporter_url").value,
|
||||
"kft_api_key": document.getElementById("kft_bug_reporter_api_key").value,
|
||||
});
|
||||
console.log(response);
|
||||
|
||||
if(response.success) {
|
||||
document.querySelector(".kft_status").src = "https://kalifast.com/assets/img/devices_enable.png";
|
||||
} else {
|
||||
document.querySelector(".kft_status").src = "https://kalifast.com/assets/img/devices_not_connected.png";
|
||||
reloadFields();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
@ -71,11 +132,11 @@ function kft_bug_reporter_config_page() {
|
|||
<div class="wrap">
|
||||
<h2>KFT-Bug-Reporter configuration</h2>
|
||||
<div id="kft-bug-reporter-config-api-form" class="kft-bug-reporter-config-form" >
|
||||
<h3><img class="kft_status" src="https://kalifast.com/assets/img/devices_not_connected.png" alt="Kalifast logo"> API Configuration </h3>
|
||||
<table>
|
||||
<tr>
|
||||
<!-- URL of the Kalifast APP -->
|
||||
|
||||
<td>Host of the Kalifast App</td>
|
||||
<td>Host of the Kalifast App </td>
|
||||
<td><input type="text" id="kft_bug_reporter_url" value=""></td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
|
@ -86,13 +147,39 @@ function kft_bug_reporter_config_page() {
|
|||
<tr>
|
||||
<td>
|
||||
<input type="submit" value="Save" id="submit_kft_bug_reporter_config" >
|
||||
<img class="kft_status" src="https://kalifast.com/assets/img/devices_not_connected.png" alt="Kalifast logo">
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="kft-bug-reporter-config-api-form" class="kft-bug-reporter-config-form" >
|
||||
<h3> Tickets configuration </h3>
|
||||
<table>
|
||||
<tr>
|
||||
<td>Pool</td>
|
||||
<td><select id="kft_bug_reporter_pool" value=""></select></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Delivery</td>
|
||||
<td><select id="kft_bug_reporter_delivery" value=""></select></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>User</td>
|
||||
<td><select id="kft_bug_reporter_user" value=""></select></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<input type="submit" value="Save" id="submit_kft_bug_reporter_ticket_config" >
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
Hyper Icon
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ function init_kalifast_bug_reporter_database() {
|
|||
// Open new PDO
|
||||
$PDO = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASSWORD);
|
||||
|
||||
// Create the table
|
||||
// Create the table API config
|
||||
$PDO->exec('CREATE TABLE IF NOT EXISTS `kalifast_bug_reporter_config` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
|
@ -50,6 +50,20 @@ function init_kalifast_bug_reporter_database() {
|
|||
`kft_api_key` varchar(255) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
)');
|
||||
|
||||
// ticket config
|
||||
$PDO->exec('CREATE TABLE IF NOT EXISTS `kalifast_bug_reporter_config_ticket` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`last_update` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`ei_pool_id` varchar(255) NOT NULL,
|
||||
`ei_delivery_id` varchar(255) NOT NULL,
|
||||
`ei_user_id` varchar(255) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
)');
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* Function to uninstall database tables */
|
||||
|
|
@ -59,13 +73,14 @@ function uninstall_kalifast_bug_reporter_database() {
|
|||
|
||||
// Drop the table
|
||||
$PDO->exec('DROP TABLE IF EXISTS `kalifast_bug_reporter_config`');
|
||||
$PDO->exec('DROP TABLE IF EXISTS `kalifast_bug_reporter_config_ticket`');
|
||||
}
|
||||
|
||||
|
||||
/* Unregister the module */
|
||||
function uninstall_kalifast_bug_reporter() {
|
||||
$instance = new EISGE_Module_Core();
|
||||
$instance->moduleUninstall(array('application' => 'eisge_api', 'module'=>'Kalifast-Bug-Reporter'));
|
||||
$instance->moduleUninstall(array('application' => 'eisge_api', 'module'=>'Kalifast_Bug_Reporter'));
|
||||
|
||||
// uninstall_kalifast_bug_reporter_database();
|
||||
}
|
||||
|
|
|
|||
128
reporter.php
128
reporter.php
|
|
@ -52,7 +52,29 @@ class Reporter extends EISGE_Library_Core {
|
|||
"description" => "API Key of the Kalifast App"
|
||||
),
|
||||
)
|
||||
),
|
||||
"set_kalifast_ticket_config" => array(
|
||||
"mode" => "EDIT",
|
||||
"guest_mod" => false,
|
||||
"desc" => "Set the Kalifast ticket configuration",
|
||||
"args" => array(
|
||||
array(
|
||||
"name" => "ei_pool_id",
|
||||
"type" => "string",
|
||||
"description" => "Pool ID of the Kalifast App"
|
||||
),
|
||||
array(
|
||||
"name" => "ei_delivery_id",
|
||||
"type" => "string",
|
||||
"description" => "Delivery ID of the Kalifast App"
|
||||
),
|
||||
array(
|
||||
"name" => "ei_user_id",
|
||||
"type" => "string",
|
||||
"description" => "User ID of the Kalifast App"
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
|
|
@ -80,25 +102,124 @@ class Reporter extends EISGE_Library_Core {
|
|||
}
|
||||
|
||||
|
||||
public function set_kalifast_ticket_config(){
|
||||
|
||||
/* Check the parameters */
|
||||
$parameters = $this->checkArguments($this->dataIn,
|
||||
array(
|
||||
"ei_pool_id" => "string",
|
||||
"ei_delivery_id" => "string",
|
||||
"ei_user_id" => "string"
|
||||
)
|
||||
);
|
||||
if (!$parameters) {
|
||||
return $this->functionFailed("parameters", "Syntax error on parameters!");
|
||||
}
|
||||
|
||||
// Insert the data into the database
|
||||
try {
|
||||
$stmt = $this->PDO->prepare("DELETE FROM kalifast_bug_reporter_config_ticket");
|
||||
|
||||
$stmt = $this->PDO->prepare("INSERT INTO kalifast_bug_reporter_config_ticket (ei_pool_id, ei_delivery_id, ei_user_id) VALUES (:ei_pool_id, :ei_delivery_id, :ei_user_id)");
|
||||
$stmt->bindParam(':ei_pool_id', $parameters["ei_pool_id"]);
|
||||
$stmt->bindParam(':ei_delivery_id', $parameters["ei_delivery_id"]);
|
||||
$stmt->bindParam(':ei_user_id', $parameters["ei_user_id"]);
|
||||
$stmt->execute();
|
||||
return $this->functionSuccess("Kalifast ticket data inserted into the database");
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_log($e->getMessage());
|
||||
return $this->functionFailed("database_error", "Error while inserting kalifast ticket data the database");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function call_kft_app($url, $key, $host, $map_fields) {
|
||||
$url = $host."/api/".$key."/".$url;
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$response = json_decode(curl_exec($ch), true);
|
||||
curl_close($ch);
|
||||
|
||||
if($response["success"]) {
|
||||
$response["data"] = array_map(function($item) use ($map_fields) {
|
||||
$new_item = array();
|
||||
foreach($map_fields as $field) {
|
||||
$new_item[$field] = $item[$field];
|
||||
}
|
||||
return $new_item;
|
||||
}, $response["data"]);
|
||||
return $response["data"];
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called when the user wants to get the Kalifast API host and key
|
||||
*/
|
||||
public function get_kalifast_api_configuration(){
|
||||
|
||||
$api_config = array();
|
||||
try {
|
||||
$stmt = $this->PDO->prepare("SELECT kft_api_host, kft_api_key FROM kalifast_bug_reporter_config ORDER BY last_update DESC LIMIT 1");
|
||||
$stmt->execute();
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if($row) {
|
||||
return $this->functionSuccess($row);
|
||||
}
|
||||
$api_config = $row;
|
||||
} else {
|
||||
return $this->functionFailed("no_data", "No data found in the database");
|
||||
}
|
||||
|
||||
|
||||
$stmt = $this->PDO->prepare("SELECT ei_pool_id, ei_delivery_id, ei_user_id FROM kalifast_bug_reporter_config_ticket ORDER BY last_update DESC LIMIT 1");
|
||||
$stmt->execute();
|
||||
$ticket_config = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_log($e->getMessage());
|
||||
return $this->functionFailed("database_error", "Error while getting kalifast API data from the database");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// SUBJECT/MAIN/DISPLAY/CORE/GETPOOLLIST
|
||||
$url = $api_config["kft_api_host"]."/api/".$api_config["kft_api_key"]."/SUBJECT/MAIN/DISPLAY/CORE/GETPOOLLIST";
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$poolList = json_decode(curl_exec($ch), true);
|
||||
curl_close($ch);
|
||||
|
||||
if($poolList["success"]) {
|
||||
$poolList["data"] = array_map(function($pool) {
|
||||
return array(
|
||||
"ei_pool_id" => $pool["ei_pool_id"],
|
||||
"pool_name" => $pool["pool_name"]
|
||||
);
|
||||
}, $poolList["data"]);
|
||||
$poolList = $poolList["data"];
|
||||
} else {
|
||||
$poolList = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return $this->functionSuccess(array(
|
||||
"api_config" => $api_config,
|
||||
"ticket_config" => $ticket_config,
|
||||
"fields" => array(
|
||||
"pools" => $this->call_kft_app("SUBJECT/MAIN/DISPLAY/CORE/GETPOOLLIST", $api_config["kft_api_key"], $api_config["kft_api_host"], array("ei_pool_id", "pool_name")),
|
||||
"deliveries" => $this->call_kft_app("SUBJECT/MAIN/DISPLAY/CORE/GETDELIVERYLISTFORSUBJECT", $api_config["kft_api_key"], $api_config["kft_api_host"], array("ei_delivery_id", "delivery_name")),
|
||||
"users" => $this->call_kft_app("SUBJECT/MAIN/DISPLAY/CORE/GETUSERLIST", $api_config["kft_api_key"], $api_config["kft_api_host"], array("username", "ei_user_id"))
|
||||
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -135,3 +256,4 @@ class Reporter extends EISGE_Library_Core {
|
|||
|
||||
}
|
||||
}
|
||||
Hyper Icon
|
||||
Loading…
Reference in New Issue
Block a user