lp1929588 Duplicate Course
authorKyle Huckins <khuckins@catalyte.io>
Sun, 27 Feb 2022 04:44:37 +0000 (04:44 +0000)
committerJane Sandberg <js7389@princeton.edu>
Thu, 7 Apr 2022 21:24:20 +0000 (14:24 -0700)
- Add Grid action to duplicate existing course

Signed-off-by: Kyle Huckins <khuckins@catalyte.io>
Signed-off-by: Jane Sandberg <js7389@princeton.edu>
Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-list.component.html
Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-list.component.ts

index 6fb0972..f3763f5 100644 (file)
@@ -7,6 +7,8 @@
 <eg-string #deleteSuccessString i18n-text text="Deletion of {{tableName}} was successful"></eg-string>
 <eg-string #archiveFailedString i18n-text text="Archival of {{tableName}} failed or was not allowed"></eg-string>
 <eg-string #archiveSuccessString i18n-text text="Archival of {{tableName}} succeeded"></eg-string>
+<eg-string #duplicateFailedString i18n-text text="Duplication of {{tableName}} failed or was not allowed"></eg-string>
+<eg-string #duplicateSuccessString i18n-text text="Duplication of {{tableName}} succeeded"></eg-string>
 <eg-string #flairTooltip i18n-text text="Limited Editing"></eg-string>
 
 <ul ngbNav #courseListNav="ngbNav" class="nav-tabs">
@@ -38,6 +40,8 @@
           </eg-grid-toolbar-action>
           <eg-grid-toolbar-action label="Archive Selected" i18n-label (onClick)="archiveSelected($event)">
           </eg-grid-toolbar-action>
+          <eg-grid-toolbar-action label="Duplicate Selected" i18n-label (onClick)="duplicateSelected($event)">
+          </eg-grid-toolbar-action>
           <eg-grid-column label="ID" path="id" [index]=true [hidden]="true" i18n-label></eg-grid-column>
           <eg-grid-column label="Terms taught" name="terms_map" i18n-label [cellTemplate]="termMapLink"></eg-grid-column>
           <eg-grid-column label="Course Name" name="name" i18n-label></eg-grid-column>
index 2ba9d40..3f0f72c 100644 (file)
@@ -36,6 +36,8 @@ export class CourseListComponent implements OnInit, AfterViewInit {
     @ViewChild('deleteSuccessString', { static: true }) deleteSuccessString: StringComponent;
     @ViewChild('archiveFailedString', { static: true }) archiveFailedString: StringComponent;
     @ViewChild('archiveSuccessString', { static: true }) archiveSuccessString: StringComponent;
+    @ViewChild('duplicateFailedString', { static: true }) duplicateFailedString: StringComponent;
+    @ViewChild('duplicateSuccessString', { static: true }) duplicateSuccessString: StringComponent;
     @ViewChild('courseMaterialDialog', {static: true})
         private courseMaterialDialog: CourseAssociateMaterialComponent;
     @ViewChild('courseUserDialog', {static: true})
@@ -181,6 +183,26 @@ export class CourseListComponent implements OnInit, AfterViewInit {
         });
     }
 
+    duplicateSelected(course: IdlObject[]) {
+        let new_course = this.idl.create('acmc');;
+        course.forEach(courseToCopy => {
+            new_course.name(courseToCopy.name());
+            new_course.course_number(courseToCopy.course_number());
+            new_course.section_number(courseToCopy.section_number());
+            new_course.owning_lib(courseToCopy.owning_lib());
+            new_course.is_archived(courseToCopy.is_archived());
+            this.pcrud.create(new_course).subscribe(val => {
+                console.debug('duplicated: ' + val);
+                this.duplicateSuccessString.current()
+                    .then(str => this.toast.success(str));
+            }, err => {
+                this.duplicateFailedString.current()
+                    .then(str => this.toast.danger(str));
+            }, () => this.grid.reload()
+            );
+        });
+    }
+
     deleteSelected(idlObject: IdlObject[]) {
         this.courseSvc.disassociateMaterials(idlObject).then(res => {
             idlObject.forEach(object => {