aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx')
-rw-r--r--src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx62
1 files changed, 5 insertions, 57 deletions
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
index 405b32e8a..24a05fd71 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx
@@ -114,6 +114,11 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
};
@action setGSuggestedTemplates = (docs: Doc[]) => {
this._suggestedTemplates = docs;
+
+ const mainCollection = this._dataViz?.DocumentView?.().containerViewPath?.().lastElement()?.ComponentView as CollectionFreeFormView;
+ docs.forEach(doc => {
+ mainCollection.addDocument(doc);
+ });
};
@computed get docsToRender() {
@@ -398,63 +403,6 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> {
return this._layout.xMargin === layout.layout.xMargin && this._layout.yMargin === layout.layout.yMargin && this._layout.type === layout.layout.type && this._layout.columns === layout.columns;
};
- @action
- generateTemplates = async (inputText: string) => {
- ++this._callCount;
- const origCount = this._callCount;
-
- let prompt: string = `(#${origCount}) Please generate for the fields:`;
- this.selectedFields?.forEach(field => (prompt += ` ${field},`));
- prompt += ` (-----NOT A FIELD-----) Additional prompt: ${inputText}`;
-
- this._GPTLoading = true;
-
- try {
- const res = await gptAPICall(prompt, GPTCallType.TEMPLATE);
-
- if (res && this._callCount === origCount) {
- this._suggestedTemplates = [];
- const templates: { template_type: string; fieldVals: { title: string; tlx: string; tly: string; brx: string; bry: string }[] }[] = JSON.parse(res);
- this.createGeneratedTemplates(templates, 500, 500);
- }
- } catch (err) {
- console.error(err);
- }
- };
-
- @action
- createGeneratedTemplates = (layouts: { template_type: string; fieldVals: { title: string; tlx: string; tly: string; brx: string; bry: string }[] }[], tempWidth: number, tempHeight: number) => {
- const mainCollection = this._dataViz?.DocumentView?.().containerViewPath?.().lastElement()?.ComponentView as CollectionFreeFormView;
- const GPTTemplates: Doc[] = [];
-
- layouts.forEach(layout => {
- const fields: Doc[] = layout.fieldVals.map(field => {
- const left: number = (Number(field.tlx) * tempWidth) / 2;
- const top: number = Number(field.tly) * tempHeight / 2; //prettier-ignore
- const right: number = (Number(field.brx) * tempWidth) / 2;
- const bottom: number = Number(field.bry) * tempHeight / 2; //prettier-ignore
- const height = bottom - top;
- const width = right - left;
- const doc = !field.title.includes('$$')
- ? Docs.Create.TextDocument('', { _height: height, _width: width, title: field.title, x: left, y: top, _text_fontSize: `${height / 2}` })
- : Docs.Create.ImageDocument('', { _height: height, _width: width, title: field.title.replace(/\$\$/g, ''), x: left, y: top });
- return doc;
- });
-
- const template = Docs.Create.FreeformDocument(fields, { _height: tempHeight, _width: tempWidth, title: layout.template_type, x: 400000, y: 400000 });
-
- mainCollection.addDocument(template);
-
- GPTTemplates.push(template);
- });
-
- setTimeout(() => {
- this.setGSuggestedTemplates(GPTTemplates); /*GPTTemplates.forEach(template => mainCollection.removeDocument(template))*/
- }, 100);
-
- this.forceUpdate();
- };
-
editTemplate = (doc: Doc) => {
//this.closeMenu();
DocumentViewInternal.addDocTabFunc(doc, OpenWhere.addRight);