Skip to content

Commit

Permalink
Add BCF file view
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgDangl committed Apr 2, 2024
1 parent 276f4f0 commit 34a6d73
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ipa-bcfier-ui/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ <h1 class="title"><strong>IPA.</strong>BCFier</h1>
<bcfier-top-menu></bcfier-top-menu>
</mat-toolbar>

<mat-tab-group *ngIf="bcfFiles">
<mat-tab-group *ngIf="bcfFiles" dynamicHeight>
<mat-tab *ngFor="let bcfFile of bcfFiles | async">
<ng-template mat-tab-label>
{{ bcfFile.fileName }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div class="issue-list">
<div class="issue-list-buttons">
<button mat-raised-button color="primary">Add Issue</button>
<button mat-raised-button color="warn">Delete Issue</button>
</div>
<div>
<mat-form-field>
<mat-label>Search</mat-label>
<input matInput placeholder="Title or description" [(ngModel)]="search" />
@if (search) {
<button matSuffix mat-icon-button (click)="search = ''">
<mat-icon>close</mat-icon>
</button>
}
</mat-form-field>
</div>
<div class="topic-list">
<mat-card *ngFor="let topic of bcfFile.topics | topicFilter : search">
<mat-card-header>
<mat-card-title-group>
<mat-card-title>{{ topic.title }}</mat-card-title>
<mat-card-subtitle>{{
topic.creationDate | date : "dd.MM.yyyy"
}}</mat-card-subtitle>

<img
mat-card-md-image
[bcfierTopicPreviewImage]="topic"
src="https://material.angular.io/assets/img/examples/shiba2.jpg"
/>
</mat-card-title-group>
</mat-card-header>
<mat-card-content>
<div class="topic-info">
<mat-icon color="primary">chat</mat-icon>
{{ topic.comments.length }}
</div>
<div class="topic-info">
<mat-icon color="primary">visibility</mat-icon>
{{ topic.viewpoints.length }}
</div>
</mat-card-content>
</mat-card>
</div>
</div>
<div class="issue-details"></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.issue-list {
margin-top: 4px;
margin-left: 4px;
display: flex;
flex-direction: column;
width: 30%;
height: 100%;
}

.issue-list-buttons {
display: flex;
flex-direction: row;
justify-content: space-evenly;
margin-bottom: 4px;

button {
width: 45%;
}
}

.topic-list {
display: flex;
flex-direction: column;
gap: 12px;
}

mat-form-field {
width: 100%;
}

mat-card-content {
display: flex;
flex-direction: row;
gap: 12px;
}

.topic-info {
display: flex;
flex-direction: row;
gap: 6px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { BcfFileComponent } from './bcf-file.component';

describe('BcfFileComponent', () => {
let component: BcfFileComponent;
let fixture: ComponentFixture<BcfFileComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [BcfFileComponent]
})
.compileComponents();

fixture = TestBed.createComponent(BcfFileComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Component, Input } from '@angular/core';

import { BcfFile } from '../../../generated/models';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { TopicFilterPipe } from '../../pipes/topic-filter.pipe';
import { TopicPreviewImageDirective } from '../../directives/topic-preview-image.directive';

@Component({
selector: 'bcfier-bcf-file',
standalone: true,
imports: [
MatButtonModule,
MatInputModule,
CommonModule,
MatCardModule,
MatIconModule,
TopicPreviewImageDirective,
FormsModule,
TopicFilterPipe,
],
templateUrl: './bcf-file.component.html',
styleUrl: './bcf-file.component.scss',
})
export class BcfFileComponent {
@Input() bcfFile!: BcfFile;

private _search = '';
public set search(value: string) {
this._search = value;
}
public get search(): string {
return this._search;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { TopicPreviewImageDirective } from './topic-preview-image.directive';

describe('TopicPreviewImageDirective', () => {
it('should create an instance', () => {
const directive = new TopicPreviewImageDirective();
expect(directive).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { BcfFile, BcfTopic } from '../../generated/models';
import { Directive, ElementRef, Input, OnInit } from '@angular/core';

@Directive({
selector: '[bcfierTopicPreviewImage]',
standalone: true,
})
export class TopicPreviewImageDirective implements OnInit {
@Input() bcfierTopicPreviewImage!: BcfTopic;

constructor(private elementRef: ElementRef) {}

ngOnInit(): void {
const viewpoints = this.bcfierTopicPreviewImage.viewpoints.filter(
(vp) => vp.snapshotBase64
);
if (viewpoints.length === 0) {
return;
}

// We're using the base64 data from the snapshot to
// generate a base64 data url with png type
const imageUrl = `data:image/png;base64,${viewpoints[0].snapshotBase64}`;
// Then we're appending it to the host element as src attribute
this.elementRef.nativeElement.src = imageUrl;
}
}
8 changes: 8 additions & 0 deletions src/ipa-bcfier-ui/src/app/pipes/topic-filter.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { TopicFilterPipe } from './topic-filter.pipe';

describe('TopicFilterPipe', () => {
it('create an instance', () => {
const pipe = new TopicFilterPipe();
expect(pipe).toBeTruthy();
});
});
33 changes: 33 additions & 0 deletions src/ipa-bcfier-ui/src/app/pipes/topic-filter.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Pipe, PipeTransform } from '@angular/core';

import { BcfTopic } from '../../generated/models';

@Pipe({
name: 'topicFilter',
standalone: true,
})
export class TopicFilterPipe implements PipeTransform {
transform(value: BcfTopic[], filter: string): BcfTopic[] {
if (!filter) {
return value;
}

return value.filter((topic) => {
if (
topic.title != null &&
topic.title.toUpperCase().indexOf(filter.toUpperCase()) !== -1
) {
return true;
}

if (
topic.description != null &&
topic.description.toUpperCase().indexOf(filter.toUpperCase()) !== -1
) {
return true;
}

return false;
});
}
}

0 comments on commit 34a6d73

Please sign in to comment.