Skip to content

Commit

Permalink
Product brand
Browse files Browse the repository at this point in the history
  • Loading branch information
shopizer-ecommerce committed May 24, 2022
1 parent bdf03fd commit 5c51aaa
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class BrandFormComponent implements OnInit {
@Input() title;
form: FormGroup;
loader = false;
defaultLanguage = localStorage.getItem('lang');
languages = [];
config = {
placeholder: '',
Expand Down Expand Up @@ -66,7 +67,7 @@ export class BrandFormComponent implements OnInit {
this.form = this.fb.group({
code: ['', [Validators.required, Validators.pattern(validators.alphanumeric)]],
order: ['', [Validators.required, Validators.pattern(validators.number)]],
selectedLanguage: ['en', [Validators.required]],
selectedLanguage: [this.defaultLanguage, [Validators.required]],
descriptions: this.fb.array([]),
});
}
Expand All @@ -93,14 +94,14 @@ export class BrandFormComponent implements OnInit {
this.form.patchValue({
code: this.brand.code,
order: this.brand.order,
selectedLanguage: 'en',
selectedLanguage: this.defaultLanguage,
descriptions: [],
});
this.fillFormArray();
}

fillFormArray() {
console.log(this.brand.descriptions);
//console.log(this.brand.descriptions);
this.form.value.descriptions.forEach((desc, index) => {
if (this.brand != null && this.brand.descriptions) {
this.brand.descriptions.forEach((description) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { TypesService } from '../../types/services/types.service';
import { StorageService } from '../../../shared/services/storage.service';
import { Image } from '../../../shared/models/image';
import { ImageBrowserComponent } from '../../../../@theme/components/image-browser/image-browser.component';
import { threadId } from 'worker_threads';
//import { threadId } from 'worker_threads';
declare var jquery: any;
declare var $: any;

Expand Down Expand Up @@ -221,8 +221,6 @@ export class ProductFormComponent implements OnInit {


fillForm() {
//this.addImageUrlComponent = this.productImageService.addImageUrl(this.product.id);
//this.refreshChilds();
this.form.patchValue({
identifier: this.product.identifier,
visible: this.product.visible,
Expand Down Expand Up @@ -319,7 +317,6 @@ export class ProductFormComponent implements OnInit {
selectedLanguage: lang,
});
this.currentLanguage = lang;
//this.fillFormArray();
}

changeName(event, index) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<div [nbSpinner]="loading" nbSpinnerSize="large" nbSpinnerStatus="primary">
<div class="inner_pages create_page">
<form [formGroup]='form'>

<form *ngIf="loaded" [formGroup]='form'>
<nb-card-header class="main_header">
<h1 class="page_title">{{ 'PRODUCT_TYPE.PRODUCT_TYPE_DETAILS' | translate}}</h1>
<div class="content_spacing">
Expand Down Expand Up @@ -67,16 +69,67 @@ <h1 class="page_title">{{ 'PRODUCT_TYPE.PRODUCT_TYPE_DETAILS' | translate}}</h1>
{{ 'COMMON.CODE_REQUIRED' | translate}}
</div>
</div>


<!--
<div class="form-group">
<label class="col-sm-10 col-form-label inputLabel">{{ 'COMMON.LANGUAGE' | translate}} *</label>
<div class="col-sm-12">
<nb-select *ngIf="languages.length" placeholder="{{ 'COMMON.LANGUAGE' | translate}}" outline
shape="rectangle" formControlName='selectedLanguage' class="fullWidth">
<nb-option *ngFor="let language of languages" [value]="language.code">{{ ('LANG.'+language.code) |
translate }}</nb-option>
</nb-select>
</div>
</div>
<div *ngIf="selectedLanguage.value !== ''" formArrayName='descriptions'>
<div *ngFor="let descr of descriptions.controls; let j=index">
<div *ngIf="descr.value.language === selectedLanguage.value">
<div [formGroupName]="j" class="description-block">
<div class="form-group">
<label for="name" class="col-sm-10 col-form-label inputLabel">{{ 'DESCRIPTION_FORM.NAME' |
translate}}</label>
<div class="col-sm-12">
<input type="text" class="form-control inputText" id="name" formControlName='name'
placeholder="{{ 'DESCRIPTION_FORM.NAME' | translate}}" (ngModelChange)="changeName($event, j)">
<span *ngIf="(descr.get('name').dirty || descr.get('name').touched)
&& descr.get('name').invalid && descr.get('name').errors.required" class="err-message">
{{ 'DESCRIPTION_FORM.NAME_REQUIRED' | translate}}
</span>
</div>
</div>
</div>
</div>
</div>
</div>
-->





<div class="form-group">
<label class="col-form-label inputLabel">{{ 'COMMON.LANGUAGE' | translate}} *</label>

<!--
<nb-select *ngIf="languages.length" placeholder="{{ 'COMMON.LANGUAGE' | translate}}" outline shape="rectangle"
class="fullWidth" name='selectedLanguage' [selected]="defaultLanguage">
<nb-option (click)="selectLanguage(language.code)" *ngFor="let language of languages"
[value]="language.code">{{
('LANG.'+language.code) |translate }}</nb-option>
</nb-select>
-->

<nb-select *ngIf="languages.length" placeholder="{{ 'COMMON.LANGUAGE' | translate}}" outline
shape="rectangle" formControlName='selectedLanguage' class="fullWidth">
<nb-option *ngFor="let language of languages" (click)="selectLanguage(language.code)" [value]="language.code">{{ ('LANG.'+language.code) |
translate }}</nb-option>
</nb-select>
</div>
<div *ngIf="selectedLanguage.value !== ''" formArrayName='descriptions'>
<div formArrayName='descriptions'>
<div *ngFor="let descr of descriptions.controls; let j=index">
<div *ngIf="descr.value.language === selectedLanguage.value">
<div [formGroupName]="j">
Expand All @@ -96,4 +149,5 @@ <h1 class="page_title">{{ 'PRODUCT_TYPE.PRODUCT_TYPE_DETAILS' | translate}}</h1>

<!-- </div> -->
</form>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TypesService } from '../services/types.service';
import { StorageService } from '../../../shared/services/storage.service';
import { NbDialogService } from '@nebular/theme';
import { ShowcaseDialogComponent } from '../../../shared/components/showcase-dialog/showcase-dialog.component';
import { forkJoin } from 'rxjs';
import { Router, ActivatedRoute } from '@angular/router';
import { DomSanitizer } from '@angular/platform-browser';
import { ConfigService } from '../../../shared/services/config.service';
Expand All @@ -19,9 +20,11 @@ export class TypeDetailsComponent implements OnInit {

form: FormGroup;
loading: boolean = false;
loaded: boolean = false;
isReadonlyCode = false;
isCodeExist = false;
isValidCode = true;
defaultLanguage = localStorage.getItem('lang');
languages = [];
type = {
id: '',
Expand All @@ -43,42 +46,55 @@ export class TypeDetailsComponent implements OnInit {
private typesService: TypesService,
private activatedRoute: ActivatedRoute,
private configService: ConfigService
) {

this.languages = [...this.configService.languages];
}
) { }

ngOnInit(): void {

this.loading = true;

let param = {
//lang: this.storageService.getLanguage(),
lang: "_all",
store: this.storageService.getMerchant()
}
const typeId = this.activatedRoute.snapshot.paramMap.get('id');
this.createForm();
if (typeId) {
this.loading = true;
let param = {
//lang: this.storageService.getLanguage(),
lang: "_all",
store: this.storageService.getMerchant()
}
this.typesService.getType(typeId, param)
.subscribe((res) => {

//console.log(JSON.stringify(res));

this.type.id = res.id;
this.type.code = res.code;
this.type.allowAddToCart = res.allowAddToCart;
this.type.visible = res.visible;
this.type.description = res.description;
this.type.descriptions = res.descriptions;

this.isReadonlyCode = true;

this.adjustForm();
this.loading = false;
const types$ = this.typesService.getType(typeId, param)
const config$ = this.configService.getListOfSupportedLanguages(localStorage.getItem('merchant'));
forkJoin([types$, config$])
.subscribe(([productType, languages]) => {

this.type.id = productType.id;
this.type.code = productType.code;
this.type.allowAddToCart = productType.allowAddToCart;
this.type.visible = productType.visible;
this.type.description = productType.description;
this.type.descriptions = productType.descriptions;

this.isReadonlyCode = true;
this.languages = [...languages];
this.createForm();
this.addFormArray();
if(this.type) {
this.fillForm();
}

this.loading = false;
this.loaded = true;


});
} else {
const config$ = this.configService.getListOfSupportedLanguages(localStorage.getItem('merchant'))
.subscribe((languages) => {
this.languages = [...languages];
this.createForm();
this.addFormArray();
this.loading = false;
this.loaded = true;
});
}

}, error => {
this.loading = false;
});
}

}

Expand All @@ -87,33 +103,30 @@ export class TypeDetailsComponent implements OnInit {
allowAddToCart: [true],
visible: [false],
code: [{ value: '', disabled: false }, [Validators.required, Validators.pattern(validators.alphanumeric)]],
selectedLanguage: ['en'],
selectedLanguage: this.defaultLanguage,
descriptions: this.fb.array([]),
// name: ['', [Validators.required]]
});
this.addFormArray();
}

addFormArray() {
const control = <FormArray>this.form.controls.descriptions;
this.languages.forEach(lang => {
control.push(
this.fb.group({
language: [lang.code, []],
name: ['', []]
language: [lang.code, [Validators.required]],
name: ['', [Validators.required]],
})
);
});
}

private adjustForm() {
private fillForm() {
this.form.patchValue({
allowAddToCart: this.type.allowAddToCart,
visible: this.type.visible,
code: this.type.code,
selectedLanguage: 'en',
selectedLanguage: this.defaultLanguage
});

if (this.type.id) {
this.form.controls['code'].disable();
}
Expand Down Expand Up @@ -186,11 +199,12 @@ export class TypeDetailsComponent implements OnInit {
return this.form.get('selectedLanguage');
}



selectLanguage(lang) {
this.form.patchValue({
selectedLanguage: lang,
});
//this.fillFormArray();
}

get descriptions(): FormArray {
Expand Down
1 change: 1 addition & 0 deletions src/app/pages/shared/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class ConfigService {
) {
}


getListOfSupportedLanguages(store: string) {
const params = {
'store': store
Expand Down
2 changes: 1 addition & 1 deletion src/assets/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
window["env"] = window["env"] || {};

// Environment variables
window["env"]["APP_BASE_URL"] = "https://api.perfectogaz.com/api";
window["env"]["APP_BASE_URL"] = "https://rest-api.shopizer.com/api";
window["env"]["APP_SHIPPING_URL"] = 'http://localhost:9090/api"';
window["env"]["APP_MAP_API_KEY"] = '';
window["env"]["APP_DEFAULT_LANGUAGE"] = 'fr';
Expand Down

0 comments on commit 5c51aaa

Please sign in to comment.