diff --git a/application/controllers/api/frontend/v1/Issues.php b/application/controllers/api/frontend/v1/Issues.php new file mode 100644 index 000000000..2e63ffeb1 --- /dev/null +++ b/application/controllers/api/frontend/v1/Issues.php @@ -0,0 +1,56 @@ + 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) : []); + } +} \ No newline at end of file diff --git a/application/models/system/Issue_model.php b/application/models/system/Issue_model.php index 331b0f050..cafb869e2 100644 --- a/application/models/system/Issue_model.php +++ b/application/models/system/Issue_model.php @@ -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); + } } diff --git a/public/js/api/factory/issues.js b/public/js/api/factory/issues.js new file mode 100644 index 000000000..376845897 --- /dev/null +++ b/public/js/api/factory/issues.js @@ -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 } + }; + } + +} \ No newline at end of file diff --git a/public/js/components/Issues/IssueList.js b/public/js/components/Issues/IssueList.js new file mode 100644 index 000000000..e70fa7831 --- /dev/null +++ b/public/js/components/Issues/IssueList.js @@ -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: ` +
+ Loading... +
+
+ + + + + + + + +
DatumInhalt
{{ formatDate(item.datum) }}{{ item.inhalt }}
+ +
+
+ ` +}