Skip to content

Commit

Permalink
fix/batch-of-fixes-2-feb
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonardo Mendoza Fernadez authored and Leonardo Mendoza Fernadez committed Feb 3, 2024
1 parent b7dd89c commit ab372f8
Show file tree
Hide file tree
Showing 31 changed files with 235 additions and 40 deletions.
7 changes: 7 additions & 0 deletions src/app/core/register2/register2.form-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export function Register2FormAdapterMixin<T extends Constructor<any>>(base: T) {
}

formGroupToAffiliationRegisterForm(formGroup: UntypedFormGroup) {
console.log('formGroupToAffiliationRegisterForm', formGroup)
const value = formGroup.controls['organization'].value
const departmentName = formGroup.controls['departmentName'].value
const roleTitle = formGroup.controls['roleTitle'].value
Expand All @@ -127,6 +128,9 @@ export function Register2FormAdapterMixin<T extends Constructor<any>>(base: T) {
} else {
return {
affiliationName: { value: value.value },
disambiguatedAffiliationSourceId: {
value: value.disambiguatedAffiliationIdentifier,
},
orgDisambiguatedId: {
value: value.disambiguatedAffiliationIdentifier,
},
Expand All @@ -137,6 +141,9 @@ export function Register2FormAdapterMixin<T extends Constructor<any>>(base: T) {
month: startDateGroup.startDateMonth,
year: startDateGroup.startDateYear,
},
city: { value: value.city },
region: { value: value.region },
country: { value: value.country },
}
}
}
Expand Down
49 changes: 49 additions & 0 deletions src/app/core/register2/sample-working.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"visibility": {
"visibility": "LIMITED"
},
"putCode": {},
"city": {
"value": "Somoskőújfalu"
},
"region": {
"value": null
},
"country": {
"value": "HU"
},
"roleTitle": {
"value": ""
},
"departmentName": {
"value": ""
},
"affiliationType": {
"value": "employment"
},
"startDate": {
"day": "",
"month": "",
"year": ""
},
"endDate": {
"day": "",
"month": "",
"year": ""
},
"url": {
"value": ""
},
"disambiguationSource": {
"value": "ROR"
},
"disambiguatedAffiliationSourceId": {
"value": "https://ror.org/01tbzkx87"
},
"orgDisambiguatedId": {
"value": "ROR"
},
"affiliationName": {
"value": "Crime Prevention Center"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,42 @@ <h3 i18n="@@register.currentEmployment" class="orc-font-body margin-top-12">
Current employment
</h3>

<!-- <div class="announce" *ngIf="affiliationFound">
<div class="announce">
<div>
<img src="/assets/vectors/personal-email-icon.svg" aria-hidden="true" />
<img
src="/assets/vectors/registration-affiliation-icon.svg"
aria-hidden="true"
/>
</div>
<div class="content">
<div>
<h3 class="orc-font-body" i18n="@@register.thisLooksLikeAPersonalEmail">
<h3 class="orc-font-body" i18n="@@register.affiliationFoud">
Affiliation found
</h3>
</div>
<div>
<ng-container>
Based on your emails we think you are currently affiliated with
</ng-container>
<strong>The University of Bath.</strong>
<ng-container
>We’ve pre-selected this organization for you in the form
below.</ng-container
>
<p class="main-paragraph">
<ng-container i18n="@@register.basedOnYourEmailWeThink">
Based on your emails we think you are currently affiliated with
</ng-container>
<strong>{{ autoCompleteDisplayOrganization(organization) }}.</strong>

<div>
<ng-container
i18n="
@@register.webePreselectedThisOrganizationForYouInTheFormBelow"
>
We’ve pre-selected this organization for you in the form
below.</ng-container
>
</p>

<div i18n="@@register.whenYouCompleteRegistrationAnEmployment">
When you complete registration an employment affiliation will be
automatically added to your new ORCID record.
</div>
</div>
</div>
</div> -->
</div>

<section id="{{ type }}-organization">
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
import { EMPTY, Observable, of } from 'rxjs'
import { RecordAffiliationService } from 'src/app/core/record-affiliations/record-affiliations.service'
import { dateMonthYearValidator } from 'src/app/shared/validators/date/date.validator'
import { RegisterStateService } from '../../register-state.service'
import { OrgDisambiguated } from 'src/app/types'
export class MyErrorStateMatcher implements ErrorStateMatcher {
isErrorState(
control: FormControl | null,
Expand Down Expand Up @@ -74,6 +76,7 @@ export class FormCurrentEmploymentComponent extends BaseForm implements OnInit {
requireOrganizationDisambiguatedDataOnRefresh = false
private _type: AffiliationType
affiliationFound = false
rorIdHasBeenMatched: boolean

@Input()
public get type(): AffiliationType {
Expand Down Expand Up @@ -104,15 +107,17 @@ export class FormCurrentEmploymentComponent extends BaseForm implements OnInit {
.fill(0)
.map((i, idx) => idx + 1)

organization: string | Organization = ''
organization: string | Organization | OrgDisambiguated = ''
platform: PlatformInfo
isMobile: boolean
rorId: string = 'https://ror.org/036mest28'
constructor(
private _register: Register2Service,
private _platform: PlatformInfoService,
private _liveAnnouncer: LiveAnnouncer,
private _recordAffiliationService: RecordAffiliationService,
private _formBuilder: FormBuilder
private _formBuilder: FormBuilder,
private registerStateService: RegisterStateService
) {
super()
this._platform.get().subscribe((platform) => {
Expand All @@ -122,6 +127,19 @@ export class FormCurrentEmploymentComponent extends BaseForm implements OnInit {
}

ngOnInit() {
this.registerStateService.matchOrganization$.subscribe((organization) => {
this.organization = organization
this.form.patchValue({
organization: organization,
})
this.rorIdHasBeenMatched = !!organization

if (this.rorIdHasBeenMatched) {
this.form.controls.organization.markAsTouched()
} else {
this.form.controls.organization.markAsUntouched()
}
})
this.form = new UntypedFormGroup({
organization: new UntypedFormControl(this.organization, {
validators: [
Expand Down Expand Up @@ -212,8 +230,12 @@ export class FormCurrentEmploymentComponent extends BaseForm implements OnInit {
)
}

autoCompleteDisplayOrganization(organization: Organization) {
return organization.value
autoCompleteDisplayOrganization(
organization: Organization | string | OrgDisambiguated
) {
if (typeof organization === 'object') {
return organization.value
}
}

private _filter(value: string): Observable<Organization[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ <h3 i18n="@@register.yourNames" class="orc-font-body margin-top-12">
[placeholder]="labelFamilyNamePlaceholder"
/>
</mat-form-field>
<mat-error
*ngIf="form.hasError('maxlength', 'familyNames')"
i18n="@@topBar.keywordMaxLength"
>
Must be less than 100 characters
</mat-error>
<mat-error
*ngIf="
familyNamesFormTouched && form.hasError('illegalName', 'familyNames')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { SnackbarService } from 'src/app/cdk/snackbar/snackbar.service'
import { SignInService } from 'src/app/core/sign-in/sign-in.service'
import { ErrorHandlerService } from 'src/app/core/error-handler/error-handler.service'
import { ERROR_REPORT } from 'src/app/errors'
import { RegisterStateService } from '../../register-state.service'
export class MyErrorStateMatcher implements ErrorStateMatcher {
isErrorState(
control: FormControl | null,
Expand Down Expand Up @@ -111,6 +112,7 @@ export class FormPersonalComponent extends BaseForm implements OnInit {
private _snackbar: SnackbarService,
private _signIn: SignInService,
private _errorHandler: ErrorHandlerService,
private _registerStateService: RegisterStateService,
@Inject(WINDOW) private window: Window
) {
super()
Expand Down Expand Up @@ -146,6 +148,19 @@ export class FormPersonalComponent extends BaseForm implements OnInit {
}
)

this.additionalEmails.controls[0].valueChanges
.pipe(
debounceTime(1000),
filter(() => !this.additionalEmails.controls[0].errors),
switchMap((value) => {
const emailDomain = value.split('@')[1]
return this._register.getEmailCategory(emailDomain)
})
)
.subscribe((value) => {
this._registerStateService.setRorAffiliationFound(value.rorId, true)
})

this.emails.controls['email'].valueChanges
.pipe(
debounceTime(1000),
Expand All @@ -159,6 +174,7 @@ export class FormPersonalComponent extends BaseForm implements OnInit {
this.professionalEmail = value.category === 'PROFESSIONAL'
this.personalEmail = value.category === 'PERSONAL'
this.undefinedEmail = value.category === 'UNDEFINED'
this._registerStateService.setRorAffiliationFound(value.rorId)
})

if (!this.reactivation?.isReactivation) {
Expand All @@ -180,7 +196,10 @@ export class FormPersonalComponent extends BaseForm implements OnInit {
asyncValidators: this._register.backendValueValidate('givenNames'),
}),
familyNames: new UntypedFormControl('', {
validators: [OrcidValidators.illegalName],
validators: [
OrcidValidators.illegalName,
Validators.maxLength(this.maxNameLenght),
],
}),
emails: this.emails,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ <h3 class="orc-font-body" i18n="@@register.termsOfUse">Terms of Use</h3>
(form.hasError('required', 'termsOfUse') ||
form.hasError('required', 'dataProcessed'))
"
i18n="@@register.youMustAccept"
>You must accept the terms we use and consent to your data being processed in
i18n="@@register.youMustAccept2"
>You must accept the terms of use and consent to your data being processed in
the United States</mat-error
>

Expand Down
6 changes: 6 additions & 0 deletions src/app/register2/components/register2.style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ mat-label.orc-font-small-print {
a {
font-style: italic;
}
button {
height: 40px;
}
}
.columns-12 {
:host ::ng-deep {
Expand Down Expand Up @@ -150,6 +153,9 @@ mat-label.orc-font-small-print {

.info,
.announce {
.main-paragraph{
margin-bottom: 16px;
}
.content div:not(:last-child) {
margin-bottom: 16px;
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/register2/pages/register/register2.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
(selectionChange)="selectionChange($event)"
role="tablist"
>
<mat-step [stepControl]="FormGroupStepA">
<!-- <mat-step [stepControl]="FormGroupStepA">
<ng-template matStepLabel i18n="@@register.personalData"
>Personal data</ng-template
>
Expand All @@ -30,7 +30,7 @@
[personalData]="personalData"
[reactivation]="reactivation"
></app-step-b>
</mat-step>
</mat-step> -->
<mat-step
[stepControl]="FormGroupStepC2"
[optional]="formGroupStepC2Optional"
Expand Down
16 changes: 16 additions & 0 deletions src/app/register2/register-state.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { RegisterStateService } from './register-state.service';

describe('RegisterStateService', () => {
let service: RegisterStateService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(RegisterStateService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
Loading

0 comments on commit ab372f8

Please sign in to comment.