Update wireframe-renderer.component.ts
This commit is contained in:
parent
29b0bd033d
commit
d0a336928c
@ -957,6 +957,7 @@ private async checkAllExistingPages(expectedPages: string[]): Promise<Map<string
|
|||||||
private async checkSinglePage(pageName: string): Promise<string | null> {
|
private async checkSinglePage(pageName: string): Promise<string | null> {
|
||||||
const sanitizedPageName = this.sanitizeFilename(pageName);
|
const sanitizedPageName = this.sanitizeFilename(pageName);
|
||||||
|
|
||||||
|
console.log(sanitizedPageName)
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.siteTreeService.readPages(this.sitename, sanitizedPageName).subscribe({
|
this.siteTreeService.readPages(this.sitename, sanitizedPageName).subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
@ -3295,15 +3296,16 @@ createPageOrderFromJson(jsonInput: string): string[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async checkIfPageExists(siteName: string, pageName: string): Promise<boolean> {
|
async checkIfPageExists(siteName: string, pageName: string): Promise<boolean> {
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
this.siteTreeService.readPages(siteName, pageName).subscribe({
|
this.siteTreeService.readPages(this.formatSiteName(siteName), this.sanitizeFilename(pageName)).subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
// Adjust this check based on your API's actual response
|
// Adjust this check based on your API's actual response
|
||||||
if (response && (response.exists || (typeof response === 'string' && response.trim() !== '' && !response.includes('❌ File not found')))) {
|
if (response && (response.exists || (typeof response === 'string' && response.trim() !== '' && !response.includes('❌ File not found')))) {
|
||||||
console.log(`Page "${pageName}" exists in site "${siteName}"`);
|
console.log(`Page "${this.sanitizeFilename(pageName)}" exists in site "${this.formatSiteName(siteName)}"`);
|
||||||
resolve(true);
|
resolve(true);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Page "${pageName}" does not exist in site "${siteName}"`);
|
console.log(`Page "${this.sanitizeFilename(pageName)}" does not exist in site "${this.formatSiteName(siteName)}"`);
|
||||||
resolve(false);
|
resolve(false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -3324,7 +3326,7 @@ async mapOfExistingPagesWithHtmlCss(existingPages: string[]): Promise<void> {
|
|||||||
// Create promises for all page requests
|
// Create promises for all page requests
|
||||||
const pagePromises = existingPages.map(page => {
|
const pagePromises = existingPages.map(page => {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
this.siteTreeService.readPages(this.sitename, page).subscribe({
|
this.siteTreeService.readPages(this.formatSiteName(this.sitename), this.sanitizeFilename(page)).subscribe({
|
||||||
next: (response) => {
|
next: (response) => {
|
||||||
if (typeof response === 'string') {
|
if (typeof response === 'string') {
|
||||||
let htmlBody: string = response;
|
let htmlBody: string = response;
|
||||||
@ -3423,7 +3425,10 @@ calculateSectionHtmlsForExistingPage(pageName: string, htmlContent: string): voi
|
|||||||
// Create all pages first, then save them
|
// Create all pages first, then save them
|
||||||
let pagesToSave = new Map<string, string>();
|
let pagesToSave = new Map<string, string>();
|
||||||
|
|
||||||
|
let sanitizedPageName = '';
|
||||||
|
|
||||||
for (const pageName of missingPages) {
|
for (const pageName of missingPages) {
|
||||||
|
|
||||||
const pageDef = allPagesDef[pageName];
|
const pageDef = allPagesDef[pageName];
|
||||||
if (!pageDef) continue;
|
if (!pageDef) continue;
|
||||||
|
|
||||||
@ -3446,8 +3451,10 @@ calculateSectionHtmlsForExistingPage(pageName: string, htmlContent: string): voi
|
|||||||
sectionHtmls.push(html);
|
sectionHtmls.push(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sanitizedPageName = this.sanitizeFilename(pageName);
|
||||||
|
|
||||||
// Combine all section HTMLs and CSS for the page
|
// Combine all section HTMLs and CSS for the page
|
||||||
const finalHtml = this.createCompleteHtml(pageName, COMMON_CSS, sectionHtmls.join('\n'));
|
const finalHtml = this.createCompleteHtml(sanitizedPageName, COMMON_CSS, sectionHtmls.join('\n'));
|
||||||
|
|
||||||
this.pageSections[pageName] = { FullPage: finalHtml };
|
this.pageSections[pageName] = { FullPage: finalHtml };
|
||||||
this.mapofPageAndHtmlBody[pageName] = finalHtml;
|
this.mapofPageAndHtmlBody[pageName] = finalHtml;
|
||||||
@ -3457,34 +3464,42 @@ calculateSectionHtmlsForExistingPage(pageName: string, htmlContent: string): voi
|
|||||||
|
|
||||||
pagesToSave.set(pageName, finalHtml.toString());
|
pagesToSave.set(pageName, finalHtml.toString());
|
||||||
|
|
||||||
console.log(pagesToSave)
|
// Instead of saving all pages at once, save each page individually
|
||||||
|
for (const [pageName, html] of pagesToSave.entries()) {
|
||||||
this.siteTreeService.createHtmlfile(this.siteId, this.sitename, pagesToSave).subscribe({
|
|
||||||
next: (response) => {
|
const pageObj: Record<string, string> = { [pageName]: html };
|
||||||
console.log('All pages created successfully:', Array.from(pagesToSave.keys()));
|
// Ensure the page name is sanitized
|
||||||
this.toastr.success(`Generated and saved ${pagesToSave} pages successfully.`);
|
await new Promise<void>((resolve) => {
|
||||||
},
|
this.siteTreeService.createHtmlfile(this.siteId, this.sitename, pageObj).subscribe({
|
||||||
error: (error) => {
|
next: (response) => {
|
||||||
console.error('Error creating pages:', error);
|
console.log(`Page "${pageName}" created successfully.`);
|
||||||
this.toastr.error('Failed to save some generated pages.');
|
this.toastr.success(`Generated and saved page: ${pageName}`);
|
||||||
}
|
resolve();
|
||||||
});
|
},
|
||||||
|
error: (error) => {
|
||||||
|
console.error(`Error creating page "${pageName}":`, error);
|
||||||
|
this.toastr.error(`Failed to save generated page: ${pageName}`);
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save all pages at once after they're all created
|
// Save all pages at once after they're all created
|
||||||
if (pagesToSave.size > 0) {
|
// if (pagesToSave.size > 0) {
|
||||||
this.siteTreeService.createHtmlfile(this.siteId, this.sitename, pagesToSave).subscribe({
|
// this.siteTreeService.createHtmlfile(this.siteId, this.sitename, pagesToSave).subscribe({
|
||||||
next: (response) => {
|
// next: (response) => {
|
||||||
console.log('All pages created successfully:', Array.from(pagesToSave.keys()));
|
// console.log('All pages created successfully:', Array.from(pagesToSave.keys()));
|
||||||
this.toastr.success(`Generated and saved ${pagesToSave.size} pages successfully.`);
|
// this.toastr.success(`Generated and saved ${pagesToSave.size} pages successfully.`);
|
||||||
},
|
// },
|
||||||
error: (error) => {
|
// error: (error) => {
|
||||||
console.error('Error creating pages:', error);
|
// console.error('Error creating pages:', error);
|
||||||
this.toastr.error('Failed to save some generated pages.');
|
// this.toastr.error('Failed to save some generated pages.');
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
console.log('Map of All Pages with HTML:', this.mapofPageAndHtmlBody);
|
console.log('Map of All Pages with HTML:', this.mapofPageAndHtmlBody);
|
||||||
this.toastr.success('Generated all missing pages with AI.');
|
this.toastr.success('Generated all missing pages with AI.');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user