diff --git a/amd/build/controllers/preferences.min.js b/amd/build/controllers/preferences.min.js index 93ffeb2..9aa8ca9 100644 --- a/amd/build/controllers/preferences.min.js +++ b/amd/build/controllers/preferences.min.js @@ -2,7 +2,7 @@ define("tiny_ai/controllers/preferences",["exports","tiny_ai/constants","tiny_ai /** * Controller for the main selection. * - * @module tiny_ai/controllers/translate + * @module tiny_ai/controllers/preferences * @copyright 2024, ISB Bayern * @author Philipp Memmel * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later diff --git a/amd/build/controllers/preferences.min.js.map b/amd/build/controllers/preferences.min.js.map index a031877..088d08b 100644 --- a/amd/build/controllers/preferences.min.js.map +++ b/amd/build/controllers/preferences.min.js.map @@ -1 +1 @@ -{"version":3,"file":"preferences.min.js","sources":["../../src/controllers/preferences.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Controller for the main selection.\n *\n * @module tiny_ai/controllers/translate\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {constants} from 'tiny_ai/constants';\nimport SELECTORS from 'tiny_ai/selectors';\nimport BaseController from 'tiny_ai/controllers/base';\nimport {getSummarizeHandler, getTranslateHandler, getTtsHandler, getImggenHandler} from 'tiny_ai/utils';\n\nexport default class extends BaseController {\n\n async init() {\n const modalFooter = document.querySelector(SELECTORS.modalFooter);\n const backButton = modalFooter.querySelector('[data-action=\"back\"]');\n const generateButton = modalFooter.querySelector('[data-action=\"generate\"]');\n\n const [summarizeHandler, translateHandler, ttsHandler, imggenHandler] = [\n getSummarizeHandler(this.uniqid),\n getTranslateHandler(this.uniqid),\n getTtsHandler(this.uniqid),\n getImggenHandler(this.uniqid)\n ];\n\n switch (this.datamanager.getCurrentTool()) {\n case 'summarize':\n case 'describe': {\n summarizeHandler.setTool(this.datamanager.getCurrentTool());\n const maxWordCountElement = this.baseElement.querySelector('[data-preference=\"maxWordCount\"]');\n const languageTypeElement = this.baseElement.querySelector('[data-preference=\"languageType\"]');\n summarizeHandler.setMaxWordCount(maxWordCountElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n summarizeHandler.setLanguageType(languageTypeElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n const currentPromptSummarize = await summarizeHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPromptSummarize);\n maxWordCountElement.addEventListener('dropdownSelectionUpdated', async (event) => {\n summarizeHandler.setMaxWordCount(event.detail.newValue);\n const currentPrompt = await summarizeHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPrompt);\n });\n languageTypeElement.addEventListener('dropdownSelectionUpdated', async (event) => {\n summarizeHandler.setLanguageType(event.detail.newValue);\n const currentPrompt = await summarizeHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPrompt);\n });\n break;\n }\n case 'translate': {\n const targetLanguageElement = this.baseElement.querySelector('[data-preference=\"targetLanguage\"]');\n translateHandler.setTargetLanguage(targetLanguageElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n const currentPromptTranslate = await translateHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPromptTranslate);\n targetLanguageElement.addEventListener('dropdownSelectionUpdated', async (event) => {\n translateHandler.setTargetLanguage(event.detail.newValue);\n const currentPromptTranslate = await translateHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPromptTranslate);\n });\n break;\n }\n case 'tts':\n case 'audiogen': {\n const ttsTargetLanguageElement = this.baseElement.querySelector('[data-preference=\"targetLanguage\"]');\n const voiceElement = this.baseElement.querySelector('[data-preference=\"voice\"]');\n const genderElement = this.baseElement.querySelector('[data-preference=\"gender\"]');\n if (ttsTargetLanguageElement) {\n ttsHandler.setTargetLanguage(ttsTargetLanguageElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n ttsTargetLanguageElement.addEventListener('dropdownSelectionUpdated', event => {\n ttsHandler.setTargetLanguage(event.detail.newValue);\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n });\n }\n if (voiceElement) {\n ttsHandler.setVoice(voiceElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n voiceElement.addEventListener('dropdownSelectionUpdated', event => {\n ttsHandler.setVoice(event.detail.newValue);\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n });\n }\n if (genderElement) {\n ttsHandler.setGender(genderElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n genderElement.addEventListener('dropdownSelectionUpdated', event => {\n ttsHandler.setGender(event.detail.newValue);\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n });\n }\n this.datamanager.setCurrentPrompt(ttsHandler.getPrompt(this.datamanager.getCurrentTool(),\n this.datamanager.getSelectionText()));\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n break;\n }\n case 'imggen': {\n const sizesElement = this.baseElement.querySelector('[data-preference=\"sizes\"]');\n\n if (sizesElement) {\n imggenHandler.setSize(sizesElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n sizesElement.addEventListener('dropdownSelectionUpdated', event => {\n imggenHandler.setSize(event.detail.newValue);\n this.datamanager.setCurrentOptions(imggenHandler.getOptions());\n });\n }\n this.datamanager.setCurrentPrompt('');\n this.datamanager.setCurrentOptions(imggenHandler.getOptions());\n break;\n }\n }\n\n if (backButton) {\n backButton.addEventListener('click', async () => {\n await this.renderer.renderStart(constants.modalModes.selection);\n });\n }\n\n if (generateButton) {\n generateButton.addEventListener('click', async () => {\n const result = await this.generateAiAnswer();\n if (result === null) {\n return;\n }\n await this.renderer.renderSuggestion();\n });\n }\n }\n}\n"],"names":["BaseController","modalFooter","document","querySelector","SELECTORS","backButton","generateButton","summarizeHandler","translateHandler","ttsHandler","imggenHandler","this","uniqid","datamanager","getCurrentTool","setTool","maxWordCountElement","baseElement","languageTypeElement","setMaxWordCount","dataset","value","setLanguageType","currentPromptSummarize","getPrompt","getSelectionText","setCurrentPrompt","addEventListener","async","event","detail","newValue","currentPrompt","targetLanguageElement","setTargetLanguage","currentPromptTranslate","ttsTargetLanguageElement","voiceElement","genderElement","setCurrentOptions","getOptions","setVoice","setGender","sizesElement","setSize","renderer","renderStart","constants","modalModes","selection","generateAiAnswer","renderSuggestion"],"mappings":";;;;;;;;8LA6B6BA,iCAGfC,YAAcC,SAASC,cAAcC,mBAAUH,aAC/CI,WAAaJ,YAAYE,cAAc,wBACvCG,eAAiBL,YAAYE,cAAc,6BAE1CI,iBAAkBC,iBAAkBC,WAAYC,eAAiB,EACpE,8BAAoBC,KAAKC,SACzB,8BAAoBD,KAAKC,SACzB,wBAAcD,KAAKC,SACnB,2BAAiBD,KAAKC,gBAGlBD,KAAKE,YAAYC,sBAChB,gBACA,YACDP,iBAAiBQ,QAAQJ,KAAKE,YAAYC,wBACpCE,oBAAsBL,KAAKM,YAAYd,cAAc,oCACrDe,oBAAsBP,KAAKM,YAAYd,cAAc,oCAC3DI,iBAAiBY,gBAAgBH,oBAAoBb,cAAc,4BAA4BiB,QAAQC,OACvGd,iBAAiBe,gBAAgBJ,oBAAoBf,cAAc,4BAA4BiB,QAAQC,aACjGE,6BAA+BhB,iBAAiBiB,UAAUb,KAAKE,YAAYY,yBAC5EZ,YAAYa,iBAAiBH,wBAClCP,oBAAoBW,iBAAiB,4BAA4BC,MAAAA,QAC7DrB,iBAAiBY,gBAAgBU,MAAMC,OAAOC,gBACxCC,oBAAsBzB,iBAAiBiB,UAAUb,KAAKE,YAAYY,yBACnEZ,YAAYa,iB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UAAUb,KAAKE,YAAYC,iBACpEH,KAAKE,YAAYY,0BAChBZ,YAAY0B,kBAAkB9B,WAAW+B,wBAG7C,gBACKG,aAAehC,KAAKM,YAAYd,cAAc,6BAEhDwC,eACAjC,cAAckC,QAAQD,aAAaxC,cAAc,4BAA4BiB,QAAQC,OACrFsB,aAAahB,iBAAiB,4BAA4BE,QACtDnB,cAAckC,QAAQf,MAAMC,OAAOC,eAC9BlB,YAAY0B,kBAAkB7B,cAAc8B,uBAGpD3B,YAAYa,iBAAiB,SAC7Bb,YAAY0B,kBAAkB7B,cAAc8B,qBAKrDnC,YACAA,WAAWsB,iBAAiB,SAASC,gBAC3BjB,KAAKkC,SAASC,YAAYC,qBAAUC,WAAWC,cAIzD3C,gBACAA,eAAeqB,iBAAiB,SAASC,UAEtB,aADMjB,KAAKuC,0BAIpBvC,KAAKkC,SAASM"} \ No newline at end of file +{"version":3,"file":"preferences.min.js","sources":["../../src/controllers/preferences.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * Controller for the main selection.\n *\n * @module tiny_ai/controllers/preferences\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {constants} from 'tiny_ai/constants';\nimport SELECTORS from 'tiny_ai/selectors';\nimport BaseController from 'tiny_ai/controllers/base';\nimport {getSummarizeHandler, getTranslateHandler, getTtsHandler, getImggenHandler} from 'tiny_ai/utils';\n\nexport default class extends BaseController {\n\n async init() {\n const modalFooter = document.querySelector(SELECTORS.modalFooter);\n const backButton = modalFooter.querySelector('[data-action=\"back\"]');\n const generateButton = modalFooter.querySelector('[data-action=\"generate\"]');\n\n const [summarizeHandler, translateHandler, ttsHandler, imggenHandler] = [\n getSummarizeHandler(this.uniqid),\n getTranslateHandler(this.uniqid),\n getTtsHandler(this.uniqid),\n getImggenHandler(this.uniqid)\n ];\n\n switch (this.datamanager.getCurrentTool()) {\n case 'summarize':\n case 'describe': {\n summarizeHandler.setTool(this.datamanager.getCurrentTool());\n const maxWordCountElement = this.baseElement.querySelector('[data-preference=\"maxWordCount\"]');\n const languageTypeElement = this.baseElement.querySelector('[data-preference=\"languageType\"]');\n summarizeHandler.setMaxWordCount(maxWordCountElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n summarizeHandler.setLanguageType(languageTypeElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n const currentPromptSummarize = await summarizeHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPromptSummarize);\n maxWordCountElement.addEventListener('dropdownSelectionUpdated', async (event) => {\n summarizeHandler.setMaxWordCount(event.detail.newValue);\n const currentPrompt = await summarizeHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPrompt);\n });\n languageTypeElement.addEventListener('dropdownSelectionUpdated', async (event) => {\n summarizeHandler.setLanguageType(event.detail.newValue);\n const currentPrompt = await summarizeHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPrompt);\n });\n break;\n }\n case 'translate': {\n const targetLanguageElement = this.baseElement.querySelector('[data-preference=\"targetLanguage\"]');\n translateHandler.setTargetLanguage(targetLanguageElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n const currentPromptTranslate = await translateHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPromptTranslate);\n targetLanguageElement.addEventListener('dropdownSelectionUpdated', async (event) => {\n translateHandler.setTargetLanguage(event.detail.newValue);\n const currentPromptTranslate = await translateHandler.getPrompt(this.datamanager.getSelectionText());\n this.datamanager.setCurrentPrompt(currentPromptTranslate);\n });\n break;\n }\n case 'tts':\n case 'audiogen': {\n const ttsTargetLanguageElement = this.baseElement.querySelector('[data-preference=\"targetLanguage\"]');\n const voiceElement = this.baseElement.querySelector('[data-preference=\"voice\"]');\n const genderElement = this.baseElement.querySelector('[data-preference=\"gender\"]');\n if (ttsTargetLanguageElement) {\n ttsHandler.setTargetLanguage(ttsTargetLanguageElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n ttsTargetLanguageElement.addEventListener('dropdownSelectionUpdated', event => {\n ttsHandler.setTargetLanguage(event.detail.newValue);\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n });\n }\n if (voiceElement) {\n ttsHandler.setVoice(voiceElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n voiceElement.addEventListener('dropdownSelectionUpdated', event => {\n ttsHandler.setVoice(event.detail.newValue);\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n });\n }\n if (genderElement) {\n ttsHandler.setGender(genderElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n genderElement.addEventListener('dropdownSelectionUpdated', event => {\n ttsHandler.setGender(event.detail.newValue);\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n });\n }\n this.datamanager.setCurrentPrompt(ttsHandler.getPrompt(this.datamanager.getCurrentTool(),\n this.datamanager.getSelectionText()));\n this.datamanager.setCurrentOptions(ttsHandler.getOptions());\n break;\n }\n case 'imggen': {\n const sizesElement = this.baseElement.querySelector('[data-preference=\"sizes\"]');\n\n if (sizesElement) {\n imggenHandler.setSize(sizesElement.querySelector('[data-dropdown=\"select\"]').dataset.value);\n sizesElement.addEventListener('dropdownSelectionUpdated', event => {\n imggenHandler.setSize(event.detail.newValue);\n this.datamanager.setCurrentOptions(imggenHandler.getOptions());\n });\n }\n this.datamanager.setCurrentPrompt('');\n this.datamanager.setCurrentOptions(imggenHandler.getOptions());\n break;\n }\n }\n\n if (backButton) {\n backButton.addEventListener('click', async () => {\n await this.renderer.renderStart(constants.modalModes.selection);\n });\n }\n\n if (generateButton) {\n generateButton.addEventListener('click', async () => {\n const result = await this.generateAiAnswer();\n if (result === null) {\n return;\n }\n await this.renderer.renderSuggestion();\n });\n }\n }\n}\n"],"names":["BaseController","modalFooter","document","querySelector","SELECTORS","backButton","generateButton","summarizeHandler","translateHandler","ttsHandler","imggenHandler","this","uniqid","datamanager","getCurrentTool","setTool","maxWordCountElement","baseElement","languageTypeElement","setMaxWordCount","dataset","value","setLanguageType","currentPromptSummarize","getPrompt","getSelectionText","setCurrentPrompt","addEventListener","async","event","detail","newValue","currentPrompt","targetLanguageElement","setTargetLanguage","currentPromptTranslate","ttsTargetLanguageElement","voiceElement","genderElement","setCurrentOptions","getOptions","setVoice","setGender","sizesElement","setSize","renderer","renderStart","constants","modalModes","selection","generateAiAnswer","renderSuggestion"],"mappings":";;;;;;;;8LA6B6BA,iCAGfC,YAAcC,SAASC,cAAcC,mBAAUH,aAC/CI,WAAaJ,YAAYE,cAAc,wBACvCG,eAAiBL,YAAYE,cAAc,6BAE1CI,iBAAkBC,iBAAkBC,WAAYC,eAAiB,EACpE,8BAAoBC,KAAKC,SACzB,8BAAoBD,KAAKC,SACzB,wBAAcD,KAAKC,SACnB,2BAAiBD,KAAKC,gBAGlBD,KAAKE,YAAYC,sBAChB,gBACA,YACDP,iBAAiBQ,QAAQJ,KAAKE,YAAYC,wBACpCE,oBAAsBL,KAAKM,YAAYd,cAAc,oCACrDe,oBAAsBP,KAAKM,YAAYd,cAAc,oCAC3DI,iBAAiBY,gBAAgBH,oBAAoBb,cAAc,4BAA4BiB,QAAQC,OACvGd,iBAAiBe,gBAAgBJ,oBAAoBf,cAAc,4BAA4BiB,QAAQC,aACjGE,6BAA+BhB,iBAAiBiB,UAAUb,KAAKE,YAAYY,yBAC5EZ,YAAYa,iBAAiBH,wBAClCP,oBAAoBW,iBAAiB,4BAA4BC,MAAAA,QAC7DrB,iBAAiB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C,UAAUb,MAAMC,OAAOC,eAC7BlB,YAAY0B,kBAAkB9B,WAAW+B,uBAGjD3B,YAAYa,iBAAiBjB,WAAWe,UAAUb,KAAKE,YAAYC,iBACpEH,KAAKE,YAAYY,0BAChBZ,YAAY0B,kBAAkB9B,WAAW+B,wBAG7C,gBACKG,aAAehC,KAAKM,YAAYd,cAAc,6BAEhDwC,eACAjC,cAAckC,QAAQD,aAAaxC,cAAc,4BAA4BiB,QAAQC,OACrFsB,aAAahB,iBAAiB,4BAA4BE,QACtDnB,cAAckC,QAAQf,MAAMC,OAAOC,eAC9BlB,YAAY0B,kBAAkB7B,cAAc8B,uBAGpD3B,YAAYa,iBAAiB,SAC7Bb,YAAY0B,kBAAkB7B,cAAc8B,qBAKrDnC,YACAA,WAAWsB,iBAAiB,SAASC,gBAC3BjB,KAAKkC,SAASC,YAAYC,qBAAUC,WAAWC,cAIzD3C,gBACAA,eAAeqB,iBAAiB,SAASC,UAEtB,aADMjB,KAAKuC,0BAIpBvC,KAAKkC,SAASM"} \ No newline at end of file diff --git a/amd/build/datahandler/translate.min.js b/amd/build/datahandler/translate.min.js index 9b92629..df2b0f4 100644 --- a/amd/build/datahandler/translate.min.js +++ b/amd/build/datahandler/translate.min.js @@ -6,6 +6,6 @@ define("tiny_ai/datahandler/translate",["exports","tiny_ai/datahandler/basedata" * @copyright 2024, ISB Bayern * @author Philipp Memmel * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,BasedataHandler=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(BasedataHandler),_base=_interopRequireDefault(_base),_config=_interopRequireDefault(_config);class _default extends _base.default{constructor(){super(...arguments),_defineProperty(this,"languageNameInCurrentUserLanguage",new Intl.DisplayNames([_config.default.language],{type:"language"})),_defineProperty(this,"targetLanguageOptions",{en:this.languageNameInCurrentUserLanguage.of("en"),de:this.languageNameInCurrentUserLanguage.of("de"),it:this.languageNameInCurrentUserLanguage.of("it"),es:this.languageNameInCurrentUserLanguage.of("es"),ru:this.languageNameInCurrentUserLanguage.of("ru"),uk:this.languageNameInCurrentUserLanguage.of("uk"),zh:this.languageNameInCurrentUserLanguage.of("zh")}),_defineProperty(this,"targetLanguage",null)}setTargetLanguage(targetLanguage){this.targetLanguage=targetLanguage}async getPrompt(selectionText){let prompt=await(0,_str.getString)("translate_baseprompt","tiny_ai",this.targetLanguageOptions[this.targetLanguage]);return prompt+=": "+selectionText,prompt}getTemplateContext(){const translateHandler=(0,_utils.getTranslateHandler)(this.uniqid),context={modal_headline:BasedataHandler.getTinyAiString("translate_headline"),showIcon:!0,tool:"translate"},targetLanguageDropdownContext={preference:"targetLanguage"};targetLanguageDropdownContext.dropdown_default=Object.values(translateHandler.targetLanguageOptions)[0],targetLanguageDropdownContext.dropdown_default_value=Object.keys(translateHandler.targetLanguageOptions)[0],targetLanguageDropdownContext.dropdown_description=BasedataHandler.getTinyAiString("targetlanguage");const targetLanguageDropdownOptions=[];for(const[key,value]of Object.entries(translateHandler.targetLanguageOptions))targetLanguageDropdownOptions.push({optionValue:key,optionLabel:value});return targetLanguageDropdownContext.dropdown_options=targetLanguageDropdownOptions,Object.assign(context,{modal_dropdowns:[targetLanguageDropdownContext]}),Object.assign(context,BasedataHandler.getShowPromptButtonContext()),Object.assign(context,BasedataHandler.getBackAndGenerateButtonContext()),context}}return _exports.default=_default,_exports.default})); + */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,BasedataHandler=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(BasedataHandler),_base=_interopRequireDefault(_base),_config=_interopRequireDefault(_config);class _default extends _base.default{constructor(uniqid){super(uniqid),_defineProperty(this,"languageNameInCurrentUserLanguage",new Intl.DisplayNames([_config.default.language],{type:"language"})),_defineProperty(this,"targetLanguageCodes",["de","fr","it","es","cs","zh","ru","uk","el","la","tr","ro","pl","bg","ar","sq","bs","sr","hr","ku","fa","ps","sk","hu"]),_defineProperty(this,"targetLanguageOptions",[]),_defineProperty(this,"targetLanguage",null),this.initTargetLanguages()}setTargetLanguage(targetLanguage){this.targetLanguage=targetLanguage}async getPrompt(selectionText){const selectedLanguageEntry=this.targetLanguageOptions.filter((languageEntry=>languageEntry.key===this.targetLanguage))[0];let prompt=await(0,_str.getString)("translate_baseprompt","tiny_ai",selectedLanguageEntry.value);return prompt+=": "+selectionText,prompt}getTemplateContext(){const translateHandler=(0,_utils.getTranslateHandler)(this.uniqid),context={modal_headline:BasedataHandler.getTinyAiString("translate_headline"),showIcon:!0,tool:"translate"},targetLanguageDropdownContext={preference:"targetLanguage"};targetLanguageDropdownContext.dropdown_default=translateHandler.targetLanguageOptions[0].value,targetLanguageDropdownContext.dropdown_default_value=translateHandler.targetLanguageOptions[0].key,targetLanguageDropdownContext.dropdown_description=BasedataHandler.getTinyAiString("targetlanguage");const targetLanguageDropdownOptions=[];return translateHandler.targetLanguageOptions.forEach((languageEntry=>{targetLanguageDropdownOptions.push({optionValue:languageEntry.key,optionLabel:languageEntry.value})})),targetLanguageDropdownContext.dropdown_options=targetLanguageDropdownOptions,Object.assign(context,{modal_dropdowns:[targetLanguageDropdownContext]}),Object.assign(context,BasedataHandler.getShowPromptButtonContext()),Object.assign(context,BasedataHandler.getBackAndGenerateButtonContext()),context}initTargetLanguages(){const firstLanguages=[{key:"en",value:this.languageNameInCurrentUserLanguage.of("en")}];if("en"!==_config.default.language&&this.targetLanguageCodes.includes(_config.default.language)){firstLanguages.push({key:_config.default.language,value:this.languageNameInCurrentUserLanguage.of(_config.default.language)});const index=this.targetLanguageCodes.indexOf(_config.default.language);this.targetLanguageCodes.splice(index,1)}this.targetLanguageCodes.forEach((languageCode=>{this.targetLanguageOptions[languageCode]=this.languageNameInCurrentUserLanguage.of(languageCode)}));const sortedLanguages=Object.entries(this.targetLanguageOptions).sort(((a,b)=>a[1].localeCompare(b[1]))).map((_ref=>{let[key,value]=_ref;return{key:key,value:value}}));this.targetLanguageOptions=[...firstLanguages,...sortedLanguages]}}return _exports.default=_default,_exports.default})); //# sourceMappingURL=translate.min.js.map \ No newline at end of file diff --git a/amd/build/datahandler/translate.min.js.map b/amd/build/datahandler/translate.min.js.map index 80731fe..b34f9c6 100644 --- a/amd/build/datahandler/translate.min.js.map +++ b/amd/build/datahandler/translate.min.js.map @@ -1 +1 @@ -{"version":3,"file":"translate.min.js","sources":["../../src/datahandler/translate.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\nimport * as BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport BaseHandler from 'tiny_ai/datahandler/base';\nimport {getTranslateHandler} from 'tiny_ai/utils';\nimport Config from 'core/config';\nimport {getString} from 'core/str';\n\n/**\n * Tiny AI data manager.\n *\n * @module tiny_ai/datahandler/translate\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport default class extends BaseHandler {\n\n languageNameInCurrentUserLanguage = new Intl.DisplayNames([Config.language], {type: 'language'});\n\n targetLanguageOptions = {\n en: this.languageNameInCurrentUserLanguage.of('en'),\n de: this.languageNameInCurrentUserLanguage.of('de'),\n it: this.languageNameInCurrentUserLanguage.of('it'),\n es: this.languageNameInCurrentUserLanguage.of('es'),\n ru: this.languageNameInCurrentUserLanguage.of('ru'),\n uk: this.languageNameInCurrentUserLanguage.of('uk'),\n zh: this.languageNameInCurrentUserLanguage.of('zh'),\n };\n targetLanguage = null;\n\n\n setTargetLanguage(targetLanguage) {\n this.targetLanguage = targetLanguage;\n }\n\n async getPrompt(selectionText) {\n let prompt = await getString('translate_baseprompt', 'tiny_ai', this.targetLanguageOptions[this.targetLanguage]);\n prompt += ': ' + selectionText;\n return prompt;\n }\n\n getTemplateContext() {\n const translateHandler = getTranslateHandler(this.uniqid);\n const context = {\n modal_headline: BasedataHandler.getTinyAiString('translate_headline'),\n showIcon: true,\n tool: 'translate',\n };\n const targetLanguageDropdownContext = {};\n targetLanguageDropdownContext.preference = 'targetLanguage';\n targetLanguageDropdownContext.dropdown_default = Object.values(translateHandler.targetLanguageOptions)[0];\n targetLanguageDropdownContext.dropdown_default_value = Object.keys(translateHandler.targetLanguageOptions)[0];\n targetLanguageDropdownContext.dropdown_description = BasedataHandler.getTinyAiString('targetlanguage');\n const targetLanguageDropdownOptions = [];\n for (const [key, value] of Object.entries(translateHandler.targetLanguageOptions)) {\n targetLanguageDropdownOptions.push({\n optionValue: key,\n optionLabel: value,\n });\n }\n targetLanguageDropdownContext.dropdown_options = targetLanguageDropdownOptions;\n\n Object.assign(context, {\n modal_dropdowns: [\n targetLanguageDropdownContext,\n ]\n });\n Object.assign(context, BasedataHandler.getShowPromptButtonContext());\n Object.assign(context, BasedataHandler.getBackAndGenerateButtonContext());\n return context;\n }\n}\n"],"names":["BaseHandler","Intl","DisplayNames","Config","language","type","en","this","languageNameInCurrentUserLanguage","of","de","it","es","ru","uk","zh","setTargetLanguage","targetLanguage","selectionText","prompt","targetLanguageOptions","getTemplateContext","translateHandler","uniqid","context","modal_headline","BasedataHandler","getTinyAiString","showIcon","tool","targetLanguageDropdownContext","dropdown_default","Object","values","dropdown_default_value","keys","dropdown_description","targetLanguageDropdownOptions","key","value","entries","push","optionValue","optionLabel","dropdown_options","assign","modal_dropdowns","getShowPromptButtonContext","getBackAndGenerateButtonContext"],"mappings":";;;;;;;;s2BA8B6BA,yGAEW,IAAIC,KAAKC,aAAa,CAACC,gBAAOC,UAAW,CAACC,KAAM,2DAE5D,CACpBC,GAAIC,KAAKC,kCAAkCC,GAAG,MAC9CC,GAAIH,KAAKC,kCAAkCC,GAAG,MAC9CE,GAAIJ,KAAKC,kCAAkCC,GAAG,MAC9CG,GAAIL,KAAKC,kCAAkCC,GAAG,MAC9CI,GAAIN,KAAKC,kCAAkCC,GAAG,MAC9CK,GAAIP,KAAKC,kCAAkCC,GAAG,MAC9CM,GAAIR,KAAKC,kCAAkCC,GAAG,8CAEjC,MAGjBO,kBAAkBC,qBACTA,eAAiBA,+BAGVC,mBACRC,aAAe,kBAAU,uBAAwB,UAAWZ,KAAKa,sBAAsBb,KAAKU,wBAChGE,QAAU,KAAOD,cACVC,OAGXE,2BACUC,kBAAmB,8BAAoBf,KAAKgB,QAC5CC,QAAU,CACZC,eAAgBC,gBAAgBC,gBAAgB,sBAChDC,UAAU,EACVC,KAAM,aAEJC,8BAAgC,CACtCA,WAA2C,kBAC3CA,8BAA8BC,iBAAmBC,OAAOC,OAAOX,iBAAiBF,uBAAuB,GACvGU,8BAA8BI,uBAAyBF,OAAOG,KAAKb,iBAAiBF,uBAAuB,GAC3GU,8BAA8BM,qBAAuBV,gBAAgBC,gBAAgB,wBAC/EU,8BAAgC,OACjC,MAAOC,IAAKC,SAAUP,OAAOQ,QAAQlB,iBAAiBF,uBACvDiB,8BAA8BI,KAAK,CAC/BC,YAAaJ,IACbK,YAAaJ,eAGrBT,8BAA8Bc,iBAAmBP,8BAEjDL,OAAOa,OAAOrB,QAAS,CACnBsB,gBAAiB,CACbhB,iCAGRE,OAAOa,OAAOrB,QAASE,gBAAgBqB,8BACvCf,OAAOa,OAAOrB,QAASE,gBAAgBsB,mCAChCxB"} \ No newline at end of file +{"version":3,"file":"translate.min.js","sources":["../../src/datahandler/translate.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\nimport * as BasedataHandler from 'tiny_ai/datahandler/basedata';\nimport BaseHandler from 'tiny_ai/datahandler/base';\nimport {getTranslateHandler} from 'tiny_ai/utils';\nimport Config from 'core/config';\nimport {getString} from 'core/str';\n\n/**\n * Tiny AI data manager.\n *\n * @module tiny_ai/datahandler/translate\n * @copyright 2024, ISB Bayern\n * @author Philipp Memmel\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport default class extends BaseHandler {\n\n languageNameInCurrentUserLanguage = new Intl.DisplayNames([Config.language], {type: 'language'});\n // English will always be added to the front of the list. All other languages can be defined here.\n // The user's current language will be shown right after English, if it is contained in this list.\n targetLanguageCodes = [\n 'de', 'fr', 'it', 'es', 'cs', 'zh', 'ru', 'uk', 'el', 'la', 'tr', 'ro', 'pl', 'bg', 'ar', 'sq',\n 'bs', 'sr', 'hr', 'ku', 'fa', 'ps', 'sk', 'hu'\n ];\n targetLanguageOptions = [];\n targetLanguage = null;\n\n constructor(uniqid) {\n super(uniqid);\n this.initTargetLanguages();\n }\n\n setTargetLanguage(targetLanguage) {\n this.targetLanguage = targetLanguage;\n }\n\n async getPrompt(selectionText) {\n const selectedLanguageEntry = this.targetLanguageOptions.filter(languageEntry => languageEntry.key === this.targetLanguage)[0];\n let prompt = await getString('translate_baseprompt', 'tiny_ai', selectedLanguageEntry.value);\n prompt += ': ' + selectionText;\n return prompt;\n }\n\n getTemplateContext() {\n const translateHandler = getTranslateHandler(this.uniqid);\n const context = {\n modal_headline: BasedataHandler.getTinyAiString('translate_headline'),\n showIcon: true,\n tool: 'translate',\n };\n const targetLanguageDropdownContext = {};\n targetLanguageDropdownContext.preference = 'targetLanguage';\n targetLanguageDropdownContext.dropdown_default = translateHandler.targetLanguageOptions[0].value;\n targetLanguageDropdownContext.dropdown_default_value = translateHandler.targetLanguageOptions[0].key;\n targetLanguageDropdownContext.dropdown_description = BasedataHandler.getTinyAiString('targetlanguage');\n const targetLanguageDropdownOptions = [];\n translateHandler.targetLanguageOptions.forEach(languageEntry => {\n targetLanguageDropdownOptions.push({\n optionValue: languageEntry.key,\n optionLabel: languageEntry.value,\n });\n });\n targetLanguageDropdownContext.dropdown_options = targetLanguageDropdownOptions;\n\n Object.assign(context, {\n modal_dropdowns: [\n targetLanguageDropdownContext,\n ]\n });\n Object.assign(context, BasedataHandler.getShowPromptButtonContext());\n Object.assign(context, BasedataHandler.getBackAndGenerateButtonContext());\n return context;\n }\n\n initTargetLanguages() {\n const firstLanguages = [\n {\n key: 'en',\n value: this.languageNameInCurrentUserLanguage.of('en')\n }\n ];\n if (Config.language !== 'en' && this.targetLanguageCodes.includes(Config.language)) {\n firstLanguages.push(\n {\n key: Config.language,\n value: this.languageNameInCurrentUserLanguage.of(Config.language)\n }\n );\n // Remove current user's language from the list.\n const index = this.targetLanguageCodes.indexOf(Config.language);\n this.targetLanguageCodes.splice(index, 1);\n }\n this.targetLanguageCodes.forEach(languageCode => {\n this.targetLanguageOptions[languageCode] = this.languageNameInCurrentUserLanguage.of(languageCode);\n });\n\n const sortedLanguages = Object\n .entries(this.targetLanguageOptions)\n .sort((a, b) => a[1].localeCompare(b[1]))\n .map(([key, value]) => ({'key': key, 'value': value}));\n this.targetLanguageOptions = [...firstLanguages, ...sortedLanguages];\n }\n}\n"],"names":["BaseHandler","constructor","uniqid","Intl","DisplayNames","Config","language","type","initTargetLanguages","setTargetLanguage","targetLanguage","selectionText","selectedLanguageEntry","this","targetLanguageOptions","filter","languageEntry","key","prompt","value","getTemplateContext","translateHandler","context","modal_headline","BasedataHandler","getTinyAiString","showIcon","tool","targetLanguageDropdownContext","dropdown_default","dropdown_default_value","dropdown_description","targetLanguageDropdownOptions","forEach","push","optionValue","optionLabel","dropdown_options","Object","assign","modal_dropdowns","getShowPromptButtonContext","getBackAndGenerateButtonContext","firstLanguages","languageNameInCurrentUserLanguage","of","targetLanguageCodes","includes","index","indexOf","splice","languageCode","sortedLanguages","entries","sort","a","b","localeCompare","map","_ref"],"mappings":";;;;;;;;s2BA8B6BA,cAYzBC,YAAYC,cACFA,iEAX0B,IAAIC,KAAKC,aAAa,CAACC,gBAAOC,UAAW,CAACC,KAAM,yDAG9D,CAClB,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAC1F,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,KAAM,oDAEtB,0CACP,WAIRC,sBAGTC,kBAAkBC,qBACTA,eAAiBA,+BAGVC,qBACNC,sBAAwBC,KAAKC,sBAAsBC,QAAOC,eAAiBA,cAAcC,MAAQJ,KAAKH,iBAAgB,OACxHQ,aAAe,kBAA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wB,IAAI6B,kBAAmBS"} \ No newline at end of file diff --git a/amd/src/controllers/preferences.js b/amd/src/controllers/preferences.js index c96f642..9bdd50a 100644 --- a/amd/src/controllers/preferences.js +++ b/amd/src/controllers/preferences.js @@ -16,7 +16,7 @@ /** * Controller for the main selection. * - * @module tiny_ai/controllers/translate + * @module tiny_ai/controllers/preferences * @copyright 2024, ISB Bayern * @author Philipp Memmel * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later diff --git a/amd/src/datahandler/translate.js b/amd/src/datahandler/translate.js index d0a43a9..d53b60a 100644 --- a/amd/src/datahandler/translate.js +++ b/amd/src/datahandler/translate.js @@ -31,25 +31,27 @@ import {getString} from 'core/str'; export default class extends BaseHandler { languageNameInCurrentUserLanguage = new Intl.DisplayNames([Config.language], {type: 'language'}); - - targetLanguageOptions = { - en: this.languageNameInCurrentUserLanguage.of('en'), - de: this.languageNameInCurrentUserLanguage.of('de'), - it: this.languageNameInCurrentUserLanguage.of('it'), - es: this.languageNameInCurrentUserLanguage.of('es'), - ru: this.languageNameInCurrentUserLanguage.of('ru'), - uk: this.languageNameInCurrentUserLanguage.of('uk'), - zh: this.languageNameInCurrentUserLanguage.of('zh'), - }; + // English will always be added to the front of the list. All other languages can be defined here. + // The user's current language will be shown right after English, if it is contained in this list. + targetLanguageCodes = [ + 'de', 'fr', 'it', 'es', 'cs', 'zh', 'ru', 'uk', 'el', 'la', 'tr', 'ro', 'pl', 'bg', 'ar', 'sq', + 'bs', 'sr', 'hr', 'ku', 'fa', 'ps', 'sk', 'hu' + ]; + targetLanguageOptions = []; targetLanguage = null; + constructor(uniqid) { + super(uniqid); + this.initTargetLanguages(); + } setTargetLanguage(targetLanguage) { this.targetLanguage = targetLanguage; } async getPrompt(selectionText) { - let prompt = await getString('translate_baseprompt', 'tiny_ai', this.targetLanguageOptions[this.targetLanguage]); + const selectedLanguageEntry = this.targetLanguageOptions.filter(languageEntry => languageEntry.key === this.targetLanguage)[0]; + let prompt = await getString('translate_baseprompt', 'tiny_ai', selectedLanguageEntry.value); prompt += ': ' + selectionText; return prompt; } @@ -63,16 +65,16 @@ export default class extends BaseHandler { }; const targetLanguageDropdownContext = {}; targetLanguageDropdownContext.preference = 'targetLanguage'; - targetLanguageDropdownContext.dropdown_default = Object.values(translateHandler.targetLanguageOptions)[0]; - targetLanguageDropdownContext.dropdown_default_value = Object.keys(translateHandler.targetLanguageOptions)[0]; + targetLanguageDropdownContext.dropdown_default = translateHandler.targetLanguageOptions[0].value; + targetLanguageDropdownContext.dropdown_default_value = translateHandler.targetLanguageOptions[0].key; targetLanguageDropdownContext.dropdown_description = BasedataHandler.getTinyAiString('targetlanguage'); const targetLanguageDropdownOptions = []; - for (const [key, value] of Object.entries(translateHandler.targetLanguageOptions)) { + translateHandler.targetLanguageOptions.forEach(languageEntry => { targetLanguageDropdownOptions.push({ - optionValue: key, - optionLabel: value, + optionValue: languageEntry.key, + optionLabel: languageEntry.value, }); - } + }); targetLanguageDropdownContext.dropdown_options = targetLanguageDropdownOptions; Object.assign(context, { @@ -84,4 +86,33 @@ export default class extends BaseHandler { Object.assign(context, BasedataHandler.getBackAndGenerateButtonContext()); return context; } + + initTargetLanguages() { + const firstLanguages = [ + { + key: 'en', + value: this.languageNameInCurrentUserLanguage.of('en') + } + ]; + if (Config.language !== 'en' && this.targetLanguageCodes.includes(Config.language)) { + firstLanguages.push( + { + key: Config.language, + value: this.languageNameInCurrentUserLanguage.of(Config.language) + } + ); + // Remove current user's language from the list. + const index = this.targetLanguageCodes.indexOf(Config.language); + this.targetLanguageCodes.splice(index, 1); + } + this.targetLanguageCodes.forEach(languageCode => { + this.targetLanguageOptions[languageCode] = this.languageNameInCurrentUserLanguage.of(languageCode); + }); + + const sortedLanguages = Object + .entries(this.targetLanguageOptions) + .sort((a, b) => a[1].localeCompare(b[1])) + .map(([key, value]) => ({'key': key, 'value': value})); + this.targetLanguageOptions = [...firstLanguages, ...sortedLanguages]; + } }