Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions copyfile.js

This file was deleted.

49 changes: 49 additions & 0 deletions generate-route-pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';

// GitHub Pages only serves real files, so deep links fall back to 404.html (HTTP 404).
// Emit a copy of index.html for every known route so they are served with HTTP 200.
// 404.html stays as the fallback for anything not listed here.

const { copyFileSync, mkdirSync, readFileSync } = require('fs');
const { join } = require('path');
const themes = require('devextreme-themebuilder/modules/themes').default;

const distDir = 'dist/devextreme-themebuilder-app';
const indexFile = join(distDir, 'index.html');

const menuRoutes = [...readFileSync('src/app/left-menu/left-menu.aliases.ts', 'utf8')
.matchAll(/route:\s*'([^']+)'/g)].map((m) => m[1]);
if(!menuRoutes.length) throw new Error('No routes found in left-menu.aliases.ts');

const themeNames = [...new Set(themes.map((t) => t.name))];

const routes = [
'master',
'import',
'import/bootstrap',
'import/meta',
'advanced',
...themeNames.flatMap((name) => [`preview/${name}`, `wizard/${name}`]),
...themes.flatMap(({ name, colorScheme }) => {
const advanced = `advanced/${name}/${colorScheme}`;
return [
`master/${name}/${colorScheme}`,
Comment thread
ajivanyandev marked this conversation as resolved.
advanced,
`${advanced}/datagrid`,
`${advanced}/treelist`,
`${advanced}/grids/datagrid`,
`${advanced}/grids/treelist`,
...menuRoutes.map((route) => `${advanced}/${route}`)
];
})
];

routes.forEach((route) => {
const dir = join(distDir, route);
mkdirSync(dir, { recursive: true });
copyFileSync(indexFile, join(dir, 'index.html'));
});

copyFileSync(indexFile, join(distDir, '404.html'));

console.log(`Generated ${routes.length} route pages`);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --configuration=production --base-href https://devexpress.github.io/ThemeBuilder/ && node ./copyfile.js",
"build": "ng build --configuration=production --base-href https://devexpress.github.io/ThemeBuilder/ && node ./generate-route-pages.js",
"lint-fix": "eslint --fix \"src/**/*.ts\"",
"lint": "eslint \"src/**/*.ts\"",
"test": "pnpm run lint && pnpm run build"
Expand Down
2 changes: 1 addition & 1 deletion src/app/iframe/iframe.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
if(this.theme !== params['theme']) {
this.loading.show();
this.theme = params['theme'];
this.url = document.getElementsByTagName('base')[0].href + (widget ? 'preview' : 'wizard') + '/' + this.theme;
this.url = document.getElementsByTagName('base')[0].href + (widget ? 'preview' : 'wizard') + '/' + this.theme + '/';
if(this.iframe) {
this.iframe.nativeElement.src = this.url;
}
Expand All @@ -49,7 +49,7 @@

receiveMessage(e: MessageEvent): void {
if(e.data.widget) {
this.router.navigate(['/advanced', this.metadataService.theme.name, this.metadataService.theme.colorScheme, e.data.widget]);

Check warning on line 52 in src/app/iframe/iframe.component.ts

View workflow job for this annotation

GitHub Actions / test

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}

if(e.data.hideLoading) {
Expand Down
4 changes: 3 additions & 1 deletion src/app/layouts/header/header.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@
display: flex;
}

.switcher-template .switcher-icon.editor {
.switcher-icon.editor {
margin-left: 11px;
padding: 3px;
height: 100%;
display: flex;
align-items: center;
}
Expand Down
14 changes: 5 additions & 9 deletions src/app/layouts/header/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
stylingMode="filled"
[grouped]="true"
groupTemplate="group"
displayExpr="text"
[displayExpr]="getDisplayText"
valueExpr="themeId"
fieldTemplate="field"
[fieldAddons]="{ beforeTemplate: 'fieldIcon' }"
[(value)]="currentThemeId"
(onValueChanged)="themeChanged($event)"
>
Expand All @@ -43,14 +43,10 @@
</dx-tooltip>
</div>
</div>
<div *dxTemplate="let data of 'field'">
<div class="switcher-template">
<div *dxTemplate="let data of 'fieldIcon'">
@if (data) {
<app-icon-theme-circle [theme]="data.text | lowercase" [small]="true" class="switcher-icon editor"></app-icon-theme-circle>
<dx-text-box
[value]="(data.name | titlecase) + ' ' + data.text"
[readOnly]="true"
></dx-text-box>
</div>
}
</div>
<div *dxTemplate="let data of 'item'">
<div class="switcher-template">
Expand Down
6 changes: 6 additions & 0 deletions src/app/layouts/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
subscription: Subscription;
currentThemeId: number;

getDisplayText = (item: { name: string; text: string } | null): string => {
if(!item) return '';
const name = item.name.toLowerCase().replace(/^\w/, (c) => c.toUpperCase());
return `${name} ${item.text}`;
};

constructor(private metadataService: MetadataRepositoryService, private route: Router) {}

themeChanged(e): void {
Expand All @@ -49,7 +55,7 @@
const urlParts = this.route.url.split('/');
const routeWidgetPosition = 4;
const widget = urlParts[routeWidgetPosition];
this.route.navigate(['advanced', theme, colorScheme, widget]);

Check warning on line 58 in src/app/layouts/header/header.component.ts

View workflow job for this annotation

GitHub Actions / test

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
} else {
this.currentThemeId = e.previousValue;
e.component.canceled = true;
Expand Down
34 changes: 12 additions & 22 deletions src/app/meta-repository.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Metadata } from './types/metadata';
export class MetadataRepositoryService {
private modifiedMetaCollection: ExportedItem[] = [];
private metadata: Metadata;
private metadataPromise: Promise<Metadata> | null = null;

theme: Theme = { name: 'generic', colorScheme: 'light' };
css = new BehaviorSubject<string>('');
Expand Down Expand Up @@ -57,14 +58,17 @@ export class MetadataRepositoryService {
}

private getMetadata(): Promise<Metadata> {
if(this.metadata) {
return Promise.resolve(this.metadata);
if(this.metadataPromise === null) {
this.metadataPromise = this.themeBuilder.getMetadata().then((metadata) => {
this.metadata = metadata;
return metadata;
}, (error) => {
this.metadataPromise = null;
throw error;
});
}

return this.themeBuilder.getMetadata().then((metadata) => {
if(!this.metadata) this.metadata = metadata;
return metadata;
});
return this.metadataPromise;
}

getData(): Promise<MetaItem[]> {
Expand Down Expand Up @@ -194,24 +198,10 @@ export class MetadataRepositoryService {
}

getVersion(): Promise<string> {
if(this.metadata) {
return Promise.resolve(this.metadata.version);
}

return this.getMetadata().then((metadata) => {
if(!this.metadata) this.metadata = metadata;
return metadata.version;
});
return this.getMetadata().then((metadata) => metadata.version);
}

getThemes(): Promise<ThemeConfig[]> {
if(this.metadata) {
return Promise.resolve(this.metadata.themes);
}

return this.getMetadata().then((metadata) => {
if(!this.metadata) this.metadata = metadata;
return metadata.themes;
});
return this.getMetadata().then((metadata) => metadata.themes);
}
}
Loading