separate endpoint for generic tabulator phrases with cacheable response

This commit is contained in:
adisposkofh
2026-05-19 16:27:54 +02:00
parent 4e5bf94a15
commit 239eaa90e9
3 changed files with 73 additions and 47 deletions
@@ -32,7 +32,8 @@ class Phrasen extends FHCAPI_Controller
'setLanguage' => self::PERM_ANONYMOUS,
'getLanguage' => self::PERM_ANONYMOUS,
'getAllLanguages' => self::PERM_ANONYMOUS,
'getPhrases' => self::PERM_ANONYMOUS
'getPhrases' => self::PERM_ANONYMOUS,
'getTabulatorPhrases' => self::PERM_ANONYMOUS,
]);
$this->load->helper('hlp_language');
@@ -119,4 +120,31 @@ class Phrasen extends FHCAPI_Controller
$this->terminateWithSuccess($result);
}
public function getTabulatorPhrases()
{
$languages = json_decode($this->input->get('languages'));
if (!$languages || !count($languages)) {
$this->load->model('system/Sprache_model', 'sprachenModel');
$activeLanguages = $this->sprachenModel->loadWhere(array('content' => true));
$activeLanguagesData = $this->getDataOrTerminateWithError($activeLanguages);
$languages = array_map(
function ($languageData) {
return $languageData->sprache;
},
$activeLanguagesData
);
}
$this->load->model('system/Phrase_model', 'phraseModel');
$result = [];
foreach ($languages as $language) {
$tabulatorPhrases = $this->phraseModel->getPhrasesByCategoryAndLanguage(['tabulator'], $language);
$result[$language] = $this->getDataOrTerminateWithError($tabulatorPhrases);
}
header('Pragma: private');
header('Cache-Control: private, max-age=' . (60 * 60 * 24 * 30));
$this->terminateWithSuccess($result);
}
}
+9
View File
@@ -52,4 +52,13 @@ export default {
},
};
},
getTabulatorPhrases(languages = []) {
return {
method: 'get',
url: '/api/frontend/v1/phrasen/getTabulatorPhrases',
params: {
languages: JSON.stringify(languages),
},
};
},
};
+35 -46
View File
@@ -373,54 +373,14 @@ export const CoreFilterCmpt = {
tabulatorOptions.locale = this.$p.user_language.value;
tabulatorOptions.langs = {};
let phrasesGroupedByCategoryRequestParam = {
tabulator: [
"loading",
"error",
"item",
"items",
"page_size",
"page_title",
"first",
"first_title",
"last",
"last_title",
"prev",
"prev_title",
"next",
"next_title",
"all",
"showing",
"of",
"rows",
"pages",
],
};
tabulatorOptions.columns.forEach((column) => {
if (column.field === "collapse") return;
let [category, phrase] = column.title.split("/");
if (phrasesGroupedByCategoryRequestParam[category]) {
phrasesGroupedByCategoryRequestParam[category].push(phrase);
} else {
phrasesGroupedByCategoryRequestParam[category] = [phrase];
}
});
const phrasesResponse = await this.$api.call(
ApiPhrases.getPhrases(phrasesGroupedByCategoryRequestParam),
const tabulatorPhrasesResponse = await this.$api.call(
ApiPhrases.getTabulatorPhrases(),
);
const phrasesData = phrasesResponse.data;
Object.keys(phrasesData).forEach((language) => {
let genericTabulatorPhrases = phrasesData[language].filter(
(phrase) => phrase.category === "tabulator",
);
const tabulatorPhrasesData = tabulatorPhrasesResponse.data;
Object.keys(tabulatorPhrasesData).forEach((language) => {
let tabulatorPhraseToTranslationMapper = {};
genericTabulatorPhrases.forEach((phrase) => {
tabulatorPhraseToTranslationMapper[phrase.phrase] =
phrase.text;
tabulatorPhrasesData[language].forEach((phrase) => {
tabulatorPhraseToTranslationMapper[phrase.phrase] = phrase.text;
});
tabulatorOptions.langs[language] = {
@@ -459,6 +419,35 @@ export const CoreFilterCmpt = {
},
},
};
});
let phrasesGroupedByCategoryRequestParam = {};
tabulatorOptions.columns.forEach((column) => {
if (column.field === "collapse") return;
let [category, phrase] = column.title.split("/");
if (phrasesGroupedByCategoryRequestParam[category]) {
phrasesGroupedByCategoryRequestParam[category].push(phrase);
} else {
phrasesGroupedByCategoryRequestParam[category] = [phrase];
}
});
const phrasesResponse = await this.$api.call(
ApiPhrases.getPhrases(phrasesGroupedByCategoryRequestParam),
);
const phrasesData = phrasesResponse.data;
Object.keys(phrasesData).forEach((language) => {
let genericTabulatorPhrases = phrasesData[language].filter(
(phrase) => phrase.category === "tabulator",
);
let tabulatorPhraseToTranslationMapper = {};
genericTabulatorPhrases.forEach((phrase) => {
tabulatorPhraseToTranslationMapper[phrase.phrase] =
phrase.text;
});
let columnHeadingPhrases = phrasesData[language].filter(
(phrase) => phrase.category !== "tabulator",