refactor: change meta class structure to include types.

Introduce requiredness of translations via implemented interface.
This commit is contained in:
Rainer Killinger
2019-02-06 14:21:46 +01:00
committed by Karl-Philipp Wulfert
parent 90e3d22399
commit 62975b9ded
32 changed files with 1060 additions and 246 deletions

View File

@@ -14,7 +14,7 @@
*/
import {SCOrganization} from './things/Organization';
import {SCPerson} from './things/Person';
import {SCTranslations} from './types/i18n';
import {SCMetaTranslations, SCTranslations} from './types/i18n';
import {SCISO8601Date} from './types/Time';
import {SCUuid} from './types/UUID';
@@ -187,41 +187,6 @@ export interface SCThingUserOrigin extends SCThingOrigin {
updated?: SCISO8601Date;
}
/**
* Meta information about things
*/
export class SCThingMeta {
/**
* Translations of fields
*/
static fieldTranslations: any = {
de: {
alternateNames: 'alternative Namen',
description: 'Beschreibung',
image: 'Bild',
name: 'Name',
translations: 'Übersetzungen',
type: 'Typ',
uid: 'Identifikation',
url: 'URL',
},
en: {
alternateNames: 'alternate names',
description: 'description',
uid: 'identification',
},
};
/**
* Translations of values of fields
*/
static fieldValueTranslations: any = {
de: {
type: 'Ding',
},
};
}
/**
* Translatable properties of things
*/
@@ -249,3 +214,63 @@ export interface SCThingTranslatablePropertyOrigin {
*/
name: string;
}
/**
* Meta information about things
*/
export class SCThingMeta implements SCMetaTranslations<SCThing> {
/**
* Set type definiton for singleton instance
*/
protected static _instance: SCThingMeta;
/**
* Translations of fields
*/
fieldTranslations = {
de: {
alternateNames: 'alternative Namen',
description: 'Beschreibung',
image: 'Bild',
name: 'Name',
origin: 'Ursprung',
translations: 'Übersetzungen',
type: 'Typ',
uid: 'Identifikation',
url: 'URL',
},
en: {
alternateNames: 'alternate names',
description: 'description',
image: 'image',
name: 'name',
origin: 'origin',
translations: 'translations',
type: 'type',
uid: 'identification',
url: 'URL',
},
};
/**
* Translations of values of fields
*/
fieldValueTranslations = {
de: {
type: 'Ding',
},
en: {
type: 'Thing',
},
};
/**
* Function to retrieve typed singleton instance
*/
public static getInstance<T extends SCThingMeta>(): T {
const typedThis = this as any as typeof SCThingMeta;
return (typedThis._instance || (typedThis._instance = new this())) as T;
}
protected constructor() {}
}