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

ufal/license-agreement-multiple-records #516

Merged
merged 4 commits into from
Feb 15, 2024
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 @@ -41,14 +41,16 @@ <h2 id="header" class="border-bottom pb-2">{{'clarin.license.agreement.title' |
<td><b>{{'clarin.license.agreement.item.handle' | translate}}</b></td>
<td><input type="text" disabled class="rounded-sm max-width border-gray" [value]="(item$ | async)?.handle"></td>
</tr>
<tr *ngFor="let requiredInfo of requiredInfo$ | async">
<td><b>{{requiredInfo.value}}</b></td>
<td class="input-group">
<input #requiredInfoRef class="rounded-sm max-width border-gray"
[value]="getMetadataValueByKey(requiredInfo.name)"
(blur)="setMetadataValue(requiredInfo.name, requiredInfoRef.value)"/>
</td>
</tr>
<ng-container *ngIf="(currentUser$ | async) == null || (userMetadata$ | async)">
<tr *ngFor="let requiredInfo of requiredInfo$ | async">
<td><b>{{requiredInfo.value}}</b></td>
<td class="input-group">
<input #requiredInfoRef class="rounded-sm max-width border-gray"
[value]="getMetadataValueByKey(requiredInfo.name)"
(blur)="setMetadataValue(requiredInfo.name, requiredInfoRef.value)"/>
</td>
</tr>
</ng-container>
<tr>
<td><b>{{'clarin.license.agreement.bitstream.name' | translate}}</b></td>
<td><input type="text" disabled class="rounded-sm max-width border-gray" [value]="(bitstream$ | async)?.name"></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ import { Router } from '@angular/router';
import { getItemPageRoute } from '../../item-page/item-page-routing-paths';
import { getBitstreamDownloadRoute } from '../../app-routing-paths';
import { hasFailed } from 'src/app/core/data/request-entry-state.model';
import {FindListOptions} from '../../core/data/find-list-options.model';
import { FindListOptions } from '../../core/data/find-list-options.model';
import isEqual from 'lodash/isEqual';
import cloneDeep from 'lodash/cloneDeep';
import { ClarinUserMetadataDataService } from '../../core/data/clarin/clarin-user-metadata.service';

/**
* The component shows the user's filled in user metadata and the user can fill in other required user metadata.
Expand Down Expand Up @@ -119,7 +120,8 @@ export class ClarinLicenseAgreementPageComponent implements OnInit {
protected halService: HALEndpointService,
protected rdbService: RemoteDataBuildService,
private hardRedirectService: HardRedirectService,
private requestService: RequestService) { }
private requestService: RequestService,
private clarinUserMetadataDataService: ClarinUserMetadataDataService) { }

ngOnInit(): void {
// Load CurrentItem by bitstreamID to show itemHandle
Expand Down Expand Up @@ -282,7 +284,7 @@ export class ClarinLicenseAgreementPageComponent implements OnInit {
this.clarinLicense$.next(clarinLicense?.payload);
// Load required info from ClarinLicense
// @ts-ignore
this.requiredInfo$.next(clarinLicense?.payload?.requiredInfo);
this.requiredInfo$.next(clarinLicense?.payload?.requiredInfo);
});
});
}
Expand Down Expand Up @@ -314,16 +316,22 @@ export class ClarinLicenseAgreementPageComponent implements OnInit {
}
this.userRegistration$.next(userRegistration);

// Load userMetadata from userRegistration
userRegistration.userMetadata
// Load user metadata for the current user only from the last transaction
const params = [
new RequestParam('userRegUUID', userRegistration.id),
new RequestParam('bitstreamUUID', this.getBitstreamUUID())];
const paramOptions = Object.assign(new FindListOptions(), {
searchParams: [...params]
});
this.clarinUserMetadataDataService.searchBy('byUserRegistrationAndBitstream', paramOptions, false)
.pipe(
getFirstCompletedRemoteData())
.subscribe(userMetadata$ => {
if (hasFailed(userMetadata$.state)) {
.subscribe(userMetadata => {
if (hasFailed(userMetadata.state)) {
this.error$.value.push('Cannot load userMetadata');
return;
}
this.userMetadata$.next(userMetadata$.payload);
this.userMetadata$.next(userMetadata.payload);
});
});
}
Expand Down
12 changes: 12 additions & 0 deletions src/app/core/data/clarin/clarin-user-metadata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import { ClarinUserMetadata } from '../../shared/clarin/clarin-user-metadata.mod
import { dataService } from '../base/data-service.decorator';
import { CoreState } from '../../core-state.model';
import { BaseDataService } from '../base/base-data.service';
import { FindListOptions } from '../find-list-options.model';
import { FollowLinkConfig } from '../../../shared/utils/follow-link-config.model';
import { Observable } from 'rxjs';
import { RemoteData } from '../remote-data';
import { PaginatedList } from '../paginated-list.model';
import { SearchData, SearchDataImpl } from '../base/search-data';

export const linkName = 'clarinusermetadatas';
export const AUTOCOMPLETE = new ResourceType(linkName);
Expand All @@ -23,6 +29,7 @@ export const AUTOCOMPLETE = new ResourceType(linkName);
@dataService(ClarinUserMetadata.type)
export class ClarinUserMetadataDataService extends BaseDataService<ClarinUserMetadata> {
protected linkPath = linkName;
private searchData: SearchData<ClarinUserMetadata>;

constructor(
protected requestService: RequestService,
Expand All @@ -35,5 +42,10 @@ export class ClarinUserMetadataDataService extends BaseDataService<ClarinUserMet
protected notificationsService: NotificationsService
) {
super(linkName, requestService, rdbService, objectCache, halService, undefined);
this.searchData = new SearchDataImpl(this.linkPath, requestService, rdbService, objectCache, halService, this.responseMsToLive);
}

searchBy(searchMethod: string, options?: FindListOptions, useCachedVersionIfAvailable?: boolean, reRequestOnStale?: boolean, ...linksToFollow: FollowLinkConfig<ClarinUserMetadata>[]): Observable<RemoteData<PaginatedList<ClarinUserMetadata>>> {
return this.searchData.searchBy(searchMethod, options, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow);
}
}
3 changes: 3 additions & 0 deletions src/app/core/shared/clarin/clarin-user-registration.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export class ClarinUserRegistration extends ListableObject implements HALResourc
@autoserialize
type: ResourceType;

@autoserialize
id: number;

@autoserialize
ePersonID: string;

Expand Down
Loading