gy-foo
Version:
A library that contains all models for the gy-web-project.
237 lines (236 loc) • 8.08 kB
TypeScript
import { Entity } from './entity.model';
import { EntityStructure } from './entityStructure.model';
import { ModeFlags } from '../enums/modeFlags.enum';
import { FieldList } from './fieldList.model';
import { Field, FieldDef } from './field.model';
export declare class Occurrence {
private pk;
private data;
private meta?;
private structure;
private modified;
private locked;
/**
* Creates a new Occrruence
* @param occ An Occrrence object or an object that looks like an Occurence
*/
constructor(occ?: {
pk: string;
structure: EntityStructure;
data?: {
[field: string]: any;
};
meta?: {
[entity: string]: FieldList[];
};
modified?: boolean;
locked?: boolean;
} | Occurrence, modeFlag?: {
add?: boolean;
cpy?: boolean;
del?: boolean;
});
/**
* Converts the SubEntities in data to Entities
* @param data data to convert
* @param structure structure of current occ
* @returns new data object
*/
private convertValues;
/**
* Gets the pk of this Occurrence
*/
getPk(): string;
/**
* Gets the structure of this Occurrence
*/
getStructure(): EntityStructure;
/**
* Gets the value of the given field
* @param field the name of the field
* @returns the value of the field
*/
getValue(field: string): any;
/**
* Returns the Mode of this Occurrence. Possible values are: 'add', 'cpy', 'del' and '';
* @returns returns the mode of the occ (ModeFlags)
*/
getMode(): ModeFlags;
/**
* Gets the data of this Occurence
* @param col get data with or without collections. Default is true (all data).
*/
getData(col?: boolean): object;
/**
* Gets the Subentity from this Occurrence
* @param name the name of the Subentity
* @returns returns the subEntity
*/
getSubEnt(name: string): Entity;
/**
* Gets the Occurences of the given SubEntity
* @param name the name of the Subentity
* @returns data from SubEntity
*/
getCollection(name: string): Occurrence[];
/**
* Gets a list of all fields of this Occurrence
* @param col if true all Subentitys will be included in this list, default false
* @returns returns an array of all field Names
*/
getFields(col?: boolean): string[];
/**
* Has the Occurrence been modified?
* @param checkSubEnt check Subentities (default: true)
*/
isModified(checkSubEnt?: boolean): boolean;
/**
* is this occurence locked and can not be edited?
*/
isLocked(): boolean;
/**
* Gets the structure of the given subentity
* @param name the name of the subentity
*/
getSubEntityStructure(name: string): EntityStructure;
/**
* Gets the Meta informations of this occurence
* @param entity the name of a subentity, whose meta information should be read
*/
getMeta(): {
[entity: string]: FieldList[];
};
/**
* Gets the Meta informations of this occurence for the given entityname
* @param entity the name of a subentity, whose meta information should be read
*/
getMetaFieldList(entity: string): FieldList;
/**
* Gets the Meta information for one field, if given
* @param field the name of the field
* @param entity the name of a subentity, where the field should be looked up
*/
getMetaField(field: string, entity: string): Field | {};
/**
* Sets the _mode value of this Occurrence
* @param mode boolean, that defines the mode. Add if this Occurrence should be added to the Database,
* cpy if this is a Copy of a Occurrrence and del if this Occurrence should be deleted in the DB.
* If missing, the _mode flag will be deleted.
* @param col set the mode for all subentitys.
*/
setMode(mode?: {
add?: boolean;
cpy?: boolean;
del?: boolean;
}, col?: boolean): void;
/**
* sets the pk property
* @param pk pk that should be set
*/
addPk(pk: string): void;
/**
* Sets the given field on the given value
* @param field the name of the field
* @param value the new value
* @param isUserChange is this change a userChange and should set the modified Flag? (default: false)
*/
setValue(field: string, value: any, isUserChange?: boolean): void;
/**
* Sets the given list of fields on the given values
* @param values list of fields and values in the form {fieldname1: value1, fieldname2: value2, ...}
* @param isUserChange is this change a userChange and should set the modified Flag? (default: false)
*/
setValues(values: {
[field: string]: any;
}, isUserChange?: boolean): void;
/**
* Changes all Occurrences of the given Subentity
* @param name name ot the subentity
* @param occs list of the new Occurences
*/
setCollection(name: string, occs: Occurrence[]): void;
/**
* Sets the structure of this Occurrence
* @param value the new value of the structure
*/
setStructure(value: EntityStructure): void;
/**
* Sets the modified flag
* @param modified occ is modified?
* @param setSubEntites should the modified flag be set also in the subentites?
*/
setModified(modified: boolean, setSubEntites?: boolean): void;
/**
* Sets the Meta information for one field
* @param field the name of the field
* @param entity the name of a subentity, where the field should be looked up
* @param value the new value of the definition
*/
setMetaField(field: string, entity: string, value: Field | FieldDef): void;
/**
* Sets the Meta information for one entity
* @param entity the name of a subentity, whose meta information should be set
* @param values the new values of the definition
*/
setMetaFieldList(entity: string, values: FieldList | FieldList[]): void;
/**
* Sets the Meta information
* @param metaValue the new values of the definition
*/
setMeta(metaValue: {
[entity: string]: FieldList[];
}): void;
/**
* Copies the given Occurrence into this Occurrence
* @param occ the Occurrence that should be copied
* @param cpy the Copy mode should be set
* @param isUserChange is this change a userChange and should set the modified Flag? (default: false)
*/
copy(occ: Occurrence, cpy?: boolean, isUserChange?: boolean): void;
/**
* Makes a copy of this Occurrence into a new instance.
* @returns new Occurrence
*/
copyOccFlat(): Occurrence;
/**
* Checks if this Occurrence has the given Subentity
* @param name the name of the Subentity
* @returns true or false
*/
hasCollection(name: string): boolean;
/**
* Checks if the Occ is type OCC or COL
* @returns true or false
*/
hasAnyCollection(): boolean;
/**
* Changes the given Subentity
* @param name the name of the Subentity
* @param SubEnt the new Entity
* @param isUserChange is this a users change (should modified flag been set) (default: false)
*/
changeSubEnt(name: string, SubEnt: Entity, isUserChange?: boolean): void;
/**
* Deletes a Subenetity from this Occurrence
* @param name name of the subentity
*/
deleteSubEnt(name: string): void;
/**
* Deletes a field from this Occurrence
* @param name name of field
*/
deleteValue(name: string): void;
/**
* checks if some subentity is modified
*/
checkSubEntityModified(): boolean;
/**
* Compares this Occurrence with the given Occ. First the PK will be compared and then the hash value.
* @param occ the second occ
*/
equals(occ: Occurrence): boolean;
/**
* Gets a string representation of this Occurrence. This is mainly for debug purpose.
*/
toString(): string;
}