diff --git a/WEB/src/app/components/songs/song-new/song-new.component.html b/WEB/src/app/components/songs/song-new/song-new.component.html
index 2657dc6..e40b680 100644
--- a/WEB/src/app/components/songs/song-new/song-new.component.html
+++ b/WEB/src/app/components/songs/song-new/song-new.component.html
@@ -14,8 +14,8 @@
-
diff --git a/WEB/src/app/components/songs/song-new/song-new.component.ts b/WEB/src/app/components/songs/song-new/song-new.component.ts
index 84ee085..925b9fb 100644
--- a/WEB/src/app/components/songs/song-new/song-new.component.ts
+++ b/WEB/src/app/components/songs/song-new/song-new.component.ts
@@ -31,4 +31,8 @@ export class SongNewComponent implements OnInit {
this.songsService.state = State.list;
}
+ public onClickAdd(): void {
+ this.songsService.saveNewSong$(this.form.value).subscribe();
+ }
+
}
diff --git a/WEB/src/app/components/songs/song/song.component.html b/WEB/src/app/components/songs/song/song.component.html
index b20d183..05f254c 100644
--- a/WEB/src/app/components/songs/song/song.component.html
+++ b/WEB/src/app/components/songs/song/song.component.html
@@ -7,7 +7,13 @@
{{ song.Name }}
- {{ song.Key }} - {{ song.Tempo }}
+
+
+ {{ renderSongType(song.SongType).name }}
+ Tonart: {{ song.Key }}
+ Tempo: {{ song.Tempo }}
+
{{ line }}
@@ -16,7 +22,7 @@
- Bearbeiten
+ bearbeiten
diff --git a/WEB/src/app/components/songs/song/song.component.ts b/WEB/src/app/components/songs/song/song.component.ts
index 7216809..2a6e524 100644
--- a/WEB/src/app/components/songs/song/song.component.ts
+++ b/WEB/src/app/components/songs/song/song.component.ts
@@ -57,4 +57,12 @@ export class SongComponent {
public get comments(): string[] {
return this.song && this.song.Comments ? this.song.Comments.split(/\r?\n/) : [];
}
+
+ public renderSongType(songType: string) {
+ switch (songType) {
+ case 'Praise': return {name: 'Lobpreis', color: '#99FFB8'};
+ case 'Worship': return {name: 'Anbetung', color: '#C999FF'};
+ default: return null;
+ }
+ }
}
diff --git a/WEB/src/app/components/songs/songs.component.ts b/WEB/src/app/components/songs/songs.component.ts
index 726090a..b786264 100644
--- a/WEB/src/app/components/songs/songs.component.ts
+++ b/WEB/src/app/components/songs/songs.component.ts
@@ -12,6 +12,6 @@ import { State } from 'src/app/data/state';
export class SongsComponent {
public State = State;
constructor(public songsService: SongsService) {
- songsService.loadSongList();
+ songsService.loadSongList$().subscribe();
}
}
diff --git a/WEB/src/app/components/songs/table/table.component.html b/WEB/src/app/components/songs/table/table.component.html
index b559497..5a94336 100644
--- a/WEB/src/app/components/songs/table/table.component.html
+++ b/WEB/src/app/components/songs/table/table.component.html
@@ -3,7 +3,9 @@
[class.pinned]="songsService.state !== State.list"
>
-
+
+
+
| # |
- {{ element.Number }} |
+
+
+ {{ element.Number }}
+
+ |
@@ -31,8 +37,13 @@
|
-
- {{ renderSongType(element.SongType).name }}
+
+ {{ renderSongType(element.SongType).name }}
|
diff --git a/WEB/src/app/data/edit-song.service.ts b/WEB/src/app/data/edit-song.service.ts
index 754295e..b7f6ea0 100644
--- a/WEB/src/app/data/edit-song.service.ts
+++ b/WEB/src/app/data/edit-song.service.ts
@@ -42,7 +42,7 @@ export class EditSongService {
private attachSync(form: FormGroup, song: Song) {
const controls = Object.keys(form.controls);
controls.forEach(control => {
- form.controls[control].valueChanges.pipe(switchMap(value => this.songsService.patch(song.ID, control, value))).subscribe();
+ form.controls[control].valueChanges.pipe(switchMap(value => this.songsService.patch$(song.ID, control, value))).subscribe();
});
}
diff --git a/WEB/src/app/data/odata.service.ts b/WEB/src/app/data/odata.service.ts
index 3f1a8e3..3681335 100644
--- a/WEB/src/app/data/odata.service.ts
+++ b/WEB/src/app/data/odata.service.ts
@@ -1,15 +1,16 @@
-import { ODataService, ODataQuery } from "odata-v4-ng";
-import { Observable } from "rxjs";
-import { map, tap } from "rxjs/operators";
-import { base } from "./urls";
+import { Song } from 'src/app/models/song.model';
+import { ODataService, ODataQuery } from 'odata-v4-ng';
+import { Observable } from 'rxjs';
+import { map, tap } from 'rxjs/operators';
+import { base } from './urls';
export class OdataService {
private url: string;
constructor(private odataService: ODataService, private entity: string) {
- this.url = base + "/odata/";
+ this.url = base + '/odata/';
}
- public list(properties: string[]): Observable {
+ public list$(properties: string[]): Observable {
const query = new ODataQuery(this.odataService, this.url)
.entitySet(this.entity)
.select(properties);
@@ -18,7 +19,7 @@ export class OdataService {
return get;
}
- public get(
+ public get$(
id: number,
properties: string[]
): Observable {
@@ -31,15 +32,30 @@ export class OdataService {
return get;
}
- public patch(id: number, control: string, value: any): Observable {
+ public patch$(id: number, control: string, value: any): Observable {
const valueSet = { [control]: value };
const query = new ODataQuery(this.odataService, this.url)
.entitySet(this.entity)
.entityKey(id);
- const get = query.patch(valueSet).pipe(
- map(() => true)
- );
+ const get = query.patch(valueSet).pipe(map(() => true));
return get;
}
+
+ public post$(values: any): Observable {
+ const querry = new ODataQuery(this.odataService, this.url);
+ const post = querry
+ .entitySet(this.entity)
+ .post(values)
+ .pipe(
+ tap(_ => console.log(_)),
+ map(_ => {
+ const mapped = _.toEntity();
+ return mapped;
+ }),
+ tap(_ => console.log(_))
+ );
+
+ return post;
+ }
}
diff --git a/WEB/src/app/data/songs.service.ts b/WEB/src/app/data/songs.service.ts
index 509e010..0de8207 100644
--- a/WEB/src/app/data/songs.service.ts
+++ b/WEB/src/app/data/songs.service.ts
@@ -3,7 +3,7 @@ import { ODataService } from 'odata-v4-ng';
import { OdataService } from './odata.service';
import { Song } from '../models/song.model';
import { BehaviorSubject, Observable } from 'rxjs';
-import { tap } from 'rxjs/operators';
+import { tap, switchMap } from 'rxjs/operators';
import { State } from './state';
@Injectable({
@@ -19,9 +19,22 @@ export class SongsService extends OdataService {
super(odataService, 'songs');
}
- public loadSongList(): void {
+ public loadSongList$(): Observable {
const properties = ['ID', 'Name', 'Number', 'SongType', 'Key', 'Tempo'];
- this.list(properties).subscribe(_ => this.songs.next(_));
+ const list = this.list$(properties).pipe(
+ tap(_ => this.songs.next(_))
+ );
+ return list;
+ }
+
+ public loadSongListAndGoTo$(id: number): Observable {
+ const properties = ['ID', 'Name', 'Number', 'SongType', 'Key', 'Tempo'];
+ const list = this.list$(properties).pipe(tap(_ => {
+ this.songs.next(_);
+ this.selectSong(id);
+ }));
+
+ return list;
}
public selectSong(id: number): void {
@@ -32,7 +45,7 @@ export class SongsService extends OdataService {
return;
}
- this.get(id, ['Text', 'Comments']).subscribe(_ => {
+ this.get$(id, ['Text', 'Comments']).subscribe(_ => {
song.Text = _.Text;
song.Comments = _.Comments;
this.selectedSong.next(song);
@@ -44,8 +57,8 @@ export class SongsService extends OdataService {
this.selectedSong.next(null);
}
- public patch(id: number, control: string, value: any): Observable {
- const patch = super.patch(id, control, value).pipe(
+ public patch$(id: number, control: string, value: any): Observable {
+ const patch = super.patch$(id, control, value).pipe(
tap(() => {
const songs = this.songs.value;
const song = songs.filter(_ => _.ID === id)[0];
@@ -54,6 +67,15 @@ export class SongsService extends OdataService {
this.selectedSong.next(song);
})
);
+
return patch;
}
+
+ public saveNewSong$(values: any): Observable {
+ const newSong = super
+ .post$(values)
+ .pipe(switchMap(_ => this.loadSongListAndGoTo$(_.ID)));
+
+ return newSong;
+ }
}