Skip to content

Commit

Permalink
closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Apr 24, 2024
1 parent af09d4e commit 098eaab
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 12 deletions.
1 change: 1 addition & 0 deletions interfaces/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export interface IProductDefinition {
export interface IProduct extends IProductDefinition {
filters: IProductFilter[];
subproducts: IProductDefinition[];
cardTemplate: string;
}
86 changes: 79 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@siemens/ngx-datatable": "^22.2.0",
"compress-json": "^2.1.2",
"csv-parse": "^5.3.2",
"handlebars": "^4.7.8",
"ionicons": "^6.0.3",
"lodash": "^4.17.21",
"luxon": "^3.1.0",
Expand Down
18 changes: 13 additions & 5 deletions src/app/card/card.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,26 @@

<ion-card-content>
<ion-list>
<ion-item *ngIf="cardData.text">
@if(cardData.text) {
<ion-item>
<ion-label text-wrap>
<div class="flavortext">
<em>{{ cardData.text }}</em>
<div>
<p>{{ cardData.text }}</p>
</div>

@if(template) {
<br>
<div [innerHTML]="template"></div>
}
</ion-label>
</ion-item>
}

<ion-item>
<ion-label text-wrap>
<ion-chip *ngFor="let tag of cardData.tags" color="primary" (click)="searchTag(tag)">{{ tag
}}</ion-chip>
@for(tag of cardData.tags; track tag) {
<ion-chip color="primary" (click)="searchTag(tag)">{{ tag }}</ion-chip>
}
</ion-label>
</ion-item>
</ion-list>
Expand Down
11 changes: 11 additions & 0 deletions src/app/card/card.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Component, inject, type OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { type ICard } from '../../../interfaces';
import { CardsService } from '../cards.service';
import { MetaService } from '../meta.service';

import Handlebars from 'handlebars';

@Component({
selector: 'app-card',
Expand All @@ -12,8 +15,10 @@ export class CardPage implements OnInit {
private router = inject(Router);
private route = inject(ActivatedRoute);
private cardsService = inject(CardsService);
private metaService = inject(MetaService);

public cardData: ICard | undefined = undefined;
public template = '';

ngOnInit() {
const cardId = this.route.snapshot.paramMap.get('id');
Expand All @@ -23,6 +28,12 @@ export class CardPage implements OnInit {
this.router.navigate(['/']);
return;
}

const template = this.metaService.getTemplateByProductId(
this.cardData.product
);
const compiledTemplate = Handlebars.compile(template);
this.template = compiledTemplate(this.cardData);
}

search(query: string) {
Expand Down
13 changes: 13 additions & 0 deletions src/app/meta.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { environment } from '../environments/environment';
})
export class MetaService {
private allProducts: IProduct[] = [];
private templatesByProductId: Record<string, string> = {};

public get products() {
return this.allProducts;
Expand All @@ -18,5 +19,17 @@ export class MetaService {
const realData = await metaData.json();

this.allProducts = realData;

this.loadTemplates();
}

private loadTemplates() {
this.allProducts.forEach((product) => {
this.templatesByProductId[product.id] = product.cardTemplate;
});
}

public getTemplateByProductId(productId: string): string {
return this.templatesByProductId[productId];
}
}

0 comments on commit 098eaab

Please sign in to comment.