From: Bill Erickson Date: Thu, 21 May 2020 19:29:07 +0000 (-0400) Subject: LPXXX MARC Batch update Angular port X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=315ff05d38d89b6e77fa39185ae8e9b3f5b48731;p=working%2FEvergreen.git LPXXX MARC Batch update Angular port Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/staff/cat/marcbatch/marcbatch.component.html b/Open-ILS/src/eg2/src/app/staff/cat/marcbatch/marcbatch.component.html index 68c2bde0cd..82a91f9481 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/marcbatch/marcbatch.component.html +++ b/Open-ILS/src/eg2/src/app/staff/cat/marcbatch/marcbatch.component.html @@ -1,7 +1,7 @@
-
+

@@ -12,10 +12,11 @@
Action (Rule Type)
- + + +
How to change the existing record.
@@ -23,7 +24,8 @@
MARC Tag
- +
Three characters, no spaces, no indicators, etc. eg: 245 @@ -32,14 +34,16 @@
Subfields (optional)
- +
No spaces, no delimiters, eg: abcnp
MARC Data
- +
MARC-Breaker formatted data with indicators and subfield delimiters, @@ -55,23 +59,54 @@
Subfield
-
-
+
+ +
+
+ A single subfield code, no delimiters, eg: a +
Expression
-
-
+
+ +
+
+ See the + + Perl documentation + for an explanation of Regular Expressions. +
+
+
+
+ +
+
+
+ +
+
Update Template Preview
- +
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/marcbatch/marcbatch.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/marcbatch/marcbatch.component.ts index b79cf104cb..44e132cf98 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/marcbatch/marcbatch.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/marcbatch/marcbatch.component.ts @@ -5,9 +5,10 @@ import {NetService} from '@eg/core/net.service'; import {AuthService} from '@eg/core/auth.service'; import {PcrudService} from '@eg/core/pcrud.service'; import {ComboboxEntry} from '@eg/share/combobox/combobox.component'; +import {MarcRecord, MarcField} from '@eg/staff/share/marc-edit/marcrecord'; interface TemplateRule { - ruleType: 'replace' | 'add' | 'delete'; + ruleType: 'r' | 'a' | 'd'; marcTag?: string; marcSubfields?: string; marcData?: string; @@ -28,8 +29,8 @@ export class MarcBatchComponent implements OnInit, AfterViewInit { csvColumn = 0; selectedFile: File; xactPerRecord = false; - templateBreaker = ''; templateRules: TemplateRule[] = []; + record: MarcRecord; constructor( private router: Router, @@ -49,10 +50,89 @@ export class MarcBatchComponent implements OnInit, AfterViewInit { } load() { - this.templateRules = [{ruleType: 'replace'}]; + this.addRule(); this.getBuckets(); } + rulesetToRecord(resetRuleData?: boolean) { + this.record = new MarcRecord(); + + this.templateRules.forEach(rule => { + + let ruleText = rule.marcTag + (rule.marcSubfields || ''); + if (rule.advSubfield) { + ruleText += `[${rule.advSubfield} ~ ${rule.advRegex}]`; + } + + // Merge behavior is encoded in the 905 field. + const ruleTag = this.record.newField({ + tag: '905', + ind1: ' ', + ind2: ' ', + subfields: [[rule.ruleType, ruleText, 0]] + }); + + this.record.insertOrderedFields(ruleTag); + + if (rule.ruleType === 'd') { return; } + + const dataRec = new MarcRecord(); + if (resetRuleData) { + + // Build a new value for the 'MARC Data' field based on + // changes to the selected tag or subfields. + + const subfields = rule.marcSubfields ? + rule.marcSubfields.split('').map((sf, idx) => [sf, '', idx]) + : []; + + dataRec.appendFields( + dataRec.newField({ + tag: rule.marcTag, + ind1: ' ', + ind2: ' ', + subfields: subfields + }) + ); + + console.log(dataRec.toBreaker()); + rule.marcData = dataRec.toBreaker().split(/\n/)[1]; + + } else { + + // Absorb the breaker data already in the 'MARC Data' field + // so it can be added to the template record in progress. + + dataRec.breakerText = rule.marcData; + dataRec.absorbBreakerChanges(); + } + + this.record.appendFields(dataRec.fields[0]); + }); + } + + breakerRows(): number { + if (this.record) { + const breaker = this.record.toBreaker(); + if (breaker) { + return breaker.split(/\n/).length + 1; + } + } + return 3; + } + + breaker(): string { + return this.record ? this.record.toBreaker() : ''; + } + + addRule() { + this.templateRules.push({ruleType: 'r'}); + } + + removeRule(idx: number) { + this.templateRules.splice(idx, 1); + } + getBuckets(): Promise { if (this.buckets) { return Promise.resolve(); } diff --git a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/marcrecord.ts b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/marcrecord.ts index d49f4ef568..4ba850bd17 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/marc-edit/marcrecord.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/marc-edit/marcrecord.ts @@ -60,7 +60,7 @@ export class MarcRecord { this.record.fields = f; } - constructor(xml: string) { + constructor(xml?: string) { this.record = new MARC21.Record({marcxml: xml, delimiter: DELIMITER}); this.breakerText = this.record.toBreaker(); this.fixedFieldChange = new EventEmitter(); @@ -113,6 +113,11 @@ export class MarcRecord { return this.record.field(spec, wantArray); } + appendFields(...newFields: MarcField[]) { + this.record.appendFields.apply(this.record, newFields); + this.stampFieldIds(); + } + insertFieldsBefore(field: MarcField, ...newFields: MarcField[]) { this.record.insertFieldsBefore.apply( this.record, [field].concat(newFields));