Skip to content

Commit

Permalink
Remove togglz that have to do with contributors (#2120)
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro authored Dec 14, 2023
1 parent 8bff47d commit 9a1f8a8
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ <h3 class="orc-font-body">
</div>
<ng-container
*ngIf="
togglzAddOtherContributors &&
contributors?.length > maxNumberOfContributors + 1
"
>
Expand Down Expand Up @@ -102,7 +101,6 @@ <h3 class="orc-font-body">
</ng-container>
<ng-container
*ngIf="
!togglzAddOtherContributors ||
!(contributors?.length > maxNumberOfContributors + 1)
"
>
Expand Down Expand Up @@ -384,7 +382,6 @@ <h3 class="orc-font-body">
<div
class="row"
*ngIf="
!togglzAddOtherContributors ||
!(contributors?.length > maxNumberOfContributors + 1)
"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ describe('WorkContributorsComponent', () => {
const mockFormGroup: UntypedFormGroup = new UntypedFormGroup({})
component['parentForm'].form = mockFormGroup
component.userRecord = getUserRecord()
component.togglzAddOtherContributors = true


fixture.detectChanges()
loader = TestbedHarnessEnvironment.loader(fixture)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ export class WorkContributorsComponent implements OnInit, OnDestroy {
maxNumberOfContributors = 49
maxNumberOfContributorsSummary = 10
privateName = 'Name is private'
togglzAddOtherContributors: boolean


contributionRoles = ContributionRoles
recordHolderContribution: Contributor

Expand All @@ -89,9 +88,7 @@ export class WorkContributorsComponent implements OnInit, OnDestroy {
private workService: RecordWorksService,
private affiliationService: RecordAffiliationService
) {
_togglz
.getStateOf('ADD_OTHER_WORK_CONTRIBUTORS')
.subscribe((value) => (this.togglzAddOtherContributors = value))

}

get contributorsFormArray() {
Expand Down Expand Up @@ -220,7 +217,7 @@ export class WorkContributorsComponent implements OnInit, OnDestroy {
'contributors'
) as UntypedFormArray

if (this.togglzAddOtherContributors && this.contributors?.length > 0) {
if (this.contributors?.length > 0) {
if (!this.recordHolderContribution && !this.recordHolderAsContributor) {
this.addRecordHolderAsContributor()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,94 +49,85 @@ export class WorkBibtexModalComponent implements OnInit, OnDestroy {
ngOnInit(): void {}

bibTexInputChange($fileInputEvent: any) {
this._togglz
.getStateOf('ADD_OTHER_WORK_CONTRIBUTORS_WITH_BIBTEX')
.subscribe((ADD_OTHER_WORK_CONTRIBUTORS_WITH_BIBTEX_TOGGLZ) => {
this.bibtexErrorParsingText = undefined
this.bibtexErrorParsing = false
this.loadingWorks = true
const textFiles = $fileInputEvent.target.files
for (const bibtex of textFiles) {
const reader = new FileReader()
reader.readAsText(bibtex)

const that = this

reader.onloadend = function (e) {
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,
ADD_OTHER_WORK_CONTRIBUTORS_WITH_BIBTEX_TOGGLZ
)
this.bibtexErrorParsingText = undefined
this.bibtexErrorParsing = false
this.loadingWorks = true
const textFiles = $fileInputEvent.target.files
for (const bibtex of textFiles) {
const reader = new FileReader()
reader.readAsText(bibtex)
const that = this
reader.onloadend = function (e) {
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 (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,
ADD_OTHER_WORK_CONTRIBUTORS_WITH_BIBTEX_TOGGLZ: boolean
bibJSON
): Work {
const work = {} as Work
const bibtex = bibtexParse.toBibtex([bibJSON])
Expand Down Expand Up @@ -270,18 +261,17 @@ export class WorkBibtexModalComponent implements OnInit, OnDestroy {
value: lowerKeyTags['url'],
}
}

if (ADD_OTHER_WORK_CONTRIBUTORS_WITH_BIBTEX_TOGGLZ) {
work.contributorsGroupedByOrcid = []
if (lowerKeyTags.hasOwnProperty('author')) {
const authors = this.removeEndingAnd(lowerKeyTags['author'])
this.addContributors(authors.split(' and '), 'author', work)
}
if (lowerKeyTags.hasOwnProperty('editor')) {
const editors = this.removeEndingAnd(lowerKeyTags['editor'])
this.addContributors(editors.split(' and '), 'editor', work)
}

work.contributorsGroupedByOrcid = []
if (lowerKeyTags.hasOwnProperty('author')) {
const authors = this.removeEndingAnd(lowerKeyTags['author'])
this.addContributors(authors.split(' and '), 'author', work)
}
if (lowerKeyTags.hasOwnProperty('editor')) {
const editors = this.removeEndingAnd(lowerKeyTags['editor'])
this.addContributors(editors.split(' and '), 'editor', work)
}

}
return work
}
Expand Down

0 comments on commit 9a1f8a8

Please sign in to comment.