issues: added vue component for displaying issues in a table

This commit is contained in:
Alexei Karpenko
2025-11-26 16:28:16 +01:00
parent a24483188b
commit 733a6a8c15
4 changed files with 274 additions and 37 deletions
@@ -0,0 +1,56 @@
<?php
defined('BASEPATH') || exit('No direct script access allowed');
class Issues extends FHCAPI_Controller
{
const DEFAULT_PERMISSION = 'system/issues_verwalten:r';
// code igniter
protected $CI;
public function __construct() {
parent::__construct(
array(
'getOpenIssuesByProperties' => Self::DEFAULT_PERMISSION
)
);
// Loads authentication library and starts authenticationfetc
$this->load->library('AuthLib');
$this->load->model('extensions/FHC-Core-Personalverwaltung/Api_model','ApiModel');
$this->load->model('person/Person_model','PersonModel');
$this->load->model('system/Fehler_model','FehlerModel');
$this->load->model('system/Issue_model', 'IssueModel');
$this->load->model('person/Benutzer_model', 'BenutzerModel');
// get CI for transaction management
$this->CI = &get_instance();
}
public function getOpenIssuesByProperties()
{
$person_id = $this->input->get('person_id', true);
$oe_kurzbz = $this->input->get('oe_kurzbz', true);
$fehlertyp_kurzbz = $this->input->get('fehlertyp_kurzbz', true);
$apps = $this->input->get('apps', true);
$behebung_parameter = $this->input->get('behebung_parameter', true);
if (isset($person_id) && !is_numeric($person_id))
$this->terminateWithError('person id is not numeric!');
if (isset($behebung_parameter) && !is_array($behebung_parameter))
$this->terminateWithError('Behebung parameter invalid');
$issueRes = $this->IssueModel->getOpenIssuesByProperties($person_id, $oe_kurzbz, $fehlertyp_kurzbz, $apps, $behebung_parameter);
if (isError($issueRes))
{
$this->terminateWithError(getError($issueRes));
}
$this->terminateWithSuccess(hasData($issueRes) ? getData($issueRes) : []);
}
}
+127 -37
View File
@@ -22,43 +22,17 @@ class Issue_model extends DB_Model
*/
public function getOpenIssues($fehlercodes, $person_id = null, $oe_kurzbz = null, $fehlercode_extern = null)
{
$params = array();
// issue exists for a fehlercode (or fehlercode_extern), person_id, oe_kurzbz, if not verarbeitet yet
$qry = 'SELECT
iss.issue_id, iss.fehlercode, fe.fehler_kurzbz, iss.inhalt, iss.fehlercode_extern,
iss.inhalt_extern, iss.person_id, iss.oe_kurzbz, iss.behebung_parameter,
iss.datum, iss.verarbeitetvon, iss.verarbeitetamum
FROM
system.tbl_issue iss
JOIN system.tbl_fehler fe USING (fehlercode)
WHERE
verarbeitetamum IS NULL';
if (!isEmptyArray($fehlercodes))
{
$qry .= ' AND fehlercode IN ?';
$params[] = $fehlercodes;
}
if (!isEmptyString($fehlercode_extern))
{
$qry .= ' AND fehlercode_extern = ?';
$params[] = $fehlercode_extern;
}
if (isset($person_id))
{
$qry .= ' AND person_id = ?';
$params[] = $person_id;
}
if (isset($oe_kurzbz))
{
$qry .= ' AND oe_kurzbz = ?';
$params[] = $oe_kurzbz;
}
return $this->execQuery($qry, $params);
return $this->_getIssues(
$person_id,
$oe_kurzbz,
$fehlertyp_kurzbz = null,
$apps = null,
$ist_verarbeitet = false,
$behebung_parameter = null,
$fehlercodes,
$fehlercode_extern
);
}
/**
@@ -83,7 +57,7 @@ class Issue_model extends DB_Model
$params[] = $fehlercode_extern;
}
if (isset($person_id))
if (isset($person_id) && is_numeric($person_id))
{
$qry .= ' AND person_id = ?';
$params[] = $person_id;
@@ -110,4 +84,120 @@ class Issue_model extends DB_Model
return $this->execQuery($qry, $params);
}
/**
* Gets issues which are open, i.e. not resolved.
* @param int $person_id
* @param string $oe_kurzbz
* @param string $fehlertyp_kurzbz
* @param string|array $apps
* @param array $behebung_parameter
* @return object success with issues or error
*/
public function getOpenIssuesByProperties(
$person_id = null,
$oe_kurzbz = null,
$fehlertyp_kurzbz = null,
$apps = null,
$behebung_parameter = null
) {
return $this->_getIssues($person_id, $oe_kurzbz, $fehlertyp_kurzbz, $apps, $ist_verarbeitet = false, $behebung_parameter);
}
/**
* Gets issues which are open, i.e. not resolved.
* @param int $person_id
* @param string $oe_kurzbz
* @param string $fehlertyp_kurzbz
* @param array $apps only issues for given apps are retrieved
* @param bool $ist_verarbeitet wether the issue has already been resolved
* @param array $behebung_parameter
* @param array $fehlercodes
* @param string $fehlercode_extern
* @return object success with issues or error
*/
private function _getIssues(
$person_id = null,
$oe_kurzbz = null,
$fehlertyp_kurzbz = null,
$apps = null,
$ist_verarbeitet = null,
$behebung_parameter = null,
$fehlercodes = null,
$fehlercode_extern = null
) {
$params = array();
$qry = 'SELECT
iss.issue_id, iss.fehlercode, fe.fehler_kurzbz, iss.inhalt, iss.fehlercode_extern,
iss.inhalt_extern, iss.person_id, iss.oe_kurzbz, iss.behebung_parameter,
iss.datum, iss.verarbeitetvon, iss.verarbeitetamum
FROM
system.tbl_issue iss
JOIN system.tbl_fehler fe USING (fehlercode)
WHERE
TRUE';
if (isset($person_id) && is_numeric($person_id))
{
$qry .= ' AND person_id = ?';
$params[] = $person_id;
}
if (isset($oe_kurzbz))
{
$qry .= ' AND oe_kurzbz = ?';
$params[] = $oe_kurzbz;
}
if (isset($fehlertyp_kurzbz))
{
$qry .= ' AND fehlertyp_kurzbz = ?';
$params[] = $fehlertyp_kurzbz;
}
if (isset($apps))
{
if (is_string($apps)) $apps = [$apps];
if (is_array($apps))
{
$qry .= ' AND app IN ?';
$params[] = $apps;
}
}
if (is_bool($ist_verarbeitet))
{
$qry .= $ist_verarbeitet ? ' AND verarbeitetamum IS NOT NULL' : ' AND verarbeitetamum IS NULL';
}
if (!isEmptyArray($behebung_parameter))
{
// convert array to JSON string for postgres
$behebung_parameter_string = json_encode($behebung_parameter);
if ($behebung_parameter_string)
{
// check if jsonb value is equal to the passed parameters array (if value contains array and array contains value)
$qry .= ' AND behebung_parameter @> ? AND behebung_parameter <@ ?';
$params = array_merge($params, array($behebung_parameter_string, $behebung_parameter_string));
}
}
if (!isEmptyArray($fehlercodes))
{
$qry .= ' AND fehlercode IN ?';
$params[] = $fehlercodes;
}
if (isset($fehlercode_extern))
{
$qry .= ' AND fehlercode_extern = ?';
$params[] = $fehlercode_extern;
}
return $this->execQuery($qry, $params);
}
}
+12
View File
@@ -0,0 +1,12 @@
export default {
getOpenIssuesByProperties(person_id, oe_kurzbz, fehlertyp_kurzbz, apps, behebung_parameter)
{
return {
method: 'get',
url: '/api/frontend/v1/Issues/getOpenIssuesByProperties',
params: { person_id, oe_kurzbz, fehlertyp_kurzbz, apps, behebung_parameter }
};
}
}
+79
View File
@@ -0,0 +1,79 @@
import ApiIssues from '../../api/factory/issues.js';
export default {
name: 'IssueList',
emits: ['issuesLoaded'],
components: {
},
props: {
person_id: Number,
oe_kurzbz: String,
fehlertyp_kurzbz: String,
apps: [String, Array],
behebung_parameter: Array,
date: null
},
data() {
return {
title: "Issues",
currentDate: null,
isFetching: false,
issues: null
}
},
computed: {
// if any property changes, get issues again
propertiesChanged() {
return `${this.person_id}|${this.oe_kurzbz}|${this.fehlertyp_kurzbz}||${this.apps}|${this.behebung_parameter}`;
},
},
watch: {
propertiesChanged(newVal, oldVal) {
this.fetchIssues();
},
},
mounted() {
//this.currentDate = props.date || new Date();
this.currentDate = new Date();
console.log("created in list");
this.fetchIssues();
},
methods: {
fetchIssues() {
this.isFetching = true;
this.$api.call(
ApiIssues.getOpenIssuesByProperties(this.person_id, this.oe_kurzbz, this.fehlertyp_kurzbz, this.apps, this.behebung_parameter)
)
.then(result => {
this.issues = result.data;
this.$emit('issuesLoaded', this.issues);
this.isFetching = false;
})
.catch(this.$fhcAlert.handleSystemError);
},
formatDate(ds) {
if (ds == undefined) return '';
var d = new Date(ds);
return d.getDate() + "." + (d.getMonth()+1) + "." + d.getFullYear()
}
},
template: `
<div v-if="isFetching" class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
<div v-if="!isFetching && issues!=null && issues!=[]">
<table class="table table-bordered">
<tbody>
<tr><th>Datum</th><th>Inhalt</th></tr>
<tr v-for="(item, index) in issues" :key="item.issue_id">
<td>{{ formatDate(item.datum) }}</td>
<td>{{ item.inhalt }} <br>
<slot name="additionalText" v-bind="item"></slot>
</td>
</tr>
</tbody>
</table>
</div>
`
}