From 10ca64d16c53bc86110ff1ef8ae63773d70da7cd Mon Sep 17 00:00:00 2001 From: amontenegro Date: Thu, 14 Dec 2023 22:15:10 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20GITHUB=20ACTIONS=20format=5Fpret?= =?UTF-8?q?tier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../work-contributors.component.html | 16 +-- .../work-contributors.component.spec.ts | 2 +- .../work-contributors.component.ts | 6 +- .../work-bibtex-modal.component.ts | 110 ++++++++---------- 4 files changed, 56 insertions(+), 78 deletions(-) diff --git a/src/app/record/components/work-contributors/work-contributors.component.html b/src/app/record/components/work-contributors/work-contributors.component.html index fae9214381..37f972fe64 100644 --- a/src/app/record/components/work-contributors/work-contributors.component.html +++ b/src/app/record/components/work-contributors/work-contributors.component.html @@ -31,11 +31,7 @@

- +
- +
{ const mockFormGroup: UntypedFormGroup = new UntypedFormGroup({}) component['parentForm'].form = mockFormGroup component.userRecord = getUserRecord() - + fixture.detectChanges() loader = TestbedHarnessEnvironment.loader(fixture) }) diff --git a/src/app/record/components/work-contributors/work-contributors.component.ts b/src/app/record/components/work-contributors/work-contributors.component.ts index c534ca65dd..c70bd32096 100644 --- a/src/app/record/components/work-contributors/work-contributors.component.ts +++ b/src/app/record/components/work-contributors/work-contributors.component.ts @@ -69,7 +69,7 @@ export class WorkContributorsComponent implements OnInit, OnDestroy { maxNumberOfContributors = 49 maxNumberOfContributorsSummary = 10 privateName = 'Name is private' - + contributionRoles = ContributionRoles recordHolderContribution: Contributor @@ -87,9 +87,7 @@ export class WorkContributorsComponent implements OnInit, OnDestroy { private platform: PlatformInfoService, private workService: RecordWorksService, private affiliationService: RecordAffiliationService - ) { - - } + ) {} get contributorsFormArray() { return this.parentForm.control.controls['contributors'] as UntypedFormArray diff --git a/src/app/record/components/work-stack-group/modals/work-bibtex-modal/work-bibtex-modal.component.ts b/src/app/record/components/work-stack-group/modals/work-bibtex-modal/work-bibtex-modal.component.ts index 0f0e3bae6e..da13f235d0 100644 --- a/src/app/record/components/work-stack-group/modals/work-bibtex-modal/work-bibtex-modal.component.ts +++ b/src/app/record/components/work-stack-group/modals/work-bibtex-modal/work-bibtex-modal.component.ts @@ -61,74 +61,65 @@ export class WorkBibtexModalComponent implements OnInit, OnDestroy { let parsed = null try { parsed = bibtexParse.toJSON(reader.result) - if ( - typeof parsed === 'string' && - parsed.substring(0, 5).toLowerCase().indexOf('error') > -1 - ) { - that.bibtexErrorParsingText = parsed - that.bibtexErrorParsing = true - that.loadingWorks = false - } else { - if (parsed) { - const newWorks = [] - if (parsed.length === 0) { - that.bibtexErrorNoEntries = true - that.loadingWorks = false - } - while (parsed.length > 0) { - const cur = parsed.shift() - const bibtexEntry = cur.entryType.toLowerCase() - if ( - bibtexEntry !== 'preamble' && - bibtexEntry !== 'comment' - ) { - newWorks.push( - that.populateWork( - cur - ) - ) - } + if ( + typeof parsed === 'string' && + parsed.substring(0, 5).toLowerCase().indexOf('error') > -1 + ) { + that.bibtexErrorParsingText = parsed + that.bibtexErrorParsing = true + that.loadingWorks = false + } else { + if (parsed) { + const newWorks = [] + if (parsed.length === 0) { + that.bibtexErrorNoEntries = true + that.loadingWorks = false + } + while (parsed.length > 0) { + const cur = parsed.shift() + const bibtexEntry = cur.entryType.toLowerCase() + if (bibtexEntry !== 'preamble' && bibtexEntry !== 'comment') { + newWorks.push(that.populateWork(cur)) } - if (newWorks.length > 0) { - that._recordWorksService - .worksValidate(newWorks) - .pipe(first()) - .subscribe((data) => { - that.worksFromBibtex = [] - data.forEach((work) => { - that.worksFromBibtex.push(work) - if (work.errors.length > 0 && !that.isAnInvalidWork) { - that.isAnInvalidWork = true - that._snackBar.showValidationError() - } - }) - that.worksFromBibtex.forEach((w) => { - const newPutCode = 'new-' + that.addedWorkCount++ - w.putCode = { - value: newPutCode, - } - that.group[newPutCode] = new UntypedFormGroup({ - checked: new UntypedFormControl(false), - }) + } + if (newWorks.length > 0) { + that._recordWorksService + .worksValidate(newWorks) + .pipe(first()) + .subscribe((data) => { + that.worksFromBibtex = [] + data.forEach((work) => { + that.worksFromBibtex.push(work) + if (work.errors.length > 0 && !that.isAnInvalidWork) { + that.isAnInvalidWork = true + that._snackBar.showValidationError() + } + }) + that.worksFromBibtex.forEach((w) => { + const newPutCode = 'new-' + that.addedWorkCount++ + w.putCode = { + value: newPutCode, + } + that.group[newPutCode] = new UntypedFormGroup({ + checked: new UntypedFormControl(false), }) - that.importForm = new UntypedFormGroup(that.group) - that.loadingWorks = false }) - } + that.importForm = new UntypedFormGroup(that.group) + that.loadingWorks = false + }) } } - } catch (e) { - that.bibtexErrorParsingText = e - that.bibtexErrorParsing = true - that.loadingWorks = false } + } catch (e) { + that.bibtexErrorParsingText = e + that.bibtexErrorParsing = true + that.loadingWorks = false } } + } } - populateWork( - bibJSON - ): Work { + populateWork(bibJSON): Work { const work = {} as Work const bibtex = bibtexParse.toBibtex([bibJSON]) @@ -261,7 +252,7 @@ export class WorkBibtexModalComponent implements OnInit, OnDestroy { value: lowerKeyTags['url'], } } - + work.contributorsGroupedByOrcid = [] if (lowerKeyTags.hasOwnProperty('author')) { const authors = this.removeEndingAnd(lowerKeyTags['author']) @@ -271,7 +262,6 @@ export class WorkBibtexModalComponent implements OnInit, OnDestroy { const editors = this.removeEndingAnd(lowerKeyTags['editor']) this.addContributors(editors.split(' and '), 'editor', work) } - } return work }