mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-03 03:52:52 +00:00
173 lines
4.6 KiB
TypeScript
173 lines
4.6 KiB
TypeScript
/*
|
|
* Copyright (C) 2019 StApps
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
* Software Foundation, version 3.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
import {SCMetaTranslations, SCTranslations} from '../../general/i18n';
|
|
import {SCMap} from '../../general/map';
|
|
import {SCThing, SCThingMeta, SCThingTranslatableProperties, SCThingWithoutReferences} from './thing';
|
|
|
|
/**
|
|
* A thing without references with categories
|
|
*
|
|
* !!! BEWARE !!!
|
|
* `T` should be a string literal union type - e.g. `T = 'foo' | 'bar' | 'foobar';`
|
|
*/
|
|
export interface SCThingWithCategoriesWithoutReferences<T, U extends SCThingWithCategoriesSpecificValues>
|
|
extends SCThingWithoutReferences {
|
|
/**
|
|
* Categories of a thing with categories
|
|
*
|
|
* @sortable ducet
|
|
* @aggregatable
|
|
* @filterable
|
|
*/
|
|
categories: T[];
|
|
|
|
/**
|
|
* Use this to explicitly override general opening hours brought in scope by openingHoursSpecification or openingHours
|
|
*
|
|
* A map from categories to their specific values.
|
|
*/
|
|
categorySpecificValues?: SCMap<U>;
|
|
|
|
/**
|
|
* Translated fields of a thing with categories
|
|
*/
|
|
translations?: SCTranslations<SCThingWithCategoriesTranslatableProperties>;
|
|
}
|
|
|
|
/**
|
|
* A thing with categories
|
|
*/
|
|
export interface SCThingWithCategories<T, U extends SCThingWithCategoriesSpecificValues>
|
|
extends SCThing, SCThingWithCategoriesWithoutReferences<T, U> {
|
|
/**
|
|
* Translated fields of a thing with categories
|
|
*/
|
|
translations?: SCTranslations<SCThingWithCategoriesTranslatableProperties>;
|
|
}
|
|
|
|
/**
|
|
* Translatable properties of a thing with categories
|
|
*/
|
|
export interface SCThingWithCategoriesTranslatableProperties
|
|
extends SCThingTranslatableProperties {
|
|
/**
|
|
* translations of the categories of a thing with categories
|
|
*
|
|
* @sortable ducet
|
|
*/
|
|
categories?: string[];
|
|
}
|
|
|
|
/**
|
|
* Category specific values of a thing with categories
|
|
*
|
|
* This interface contains properties that can be specific to a certain category.
|
|
*/
|
|
export interface SCThingWithCategoriesSpecificValues {
|
|
/**
|
|
* Category specific alternate names of a thing
|
|
*
|
|
* @keyword
|
|
*/
|
|
alternateNames?: string[];
|
|
|
|
/**
|
|
* Category specific description of a thing
|
|
*
|
|
* @text
|
|
*/
|
|
description?: string;
|
|
|
|
/**
|
|
* URL of a category specific image of a thing
|
|
*
|
|
* @keyword
|
|
*/
|
|
image?: string;
|
|
|
|
/**
|
|
* Category specific name of a thing
|
|
*
|
|
* @sortable ducet
|
|
* @text
|
|
*/
|
|
name?: string;
|
|
|
|
/**
|
|
* Category specific URL of a thing
|
|
*
|
|
* @keyword
|
|
*/
|
|
url?: string;
|
|
}
|
|
|
|
/**
|
|
* Meta information about a thing without references that accepts payments
|
|
* It intentionally does not extend the SCThingMeta implementation to be able to include generics.
|
|
*/
|
|
export class SCThingWithCategoriesWithoutReferencesMeta<T, U>
|
|
implements SCMetaTranslations<SCThingWithCategoriesWithoutReferences<T, U>> {
|
|
|
|
/**
|
|
* Instance
|
|
*/
|
|
protected static _instance = new Map<string, unknown>();
|
|
|
|
/**
|
|
* Translations of fields
|
|
*/
|
|
fieldTranslations = {
|
|
de: {
|
|
...SCThingMeta.getInstance<SCThingMeta>().fieldTranslations.de,
|
|
categories: 'Kategorien',
|
|
categorySpecificValues: 'besondere Kategorien',
|
|
},
|
|
en: {
|
|
...SCThingMeta.getInstance<SCThingMeta>().fieldTranslations.en,
|
|
categories: 'categories',
|
|
categorySpecificValues: 'category with specific values',
|
|
},
|
|
};
|
|
|
|
/**
|
|
* Translations of values of fields
|
|
*/
|
|
fieldValueTranslations = {
|
|
de: {
|
|
...SCThingMeta.getInstance<SCThingMeta>().fieldValueTranslations.de,
|
|
},
|
|
en: {
|
|
...SCThingMeta.getInstance<SCThingMeta>().fieldValueTranslations.en,
|
|
},
|
|
};
|
|
|
|
// tslint:disable:static-this
|
|
/**
|
|
* Function to retrieve typed singleton instance (including generics)
|
|
*/
|
|
public static getInstance<T, U>(): SCThingWithCategoriesWithoutReferencesMeta<T, U> {
|
|
if (!SCThingWithCategoriesWithoutReferencesMeta._instance.has(this.name)) {
|
|
SCThingWithCategoriesWithoutReferencesMeta._instance
|
|
.set(this.name, new SCThingWithCategoriesWithoutReferencesMeta<T, U>());
|
|
}
|
|
|
|
return SCThingWithCategoriesWithoutReferencesMeta._instance
|
|
.get(this.name) as SCThingWithCategoriesWithoutReferencesMeta<T, U>;
|
|
}
|
|
|
|
protected constructor() {
|
|
}
|
|
}
|