Skip to content

Commit 92d2f3d

Browse files
authored
fix show prodChars (in2workspace#22)
* fix show prodChars * fix update control * back * version * fix tests * version fix * improve code * fix * new
1 parent aef36a4 commit 92d2f3d

File tree

14 files changed

+96
-85
lines changed

14 files changed

+96
-85
lines changed

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ name: isbe-catalog-ui
22

33
services:
44
catalog-ui:
5-
image: in2workspace/bae-frontend:v0.0.6
5+
image: in2workspace/bae-frontend:v0.0.7
66
container_name: isbe-catalog-ui
77
restart: always

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bae-frontend",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve",

src/app/guard/auth.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,4 @@ export class AuthService {
139139
return null;
140140
}
141141
}
142-
}
142+
}

src/app/offerings/gallery/gallery.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

8484
</section>
8585

86-
@if (products.length === 0){
86+
@if (products.length === 0 && !loading) {
8787
<div class="py-8 flex justify-center w-full lg:py-16">
8888
<div class="flex items-center p-4 mb-4 text-sm text-primary-100 rounded-lg bg-purple-50 dark:bg-secondary-200 dark:text-primary-50" role="alert">
8989
<svg class="flex-shrink-0 inline w-4 h-4 me-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">

src/app/pages/admin/categories/update-category/update-category.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ <h2 class="text-3xl font-bold text-primary-100 ml-4 dark:text-white">{{ 'UPDATE_
181181

182182

183183
<div class="flex w-full justify-items-end justify-end ml-4">
184-
<button type="button" (click)="updateCategory();" [disabled]="isCatValid()" [ngClass]="isCatValid() ? 'opacity-50' : 'hover:bg-primary-50'" class="flex text-white justify-end bg-primary-100 hover:bg-primary-50 focus:ring-4 focus:outline-none focus:ring-purple-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center">
184+
<button type="button" (click)="updateCategory();" [disabled]="!isCatValid()" [ngClass]="!isCatValid() ? 'opacity-50' : 'hover:bg-primary-50'" class="flex text-white justify-end bg-primary-100 hover:bg-primary-50 focus:ring-4 focus:outline-none focus:ring-purple-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center inline-flex items-center">
185185
{{ 'UPDATE_CATEGORIES._update' | translate }}
186186
<svg class="rtl:rotate-180 w-3.5 h-3.5 ms-2" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 10">
187187
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 5h12m0 0L9 1m4 4L9 9"/>

src/app/pages/admin/categories/update-category/update-category.component.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,15 @@ describe('UpdateCategoryComponent', () => {
111111
component.edited = false;
112112
component.catStatusDraft = 'Active';
113113
expect(component.generalForm.valid).toBe(false);
114-
expect(component.isCatValid()).toBe(true);
114+
expect(component.isCatValid()).toBe(false);
115115
component.generalForm.controls['name'].setValue('Valid Name');
116116
component.edited = true;
117117
component.catStatusDraft = 'Launched';
118118
expect(component.generalForm.valid).toBe(true);
119-
expect(component.isCatValid()).toBe(true);
119+
expect(component.isCatValid()).toBe(false);
120120

121121
component.edited = false;
122122
component.catStatusDraft = 'Active';
123-
expect(component.isCatValid()).toBe(false);
123+
expect(component.isCatValid()).toBe(true);
124124
});
125125
});

src/app/pages/admin/categories/update-category/update-category.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,9 @@ export class UpdateCategoryComponent implements OnInit {
459459
}
460460

461461
isCatValid(){
462-
if((this.edited && this.catStatusDraft !== 'Active')|| !this.generalForm.valid){
463-
return true;
462+
if((this.edited && this.catStatusDraft === 'Launched')|| !this.generalForm.valid){
463+
return false;
464464
}
465-
return false;
465+
return true;
466466
}
467467
}

src/app/pages/product-details/product-details.component.spec.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,5 @@ describe('ProductDetailsComponent', () => {
139139
expect(component.checkCustom).toBe(true);
140140
});
141141

142-
it('should filter out compliance and certification characteristics when prodSpec provided before ngOnInit', () => {
143-
component.prodSpec = {
144-
productSpecCharacteristic: [
145-
{ name: 'Compliance:VC' },
146-
{ name: 'Compliance:SelfAtt' },
147-
{ name: 'SomeChar' },
148-
{ name: 'CertA' }
149-
]
150-
} as any;
151-
component.ngOnInit();
152-
expect(component.prodChars.find((c:any) => c.name === 'SomeChar')).toBeTruthy();
153-
expect(component.prodChars.find((c:any) => c.name === 'Compliance:VC')).toBeUndefined();
154-
expect(component.prodChars.find((c:any) => c.name === 'Compliance:SelfAtt')).toBeUndefined();
155-
});
156142

157143
});

src/app/pages/product-details/product-details.component.ts

Lines changed: 71 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,52 +41,85 @@ export class ProductDetailsComponent implements OnInit {
4141
categoriesMore: any[] | undefined = [];
4242
category: string = 'none';
4343

44-
ngOnInit() {
45-
this.category = this.productOff?.category?.at(0)?.name ?? 'none';
46-
if(this.productOff?.category!=undefined&&this.productOff?.category.length>5){
47-
this.categories = this.productOff?.category.slice(0, 4);
48-
this.categoriesMore = this.productOff?.category.slice(4);
49-
this.checkMoreCats=true;
44+
ngOnInit(): void {
45+
this.initCategories();
46+
this.initImages();
47+
void this.initAsync();
48+
}
49+
50+
private async initAsync(): Promise<void> {
51+
await this.loadProductSpecificationAndPrices();
52+
this.filterCharacteristics();
53+
}
54+
55+
private initCategories(): void {
56+
const categories = this.productOff?.category ?? [];
57+
58+
this.category = categories[0]?.name ?? 'none';
59+
60+
if (categories.length > 5) {
61+
this.categories = categories.slice(0, 4);
62+
this.categoriesMore = categories.slice(4);
63+
this.checkMoreCats = true;
5064
} else {
51-
this.categories = this.productOff?.category;
52-
this.checkMoreCats=false;
65+
this.categories = categories;
66+
this.categoriesMore = [];
67+
this.checkMoreCats = false;
5368
}
54-
let profile = this.productOff?.attachment?.filter(item => item.name === 'Profile Picture') ?? [];
55-
if(profile.length==0){
56-
this.images = this.productOff?.attachment?.filter(item => item.attachmentType === 'Picture') ?? [];
57-
} else {
58-
this.images = profile;
69+
}
70+
71+
private initImages(): void {
72+
const attachments = this.productOff?.attachment ?? [];
73+
const profile = attachments.filter(item => item.name === 'Profile Picture');
74+
75+
this.images = profile.length > 0
76+
? profile
77+
: attachments.filter(item => item.attachmentType === 'Picture');
78+
}
79+
80+
private async loadProductSpecificationAndPrices(): Promise<void> {
81+
const specId = this.productOff?.productSpecification?.id;
82+
if (!specId) return;
83+
84+
try {
85+
this.prodSpec = await this.api.getProductSpecification(specId);
86+
87+
const prodPrices = this.productOff?.productOfferingPrice ?? [];
88+
if (prodPrices.length === 0) return;
89+
90+
const prices = await Promise.all(
91+
prodPrices.map(p => this.api.getProductPrice(p.id))
92+
);
93+
94+
this.checkCustom = prices.some(price => price.priceType === 'custom');
95+
} catch (error) {
96+
console.error('Error loading product specification or prices', error);
5997
}
60-
let specId = this.productOff?.productSpecification?.id;
61-
if(specId != undefined){
62-
this.api.getProductSpecification(specId).then(spec => {
63-
this.prodSpec = spec;
64-
let prodPrices: any[] | undefined= this.productOff?.productOfferingPrice;
65-
if(prodPrices!== undefined){
66-
for(const element of prodPrices){
67-
this.api.getProductPrice(element.id).then(price => {
68-
if(price.priceType == 'custom'){
69-
this.checkCustom=true;
70-
}
71-
})
72-
}
73-
}
74-
})
98+
}
99+
100+
private filterCharacteristics(): void {
101+
const characteristics = this.prodSpec?.productSpecCharacteristic;
102+
if (!characteristics) {
103+
this.prodChars = [];
104+
return;
75105
}
76-
if(this.prodSpec.productSpecCharacteristic != undefined) {
77-
this.prodChars = this.prodSpec.productSpecCharacteristic.filter((char: any) => {
78-
return char.name != 'Compliance:VC' && char.name != 'Compliance:SelfAtt'
79-
})
80-
81-
for(const element of certifications){
82-
const index = this.prodChars.findIndex(item => item.name === element.name);
83-
if(index!==-1){
84-
this.prodChars.splice(index, 1);
85-
}
106+
107+
this.prodChars = characteristics.filter((char: any) =>
108+
char.name !== 'Compliance:VC' && char.name !== 'Compliance:SelfAtt'
109+
);
110+
111+
for (const cert of certifications) {
112+
const index = this.prodChars.findIndex(
113+
(item: any) => item.name === cert.name
114+
);
115+
if (index !== -1) {
116+
this.prodChars.splice(index, 1);
86117
}
87118
}
88119
}
89120

121+
122+
90123
closeCategories(){
91124
this.closeCats=false;
92125
this.checkMoreCats=true;

0 commit comments

Comments
 (0)