Own YAML Converter and update note won't override user data anymore

This commit is contained in:
mProjectsCode 2022-05-31 22:26:45 +02:00
parent 5916ed66eb
commit 0298270b03
14 changed files with 129 additions and 38 deletions

View file

@ -20,8 +20,10 @@ export class GameModel extends MediaTypeModel {
released: boolean;
releaseDate: string;
played: boolean;
personalRating: number;
userData: {
played: boolean;
personalRating: number;
};
constructor(obj: any = {}) {

View file

@ -1,5 +1,5 @@
import {MediaType} from '../utils/MediaType';
import {stringifyYaml} from 'obsidian';
import {YAMLConverter} from '../utils/YAMLConverter';
export abstract class MediaTypeModel {
type: string;
@ -11,12 +11,20 @@ export abstract class MediaTypeModel {
url: string;
id: string;
userData: object;
abstract getMediaType(): MediaType;
abstract getTags(): string[];
toMetaData(): string {
return stringifyYaml({...this, tags: '#' + this.getTags().join('/')});
return YAMLConverter.toYaml({...this.getWithOutUserData(), ...this.userData, tags: '#' + this.getTags().join('/')});
}
getWithOutUserData(): object {
const copy = JSON.parse(JSON.stringify(this));
delete copy.userData;
return copy;
}
}

View file

@ -22,10 +22,11 @@ export class MovieModel extends MediaTypeModel {
released: boolean;
premiere: string;
watched: boolean;
lastWatched: string;
personalRating: number;
userData: {
watched: boolean;
lastWatched: string;
personalRating: number;
};
constructor(obj: any = {}) {
super();

View file

@ -17,7 +17,9 @@ export class MusicReleaseModel extends MediaTypeModel {
artists: string[];
rating: number;
personalRating: number;
userData: {
personalRating: number;
};
constructor(obj: any = {}) {
super();

View file

@ -25,10 +25,11 @@ export class SeriesModel extends MediaTypeModel {
airedFrom: string;
airedTo: string;
watched: boolean;
lastWatched: string;
personalRating: number;
userData: {
watched: boolean;
lastWatched: string;
personalRating: number;
};
constructor(obj: any = {}) {
super();

View file

@ -17,6 +17,7 @@ export class WikiModel extends MediaTypeModel {
lastUpdated: string;
length: number;
userData: {};
constructor(obj: any = {}) {
super();