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 | 3x 3x 3x 3x 3x 3x 3x 3x 3x 25x 3x 25x 25x 25x 25x 25x 25x 25x 25x 2x 2x 2x 2x 1x 2x 1x 1x 2x 1x 1x 2x 25x 4x 1x 3x 3x 3x 3x 3x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 2x 1x 1x 25x 7x 7x 7x 7x 7x 7x 7x 6x 1x 7x 7x 7x 1x 1x 7x 28x 6x 28x 25x 6x 7x 7x 1x 2x 2x 1x 1x 3x 1x 2x 2x 1x 2x 2x 1x 1x 1x 2x 1x 1x 1x 4x 4x 1x 1x 4x 1x 1x 4x | import { Component, AfterViewInit, OnChanges, OnDestroy, SimpleChanges } from '@angular/core';
import { Input, Output, EventEmitter } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { FormControl, Validators } from '@angular/forms';
import { ViewRenderer } from '@unpispas/upp-wdgt';
import { OnForm } from '@unpispas/upp-wdgt';
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 { CategoryView } from '@unpispas/upp-data';
import { PreselectView } from '@unpispas/upp-data';
import { ProductView } from '@unpispas/upp-data';
import { ProductOptView } from '@unpispas/upp-data';
@Component({
selector: 'upp-shortcut-edit',
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './upp-edit.html',
styleUrls: [
'./upp-edit.scss'
],
providers: [{
provide: ViewRenderer,
useFactory: (change: ChangeDetectorRef) => new ViewRenderer(change),
deps: [ChangeDetectorRef]
}]
})
export class UppShortcutEditComponent extends languageSupport implements OnForm, AfterViewInit, OnChanges, OnDestroy {
@Input() place: PlaceView | null = null;
@Input() product: ProductView | null = null;
@Input() select: PreselectView | null = null;
@Output() Updated = new EventEmitter<void>();
@Output() Closed = new EventEmitter<void>();
constructor(private lang: languageService, private change: ViewRenderer, private data: dataService, public view: viewService){
super(lang, change.cdref);
}
public ChangeUpdate = false;
ngOnChanges(changes: SimpleChanges){
void changes; // debugging purposes
this.ChangeUpdate = true;
this._selectForm = null;
if (this.product){
this.product.ResetChecked();
}
setTimeout(() => {
this.ChangeUpdate = false;
this.change.markForCheck();
}, 0);
}
ngAfterViewInit(): void {
if (this.select){
for(const _option of this.select.options){
_option.Checked = true;
}
}
this.change.markForCheck();
}
ngOnDestroy(): void {
super.OnDestroy();
}
/********************************/
/* ONFORM IMPLEMENTATION */
/********************************/
CanAccept(): boolean[] {
if (!this.select){
return [ true, true ];
}
let _dirty = false;
_dirty = _dirty || this.ContentDirty;
_dirty = _dirty || this.SelectForm.dirty;
return [ _dirty && this.SelectForm.valid && this.select.IsCompleted, false ];
}
async OnApply(): Promise <boolean> {
if (!this.product || !this.select){
return true;
}
const _photo: string | null = this.SelectForm.get('photo')?.value || null;
const _name: string | null = this.SelectForm.get('name')?.value || null;
const _code: string | null = this.SelectForm.get('code')?.value || null;
const _descr: string | null = this.SelectForm.get('description')?.value || null;
const _sort: number | null = this.SelectForm.get('sort')?.value || null;
this.select.photo = _photo;
this.select.name = _name;
this.select.code = _code;
this.select.description = _descr;
this.select.sort = _sort;
this.product.AddSelect(this.select.object);
this.Updated.emit(); // activates main form acceptance
return false; // accepted form: do not continue
}
async OnAccept(): Promise <boolean> {
return this.OnApply();
}
async OnCancel(): Promise <boolean> {
if (!this.select){
return true; // nothing to be cancelled: continue
}
return false; // cancelled form: do not continue
}
/********************************/
/* PRESELECT FORM */
/********************************/
private _selectForm: FormGroup | null = null;
private LoadSelectForm(): FormGroup {
const _photo: string | null = this.select?.photo || null;
const _name: string | null = this.select?.name || null;
const _code: string | null = this.select?.code || null;
const _descr: string | null = this.select?.description || null;
const _sort: number | null = this.select?.sort || null;
let _form: FormGroup | null = this._selectForm;
if (_form == null){
_form = new FormGroup({
photo: new FormControl(_photo, [
// no validators required
]),
name: new FormControl(_name, [
Validators.required,
]),
code: new FormControl(_code, [
// no validators required
]),
description: new FormControl(_descr, [
// no validators required
]),
sort: new FormControl(_sort, [
// no validators required
]),
});
}
else {
_form.patchValue({
photo: _photo,
name: _name,
code: _code,
description: _descr,
sort: _sort
});
}
this.change.markForCheck();
_form.markAsPristine();
setTimeout(() => {
_form?.markAsPristine();
this.ContentDirty = false;
}, 0)
return _form;
}
get SelectForm(): FormGroup {
if (this._selectForm == null){
this._selectForm = this.LoadSelectForm();
}
return this._selectForm;
}
/********************************/
/* DISPLAY OPTIONS */
/********************************/
private _contentdirty = false;
get ContentDirty(): boolean {
return this._contentdirty;
}
set ContentDirty(value: boolean){
this._contentdirty = value;
this.change.markForCheck();
}
CategoryTrack(index: number, category: CategoryView): any {
return category?._uuid || null;
}
OptionTrack(index: number, option: ProductOptView): any {
return option?._uuid || null;
}
get CanRemove(){
if (!this.product || !this.select){
return false;
}
return (this.product.selects.includes(this.select));
}
/********************************/
/* EVENT HANDLERS */
/********************************/
OnSingleSelected(event: CustomEvent, category: CategoryView): void {
if (!this.select){
return;
}
category.SingleOption = event.detail.value as ProductOptView;
if (!this.SelectForm.get('name')?.value){
this.SelectForm.get('name')?.setValue(category.SingleOption?.name || null);
}
this._RefreshSelected();
}
OnOptionSelected(event: CustomEvent, option: ProductOptView){
if (!this.select || !option){
return;
}
option.Checked = event.detail.checked;
this._RefreshSelected();
}
OnDeleteSelect(){
if (!this.select){
return;
}
this.select.status = 'DE';
this.Closed.emit();
}
/********************************/
/* PRIVATE METHODS */
/********************************/
_RefreshSelected(): void {
Iif (!this.product || !this.select){
return;
}
for(const _option of this.select.options){
if (_option.Checked == false){
this.select.DelOption(_option.object);
}
}
for(const _option of this.product.options){
if (_option.Checked){
this.select.AddOption(_option.object);
}
}
this.ContentDirty = true;
}
} |