From 71c72adf6e4559e1638514a19dbb3a18a6a1430b Mon Sep 17 00:00:00 2001 From: nikiquickie Date: Thu, 28 Nov 2024 16:13:54 +0200 Subject: [PATCH] fix commerrceproductquantities --- src/app/app.module.ts | 10 ++ src/app/core/theme/user/user.component.html | 10 ++ .../pages/commerces/commerces.component.ts | 6 + .../commercebrands/commercebrands.module.ts | 4 - .../commercecontent.formcomponents.ts | 35 +++++ .../interfaces/commercecontent.interface.ts | 7 + .../commercecontents.component.html | 6 + .../commercecontents.component.scss | 0 .../commercecontents.component.ts | 142 ++++++++++++++++++ .../commercecontents.module.ts | 22 +++ .../commercecontent-selector.component.html | 6 + .../commercecontent-selector.component.scss | 0 .../commercecontent-selector.component.ts | 35 +++++ .../services/commercecontent.service.ts | 39 +++++ .../commerceproducts.component.ts | 6 + .../commerceproductquantity.interface.ts | 3 + .../commerceproductquantities.component.ts | 41 ++++- .../commerceproductquantities.module.ts | 12 ++ .../commercestores.component.ts | 6 + .../commercewarehouses.component.ts | 6 + 20 files changed, 391 insertions(+), 5 deletions(-) create mode 100644 src/app/modules/commercecontent/formcomponents/commercecontent.formcomponents.ts create mode 100644 src/app/modules/commercecontent/interfaces/commercecontent.interface.ts create mode 100644 src/app/modules/commercecontent/pages/commercecontents/commercecontents.component.html create mode 100644 src/app/modules/commercecontent/pages/commercecontents/commercecontents.component.scss create mode 100644 src/app/modules/commercecontent/pages/commercecontents/commercecontents.component.ts create mode 100644 src/app/modules/commercecontent/pages/commercecontents/commercecontents.module.ts create mode 100644 src/app/modules/commercecontent/selectors/commercecontent/commercecontent-selector.component.html create mode 100644 src/app/modules/commercecontent/selectors/commercecontent/commercecontent-selector.component.scss create mode 100644 src/app/modules/commercecontent/selectors/commercecontent/commercecontent-selector.component.ts create mode 100644 src/app/modules/commercecontent/services/commercecontent.service.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 8ef390f..a439750 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -73,6 +73,16 @@ const routes: Routes = [ component: UserComponent, children: [ /* user */ + { + path: 'commercecontents', + canActivate: [MetaGuard], + data: { + meta: { + title: 'Commercecontents' + } + }, + loadChildren: () => import('./modules/commercecontent/pages/commercecontents/commercecontents.module').then(m => m.CommercecontentsModule) + }, { path: 'commerceproductquantities', canActivate: [MetaGuard], diff --git a/src/app/core/theme/user/user.component.html b/src/app/core/theme/user/user.component.html index 8cfba8f..5620283 100644 --- a/src/app/core/theme/user/user.component.html +++ b/src/app/core/theme/user/user.component.html @@ -64,6 +64,11 @@ store Theme.Stores + + people + Theme.Clients + home @@ -84,6 +89,11 @@ photo_camera Theme.Portfolios + + content_paste + Theme.Contents + style diff --git a/src/app/modules/commerce/pages/commerces/commerces.component.ts b/src/app/modules/commerce/pages/commerces/commerces.component.ts index 0007a79..39db5f4 100644 --- a/src/app/modules/commerce/pages/commerces/commerces.component.ts +++ b/src/app/modules/commerce/pages/commerces/commerces.component.ts @@ -90,6 +90,12 @@ export class CommercesComponent { return '/commerceportfolios/' + doc._id; } }, + { + icon: 'content_paste', + hrefFunc: (doc: Commerce): string => { + return '/commercecontents/' + doc._id; + } + }, { icon: 'style', hrefFunc: (doc: Commerce): string => { diff --git a/src/app/modules/commercebrand/pages/commercebrands/commercebrands.module.ts b/src/app/modules/commercebrand/pages/commercebrands/commercebrands.module.ts index 14e88bb..5775e2b 100644 --- a/src/app/modules/commercebrand/pages/commercebrands/commercebrands.module.ts +++ b/src/app/modules/commercebrand/pages/commercebrands/commercebrands.module.ts @@ -4,10 +4,6 @@ import { CommercebrandsComponent } from './commercebrands.component'; import { Routes, RouterModule } from '@angular/router'; const routes: Routes = [ - { - path: '', - component: CommercebrandsComponent - }, { path: ':commerce_id', component: CommercebrandsComponent diff --git a/src/app/modules/commercecontent/formcomponents/commercecontent.formcomponents.ts b/src/app/modules/commercecontent/formcomponents/commercecontent.formcomponents.ts new file mode 100644 index 0000000..5cb7d41 --- /dev/null +++ b/src/app/modules/commercecontent/formcomponents/commercecontent.formcomponents.ts @@ -0,0 +1,35 @@ +export const commercecontentFormComponents = { + formId: 'commercecontent', + title: 'Commercecontent', + components: [ + { + name: 'Text', + key: 'name', + focused: true, + fields: [ + { + name: 'Placeholder', + value: 'fill commercecontent title', + }, + { + name: 'Label', + value: 'Title', + } + ] + }, + { + name: 'Text', + key: 'description', + fields: [ + { + name: 'Placeholder', + value: 'fill commercecontent description', + }, + { + name: 'Label', + value: 'Description', + } + ] + } + ] +} diff --git a/src/app/modules/commercecontent/interfaces/commercecontent.interface.ts b/src/app/modules/commercecontent/interfaces/commercecontent.interface.ts new file mode 100644 index 0000000..b9ac400 --- /dev/null +++ b/src/app/modules/commercecontent/interfaces/commercecontent.interface.ts @@ -0,0 +1,7 @@ +import { CrudDocument } from 'wacom'; + +export interface Commercecontent extends CrudDocument { + name: string; + description: string; + commerce: string; +} diff --git a/src/app/modules/commercecontent/pages/commercecontents/commercecontents.component.html b/src/app/modules/commercecontent/pages/commercecontents/commercecontents.component.html new file mode 100644 index 0000000..6dffb95 --- /dev/null +++ b/src/app/modules/commercecontent/pages/commercecontents/commercecontents.component.html @@ -0,0 +1,6 @@ + diff --git a/src/app/modules/commercecontent/pages/commercecontents/commercecontents.component.scss b/src/app/modules/commercecontent/pages/commercecontents/commercecontents.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/modules/commercecontent/pages/commercecontents/commercecontents.component.ts b/src/app/modules/commercecontent/pages/commercecontents/commercecontents.component.ts new file mode 100644 index 0000000..b3b44b8 --- /dev/null +++ b/src/app/modules/commercecontent/pages/commercecontents/commercecontents.component.ts @@ -0,0 +1,142 @@ +import { Component } from '@angular/core'; +import { AlertService, CoreService } from 'wacom'; +import { CommercecontentService } from '../../services/commercecontent.service'; +import { Commercecontent } from '../../interfaces/commercecontent.interface'; +import { FormService } from 'src/app/core/modules/form/form.service'; +import { TranslateService } from 'src/app/core/modules/translate/translate.service'; +import { FormInterface } from 'src/app/core/modules/form/interfaces/form.interface'; +import { commercecontentFormComponents } from '../../formcomponents/commercecontent.formcomponents'; +import { Router } from '@angular/router'; + +@Component({ + templateUrl: './commercecontents.component.html', + styleUrls: ['./commercecontents.component.scss'], + standalone: false +}) +export class CommercecontentsComponent { + columns = ['name', 'description']; + + commerce = this._router.url.includes('/commercebrands/') + ? this._router.url.replace('/commercebrands/', '') + : ''; + + form: FormInterface = this._form.getForm('commercecontent', commercecontentFormComponents); + + config = { + create: (): void => { + this._form.modal(this.form, { + label: 'Create', + click: (created: unknown, close: () => void) => { + if (this.commerce) { + (created as Commercecontent).commerce = this.commerce; + } + this._commercecontentService.create(created as Commercecontent); + + close(); + } + }); + }, + update: (doc: Commercecontent): void => { + this._form.modal(this.form, [], doc).then((updated: Commercecontent) => { + this._core.copy(updated, doc); + + this._commercecontentService.update(doc); + }); + }, + delete: (doc: Commercecontent): void => { + this._alert.question({ + text: this._translate.translate( + 'Common.Are you sure you want to delete this commercecontent?' + ), + buttons: [ + { + text: this._translate.translate('Common.No') + }, + { + text: this._translate.translate('Common.Yes'), + callback: (): void => { + this._commercecontentService.delete(doc); + } + } + ] + }); + }, + buttons: [ + { + icon: 'cloud_download', + click: (doc: Commercecontent): void => { + this._form.modalUnique('commercecontent', 'url', doc); + } + } + ], + headerButtons: [ + { + icon: 'playlist_add', + click: this._bulkManagement(), + class: 'playlist', + }, + { + icon: 'edit_note', + click: this._bulkManagement(false), + class: 'edit', + }, + ] + }; + + get rows(): Commercecontent[] { + return this._commercecontentService.commercecontents; + } + + constructor( + private _translate: TranslateService, + private _commercecontentService: CommercecontentService, + private _alert: AlertService, + private _form: FormService, + private _core: CoreService, + private _router: Router + ) {} + + private _bulkManagement(create = true): () => void { + return (): void => { + this._form + .modalDocs(create ? [] : this.rows) + .then((commercecontents: Commercecontent[]) => { + if (create) { + for (const commercecontent of commercecontents) { + if (this.commerce) { + commercecontent.commerce = this.commerce; + } + this._commercecontentService.create(commercecontent); + } + } else { + for (const commercecontent of this.rows) { + if (!commercecontents.find( + localCommercecontent => localCommercecontent._id === commercecontent._id + )) { + this._commercecontentService.delete(commercecontent); + } + } + + for (const commercecontent of commercecontents) { + const localCommercecontent = this.rows.find( + localCommercecontent => localCommercecontent._id === commercecontent._id + ); + + if (localCommercecontent) { + this._core.copy(commercecontent, localCommercecontent); + + this._commercecontentService.update(localCommercecontent); + } else { + if (this.commerce) { + commercecontent.commerce = this.commerce; + } + commercecontent.__created = false; + + this._commercecontentService.create(commercecontent); + } + } + } + }); + }; + } +} diff --git a/src/app/modules/commercecontent/pages/commercecontents/commercecontents.module.ts b/src/app/modules/commercecontent/pages/commercecontents/commercecontents.module.ts new file mode 100644 index 0000000..ef921d5 --- /dev/null +++ b/src/app/modules/commercecontent/pages/commercecontents/commercecontents.module.ts @@ -0,0 +1,22 @@ +import { NgModule } from '@angular/core'; +import { CoreModule } from 'src/app/core/core.module'; +import { CommercecontentsComponent } from './commercecontents.component'; +import { Routes, RouterModule } from '@angular/router'; + +const routes: Routes = [ + { + path: '', + component: CommercecontentsComponent + }, + { + path: ':commerce_id', + component: CommercecontentsComponent + } +]; + +@NgModule({ + imports: [RouterModule.forChild(routes), CoreModule], + declarations: [CommercecontentsComponent], + providers: [] +}) +export class CommercecontentsModule {} diff --git a/src/app/modules/commercecontent/selectors/commercecontent/commercecontent-selector.component.html b/src/app/modules/commercecontent/selectors/commercecontent/commercecontent-selector.component.html new file mode 100644 index 0000000..36c7ee5 --- /dev/null +++ b/src/app/modules/commercecontent/selectors/commercecontent/commercecontent-selector.component.html @@ -0,0 +1,6 @@ + diff --git a/src/app/modules/commercecontent/selectors/commercecontent/commercecontent-selector.component.scss b/src/app/modules/commercecontent/selectors/commercecontent/commercecontent-selector.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/modules/commercecontent/selectors/commercecontent/commercecontent-selector.component.ts b/src/app/modules/commercecontent/selectors/commercecontent/commercecontent-selector.component.ts new file mode 100644 index 0000000..46d1176 --- /dev/null +++ b/src/app/modules/commercecontent/selectors/commercecontent/commercecontent-selector.component.ts @@ -0,0 +1,35 @@ +import { + SimpleChanges, + EventEmitter, + Component, + OnChanges, + Output, + Input +} from '@angular/core'; +import { SelectModule } from 'src/app/core/modules/select/select.module'; +import { CommercecontentService } from '../../services/commercecontent.service'; +import { Commercecontent } from '../../interfaces/commercecontent.interface'; + +@Component({ + selector: 'commercecontent-selector', + templateUrl: './commercecontent-selector.component.html', + styleUrls: ['./commercecontent-selector.component.scss'], + imports: [SelectModule] +}) +export class SelectUserComponent implements OnChanges { + @Input() value: string; + + @Output() wChange = new EventEmitter(); + + get items(): Commercecontent[] { + return this._commercecontentService.commercecontents; + } + + constructor(private _commercecontentService: CommercecontentService) {} + + ngOnChanges(changes: SimpleChanges): void { + if (changes['value'] && !changes['value'].firstChange) { + this.value = changes['value'].currentValue; + } + } +} diff --git a/src/app/modules/commercecontent/services/commercecontent.service.ts b/src/app/modules/commercecontent/services/commercecontent.service.ts new file mode 100644 index 0000000..4415748 --- /dev/null +++ b/src/app/modules/commercecontent/services/commercecontent.service.ts @@ -0,0 +1,39 @@ +import { Injectable } from '@angular/core'; +import { Commercecontent } from '../interfaces/commercecontent.interface'; +import { + AlertService, + CoreService, + HttpService, + StoreService, + CrudService +} from 'wacom'; + +@Injectable({ + providedIn: 'root', +}) +export class CommercecontentService extends CrudService { + commercecontents: Commercecontent[] = this.getDocs(); + + commercecontentsByAuthor: Record = {}; + + constructor( + _http: HttpService, + _store: StoreService, + _alert: AlertService, + _core: CoreService + ) { + super( + { + name: 'commercecontent', + }, + _http, + _store, + _alert, + _core + ); + + this.get(); + + this.filteredDocuments(this.commercecontentsByAuthor); + } +} diff --git a/src/app/modules/commerceproduct/pages/commerceproducts/commerceproducts.component.ts b/src/app/modules/commerceproduct/pages/commerceproducts/commerceproducts.component.ts index 5aab111..b7b9171 100644 --- a/src/app/modules/commerceproduct/pages/commerceproducts/commerceproducts.component.ts +++ b/src/app/modules/commerceproduct/pages/commerceproducts/commerceproducts.component.ts @@ -61,6 +61,12 @@ export class CommerceproductsComponent { }); }, buttons: [ + { + icon: '1x_mobiledata', + hrefFunc: (doc: Commerceproduct): string => { + return '/commerceproductquantities/' + doc._id; + } + }, { icon: 'cloud_download', click: (doc: Commerceproduct): void => { diff --git a/src/app/modules/commerceproductquantity/interfaces/commerceproductquantity.interface.ts b/src/app/modules/commerceproductquantity/interfaces/commerceproductquantity.interface.ts index 9a56c3f..2b9c060 100644 --- a/src/app/modules/commerceproductquantity/interfaces/commerceproductquantity.interface.ts +++ b/src/app/modules/commerceproductquantity/interfaces/commerceproductquantity.interface.ts @@ -3,4 +3,7 @@ import { CrudDocument } from 'wacom'; export interface Commerceproductquantity extends CrudDocument { name: string; description: string; + commerceproduct: string; + commercestore: string; + commercewarehouse: string; } diff --git a/src/app/modules/commerceproductquantity/pages/commerceproductquantities/commerceproductquantities.component.ts b/src/app/modules/commerceproductquantity/pages/commerceproductquantities/commerceproductquantities.component.ts index 707e3a0..5713739 100644 --- a/src/app/modules/commerceproductquantity/pages/commerceproductquantities/commerceproductquantities.component.ts +++ b/src/app/modules/commerceproductquantity/pages/commerceproductquantities/commerceproductquantities.component.ts @@ -6,6 +6,7 @@ import { FormService } from 'src/app/core/modules/form/form.service'; import { TranslateService } from 'src/app/core/modules/translate/translate.service'; import { FormInterface } from 'src/app/core/modules/form/interfaces/form.interface'; import { commerceproductquantityFormComponents } from '../../formcomponents/commerceproductquantity.formcomponents'; +import { Route, Router } from '@angular/router'; @Component({ templateUrl: './commerceproductquantities.component.html', @@ -15,6 +16,18 @@ import { commerceproductquantityFormComponents } from '../../formcomponents/comm export class CommerceproductquantitiesComponent { columns = ['name', 'description']; + commerceproduct = this._router.url.includes('/commerceproductquantities/') + ? this._router.url.replace('/commerceproductquantities/', '') + : ''; + + commercestore = this._router.url.includes('/commerceproductquantities/') + ? this._router.url.replace('/commerceproductquantities/', '') + : ''; + + commercewarehouse = this._router.url.includes('/commerceproductquantities/') + ? this._router.url.replace('/commerceproductquantities/', '') + : ''; + form: FormInterface = this._form.getForm('commerceproductquantity', commerceproductquantityFormComponents); config = { @@ -22,6 +35,15 @@ export class CommerceproductquantitiesComponent { this._form.modal(this.form, { label: 'Create', click: (created: unknown, close: () => void) => { + if (this.commerceproduct) { + (created as Commerceproductquantity).commerceproduct = this.commerceproduct; + } + if (this.commercestore) { + (created as Commerceproductquantity).commercestore = this.commercestore; + } + if (this.commercewarehouse) { + (created as Commerceproductquantity).commercewarehouse = this.commercewarehouse; + } this._commerceproductquantityService.create(created as Commerceproductquantity); close(); @@ -84,7 +106,8 @@ export class CommerceproductquantitiesComponent { private _commerceproductquantityService: CommerceproductquantityService, private _alert: AlertService, private _form: FormService, - private _core: CoreService + private _core: CoreService, + private _router: Router ) { } private _bulkManagement(create = true): () => void { @@ -94,6 +117,14 @@ export class CommerceproductquantitiesComponent { .then((commerceproductquantitys: Commerceproductquantity[]) => { if (create) { for (const commerceproductquantity of commerceproductquantitys) { + if (this.commerceproduct) { + commerceproductquantity.commerceproduct = this.commerceproduct; + } + if (this.commercestore) { + commerceproductquantity.commercestore = this.commercestore; + } if (this.commercewarehouse) { + commerceproductquantity.commercewarehouse = this.commercewarehouse; + } this._commerceproductquantityService.create(commerceproductquantity); } } else { @@ -115,6 +146,14 @@ export class CommerceproductquantitiesComponent { this._commerceproductquantityService.update(localCommerceproductquantity); } else { + if (this.commerceproduct) { + commerceproductquantity.commerceproduct = this.commerceproduct; + } + if (this.commercestore) { + commerceproductquantity.commercestore = this.commercestore; + } if (this.commercewarehouse) { + commerceproductquantity.commercewarehouse = this.commercewarehouse; + } commerceproductquantity.__created = false; this._commerceproductquantityService.create(commerceproductquantity); diff --git a/src/app/modules/commerceproductquantity/pages/commerceproductquantities/commerceproductquantities.module.ts b/src/app/modules/commerceproductquantity/pages/commerceproductquantities/commerceproductquantities.module.ts index 6216d42..a33c3a4 100644 --- a/src/app/modules/commerceproductquantity/pages/commerceproductquantities/commerceproductquantities.module.ts +++ b/src/app/modules/commerceproductquantity/pages/commerceproductquantities/commerceproductquantities.module.ts @@ -7,6 +7,18 @@ const routes: Routes = [ { path: '', component: CommerceproductquantitiesComponent + }, + { + path: 'commerceproduct/:commerceproduct_id', + component: CommerceproductquantitiesComponent + }, + { + path: 'commercestore/:commercestore_id', + component: CommerceproductquantitiesComponent + }, + { + path: 'warehouse/:warehouse_id', + component: CommerceproductquantitiesComponent } ]; diff --git a/src/app/modules/commercestore/pages/commercestores/commercestores.component.ts b/src/app/modules/commercestore/pages/commercestores/commercestores.component.ts index 04aa00f..1f558e2 100644 --- a/src/app/modules/commercestore/pages/commercestores/commercestores.component.ts +++ b/src/app/modules/commercestore/pages/commercestores/commercestores.component.ts @@ -62,6 +62,12 @@ export class CommercestoresComponent { }); }, buttons: [ + { + icon: '1x_mobiledata', + hrefFunc: (doc: Commercestore): string => { + return '/commerceproductquantities/' + doc._id; + } + }, { icon: 'cloud_download', click: (doc: Commercestore): void => { diff --git a/src/app/modules/commercewarehouse/pages/commercewarehouses/commercewarehouses.component.ts b/src/app/modules/commercewarehouse/pages/commercewarehouses/commercewarehouses.component.ts index 9e7259f..6e4a4cc 100644 --- a/src/app/modules/commercewarehouse/pages/commercewarehouses/commercewarehouses.component.ts +++ b/src/app/modules/commercewarehouse/pages/commercewarehouses/commercewarehouses.component.ts @@ -62,6 +62,12 @@ export class CommercewarehousesComponent { }); }, buttons: [ + { + icon: '1x_mobiledata', + hrefFunc: (doc: Commercewarehouse): string => { + return '/commerceproductquantities/' + doc._id; + } + }, { icon: 'cloud_download', click: (doc: Commercewarehouse): void => {