Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove togglz that have to do with contributors #2120

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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