mirror of
https://github.com/ONLYOFFICE/onlyoffice.github.io.git
synced 2026-04-07 14:04:30 +08:00
added a warning message
This commit is contained in:
@ -43,6 +43,21 @@ label {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#warning_text {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
padding-top: 8px;
|
||||||
|
gap: 12px;
|
||||||
|
line-height: 16px;
|
||||||
|
}
|
||||||
|
#warning_text svg {
|
||||||
|
margin-top: 7px;
|
||||||
|
}
|
||||||
|
#warning_text p {
|
||||||
|
width: calc(100% - 76px);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#custom_assistant {
|
#custom_assistant {
|
||||||
height: auto;
|
height: auto;
|
||||||
padding: 14px 0 8px 0;
|
padding: 14px 0 8px 0;
|
||||||
|
|||||||
@ -30,6 +30,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/// <reference path="./text-annotations/custom-annotations/manager.js" />
|
||||||
|
|
||||||
let settingsWindow = null;
|
let settingsWindow = null;
|
||||||
let aiModelsListWindow = null;
|
let aiModelsListWindow = null;
|
||||||
let aiModelEditWindow = null;
|
let aiModelEditWindow = null;
|
||||||
@ -961,7 +963,7 @@ async function onCheckGrammarSpelling(isCurrent)
|
|||||||
function customAssistantWindowShow(assistantId, buttonAssistant)
|
function customAssistantWindowShow(assistantId, buttonAssistant)
|
||||||
{
|
{
|
||||||
if (window.customAssistantWindow) {
|
if (window.customAssistantWindow) {
|
||||||
closeCustomAssistantWindow();
|
customAssistantWindowClose();
|
||||||
}
|
}
|
||||||
const actionButtonText = assistantId ? 'Save' : 'Create';
|
const actionButtonText = assistantId ? 'Save' : 'Create';
|
||||||
const description = assistantId ? 'Edit' : 'Create a new assistant';
|
const description = assistantId ? 'Edit' : 'Create a new assistant';
|
||||||
@ -1025,7 +1027,7 @@ function customAssistantWindowShow(assistantId, buttonAssistant)
|
|||||||
Asc.Buttons.updateToolbarMenu(window.buttonMainToolbar.id, window.buttonMainToolbar.name, [buttonAssistant]);
|
Asc.Buttons.updateToolbarMenu(window.buttonMainToolbar.id, window.buttonMainToolbar.name, [buttonAssistant]);
|
||||||
customAssistantManager.createAssistant(element);
|
customAssistantManager.createAssistant(element);
|
||||||
}
|
}
|
||||||
closeCustomAssistantWindow();
|
customAssistantWindowClose();
|
||||||
} else {
|
} else {
|
||||||
await window.pluginsButtonsCallback(id, windowId, ...args);
|
await window.pluginsButtonsCallback(id, windowId, ...args);
|
||||||
}
|
}
|
||||||
@ -1034,7 +1036,7 @@ function customAssistantWindowShow(assistantId, buttonAssistant)
|
|||||||
window.customAssistantWindow = customAssistantWindow;
|
window.customAssistantWindow = customAssistantWindow;
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeCustomAssistantWindow() {
|
function customAssistantWindowClose() {
|
||||||
if (window.customAssistantWindow) {
|
if (window.customAssistantWindow) {
|
||||||
window.customAssistantWindow.close();
|
window.customAssistantWindow.close();
|
||||||
window.customAssistantWindow = null;
|
window.customAssistantWindow = null;
|
||||||
@ -1050,7 +1052,7 @@ function closeCustomAssistantWindow() {
|
|||||||
*/
|
*/
|
||||||
function customAssistantWindowDeleteConfirm(assistantId, buttonAssistant) {
|
function customAssistantWindowDeleteConfirm(assistantId, buttonAssistant) {
|
||||||
if (window.customAssistantWindow) {
|
if (window.customAssistantWindow) {
|
||||||
closeCustomAssistantWindow();
|
customAssistantWindowClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
const savedAssistants = JSON.parse(
|
const savedAssistants = JSON.parse(
|
||||||
@ -1101,7 +1103,50 @@ if (window.customAssistantWindow) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closeCustomAssistantWindow();
|
customAssistantWindowClose();
|
||||||
|
} else {
|
||||||
|
await window.pluginsButtonsCallback(id, windowId, ...args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.customAssistantWindow = customAssistantWindow;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @param {localStorageCustomAssistantItem} assistantData
|
||||||
|
* @param {string} warningText
|
||||||
|
*/
|
||||||
|
function customAssistantWarning(assistantData, warningText) {
|
||||||
|
if (window.customAssistantWindow) {
|
||||||
|
customAssistantWindowClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
let variation = {
|
||||||
|
url : "customAssistant.html",
|
||||||
|
description : window.Asc.plugin.tr('Warning!'),
|
||||||
|
isVisual : true,
|
||||||
|
buttons : [
|
||||||
|
{ text: window.Asc.plugin.tr('Ok'), primary: true },
|
||||||
|
],
|
||||||
|
isModal : true,
|
||||||
|
isCanDocked: false,
|
||||||
|
type: "window",
|
||||||
|
EditorsSupport : ["word"],
|
||||||
|
size : [ 350, 76 ]
|
||||||
|
};
|
||||||
|
|
||||||
|
const customAssistantWindow = new window.Asc.PluginWindow();
|
||||||
|
customAssistantWindow.attachEvent("onWindowReady", function() {
|
||||||
|
Asc.Editor.callMethod("ResizeWindow", [customAssistantWindow.id, [350, 76], [350, 76], [0, 0]]);
|
||||||
|
customAssistantWindow.command('onWarningAssistant', warningText);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
customAssistantWindow.show(variation);
|
||||||
|
|
||||||
|
window.pluginsButtonsCallback = window.Asc.plugin.button;
|
||||||
|
window.Asc.plugin.button = async function(id, windowId, ...args) {
|
||||||
|
if (customAssistantWindow && windowId === customAssistantWindow.id) {
|
||||||
|
customAssistantWindowClose();
|
||||||
} else {
|
} else {
|
||||||
await window.pluginsButtonsCallback(id, windowId, ...args);
|
await window.pluginsButtonsCallback(id, windowId, ...args);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -110,6 +110,20 @@
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
window.Asc.plugin.attachEvent(
|
||||||
|
"onWarningAssistant",
|
||||||
|
(/** @type {string} */ warningText) => {
|
||||||
|
const image = '<svg width="44" height="39" viewBox="0 0 44 39" fill="none" xmlns="http://www.w3.org/2000/svg">' +
|
||||||
|
'<path d="M20.5201 0.853631C21.1693 -0.284655 22.8103 -0.284653 23.4594 0.853633L43.7548 36.4414C44.398 37.5693 43.5835 38.9714 42.2851 38.9714H1.69445C0.396056 38.9714 -0.418416 37.5693 0.224796 36.4414L20.5201 0.853631Z" fill="#F2BE08"/>' +
|
||||||
|
'<circle cx="21.99" cy="32.4614" r="2.51612" fill="white"/>' +
|
||||||
|
'<path d="M25.3447 12.3324C25.3447 13.1968 24.33 17.5992 23.6672 21.5581C23.0761 25.0894 22.8285 28.2678 22.8285 28.2678C22.4092 28.2678 21.7103 28.2678 21.1511 28.2678C21.1511 28.2678 20.9036 25.0894 20.3124 21.5581C19.6496 17.5992 18.635 13.1968 18.635 12.3324C18.635 10.4795 20.137 8.97754 21.9898 8.97754C23.8427 8.97754 25.3447 10.4795 25.3447 12.3324Z" fill="white"/>' +
|
||||||
|
'</svg>';
|
||||||
|
const text = '<div id="warning_text" class="noselect">' +
|
||||||
|
image + '<p>' + window.Asc.plugin.tr(warningText) + '</p></div>'
|
||||||
|
mainContainer.innerHTML = image + text;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
function onThemeChanged(theme) {
|
function onThemeChanged(theme) {
|
||||||
window.Asc.plugin.onThemeChangedBase(theme);
|
window.Asc.plugin.onThemeChangedBase(theme);
|
||||||
updateBodyThemeClasses(theme.type, theme.name);
|
updateBodyThemeClasses(theme.type, theme.name);
|
||||||
|
|||||||
@ -51,6 +51,7 @@ Object.assign(CustomAnnotator.prototype, {
|
|||||||
* @param {string} paraId
|
* @param {string} paraId
|
||||||
* @param {string} recalcId
|
* @param {string} recalcId
|
||||||
* @param {string} text
|
* @param {string} text
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
annotateParagraph: async function (paraId, recalcId, text) {
|
annotateParagraph: async function (paraId, recalcId, text) {
|
||||||
this.paragraphs[paraId] = {};
|
this.paragraphs[paraId] = {};
|
||||||
@ -60,7 +61,10 @@ Object.assign(CustomAnnotator.prototype, {
|
|||||||
const argPrompt = this._createPrompt(text);
|
const argPrompt = this._createPrompt(text);
|
||||||
|
|
||||||
let response = await this.chatRequest(argPrompt);
|
let response = await this.chatRequest(argPrompt);
|
||||||
if (!response) return false;
|
|
||||||
|
if (!response || response === '[]') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ranges = this._convertToRanges(paraId, text, JSON.parse(response));
|
const ranges = this._convertToRanges(paraId, text, JSON.parse(response));
|
||||||
@ -73,6 +77,8 @@ Object.assign(CustomAnnotator.prototype, {
|
|||||||
};
|
};
|
||||||
await Asc.Editor.callMethod("AnnotateParagraph", [obj]);
|
await Asc.Editor.callMethod("AnnotateParagraph", [obj]);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @param {string} paraId
|
* @param {string} paraId
|
||||||
@ -103,18 +109,19 @@ Object.assign(CustomAnnotator.prototype, {
|
|||||||
|
|
||||||
if (annot["original"] !== text.substring(start, start + len)) {
|
if (annot["original"] !== text.substring(start, start + len)) {
|
||||||
let annotRange = this.getAnnotationRangeObj(paraId, rangeId);
|
let annotRange = this.getAnnotationRangeObj(paraId, rangeId);
|
||||||
Asc.Editor.callMethod("RemoveAnnotationRange", [annotRange]);
|
return Asc.Editor.callMethod("RemoveAnnotationRange", [annotRange]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @param {string[]} paraIds
|
* @param {string[]} paraIds
|
||||||
|
* @returns {Promise<boolean[]>}
|
||||||
*/
|
*/
|
||||||
checkParagraphs: async function (paraIds) {
|
checkParagraphs: async function (paraIds) {
|
||||||
if (this._skipNextChangeParagraph) {
|
if (this._skipNextChangeParagraph) {
|
||||||
this._skipNextChangeParagraph = false;
|
this._skipNextChangeParagraph = false;
|
||||||
return;
|
return paraIds.map(() => false);
|
||||||
}
|
}
|
||||||
TextAnnotator.prototype.checkParagraphs.call(this, paraIds);
|
return await TextAnnotator.prototype.checkParagraphs.call(this, paraIds);
|
||||||
},
|
},
|
||||||
onAccept: async function (paraId, rangeId) {
|
onAccept: async function (paraId, rangeId) {
|
||||||
this._skipNextChangeParagraph = true;
|
this._skipNextChangeParagraph = true;
|
||||||
|
|||||||
@ -140,7 +140,7 @@ class CustomAssistantManager {
|
|||||||
* @param {string} assistantId
|
* @param {string} assistantId
|
||||||
* @param {string[]} paraIds
|
* @param {string[]} paraIds
|
||||||
*/
|
*/
|
||||||
run(assistantId, paraIds) {
|
async run(assistantId, paraIds) {
|
||||||
const assistant = this._customAssistants.get(assistantId);
|
const assistant = this._customAssistants.get(assistantId);
|
||||||
if (!assistant) {
|
if (!assistant) {
|
||||||
console.error("Custom assistant not found: " + assistantId);
|
console.error("Custom assistant not found: " + assistantId);
|
||||||
@ -148,17 +148,32 @@ class CustomAssistantManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this._isCustomAssistantInit.get(assistantId)) {
|
if (!this._isCustomAssistantInit.get(assistantId)) {
|
||||||
|
/** @type {Promise<boolean>[]} */
|
||||||
|
const promises = [];
|
||||||
this._paragraphsStack.forEach((value, paraId) => {
|
this._paragraphsStack.forEach((value, paraId) => {
|
||||||
assistant.onChangeParagraph(
|
const promise = assistant.onChangeParagraph(
|
||||||
paraId,
|
paraId,
|
||||||
value.recalcId,
|
value.recalcId,
|
||||||
value.text,
|
value.text,
|
||||||
value.annotations,
|
value.annotations,
|
||||||
);
|
);
|
||||||
|
promises.push(promise);
|
||||||
});
|
});
|
||||||
|
await Promise.all(promises);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @type {boolean[]} */
|
||||||
|
const isParagraphsChecked = await assistant.checkParagraphs(paraIds);
|
||||||
|
|
||||||
|
if (
|
||||||
|
isParagraphsChecked &&
|
||||||
|
isParagraphsChecked.length &&
|
||||||
|
isParagraphsChecked.every(isDone => !isDone)
|
||||||
|
) {
|
||||||
|
const warningMessage = "Not able to perform this action. Please use prompts related to text analysis, editing, or formatting.";
|
||||||
|
customAssistantWarning(assistant.assistantData, warningMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
assistant.checkParagraphs(paraIds);
|
|
||||||
this._isCustomAssistantInit.set(assistantId, true);
|
this._isCustomAssistantInit.set(assistantId, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -50,19 +50,21 @@ function TextAnnotator(annotatorPopup)
|
|||||||
* @param {string} recalcId
|
* @param {string} recalcId
|
||||||
* @param {string} text
|
* @param {string} text
|
||||||
* @param {string[]} ranges
|
* @param {string[]} ranges
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
TextAnnotator.prototype.onChangeParagraph = async function(paraId, recalcId, text, ranges)
|
TextAnnotator.prototype.onChangeParagraph = async function(paraId, recalcId, text, ranges)
|
||||||
{
|
{
|
||||||
this._handleNewRanges(ranges, paraId, text);
|
await this._handleNewRanges(ranges, paraId, text);
|
||||||
this.waitParagraphs[paraId] = {
|
this.waitParagraphs[paraId] = {
|
||||||
recalcId : recalcId,
|
recalcId : recalcId,
|
||||||
text : text
|
text : text
|
||||||
};
|
};
|
||||||
|
|
||||||
this._checkParagraph(paraId);
|
return this._checkParagraph(paraId);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @param {string[]} paraIds
|
* @param {string[]} paraIds
|
||||||
|
* @returns {Promise<boolean[]>}
|
||||||
*/
|
*/
|
||||||
TextAnnotator.prototype.checkParagraphs = async function(paraIds)
|
TextAnnotator.prototype.checkParagraphs = async function(paraIds)
|
||||||
{
|
{
|
||||||
@ -73,12 +75,19 @@ TextAnnotator.prototype.checkParagraphs = async function(paraIds)
|
|||||||
_t.paraToCheck.add(paraId);
|
_t.paraToCheck.add(paraId);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.paraToCheck.forEach(paraId => this._checkParagraph(paraId));
|
/** @type {Promise<boolean>[]} */
|
||||||
|
const promises = [];
|
||||||
|
this.paraToCheck.forEach(paraId => {promises.push(this._checkParagraph(paraId))});
|
||||||
|
return Promise.all(promises);
|
||||||
};
|
};
|
||||||
|
/**
|
||||||
|
* @param {string} paraId
|
||||||
|
* @returns {Promise<boolean>}
|
||||||
|
*/
|
||||||
TextAnnotator.prototype._checkParagraph = async function(paraId)
|
TextAnnotator.prototype._checkParagraph = async function(paraId)
|
||||||
{
|
{
|
||||||
if (!this.paraToCheck.has(paraId) || !this.waitParagraphs[paraId])
|
if (!this.paraToCheck.has(paraId) || !this.waitParagraphs[paraId])
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
let recalcId = this.waitParagraphs[paraId].recalcId;
|
let recalcId = this.waitParagraphs[paraId].recalcId;
|
||||||
let text = this.waitParagraphs[paraId].text;
|
let text = this.waitParagraphs[paraId].text;
|
||||||
@ -88,12 +97,14 @@ TextAnnotator.prototype._checkParagraph = async function(paraId)
|
|||||||
range["rangeId"] = undefined;
|
range["rangeId"] = undefined;
|
||||||
range["all"] = true;
|
range["all"] = true;
|
||||||
await Asc.Editor.callMethod("RemoveAnnotationRange", [range]);
|
await Asc.Editor.callMethod("RemoveAnnotationRange", [range]);
|
||||||
await this.annotateParagraph(paraId, recalcId, text);
|
const isAnnotate = await this.annotateParagraph(paraId, recalcId, text);
|
||||||
|
|
||||||
delete this.waitParagraphs[paraId];
|
delete this.waitParagraphs[paraId];
|
||||||
this.paraToCheck.delete(paraId);
|
this.paraToCheck.delete(paraId);
|
||||||
|
|
||||||
this.checked.add(paraId);
|
this.checked.add(paraId);
|
||||||
|
|
||||||
|
return isAnnotate;
|
||||||
};
|
};
|
||||||
TextAnnotator.prototype.annotateParagraph = async function(paraId, recalcId, text)
|
TextAnnotator.prototype.annotateParagraph = async function(paraId, recalcId, text)
|
||||||
{
|
{
|
||||||
@ -174,17 +185,18 @@ TextAnnotator.prototype.resetCurrentRange = function()
|
|||||||
this.paraId = null;
|
this.paraId = null;
|
||||||
this.rangeId = null;
|
this.rangeId = null;
|
||||||
};
|
};
|
||||||
TextAnnotator.prototype._handleNewRanges = function(ranges, paraId, text)
|
TextAnnotator.prototype._handleNewRanges = async function(ranges, paraId, text)
|
||||||
{
|
{
|
||||||
if (!ranges || !Array.isArray(ranges))
|
if (!ranges || !Array.isArray(ranges))
|
||||||
return;
|
return;
|
||||||
|
const promises = [];
|
||||||
ranges.forEach(range => this._handleNewRangePositions(range, paraId, text));
|
|
||||||
// ↓↓↓ TODO: the cycle seems to make no sense ↓↓↓
|
|
||||||
for (let i = 0; i < ranges.length; ++i)
|
for (let i = 0; i < ranges.length; ++i)
|
||||||
{
|
{
|
||||||
this._handleNewRangePositions(ranges[i]);
|
promises[i] = this._handleNewRangePositions(ranges[i], paraId, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Promise.all(promises);
|
||||||
};
|
};
|
||||||
TextAnnotator.prototype._handleNewRangePositions = function(range, paraId, text)
|
TextAnnotator.prototype._handleNewRangePositions = function(range, paraId, text)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user