mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 00:23:03 +00:00
183
src/things/setting.ts
Normal file
183
src/things/setting.ts
Normal file
@@ -0,0 +1,183 @@
|
||||
/*
|
||||
* 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 {SCThing, SCThingMeta, SCThingType} from './abstract/thing';
|
||||
import {
|
||||
SCThingWithCategories,
|
||||
SCThingWithCategoriesSpecificValues,
|
||||
SCThingWithCategoriesTranslatableProperties,
|
||||
SCThingWithCategoriesWithoutReferences,
|
||||
SCThingWithCategoriesWithoutReferencesMeta,
|
||||
} from './abstract/thing-with-categories';
|
||||
|
||||
/**
|
||||
* A setting without references
|
||||
*/
|
||||
export interface SCSettingWithoutReferences
|
||||
extends SCThingWithCategoriesWithoutReferences<SCSettingCategories, SCThingWithCategoriesSpecificValues> {
|
||||
/**
|
||||
* Categories of a setting
|
||||
*/
|
||||
categories: SCSettingCategories[];
|
||||
/**
|
||||
* The default value of a setting
|
||||
*/
|
||||
defaultValue: SCSettingValue | SCSettingValues;
|
||||
/**
|
||||
* The input type of this setting
|
||||
*/
|
||||
inputType: SCSettingInputType;
|
||||
/**
|
||||
* The order number this setting should show up in its category list
|
||||
*
|
||||
* @integer
|
||||
*/
|
||||
order: number;
|
||||
/**
|
||||
* Translated fields of a setting
|
||||
*/
|
||||
translations?: SCTranslations<SCSettingValueTranslatableProperties>;
|
||||
/**
|
||||
* The type of this model
|
||||
*/
|
||||
type: SCThingType.Setting;
|
||||
/**
|
||||
* The key of a value of a setting
|
||||
*/
|
||||
value?: SCSettingValue | SCSettingValues;
|
||||
/**
|
||||
* The possible values of a setting
|
||||
*/
|
||||
values?: SCSettingValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of categories for settings
|
||||
*/
|
||||
export type SCSettingCategories =
|
||||
'profile'
|
||||
| 'privacy'
|
||||
| 'credentials'
|
||||
| 'others';
|
||||
|
||||
/**
|
||||
* The types of input/value a setting object can carry
|
||||
*/
|
||||
export enum SCSettingInputType {
|
||||
SingleChoice = 'single choice',
|
||||
MultipleChoice = 'multiple choice',
|
||||
Number = 'number',
|
||||
Text = 'text',
|
||||
Password = 'password',
|
||||
}
|
||||
|
||||
/**
|
||||
* A setting with references
|
||||
*
|
||||
* @validatable
|
||||
* @indexable
|
||||
*/
|
||||
export interface SCSetting
|
||||
extends SCSettingWithoutReferences, SCThing,
|
||||
SCThingWithCategories<SCSettingCategories, SCThingWithCategoriesSpecificValues> {
|
||||
/**
|
||||
* Translated fields of a setting
|
||||
*/
|
||||
translations?: SCTranslations<SCSettingValueTranslatableProperties>;
|
||||
/**
|
||||
* The type of this model
|
||||
*/
|
||||
type: SCThingType.Setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* The type a value of a setting can have
|
||||
*/
|
||||
export type SCSettingValue = string | number | boolean;
|
||||
|
||||
/**
|
||||
* The type of multiple values a setting can have
|
||||
*/
|
||||
export type SCSettingValues = SCSettingValue[];
|
||||
|
||||
/**
|
||||
* Translatable properties of a setting
|
||||
*/
|
||||
export interface SCSettingValueTranslatableProperties extends SCThingWithCategoriesTranslatableProperties {
|
||||
/**
|
||||
* The translations of the possible values of a setting
|
||||
*
|
||||
* @keyword
|
||||
*/
|
||||
values?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Meta information about settings
|
||||
*/
|
||||
export class SCSettingMeta extends SCThingMeta implements SCMetaTranslations<SCSetting> {
|
||||
/**
|
||||
* Translations of fields
|
||||
*/
|
||||
fieldTranslations = {
|
||||
de: {
|
||||
...SCThingWithCategoriesWithoutReferencesMeta.getInstance<SCSettingCategories,
|
||||
SCThingWithCategoriesSpecificValues>().fieldTranslations.de,
|
||||
defaultValue: 'Standard Wert',
|
||||
inputType: 'Eingabetyp',
|
||||
order: 'Position',
|
||||
value: 'Wert',
|
||||
values: 'Werte',
|
||||
},
|
||||
en: {
|
||||
...SCThingWithCategoriesWithoutReferencesMeta.getInstance<SCSettingCategories,
|
||||
SCThingWithCategoriesSpecificValues>().fieldTranslations.en,
|
||||
defaultValue: 'default value',
|
||||
inputType: 'input type',
|
||||
order: 'position',
|
||||
value: 'value',
|
||||
values: 'values',
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Translations of values of fields
|
||||
*/
|
||||
fieldValueTranslations = {
|
||||
de: {
|
||||
...SCThingWithCategoriesWithoutReferencesMeta.getInstance<SCSettingCategories,
|
||||
SCThingWithCategoriesSpecificValues>().fieldValueTranslations.de,
|
||||
categories: {
|
||||
credentials: 'Anmeldedaten',
|
||||
others: 'Andere',
|
||||
privacy: 'Privatsphäre',
|
||||
profile: 'Profil',
|
||||
},
|
||||
inputType: {
|
||||
'multiple choice': 'mehrfach Auswahl',
|
||||
number: 'Zahl',
|
||||
password: 'Passwort',
|
||||
'single choice': 'einfache Auswahl',
|
||||
text: 'Text',
|
||||
},
|
||||
type: 'Einstellung',
|
||||
},
|
||||
en: {
|
||||
...SCThingWithCategoriesWithoutReferencesMeta.getInstance<SCSettingCategories,
|
||||
SCThingWithCategoriesSpecificValues>().fieldValueTranslations.en,
|
||||
type: SCThingType.Setting,
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user