|
@@ -1,5 +1,7 @@
|
|
|
import { Injectable } from '@angular/core';
|
|
|
import Localbase from 'localbase';
|
|
|
+import { Character } from 'src/interfaces/character';
|
|
|
+import { Router } from '@angular/router';
|
|
|
|
|
|
@Injectable({
|
|
|
providedIn: 'root',
|
|
@@ -7,10 +9,13 @@ import Localbase from 'localbase';
|
|
|
export class DataService {
|
|
|
db: any;
|
|
|
|
|
|
- constructor() {
|
|
|
+ constructor(private Router: Router) {
|
|
|
this.db = new Localbase('myDatabase');
|
|
|
}
|
|
|
|
|
|
+ public character: Character = { name: '' };
|
|
|
+ public characterData: any = {};
|
|
|
+
|
|
|
public addData(collection: string, data: any, key?: string): void {
|
|
|
if (key) {
|
|
|
this.db.collection(collection).add(data, key);
|
|
@@ -19,17 +24,24 @@ export class DataService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // public addData(collection: string, data: any): void {
|
|
|
- // this.db.collection(collection).add(data);
|
|
|
- // }
|
|
|
-
|
|
|
getData(collection: string, key: string) {
|
|
|
return this.db.collection(collection).doc(key).get();
|
|
|
}
|
|
|
|
|
|
getCollection(collection: string) {
|
|
|
- const res = this.db.collection(collection).get();
|
|
|
- console.log(res);
|
|
|
- return res;
|
|
|
+ return this.db.collection(collection).get();
|
|
|
+ }
|
|
|
+
|
|
|
+ public async selectCharacter(character: any) {
|
|
|
+ this.character = character;
|
|
|
+ await this.getCharacterData(character.name);
|
|
|
+ this.Router.navigate(['journal']);
|
|
|
+ }
|
|
|
+
|
|
|
+ public getCharacterData(characterName: string) {
|
|
|
+ this.getCollection(characterName).then((characterData: any) => {
|
|
|
+ this.characterData = characterData;
|
|
|
+ console.log(this.characterData);
|
|
|
+ });
|
|
|
}
|
|
|
}
|