4 Commits

Author SHA1 Message Date
a3a09507a6 upped version
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
FarmMaps/FarmMapsLib/pipeline/head This commit looks good
2022-06-06 12:52:56 +02:00
9bbde64147 AW-3836 fix build
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
2022-06-06 12:48:52 +02:00
0c4259d72e AW-3836 fixed tags component
Some checks failed
FarmMaps.Develop/FarmMapsLib/pipeline/head There was a failure building this commit
2022-06-06 12:45:23 +02:00
Willem Dantuma
57e0a37c78 add ifPackageListExists to packageservice
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
FarmMaps/FarmMapsLib/pipeline/head This commit looks good
2022-03-16 15:56:23 +01:00
4 changed files with 146 additions and 110 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "farmmaps-lib-app", "name": "farmmaps-lib-app",
"version": "2.0.4", "version": "2.0.5",
"scripts": { "scripts": {
"ng": "ng", "ng": "ng",
"start": "ng serve", "start": "ng serve",

View File

@@ -1,3 +1,11 @@
<div class="tags"> <div class="tags">
<span class="tag rounded bg-primary text-white" *ngFor="let tag of tags;"><span>{{tag}}</span> <i (click)="handleDeleteTag(tag)" class="fal fa-times" aria-hidden="true"></i></span><input type="text" #taginput (blur)="handleAddTag($event)" (keyup)="handleCheckAddTag($event)" [(ngModel)]="tag" [ngbTypeahead]="findTag" (selectItem)="handleSelect($event)" placeholder="New tag"/> <span class="tag rounded bg-primary text-white" *ngFor="let tag of tags;"><span>{{tag}}</span> <i
</div> (click)="handleDeleteTag(tag)" class="fal fa-times" aria-hidden="true"></i></span><input
type="text" #tagInputElement
(blur)="handleBlur($event, false)"
(keyup)="handleKeyUp($event)"
[(ngModel)]="tag"
[ngbTypeahead]="findTag"
(selectItem)="handleSelect($event)"
placeholder="New tag"/>
</div>

View File

@@ -1,104 +1,122 @@
import { Component, Input, forwardRef,ElementRef,ViewChild } from '@angular/core'; import {Component, ElementRef, forwardRef, Input, ViewChild} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR,NgModel } from '@angular/forms'; import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
import { Observable,of } from 'rxjs'; import {Observable, of} from 'rxjs';
import { tap,catchError,debounceTime,distinctUntilChanged,switchMap } from 'rxjs/operators' import {catchError, debounceTime, distinctUntilChanged, switchMap, tap} from 'rxjs/operators';
import { TypeaheadService } from '../../services/typeahead.service'; import {TypeaheadService} from '../../services/typeahead.service';
import {NgbTypeahead} from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'fm-tag-input', @Component({
templateUrl: 'tag-input.component.html', selector: 'fm-tag-input',
styleUrls: ['tag-input.component.scss'], templateUrl: 'tag-input.component.html',
providers: [ styleUrls: ['tag-input.component.scss'],
{ providers: [
provide: NG_VALUE_ACCESSOR, {
useExisting: forwardRef(() => TagInputComponent), provide: NG_VALUE_ACCESSOR,
multi: true useExisting: forwardRef(() => TagInputComponent),
} multi: true
] }
}) ]
})
export class TagInputComponent implements ControlValueAccessor {
@Input() tags: string[] export class TagInputComponent implements ControlValueAccessor {
@ViewChild('taginput', { static: true }) tagInputElement: ElementRef; @Input() tags: string[] = [];
public tag: string; @ViewChild('tagInputElement', {static: true}) tagInputElement: ElementRef;
searching = false; @ViewChild(NgbTypeahead, {static: true}) typeahead: NgbTypeahead;
searchFailed = false;
public tag: string;
constructor(private typeaheadService: TypeaheadService) { searching = false;
} searchFailed = false;
tagExists(tag) { constructor(private typeaheadService: TypeaheadService) {
if (tag.length == 0) return true; }
for (let t of this.tags) {
if (t.toLowerCase() == tag.toLowerCase()) return true; tagExists(tag) {
} if (tag.length === 0) {
return false; return true;
} }
for (const t of this.tags) {
handleDeleteTag(tag) { if (t.toLowerCase() === tag.toLowerCase()) {
let tags = []; return true;
for (let t of this.tags) { }
if (t != tag) tags.push(t); }
} return false;
this.tags = tags; }
this.propagateChange(tags);
} addTag(tag, keepFocus = true) {
if (!this.tagExists(tag)) {
handleAddTag(event) { this.tags.push(tag);
if (!this.tagExists(this.tag)) { this.propagateChange(this.tags);
this.tags.push(this.tag); }
this.propagateChange(this.tags); this.tag = '';
}
this.tag = ""; if (keepFocus) {
this.tagInputElement.nativeElement.focus(); this.tagInputElement.nativeElement.focus();
} }
}
handleCheckAddTag(event: KeyboardEvent) {
if (event.keyCode == 188) { handleDeleteTag(tag) {
let tag = this.tag.substr(0, this.tag.length - 1); // strip , const tags = [];
if (!this.tagExists(tag)) { for (const t of this.tags) {
this.tags.push(tag); if (t !== tag) {
this.propagateChange(this.tags); tags.push(t);
} }
this.tag = ""; }
} this.tags = tags;
} this.propagateChange(tags);
}
handleSelect(event) {
if (!this.tagExists(event.item)) { handleBlur(event, keepFocus = true) {
this.tags.push(event.item); if (!this.typeahead.isPopupOpen()) {
this.propagateChange(this.tags); this.addTag(this.tag, keepFocus);
} } else {
event.preventDefault(); this.tag = '';
this.tag = ""; }
} }
propagateChange = (_: any) => { }; handleKeyUp(event: KeyboardEvent) {
if (event.keyCode === 188) {
registerOnChange(fn) { const tag = this.tag.substr(0, this.tag.length - 1); // strip ,
this.propagateChange = fn; this.addTag(tag);
} }
}
findTag = (text$: Observable<string>) =>
text$.pipe( handleSelect(event) {
debounceTime(200), if (!this.tagExists(event.item)) {
distinctUntilChanged(), this.tags.push(event.item);
tap(() => this.searching = true), this.propagateChange(this.tags);
switchMap(term => term.length < 1 ? of([]) : }
this.typeaheadService.getTagTypeaheadItems(term).pipe( event.preventDefault();
tap(() => this.searchFailed = false), this.tag = '';
catchError(() => { }
this.searchFailed = true;
return of([]); propagateChange = (_: any) => {
})) };
),
tap(() => this.searching = false) registerOnChange(fn) {
); this.propagateChange = fn;
}
writeValue(value: any) {
this.tags = value; findTag = (text$: Observable<string>) =>
this.tag = ""; text$.pipe(
} distinctUntilChanged(),
debounceTime(200),
registerOnTouched() { } tap(() => this.searching = true),
} switchMap(term => term.length < 1 ? of([]) :
this.typeaheadService.getTagTypeaheadItems(term).pipe(
tap(() => this.searchFailed = false),
catchError(() => {
this.searchFailed = true;
return of([]);
}))
),
tap(() => this.searching = false)
);
writeValue(value: any) {
this.tags = value;
this.tag = '';
}
registerOnTouched() {
}
}

View File

@@ -7,7 +7,8 @@ import {IItem} from '../models/item';
import {IItemTask} from '../models/itemTask'; import {IItemTask} from '../models/itemTask';
import {HttpClient} from '@angular/common/http'; import {HttpClient} from '@angular/common/http';
import {AppConfig} from '../shared/app.config'; import {AppConfig} from '../shared/app.config';
import {Observable} from 'rxjs'; import {Observable,iif,of} from 'rxjs';
import {switchMap} from 'rxjs/operators';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
@@ -16,12 +17,13 @@ import {Observable} from 'rxjs';
export class PackageService { export class PackageService {
private userPackages: { [key: string]: IPackage } = {}; private userPackages: { [key: string]: IPackage } = {};
private packages: { [key: string]: IPackage } = {}; private packages: { [key: string]: IPackage } = {};
private packagesObservable = this.store$.select(appCommonReducer.SelectGetPackages);
constructor(private store$: Store<appCommonReducer.State>, public httpClient: HttpClient, public appConfig: AppConfig) { constructor(private store$: Store<appCommonReducer.State>, public httpClient: HttpClient, public appConfig: AppConfig) {
store$.select(appCommonReducer.SelectGetValidUserPackages).subscribe((packages) => { store$.select(appCommonReducer.SelectGetValidUserPackages).subscribe((packages) => {
this.userPackages = packages; this.userPackages = packages;
}); });
store$.select(appCommonReducer.SelectGetPackages).subscribe((packages) => { this.packagesObservable.subscribe((packages) => {
this.packages = packages; this.packages = packages;
}); });
} }
@@ -41,6 +43,14 @@ export class PackageService {
postItemPackageTask(item: IItem, task: IItemTask): Observable<IItemTask> { postItemPackageTask(item: IItem, task: IItemTask): Observable<IItemTask> {
return this.httpClient.post<IItemTask>(`${this.ApiEndpoint()}/api/v1/items/${item.code}/packagetasks`, task); return this.httpClient.post<IItemTask>(`${this.ApiEndpoint()}/api/v1/items/${item.code}/packagetasks`, task);
} }
ifPackageListExists<Type>(packageList: Array<string>, ifTrue:Observable<Type>,ifFalse:Observable<Type>):Observable<Type> {
return this.packagesObservable.pipe(switchMap(packages =>
iif(( )=> Object.keys(packages).some(id => packageList.includes(id)),
ifTrue,
ifFalse)
));
}
} }
export function getValidPackages(packageMap: IPackages): {[key: string]: IPackage} { export function getValidPackages(packageMap: IPackages): {[key: string]: IPackage} {