update tslint -> eslint

This commit is contained in:
2021-05-21 20:17:26 +02:00
parent 80260df71f
commit a195fafa6b
252 changed files with 3080 additions and 2420 deletions

View File

@@ -6,11 +6,11 @@ describe('DocxService', () => {
let service: DocxService;
beforeEach(() => {
TestBed.configureTestingModule({});
void TestBed.configureTestingModule({});
service = TestBed.inject(DocxService);
});
it('should be created', () => {
expect(service).toBeTruthy();
void expect(service).toBeTruthy();
});
});

View File

@@ -24,29 +24,24 @@ export interface DownloadOptions {
}
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class DocxService {
constructor(
public constructor(
private showService: ShowService,
private showSongService: ShowSongService,
private songService: SongService,
private textRenderingService: TextRenderingService,
private userService: UserService,
private configService: ConfigService,
) {
}
private configService: ConfigService
) {}
public async create(showId: string, options: DownloadOptions = {}): Promise<any> {
public async create(showId: string, options: DownloadOptions = {}): Promise<void> {
const {show, songs, user, config} = await this.prepareData(showId);
const type = new ShowTypePipe().transform(show.showType);
const title = `${type} ${show.date.toDate().toLocaleDateString()}`;
const paragraphs = [
...this.renderTitle(title),
...this.renderSongs(songs, options, config),
];
const paragraphs = [...this.renderTitle(title), ...this.renderSongs(songs, options, config)];
const sections: ISectionOptions[] = [
{
@@ -56,11 +51,10 @@ export class DocxService {
},
},
children: paragraphs,
}
]
},
];
const document = this.prepareNewDocument(type, user.name, options, sections);
const blob = await Packer.toBlob(document);
// saveAs from FileSaver will download the file
@@ -72,7 +66,7 @@ export class DocxService {
creator: name,
title: type,
description: '... mit Beschreibung',
sections: sections,
sections,
styles: {
paragraphStyles: [
{
@@ -83,7 +77,8 @@ export class DocxService {
quickFormat: true,
run: options?.chordMode === 'hide' ? {} : {font: 'courier new'},
paragraph: {indent: {left: 0}},
}, {
},
{
id: 'licence',
name: 'Lizenz',
basedOn: 'Normal',
@@ -92,13 +87,13 @@ export class DocxService {
run: {size: 15, color: 'grey'},
paragraph: {indent: {left: 0}},
},
]
}
],
},
});
}
private renderSongs(songs: { showSong: ShowSong; song: Song; sections: Section[] }[], options: DownloadOptions, config: Config): Paragraph[] {
return songs.reduce((p, song) => [...p, ...this.renderSong(song.showSong, song.song, song.sections, options, config)], []);
private renderSongs(songs: {showSong: ShowSong; song: Song; sections: Section[]}[], options: DownloadOptions, config: Config): Paragraph[] {
return songs.reduce((p: Paragraph[], song) => [...p, ...this.renderSong(song.showSong, song.song, song.sections, options, config)], []);
}
private renderSong(showSong: ShowSong, song: Song, sections: Section[], options: DownloadOptions, config: Config): Paragraph[] {
@@ -106,15 +101,11 @@ export class DocxService {
const copyright = this.renderCopyright(song, options, config);
const songText = this.renderSongText(sections, options?.chordMode ?? showSong.chordMode);
return [
songTitle,
copyright,
...songText
].filter(_ => _);
return [songTitle, copyright, ...songText].filter(_ => _);
}
private renderSongText(sections: Section[], chordMode: ChordMode) {
return sections.reduce((p, section) => [...p, ...this.renderSection(section, chordMode)], []);
private renderSongText(sections: Section[], chordMode: ChordMode): Paragraph[] {
return sections.reduce((p: Paragraph[], section) => [...p, ...this.renderSection(section, chordMode)], []);
}
private renderSongTitle(song: Song): Paragraph {
@@ -137,9 +128,7 @@ export class DocxService {
const artist = song.artist ? song.artist + ', ' : '';
const termsOfUse = song.termsOfUse ? song.termsOfUse + ', ' : '';
const origin = song.origin ? song.origin + ', ' : '';
const licence = song.legalOwner === 'CCLI'
? 'CCLI-Liednummer: ' + song.legalOwnerId + ', CCLI-Lizenz: ' + config.ccliLicenseId
: 'CCLI-Liednummer: ' + song.legalOwnerId;
const licence = song.legalOwner === 'CCLI' ? 'CCLI-Liednummer: ' + song.legalOwnerId + ', CCLI-Lizenz: ' + config.ccliLicenseId : 'CCLI-Liednummer: ' + song.legalOwnerId;
return new Paragraph({
text: artist + label + termsOfUse + origin + licence,
@@ -147,7 +136,6 @@ export class DocxService {
});
}
private renderSection(section: Section, chordMode: ChordMode): Paragraph[] {
return section.lines
.filter(line => {
@@ -171,13 +159,11 @@ export class DocxService {
return new Paragraph({
text: line.text,
style: 'songtext',
spacing
spacing,
});
}
private renderTitle(type: string): Paragraph[] {
const songTitle = new Paragraph({
text: type,
heading: HeadingLevel.HEADING_1,
@@ -187,34 +173,39 @@ export class DocxService {
return [songTitle];
}
private async prepareData(showId: string): Promise<{ songs: ({ showSong: ShowSong, song: Song, sections: Section[] })[]; show: Show, user: User, config: Config }> {
private async prepareData(showId: string): Promise<{
songs: {showSong: ShowSong; song: Song; sections: Section[]}[];
show: Show;
user: User;
config: Config;
}> {
const show = await this.showService.read$(showId).pipe(first()).toPromise();
const user = await this.userService.getUserbyId(show.owner);
const config = await this.configService.get();
const showSongs = await this.showSongService.list(showId);
const songsAsync = await showSongs.map(async showSong => {
const songsAsync = showSongs.map(async showSong => {
const song = await this.songService.read(showSong.songId);
const sections = this.textRenderingService.parse(song.text, {
baseKey: showSong.keyOriginal,
targetKey: showSong.key
targetKey: showSong.key,
});
return {
showSong,
song,
sections
sections,
};
});
const songs = await Promise.all(songsAsync);
return {songs, show, user, config};
}
private saveAs(blob, fileName) {
const a = document.createElement('a') as any;
private saveAs(blob: Blob, fileName: string) {
const a = document.createElement('a');
document.body.appendChild(a);
a.setAttribute('target', '_self');
a.style = 'display: none';
a.style.display = 'none';
const url = window.URL.createObjectURL(blob);
a.href = url;

View File

@@ -3,10 +3,10 @@ import {TestBed} from '@angular/core/testing';
import {ShowDataService} from './show-data.service';
describe('ShowDataService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
beforeEach(() => void TestBed.configureTestingModule({}));
it('should be created', () => {
const service: ShowDataService = TestBed.get(ShowDataService);
expect(service).toBeTruthy();
const service: ShowDataService = TestBed.inject(ShowDataService);
void expect(service).toBeTruthy();
});
});

View File

@@ -2,17 +2,17 @@ import {Injectable} from '@angular/core';
import {Observable} from 'rxjs';
import {DbService} from '../../../services/db.service';
import {Show} from './show';
import {QueryFn} from '@angular/fire/firestore/interfaces';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class ShowDataService {
private collection = 'shows';
constructor(private dbService: DbService) {
}
public constructor(private dbService: DbService) {}
public list$ = (queryFn?): Observable<Show[]> => this.dbService.col$(this.collection, queryFn);
public list$ = (queryFn?: QueryFn): Observable<Show[]> => this.dbService.col$(this.collection, queryFn);
public read$ = (showId: string): Observable<Show | undefined> => this.dbService.doc$(`${this.collection}/${showId}`);
public update = async (showId: string, data: Partial<Show>): Promise<void> => await this.dbService.doc(`${this.collection}/${showId}`).update(data);
public add = async (data: Partial<Show>): Promise<string> => (await this.dbService.col(this.collection).add(data)).id;

View File

@@ -6,11 +6,11 @@ describe('ShowSongDataService', () => {
let service: ShowSongDataService;
beforeEach(() => {
TestBed.configureTestingModule({});
void TestBed.configureTestingModule({});
service = TestBed.inject(ShowSongDataService);
});
it('should be created', () => {
expect(service).toBeTruthy();
void expect(service).toBeTruthy();
});
});

View File

@@ -2,20 +2,21 @@ import {Injectable} from '@angular/core';
import {DbService} from '../../../services/db.service';
import {Observable} from 'rxjs';
import {ShowSong} from './show-song';
import {QueryFn} from '@angular/fire/firestore/interfaces';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class ShowSongDataService {
private collection = 'shows';
private subCollection = 'songs';
constructor(private dbService: DbService) {
}
public constructor(private dbService: DbService) {}
public list$ = (showId: string, queryFn?): Observable<ShowSong[]> => this.dbService.col$(`${this.collection}/${showId}/${this.subCollection}`, queryFn);
public list$ = (showId: string, queryFn?: QueryFn): Observable<ShowSong[]> => this.dbService.col$(`${this.collection}/${showId}/${this.subCollection}`, queryFn);
public read$ = (showId: string, songId: string): Observable<ShowSong | undefined> => this.dbService.doc$(`${this.collection}/${showId}/${this.subCollection}/${songId}`);
public update$ = async (showId: string, songId: string, data: Partial<ShowSong>): Promise<void> => await this.dbService.doc(`${this.collection}/${showId}/${this.subCollection}/${songId}`).update(data);
public update$ = async (showId: string, songId: string, data: Partial<ShowSong>): Promise<void> =>
await this.dbService.doc(`${this.collection}/${showId}/${this.subCollection}/${songId}`).update(data);
public delete = async (showId: string, songId: string): Promise<void> => await this.dbService.doc(`${this.collection}/${showId}/${this.subCollection}/${songId}`).delete();
public add = async (showId: string, data: Partial<ShowSong>): Promise<string> => (await this.dbService.col(`${this.collection}/${showId}/${this.subCollection}`).add(data)).id;
}

View File

@@ -6,11 +6,11 @@ describe('ShowSongService', () => {
let service: ShowSongService;
beforeEach(() => {
TestBed.configureTestingModule({});
void TestBed.configureTestingModule({});
service = TestBed.inject(ShowSongService);
});
it('should be created', () => {
expect(service).toBeTruthy();
void expect(service).toBeTruthy();
});
});

View File

@@ -7,16 +7,10 @@ import {first, take} from 'rxjs/operators';
import {UserService} from '../../../services/user/user.service';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class ShowSongService {
constructor(
private showSongDataService: ShowSongDataService,
private songDataService: SongDataService,
private userService: UserService,
) {
}
public constructor(private showSongDataService: ShowSongDataService, private songDataService: SongDataService, private userService: UserService) {}
public async new$(showId: string, songId: string, order: number, addedLive = false): Promise<string> {
const song = await this.songDataService.read$(songId).pipe(take(1)).toPromise();
@@ -27,7 +21,7 @@ export class ShowSongService {
key: song.key,
keyOriginal: song.key,
chordMode: user.chordMode,
addedLive
addedLive,
};
return await this.showSongDataService.add(showId, data);
}

View File

@@ -5,33 +5,40 @@ import {ShowDataService} from './show-data.service';
describe('ShowService', () => {
const mockShowDataService = {add: Promise.resolve(null)};
beforeEach(() => TestBed.configureTestingModule({
providers: [
{provide: ShowDataService, useValue: mockShowDataService}
]
}));
beforeEach(
() =>
void TestBed.configureTestingModule({
providers: [{provide: ShowDataService, useValue: mockShowDataService}],
})
);
ShowService.SHOW_TYPE_PUBLIC.forEach(type => {
it('should calc public flag for ' + type, async () => {
const service: ShowService = TestBed.get(ShowService);
const service: ShowService = TestBed.inject(ShowService);
const addSpy = spyOn(TestBed.inject(ShowDataService), 'add').and.returnValue(Promise.resolve('id'));
const id = await service.new$({showType: type});
expect(id).toBe('id');
expect(addSpy).toHaveBeenCalledWith({showType: type, public: true});
void expect(id).toBe('id');
void expect(addSpy).toHaveBeenCalledWith({
showType: type,
public: true,
});
});
});
ShowService.SHOW_TYPE_PRIVATE.forEach(type => {
it('should calc private flag for ' + type, async () => {
const service: ShowService = TestBed.get(ShowService);
const service: ShowService = TestBed.inject(ShowService);
const addSpy = spyOn(TestBed.inject(ShowDataService), 'add').and.returnValue(Promise.resolve('id'));
const id = await service.new$({showType: type});
expect(id).toBe('id');
expect(addSpy).toHaveBeenCalledWith({showType: type, public: false});
void expect(id).toBe('id');
void expect(addSpy).toHaveBeenCalledWith({
showType: type,
public: false,
});
});
});
});

View File

@@ -7,31 +7,28 @@ import {map, switchMap} from 'rxjs/operators';
import {User} from '../../../services/user/user';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class ShowService {
public static SHOW_TYPE = ['service-worship', 'service-praise', 'home-group-big', 'home-group', 'prayer-group', 'teens-group', 'kids-group', 'misc-public', 'misc-private'];
public static SHOW_TYPE_PUBLIC = ['service-worship', 'service-praise', 'home-group-big', 'teens-group', 'kids-group', 'misc-public'];
public static SHOW_TYPE_PRIVATE = ['home-group', 'prayer-group', 'misc-private',];
public static SHOW_TYPE_PRIVATE = ['home-group', 'prayer-group', 'misc-private'];
private user: User;
constructor(private showDataService: ShowDataService, private userService: UserService) {
userService.user$.subscribe(_ => this.user = _);
public constructor(private showDataService: ShowDataService, private userService: UserService) {
userService.user$.subscribe(_ => (this.user = _));
}
public read$ = (showId: string): Observable<Show> => this.showDataService.read$(showId);
public list$(publishedOnly: boolean = false): Observable<Show[]> {
public list$(publishedOnly = false): Observable<Show[]> {
return this.userService.user$.pipe(
switchMap(_ => this.showDataService.list$(), (user: User, shows: Show[]) => ({user, shows})),
map(_ => _.shows
.filter(_ => !_.archived)
.filter(show => show.published || (show.owner === _.user.id && !publishedOnly))
)
switchMap(
() => this.showDataService.list$(),
(user: User, shows: Show[]) => ({user, shows})
),
map(s => s.shows.filter(_ => !_.archived).filter(show => show.published || (show.owner === s.user.id && !publishedOnly)))
);
}
public update$ = async (showId: string, data: Partial<Show>): Promise<void> => this.showDataService.update(showId, data);

View File

@@ -14,6 +14,4 @@ export interface Show {
presentationSongId: string;
presentationSection: number;
presentationZoom: number;
}