diff --git a/src/app/shared/object-list/listable-notification-object/listable-notification-object.component.html b/src/app/shared/object-list/listable-notification-object/listable-notification-object.component.html new file mode 100644 index 0000000000..ba850622ed --- /dev/null +++ b/src/app/shared/object-list/listable-notification-object/listable-notification-object.component.html @@ -0,0 +1 @@ +

{{ object?.message | translate }}

diff --git a/src/app/shared/object-list/listable-notification-object/listable-notification-object.component.scss b/src/app/shared/object-list/listable-notification-object/listable-notification-object.component.scss new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/app/shared/object-list/listable-notification-object/listable-notification-object.component.spec.ts b/src/app/shared/object-list/listable-notification-object/listable-notification-object.component.spec.ts new file mode 100644 index 0000000000..3cf05f7fec --- /dev/null +++ b/src/app/shared/object-list/listable-notification-object/listable-notification-object.component.spec.ts @@ -0,0 +1,43 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ListableNotificationObjectComponent } from './listable-notification-object.component'; +import { NotificationType } from '../../notifications/models/notification-type'; +import { ListableNotificationObject } from './listable-notification-object.model'; +import { By } from '@angular/platform-browser'; +import { TranslateModule } from '@ngx-translate/core'; + +describe('ListableNotificationObjectComponent', () => { + let component: ListableNotificationObjectComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ + TranslateModule.forRoot(), + ], + declarations: [ + ListableNotificationObjectComponent, + ], + }).compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(ListableNotificationObjectComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + describe('ui', () => { + it('should display the given error message', () => { + component.object = new ListableNotificationObject(NotificationType.Error, 'test error message'); + fixture.detectChanges(); + + const listableNotificationObject: Element = fixture.debugElement.query(By.css('.alert')).nativeElement; + expect(listableNotificationObject.className).toContain(NotificationType.Error); + expect(listableNotificationObject.innerHTML).toBe('test error message'); + }); + }); + + afterEach(() => { + fixture.debugElement.nativeElement.remove(); + }); +}); diff --git a/src/app/shared/object-list/listable-notification-object/listable-notification-object.component.ts b/src/app/shared/object-list/listable-notification-object/listable-notification-object.component.ts new file mode 100644 index 0000000000..ca23ee76a2 --- /dev/null +++ b/src/app/shared/object-list/listable-notification-object/listable-notification-object.component.ts @@ -0,0 +1,21 @@ +import { Component } from '@angular/core'; +import { + AbstractListableElementComponent +} from '../../object-collection/shared/object-collection-element/abstract-listable-element.component'; +import { ListableNotificationObject } from './listable-notification-object.model'; +import { listableObjectComponent } from '../../object-collection/shared/listable-object/listable-object.decorator'; +import { ViewMode } from '../../../core/shared/view-mode.model'; +import { LISTABLE_NOTIFICATION_OBJECT } from './listable-notification-object.resource-type'; + +/** + * The component for displaying a notifications inside an object list + */ +@listableObjectComponent(ListableNotificationObject, ViewMode.ListElement) +@listableObjectComponent(LISTABLE_NOTIFICATION_OBJECT.value, ViewMode.ListElement) +@Component({ + selector: 'ds-listable-notification-object', + templateUrl: './listable-notification-object.component.html', + styleUrls: ['./listable-notification-object.component.scss'], +}) +export class ListableNotificationObjectComponent extends AbstractListableElementComponent { +} diff --git a/src/app/shared/object-list/listable-notification-object/listable-notification-object.model.ts b/src/app/shared/object-list/listable-notification-object/listable-notification-object.model.ts new file mode 100644 index 0000000000..7e25030498 --- /dev/null +++ b/src/app/shared/object-list/listable-notification-object/listable-notification-object.model.ts @@ -0,0 +1,36 @@ +import { ListableObject } from '../../object-collection/shared/listable-object.model'; +import { typedObject } from '../../../core/cache/builders/build-decorators'; +import { TypedObject } from '../../../core/cache/object-cache.reducer'; +import { LISTABLE_NOTIFICATION_OBJECT } from './listable-notification-object.resource-type'; +import { GenericConstructor } from '../../../core/shared/generic-constructor'; +import { NotificationType } from '../../notifications/models/notification-type'; +import { ResourceType } from '../../../core/shared/resource-type'; + +/** + * Object representing a notification message inside a list of objects + */ +@typedObject +export class ListableNotificationObject extends ListableObject implements TypedObject { + + static type: ResourceType = LISTABLE_NOTIFICATION_OBJECT; + type: ResourceType = LISTABLE_NOTIFICATION_OBJECT; + + protected renderTypes: string[]; + + constructor( + public notificationType: NotificationType = NotificationType.Error, + public message: string = 'listable-notification-object.default-message', + ...renderTypes: string[] + ) { + super(); + this.renderTypes = renderTypes; + } + + /** + * Method that returns as which type of object this object should be rendered. + */ + getRenderTypes(): (string | GenericConstructor)[] { + return [...this.renderTypes, this.constructor as GenericConstructor]; + } + +} diff --git a/src/app/shared/object-list/listable-notification-object/listable-notification-object.resource-type.ts b/src/app/shared/object-list/listable-notification-object/listable-notification-object.resource-type.ts new file mode 100644 index 0000000000..ed458126bb --- /dev/null +++ b/src/app/shared/object-list/listable-notification-object/listable-notification-object.resource-type.ts @@ -0,0 +1,9 @@ +import { ResourceType } from '../../../core/shared/resource-type'; + +/** + * The resource type for {@link ListableNotificationObject} + * + * Needs to be in a separate file to prevent circular + * dependencies in webpack. + */ +export const LISTABLE_NOTIFICATION_OBJECT = new ResourceType('listable-notification-object'); diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts index 715ee66a99..35aa880052 100644 --- a/src/app/shared/shared.module.ts +++ b/src/app/shared/shared.module.ts @@ -177,6 +177,9 @@ import { ScopeSelectorModalComponent } from './search-form/scope-selector-modal/ import { BitstreamRequestACopyPageComponent } from './bitstream-request-a-copy-page/bitstream-request-a-copy-page.component'; import { DsSelectComponent } from './ds-select/ds-select.component'; import { LogInOidcComponent } from './log-in/methods/oidc/log-in-oidc.component'; +import { + ListableNotificationObjectComponent +} from './object-list/listable-notification-object/listable-notification-object.component'; const MODULES = [ // Do NOT include UniversalModule, HttpModule, or JsonpModule here @@ -346,6 +349,7 @@ const COMPONENTS = [ CommunitySidebarSearchListElementComponent, SearchNavbarComponent, ScopeSelectorModalComponent, + ListableNotificationObjectComponent, ]; const ENTRY_COMPONENTS = [ @@ -402,6 +406,7 @@ const ENTRY_COMPONENTS = [ OnClickMenuItemComponent, TextMenuItemComponent, ScopeSelectorModalComponent, + ListableNotificationObjectComponent, ]; const SHARED_ITEM_PAGE_COMPONENTS = [ diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index f742273edb..dce6f9d3b7 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -4162,5 +4162,8 @@ "idle-modal.log-out": "Log out", - "idle-modal.extend-session": "Extend session" + "idle-modal.extend-session": "Extend session", + + + "listable-notification-object.default-message": "This object couldn't be retrieved", }