Skip to content
Snippets Groups Projects
Commit dd466328 authored by Alexander Reifschneider's avatar Alexander Reifschneider
Browse files

Revert "OZG-5977 hide file container on empty content"

This reverts commit b8499321.
parent 210e793b
No related branches found
No related tags found
1 merge request!85OZG-5977 ui styling
...@@ -23,8 +23,9 @@ ...@@ -23,8 +23,9 @@
unter der Lizenz sind dem Lizenztext zu entnehmen. unter der Lizenz sind dem Lizenztext zu entnehmen.
--> -->
@if (binaryFileList) {
<ods-attachment-wrapper> <ods-attachment-wrapper>
<alfa-binary-file-list [binaryFileList]="binaryFileList" [listOrientation]="listOrientation" /> <alfa-binary-file-list
[binaryFileListStateResource]="binaryFileListStateResource$ | async"
[listOrientation]="listOrientation"
></alfa-binary-file-list>
</ods-attachment-wrapper> </ods-attachment-wrapper>
}
...@@ -42,11 +42,9 @@ describe('BinaryFileListContainerComponent', () => { ...@@ -42,11 +42,9 @@ describe('BinaryFileListContainerComponent', () => {
const binaryFileService: Mock<BinaryFileService> = mock(BinaryFileService); const binaryFileService: Mock<BinaryFileService> = mock(BinaryFileService);
const fileList: Resource[] = []; const binaryFileStateResource: StateResource<BinaryFileResource> = createStateResource(
const binaryFileStateResource: StateResource<BinaryFileResource> = createStateResource({ createBinaryFileResource(),
...createBinaryFileResource(), );
_embedded: { ozgFileList: fileList },
});
const resource: Resource = createDummyResource(); const resource: Resource = createDummyResource();
const linkRel: LinkRelationName = DummyLinkRel.DUMMY; const linkRel: LinkRelationName = DummyLinkRel.DUMMY;
...@@ -83,31 +81,14 @@ describe('BinaryFileListContainerComponent', () => { ...@@ -83,31 +81,14 @@ describe('BinaryFileListContainerComponent', () => {
expect(binaryFileService.getFiles).toHaveBeenCalledWith(resource, linkRel); expect(binaryFileService.getFiles).toHaveBeenCalledWith(resource, linkRel);
}); });
it('should NOT set binaryFileList', () => {
component.binaryFileList = null;
binaryFileService.getFiles.mockReturnValue(of(createStateResource(null)));
component.ngOnInit();
expect(component.binaryFileList).toBe(null);
});
it('should set binaryFileList', () => {
component.ngOnInit();
expect(component.binaryFileList).toBe(fileList);
});
}); });
describe('binary file list', () => { describe('binary file list', () => {
it('should be called with binary file state resource', () => { it('should be called with binary file state resource', () => {
const binaryFileListComponent: BinaryFileListComponent = getMockComponent<BinaryFileListComponent>( const binaryFileListComponent: BinaryFileListComponent =
fixture, getMockComponent<BinaryFileListComponent>(fixture, BinaryFileListComponent);
BinaryFileListComponent,
);
expect(binaryFileListComponent.binaryFileList).toBe(fileList); expect(binaryFileListComponent.binaryFileListStateResource).toBe(binaryFileStateResource);
}); });
}); });
}); });
...@@ -21,38 +21,27 @@ ...@@ -21,38 +21,27 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen * Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
import { BinaryFile, BinaryFileListLinkRel, BinaryFileListResource, BinaryFileService } from '@alfa-client/binary-file-shared'; import { BinaryFileListResource, BinaryFileService } from '@alfa-client/binary-file-shared';
import { isNotNull, LinkRelationName, StateResource } from '@alfa-client/tech-shared'; import { LinkRelationName, StateResource } from '@alfa-client/tech-shared';
import { Component, Input, OnDestroy, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { getEmbeddedResource, Resource } from '@ngxp/rest'; import { Resource } from '@ngxp/rest';
import { filter, Subscription } from 'rxjs'; import { Observable } from 'rxjs';
import { BinaryFileListOrientation } from '../directive/binary-file-list-orientation/binary-file-list-orientation.directive'; import { BinaryFileListOrientation } from '../directive/binary-file-list-orientation/binary-file-list-orientation.directive';
@Component({ @Component({
selector: 'alfa-binary-file-list-container', selector: 'alfa-binary-file-list-container',
templateUrl: './binary-file-list-container.component.html', templateUrl: './binary-file-list-container.component.html',
}) })
export class BinaryFileListContainerComponent implements OnInit, OnDestroy { export class BinaryFileListContainerComponent implements OnInit {
@Input() resource: Resource; @Input() resource: Resource;
@Input() linkRel: LinkRelationName; @Input() linkRel: LinkRelationName;
@Input() listOrientation: BinaryFileListOrientation = BinaryFileListOrientation.HORIZONTAL; @Input() listOrientation: BinaryFileListOrientation = BinaryFileListOrientation.HORIZONTAL;
public binaryFileList: BinaryFile[]; public binaryFileListStateResource$: Observable<StateResource<BinaryFileListResource>>;
public readonly binaryFileListLinkRel = BinaryFileListLinkRel;
binaryFileListSubscription: Subscription;
constructor(private service: BinaryFileService) {} constructor(private service: BinaryFileService) {}
ngOnInit(): void { ngOnInit(): void {
this.binaryFileListSubscription = this.service this.binaryFileListStateResource$ = this.service.getFiles(this.resource, this.linkRel);
.getFiles(this.resource, this.linkRel)
.pipe(filter((stateResource) => isNotNull(stateResource.resource)))
.subscribe((stateResource: StateResource<BinaryFileListResource>) => {
this.binaryFileList = getEmbeddedResource(stateResource.resource, this.binaryFileListLinkRel.FILE_LIST);
});
}
ngOnDestroy() {
this.binaryFileListSubscription.unsubscribe();
} }
} }
...@@ -24,5 +24,10 @@ ...@@ -24,5 +24,10 @@
--> -->
<div [binaryFileListOrientation]="listOrientation"> <div [binaryFileListOrientation]="listOrientation">
<alfa-binary-file2-container *ngFor="let binaryFile of binaryFileList" [file]="binaryFile" [deletable]="false" /> <alfa-binary-file2-container
*ngFor="let binaryFile of binaryFileListStateResource.resource | toEmbeddedResources: binaryFileListLinkRel.FILE_LIST"
[file]="binaryFile"
[deletable]="false"
>
</alfa-binary-file2-container>
</div> </div>
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen * Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
import { BinaryFileResource } from '@alfa-client/binary-file-shared'; import { BinaryFileListResource, BinaryFileResource } from '@alfa-client/binary-file-shared';
import { ToEmbeddedResourcesPipe } from '@alfa-client/tech-shared'; import { createStateResource, StateResource, ToEmbeddedResourcesPipe } from '@alfa-client/tech-shared';
import { getMockComponent } from '@alfa-client/test-utils'; import { getMockComponent } from '@alfa-client/test-utils';
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { createBinaryFileResource } from 'libs/binary-file-shared/test/binary-file'; import { createBinaryFileListResource, createBinaryFileResource } from 'libs/binary-file-shared/test/binary-file';
import { MockComponent, MockDirective } from 'ng-mocks'; import { MockComponent, MockDirective } from 'ng-mocks';
import { BinaryFile2ContainerComponent } from '../../binary-file2-container/binary-file2-container.component'; import { BinaryFile2ContainerComponent } from '../../binary-file2-container/binary-file2-container.component';
import { BinaryFileListOrientationDirective } from '../../directive/binary-file-list-orientation/binary-file-list-orientation.directive'; import { BinaryFileListOrientationDirective } from '../../directive/binary-file-list-orientation/binary-file-list-orientation.directive';
...@@ -36,6 +36,9 @@ describe('BinaryFileListComponent', () => { ...@@ -36,6 +36,9 @@ describe('BinaryFileListComponent', () => {
let fixture: ComponentFixture<BinaryFileListComponent>; let fixture: ComponentFixture<BinaryFileListComponent>;
const binaryFile: BinaryFileResource = createBinaryFileResource(); const binaryFile: BinaryFileResource = createBinaryFileResource();
const binaryFileListStateResource: StateResource<BinaryFileListResource> = createStateResource(
createBinaryFileListResource([binaryFile]),
);
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
...@@ -49,7 +52,7 @@ describe('BinaryFileListComponent', () => { ...@@ -49,7 +52,7 @@ describe('BinaryFileListComponent', () => {
fixture = TestBed.createComponent(BinaryFileListComponent); fixture = TestBed.createComponent(BinaryFileListComponent);
component = fixture.componentInstance; component = fixture.componentInstance;
component.binaryFileList = [binaryFile]; component.binaryFileListStateResource = binaryFileListStateResource;
fixture.detectChanges(); fixture.detectChanges();
}); });
......
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
* Die sprachspezifischen Genehmigungen und Beschränkungen * Die sprachspezifischen Genehmigungen und Beschränkungen
* unter der Lizenz sind dem Lizenztext zu entnehmen. * unter der Lizenz sind dem Lizenztext zu entnehmen.
*/ */
import { BinaryFile } from '@alfa-client/binary-file-shared'; import { BinaryFileListLinkRel, BinaryFileListResource } from '@alfa-client/binary-file-shared';
import { StateResource } from '@alfa-client/tech-shared';
import { Component, Input } from '@angular/core'; import { Component, Input } from '@angular/core';
import { BinaryFileListOrientation } from '../../directive/binary-file-list-orientation/binary-file-list-orientation.directive'; import { BinaryFileListOrientation } from '../../directive/binary-file-list-orientation/binary-file-list-orientation.directive';
...@@ -30,6 +31,8 @@ import { BinaryFileListOrientation } from '../../directive/binary-file-list-orie ...@@ -30,6 +31,8 @@ import { BinaryFileListOrientation } from '../../directive/binary-file-list-orie
templateUrl: './binary-file-list.component.html', templateUrl: './binary-file-list.component.html',
}) })
export class BinaryFileListComponent { export class BinaryFileListComponent {
@Input() public binaryFileList: BinaryFile[]; @Input() public binaryFileListStateResource: StateResource<BinaryFileListResource>;
@Input() listOrientation: BinaryFileListOrientation = BinaryFileListOrientation.HORIZONTAL; @Input() listOrientation: BinaryFileListOrientation = BinaryFileListOrientation.HORIZONTAL;
public readonly binaryFileListLinkRel = BinaryFileListLinkRel;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment