Skip to content

Commit

Permalink
Fix/minor code issues (#11)
Browse files Browse the repository at this point in the history
* fix: minor code issues

* fix: minor code issues

* fix: minor code issues
  • Loading branch information
HenryT-CG authored Jan 22, 2024
1 parent a21d73b commit 1ef18fb
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 115 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ COPY dist/onecx-product-store-ui/ $DIR_HTML
ENV BFF_URL http://onecx-product-store-bff:8080/
ENV APP_BASE_HREF /product-store/

RUN chmod 775 -R $DIR_HTML/assets
RUN chmod 775 -R "$DIR_HTML"/assets
USER 1001
Empty file removed src/app/app.component.scss
Empty file.
4 changes: 2 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Component } from '@angular/core'

@Component({
selector: 'ps-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
templateUrl: './app.component.html'
})
export class AppComponent {
title = 'product-store-ui'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ocx-page-header>
<ocx-page-content>
<div *ngIf="!loading && !product && changeMode !== 'CREATE'" class="card px-3 align-items-center">
<p-message severity="error" styleClass="p-2" [text]="'VALIDATION.PRODUCT.NOT_EXISTS' | translate"></p-message>
<p-message severity="error" styleClass="p-2" [text]="'ACTIONS.SEARCH.PRODUCT.NOT_EXISTS' | translate"></p-message>
</div>
<p-tabView *ngIf="(product && !loading) || changeMode === 'CREATE'">
<p-tabPanel id="product_detail_panel_props" [header]="'DIALOG.TABS.PROPERTIES' | translate">
Expand Down
15 changes: 9 additions & 6 deletions src/app/product-store/product-detail/product-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export class ProductDetailComponent implements OnInit {
}

ngOnInit(): void {
console.log('product detail ngOnInit()')
if (this.productName !== '') {
this.changeMode = 'VIEW'
this.loadProduct()
Expand Down Expand Up @@ -75,9 +74,10 @@ export class ProductDetailComponent implements OnInit {
this.prepareTranslations()
},
error: (err: any) => {
console.error('search: ', err)
this.msgService.error({
summaryKey: 'DIALOG.LOAD_ERROR'
// detailKey: err.error.indexOf('was not found') > 1 ? 'DIALOG.NOT_FOUND' : err.error
summaryKey: 'ACTIONS.SEARCH.PRODUCT.LOAD_ERROR'
// detailKey: err.error.indexOf('was not found') > 1 ? 'SEARCH.NOT_FOUND' : err.error
})
this.close()
}
Expand Down Expand Up @@ -196,6 +196,7 @@ export class ProductDetailComponent implements OnInit {
public onClose() {
this.close()
}

public onEdit() {
this.getProduct()
this.changeMode = 'EDIT'
Expand All @@ -214,21 +215,23 @@ export class ProductDetailComponent implements OnInit {
public onSave() {
this.productPropsComponent.onSubmit()
}

public onCreate(data: any) {
this.product = data
this.changeMode === 'VIEW'
this.changeMode = 'VIEW'
this.router.navigate(['./../', this.product?.name], { relativeTo: this.route })
}

public onChange(nameChanged: boolean) {
console.log('detail.onChange ')
if (nameChanged) {
this.close()
} else {
this.getProduct()
this.changeMode === 'VIEW'
this.changeMode = 'VIEW'
this.prepareTranslations()
}
}

public onDelete(ev: MouseEvent, item: Product): void {
ev.stopPropagation()
this.product = item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,79 +72,3 @@
</div>
</div>
</div>

<!--
<div class="surface-section grid grid-nogutter">
<div class="col-12 md:col-6">
<div class="col-12 md:col-6 p-3">
<span class="p-float-label">
<input
pInputText
type="text"
readonly
id="portal_detail_item_creationDate"
class="w-full pt-3 pb-2"
[value]="product?.creationDate | date : dateFormat"
[pTooltip]="'INTERNAL.TOOLTIPS.CREATION_DATE' | translate"
tooltipPosition="top"
tooltipEvent="focus"
/>
<label for="portal_detail_item_creationDate">{{ 'INTERNAL.CREATION_DATE' | translate }}</label>
</span>
</div>
<div class="col-12 md:col-6 p-3">
<span class="p-float-label">
<input
pInputText
type="text"
readonly
id="portal_detail_item_creationUser"
class="w-full pt-3 pb-2"
[value]="product?.creationUser"
[pTooltip]="'INTERNAL.TOOLTIPS.CREATION_USER' | translate"
tooltipPosition="top"
tooltipEvent="focus"
/>
<label for="portal_detail_item_creationUser">{{ 'INTERNAL.CREATION_USER' | translate }}</label>
</span>
</div>
</div>
<div class="col-12 md:col-6">
<div class="col-12 md:col-3 p-3">
<span class="p-float-label">
<input
pInputText
type="text"
readonly
id="portal_detail_item_modificationDate"
class="w-full pt-3 pb-2"
[value]="product?.modificationDate | date : dateFormat"
[pTooltip]="'INTERNAL.TOOLTIPS.MODIFICATION_DATE' | translate"
tooltipPosition="top"
tooltipEvent="focus"
/>
<label for="portal_detail_item_modificationDate">{{ 'INTERNAL.MODIFICATION_DATE' | translate }}</label>
</span>
</div>
<div class="col-12 md:col-3 p-3">
<span class="p-float-label">
<input
pInputText
type="text"
readonly
id="portal_detail_item_modificationUser"
class="w-full pt-3 pb-2"
[value]="product?.modificationUser"
[pTooltip]="'INTERNAL.TOOLTIPS.MODIFICATION_USER' | translate"
tooltipPosition="top"
tooltipEvent="focus"
/>
<label for="portal_detail_item_modificationUser">{{ 'INTERNAL.MODIFICATION_USER' | translate }}</label>
</span>
</div>
</div>
</div>
-->
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export class ProductPropertyComponent implements OnChanges {
})
.subscribe({
next: () => {
this.changeMode === 'VIEW'
this.msgService.success({ summaryKey: 'ACTIONS.EDIT.PRODUCT.OK' })
this.productChanged.emit(this.productName !== this.formGroup.value['name'])
},
Expand All @@ -148,12 +147,14 @@ export class ProductPropertyComponent implements OnChanges {
}

private displaySaveError(err: any) {
err.error && err.error.errorCode && err.error.errorCode === 'MERGE_ENTITY_FAILED' // 'PERSIST_ENTITY_FAILED'
? this.msgService.error({
summaryKey: 'ACTIONS.' + this.changeMode + '.PRODUCT.NOK',
detailKey: 'VALIDATION.PRODUCT.UNIQUE_CONSTRAINT'
})
: this.msgService.error({ summaryKey: 'ACTIONS.' + this.changeMode + '.PRODUCT.NOK' })
if (err.error?.errorCode === 'MERGE_ENTITY_FAILED') {
this.msgService.error({
summaryKey: 'ACTIONS.' + this.changeMode + '.PRODUCT.NOK',
detailKey: 'VALIDATION.PRODUCT.UNIQUE_CONSTRAINT'
})
} else {
this.msgService.error({ summaryKey: 'ACTIONS.' + this.changeMode + '.PRODUCT.NOK' })
}
}

/** File Handling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('ProductDetailComponent', () => {
component.ngOnInit()

expect(msgServiceSpy.error).toHaveBeenCalledWith({
summaryKey: 'DIALOG.LOAD_ERROR'
summaryKey: 'ACTIONS.SEARCH.PRODUCT.LOAD_ERROR'
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<ocx-page-content>
<div *ngIf="!product$" class="card px-3 align-items-center">
<p-message severity="error" styleClass="p-2" [text]="'VALIDATION.PRODUCT.NOT_EXISTS' | translate"></p-message>
<p-message severity="error" styleClass="p-2" [text]="'ACTIONS.SEARCH.PRODUCT.NOT_EXISTS' | translate"></p-message>
</div>
<ng-container *ngIf="product$ | async as products">
<p-dataView
Expand All @@ -31,6 +31,7 @@
[rowsPerPageOptions]="[10, 20, 50]"
[rows]="viewMode === 'grid' ? 12 : 10"
[layout]="viewMode"
[emptyMessage]="'ACTIONS.SEARCH.NOT_FOUND' | translate"
filterBy="name,displayName"
[sortField]="sortField"
[sortOrder]="sortOrder"
Expand Down
2 changes: 1 addition & 1 deletion src/app/shared/can-active-guard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const DEFAULT_LANG = 'en'
export class CanActivateGuard implements CanActivate {
constructor(private txService: TranslateService, private config: ConfigurationService) {}

/* eslint-disable @typescript-eslint/no-unused-vars */ /* TODO: is route and state needed */
/* eslint-disable @typescript-eslint/no-unused-vars */
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class ImageContainerComponent implements OnChanges {

// if image Url does not start with a http the api-prefix ...
// ...then it stored in the backend. So we need to put prefix in front
if (this.imageUrl && !this.imageUrl.match(/^(http|https)/g) && this.imageUrl.indexOf(this.apiPrefix) !== 0) {
if (this.imageUrl && !this.imageUrl.match(/^(http|https)/g) && !this.imageUrl.startsWith(this.apiPrefix)) {
this.imageUrl = this.apiPrefix + this.imageUrl
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/label.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { ActivatedRouteSnapshot, Resolve, RouterStateSnapshot } from '@angular/r
import { TranslateService } from '@ngx-translate/core'
import { Observable } from 'rxjs'

//dont use `providedIn root` - wont work when we are in shell
// don't use 'providedIn root' - wont work when we are in shell
@Injectable()
export class LabelResolver implements Resolve<string> {
constructor(private translate: TranslateService) {}
/* eslint-disable @typescript-eslint/no-unused-vars */ /* TODO: is state needed */
/* eslint-disable @typescript-eslint/no-unused-vars */
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): string | Observable<string> | Promise<string> {
return route.data['breadcrumb'] ? this.translate.instant(route.data['breadcrumb']) : route.routeConfig?.path
}
Expand Down
16 changes: 13 additions & 3 deletions src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@
"VIEW_MODE_LIST": "Listenansicht",
"VIEW_MODE_TABLE": "Tabellenansicht"
},
"SEARCH": {
"NOT_FOUND": "Keine Daten gefunden",
"APP": {
"NOT_EXISTS": "Eine App mit diesem Namen konnte nicht gefunden werden.",
"LOAD_ERROR": "App konnte nicht geladen werden",
"NOT_FOUND": "App nicht gefunden"
},
"PRODUCT": {
"NOT_EXISTS": "Ein Produkt mit diesem Namen konnte nicht gefunden werden.",
"LOAD_ERROR": "Produkt konnte nicht geladen werden",
"NOT_FOUND": "Produkt nicht gefunden"
}
},
"CANCEL": "Abbrechen",
"CHOOSE": "Auswählen",
"SAVE": "Speichern",
Expand Down Expand Up @@ -115,8 +128,6 @@
"SEARCH.HEADER": "Product Store",
"SEARCH.SUBHEADER": "Produkte und deren Apps verwalten",
"DETAIL.SUBHEADER": "Produkt Details",
"LOAD_ERROR": "Produkt konnte nicht geladen werden",
"NOT_FOUND": "Produkt nicht gefunden",
"TABS": {
"APPS": "Apps",
"INTERN": "Intern",
Expand Down Expand Up @@ -172,7 +183,6 @@
"VALIDATION": {
"FORM_INVALID": "Die Daten sind nicht bereit zum Speichern.",
"PRODUCT.UNIQUE_CONSTRAINT": "Ein Produkt mit diesem Namen existiert bereits.",
"PRODUCT.NOT_EXISTS": "Ein Produkt mit diesem Namen konnte nicht gefunden werden.",
"PRODUCT.INVALID_NAME": "Dieser Namen kann nicht verwendet werden.",
"ERRORS": {
"PARSE_ERROR": "Parserfehler: Die enthaltene Struktur entspricht nicht dem erwarteten Format.",
Expand Down
16 changes: 13 additions & 3 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@
"VIEW_MODE_LIST": "List view",
"VIEW_MODE_TABLE": "Table view"
},
"SEARCH": {
"NOT_FOUND": "No data found",
"APP": {
"PRODUCT.NOT_EXISTS": "An App with this name could not be found.",
"LOAD_ERROR": "Failed to load App",
"NOT_FOUND": "App was not found"
},
"PRODUCT": {
"PRODUCT.NOT_EXISTS": "A Product with this name could not be found.",
"LOAD_ERROR": "Failed to load Product",
"NOT_FOUND": "Product was not found"
}
},
"CANCEL": "Cancel",
"CHOOSE": "Choose",
"SAVE": "Save",
Expand Down Expand Up @@ -119,8 +132,6 @@
"SEARCH.HEADER": "Product Store",
"SEARCH.SUBHEADER": "Viewing and Managing Products and their Apps",
"DETAIL.SUBHEADER": "Product Details",
"LOAD_ERROR": "Failed to load Product",
"NOT_FOUND": "Product was not found",
"TABS": {
"APPS": "Apps",
"INTERN": "Internal",
Expand Down Expand Up @@ -176,7 +187,6 @@
"VALIDATION": {
"FORM_INVALID": "The data are not ready to store.",
"PRODUCT.UNIQUE_CONSTRAINT": "A Product with this name exists already.",
"PRODUCT.NOT_EXISTS": "A product with this name could not be found.",
"PRODUCT.INVALID_NAME": "This name is a reserved term and cannot be used.",
"ERRORS": {
"PARSE_ERROR": "Parse error: The contained structure does not match the expected format.",
Expand Down
6 changes: 5 additions & 1 deletion src/assets/silent-check-sso.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Post Message</title>
</head>
<body>
<script>
parent.postMessage(location.href, location.origin)
Expand Down
9 changes: 0 additions & 9 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,3 @@ export const environment = {
skipRemoteConfigLoad: true,
apiPrefix: 'product-store-bff'
}

/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/plugins/zone-error'; // Included with Angular CLI.

0 comments on commit 1ef18fb

Please sign in to comment.