[CST-4875] Fix related page using the complete url

This commit is contained in:
Giuseppe Digilio
2022-01-26 16:40:39 +01:00
parent ed6cb04de4
commit d156e01517
6 changed files with 31 additions and 11 deletions

View File

@@ -32,6 +32,12 @@ export function getBitstreamRequestACopyRoute(item, bitstream): { routerLink: st
};
}
export const HOME_PAGE_PATH = 'admin';
export function getHomePageRoute() {
return `/${HOME_PAGE_PATH}`;
}
export const ADMIN_MODULE_PATH = 'admin';
export function getAdminModuleRoute() {

View File

@@ -8,7 +8,7 @@
<div class="control-group col-sm-12">
<label class="control-label" for="email">{{ 'info.feedback.email-label' | translate }}&nbsp;</label>
<input id="email" class="form-control" name="email" type="text" value="" formControlName="email" autofocus="autofocus" title="{{ 'info.feedback.email_help' | translate }}">
<p class="help-block">{{ 'info.feedback.email_help' | translate }}</p>
<small class="text-muted">{{ 'info.feedback.email_help' | translate }}</small>
</div>
</div>
@@ -27,12 +27,11 @@
class="alert">
<ds-error *ngIf="feedbackForm.controls.message.errors?.required" message="{{'info.feedback.error.message.required' | translate}}"></ds-error>
</ng-container>
<!-- <input class="form-control" readonly formControlName="page" name="page" type="text" [value]="routeService.getPreviousUrl() | async"/> -->
<div class="row">
<div class="control-group col-sm-12">
<label class="control-label" for="page">{{ 'info.feedback.page-label' | translate }}&nbsp;</label>
<input id="page" readonly class="form-control" name="page" type="text" value="" formControlName="page" autofocus="autofocus" title="{{ 'info.feedback.page_help' | translate }}">
<p class="help-block">{{ 'info.feedback.page_help' | translate }}</p>
<small class="text-muted">{{ 'info.feedback.page_help' | translate }}</small>
</div>
</div>
<div class="row py-2">
@@ -43,4 +42,4 @@
</fieldset>
</form>
</div>
</div>
</div>

View File

@@ -16,6 +16,8 @@ import { of } from 'rxjs';
import { Feedback } from '../../../core/feedback/models/feedback.model';
import { Router } from '@angular/router';
import { RouterMock } from '../../../shared/mocks/router.mock';
import { NativeWindowService } from '../../../core/services/window.service';
import { NativeWindowMockFactory } from '../../../shared/mocks/mock-native-window-ref';
describe('FeedbackFormComponent', () => {
@@ -43,6 +45,7 @@ describe('FeedbackFormComponent', () => {
{ provide: NotificationsService, useValue: notificationService },
{ provide: FeedbackDataService, useValue: feedbackDataServiceStub },
{ provide: AuthService, useValue: authService },
{ provide: NativeWindowService, useFactory: NativeWindowMockFactory },
{ provide: Router, useValue: routerStub },
],
schemas: [NO_ERRORS_SCHEMA]
@@ -61,7 +64,7 @@ describe('FeedbackFormComponent', () => {
});
it('should have page value', () => {
expect(component.feedbackForm.controls.page.value).toEqual('/home');
expect(component.feedbackForm.controls.page.value).toEqual('http://localhost/home');
});
it('should have email if ePerson', () => {

View File

@@ -1,7 +1,7 @@
import { RemoteData } from '../../../core/data/remote-data';
import { NoContent } from '../../../core/shared/NoContent.model';
import { FeedbackDataService } from '../../../core/feedback/feedback-data.service';
import { Component, OnInit } from '@angular/core';
import { Component, Inject, OnInit } from '@angular/core';
import { RouteService } from '../../../core/services/route.service';
import { FormBuilder, Validators } from '@angular/forms';
import { NotificationsService } from '../../../shared/notifications/notifications.service';
@@ -10,6 +10,10 @@ import { AuthService } from '../../../core/auth/auth.service';
import { EPerson } from '../../../core/eperson/models/eperson.model';
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
import { Router } from '@angular/router';
import { getHomePageRoute } from '../../../app-routing-paths';
import { take } from 'rxjs/operators';
import { NativeWindowRef, NativeWindowService } from '../../../core/services/window.service';
import { URLCombiner } from '../../../core/url-combiner/url-combiner';
@Component({
selector: 'ds-feedback-form',
@@ -31,6 +35,7 @@ export class FeedbackFormComponent implements OnInit {
});
constructor(
@Inject(NativeWindowService) protected _window: NativeWindowRef,
public routeService: RouteService,
private fb: FormBuilder,
protected notificationsService: NotificationsService,
@@ -45,17 +50,18 @@ export class FeedbackFormComponent implements OnInit {
*/
ngOnInit() {
this.authService.getAuthenticatedUserFromStore().subscribe((user: EPerson) => {
this.authService.getAuthenticatedUserFromStore().pipe(take(1)).subscribe((user: EPerson) => {
if (!!user) {
this.feedbackForm.patchValue({ email: user.email });
}
});
this.routeService.getPreviousUrl().subscribe((url: string) => {
this.routeService.getPreviousUrl().pipe(take(1)).subscribe((url: string) => {
if (!url) {
url = '/home';
url = getHomePageRoute();
}
this.feedbackForm.patchValue({ page: url });
const relatedUrl = new URLCombiner(this._window.nativeWindow.origin, url).toString();
this.feedbackForm.patchValue({ page: relatedUrl });
});
}

View File

@@ -7,7 +7,8 @@ export const MockWindow = {
get href() {
return this._href;
}
}
},
origin: 'http://localhost'
};
export class NativeWindowRefMock {

View File

@@ -1594,6 +1594,11 @@
"info.feedback.error.message.required" : "A comment is required",
"info.feedback.page-label" : "Page",
"info.feedback.page_help" : "Tha page related to your feedback",
"item.alerts.private": "This item is private",