Skip to content

Commit f615df9

Browse files
author
pipeline
committed
feature(EJ2-4949): Wrong Route handled in TypeScript Sample Browser for Production Branch
1 parent e37fe43 commit f615df9

File tree

5 files changed

+39
-14
lines changed

5 files changed

+39
-14
lines changed

src/accordion/sample.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "Accordion",
33
"directory": "accordion",
44
"category": "Navigation",
5-
"type": "new",
65
"samples": [
76
{
87
"url": "default",

src/common/index.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ let selectedTheme: string = location.hash.split('/')[1];
2020
let availableThemes: string[] = ['material', 'fabric', 'bootstrap'];
2121
let isHashChanged: boolean = true;
2222
let isButtonClick: boolean = false;
23+
let themeRegex: RegExp = /#\/(material|fabric|bootstrap)/i;
24+
let defaultSamples: any = [];
25+
let samplePath: string[] = [];
2326

2427
interface DestroyMethod extends HTMLElement {
2528
destroy: Function;
@@ -253,9 +256,22 @@ function routeDefault(): void {
253256
window.location.href = '#/' + selectedTheme + '/chart/line.html';
254257
isInitRedirected = true;
255258
});
256-
bypassed.add((request: Object) => {
257-
loadPage('404');
259+
bypassed.add((request: string) => {
260+
let hash: string[] = request.split('.html')[0].split('/');
261+
if (samplePath.indexOf(hash.slice(1).join('/')) === -1) {
262+
let path: string;
263+
for (let sample of samplePath) {
264+
if (sample.indexOf(hash[1] + '/') !== -1) {
265+
path = hash[0] + '/' + sample + '.html';
266+
break;
267+
}
268+
}
269+
location.hash = path ? path : '#/material/chart/line.html';
270+
location.hash = '#/' + hash[0] + '/' + (defaultSamples[hash[1]] || 'chart/line.html');
271+
isInitRedirected = true;
272+
}
258273
});
274+
259275
}
260276

261277
function wireEvents(): void {
@@ -296,12 +312,14 @@ function loadTheme(theme: string): void {
296312
}
297313
function addRoutes(samplesList: Controls[]): void {
298314
for (let node of samplesList) {
315+
defaultSamples[node.directory] = node.directory + '/' + node.samples[0].url + '.html';
299316
let dataManager: DataManager = new DataManager(node.samples);
300317
let samples: Samples[] & { [key: string]: Object }[] = <Samples[] & { [key: string]: Object }[]>
301318
dataManager.executeLocal(new Query().sortBy('order', 'ascending'));
302319
for (let subNode of samples) {
303320
let control: string = node.directory;
304321
let sample: string = subNode.url;
322+
samplePath = samplePath.concat(control + '/' + sample);
305323
let sampleName: string = node.name + ' / ' + ((node.name !== subNode.category) ?
306324
(subNode.category + ' / ') : '') + subNode.name;
307325
let selectedTheme: string = location.hash.split('/')[1] ? location.hash.split('/')[1] : 'material';
@@ -536,6 +554,16 @@ function parseHash(newHash: string, oldHash: string): void {
536554
function checkSampleLength(directory: string): boolean {
537555
let data: DataManager = new DataManager(samplesList);
538556
let controls: Controls[] = <Controls[]>data.executeLocal(new Query().where('directory', 'equal', directory));
557+
if (!controls.length) {
558+
let hash: string = location.hash;
559+
let split: string[] = hash.split('/');
560+
if (!themeRegex.test(hash) && split.length === 3) {
561+
location.hash = '#/material/' + split[1] + '/' + split[2];
562+
} else {
563+
location.hash = '#/material/chart/line.html';
564+
}
565+
location.reload();
566+
}
539567
return controls[0].samples.length > 1;
540568
}
541569

0 commit comments

Comments
 (0)