diff options
author | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-09-02 19:15:49 -0400 |
---|---|---|
committer | Nathan-SR <144961007+Nathan-SR@users.noreply.github.com> | 2024-09-02 19:15:49 -0400 |
commit | 0581f0943aad45fae70bb34e61fa219121d64b8f (patch) | |
tree | 7624c15fe5610554d123be9667ec61439397a7f7 /src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx | |
parent | 39d02461d9c530996cdcd5fbac4fe3a932550c4a (diff) |
default content for columns in preview templates
Diffstat (limited to 'src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx')
-rw-r--r-- | src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx index fd5e58ae9..e36adc40a 100644 --- a/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx +++ b/src/client/views/nodes/DataVizBox/DocCreatorMenu.tsx @@ -136,8 +136,9 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { } @computed get fieldsInfos(): Col[] { - const colInfo = this._dataViz?.colInfo; - return this.selectedFields.map(field => {return {title: field, type: colInfo?.get(field)?.type ?? TemplateFieldType.UNSET, desc: colInfo?.get(field)?.desc ?? '', size: colInfo?.get(field)?.size ?? TemplateFieldSize.MEDIUM}}).concat(this._columns); + const colInfo = this._dataViz?.colsInfo; + return this.selectedFields.map(field => {return {title: field, type: colInfo?.get(field)?.type ?? TemplateFieldType.UNSET, desc: colInfo?.get(field)?.desc ?? '', size: colInfo?.get(field)?.size ?? TemplateFieldSize.MEDIUM, defaultContent: colInfo?.get(field)?.defaultContent ?? ''}}); + //.concat(this._columns) } @computed get canMakeDocs(){ @@ -429,7 +430,9 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { // this.createEmptyTemplate(temp, assignments); - this.generatePresetTemplates([TemplateLayouts.FourField001, TemplateLayouts.FourField002], this.fieldsInfos); + this.generatePresetTemplates(this.findValidTemplates(this.fieldsInfos, TemplateLayouts.allTemplates), this.fieldsInfos); + // console.log(this._dataViz?.colsInfo.get("IMG")?.size, this._dataViz?.colsInfo.get("IMG")?.type) + // console.log(this.fieldsInfos) }; @action addField = () => { @@ -533,7 +536,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { findValidTemplates = (cols: Col[], templates: TemplateDocInfos[]) => { - const validTemplates: string[] = []; + let validTemplates: any[] = []; templates.forEach(template => { const numFields = template.fields.length; const matches = this.matchesForTemplate(template, cols); @@ -542,6 +545,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { } }) + validTemplates = validTemplates.map(title => TemplateLayouts.fieldByTitle(title)); return validTemplates; }; @@ -579,7 +583,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { template.height, template.width, col.title, - '', + col.defaultContent ?? '', field.opts ); @@ -630,7 +634,7 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { compileColDescriptions = (cols: Col[]): string => { let descriptions: string = ''; - cols.forEach(col => descriptions += `{"${col.title} column: ${col.desc}} `); + cols.forEach(col => descriptions += `{title: ${col.title}, size: ${col.size}, type: ${col.type}, descreiption: ${col.desc}} `); return descriptions; }; @@ -644,8 +648,6 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { const inputText = fieldDescriptions.concat(colDescriptions); - console.log(inputText) - ++this._callCount; const origCount = this._callCount; @@ -659,18 +661,15 @@ export class DocCreatorMenu extends ObservableReactComponent<FieldViewProps> { if (res && this._callCount === origCount) { this._GPTLoading = false; const assignments: {[templateTitle: string]: {[field: string]: string}} = JSON.parse(res); - console.log(assignments); const brokenDownAssignments: [TemplateDocInfos, {[field: number]: Col}][] = []; Object.entries(assignments).forEach(([tempTitle, assignment]) => { const template = TemplateLayouts.fieldByTitle(tempTitle); - console.log('template', template) - if (!template) {console.log('returned'); return}; + if (!template) return; + console.log(assignments) const toObj = Object.entries(assignment).reduce((a, [fieldNum, colTitle]) => { - console.log('hey', a, fieldNum, colTitle) a[Number(fieldNum)] = this.getColByTitle(colTitle); return a; }, {} as { [field: number]: Col }); - console.log('obj', toObj) brokenDownAssignments.push([template, toObj]) }) return brokenDownAssignments; @@ -1213,6 +1212,7 @@ export type Col = { desc: string; title: string; type: TemplateFieldType; + defaultContent?: string; } type Field = { @@ -1295,7 +1295,7 @@ export class FieldFuncs { } currTextHeight = rowsCount * currFontSize * (uppercase ? 1.25 : 1); - console.log(rowsCount, currTextHeight) + //console.log(rowsCount, currTextHeight) currFontSize += 1; } @@ -1342,14 +1342,14 @@ export class FieldFuncs { const bool = true; - const docWithBasicOpts = (Docs.Create.TextDocument)('Fluorite is a very', { + const docWithBasicOpts = (Docs.Create.TextDocument)(content, { isDefaultTemplateDoc: true, _height: height, _width: width, title: title, x: coord.x, y: coord.y, - _text_fontSize: `${FieldFuncs.calculateFontSize(width, height, 'Fluorite is a very', true)}` , + _text_fontSize: `${FieldFuncs.calculateFontSize(width, height, content, true)}` , backgroundColor: opts.backgroundColor ?? '', text_fontColor: opts.color, contentBold: opts.fontBold, @@ -1401,6 +1401,12 @@ export class FieldFuncs { export class TemplateLayouts { + public static get allTemplates(): TemplateDocInfos[] { + return Object.values(TemplateLayouts).filter( + value => typeof value === 'object' && value !== null && 'title' in value + ) as TemplateDocInfos[]; + } + public static fieldByTitle = (title: string): TemplateDocInfos | undefined => { switch (title){ case 'fourfield1': @@ -1438,6 +1444,7 @@ export class TemplateLayouts { backgroundColor: 'transparent', color: '#F1F0E9', contentXCentering: 'h-center', + fontBold: true, } }, { tl: [-.87, -.83], |