From 322544c7fb0746c85934e21d232845f7f38971e6 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Mon, 14 Oct 2024 11:20:46 +0200 Subject: [PATCH] dynamic image url for searchresults --- application/config/search.php | 15 ++++++++++++--- application/libraries/SearchBarLib.php | 1 - .../components/searchbar/result/mergedperson.js | 12 ++++-------- public/js/components/searchbar/result/person.js | 9 +-------- .../js/components/searchbar/result/prestudent.js | 9 +-------- public/js/components/searchbar/result/student.js | 9 +-------- 6 files changed, 19 insertions(+), 36 deletions(-) diff --git a/application/config/search.php b/application/config/search.php index ac6189527..14b6e89d8 100644 --- a/application/config/search.php +++ b/application/config/search.php @@ -74,7 +74,10 @@ $config['person'] = [ "p.person_id", "(p.vorname || ' ' || p.nachname) AS name", "ARRAY( SELECT kontakt FROM public.tbl_kontakt WHERE kontakttyp = 'email' AND person_id=p.person_id ) AS email", - "p.foto" + "CASE + WHEN p.foto IS NOT NULL THEN 'data:image/jpeg' || CONVERT_FROM(DECODE('3b','hex'), 'UTF8') || 'base64,' || p.foto + ELSE NULL END + AS photo_url" ], 'resultjoin' => " JOIN public.tbl_person p USING (person_id) @@ -200,7 +203,10 @@ $config['student'] = [ "p.person_id", "(p.vorname || ' ' || p.nachname) AS name", "ARRAY( SELECT kontakt FROM public.tbl_kontakt WHERE kontakttyp = 'email' AND person_id=p.person_id ) AS email", - "p.foto" + "CASE + WHEN p.foto IS NOT NULL THEN 'data:image/jpeg' || CONVERT_FROM(DECODE('3b','hex'), 'UTF8') || 'base64,' || p.foto + ELSE NULL END + AS photo_url" ], 'resultjoin' => " JOIN public.tbl_student s USING (student_uid) @@ -298,7 +304,10 @@ $config['prestudent'] = [ "b.uid", "(p.vorname || ' ' || p.nachname) AS name", "ARRAY( SELECT kontakt FROM public.tbl_kontakt WHERE kontakttyp = 'email' AND person_id=p.person_id ) AS email", - "p.foto", + "CASE + WHEN p.foto IS NOT NULL THEN 'data:image/jpeg' || CONVERT_FROM(DECODE('3b','hex'), 'UTF8') || 'base64,' || p.foto + ELSE NULL END + AS photo_url", "UPPER(sg.typ || sg.kurzbz) AS stg_kuerzel", "sg.bezeichnung", "( diff --git a/application/libraries/SearchBarLib.php b/application/libraries/SearchBarLib.php index 6547cd107..c3528978d 100644 --- a/application/libraries/SearchBarLib.php +++ b/application/libraries/SearchBarLib.php @@ -228,7 +228,6 @@ class SearchBarLib GROUP BY " . $table_config['primarykey'] . " )"; - $other_selects = $selects[] = " SELECT " . $this->_ci->db->escape($type) . " AS type, diff --git a/public/js/components/searchbar/result/mergedperson.js b/public/js/components/searchbar/result/mergedperson.js index f6b07f3d2..09b967b2f 100644 --- a/public/js/components/searchbar/result/mergedperson.js +++ b/public/js/components/searchbar/result/mergedperson.js @@ -20,8 +20,9 @@ export default { if (person.length) return person.pop(); - const { person_id, name, foto, photo_url, email } = this.res.list[0]; - return { person_id, name, foto, photo_url, email }; + // TODO(chris): first one might have not one of these but a later one + const { person_id, name, photo_url, email } = this.res.list[0]; + return { person_id, name, photo_url, email }; }, employee() { const ma = this.res.list.filter(item => [ @@ -34,11 +35,6 @@ export default { const students = this.res.list.filter(item => item.type == 'prestudent'); return students.length ? students : null; }, - foto() { - if (this.person.foto) - return 'data:image/jpeg;base64,' + this.person.foto; - return this.person.photo_url; - }, emails() { if (Array.isArray(this.person.email)) return this.person.email; @@ -51,7 +47,7 @@ export default { :res="person" :actions="actions" :title="person.name" - :image="foto" + :image="this.person.photo_url" image-fallback="fas fa-user-circle fa-7x" @actionexecuted="$emit('actionexecuted')" > diff --git a/public/js/components/searchbar/result/person.js b/public/js/components/searchbar/result/person.js index f8adee56e..65155a95f 100644 --- a/public/js/components/searchbar/result/person.js +++ b/public/js/components/searchbar/result/person.js @@ -9,20 +9,13 @@ export default { res: Object, actions: Object }, - computed: { - foto() { - if (this.res.foto) - return 'data:image/jpeg;base64,' + this.res.foto; - return null; - } - }, template: ` diff --git a/public/js/components/searchbar/result/prestudent.js b/public/js/components/searchbar/result/prestudent.js index 8c174d3c0..662069b75 100644 --- a/public/js/components/searchbar/result/prestudent.js +++ b/public/js/components/searchbar/result/prestudent.js @@ -9,20 +9,13 @@ export default { res: Object, actions: Object }, - computed: { - foto() { - if (this.res.foto) - return 'data:image/jpeg;base64,' + this.res.foto; - return null; - } - }, template: ` diff --git a/public/js/components/searchbar/result/student.js b/public/js/components/searchbar/result/student.js index 8d8c4894b..93033d08b 100644 --- a/public/js/components/searchbar/result/student.js +++ b/public/js/components/searchbar/result/student.js @@ -9,20 +9,13 @@ export default { res: Object, actions: Object }, - computed: { - foto() { - if (this.res.foto) - return 'data:image/jpeg;base64,' + this.res.foto; - return null; - } - }, template: `