aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2024-10-29 23:53:12 -0400
committerNathan-SR <144961007+Nathan-SR@users.noreply.github.com>2024-10-29 23:53:12 -0400
commite222d796534a2efaed48641c8e480f1b7982811b (patch)
tree6aaf1af2ea3ff001cd445521b577825de32f55df /src
parentde18eecdbd0ac99cdc78aef2dd477e341c28df76 (diff)
templates are being generated correctly
Diffstat (limited to 'src')
-rw-r--r--src/client/views/nodes/DataVizBox/DocCreatorMenu/DocCreatorMenu.tsx62
-rw-r--r--src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx6
-rw-r--r--src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx2
-rw-r--r--src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx8
-rw-r--r--src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx6
5 files changed, 17 insertions, 67 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);
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
index c47db2007..136392c07 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/DynamicField.tsx
@@ -88,15 +88,17 @@ export class DynamicField implements Field {
renderedDoc = (): Doc => {
switch (this.settings.viewType) {
case ViewType.CAROUSEL3D:
- const carouselDoc = Docs.Create.Carousel3DDocument([], {
+ const carouselDoc = Docs.Create.Carousel3DDocument(this.subfields.map(field => field.renderedDoc()), {
title: this.title,
});
FieldUtils.applyBasicOpts(carouselDoc, this.dimensions, this.settings);
+ return carouselDoc;
case ViewType.FREEFORM:
- const freeformDoc = Docs.Create.FreeformDocument([], {
+ const freeformDoc = Docs.Create.FreeformDocument(this.subfields.map(field => field.renderedDoc()), {
title: this.title,
});
FieldUtils.applyBasicOpts(freeformDoc, this.dimensions, this.settings);
+ return freeformDoc;
default:
return new Doc();
}
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
index feba6a8ef..aeeaa58dd 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/Field.tsx
@@ -14,7 +14,7 @@ export interface Field {
getTitle: () => string;
setTitle: (title: string) => void;
setupSubfields: () => Field[];
- renderedDoc: (content: string) => Doc;
+ renderedDoc: () => Doc;
matches: (cols: Col[]) => number[];
}
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx
index c389704cf..fdb74c544 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/FieldUtils.tsx
@@ -5,10 +5,10 @@ import { FieldDimensions, FieldSettings } from "./Field";
export class FieldUtils {
public static getLocalDimensions = (coords: { tl: [number, number]; br: [number, number] }, parentDimensions: FieldDimensions): FieldDimensions => {
- const l = (coords.tl[0] * parentDimensions.height) / 2;
- const t = coords.tl[1] * parentDimensions.width / 2; //prettier-ignore
- const r = (coords.br[0] * parentDimensions.height) / 2;
- const b = coords.br[1] * parentDimensions.width / 2; //prettier-ignore
+ const l = (coords.tl[0] * parentDimensions.width) / 2;
+ const t = coords.tl[1] * parentDimensions.height / 2; //prettier-ignore
+ const r = (coords.br[0] * parentDimensions.width) / 2;
+ const b = coords.br[1] * parentDimensions.height / 2; //prettier-ignore
const width = r - l;
const height = b - t;
const coord = { x: l, y: t };
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx
index a0b25485a..a56fa4fd6 100644
--- a/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx
+++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu/FieldTypes/StaticField.tsx
@@ -99,14 +99,14 @@ export class StaticField {
return matches;
};
- renderedDoc = (content: string): Doc => {
+ renderedDoc = (): Doc => {
const opts = this.settings.opts;
if (!this.contentType) { this.contentType = FieldContentType.STRING };
switch (this.contentType) {
case FieldContentType.STRING:
- const text = String(content);
+ const text = String(this.content);
const textDoc = Docs.Create.TextDocument(text, {
title: this.title,
text_fontColor: opts.color,
@@ -118,7 +118,7 @@ export class StaticField {
FieldUtils.applyBasicOpts(textDoc, this.dimensions, this.settings);
return textDoc;
case FieldContentType.IMAGE:
- const url = String(content);
+ const url = String(this.content);
const imgDoc = Docs.Create.ImageDocument(url, {
title: this.title,
_layout_fitWidth: false,