From b36ac41bd10b2a79849f1d1249442088ee77804b Mon Sep 17 00:00:00 2001 From: Kyle Huckins Date: Tue, 15 Mar 2022 02:20:40 +0000 Subject: [PATCH] lp1942647 Provide Warning when deleting Term linked to Courses - Separates out Course Term Grid to its own component - Adds retrieval service function for Course/Term Maps based on Term ID - Displays Confirmation dialog when deleting terms on the term grid if term is mapped to a course Signed-off-by: Kyle Huckins Changes to be committed: modified: Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-list.component.html modified: Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-reserves.module.ts new file: Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-term-grid.component.html new file: Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-term-grid.component.ts modified: Open-ILS/src/eg2/src/app/staff/share/course.service.ts Signed-off-by: Beth Willis Signed-off-by: Michele Morgan --- .../course-reserves/course-list.component.html | 2 +- .../course-reserves/course-reserves.module.ts | 4 +- .../course-term-grid.component.html | 44 +++++ .../course-reserves/course-term-grid.component.ts | 186 ++++++++++++++++++++ .../src/eg2/src/app/staff/share/course.service.ts | 13 ++ 5 files changed, 247 insertions(+), 2 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-term-grid.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-term-grid.component.ts diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-list.component.html b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-list.component.html index 6fb0972..bd9a39e 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-list.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-list.component.html @@ -51,7 +51,7 @@
  • Terms - +
  • diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-reserves.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-reserves.module.ts index 149a39a..b7318a4 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-reserves.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-reserves.module.ts @@ -12,6 +12,7 @@ import {MarcSimplifiedEditorModule} from '@eg/staff/share/marc-edit/simplified-e import {PatronModule} from '@eg/staff/share/patron/patron.module'; import {CourseTermMapComponent} from './course-term-map.component'; import {CourseTermMapGridComponent} from './course-term-map-grid.component'; +import {TermListComponent} from './course-term-grid.component'; @NgModule({ declarations: [ @@ -20,7 +21,8 @@ import {CourseTermMapGridComponent} from './course-term-map-grid.component'; CourseAssociateMaterialComponent, CourseAssociateUsersComponent, CourseTermMapComponent, - CourseTermMapGridComponent + CourseTermMapGridComponent, + TermListComponent ], imports: [ StaffCommonModule, diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-term-grid.component.html b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-term-grid.component.html new file mode 100644 index 0000000..33b182c --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-term-grid.component.html @@ -0,0 +1,44 @@ + + + + + + + +
    +
    + + +
    +
    +
    + +
    + + + + + + + + + + +
    +
    + + + + + \ No newline at end of file diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-term-grid.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-term-grid.component.ts new file mode 100644 index 0000000..9b6fb70 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-term-grid.component.ts @@ -0,0 +1,186 @@ +import {Component, Input, ViewChild, OnInit, AfterViewInit} from '@angular/core'; +import {Router} from '@angular/router'; +import {IdlObject, IdlService} from '@eg/core/idl.service'; +import {PcrudService} from '@eg/core/pcrud.service'; +import {CourseService} from '@eg/staff/share/course.service'; +import {GridComponent} from '@eg/share/grid/grid.component'; +import {Pager} from '@eg/share/util/pager'; +import {GridDataSource, GridColumn} from '@eg/share/grid/grid'; +import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component'; +import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component'; +import {StringComponent} from '@eg/share/string/string.component'; +import {ToastService} from '@eg/share/toast/toast.service'; +import {LocaleService} from '@eg/core/locale.service'; +import {AuthService} from '@eg/core/auth.service'; +import {OrgService} from '@eg/core/org.service'; +import {OrgFamily} from '@eg/share/org-family-select/org-family-select.component'; + +@Component({ + selector: 'eg-course-term-grid', + templateUrl: './course-term-grid.component.html' +}) + +export class TermListComponent implements OnInit, AfterViewInit { + + @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent; + @ViewChild('deleteLinkedTermWarning', { static: true }) deleteLinkedTermWarning: ConfirmDialogComponent; + @ViewChild('grid') grid: GridComponent; + @ViewChild('successString', { static: true }) successString: StringComponent; + @ViewChild('createString') createString: StringComponent; + @ViewChild('createErrString') createErrString: StringComponent; + @ViewChild('updateFailedString') updateFailedString: StringComponent; + @ViewChild('deleteFailedString', { static: true }) deleteFailedString: StringComponent; + @ViewChild('deleteSuccessString', { static: true }) deleteSuccessString: StringComponent; + @ViewChild('deleteLinkedTermWarningString', { static: true }) deleteLinkedTermWarningString: StringComponent; + + @Input() sortField: string; + @Input() idlClass = 'acmt'; + @Input() dialog_size: 'sm' | 'lg' = 'lg'; + @Input() tableName = 'Term'; + grid_source: GridDataSource = new GridDataSource(); + currentMaterials: any[] = []; + search_value = ''; + defaultOuId: number; + searchOrgs: OrgFamily; + defaultTerm: IdlObject; + termToDelete: String; + + + constructor( + private courseSvc: CourseService, + private locale: LocaleService, + private auth: AuthService, + private idl: IdlService, + private org: OrgService, + private pcrud: PcrudService, + private router: Router, + private toast: ToastService + ) {} + + ngOnInit() { + this.getSource(); + this.defaultTerm = this.idl.create('acmt'); + this.defaultOuId = this.auth.user().ws_ou() || this.org.root().id(); + this.defaultTerm.owning_lib(this.defaultOuId); + this.searchOrgs = {primaryOrgId: this.defaultOuId}; + } + + ngAfterViewInit() { + this.grid.onRowActivate.subscribe((term: IdlObject) => { + const idToEdit = term.id(); + this.editSelected([term]); + }); + + } + + /** + * Gets the data, specified by the class, that is available. + */ + getSource() { + this.grid_source.getRows = (pager: Pager, sort: any[]) => { + const orderBy: any = {}; + if (sort.length) { + // Sort specified from grid + orderBy[this.idlClass] = sort[0].name + ' ' + sort[0].dir; + } else if (this.sortField) { + // Default sort field + orderBy[this.idlClass] = this.sortField; + } + const search: any = new Array(); + const orgFilter: any = {}; + orgFilter['owning_lib'] = + this.searchOrgs.orgIds || [this.defaultOuId]; + search.push(orgFilter); + const searchOps = { + offset: pager.offset, + limit: pager.limit, + order_by: orderBy + }; + return this.pcrud.search(this.idlClass, search, searchOps, {fleshSelectors: true}); + }; + } + + createNew() { + this.editDialog.mode = 'create'; + const course_module_term = this.idl.create('acmt'); + course_module_term.owning_lib(this.auth.user().ws_ou()); + this.editDialog.recordId = null; + this.editDialog.record = course_module_term; + this.editDialog.open({size: this.dialog_size}).subscribe( + ok => { + this.createString.current() + .then(str => this.toast.success(str)); + this.grid.reload(); + }, + rejection => { + if (!rejection.dismissed) { + this.createErrString.current() + .then(str => this.toast.danger(str)); + } + } + ); + } + + editSelected(fields: IdlObject[]) { + this.editDialog.mode = 'update'; + // Edit each IDL thing one at a time + const course_ids = []; + fields.forEach(field => { + this.editDialog.record = field; + this.editDialog.open({size: this.dialog_size}).subscribe( + ok => { + this.createString.current() + .then(str => this.toast.success(str)); + this.grid.reload(); + }, + rejection => { + if (!rejection.dismissed) { + this.createErrString.current() + .then(str => this.toast.danger(str)); + } + } + ); + }); + } + + deleteSelected(fields: IdlObject[]) { + console.log(this.deleteLinkedTermWarningString); + fields.forEach(field => { + let termHasLinkedCourses = false; + this.courseSvc.getTermMaps(field.id()).subscribe(map => { + if (map) { + termHasLinkedCourses = true; + } + }, err => { + console.error(err); + }, () => { + if (termHasLinkedCourses) { + this.termToDelete = field.name(); + this.deleteLinkedTermWarning.open().toPromise().then(yes => { + if (!yes) return; + this.doDelete(field); + }); + } else { + this.doDelete(field); + } + }); + }); + + } + + doDelete(idlThing: IdlObject) { + idlThing.isdeleted(true); + this.pcrud.autoApply(idlThing).subscribe( + val => { + console.debug('deleted: ' + val); + this.deleteSuccessString.current() + .then(str => this.toast.success(str)); + }, + err => { + this.deleteFailedString.current() + .then(str => this.toast.danger(str)); + }, + () => this.grid.reload() + ); + } +} diff --git a/Open-ILS/src/eg2/src/app/staff/share/course.service.ts b/Open-ILS/src/eg2/src/app/staff/share/course.service.ts index 080626b..6c84647 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/course.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/course.service.ts @@ -86,6 +86,19 @@ export class CourseService { }); } + getTermMaps(term_ids) { + const flesher = {flesh: 2, flesh_fields: { + 'acmtcm': ['course']}}; + + if (!term_ids) { + return this.pcrud.retrieveAll('acmtcm', + flesher); + } else { + return this.pcrud.search('acmtcm', {term: term_ids}, + flesher); + } + } + fetchCoursesForRecord(recordId) { const courseIds = new Set(); return this.pcrud.search( -- 1.7.2.5