Skip to content

Commit

Permalink
Add translation for the order type
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Rusakov committed Nov 18, 2024
1 parent 4f76d6f commit 660abfb
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 70 deletions.
3 changes: 2 additions & 1 deletion src/app/_services/api-order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { catchError, flatMap, map } from 'rxjs/operators';
import { Contact, IContact } from '../_models/IContact';
import { GeoshopUtils } from '../_helpers/GeoshopUtils';
import { MatSnackBar } from '@angular/material/snack-bar';
import { ConstantsService } from '../constants.service';


@Injectable({
Expand Down Expand Up @@ -244,7 +245,7 @@ export class ApiOrderService {
);
}

public downloadResult(guid: string): Observable<HttpResponse<Blob|null>> {
public downloadResult(guid: string): Observable<HttpResponse<Blob | null>> {
this._getApiUrl();
const url = new URL(`${this.apiUrl}/download/${guid}/result`);
return this.http.get(url.toString(), {
Expand Down
2 changes: 1 addition & 1 deletion src/app/account/new-order/new-order.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<mat-select formControlName="orderType" required (selectionChange)="clearForms()"
[compareWith]="orderTypeCompareWith">
<mat-option *ngFor="let orderType of orderTypes" [value]="orderType">
{{orderType.name}}
{{getLocalizedTypeName(orderType)}}
</mat-option>
</mat-select>
<mat-error *ngIf="orderFormGroup.get('orderType')?.hasError('required')">{{ REQUIRED }}</mat-error>
Expand Down
114 changes: 63 additions & 51 deletions src/app/account/new-order/new-order.component.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import {Component, HostBinding, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators} from '@angular/forms';
import {ApiService} from '../../_services/api.service';
import {PHONE_REGEX, IDE_REGEX, EMAIL_REGEX, EXTRACT_FORBIDDEN_REGEX} from '../../_helpers/regex';
import {Observable, Subject} from 'rxjs';
import {IIdentity} from '../../_models/IIdentity';
import {debounceTime, filter, map, mergeMap, startWith, switchMap, takeUntil} from 'rxjs/operators';
import {IProduct} from '../../_models/IProduct';
import {select, Store} from '@ngrx/store';
import {AppState, getUser, selectOrder, selectAllProduct} from '../../_store';
import {MatSort} from '@angular/material/sort';
import {MatTableDataSource} from '@angular/material/table';
import {MatAutocompleteSelectedEvent} from '@angular/material/autocomplete';
import {IOrder, IOrderType, Order, IOrderItem} from '../../_models/IOrder';
import {ApiOrderService} from '../../_services/api-order.service';
import {MatStepper} from '@angular/material/stepper';
import {StoreService} from '../../_services/store.service';
import {MatSnackBar} from '@angular/material/snack-bar';
import {Contact, IContact} from '../../_models/IContact';
import {Router} from '@angular/router';
import { Component, HostBinding, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms';
import { ApiService } from '../../_services/api.service';
import { PHONE_REGEX, IDE_REGEX, EMAIL_REGEX, EXTRACT_FORBIDDEN_REGEX } from '../../_helpers/regex';
import { Observable, Subject } from 'rxjs';
import { IIdentity } from '../../_models/IIdentity';
import { debounceTime, filter, map, mergeMap, startWith, switchMap, takeUntil } from 'rxjs/operators';
import { IProduct } from '../../_models/IProduct';
import { select, Store } from '@ngrx/store';
import { AppState, getUser, selectOrder, selectAllProduct } from '../../_store';
import { MatSort } from '@angular/material/sort';
import { MatTableDataSource } from '@angular/material/table';
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
import { IOrder, IOrderType, Order, IOrderItem } from '../../_models/IOrder';
import { ApiOrderService } from '../../_services/api-order.service';
import { MatStepper } from '@angular/material/stepper';
import { StoreService } from '../../_services/store.service';
import { MatSnackBar } from '@angular/material/snack-bar';
import { Contact, IContact } from '../../_models/IContact';
import { Router } from '@angular/router';
import * as fromCart from '../../_store/cart/cart.action';
import {MatDialog, MatDialogRef} from '@angular/material/dialog';
import {ConfirmDialogComponent} from '../../_components/confirm-dialog/confirm-dialog.component';
import { MatDialog, MatDialogRef } from '@angular/material/dialog';
import { ConfirmDialogComponent } from '../../_components/confirm-dialog/confirm-dialog.component';
import { ConstantsService } from 'src/app/constants.service';

@Component({
Expand All @@ -33,7 +33,7 @@ export class NewOrderComponent implements OnInit, OnDestroy {
private onDestroy$ = new Subject<boolean>();

@HostBinding('class') class = 'main-container';
@ViewChild(MatSort, {static: true}) sort: MatSort;
@ViewChild(MatSort, { static: true }) sort: MatSort;
@ViewChild('stepper') stepper: MatStepper;

// constants
Expand All @@ -42,7 +42,7 @@ export class NewOrderComponent implements OnInit, OnDestroy {
readonly WRONG_PHONE = ConstantsService.WRONG_PHONE;
readonly NEXT = ConstantsService.NEXT;
readonly PREVIOUS = ConstantsService.PREVIOUS;
readonly BACK: string = $localize `Réinitialiser`;
readonly BACK: string = $localize`Réinitialiser`;


orderFormGroup: UntypedFormGroup;
Expand Down Expand Up @@ -73,7 +73,7 @@ export class NewOrderComponent implements OnInit, OnDestroy {
}

get IsOrderTypePrivate() {
return this.orderFormGroup?.get('orderType')?.value?.name === ConstantsService.ORDERTYPE_PRIVATE;
return this.orderFormGroup?.get('orderType')?.value?.name.startsWith('Priv');
}

get orderTypeCtrl() {
Expand Down Expand Up @@ -109,13 +109,13 @@ export class NewOrderComponent implements OnInit, OnDestroy {
}

constructor(private formBuilder: UntypedFormBuilder,
private apiOrderService: ApiOrderService,
private apiService: ApiService,
private storeService: StoreService,
private snackBar: MatSnackBar,
private router: Router,
private store: Store<AppState>,
private dialog: MatDialog) {
private apiOrderService: ApiOrderService,
private apiService: ApiService,
private storeService: StoreService,
private snackBar: MatSnackBar,
private router: Router,
private store: Store<AppState>,
private dialog: MatDialog) {

this.createForms();
}
Expand All @@ -130,7 +130,10 @@ export class NewOrderComponent implements OnInit, OnDestroy {

this.apiOrderService.getOrderTypes()
.pipe(takeUntil(this.onDestroy$))
.subscribe(orderTypes => this.orderTypes = orderTypes);
.subscribe(orderTypes => {
console.log(orderTypes);
this.orderTypes = orderTypes;
});

this.filteredCustomers$ = this.contactFormGroup.get('customer')?.valueChanges.pipe(
debounceTime(500),
Expand All @@ -151,7 +154,6 @@ export class NewOrderComponent implements OnInit, OnDestroy {
select(selectOrder),
switchMap(x => this.apiOrderService.getFullOrder(x)),
).subscribe(order => {
console.log("HERE: " + order);
if (order) {
this.currentOrder = order;
this.updateForms(this.currentOrder);
Expand Down Expand Up @@ -220,7 +222,7 @@ export class NewOrderComponent implements OnInit, OnDestroy {
});
this.orderTypeCtrl?.valueChanges.subscribe(
(choice) => {
if (choice.name === ConstantsService.ORDERTYPE_PRIVATE) {
if (choice.name === ConstantsService.ORDER_NAME.PRIVATE) {
this.addressChoiceCtrl?.setValue('1');
} else {
this.addressChoiceCtrl?.setValue('2');
Expand Down Expand Up @@ -324,9 +326,9 @@ export class NewOrderComponent implements OnInit, OnDestroy {

if (item.data_format && item.available_formats &&
item.available_formats.indexOf(item.data_format) > -1) {
itemFormControl.setValue(item.data_format);
}
itemFormControl.setValue(item.data_format);
}
}

// create table source only on order PUT, don't refresh table on PATCH
if (this.isOrderPatchLoading) {
Expand Down Expand Up @@ -498,22 +500,22 @@ export class NewOrderComponent implements OnInit, OnDestroy {
if (this.currentOrder.id === -1) {
this.currentOrder.invoiceContact = invoiceContact;
this.apiOrderService.createOrder(this.currentOrder.toPostAsJson, invoiceContact, this.IsAddressForCurrentUser)
.subscribe(newOrder => {
if (newOrder) {
this.resetCustomerForm();
this.storeService.addOrderToStore(new Order(newOrder as IOrder));
this.stepper.next();
}
});
.subscribe(newOrder => {
if (newOrder) {
this.resetCustomerForm();
this.storeService.addOrderToStore(new Order(newOrder as IOrder));
this.stepper.next();
}
});
} else {
this.apiOrderService.updateOrder(this.currentOrder, invoiceContact, this.IsAddressForCurrentUser)
.subscribe(newOrder => {
if (newOrder) {
this.resetCustomerForm();
this.storeService.addOrderToStore(new Order(newOrder as IOrder));
this.stepper.next();
}
});
.subscribe(newOrder => {
if (newOrder) {
this.resetCustomerForm();
this.storeService.addOrderToStore(new Order(newOrder as IOrder));
this.stepper.next();
}
});
}
}

Expand Down Expand Up @@ -611,4 +613,14 @@ export class NewOrderComponent implements OnInit, OnDestroy {
});
}
}

public getLocalizedTypeName(type: IOrderType): string {
switch (type.name) {
case 'Privé':
return ConstantsService.ORDER_NAME.PRIVATE;
case 'Public':
return ConstantsService.ORDER_NAME.PUBLIC;
};
return type.name;
}
}
5 changes: 5 additions & 0 deletions src/app/constants.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ export class ConstantsService {
// CONFIRM_REQUEST: $localize `:@@order.rejected:Rejected`, // TODO: looks not used
UNKNOWN: $localize `:@@order.unkown:Etat inconnu`
};

static ORDER_NAME = {
PUBLIC: $localize `:@@order.public:Public`,
PRIVATE: $localize `:@@order.private:Privé`
}
}
16 changes: 16 additions & 0 deletions src/locale/messages.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,22 @@
<context context-type="linenumber">33</context>
</context-group>
</trans-unit>
<trans-unit id="order.public" datatype="html">
<source>Public</source>
<target>Öffentlich</target>
<context-group purpose="location">
<context context-type="sourcefile">src/app/constants.service.ts</context>
<context context-type="linenumber">37</context>
</context-group>
</trans-unit>
<trans-unit id="order.private" datatype="html">
<source>Privé</source>
<target>Privat</target>
<context-group purpose="location">
<context context-type="sourcefile">src/app/constants.service.ts</context>
<context context-type="linenumber">38</context>
</context-group>
</trans-unit>
<trans-unit id="catalog_productSearch" datatype="html">
<source>Rechercher un produit...</source>
<target>Suche nach Produkt...</target>
Expand Down
16 changes: 16 additions & 0 deletions src/locale/messages.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,22 @@
<context context-type="linenumber">33</context>
</context-group>
</trans-unit>
<trans-unit id="order.public" datatype="html">
<source>Public</source>
<target>Public</target>
<context-group purpose="location">
<context context-type="sourcefile">src/app/constants.service.ts</context>
<context context-type="linenumber">37</context>
</context-group>
</trans-unit>
<trans-unit id="order.private" datatype="html">
<source>Privé</source>
<target>Private</target>
<context-group purpose="location">
<context context-type="sourcefile">src/app/constants.service.ts</context>
<context context-type="linenumber">38</context>
</context-group>
</trans-unit>
<trans-unit id="catalog_productSearch" datatype="html">
<source>Rechercher un produit...</source>
<context-group purpose="location">
Expand Down
34 changes: 17 additions & 17 deletions src/locale/messages.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,18 @@
<context context-type="linenumber">5</context>
</context-group>
</trans-unit>
<trans-unit id="help.pricing" datatype="html">
<source> Informations sur la tarificatio </source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/_components/help-overlay/help-overlay.component.html</context>
<context context-type="linenumber">9,11</context>
</context-group>
</trans-unit>
<trans-unit id="help.conditions" datatype="html">
<source> Conditions d&apos;utilisation </source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/_components/help-overlay/help-overlay.component.html</context>
<context context-type="linenumber">14,16</context>
</context-group>
</trans-unit>
<trans-unit id="b6b06490c915e07bc8ba7c88177574efa714af32" datatype="html">
<source>Avez-vous des questions ?</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/_components/help-overlay/help-overlay.component.html</context>
<context context-type="linenumber">19</context>
<context context-type="linenumber">12</context>
</context-group>
</trans-unit>
<trans-unit id="main.phone" datatype="html">
<source>phone</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/_components/help-overlay/help-overlay.component.html</context>
<context context-type="linenumber">23</context>
<context context-type="linenumber">16</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/account/profile/profile.component.html</context>
Expand All @@ -121,7 +107,7 @@
<source>email</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/_components/help-overlay/help-overlay.component.html</context>
<context context-type="linenumber">30</context>
<context context-type="linenumber">23</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/account/profile/profile.component.html</context>
Expand Down Expand Up @@ -892,6 +878,20 @@
<context context-type="linenumber">33</context>
</context-group>
</trans-unit>
<trans-unit id="order.public" datatype="html">
<source>Public</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/constants.service.ts</context>
<context context-type="linenumber">37</context>
</context-group>
</trans-unit>
<trans-unit id="order.private" datatype="html">
<source>Privé</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/constants.service.ts</context>
<context context-type="linenumber">38</context>
</context-group>
</trans-unit>
<trans-unit id="catalog_productSearch" datatype="html">
<source>Rechercher un produit...</source>
<context-group purpose="location">
Expand Down

0 comments on commit 660abfb

Please sign in to comment.