From 638261714371dad0e3914120253e099da9c13794 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Sun, 28 Mar 2021 17:17:02 -0400 Subject: [PATCH] funds: implement fund tags component Signed-off-by: Galen Charlton --- .../acq/funds/fund-details-dialog.component.html | 1 + .../acq/funds/fund-details-dialog.component.ts | 1 + .../staff/admin/acq/funds/fund-tags.component.html | 34 ++++++ .../staff/admin/acq/funds/fund-tags.component.ts | 124 +++++++++++++++++++++ .../src/app/staff/admin/acq/funds/funds.module.ts | 4 +- 5 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-tags.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-tags.component.ts diff --git a/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-details-dialog.component.html b/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-details-dialog.component.html index a2f30b86c7..1ee4a0f22c 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-details-dialog.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-details-dialog.component.html @@ -125,6 +125,7 @@ Tags
+
diff --git a/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-details-dialog.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-details-dialog.component.ts index f1cca336c2..0c985db8b9 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-details-dialog.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-details-dialog.component.ts @@ -13,6 +13,7 @@ import {Pager} from '@eg/share/util/pager'; import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; import {StringComponent} from '@eg/share/string/string.component'; import {ToastService} from '@eg/share/toast/toast.service'; +import {FundTagsComponent} from './fund-tags.component'; @Component({ selector: 'eg-fund-details-dialog', diff --git a/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-tags.component.html b/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-tags.component.html new file mode 100644 index 0000000000..c9715779b2 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-tags.component.html @@ -0,0 +1,34 @@ +Added tag + +Failed to add tag + +Removed tag + +Failed to remove tag + + +
+
+ + {{ftm.tag().name()}} ({{ftm.tag().owner().shortname()}}) +
+
+
+
+ +
+
+ +
+
+ (tag is already assigned to this fund) +
+
diff --git a/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-tags.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-tags.component.ts new file mode 100644 index 0000000000..529bca2792 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-tags.component.ts @@ -0,0 +1,124 @@ +import {Component, OnInit, Input, ViewChild} from '@angular/core'; +import {IdlService, IdlObject} from '@eg/core/idl.service'; +import {EventService} from '@eg/core/event.service'; +import {NetService} from '@eg/core/net.service'; +import {AuthService} from '@eg/core/auth.service'; +import {PcrudService} from '@eg/core/pcrud.service'; +import {OrgService} from '@eg/core/org.service'; +import {StringComponent} from '@eg/share/string/string.component'; +import {ToastService} from '@eg/share/toast/toast.service'; +import {ComboboxComponent} from '@eg/share/combobox/combobox.component'; +import {ComboboxEntry} from '@eg/share/combobox/combobox.component'; +import {Observable} from 'rxjs'; +import {map} from 'rxjs/operators'; + +@Component({ + selector: 'eg-fund-tags', + templateUrl: './fund-tags.component.html' +}) +export class FundTagsComponent implements OnInit { + + @Input() fundId: number; + @Input() fundOwner: number; + + @ViewChild('addSuccessString', { static: true }) addSuccessString: StringComponent; + @ViewChild('addErrorString', { static: true }) addErrorString: StringComponent; + @ViewChild('removeSuccessString', { static: true }) removeSuccessString: StringComponent; + @ViewChild('removeErrorString', { static: true }) removeErrorString: StringComponent; + @ViewChild('tagSelector', { static: false }) tagSelector: ComboboxComponent; + + tagMaps: IdlObject[]; + newTag: ComboboxEntry = null; + tagSelectorDataSource: (term: string) => Observable + + constructor( + private idl: IdlService, + private evt: EventService, + private net: NetService, + private auth: AuthService, + private pcrud: PcrudService, + private org: OrgService, + private toast: ToastService + ) {} + + ngOnInit() { + this._loadTagMaps(); + this.tagSelectorDataSource = term => { + const field = 'name'; + const args = {}; + const extra_args = { order_by : {} }; + args[field] = {'ilike': `%${term}%`}; // could -or search on label + args['owner'] = this.org.ancestors(this.fundOwner, true) + extra_args['order_by']['acqft'] = field; + extra_args['limit'] = 100; + extra_args['flesh'] = 2; + const flesh_fields: Object = {}; + flesh_fields['acqft'] = ['owner']; + extra_args['flesh_fields'] = flesh_fields; + return this.pcrud.search('acqft', args, extra_args).pipe(map(data => { + return { + id: data.id(), + label: data.name() + ' (' + data.owner().shortname() + ')', + fm: data + }; + })); + }; + } + + _loadTagMaps() { + this.tagMaps = []; + this.pcrud.search('acqftm', { fund: this.fundId }, { + flesh: 2, + flesh_fields: { + acqftm: ['tag'], + acqft: ['owner'] + } + }).subscribe( + res => this.tagMaps.push(res), + err => {}, + () => this.tagMaps.sort((a, b) => { + return a.tag().name() < b.tag().name() ? -1 : 1 + }) + ); + } + + checkNewTagAlreadyMapped(): boolean { + if ( this.newTag == null) { return false; } + const matches: IdlObject[] = this.tagMaps.filter(tm => tm.tag().id() === this.newTag.id); + return matches.length > 0 ? true : false; + } + + addTagMap() { + const ftm = this.idl.create('acqftm'); + ftm.tag(this.newTag.id); + ftm.fund(this.fundId); + this.pcrud.create(ftm).subscribe( + ok => { + this.addSuccessString.current() + .then(str => this.toast.success(str)); + }, + err => { + this.addErrorString.current() + .then(str => this.toast.danger(str)); + }, + () => { + this.newTag = null; + this.tagSelector.selectedId = null; + this._loadTagMaps(); + } + ); + } + removeTagMap(ftm: IdlObject) { + this.pcrud.remove(ftm).subscribe( + ok => { + this.removeSuccessString.current() + .then(str => this.toast.success(str)); + }, + err => { + this.removeErrorString.current() + .then(str => this.toast.danger(str)); + }, + () => this._loadTagMaps() + ) + } +} diff --git a/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/funds.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/funds.module.ts index a74dadd36a..5f3892bf3b 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/funds.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/acq/funds/funds.module.ts @@ -7,6 +7,7 @@ import {FundsManagerComponent} from './funds-manager.component'; import {FundDetailsDialogComponent} from './fund-details-dialog.component'; import {FundingSourcesComponent} from './funding-sources.component'; import {FundingSourceTransactionsDialogComponent} from './funding-source-transactions-dialog.component'; +import {FundTagsComponent} from './fund-tags.component'; @NgModule({ declarations: [ @@ -14,7 +15,8 @@ import {FundingSourceTransactionsDialogComponent} from './funding-source-transac FundsManagerComponent, FundDetailsDialogComponent, FundingSourcesComponent, - FundingSourceTransactionsDialogComponent + FundingSourceTransactionsDialogComponent, + FundTagsComponent ], imports: [ StaffCommonModule, -- 2.11.0