Commit 625cadbc authored by Alicia.DeDiosFuente's avatar Alicia.DeDiosFuente Committed by Homada.Boumedane
Browse files

feat: move avatar from user to person

parent ac5873d4
......@@ -6,6 +6,7 @@
<dlcm-shared-avatar-upload-wrapper-container [user]="getUser()"
[resourceLogoNameSpace]="userAvatarActionNameSpace"
[resourceLogoState]="userState"
[resId]="getPersonResId()"
></dlcm-shared-avatar-upload-wrapper-container>
<div class="wrapper"
[dlcmSpinner]="isLoadingPersonObs | async"
......
......@@ -66,4 +66,8 @@ export class UserDialog extends SharedAbstractContainer implements OnInit {
}
return this.formPresentational.form.value as User;
}
getPersonResId(): string {
return this.user.person.resId;
}
}
......@@ -4,6 +4,7 @@
>
<dlcm-shared-image-upload-wrapper-container [resourceLogoNameSpace]="organizationalUnitActionNameSpace"
[resourceLogoState]="organizationalUnitState"
[resId]="model?.resId"
></dlcm-shared-image-upload-wrapper-container>
<div class="two-columns-wrapper">
......
......@@ -141,6 +141,10 @@ export class AdminOrganizationalUnitState extends ResourceLogoState<AdminOrganiz
return AdminResourceApiEnum.organizationalUnits;
}
protected get _urlLogoResource(): string {
return this._urlResource;
}
@Selector()
static isLoading(state: AdminOrganizationalUnitStateModel): boolean {
return StoreUtil.isLoadingState(state);
......@@ -345,7 +349,7 @@ export class AdminOrganizationalUnitState extends ResourceLogoState<AdminOrganiz
getByIdSuccess(ctx: StateContext<AdminOrganizationalUnitStateModel>, action: AdminOrganizationalUnitAction.GetByIdSuccess): void {
super.getByIdSuccess(ctx, action);
if (isNotNullNorUndefined(action.model.logo)) {
ctx.dispatch(new AdminOrganizationalUnitAction.GetPhoto());
ctx.dispatch(new AdminOrganizationalUnitAction.GetPhoto(action.model.resId));
}
}
}
......@@ -7,6 +7,7 @@
[resourceLogoNameSpace]="userAvatarActionNameSpace"
[resourceLogoState]="userState"
class="avatar"
[resId]="getPersonResId()"
></dlcm-shared-avatar-upload-wrapper-container>
<div class="two-columns-wrapper">
......
......@@ -116,6 +116,10 @@ export class AdminUserFormPresentational extends SharedAbstractFormPresentationa
}
return this.form.value as User;
}
getPersonResId(): string {
return this.model.person.resId;
}
}
class FormComponentFormDefinition extends BaseFormDefinition {
......
......@@ -68,6 +68,10 @@ export class AdminUserState extends ResourceLogoState<AdminUserStateModel, User>
return AdminResourceApiEnum.users;
}
protected get _urlLogoResource(): string {
return AdminResourceApiEnum.people;
}
@Selector()
static isLoading(state: AdminUserStateModel): boolean {
return StoreUtil.isLoadingState(state);
......@@ -127,7 +131,7 @@ export class AdminUserState extends ResourceLogoState<AdminUserStateModel, User>
getByIdSuccess(ctx: StateContext<AdminUserStateModel>, action: AdminUserAction.GetByIdSuccess): void {
super.getByIdSuccess(ctx, action);
if (isNotNullNorUndefined(action.model.avatar)) {
ctx.dispatch(new AdminUserAction.GetPhoto());
ctx.dispatch(new AdminUserAction.GetPhoto(action.model.person.resId));
}
}
}
......@@ -8,6 +8,7 @@
<dlcm-shared-image-upload-wrapper-container [resourceLogoNameSpace]="depositActionNameSpace"
[resourceLogoState]="depositState"
[resId]="model?.resId"
[preFallbackImage]="orgUnitLogo"
[isEditable]="editAvailable && (model | isNotNullNorUndefined) && model.metadataVersion !==
metadataVersionEnum._10 && model.metadataVersion !==
......
......@@ -231,6 +231,10 @@ export class DepositState extends ResourceLogoState<DepositStateModel, Deposit>
return PreIngestResourceApiEnum.deposits;
}
protected get _urlLogoResource(): string {
return this._urlResource;
}
@Selector()
static isLoading(state: DepositStateModel): boolean {
return StoreUtil.isLoadingState(state);
......@@ -941,7 +945,7 @@ export class DepositState extends ResourceLogoState<DepositStateModel, Deposit>
@Action(DepositAction.UploadPhoto)
uploadPhoto(ctx: StateContext<DepositStateModel>, action: DepositAction.UploadPhoto): Observable<any> {
if (isNotNullNorUndefined(ctx.getState().dataFileLogo)) {
ctx.dispatch(new DepositAction.DeletePhoto());
ctx.dispatch(new DepositAction.DeletePhoto(action.resId, action.file));
return this.actions$.pipe(
ofActionCompleted(DepositAction.DeletePhotoSuccess),
switchMap(result => {
......@@ -1007,7 +1011,7 @@ export class DepositState extends ResourceLogoState<DepositStateModel, Deposit>
dataFileLogo: collection._data[0],
});
ctx.dispatch(new DepositAction.GetPhoto());
ctx.dispatch(new DepositAction.GetPhoto(depositId));
}
}),
catchError(error => {
......
......@@ -68,6 +68,10 @@ export class DepositOrganizationalUnitState extends ResourceLogoState<DepositOrg
return AdminResourceApiEnum.organizationalUnits;
}
protected get _urlLogoResource(): string {
return this._urlResource;
}
@Selector()
static currentTitle(state: DepositOrganizationalUnitStateModel): string | undefined {
if (isNullOrUndefined(state.current)) {
......@@ -83,7 +87,7 @@ export class DepositOrganizationalUnitState extends ResourceLogoState<DepositOrg
current: action.model,
});
if (isNotNullNorUndefined(action.model.logo)) {
ctx.dispatch(new DepositOrganizationalUnitAction.GetPhoto());
ctx.dispatch(new DepositOrganizationalUnitAction.GetPhoto(action.model.resId));
} else {
ctx.patchState({
logo: undefined,
......
......@@ -5,6 +5,7 @@
<dlcm-shared-image-upload-wrapper-container [resourceLogoNameSpace]="organizationalUnitActionNameSpace"
[resourceLogoState]="organizationalUnitState"
[isEditable]="isManager"
[resId]="model?.resId"
[tourAnchor]="tourEnum.preservationSpaceOrgUnitThumbnail"
></dlcm-shared-image-upload-wrapper-container>
......@@ -257,4 +258,4 @@
{{labelTranslateEnum.requestMembership | translate}}
</button>
</ng-template>
\ No newline at end of file
</ng-template>
......@@ -133,6 +133,10 @@ export class PreservationSpaceOrganizationalUnitState extends ResourceLogoState<
return this._securityService.isManagerOfOrgUnit(organizationalUnit?.resId) ? adminResourceApiEnum : accessResourceApiEnum;
}
protected get _urlLogoResource(): string {
return this._urlResource;
}
@Selector()
static currentUserIsManager(state: PreservationSpaceOrganizationalUnitStateModel): boolean | undefined {
return state.currentUserIsManager;
......@@ -224,7 +228,7 @@ export class PreservationSpaceOrganizationalUnitState extends ResourceLogoState<
ctx.dispatch(new PreservationSpaceOrganizationalUnitAction.ComputeCurrentUserIsManager());
if (isNotNullNorUndefined(action.model.logo)) {
ctx.dispatch(new PreservationSpaceOrganizationalUnitAction.GetPhoto());
ctx.dispatch(new PreservationSpaceOrganizationalUnitAction.GetPhoto(action.model.resId));
}
}
......
......@@ -48,6 +48,9 @@ export abstract class SharedAbstractImageUploadWrapperContainer extends SharedAb
isLoadingObs: Observable<boolean>;
photoObs: Observable<string | undefined>;
@Input()
resId: string;
@ViewChild("fileInput", {static: false})
fileInput: ElementRef;
......@@ -86,7 +89,7 @@ export abstract class SharedAbstractImageUploadWrapperContainer extends SharedAb
}),
),
);
this._store.dispatch(new this.resourceLogoNameSpace.DeletePhoto());
this._store.dispatch(new this.resourceLogoNameSpace.DeletePhoto(this.resId));
}
openModal(): void {
......@@ -122,11 +125,11 @@ export abstract class SharedAbstractImageUploadWrapperContainer extends SharedAb
if (isFalse(action.result.successful)) {
return;
}
this._store.dispatch(new this.resourceLogoNameSpace.GetPhoto());
this._store.dispatch(new this.resourceLogoNameSpace.GetPhoto(this.resId));
}),
),
);
this._store.dispatch(new this.resourceLogoNameSpace.UploadPhoto(blob as any));
this._store.dispatch(new this.resourceLogoNameSpace.UploadPhoto(this.resId, blob as any));
this.fileInput.nativeElement.value = null;
}),
));
......
......@@ -77,6 +77,10 @@ export class SharedLogoWrapperContainer<TResource extends BaseResource> extends
ngOnChanges(): void {
if (isNotNullNorUndefined(this._idResource) && isNotNullNorUndefined(this.logoNamespace)) {
//in case of user, the id_resource has to be changed from user to person.resId
if (this.isUser && !isNullOrUndefined(this.user.person)) {
this._idResource = this.user.person.resId;
}
this.listPhotosObs = MemoizedUtil.select(this._store, this.logoState, (state: ResourceLogoStateModel<TResource>) => state.listLogo);
this.getLogo();
}
......
......@@ -7,6 +7,10 @@ import {
export namespace ResourceLogoAction {
export class GetPhoto extends BaseAction {
static readonly type: string = `[{0}] Get Photo`;
constructor(public resId: string) {
super();
}
}
export class GetPhotoSuccess extends BaseSubAction<GetPhoto> {
......@@ -48,7 +52,7 @@ export namespace ResourceLogoAction {
export class UploadPhoto extends BaseAction {
static readonly type: string = `[{0}] Upload Photo`;
constructor(public file: File) {
constructor(public resId: string, public file: File) {
super();
}
}
......@@ -67,6 +71,10 @@ export namespace ResourceLogoAction {
export class DeletePhoto extends BaseAction {
static readonly type: string = `[{0}] Delete Photo`;
constructor(public resId: string, public file: File) {
super();
}
}
export class DeletePhotoSuccess extends BaseSubAction<DeletePhoto> {
......
......@@ -89,6 +89,8 @@ export abstract class ResourceLogoState<TStateModel extends BaseStateModel, TRes
}
}
protected abstract get _urlLogoResource(): string;
@RegisterDefaultAction((userAvatarNameSpace: ResourceLogoNameSpace) => userAvatarNameSpace.GetPhoto, {}, ResourceState)
getPhoto(ctx: StateContext<ResourceLogoStateModel<TResource>>, action: ResourceLogoAction.GetPhoto): Observable<any> {
ctx.patchState({
......@@ -98,7 +100,7 @@ export abstract class ResourceLogoState<TStateModel extends BaseStateModel, TRes
let headers = new HttpHeaders();
headers = headers.set("Content-Disposition", "attachment; filename=" + "photo");
return this._httpClient.get(`${this._urlResource}/${ctx.getState().current.resId}/${this._getDownloadAction()}`, {
return this._httpClient.get(`${this._urlLogoResource}/${action.resId}/${this._getDownloadAction()}`, {
headers,
responseType: "blob",
}).pipe(
......@@ -137,7 +139,7 @@ export abstract class ResourceLogoState<TStateModel extends BaseStateModel, TRes
let headers = new HttpHeaders();
headers = headers.set("Content-Disposition", "attachment; filename=" + "photo");
return this._httpClient.get(`${this._urlResource}/${action.resId}/${this._getDownloadAction()}`, {
return this._httpClient.get(`${this._urlLogoResource}/${action.resId}/${this._getDownloadAction()}`, {
headers,
responseType: "blob",
}).pipe(
......@@ -183,10 +185,11 @@ export abstract class ResourceLogoState<TStateModel extends BaseStateModel, TRes
ctx.patchState({
isLoadingLogo: true,
});
console.error(action.file);
const formData = new FormData();
formData.append(this._FILE_KEY, action.file, action.file.name);
return this.apiService.upload(`${this._urlResource}/${ctx.getState().current.resId}/${this._getUploadAction()}`, formData)
return this.apiService.upload(`${this._urlLogoResource}/${action.resId}/${this._getUploadAction()}`, formData)
.pipe(
map((event: UploadEventModel) => {
switch (event.type) {
......@@ -233,7 +236,7 @@ export abstract class ResourceLogoState<TStateModel extends BaseStateModel, TRes
isLoadingLogo: true,
});
return this.apiService.delete(`${this._urlResource}/${ctx.getState().current.resId}/${this._getDeleteAction()}`)
return this.apiService.delete(`${this._urlLogoResource}/${action.resId}/${this._getDeleteAction()}`)
.pipe(
tap((result: any) => {
ctx.dispatch(ResourceLogoActionHelper.deletePhotoSuccess(this._nameSpace, action));
......
......@@ -67,6 +67,10 @@ export class AppUserState extends ResourceLogoState<AppUserStateModel, User> {
return AdminResourceApiEnum.users;
}
protected get _urlLogoResource(): string {
return AdminResourceApiEnum.people;
}
@Action(AppUserAction.GetCurrentUser)
getCurrentUser(ctx: StateContext<AppUserStateModel>, action: AppUserAction.GetCurrentUser): Observable<CollectionTyped<User>> {
return this.apiService.get<User>(AdminResourceApiEnum.users + urlSeparator + ApiActionEnum.AUTHENTICATED, null)
......@@ -89,8 +93,8 @@ export class AppUserState extends ResourceLogoState<AppUserStateModel, User> {
ctx.dispatch(new AppPersonAction.AddCurrentPerson(action.user.person));
if (isNotNullNorUndefined(action.user.avatar)) {
ctx.dispatch(new AppUserAction.GetPhoto());
if (isNullOrUndefined(action.user.avatar)) {
ctx.dispatch(new AppUserAction.GetPhoto(action.user.person.resId));
}
if (isNullOrUndefined(action.user.lastLoginTime)) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment