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('ConfigService', () => {
let service: ConfigService;
beforeEach(() => {
TestBed.configureTestingModule({});
void TestBed.configureTestingModule({});
service = TestBed.inject(ConfigService);
});
it('should be created', () => {
expect(service).toBeTruthy();
void expect(service).toBeTruthy();
});
});

View File

@@ -5,11 +5,10 @@ import {Config} from './config';
import {first} from 'rxjs/operators';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class ConfigService {
constructor(private db: DbService) {
}
public constructor(private db: DbService) {}
public get get$(): Observable<Config> {
return this.db.doc$<Config>('global/config');

View File

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

View File

@@ -1,19 +1,18 @@
import {Injectable} from '@angular/core';
import {AngularFirestore, AngularFirestoreCollection, AngularFirestoreDocument} from '@angular/fire/firestore';
import {Observable} from 'rxjs';
import {QueryFn} from '@angular/fire/firestore/interfaces';
type CollectionPredicate<T> = string | AngularFirestoreCollection<T>;
type DocumentPredicate<T> = string | AngularFirestoreDocument<T>;
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class DbService {
public constructor(private afs: AngularFirestore) {}
constructor(private afs: AngularFirestore) {
}
public col<T>(ref: CollectionPredicate<T>, queryFn?): AngularFirestoreCollection<T> {
public col<T>(ref: CollectionPredicate<T>, queryFn?: QueryFn): AngularFirestoreCollection<T> {
return typeof ref === 'string' ? this.afs.collection<T>(ref, queryFn) : ref;
}
@@ -23,10 +22,9 @@ export class DbService {
public doc$<T>(ref: DocumentPredicate<T>): Observable<T> {
return this.doc(ref).valueChanges({idField: 'id'});
}
public col$<T>(ref: CollectionPredicate<T>, queryFn?): Observable<T[]> {
public col$<T>(ref: CollectionPredicate<T>, queryFn?: QueryFn): Observable<T[]> {
return this.col(ref, queryFn).valueChanges({idField: 'id'});
}
}

View File

@@ -1 +1 @@
export const delay = (ms: number): Promise<any> => new Promise(resolve => setTimeout(resolve, ms));
export const delay = (ms: number): Promise<void> => new Promise(resolve => setTimeout(resolve, ms));

View File

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

View File

@@ -4,18 +4,16 @@ import {GlobalSettings} from './global-settings';
import {Observable} from 'rxjs';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class GlobalSettingsService {
constructor(private db: DbService) {
}
public constructor(private db: DbService) {}
public get get$(): Observable<GlobalSettings> {
return this.db.doc$<GlobalSettings>('global/static');
}
public async set(data: Partial<GlobalSettings>) {
public async set(data: Partial<GlobalSettings>): Promise<void> {
await this.db.doc<GlobalSettings>('global/static').update(data);
}
}

View File

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

View File

@@ -2,24 +2,24 @@ import {Injectable} from '@angular/core';
import {BehaviorSubject} from 'rxjs';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class ScrollService {
private scrollPosition: number;
private scrollSlots = {};
private _restoreScrollPosition$ = new BehaviorSubject<number>(0);
public restoreScrollPosition$ = this._restoreScrollPosition$.asObservable();
private scrollSlots: {[key: string]: number} = {};
private iRestoreScrollPosition$ = new BehaviorSubject<number>(0);
public restoreScrollPosition$ = this.iRestoreScrollPosition$.asObservable();
public saveScrollPosition(pos: number) {
public saveScrollPosition(pos: number): void {
this.scrollPosition = pos;
}
public storeScrollPositionFor(slot: string) {
public storeScrollPositionFor(slot: string): void {
this.scrollSlots[slot] = this.scrollPosition;
}
public restoreScrollPositionFor(slot: string) {
public restoreScrollPositionFor(slot: string): void {
const pos = this.scrollSlots[slot];
this._restoreScrollPosition$.next(pos);
this.iRestoreScrollPosition$.next(pos);
}
}

View File

@@ -2,27 +2,21 @@ import {Directive, ElementRef, Input, OnInit, TemplateRef, ViewContainerRef} fro
import {UserService} from './user.service';
@Directive({
selector: '[appOwner]'
selector: '[appOwner]',
})
export class OwnerDirective implements OnInit {
private currentUserId: string;
private _appOwner: string;
private iAppOwner: string;
@Input() set appOwner(value: string) {
this._appOwner = value;
public constructor(private element: ElementRef, private templateRef: TemplateRef<unknown>, private viewContainer: ViewContainerRef, private userService: UserService) {}
@Input()
public set appOwner(value: string) {
this.iAppOwner = value;
this.updateView();
}
constructor(
private element: ElementRef,
private templateRef: TemplateRef<any>,
private viewContainer: ViewContainerRef,
private userService: UserService
) {
}
public ngOnInit(): void {
this.userService.userId$.subscribe(user => {
this.currentUserId = user;
@@ -33,9 +27,8 @@ export class OwnerDirective implements OnInit {
private updateView() {
this.viewContainer.clear();
if (this.currentUserId === this._appOwner) {
if (this.currentUserId === this.iAppOwner) {
this.viewContainer.createEmbeddedView(this.templateRef);
}
}
}

View File

@@ -5,9 +5,6 @@ import {CommonModule} from '@angular/common';
@NgModule({
declarations: [OwnerDirective],
exports: [OwnerDirective],
imports: [
CommonModule
]
imports: [CommonModule],
})
export class OwnerModule {
}
export class OwnerModule {}

View File

@@ -4,21 +4,14 @@ import {UserService} from './user.service';
import {User} from './user';
@Directive({
selector: '[appRole]'
selector: '[appRole]',
})
export class RoleDirective implements OnInit {
@Input() appRole: roles[] = [];
@Input() public appRole: roles[] = [];
private currentUser: User;
private loggedIn: boolean;
constructor(
private element: ElementRef,
private templateRef: TemplateRef<any>,
private viewContainer: ViewContainerRef,
private userService: UserService
) {
}
public constructor(private element: ElementRef, private templateRef: TemplateRef<unknown>, private viewContainer: ViewContainerRef, private userService: UserService) {}
public ngOnInit(): void {
this.userService.user$.subscribe(user => {
@@ -53,6 +46,4 @@ export class RoleDirective implements OnInit {
return false;
}
}

View File

@@ -5,9 +5,6 @@ import {RoleDirective} from './role.directive';
@NgModule({
declarations: [RoleDirective],
exports: [RoleDirective],
imports: [
CommonModule
]
imports: [CommonModule],
})
export class RoleModule {
}
export class RoleModule {}

View File

@@ -1 +1 @@
{{name$|async}}
{{ name$ | async }}

View File

@@ -6,12 +6,13 @@ describe('UserNameComponent', () => {
let component: UserNameComponent;
let fixture: ComponentFixture<UserNameComponent>;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [UserNameComponent]
beforeEach(
waitForAsync(() => {
void TestBed.configureTestingModule({
declarations: [UserNameComponent],
}).compileComponents();
})
.compileComponents();
}));
);
beforeEach(() => {
fixture = TestBed.createComponent(UserNameComponent);
@@ -20,6 +21,6 @@ describe('UserNameComponent', () => {
});
it('should create', () => {
expect(component).toBeTruthy();
void expect(component).toBeTruthy();
});
});

View File

@@ -6,18 +6,15 @@ import {Observable} from 'rxjs';
@Component({
selector: 'app-user-name',
templateUrl: './user-name.component.html',
styleUrls: ['./user-name.component.less']
styleUrls: ['./user-name.component.less'],
})
export class UserNameComponent {
public name$: Observable<string>;
constructor(
private userService: UserService
) {
}
public constructor(private userService: UserService) {}
@Input() set userId(id: string) {
@Input()
public set userId(id: string) {
this.name$ = this.userService.getUserbyId$(id).pipe(map(_ => _.name));
}
}

View File

@@ -5,7 +5,6 @@ import {UserNameComponent} from './user-name.component';
@NgModule({
declarations: [UserNameComponent],
exports: [UserNameComponent],
imports: [CommonModule]
imports: [CommonModule],
})
export class UserNameModule {
}
export class UserNameModule {}

View File

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

View File

@@ -8,27 +8,28 @@ import {environment} from '../../../environments/environment';
import {Router} from '@angular/router';
@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class UserService {
constructor(private afAuth: AngularFireAuth, private db: DbService, private router: Router) {
this.afAuth.authState.pipe(
filter(_ => !!_),
tap(auth => this._userId$.next(auth.uid)),
switchMap(auth => this.readUser$(auth.uid)),
).subscribe(_ => this._user$.next(_));
}
private iUserId$ = new BehaviorSubject<string>(null);
private iUser$ = new BehaviorSubject<User>(null);
private _userId$ = new BehaviorSubject<string>(null);
public constructor(private afAuth: AngularFireAuth, private db: DbService, private router: Router) {
this.afAuth.authState
.pipe(
filter(_ => !!_),
tap(auth => this.iUserId$.next(auth.uid)),
switchMap(auth => this.readUser$(auth.uid))
)
.subscribe(_ => this.iUser$.next(_));
}
public get userId$(): Observable<string> {
return this._userId$.asObservable();
return this.iUserId$.asObservable();
}
private _user$ = new BehaviorSubject<User>(null);
public get user$(): Observable<User> {
return this._user$.pipe(filter(_ => !!_));
return this.iUser$.pipe(filter(_ => !!_));
}
public async currentUser(): Promise<User> {
@@ -43,44 +44,42 @@ export class UserService {
return this.db.doc$<User>('users/' + userId);
}
public async login(user: string, password: string): Promise<any> {
public async login(user: string, password: string): Promise<string> {
const aUser = await this.afAuth.signInWithEmailAndPassword(user, password);
const dUser = await this.readUser(aUser.user.uid);
this._user$.next(dUser);
this._userId$.next(aUser.user.uid);
this.iUser$.next(dUser);
this.iUserId$.next(aUser.user.uid);
return aUser.user.uid;
}
public loggedIn$ = () => this.afAuth.authState;
public loggedIn$: () => Observable<firebase.User | null> = () => this.afAuth.authState;
public list$ = (): Observable<User[]> => this.db.col$('users');
public list$: () => Observable<User[]> = (): Observable<User[]> => this.db.col$('users');
public async logout(): Promise<any> {
public async logout(): Promise<void> {
await this.afAuth.signOut();
this._user$.next(null);
this._userId$.next(null);
this.iUser$.next(null);
this.iUserId$.next(null);
}
public async update$(uid: string, data: Partial<User>): Promise<void> {
await this.db.doc<User>('users/' + uid).update(data);
}
public async changePassword(user: string): Promise<any> {
public async changePassword(user: string): Promise<void> {
const url = environment.url;
await this.afAuth.sendPasswordResetEmail(user, {url});
}
public async createNewUser(user: string, name: string, password: string): Promise<any> {
public async createNewUser(user: string, name: string, password: string): Promise<void> {
const aUser = await this.afAuth.createUserWithEmailAndPassword(user, password);
const userId = aUser.user.uid;
await this.db.doc('users/' + userId).set({name, chordMode: 'onlyFirst'});
const dUser = await this.readUser(aUser.user.uid);
this._user$.next(dUser);
this.iUser$.next(dUser);
await this.router.navigateByUrl('/brand/new-user');
}
private readUser$ = (uid) => this.db.doc$<User>('users/' + uid);
private async readUser(uid): Promise<User> {
return await this.readUser$(uid).pipe(first()).toPromise();
}
private readUser$ = (uid: string) => this.db.doc$<User>('users/' + uid);
private readUser = async (uid: string): Promise<User> => await this.readUser$(uid).pipe(first()).toPromise();
}