From 64e3aa18e638b58bda379bbd87db340ca206cd75 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Tue, 13 Feb 2018 10:23:19 +0000 Subject: edited source to comply with linter --- src/serverConfig.ts | 119 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 74 insertions(+), 45 deletions(-) (limited to 'src/serverConfig.ts') diff --git a/src/serverConfig.ts b/src/serverConfig.ts index b10641a..0403b05 100644 --- a/src/serverConfig.ts +++ b/src/serverConfig.ts @@ -1,52 +1,81 @@ -var serverConfig : Property[] = []; +const serverConfig: Property[] = []; /* This is a class used to define the optional attribute of Property, - if the property is user configurable*/ -class PropertyDisplay { - constructor(cat : string, grp : string, dn : string, desc : string) { - this.category = cat; - this.group = grp; - this.display_name = dn; - this.description = desc; - }; - category : string; - group : string; - display_name : string; - description : string; -}; + if the property is user configurable*/ +export class PropertyDisplay { + public category: string; + public group: string; + public displayName: string; + public description: string; -/* This is a class used to contain all of the protocol attributes of a Property - of the current backend server.*/ -class Property { - id : string; - display? : PropertyDisplay; - read_only : boolean; - type : string; - value : string | number | boolean; + public constructor(cat: string, grp: string, dn: string, desc: string) { + this.category = cat; + this.group = grp; + this.displayName = dn; + this.description = desc; + } } -//Logging -var property_display = new PropertyDisplay("Logging", "BE4", "Is logging enabled?", "This property defines if logging is currently enabled on this backend server."); -serverConfig.push({id : "Server_Log", display : property_display, read_only : false, type : "boolean", value : false}); - -//caching settings (global) -serverConfig.push({id : "Global_Cache_Limit", read_only : true, type : "integer", value : 1}); -//caching settings (project level) -property_display = new PropertyDisplay("Caching", "BE4", "Caching Type", "This property defines the current caching style for this project."); -serverConfig.push({id : "project_example", display : property_display, read_only : false, type : "integer", value : 1}); - -function propertyExists (propKey : string): number { - var found = -1; - for (var prop in serverConfig) { - if (serverConfig[prop].id == propKey) { - found = parseInt(prop); - break; - } - } - return found; +/* This is a class used to contain all of the protocol attributes of a Property + of the current backend server.*/ +export interface Property { + id: string; + display?: PropertyDisplay; + readOnly: boolean; + type: string; + value: string | number | boolean; } -module.exports = { - default : serverConfig, - propertyExists : propertyExists, -} +// Logging +let propertyDisplay: PropertyDisplay = new PropertyDisplay( + 'Logging', + 'BE4', + 'Is logging enabled?', + 'This property defines if logging is currently enabled on this backend server.' +); + +serverConfig.push({ + id: 'Server_Log', + display: propertyDisplay, + readOnly: false, + type: 'boolean', + value: false +}); + +// Caching Settings (global) +serverConfig.push({ + id: 'Global_Cache_Limit', + readOnly: true, + type: 'integer', + value: 1 +}); + +// Caching Settings (project level) +propertyDisplay = new PropertyDisplay( + 'Caching', + 'BE4', + 'Caching Type', + 'This property defines the current caching style for this project.' +); + +serverConfig.push({ + id: 'project_example', + display: propertyDisplay, + readOnly: false, + type: 'integer', + value: 1 +}); + +export const propertyExists: (propKey: string) => number = + (propKey: string): number => { + let found: number = -1; + for (const prop in serverConfig) { + if (serverConfig[prop].id === propKey) { + found = parseInt(prop, 10); + break; + } + } + return found; +}; + +export default serverConfig; -- cgit v1.2.1 From 59d745c631debc34a3d2bcf38f26df95d3fed6d5 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Tue, 13 Feb 2018 14:29:29 +0000 Subject: Adding example documentation to serverConfig.ts. --- src/serverConfig.ts | 65 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 4 deletions(-) (limited to 'src/serverConfig.ts') diff --git a/src/serverConfig.ts b/src/serverConfig.ts index b10641a..1ef7c83 100644 --- a/src/serverConfig.ts +++ b/src/serverConfig.ts @@ -1,31 +1,81 @@ var serverConfig : Property[] = []; -/* This is a class used to define the optional attribute of Property, - if the property is user configurable*/ +/** + * A way to display user-configurable properties. + */ class PropertyDisplay { + /** + * Constructs a [[PropertyDisplay]] using its properties. + * + * @param cat The property's category. + * @param grp The property's group. + * @param dn The property's displayable name. + * @param desc A description of the property. + */ constructor(cat : string, grp : string, dn : string, desc : string) { this.category = cat; this.group = grp; this.display_name = dn; this.description = desc; }; + + /** + * The category the property belongs to. + */ category : string; + + /** + * The group the property belongs to. + */ group : string; + + /** + * The name for the property to display to a user. + */ display_name : string; + + /** + * The description of the property. + */ description : string; }; /* This is a class used to contain all of the protocol attributes of a Property of the current backend server.*/ +/** + * A server property that infuences the running of the server. + * Loaded from configs at launch, and possibly editable during run-time. + */ class Property { + /** + * The property's unique ID. + */ id : string; + + /** + * How to display the property to the user. + */ display? : PropertyDisplay; + + /** + * Is the property read-only, or can it be edited at run-time? + */ read_only : boolean; - type : string; + + /** + * The variable type of the property. + * + * These strings represent Javascript types directly, + * except `"integer"`, which is a `number` in logic. + */ + type : "string" | "number" | "integer" | "boolean"; + + /** + * The value of the property. + */ value : string | number | boolean; } -//Logging var property_display = new PropertyDisplay("Logging", "BE4", "Is logging enabled?", "This property defines if logging is currently enabled on this backend server."); serverConfig.push({id : "Server_Log", display : property_display, read_only : false, type : "boolean", value : false}); @@ -35,6 +85,13 @@ serverConfig.push({id : "Global_Cache_Limit", read_only : true, type : "integer" property_display = new PropertyDisplay("Caching", "BE4", "Caching Type", "This property defines the current caching style for this project."); serverConfig.push({id : "project_example", display : property_display, read_only : false, type : "integer", value : 1}); +/** + * Checks if a property exists in the server's property list. + * + * @param propKey The property unique ID to search for. + * @returns The index of the property in the server's property list, + * or `-1` if the property is not present. + */ function propertyExists (propKey : string): number { var found = -1; for (var prop in serverConfig) { -- cgit v1.2.1 From e6bc24399808a64c0c6c2e69def9f08aa2818743 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Tue, 13 Feb 2018 20:05:35 +0000 Subject: Export Property from serverConfig.ts. Whoops. --- src/serverConfig.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/serverConfig.ts') diff --git a/src/serverConfig.ts b/src/serverConfig.ts index 9e75085..ea7b195 100644 --- a/src/serverConfig.ts +++ b/src/serverConfig.ts @@ -44,7 +44,7 @@ class PropertyDisplay { * A server property that infuences the running of the server. * Loaded from configs at launch, and possibly editable during run-time. */ -interface Property { +export interface Property { /** * The property's unique ID. */ -- cgit v1.2.1