...
 
Commits (2)
......@@ -8,6 +8,7 @@ import { BcdData, BcdDataType, BrowserData, BrowserInfos } from './browser-compa
export type DataValue = (string | { [key: string]: DataValue })[];
export interface ChangePage { path: string[]; fileName: string; data: BcdDataType; }
const pattern = /^\/([^\/]+)\/(.*)$/;
@Injectable({
......@@ -22,7 +23,7 @@ export class AppService {
browsers: { [key: string]: BrowserInfos } = {};
data: { [key: string]: DataValue } = {};
page: BcdData;
pages: { [key: string]: ChangePage } = {};
constructor(
private http: HttpClient
......@@ -88,31 +89,43 @@ export class AppService {
for (const i in data.browsers) {
if (data.browsers[i]) {
this.browsers[i] = data.browsers[i];
this.browsers[i].id = i;
}
}
const tmp = this.browsers;
const browsers = {};
Object.values(tmp).sort((a, b) => a.name.localeCompare(b.name)).forEach(b => {
browsers[b.id] = b;
});
this.browsers = browsers;
console.log(browsers);
}
);
}
show(path: string) {
this.http
.get('./assets/browser-compat-data' + path, { responseType: 'json' })
.subscribe(
(data: BcdData) => {
const frag = path.split('/');
frag.shift();
const fileName = frag.pop().replace(/\.json/g, '');
let part: any = data;
for (let i = 0; i < frag.length; i++) {
part = part[frag[i]];
if (this.pages[path]) {
this.onChangePage.next(this.pages[path]);
} else {
this.http
.get('./assets/browser-compat-data' + path, { responseType: 'json' })
.subscribe(
(data: BcdData) => {
const frag = path.split('/');
frag.shift();
const fileName = frag.pop().replace(/\.json/g, '');
let part: any = data;
for (let i = 0; i < frag.length; i++) {
part = part[frag[i]];
}
this.pages[path] = {
path: frag,
fileName: fileName.replace(/_/g, ' '),
data: part[fileName]
};
this.onChangePage.next(this.pages[path]);
}
this.onChangePage.next({
path: frag,
fileName: fileName.replace(/_/g, ' '),
data: part[fileName]
});
}
);
);
}
}
}
......@@ -40,6 +40,7 @@ export interface BrowserInfos {
status: string
}
};
id: string;
}
......
......@@ -15,23 +15,20 @@ export class ElementLineComponent implements OnChanges {
browsers = [];
constructor(private appService: AppService) {
}
constructor(private appService: AppService) { }
ngOnChanges(changes: SimpleChanges) {
if (changes['element'].currentValue !== changes['element'].previousValue) {
setTimeout(() => {
const browser = this.appService.browsers;
this.browsers = [];
for (const i in browser) {
if (browser[i]) {
this.browsers.push({
id: i,
...this.element.support[i]
});
}
const browser = this.appService.browsers;
this.browsers = [];
for (const i in browser) {
if (browser[i]) {
this.browsers.push({
id: i,
...this.element.support[i]
});
}
});
}
}
}
......@@ -39,6 +36,4 @@ export class ElementLineComponent implements OnChanges {
return typeof data === 'object' && data.length;
}
}