import {Component, OnInit, AfterViewInit, ViewChild, Renderer2} from '@angular/core';
import {Router, ActivatedRoute, ParamMap} from '@angular/router';
import {tap} from 'rxjs/operators';
-import {IdlObject} from '@eg/core/idl.service';
+import {IdlObject, IdlService} from '@eg/core/idl.service';
+import {EventService} from '@eg/core/event.service';
import {OrgService} from '@eg/core/org.service';
+import {NetService} from '@eg/core/net.service';
+import {AuthService} from '@eg/core/auth.service';
import {PcrudService} from '@eg/core/pcrud.service';
import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
import {VolCopyContext} from './volcopy';
private router: Router,
private route: ActivatedRoute,
private renderer: Renderer2,
+ private evt: EventService,
+ private idl: IdlService,
private org: OrgService,
+ private net: NetService,
+ private auth: AuthService,
private pcrud: PcrudService,
private holdings: HoldingsService
) { }
{}, {idlist: true, atomic: true}
).toPromise().then(volIds =>this.fetchVols(volIds));
}
+
+
+ save() {
+ this.loadingProgress.reset();
+ this.loading = true;
+
+ // Volume update API wants volumes fleshed with copies, instead
+ // of the other way around, which is what we have here.
+ const volumes: IdlObject[] = [];
+
+ this.context.volNodes().forEach(volNode => {
+ const newVol = this.idl.clone(volNode.target);
+ const copies: IdlObject[] = [];
+
+ volNode.children.forEach(copyNode => {
+ const copy = copyNode.target;
+
+ if (copy.ischanged() || copy.isnew() || copy.isdeleted()) {
+ const copyClone = this.idl.clone(copy);
+ // De-flesh call number
+ copyClone.call_number(copy.call_number().id());
+ copies.push(copyClone);
+ }
+ });
+
+ newVol.copies(copies);
+
+ if (newVol.ischanged() || newVol.isnew() || copies.length > 0) {
+ volumes.push(newVol);
+ }
+ });
+
+ // TODO: deletedVols and deletedCopies
+
+ if (volumes.length > 0) {
+ this.saveApi(volumes);
+ }
+ }
+
+ saveApi(volumes: IdlObject[], override?: boolean) {
+
+ let method = 'open-ils.cat.asset.volume.fleshed.batch.update';
+ if (override) { method += '.override'; }
+
+ this.net.request('open-ils.cat',
+ method, this.auth.token(), volumes).toPromise()
+
+ .then(resp => {
+
+ const evt = this.evt.parse(resp);
+
+ // TODO: confirm / handle overrides
+
+ if (evt) {
+ alert(evt);
+ return;
+ }
+
+ return this.load();
+ });
+ }
}