this.copyAlertsDialog.inPlaceCreateMode = true;
this.copyAlertsDialog.copyIds = this.context.copyList().map(c => c.id());
- this.copyAlertsDialog.open({size: 'lg'}).subscribe(
- newAlert => {
- if (newAlert) {
- this.context.copyList().forEach(copy => {
+ this.copyAlertsDialog.open({size: 'lg'}).subscribe(changes => {
+ if (!changes) { return; }
+
+ if ((!changes.newAlerts || changes.newAlerts.length === 0) &&
+ (!changes.changedAlerts || changes.changedAlerts.length === 0)
+ ) {
+ return;
+ }
+
+ if (changes.newAlerts) {
+ this.context.copyList().forEach(copy => {
+ changes.newAlerts.forEach(newAlert => {
const a = this.idl.clone(newAlert);
a.isnew(true);
a.copy(copy.id());
copy.copy_alerts().push(a);
copy.ischanged(true);
});
- }
+ });
}
- );
+ if (changes.changedAlerts && this.context.copyList().length === 1) {
+ const copy = this.context.copyList()[0];
+ changes.changedAlerts.forEach(alert => {
+ const existing = copy.copy_alerts().filter(a => a.id() === alert.id())[0];
+ if (existing) {
+ existing.ischanged(true);
+ existing.alert_type(alert.alert_type());
+ existing.temp(alert.temp());
+ existing.ack_time(alert.ack_time());
+ if (alert.ack_time() === 'now') {
+ existing.ack_staff(this.auth.user().id());
+ }
+ copy.ischanged(true);
+ }
+ });
+ }
+ });
}
openCopyTags() {
flesh_fields: {
acp: [
'call_number', 'location', 'parts', 'tags',
- 'creator', 'editor', 'stat_cat_entries', 'notes'
+ 'creator', 'editor', 'stat_cat_entries', 'notes',
+ 'copy_alerts'
],
acptcm: ['tag'],
acpt: ['tag_type']
</eg-grid-toolbar-action>
<eg-grid-toolbar-action
- i18n-group group="Add" i18n-label label="Add Item Alerts"
- (onClick)="openItemAlerts($event, 'create')">
+ i18n-group group="Add" i18n-label label="Add/Manage Item Alerts"
+ (onClick)="openItemAlerts($event)">
</eg-grid-toolbar-action>
<eg-grid-toolbar-action
</eg-grid-toolbar-action>
<eg-grid-toolbar-action
- i18n-group group="Edit" i18n-label label="Edit Item Alerts"
- (onClick)="openItemAlerts($event, 'manage')">
- </eg-grid-toolbar-action>
-
- <eg-grid-toolbar-action
i18n-group group="Edit" i18n-label label="Replace Barcodes"
(onClick)="openReplaceBarcodeDialog($event)">
</eg-grid-toolbar-action>
}
}
- openItemAlerts(rows: HoldingsEntry[], mode: string) {
+ openItemAlerts(rows: HoldingsEntry[]) {
const copyIds = this.selectedCopyIds(rows);
if (copyIds.length === 0) { return; }
this.copyAlertsDialog.copyIds = copyIds;
- this.copyAlertsDialog.mode = mode;
this.copyAlertsDialog.open({size: 'lg'}).subscribe(
- modified => {
- if (modified) {
+ changes => {
+ if (!changes) { return; }
+ if (changes.newAlerts.length > 0 || changes.changedAlerts.length > 0) {
this.hardRefresh();
}
}
<div class="row mt-2 p-2 rounded border border-success">
<div class="col-lg-4">
<eg-combobox [entries]="alertTypes"
- i18n-placeholder placeholder="New Alert Type..."
- [required]="true"
+ i18n-placeholder placeholder="Select Alert Type..."
+ [selectedId]="newAlert.alert_type()"
+ [mandatory]="true"
(onChange)="newAlert.alert_type($event ? $event.id : null)">
</eg-combobox>
</div>
</div>
</div>
</div>
+ <h4 class="mt-2" i18n *ngIf="newAlerts.length > 0">Pending New Alerts</h4>
+ <div class="row mt-2" *ngFor="let alert of newAlerts">
+ <div class="col-lg-4">{{getAlertTypeLabel(alert)}}</div>
+ <div class="col-lg-5">{{alert.note()}}</div>
+ <div class="col-lg-3">
+ <button class="btn btn-outline-danger" (click)="removeAlert(alert)" i18n>
+ Remove
+ </button>
+ </div>
+ </div>
+
<ng-container *ngIf="mode == 'manage'">
<!-- in manage mode list all of the alerts linked to the copy -->
<div class="row mt-2"
<div class="modal-footer">
<button type="button" class="btn btn-secondary"
(click)="close()" i18n>Close</button>
- <ng-container *ngIf="mode == 'manage'">
- <button class="btn btn-success mr-2"
- (click)="applyChanges()" i18n>Apply Changes</button>
- </ng-container>
+ <button class="btn btn-success mr-2"
+ (click)="applyChanges()" i18n>Apply Changes</button>
</div>
</ng-template>
* Dialog for managing copy alerts.
*/
+export interface CopyAlertsChanges {
+ newAlerts: IdlObject[];
+ changedAlerts: IdlObject[];
+}
+
@Component({
selector: 'eg-copy-alerts-dialog',
templateUrl: 'copy-alerts-dialog.component.html'
alertTypes: ComboboxEntry[];
newAlert: IdlObject;
+ newAlerts: IdlObject[];
+ autoId = -1;
changesMade: boolean;
@ViewChild('successMsg', { static: true }) private successMsg: StringComponent;
* Dialog promise resolves with true/false indicating whether
* the mark-damanged action occured or was dismissed.
*/
- open(args: NgbModalOptions): Observable<boolean> {
+ open(args: NgbModalOptions): Observable<CopyAlertsChanges> {
this.copy = null;
this.copies = [];
this.newAlert = this.idl.create('aca');
+ this.newAlerts = [];
this.newAlert.create_staff(this.auth.user().id());
if (this.copyIds.length === 0 && !this.inPlaceCreateMode) {
});
}
+ getAlertTypeLabel(alert: IdlObject): string {
+ const alertType = this.alertTypes.filter(t => t.id === alert.alert_type());
+ return alertType[0].label;
+ }
+
+ removeAlert(alert: IdlObject) {
+ // the only type of alerts we can remove are pending ones that
+ // we have created during the lifetime of this modal; alerts
+ // that already exist can only be cleared
+ this.newAlerts = this.newAlerts.filter(t => t.id() !== alert.id());
+ }
+
// Add the in-progress new note to all copies.
addNew() {
if (!this.newAlert.alert_type()) { return; }
+ this.newAlert.id(this.autoId--);
+ this.newAlert.isnew(true);
+ this.newAlerts.push(this.newAlert);
+
+ this.newAlert = this.idl.create('aca');
+
+ }
+
+ applyChanges() {
+
+ const changedAlerts = this.copy ?
+ this.copy.copy_alerts().filter(a => a.ischanged()) :
+ [];
if (this.inPlaceCreateMode) {
- this.close(this.newAlert);
+ this.close({ newAlerts: this.newAlerts, changedAlerts: changedAlerts });
return;
}
- const alerts: IdlObject[] = [];
- this.copies.forEach(c => {
- const a = this.idl.clone(this.newAlert);
- a.copy(c.id());
- alerts.push(a);
+ const alerts = [];
+ this.newAlerts.forEach(alert => {
+ this.copies.forEach(c => {
+ const a = this.idl.clone(alert);
+ a.isnew(true);
+ a.id(null);
+ a.copy(c.id());
+ alerts.push(a);
+ });
});
-
- this.pcrud.create(alerts).toPromise().then(
- newAlert => {
+ if (this.mode === 'manage') {
+ changedAlerts.forEach(alert => {
+ alerts.push(alert);
+ });
+ }
+ this.pcrud.autoApply(alerts).toPromise().then(
+ ok => {
this.successMsg.current().then(msg => this.toast.success(msg));
- this.changesMade = true;
- if (this.mode === 'create') {
- // In create mode, we assume the user wants to create
- // a single alert and be done with it.
- this.close(this.changesMade);
- } else {
- // Otherwise, add the alert to the copy
- this.copy.copy_alerts().push(newAlert);
- }
+ this.close({ newAlerts: this.newAlerts, changedAlerts: changedAlerts });
},
- err => {
- this.errorMsg.current().then(msg => this.toast.danger(msg));
- }
- );
- }
-
- applyChanges() {
- const alerts = this.copy.copy_alerts().filter(a => a.ischanged());
- if (alerts.length === 0) { return; }
- this.pcrud.update(alerts).toPromise().then(
- ok => this.successMsg.current().then(msg => this.toast.success(msg)),
err => this.errorMsg.current().then(msg => this.toast.danger(msg))
);
}
}
-