Merge branch 'user/khuckins/lp1929588-duplicate-course' into course-material-test-3
authorKyle Huckins <khuckins@catalyte.io>
Tue, 22 Mar 2022 21:29:01 +0000 (21:29 +0000)
committerKyle Huckins <khuckins@catalyte.io>
Tue, 22 Mar 2022 21:29:01 +0000 (21:29 +0000)
1  2 
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

@@@ -7,8 -7,8 +7,10 @@@
  <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 #unarchiveFailedString i18n-text text="Reopening of {{tableName}} failed or was not allowed"></eg-string>
 +<eg-string #unarchiveSuccessString i18n-text text="Reopening 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">
            </eg-grid-toolbar-action>
            <eg-grid-toolbar-action label="Delete Selected" i18n-label (onClick)="deleteSelected($event)">
            </eg-grid-toolbar-action>
 -          <eg-grid-toolbar-action label="Archive Selected" i18n-label (onClick)="archiveSelected($event)">
 +          <eg-grid-toolbar-action label="Archive Selected" i18n-label (onClick)="archiveSelected($event)" [disabled]="is_archived">
 +          </eg-grid-toolbar-action>
 +          <eg-grid-toolbar-action label="Reopen Selected" i18n-label (onClick)="unarchiveSelected($event)" [disabled]="!is_archived">
            </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>
@@@ -36,8 -36,8 +36,10 @@@ export class CourseListComponent implem
      @ViewChild('deleteSuccessString', { static: true }) deleteSuccessString: StringComponent;
      @ViewChild('archiveFailedString', { static: true }) archiveFailedString: StringComponent;
      @ViewChild('archiveSuccessString', { static: true }) archiveSuccessString: StringComponent;
 +    @ViewChild('unarchiveFailedString', { static: true }) unarchiveFailedString: StringComponent;
 +    @ViewChild('unarchiveSuccessString', { static: true }) unarchiveSuccessString: StringComponent;
+     @ViewChild('duplicateFailedString', { static: true }) duplicateFailedString: StringComponent;
+     @ViewChild('duplicateSuccessString', { static: true }) duplicateSuccessString: StringComponent;
      @ViewChild('courseMaterialDialog', {static: true})
          private courseMaterialDialog: CourseAssociateMaterialComponent;
      @ViewChild('courseUserDialog', {static: true})
              );
          });
      }
 +    
 +    courseArchiveableOrNot(course: IdlObject[], archiveBool) {
 +        course.forEach(courseToMod => {
 +            if (archiveBool == false) return courseToMod.is_archived() == 't';
 +            return courseToMod.is_archived() == 'f';
 +        });
 +    }
 +
 +    unarchiveSelected(course: IdlObject[]) {
 +        course.forEach(courseToUnarchive => {
 +            courseToUnarchive.is_archived(false);
 +        });
 +        this.pcrud.update(course).subscribe(
 +            val => {
 +                course.forEach(courseEntry => {
 +                    this.courseSvc.removeNonPublicUsers(courseEntry.id());
 +                });
 +                console.debug('archived: ' + val);
 +                this.unarchiveSuccessString.current()
 +                    .then(str => this.toast.success(str));
 +            }, err => {
 +                this.unarchiveFailedString.current()
 +                    .then(str => this.toast.danger(str));
 +            }, () => {
 +                this.grid.reload();
 +            }
 +        );
 +    }
  
+     duplicateSelected(course: IdlObject[]) {
+         let new_course = this.idl.create('acmc');;
+         course.forEach(courseToCopy => {
+             new_course.name(courseToCopy.name() + " (Copy));
+             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 => {