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

Merge pull request #1183 from ever-co/feat/#42-view-delivery-or-takeaway

fix: refactored product delivery or takeaway
parents ed5120d5 ceef2487
Loading
Loading
Loading
Loading
+79 −0
Original line number Diff line number Diff line
import { Component, Input } from '@angular/core';

@Component({
	styles: [
		`
			div {
				white-space: nowrap;
				padding-bottom: 4px;
			}

			div img {
				width: 40px;
				height: 40px;
			}

			.icon-closed {
				color: red;
				margin-right: 3px;
			}

			.icon-checked {
				color: green;
				margin-right: 3px;
			}
		`,
	],
	template: `
		<div
			*ngIf="
				rowData.type.isDeliveryRequired && !rowData.type.isTakeaway;
				else takeaway
			"
		>
			<div>
				<i class="ion-md-checkmark icon-checked"></i>
				{{ 'WAREHOUSE_VIEW.PRODUCTS_TAB.DELIVERY' | translate }}
			</div>
			<div>
				<i class="ion-md-close icon-closed"></i>
				{{ 'WAREHOUSE_VIEW.PRODUCTS_TAB.TAKEAWAY' | translate }}
			</div>
		</div>
		<ng-template #takeaway>
			<div
				*ngIf="
					!rowData.type.isDeliveryRequired && rowData.type.isTakeaway;
					else both
				"
			>
				<div>
					<i class="ion-md-close icon-closed"></i>
					{{ 'WAREHOUSE_VIEW.PRODUCTS_TAB.DELIVERY' | translate }}
				</div>
				<div>
					<i class="ion-md-checkmark icon-checked"></i>
					{{ 'WAREHOUSE_VIEW.PRODUCTS_TAB.TAKEAWAY' | translate }}
				</div>
			</div>
			<ng-template #both>
				<div>
					<div>
						<i class="ion-md-checkmark icon-checked"></i>
						{{ 'WAREHOUSE_VIEW.PRODUCTS_TAB.DELIVERY' | translate }}
					</div>
					<div>
						<i class="ion-md-checkmark icon-checked"></i>
						{{ 'WAREHOUSE_VIEW.PRODUCTS_TAB.TAKEAWAY' | translate }}
					</div>
				</div>
			</ng-template>
		</ng-template>
	`,
})
export class ProductTakeawayDeliveryComponent {
	@Input()
	rowData: any;

	constructor() {}
}
+9 −1
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@ import { CustomerEmailComponent } from './customer-email/customer-email.componen
import { CustomerPhoneComponent } from './customer-phone/customer-phone.component';
import { CheckboxComponent } from './customer-orders-table/checkbox/checkbox.component';
import { IsAvailableCheckBox } from './store-product-is-available-checkbox/is-available-checkbox.component';
import { ProductTakeawayDeliveryComponent } from './product-takeaway-delivery/product-takeaway-delivery.component';
import { TranslateModule } from '@ngx-translate/core';

const COMPONENTS = [
	PriceCountInputComponent,
@@ -30,10 +32,16 @@ const COMPONENTS = [
	CustomerEmailComponent,
	CustomerPhoneComponent,
	IsAvailableCheckBox,
	ProductTakeawayDeliveryComponent,
];

@NgModule({
	imports: [CommonModule, ThemeModule, MomentModule],
	imports: [
		CommonModule,
		ThemeModule,
		MomentModule,
		TranslateModule.forChild(),
	],
	declarations: COMPONENTS,
	entryComponents: COMPONENTS,
})
+10 −21
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ import { StoreProductPriceComponent } from '@app/@shared/render-component/store-
import { StoreProductAmountComponent } from '@app/@shared/render-component/store-products-table/store-product-amount/store-product-amount.component';
import { ProductCategoriesComponent } from '@app/@shared/render-component/product-categories/product-categories';
import { ProductTitleRedirectComponent } from '@app/@shared/render-component/product-title-redirect/product-title-redirect.component';
import { Observable, forkJoin, Subject, Subscription } from 'rxjs';
import { Observable, forkJoin, Subject } from 'rxjs';
import { TranslateService } from '@ngx-translate/core';
import { takeUntil } from 'rxjs/operators';
import WarehouseProduct from '@modules/server.common/entities/WarehouseProduct';
@@ -21,6 +21,7 @@ import Product from '@modules/server.common/entities/Product';
import { StoreProductImageComponent } from '@app/@shared/render-component/store-products-table/store-product-image/store-product-image.component';
import { CheckboxComponent } from '@app/@shared/render-component/customer-orders-table/checkbox/checkbox.component';
import { IsAvailableCheckBox } from '@app/@shared/render-component/store-product-is-available-checkbox/is-available-checkbox.component';
import { ProductTakeawayDeliveryComponent } from '@app/@shared/render-component/product-takeaway-delivery/product-takeaway-delivery.component';

export interface WarehouseProductViewModel {
	id: string;
@@ -55,9 +56,6 @@ export class WarehouseProductsComponent implements OnInit, OnDestroy {
	settingsSmartTable: object;
	sourceSmartTable = new LocalDataSource();
	selectedProducts: WarehouseProductViewModel[] = [];
	columnTitlePrefix = 'WAREHOUSE_VIEW.PRODUCTS_TAB.';
	subscription: Subscription;
	suffix: string;

	private ngDestroy$ = new Subject<void>();
	private categoriesInfo: any = [];
@@ -81,7 +79,6 @@ export class WarehouseProductsComponent implements OnInit, OnDestroy {
	ngOnDestroy(): void {
		this.ngDestroy$.next();
		this.ngDestroy$.complete();
		this.subscription.unsubscribe();
	}

	async loadDataSmartTable(products: WarehouseProduct[], storeId: string) {
@@ -115,9 +112,7 @@ export class WarehouseProductsComponent implements OnInit, OnDestroy {
				},
				price: product.price,
				qty: product.count,
				type: product.isTakeaway
					? this._translate(`${this.columnTitlePrefix}TAKEAWAY`)
					: this._translate(`${this.columnTitlePrefix}DELIVERY`),
				type: product,
				storeId,
				product: product.product,
				allCategories: this.categoriesInfo,
@@ -141,8 +136,9 @@ export class WarehouseProductsComponent implements OnInit, OnDestroy {
	}

	private _loadSettingsSmartTable() {
		let columnTitlePrefix = 'WAREHOUSE_VIEW.PRODUCTS_TAB.';
		const getTranslate = (name: string): Observable<any> =>
			this._translateService.get(this.columnTitlePrefix + name);
			this._translateService.get(columnTitlePrefix + name);

		forkJoin(
			this._translateService.get('Id'),
@@ -168,7 +164,7 @@ export class WarehouseProductsComponent implements OnInit, OnDestroy {
					price,
					quantity,
					availability,
					type
					type,
				]) => {
					this.settingsSmartTable = {
						mode: 'external',
@@ -228,10 +224,12 @@ export class WarehouseProductsComponent implements OnInit, OnDestroy {
							isAvailable: {
								title: availability,
								type: 'custom',
								renderComponent: IsAvailableCheckBox
								renderComponent: IsAvailableCheckBox,
							},
							type: {
								title: type,
								type: 'custom',
								renderComponent: ProductTakeawayDeliveryComponent,
							},
						},
						pager: {
@@ -248,13 +246,4 @@ export class WarehouseProductsComponent implements OnInit, OnDestroy {
			this._loadSettingsSmartTable();
		});
	}

	private _translate(key: string) {
		this.subscription = this._translateService
			.stream(key)
			.subscribe((res) => {
				this.suffix = res;
			});
		return this.suffix;
	}
}