Unverified Commit c66fe7c0 authored by Ruslan Konviser's avatar Ruslan Konviser Committed by GitHub
Browse files

Merge pull request #1332 from ever-co/feature/show-order-product-comments

Feature/show order product comments
parents e83f3cce e072c824
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { ViewCell } from 'ng2-smart-table';

@Component({
	styles: [
		`
			.order-comment-wrapper textarea {
				width: 100%;
			}
		`,
	],
	template: `
		<div class="order-comment-wrapper">
			<textarea (blur)="setComment($event)"></textarea>
		</div>
	`,
})
export class MakeOrderCommentComponent implements ViewCell {
	@Input()
	value;
	@Input()
	rowData: any;

	@Output()
	comment = new EventEmitter<string>();

	get productId(): string {
		return this.value.productId;
	}

	setComment(e) {
		this.comment.emit(e.target.value);
	}
}
+30 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import { ProductLocalesService } from '@modules/client.common.angular2/locale/pr
import { ILocaleMember } from '@modules/server.common/interfaces/ILocale';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { takeUntil } from 'rxjs/operators';
import { MakeOrderCommentComponent } from './make-order-comment.component';

@Component({
	selector: 'ea-warehouse-order-modal',
@@ -78,6 +79,7 @@ export class WarehouseOrderModalComponent implements OnInit, OnDestroy {
					PRICE: `${basePrefix}.${smartTableTitlesPrefix}.PRICE`,
					AVAILABLE: `${basePrefix}.${smartTableTitlesPrefix}.AVAILABLE`,
					AMOUNT: `${basePrefix}.${smartTableTitlesPrefix}.AMOUNT`,
					COMMENT: `${basePrefix}.${smartTableTitlesPrefix}.COMMENT`,
				},
			},
		};
@@ -141,6 +143,7 @@ export class WarehouseOrderModalComponent implements OnInit, OnDestroy {
				return {
					productId: wp.productId,
					count: 0,
					comment: '',
				};
			}
		);
@@ -149,7 +152,7 @@ export class WarehouseOrderModalComponent implements OnInit, OnDestroy {
			(wp: WarehouseProduct) => {
				return {
					img: `
						<img src="${this._getTranslate(wp.product['images'])}" height="68px"/>
						<img src="${this._getTranslate(wp.product['images'])}" height="50px"/>
					`,
					product: `
						<span class="float-left">${this._getTranslate(wp.product['title'])}</span>
@@ -159,6 +162,7 @@ export class WarehouseOrderModalComponent implements OnInit, OnDestroy {
						<div class="badge badge-pill badge-secondary">${wp.count}</div>
					`,
					amount: { productId: wp.productId, available: wp.count },
					comment: { productId: wp.productId },
				};
			}
		);
@@ -214,6 +218,10 @@ export class WarehouseOrderModalComponent implements OnInit, OnDestroy {
			this.TRANSLATE_PREFIXES.SMART_TABLE.TITLES.AMOUNT
		);

		const comment = this._translate(
			this.TRANSLATE_PREFIXES.SMART_TABLE.TITLES.COMMENT
		);

		this.settingsSmartTable = {
			actions: false,
			pager: { perPage: 5 },
@@ -270,6 +278,27 @@ export class WarehouseOrderModalComponent implements OnInit, OnDestroy {
							});
					},
				},

				comment: {
					title: comment,
					filter: false,
					type: 'custom',
					renderComponent: MakeOrderCommentComponent,
					onComponentInitFunction: (
						childInstance: MakeOrderCommentComponent
					) => {
						childInstance.comment
							.pipe(takeUntil(this._ngDestroy$))
							.subscribe((comment) => {
								const wProduct = this._orderProducts.find(
									({ productId }) =>
										productId === childInstance.productId
								);

								wProduct.comment = comment;
							});
					},
				},
			},
		};
	}
+11 −2
Original line number Diff line number Diff line
@@ -6,8 +6,13 @@ import { WarehouseOrderModalComponent } from './warehouse-order-modal.component'
import { WarehouseOrderInputComponent } from './warehouse-order-input.component';
import { TranslateModule } from '@ngx-translate/core';
import { NbSpinnerModule, NbButtonModule } from '@nebular/theme';
import { MakeOrderCommentComponent } from './make-order-comment.component';

const COMPONENTS = [WarehouseOrderModalComponent, WarehouseOrderInputComponent];
const COMPONENTS = [
	WarehouseOrderModalComponent,
	WarehouseOrderInputComponent,
	MakeOrderCommentComponent,
];

@NgModule({
	imports: [
@@ -19,7 +24,11 @@ const COMPONENTS = [WarehouseOrderModalComponent, WarehouseOrderInputComponent];
		TranslateModule.forChild(),
		NbButtonModule,
	],
	declarations: [WarehouseOrderModalComponent, WarehouseOrderInputComponent],
	declarations: [
		WarehouseOrderModalComponent,
		WarehouseOrderInputComponent,
		MakeOrderCommentComponent,
	],
	entryComponents: COMPONENTS,
	exports: COMPONENTS,
})
+10 −2
Original line number Diff line number Diff line
@@ -82,6 +82,8 @@ export class OrderProductsComponent implements OnInit, OnChanges, OnDestroy {
	async loadDataSmartTable() {
		const loadData = () => {
			if (this.order) {
				console.error();

				const productsVM = this.order.products.map(
					(product: OrderProduct) => {
						return {
@@ -89,6 +91,7 @@ export class OrderProductsComponent implements OnInit, OnChanges, OnDestroy {
							price: product.price,
							qty: product.count,
							product: product.product,
							comment: product.comment,
							image: this._productLocalesService.getTranslate(
								product.product['images']
							),
@@ -238,10 +241,11 @@ export class OrderProductsComponent implements OnInit, OnChanges, OnDestroy {
			getTranslate('IMAGE'),
			getTranslate('NAME'),
			getTranslate('QTY'),
			getTranslate('PRICE')
			getTranslate('PRICE'),
			getTranslate('COMMENT')
		)
			.pipe(takeUntil(this._ngDestroy$))
			.subscribe(([id, image, name, qty, price]) => {
			.subscribe(([id, image, name, qty, price, comment]) => {
				this.settingsSmartTable = {
					actions: false,
					selectMode: 'multi',
@@ -251,6 +255,10 @@ export class OrderProductsComponent implements OnInit, OnChanges, OnDestroy {
							renderComponent: ProductTitleRedirectComponent,
							type: 'custom',
						},
						comment: {
							title: comment,
							width: '15%',
						},
						qty: {
							title: qty,
							class: 'text-center',
+1 −1
Original line number Diff line number Diff line
@@ -95,7 +95,7 @@ export class WarehouseComponent implements OnDestroy, AfterViewInit, OnChanges {
		const modalRef: NgbModalRef = this.modalService.open(
			WarehouseOrderComponent,
			{
				size: 'lg',
				size: 'xl',
				container: 'nb-layout',
				windowClass: 'ng-custom',
				backdrop: 'static',
Loading