update(Sprachen.js): shows the sprachen in the component always using their bezeichnung

This commit is contained in:
SimonGschnell
2024-12-12 14:46:32 +01:00
parent 7bd9129056
commit 8f07bd6b4d
2 changed files with 21 additions and 4 deletions
@@ -73,11 +73,22 @@ class Phrasen extends FHCAPI_Controller
// gets all languages that are set as active in the database
public function getAllLanguages()
{
$langs = getDBActiveLanguages();
$this->load->model('system/Sprache_model', 'SprachenModel');
// Add order clause by index and select the sprache,bezeichnung and index column
$this->SprachenModel->addOrder('index');
$this->SprachenModel->addSelect('sprache, bezeichnung, index');
// Retrieves from public.tbl_sprache
$langs = $this->SprachenModel->loadWhere(array('content' => true));
$langs = $this->getDataOrTerminateWithError($langs);
$langs = array_map(function($lang){
return $lang->sprache;
$data = new stdClass();
$data->sprache = $lang->sprache;
$data->bezeichnung = $lang->bezeichnung[($lang->index-1)];
return $data;
}, $langs);
$this->terminateWithSuccess($langs);
}
+8 -2
View File
@@ -2,6 +2,7 @@ export default {
data(){
return {
allActiveLanguages: null,
sprachenTranslation:null,
}
},
methods:{
@@ -11,20 +12,25 @@ export default {
this.$p.setLanguage(lang, this.$fhcApi);
}
},
getSprachenBezeichnung: function(lang){
if (!Array.isArray(this.sprachenTranslation) || this.sprachenTranslation.length == 0) return;
return this.sprachenTranslation.find(s=>s.sprache == lang)?.bezeichnung;
},
},
mounted(){
this.$fhcApi.factory.phrasen.getActiveDbLanguages()
.then(res => res.data)
.then(
(langs) => {
this.allActiveLanguages = langs;
this.allActiveLanguages = langs.map(l=>l.sprache);
this.sprachenTranslation = langs;
}
);
},
template:/*html*/`
<div class="container">
<div class="row justify-content-center align-items-center flex-nowrap overflow-hidden">
<button v-for="lang in allActiveLanguages" @click.prevent="changeLanguage(lang)" class="col text-white fhc-entry btn text-center w-100" :selected="$p.user_language.value==lang?'':null">{{lang}}</button>
<button v-for="lang in allActiveLanguages" @click.prevent="changeLanguage(lang)" class="col text-white fhc-entry btn text-center w-100" :selected="$p.user_language.value==lang?'':null">{{getSprachenBezeichnung(lang)}}</button>
</div>
</div>
`,