update tslint -> eslint
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
<app-card closeLink="../" heading="Neues Lied">
|
||||
|
||||
<div [formGroup]="form" class="split">
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Nummer</mat-label>
|
||||
<input formControlName="number" matInput>
|
||||
<input formControlName="number" matInput/>
|
||||
</mat-form-field>
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Titel</mat-label>
|
||||
<input autofocus formControlName="title" matInput>
|
||||
<input autofocus formControlName="title" matInput/>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
|
||||
@@ -15,4 +14,3 @@
|
||||
<app-button (click)="onSave()" [icon]="faSave">Anlegen</app-button>
|
||||
</app-button-row>
|
||||
</app-card>
|
||||
|
||||
|
||||
@@ -6,12 +6,13 @@ describe('NewComponent', () => {
|
||||
let component: NewComponent;
|
||||
let fixture: ComponentFixture<NewComponent>;
|
||||
|
||||
beforeEach(waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [NewComponent]
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
void TestBed.configureTestingModule({
|
||||
declarations: [NewComponent],
|
||||
}).compileComponents();
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(NewComponent);
|
||||
@@ -20,6 +21,6 @@ describe('NewComponent', () => {
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
void expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,14 +10,13 @@ import {Router} from '@angular/router';
|
||||
@Component({
|
||||
selector: 'app-new',
|
||||
templateUrl: './new.component.html',
|
||||
styleUrls: ['./new.component.less']
|
||||
styleUrls: ['./new.component.less'],
|
||||
})
|
||||
export class NewComponent implements OnInit {
|
||||
public faSave = faSave;
|
||||
public form: FormGroup;
|
||||
|
||||
constructor(private songService: SongService, private router: Router) {
|
||||
}
|
||||
public constructor(private songService: SongService, private router: Router) {}
|
||||
|
||||
public ngOnInit(): void {
|
||||
this.form = new FormGroup({
|
||||
@@ -25,23 +24,27 @@ export class NewComponent implements OnInit {
|
||||
title: new FormControl(null, Validators.required),
|
||||
});
|
||||
|
||||
this.songService.list$().pipe(autoComplete(this)).subscribe(songs => {
|
||||
const freeSongnumber = this.getFreeSongNumber(songs);
|
||||
this.form.controls.number.setValue(freeSongnumber);
|
||||
});
|
||||
this.songService
|
||||
.list$()
|
||||
.pipe(autoComplete(this))
|
||||
.subscribe(songs => {
|
||||
const freeSongnumber = this.getFreeSongNumber(songs);
|
||||
this.form.controls.number.setValue(freeSongnumber);
|
||||
});
|
||||
}
|
||||
|
||||
public async onSave(): Promise<void> {
|
||||
const number = this.form.value.number;
|
||||
const title = this.form.value.title;
|
||||
const newSongId = await this.songService.new(number, title);
|
||||
const value = this.form.value as {number: number; title: string};
|
||||
const songNumber = value.number;
|
||||
const title = value.title;
|
||||
const newSongId = await this.songService.new(songNumber, title);
|
||||
await this.router.navigateByUrl('/songs/' + newSongId + '/edit');
|
||||
}
|
||||
|
||||
private getFreeSongNumber(songs: Song[]): Number {
|
||||
const numbers = songs.map(_ => _.number);
|
||||
private getFreeSongNumber(songs: Song[]): number {
|
||||
const songNumber = songs.map(_ => _.number);
|
||||
for (let i = 1; i < Number.MAX_SAFE_INTEGER; i++) {
|
||||
if (!numbers.some(_ => _ === i)) {
|
||||
if (!songNumber.some(_ => _ === i)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,19 +9,8 @@ import {ButtonRowModule} from '../../../../widget-modules/components/button-row/
|
||||
import {ButtonModule} from '../../../../widget-modules/components/button/button.module';
|
||||
import {AutofocusModule} from '../../../../widget-modules/directives/autofocus/autofocus.module';
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [NewComponent],
|
||||
imports: [
|
||||
CommonModule,
|
||||
CardModule,
|
||||
ReactiveFormsModule,
|
||||
MatFormFieldModule,
|
||||
MatInputModule,
|
||||
ButtonRowModule,
|
||||
ButtonModule,
|
||||
AutofocusModule
|
||||
]
|
||||
imports: [CommonModule, CardModule, ReactiveFormsModule, MatFormFieldModule, MatInputModule, ButtonRowModule, ButtonModule, AutofocusModule],
|
||||
})
|
||||
export class NewModule {
|
||||
}
|
||||
export class NewModule {}
|
||||
|
||||
Reference in New Issue
Block a user