get_calendar_events has now the ability to specify a different API. see #498
This commit is contained in:
parent
b632206d24
commit
f5dcebefb2
4 changed files with 111 additions and 18 deletions
|
|
@ -1211,6 +1211,10 @@
|
||||||
"message": "If checked, the Model and API specified below will be used for adding tags to emails, regardless the one choosen in the ThunderAI options page.",
|
"message": "If checked, the Model and API specified below will be used for adding tags to emails, regardless the one choosen in the ThunderAI options page.",
|
||||||
"description": ""
|
"description": ""
|
||||||
},
|
},
|
||||||
|
"prefs_OptionText_get_calendar_event_use_specific_integration_Info": {
|
||||||
|
"message": "If checked, the Model and API specified below will be used for creating calendar events, regardless the one choosen in the ThunderAI options page.",
|
||||||
|
"description": ""
|
||||||
|
},
|
||||||
"placeholder_thunderai_def_sign": {
|
"placeholder_thunderai_def_sign": {
|
||||||
"message": "Default signature as defined in ThunderAI options.",
|
"message": "Default signature as defined in ThunderAI options.",
|
||||||
"description": ""
|
"description": ""
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const special_prompts_with_integration = ['add_tags', 'spamfilter', 'summarize'];
|
const special_prompts_with_integration = ['add_tags', 'spamfilter', 'summarize', 'get_calendar_event']; //, 'get_task'];
|
||||||
|
|
||||||
export const integration_options_config = {
|
export const integration_options_config = {
|
||||||
chatgpt: {
|
chatgpt: {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>ThunderAI - __MSG_GetCalendarEvent_PageTitle__</title>
|
<title>ThunderAI - __MSG_GetCalendarEvent_PageTitle__</title>
|
||||||
<link rel="stylesheet" href="mzta-get-calendar-event.css">
|
<link rel="stylesheet" href="mzta-get-calendar-event.css">
|
||||||
|
<link rel="stylesheet" href="../_lib/connection-ui.css">
|
||||||
<link rel="icon" href="../../images/icon-16px.png">
|
<link rel="icon" href="../../images/icon-16px.png">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
@ -13,8 +14,20 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="get_calendar_event_table_title section_title">__MSG_get_calendar_event_prompt_prefs_title__</div>
|
<div class="get_calendar_event_table_title section_title">__MSG_get_calendar_event_prompt_prefs_title__</div>
|
||||||
<table id="miczPrefs">
|
<table id="miczPrefs">
|
||||||
|
<tr class="get_calendar_event_tr specific_integration">
|
||||||
|
<td><span class="opt_title">__MSG_prefs_OptionText_use_specific_integration__</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="get_calendar_event_use_specific_integration" name="get_calendar_event_use_specific_integration" class="option-input" />
|
||||||
|
__MSG_prefs_OptionText_get_calendar_event_use_specific_integration_Info__
|
||||||
|
</label>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr id="connection_ui_anchor"></tr>
|
||||||
|
<tr id="connection_ui_end"><td colspan="2"></td></tr>
|
||||||
<tr class="get_calendar_event_tr">
|
<tr class="get_calendar_event_tr">
|
||||||
<td><span>__MSG_prefs_OptionText_calendar_enforce_timezone__</span></td>
|
<td><span class="opt_title">__MSG_prefs_OptionText_calendar_enforce_timezone__</span></td>
|
||||||
<td>
|
<td>
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" id="calendar_enforce_timezone" name="calendar_enforce_timezone" class="option-input" /> __MSG_prefs_OptionText_calendar_enforce_timezone_Info__
|
<input type="checkbox" id="calendar_enforce_timezone" name="calendar_enforce_timezone" class="option-input" /> __MSG_prefs_OptionText_calendar_enforce_timezone_Info__
|
||||||
|
|
|
||||||
|
|
@ -16,23 +16,59 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { prefs_default } from '../../options/mzta-options-default.js';
|
import {
|
||||||
|
prefs_default,
|
||||||
|
integration_options_config
|
||||||
|
} from '../../options/mzta-options-default.js';
|
||||||
import { taLogger } from '../../js/mzta-logger.js';
|
import { taLogger } from '../../js/mzta-logger.js';
|
||||||
import { getSpecialPrompts, setSpecialPrompts } from "../../js/mzta-prompts.js";
|
import {
|
||||||
|
getSpecialPrompts,
|
||||||
|
setSpecialPrompts
|
||||||
|
} from "../../js/mzta-prompts.js";
|
||||||
import {
|
import {
|
||||||
getPlaceholders,
|
getPlaceholders,
|
||||||
mapPlaceholderToSuggestion
|
mapPlaceholderToSuggestion
|
||||||
} from "../../js/mzta-placeholders.js";
|
} from "../../js/mzta-placeholders.js";
|
||||||
import { textareaAutocomplete } from "../../js/mzta-placeholders-autocomplete.js";
|
import { textareaAutocomplete } from "../../js/mzta-placeholders-autocomplete.js";
|
||||||
import { isAPIKeyValue } from "../../js/mzta-utils.js";
|
import {
|
||||||
|
isAPIKeyValue,
|
||||||
|
setTomSelectBorder
|
||||||
|
} from "../../js/mzta-utils.js";
|
||||||
|
import {
|
||||||
|
initializeSpecificIntegrationUI
|
||||||
|
} from "../_lib/connection-ui.js";
|
||||||
|
|
||||||
let autocompleteSuggestions = [];
|
let autocompleteSuggestions = [];
|
||||||
let taLog = new taLogger("mzta-get-calendar-event-page",true);
|
let taLog = new taLogger("mzta-get-calendar-event-page",true);
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', async () => {
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
|
|
||||||
|
let specialPrompts = await getSpecialPrompts();
|
||||||
|
let get_calendar_event_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_get_calendar_event');
|
||||||
|
|
||||||
|
if (get_calendar_event_prompt && get_calendar_event_prompt.api_type && get_calendar_event_prompt.api_type !== '') {
|
||||||
|
let update_prefs = {};
|
||||||
|
update_prefs['get_calendar_event_connection_type'] = get_calendar_event_prompt.api_type;
|
||||||
|
|
||||||
|
let integration = get_calendar_event_prompt.api_type.replace('_api', '');
|
||||||
|
if (integration_options_config && integration_options_config[integration]) {
|
||||||
|
for (const key of Object.keys(integration_options_config[integration])) {
|
||||||
|
if (get_calendar_event_prompt[key] !== undefined) {
|
||||||
|
update_prefs[`get_calendar_event_${integration}_${key}`] = get_calendar_event_prompt[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await browser.storage.sync.set(update_prefs);
|
||||||
|
}
|
||||||
|
|
||||||
|
await initializeSpecificIntegrationUI({
|
||||||
|
prefix: 'get_calendar_event',
|
||||||
|
promptId: 'prompt_get_calendar_event',
|
||||||
|
taLog: taLog,
|
||||||
|
restoreOptionsCallback: restoreOptions
|
||||||
|
});
|
||||||
|
|
||||||
i18n.updateDocument();
|
i18n.updateDocument();
|
||||||
await restoreOptions();
|
|
||||||
|
|
||||||
document.querySelectorAll(".option-input").forEach(element => {
|
document.querySelectorAll(".option-input").forEach(element => {
|
||||||
element.addEventListener("change", saveOptions);
|
element.addEventListener("change", saveOptions);
|
||||||
|
|
@ -41,9 +77,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
let get_calendar_event_textarea = document.getElementById('get_calendar_event_prompt_text');
|
let get_calendar_event_textarea = document.getElementById('get_calendar_event_prompt_text');
|
||||||
let get_calendar_event_save_btn = document.getElementById('btn_save_prompt');
|
let get_calendar_event_save_btn = document.getElementById('btn_save_prompt');
|
||||||
let get_calendar_event_reset_btn = document.getElementById('btn_reset_prompt');
|
let get_calendar_event_reset_btn = document.getElementById('btn_reset_prompt');
|
||||||
|
let get_calendar_event_use_specific_integration = document.getElementById('get_calendar_event_use_specific_integration');
|
||||||
let specialPrompts = await getSpecialPrompts();
|
|
||||||
let get_calendar_event_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_get_calendar_event');
|
|
||||||
|
|
||||||
get_calendar_event_textarea.addEventListener('input', (event) => {
|
get_calendar_event_textarea.addEventListener('input', (event) => {
|
||||||
get_calendar_event_reset_btn.disabled = (event.target.value === browser.i18n.getMessage('prompt_get_calendar_event_full_text'));
|
get_calendar_event_reset_btn.disabled = (event.target.value === browser.i18n.getMessage('prompt_get_calendar_event_full_text'));
|
||||||
|
|
@ -55,6 +89,12 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
get_calendar_event_use_specific_integration.addEventListener('change', (event) => {
|
||||||
|
if (!event.target.checked) {
|
||||||
|
browser.storage.sync.set({ get_calendar_event_connection_type: '' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
get_calendar_event_reset_btn.addEventListener('click', () => {
|
get_calendar_event_reset_btn.addEventListener('click', () => {
|
||||||
get_calendar_event_textarea.value = browser.i18n.getMessage('prompt_get_calendar_event_full_text');
|
get_calendar_event_textarea.value = browser.i18n.getMessage('prompt_get_calendar_event_full_text');
|
||||||
get_calendar_event_reset_btn.disabled = true;
|
get_calendar_event_reset_btn.disabled = true;
|
||||||
|
|
@ -97,8 +137,8 @@ function saveOptions(e) {
|
||||||
case 'number':
|
case 'number':
|
||||||
options[element.id] = element.valueAsNumber;
|
options[element.id] = element.valueAsNumber;
|
||||||
break;
|
break;
|
||||||
case 'text':
|
case 'text':
|
||||||
case 'password':
|
case 'password':
|
||||||
options[element.id] = element.value.trim();
|
options[element.id] = element.value.trim();
|
||||||
break;
|
break;
|
||||||
case 'select-one':
|
case 'select-one':
|
||||||
|
|
@ -114,6 +154,7 @@ function saveOptions(e) {
|
||||||
async function restoreOptions() {
|
async function restoreOptions() {
|
||||||
function setCurrentChoice(result) {
|
function setCurrentChoice(result) {
|
||||||
document.querySelectorAll(".option-input").forEach(element => {
|
document.querySelectorAll(".option-input").forEach(element => {
|
||||||
|
if(!element.id) return;
|
||||||
taLog.log("Options restoring " + element.id + " = " + (isAPIKeyValue(element.id) ? "****************" : result[element.id]));
|
taLog.log("Options restoring " + element.id + " = " + (isAPIKeyValue(element.id) ? "****************" : result[element.id]));
|
||||||
switch (element.type) {
|
switch (element.type) {
|
||||||
case 'checkbox':
|
case 'checkbox':
|
||||||
|
|
@ -131,15 +172,28 @@ async function restoreOptions() {
|
||||||
if(element.id == 'default_chatgpt_lang') default_text_value = prefs_default.default_chatgpt_lang;
|
if(element.id == 'default_chatgpt_lang') default_text_value = prefs_default.default_chatgpt_lang;
|
||||||
element.value = result[element.id] || default_text_value;
|
element.value = result[element.id] || default_text_value;
|
||||||
break;
|
break;
|
||||||
|
case 'textarea':
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (element.tagName === 'SELECT') {
|
if (element.tagName === 'SELECT') {
|
||||||
let default_select_value = '';
|
let default_select_value = '';
|
||||||
if(element.id == 'reply_type') default_select_value = 'reply_all';
|
const restoreValue = result[element.id] || default_select_value;
|
||||||
if(element.id == 'connection_type') default_select_value = 'chatgpt_web';
|
// Check if option exists
|
||||||
element.value = result[element.id] || default_select_value;
|
let optionExists = Array.from(element.options).some(opt => opt.value === restoreValue);
|
||||||
if (element.value === '') {
|
// If it doesn't exist and restoreValue is not empty, create it
|
||||||
element.selectedIndex = -1;
|
if (!optionExists && restoreValue !== '') {
|
||||||
}
|
let newOption = new Option(restoreValue, restoreValue);
|
||||||
|
element.add(newOption);
|
||||||
|
}
|
||||||
|
// Set value
|
||||||
|
element.value = restoreValue;
|
||||||
|
if (element.value === '') {
|
||||||
|
element.selectedIndex = -1;
|
||||||
|
}
|
||||||
|
if (element.tomselect) {
|
||||||
|
element.tomselect.setValue(element.value, true);
|
||||||
|
setTomSelectBorder(element.tomselect);
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
console.error("[ThunderAI] Unhandled input type:", element.type);
|
console.error("[ThunderAI] Unhandled input type:", element.type);
|
||||||
}
|
}
|
||||||
|
|
@ -148,5 +202,27 @@ async function restoreOptions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let getting = await browser.storage.sync.get(prefs_default);
|
let getting = await browser.storage.sync.get(prefs_default);
|
||||||
|
|
||||||
|
let specialPrompts = await getSpecialPrompts();
|
||||||
|
let get_calendar_event_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_get_calendar_event');
|
||||||
|
|
||||||
|
if (get_calendar_event_prompt) {
|
||||||
|
if (get_calendar_event_prompt.api_type && get_calendar_event_prompt.api_type !== '') {
|
||||||
|
getting['get_calendar_event_connection_type'] = get_calendar_event_prompt.api_type;
|
||||||
|
} else {
|
||||||
|
getting['get_calendar_event_connection_type'] = getting['connection_type'];
|
||||||
|
}
|
||||||
|
for (const [integration, options] of Object.entries(integration_options_config)) {
|
||||||
|
for (const key of Object.keys(options)) {
|
||||||
|
const propName = `${integration}_${key}`;
|
||||||
|
if (get_calendar_event_prompt[propName] !== undefined && get_calendar_event_prompt[propName] !== '') {
|
||||||
|
getting[`get_calendar_event_${propName}`] = get_calendar_event_prompt[propName];
|
||||||
|
} else {
|
||||||
|
getting[`get_calendar_event_${propName}`] = getting[propName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setCurrentChoice(getting);
|
setCurrentChoice(getting);
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue