refine list

This commit is contained in:
Benjamin Ifland
2019-03-24 14:37:29 +01:00
parent 1cb8a119b9
commit af4493ec94
23 changed files with 268 additions and 231 deletions

View File

@@ -1,26 +1,45 @@
import { Component, OnInit, Input } from '@angular/core';
import { Song } from 'src/app/models/song.model';
import { SongsService } from './../../../data/songs.service';
import {
Component,
ChangeDetectionStrategy,
ChangeDetectorRef
} from '@angular/core';
@Component({
selector: 'app-table',
templateUrl: './table.component.html',
styleUrls: ['./table.component.less']
styleUrls: ['./table.component.less'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TableComponent implements OnInit {
@Input() public songs: Song[];
public columns = [
'Number',
'Name',
'Key',
'SongType',
'Tempo',
];
constructor() { }
ngOnInit() {
console.log(this.songs);
export class TableComponent {
public selectedSongId = 0;
public columnsFull = ['Number', 'Name', 'Key', 'SongType', 'Tempo'];
public columnsPinned = ['Number', 'Name'];
public get columns(): string[] {
return this.selectedSongId === 0 ? this.columnsFull : this.columnsPinned;
}
constructor(
public songsService: SongsService,
private change: ChangeDetectorRef
) {
songsService.selectedSong.subscribe(_ => {
this.selectedSongId = _ ? _.ID : 0;
this.change.markForCheck();
}
);
}
public renderSongType(songType: string) {
switch (songType) {
case 'Praise': return {name: 'Lobpreis', color: '#99FFB8'};
case 'Worship': return {name: 'Anbetung', color: '#C999FF'};
default: return null;
}
}
public onClick(id: number): void {
this.songsService.selectSong(id);
this.change.detectChanges();
}
}