diff --git a/src/app/pages/entry/edit/edit.page.html b/src/app/pages/entry/edit/edit.page.html index de6394d..415924d 100644 --- a/src/app/pages/entry/edit/edit.page.html +++ b/src/app/pages/entry/edit/edit.page.html @@ -31,7 +31,8 @@ - + + diff --git a/src/app/pages/entry/edit/edit.page.ts b/src/app/pages/entry/edit/edit.page.ts index 257157a..1167a4b 100644 --- a/src/app/pages/entry/edit/edit.page.ts +++ b/src/app/pages/entry/edit/edit.page.ts @@ -7,6 +7,7 @@ import { distinctUntilChanged, debounceTime } from 'rxjs/operators'; import { MatSnackBar } from '@angular/material/snack-bar'; import { MatChipInputEvent } from '@angular/material/chips'; import { TagsService } from 'src/app/services/tags.service'; +import { SettingsService } from 'src/app/services/settings.service'; @Component({ selector: 'page-entry-edit', @@ -23,11 +24,13 @@ export class PageEntryEdit implements OnInit { working: boolean = false; success: boolean = false; form: FormGroup; + settings: any; readonly tagsSeparatorKeysCodes = [ ENTER, COMMA, SPACE ] as const; @ViewChild('formDirective') private formDirective: NgForm; constructor(private entriesService: EntriesService, private tagsService: TagsService, + private settingsService: SettingsService, private formBuilder: FormBuilder, private route: ActivatedRoute, private snackBar: MatSnackBar) { } @@ -40,6 +43,10 @@ export class PageEntryEdit implements OnInit { text: [ '', Validators.nullValidator ], }); + this.settingsService.settings.subscribe((settings) => { + this.settings = settings; + }); + this.form.get('entryType').disable(); this.form.get('entryType').valueChanges.subscribe((value) => { diff --git a/src/app/pages/submission/submission.page.html b/src/app/pages/submission/submission.page.html index 304bfff..72272e8 100644 --- a/src/app/pages/submission/submission.page.html +++ b/src/app/pages/submission/submission.page.html @@ -38,7 +38,8 @@ - + + diff --git a/src/app/pages/submission/submission.page.ts b/src/app/pages/submission/submission.page.ts index 9bab0be..fb058f0 100644 --- a/src/app/pages/submission/submission.page.ts +++ b/src/app/pages/submission/submission.page.ts @@ -5,6 +5,7 @@ import { FormBuilder, FormGroup, Validators, NgForm } from '@angular/forms'; import { COMMA, ENTER, SPACE } from '@angular/cdk/keycodes'; import { distinctUntilChanged, debounceTime } from 'rxjs/operators'; import { MatChipInputEvent } from '@angular/material/chips'; +import { SettingsService } from 'src/app/services/settings.service'; @Component({ selector: 'page-submission', @@ -19,9 +20,11 @@ export class PageSubmission implements OnInit { form: FormGroup; readonly tagsSeparatorKeysCodes = [ ENTER, COMMA, SPACE ] as const; tags: string[] = []; + settings: any; @ViewChild('formDirective') private formDirective: NgForm; constructor(private entriesService: EntriesService, + private settingsService: SettingsService, private router: Router, private formBuilder: FormBuilder) { } @@ -33,6 +36,10 @@ export class PageSubmission implements OnInit { text: [ '', Validators.nullValidator ], }); + this.settingsService.settings.subscribe((settings) => { + this.settings = settings; + }); + this.form.get('entryType').setValue(this.entryType); this.form.get('entryType').valueChanges.subscribe((value) => { diff --git a/src/app/ui/entries/entries.ui.html b/src/app/ui/entries/entries.ui.html index 0fa7041..f511598 100644 --- a/src/app/ui/entries/entries.ui.html +++ b/src/app/ui/entries/entries.ui.html @@ -25,7 +25,7 @@ filter_alt
- + ; boundTagspickerChange: Function; - searchFormControl = new FormControl(); - readonly separatorKeysCodes = [ ENTER, COMMA, SPACE ] as const; constructor(private tagsService: TagsService) { } ngOnInit(): void { this.checkFilterOpen(); this.boundTagspickerChange = this.tagspickerChange.bind(this); - this.searchTags = this.searchFormControl - .valueChanges - .pipe( - debounceTime(300), - switchMap(value => this.tagsService.search(value)) - ); } checkFilterOpen() { @@ -54,7 +46,7 @@ export class UiEntries implements OnInit { tagspickerChange(value: any) { console.log("change", value); - this.setFilter('tag', value); + this.setFilter('tag', value[0]); } setFilter(key: string, value) { diff --git a/src/app/ui/tags/tagspicker.ui.html b/src/app/ui/tags/tagspicker.ui.html index f8ddbcb..5970956 100644 --- a/src/app/ui/tags/tagspicker.ui.html +++ b/src/app/ui/tags/tagspicker.ui.html @@ -1,4 +1,4 @@ - + tag{{tag}} @@ -6,9 +6,10 @@ cancel - + {{tags && tags.length || 0}}/{{max}} diff --git a/src/app/ui/tags/tagspicker.ui.ts b/src/app/ui/tags/tagspicker.ui.ts index 590e766..e5f27a9 100644 --- a/src/app/ui/tags/tagspicker.ui.ts +++ b/src/app/ui/tags/tagspicker.ui.ts @@ -18,7 +18,7 @@ export class UiTagsPicker implements OnInit { @Input() change: Function; @Input() model: any; @Input() placeholder: string; - @Input() singleton: boolean = false; + @Input() max: number = 0; tags: string[] = []; searchTags: Observable; @@ -37,13 +37,7 @@ export class UiTagsPicker implements OnInit { switchMap(value => this.tagsService.search(value)) ); - if (this.singleton) { - if (this.model) { - this.tags = [ this.model ]; - } - } else { - this.tags = this.model || []; - } + this.tags = this.model || []; } addTag(tag: string) { @@ -51,14 +45,11 @@ export class UiTagsPicker implements OnInit { tag = tag.replace('#', ''); } tag = tag.split('#').join('-'); - if (tag && this.tags.indexOf(tag) == -1) { + if (tag && this.tags.indexOf(tag) == -1 && (this.max == 0 || this.tags.length < this.max)) { this.tags.push(tag); } - if (this.singleton) { - this.model = this.tags && this.tags[ 0 ] || undefined; - } else { - this.model = this.tags; - } + + this.model = this.tags; if (this.change) { this.change(this.model); } @@ -80,11 +71,7 @@ export class UiTagsPicker implements OnInit { this.tags.splice(index, 1); } - if (this.singleton) { - this.model = undefined; - } else { - this.model = this.tags; - } + this.model = this.tags; if (this.change) { this.change(this.model);