Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 4x 1x 4x 8x 2x 2x 4x 6x 3x 3x 6x 1x 1x 1x 3x 3x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 16x 7x 16x 16x 16x 16x 16x 16x 16x 16x 1x 1x 1x 1x 1x 16x 1x 1x 1x 1x 1x 17x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 15x 16x 16x 16x 16x 16x 33x 16x 16x 33x 16x 3x 2x 2x 1x 1x 1x 4x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 16x 23x 23x 4x 23x 3x 3x 3x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { Component, OnChanges, OnDestroy, SimpleChanges } from '@angular/core';
import { Input, Output, EventEmitter } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';
import { PlacePanel } from '@unpispas/upp-base';
import { PriceInfo, PriceType } from '@unpispas/upp-defs';
import { ViewRenderer } from '@unpispas/upp-wdgt';
import { alertService } from '@unpispas/upp-base';
import { languageService, languageSupport } from '@unpispas/upp-base';
import { dataService, } from '@unpispas/upp-data';
import { viewService } from '@unpispas/upp-base';
import { PlaceView } from '@unpispas/upp-data';
import { TicketView } from '@unpispas/upp-data';
import { CategoryView } from '@unpispas/upp-data';
import { ProductView } from '@unpispas/upp-data';
import { ProductOptView } from '@unpispas/upp-data';
class Selection {
constructor(public product: ProductView, private ProductForm: FormGroup, private change: ViewRenderer){
// nothing to do
}
get comments(): string | null {
return this.ProductForm.get('comments')?.value || null;
}
public _itemstocart = 1;
get tocart(): number{
return this._itemstocart;
}
set tocart(value: number){
this._itemstocart = value;
this.change.markForCheck();
}
private _iscompleted: boolean | null = null;
get IsCompleted(): boolean {
if (this._iscompleted === null){
this._iscompleted = this._IsCompleted;
// avoid recalculating until next cycle
setTimeout(() => {
this._iscompleted = null;
}, 0);
}
return this._iscompleted;
}
get options(): Array <ProductOptView> {
const _options: Array <ProductOptView> = [];
for(const _option of this.product.options){
Iif (_option.Checked){
_options.push(_option);
}
}
return _options;
}
get priceinfo(): PriceType {
Iif (!this.IsCompleted){
return new PriceInfo(0, 0).price;;
}
let _p = this.product.price || 0;
for (const _option of this.options){
_p += _option.price || 0;
}
const _r = this.product.taxrate;
return new PriceInfo(_p, _r).price;
}
/*******************************/
/* PRIVATE METHODS */
/*******************************/
private get _IsCompleted(): boolean {
Iif (!this.product || !this.ProductForm.valid){
return false;
}
if (this.product.options.length == 0){
return true; // no options in this product
}
let _completed = true;
for (const _category of this.product.categories){
Iif (!_category.Suitable){
continue;
}
if (_category.type == 'SINGLE'){
const _size: number = _category.Selected.length;
_completed = _completed && (_size == 1)
}
Iif (_category.type == 'FIXED'){
const _size: number = _category.Selected.length;
_completed = _completed && (_size >= (_category.fxmin || 0)) && (_size <= (_category.fxmax || 0));
}
if (!_completed){
return false;
}
}
return true;
}
}
@Component({
selector: 'upp-product-cart',
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './upp-cart.html',
styleUrls: [
'./upp-cart.scss'
],
providers: [{
provide: ViewRenderer,
useFactory: (change: ChangeDetectorRef) => new ViewRenderer(change),
deps: [ChangeDetectorRef]
}]
})
export class UppProductCartComponent extends languageSupport implements OnChanges, OnDestroy {
@Input() place: PlaceView | null = null;
@Input() product: ProductView | null = null;
@Input() options: Array <ProductOptView> | null = null;
@Input() ticket: TicketView | null = null;
@Output() ToPanel = new EventEmitter <PlacePanel> ();
private ContentDirty = false;
constructor(private lang: languageService, private change: ViewRenderer, private alertCtrl: alertService, private data: dataService, public view: viewService){
super(lang, change.cdref);
}
private _resetForm(){
this._expandedoptions.clear();
this._selection = null;
if (this.product){
this.product.ResetChecked();
Iif (this.options){
for (const _option of this.options){
_option.Checked = true;
}
}
}
}
public ChangeUpdate = false;
ngOnChanges(changes: SimpleChanges){
void changes; // debugging purposes
this._resetForm();
setTimeout(() => {
this.ChangeUpdate = false;
this.change.markForCheck();
}, 0);
}
ngOnDestroy(): void {
super.OnDestroy();
}
/********************************/
/* PRODUCT FORM */
/********************************/
private _productForm: FormGroup | null = null;
private LoadProductForm(): FormGroup {
const _market: number | null = null; // TODO: leer de la entrada
const _weight: number | null = null; // TODO: leer de la entrada
const _comments: string | null = null; // TODO: leer de la entrada
let _form: FormGroup | null = this._productForm;
if (_form == null){
_form = new FormGroup({
market: new FormControl(_market, [
Validators.required
]),
weight: new FormControl(_weight, [
Validators.required
]),
comments: new FormControl(_comments, [
// no validators required
])
});
}
else E{
_form.patchValue({
market: _market,
weight: _weight,
comments: _comments
});
}
// adjust validators based on product configuration
if (this.product && !this.product.IsMarket){
_form.get('market')?.clearValidators();
}
if (this.product && !this.product.IsWeighted){
_form.get('weight')?.clearValidators();
}
this.change.markForCheck();
_form.markAsPristine();
setTimeout(() => {
_form?.markAsPristine();
}, 0)
return _form;
}
private _status_break = false;
get ProductForm(): FormGroup {
if (this._productForm == null){
this._productForm = this.LoadProductForm();
Iif (this._status_break){
this._productForm.statusChanges.subscribe(status => {
console.log('Form status changed:', status, 'Pristine:', this._productForm?.pristine);
});
}
}
return this._productForm;
}
/********************************/
/* OPTION DESCRIPTIONS */
/********************************/
private _expandedoptions = new Set <ProductOptView> ();
ExpandedOption(option: ProductOptView){
return this._expandedoptions.has(option);
}
OnOptionExpand(event: Event, option: ProductOptView){
event.stopPropagation();
if (option.description){
Iif (this._expandedoptions.has(option)){
this._expandedoptions.delete(option);
}
else {
this._expandedoptions.add(option);
}
this.change.markForCheck();
}
}
/********************************/
/* ITEMS TO CART */
/********************************/
get ItemSize(): number {
return this.select?.tocart || 0;
}
get ItemUnits(): string {
if (this.product && this.product.IsWeighted){
return this.lang.tr('@kilograms');
}
return '';
}
get CanAddItem(): boolean {
Iif (!this.select || !this.select.IsCompleted){
return false;
}
return (this.ItemSize < 99)
}
get CanDelItem(): boolean {
Iif (!this.select || !this.select.IsCompleted){
return false;
}
return (this.ItemSize > 1)
}
OnAddItem(event: Event){
event.stopPropagation();
if (this.select && this.CanAddItem){
this.select.tocart++;
this.change.markForCheck();
}
}
OnDelItem(event: Event){
event.stopPropagation();
if (this.select && this.CanDelItem){
this.select.tocart--;
this.change.markForCheck();
}
}
get CanAccept(): boolean {
return (this.select != null) && (this.select.IsCompleted);
}
OnAccept(){
if (!this.ticket || !this.product || !this.select) {
return;
}
this.ticket.ToCart(this.select.product, this.select.options, this.select.tocart, { comments: this.select.comments })
this._OnClose();
}
/********************************/
/* DISPLAY OPTIONS */
/********************************/
CategoryTrack(index: number, category: CategoryView): any {
return category?._uuid || null;
}
OptionTrack(index: number, option: ProductOptView): any {
return option?._uuid || null;
}
private _selection: Selection | null = null;
get select(): Selection | null {
Iif (!this.product){
return null;
}
if (this._selection === null){
this._selection = new Selection(this.product, this.ProductForm, this.change);
}
return this._selection;
}
/********************************/
/* EVENT HANDLERS */
/********************************/
private _OnClose(){
this.ContentDirty = false;
this.ProductForm.markAsPristine();
this.ToPanel.emit({
scnd: 'ticket',
args: {
ticket: this.ticket
}
});
}
async OnClose(){
if (this.ProductForm.dirty || this.ContentDirty){
const alert = this.alertCtrl.alert({
header: this.lang.tr('@changes_lost_confirm_tittle'),
message: this.lang.tr('@changes_lost_confirm_message'),
backdropDismiss: false,
buttons: [{
text: this.lang.tr('@yes'),
handler: () => {
setTimeout(() => {
alert.dismiss(true);
}, 100);
return false;
}
}, {
text: this.lang.tr('@no'),
handler: () => {
setTimeout(() => {
alert.dismiss(false);
}, 100);
return false;
}
}]
});
alert.onDidDismiss().then((detail:any) => {
if (detail.data == true){
this._OnClose();
}
});
await alert.present();
}
else {
this._OnClose();
}
}
OnSingleSelected(event: CustomEvent, category: CategoryView): void {
category.SingleOption = event.detail.value as ProductOptView;
this.ContentDirty = true;
}
OnOptionSelected(event: CustomEvent, option: ProductOptView){
option.Checked = event.detail.checked;
this.ContentDirty = true;
}
} |