UNPKG

gy-foo

Version:

A library that contains all models for the gy-web-project.

993 lines (978 loc) 36 kB
import { __values, __read, __assign, __spread } from 'tslib'; var IButton = /** @class */ (function () { function IButton(obj) { this.icon = obj.icon ? obj.icon : ''; this.label = obj.label ? obj.label : ''; this.class = obj.class ? obj.class : ''; this.disabled = obj.disabled ? obj.disabled : false; this.tooltip = obj.tooltip ? obj.tooltip : ''; this.tooltipPosition = obj.tooltipPosition ? obj.tooltipPosition : 'bottom'; } return IButton; }()); /** * Save modes for Occurrences */ var ModeFlags; (function (ModeFlags) { /** * Add this new Occurrence to the Entity */ ModeFlags["ADD"] = "add"; /** * This Occurrence is a Copy of another Occurrence */ ModeFlags["CPY"] = "cpy"; /** * Delete this Occurrence from the Entity */ ModeFlags["DEL"] = "del"; })(ModeFlags || (ModeFlags = {})); var FieldRight; (function (FieldRight) { FieldRight["ALL"] = "ALL"; FieldRight["RDO"] = "RDO"; FieldRight["DNY"] = "DNY"; })(FieldRight || (FieldRight = {})); var FieldDisplay; (function (FieldDisplay) { FieldDisplay["INPUT"] = "INP"; FieldDisplay["CALENDAR"] = "CAL"; FieldDisplay["CHECKBOX"] = "CHK"; FieldDisplay["DROPDOWN"] = "DDL"; FieldDisplay["IOV"] = "IOV"; FieldDisplay["RADIOGROUP"] = "RAD"; FieldDisplay["TEXTAREA"] = "TXT"; })(FieldDisplay || (FieldDisplay = {})); var Field = /** @class */ (function () { function Field(field) { var _this = this; if (field) { Object.keys(field).forEach(function (key) { return (_this[key] = field[key]); }); } } Field.prototype.canRead = function (checkType, meta) { var readRights = [FieldRight.RDO, FieldRight.ALL]; return meta && meta[checkType] ? readRights.includes(meta[checkType]) : readRights.includes(this[checkType]); }; Field.prototype.canReadWrite = function (checkType, meta) { return meta && meta[checkType] ? meta[checkType] === FieldRight.ALL : this[checkType] === FieldRight.ALL; }; Field.prototype.displayIOVBez = function () { return this.display === FieldDisplay.IOV && this.iov; }; Field.prototype.isIOVId = function () { return this.iov && this.display !== FieldDisplay.IOV; }; return Field; }()); var Occurrence = /** @class */ (function () { /** * Creates a new Occrruence * @param occ An Occrrence object or an object that looks like an Occurence */ function Occurrence(occ, modeFlag) { if (occ) { if (occ instanceof Occurrence) { this.pk = occ.getPk(); this.structure = occ.getStructure(); this.data = occ.getData() ? this.convertValues(occ.getData(), occ.getStructure()) : {}; this.meta = occ.getMeta() || {}; this.modified = occ.isModified(); this.locked = occ.isLocked(); } else { this.pk = occ.pk; this.structure = occ.structure; this.data = occ.data ? this.convertValues(occ.data, occ.structure) : {}; this.meta = occ.meta || {}; this.modified = occ.modified ? occ.modified : false; this.locked = occ.locked ? occ.locked : false; } } else { this.pk = null; this.data = {}; this.structure = {}; this.meta = {}; this.modified = false; this.locked = false; } this.setMode(modeFlag); } /** * Converts the SubEntities in data to Entities * @param data data to convert * @param structure structure of current occ * @returns new data object */ Occurrence.prototype.convertValues = function (data, structure) { var e_1, _a; try { for (var _b = __values(Object.keys(structure)), _c = _b.next(); !_c.done; _c = _b.next()) { var key = _c.value; var value = data[key.toUpperCase()]; if (value) { data[key.toUpperCase()] = new Entity(value.occs ? value : { occs: value, structure: structure[key.toUpperCase()] }); } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } return data; }; // ------------------------------------------------------------------------------------------------------ // Get Functions // ------------------------------------------------------------------------------------------------------ /** * Gets the pk of this Occurrence */ Occurrence.prototype.getPk = function () { return this.pk; }; /** * Gets the structure of this Occurrence */ Occurrence.prototype.getStructure = function () { return this.structure; }; /** * Gets the value of the given field * @param field the name of the field * @returns the value of the field */ Occurrence.prototype.getValue = function (field) { return this.data[field.toUpperCase()]; }; /** * Returns the Mode of this Occurrence. Possible values are: 'add', 'cpy', 'del' and ''; * @returns returns the mode of the occ (ModeFlags) */ Occurrence.prototype.getMode = function () { return this.data._mode || ''; }; /** * Gets the data of this Occurence * @param col get data with or without collections. Default is true (all data). */ Occurrence.prototype.getData = function (col) { var _this = this; return col === false ? Object.keys(this.data) .filter(function (field) { return !_this.structure[field.toUpperCase()]; }) .reduce(function (prev, field) { var _a; return Object.assign(prev, (_a = {}, _a[field] = _this.data[field], _a)); }, {}) : this.data; }; /** * Gets the Subentity from this Occurrence * @param name the name of the Subentity * @returns returns the subEntity */ Occurrence.prototype.getSubEnt = function (name) { if (!this.hasCollection(name)) { return (this.data[name.toUpperCase()] = new Entity()); } return this.data[name.toUpperCase()]; }; /** * Gets the Occurences of the given SubEntity * @param name the name of the Subentity * @returns data from SubEntity */ Occurrence.prototype.getCollection = function (name) { return this.data[name.toUpperCase()] ? this.data[name.toUpperCase()].occs : []; }; /** * 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 */ Occurrence.prototype.getFields = function (col) { var _this = this; return Object.keys(this.data).filter(function (value) { return col || !_this.structure[value.toUpperCase()]; }); }; /** * Has the Occurrence been modified? * @param checkSubEnt check Subentities (default: true) */ Occurrence.prototype.isModified = function (checkSubEnt) { if (checkSubEnt === void 0) { checkSubEnt = true; } return this.modified || (!checkSubEnt || !this.hasAnyCollection() ? this.modified : this.checkSubEntityModified()); }; /** * is this occurence locked and can not be edited? */ Occurrence.prototype.isLocked = function () { return this.locked; }; /** * Gets the structure of the given subentity * @param name the name of the subentity */ Occurrence.prototype.getSubEntityStructure = function (name) { return this.structure[name.toUpperCase()]; }; /** * Gets the Meta informations of this occurence * @param entity the name of a subentity, whose meta information should be read */ Occurrence.prototype.getMeta = function () { return this.meta; }; /** * Gets the Meta informations of this occurence for the given entityname * @param entity the name of a subentity, whose meta information should be read */ Occurrence.prototype.getMetaFieldList = function (entity) { return this.meta[entity.toUpperCase()] ? this.meta[entity.toUpperCase()].reduce(function (acc, val) { return Object.assign(acc, val); }, {}) || {} : {}; }; /** * 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 */ Occurrence.prototype.getMetaField = function (field, entity) { var fieldname = field.startsWith('_') ? field : field.toUpperCase(); var metaList = this.meta[entity.toUpperCase()] ? this.meta[entity.toUpperCase()].find(function (value) { return fieldname in value; }) : undefined; return metaList ? metaList[fieldname] : {}; }; // ------------------------------------------------------------------------------------------------------ // Set Functions // ------------------------------------------------------------------------------------------------------ /** * 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. */ Occurrence.prototype.setMode = function (mode, col) { var _this = this; if (mode) { if (mode.del) { this.data._mode = ModeFlags.DEL; } else if (mode.cpy) { this.data._mode = ModeFlags.CPY; } else if (mode.add) { this.data._mode = ModeFlags.ADD; } else if (this.data._mode) { delete this.data._mode; } } else if (this.data._mode) { delete this.data._mode; } if (col) { Object.keys(this.structure).forEach(function (subEnt) { if (_this.data.hasOwnProperty(subEnt)) { _this.getCollection(subEnt).forEach(function (occ) { return occ.setMode(mode, col); }); } }); } }; /** * sets the pk property * @param pk pk that should be set */ Occurrence.prototype.addPk = function (pk) { if (this.pk) { return; } this.pk = pk; }; /** * 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) */ Occurrence.prototype.setValue = function (field, value, isUserChange) { if (isUserChange === void 0) { isUserChange = false; } if (isUserChange && this.isLocked()) { return; } if (!field.startsWith('_')) { field = field.toUpperCase(); } var undovalue = this.data[field]; this.data[field] = value; if (isUserChange && undovalue != value) { this.modified = true; } }; /** * 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) */ Occurrence.prototype.setValues = function (values, isUserChange) { var _this = this; if (isUserChange === void 0) { isUserChange = false; } if (!values || (isUserChange && this.isLocked())) { return; } Object.entries(values).forEach(function (_a) { var _b = __read(_a, 2), field = _b[0], value = _b[1]; return _this.setValue(field, value, isUserChange && !_this.modified); }); this.data = this.convertValues(this.data, this.structure); }; /** * Changes all Occurrences of the given Subentity * @param name name ot the subentity * @param occs list of the new Occurences */ Occurrence.prototype.setCollection = function (name, occs) { if (this.hasCollection(name.toUpperCase())) { this.data[name.toUpperCase()].occs = occs; } else if (this.getSubEntityStructure(name)) { this.data[name.toUpperCase()] = new Entity({ occs: occs, structure: this.getSubEntityStructure(name) }); } }; /** * Sets the structure of this Occurrence * @param value the new value of the structure */ Occurrence.prototype.setStructure = function (value) { this.structure = Object.assign(this.structure, value); }; /** * Sets the modified flag * @param modified occ is modified? * @param setSubEntites should the modified flag be set also in the subentites? */ Occurrence.prototype.setModified = function (modified, setSubEntites) { var _this = this; if (setSubEntites === void 0) { setSubEntites = false; } this.modified = modified; if (setSubEntites) { Object.keys(this.structure).forEach(function (entName) { _this.getSubEnt(entName).setModified(modified, setSubEntites); }); } }; /** * 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 */ Occurrence.prototype.setMetaField = function (field, entity, value) { var _a, _b, _c, _d; if (value) { var fldvalue = new Field(value); var fldname_1 = field.toUpperCase(); var entityname = entity.toUpperCase(); if (!this.meta) { this.meta = (_a = {}, _a[entityname] = [(_b = {}, _b[fldname_1] = fldvalue, _b)], _a); } else if (!this.meta[entityname]) { this.meta[entityname] = [(_c = {}, _c[fldname_1] = fldvalue, _c)]; } else { var metaList = this.meta[entityname].find(function (fldlst) { return fldname_1 in fldlst; }); if (!metaList) { this.meta[entityname].push((_d = {}, _d[fldname_1] = fldvalue, _d)); } else { Object.assign(metaList[fldname_1], fldvalue); } } } }; /** * 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 */ Occurrence.prototype.setMetaFieldList = function (entity, values) { var _a; var _this = this; if (values) { var fldlsts = Array.isArray(values) ? values : [values]; var entityname = entity.toUpperCase(); if (!this.meta) { this.meta = (_a = {}, _a[entityname] = fldlsts, _a); } else if (!this.meta[entityname]) { this.meta[entityname] = fldlsts; } else { fldlsts.forEach(function (fldlst) { return Object.entries(fldlst).forEach(function (_a) { var _b = __read(_a, 2), field = _b[0], value = _b[1]; return _this.setMetaField(field, entity, value); }); }); } } }; /** * Sets the Meta information * @param metaValue the new values of the definition */ Occurrence.prototype.setMeta = function (metaValue) { var _this = this; if (metaValue) { if (!this.meta) { this.meta = metaValue; } else { Object.entries(metaValue).forEach(function (_a) { var _b = __read(_a, 2), entity = _b[0], fieldlsts = _b[1]; _this.setMetaFieldList(entity, fieldlsts); }); } } }; // ------------------------------------------------------------------------------------------------------ // Copy Functions // ------------------------------------------------------------------------------------------------------ /** * 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) */ Occurrence.prototype.copy = function (occ, cpy, isUserChange) { if (isUserChange === void 0) { isUserChange = false; } this.pk = occ.pk; this.data = occ.data; this.structure = occ.structure; this.meta = occ.meta; this.modified = isUserChange; this.locked = false; this.setMode({ cpy: cpy }); }; /** * Makes a copy of this Occurrence into a new instance. * @returns new Occurrence */ Occurrence.prototype.copyOccFlat = function () { return new Occurrence({ pk: this.pk, structure: this.structure, meta: this.meta, data: { _pk: this.data._pk, _hash: this.data._hash }, modified: this.modified, }); }; // ------------------------------------------------------------------------------------------------------ // SubEntity/Structure Functions // ------------------------------------------------------------------------------------------------------ /** * Checks if this Occurrence has the given Subentity * @param name the name of the Subentity * @returns true or false */ Occurrence.prototype.hasCollection = function (name) { return this.data[name.toUpperCase()]; }; /** * Checks if the Occ is type OCC or COL * @returns true or false */ Occurrence.prototype.hasAnyCollection = function () { var e_2, _a; try { for (var _b = __values(Object.keys(this.structure)), _c = _b.next(); !_c.done; _c = _b.next()) { var subEnt = _c.value; if (this.data.hasOwnProperty(subEnt)) { return true; } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_2) throw e_2.error; } } return false; }; /** * 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) */ Occurrence.prototype.changeSubEnt = function (name, SubEnt, isUserChange) { if (isUserChange === void 0) { isUserChange = false; } this.data[name.toUpperCase()] = SubEnt; if (isUserChange) { this.getSubEnt(name).setModified(true, false); } }; // ------------------------------------------------------------------------------------------------------ // Delete Functions // ------------------------------------------------------------------------------------------------------ /** * Deletes a Subenetity from this Occurrence * @param name name of the subentity */ Occurrence.prototype.deleteSubEnt = function (name) { delete this.data[name.toUpperCase()]; }; /** * Deletes a field from this Occurrence * @param name name of field */ Occurrence.prototype.deleteValue = function (name) { delete this.data[name.toUpperCase()]; }; // ------------------------------------------------------------------------------------------------------ // Check Functions // ------------------------------------------------------------------------------------------------------ /** * checks if some subentity is modified */ Occurrence.prototype.checkSubEntityModified = function () { var e_3, _a; try { for (var _b = __values(Object.keys(this.structure)), _c = _b.next(); !_c.done; _c = _b.next()) { var entName = _c.value; if (this.hasCollection(entName) && this.getSubEnt(entName).isModified()) { return true; } } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_3) throw e_3.error; } } return false; }; // ------------------------------------------------------------------------------------------------------ // Additional // ------------------------------------------------------------------------------------------------------ /** * Compares this Occurrence with the given Occ. First the PK will be compared and then the hash value. * @param occ the second occ */ Occurrence.prototype.equals = function (occ) { return this.getPk() === occ.getPk() && this.getValue('_hash') === occ.getValue('_hash'); }; /** * Gets a string representation of this Occurrence. This is mainly for debug purpose. */ Occurrence.prototype.toString = function () { return JSON.stringify({ pk: this.pk, _hash: this.data._hash }); }; return Occurrence; }()); var Entity = /** @class */ (function () { function Entity(entity, keepModes) { if (keepModes === void 0) { keepModes = true; } if (entity) { if (entity instanceof Entity) { this.structure = entity.getStructure(); this.occs = this.convertOccurences(entity.getOccs(), keepModes) || []; } else { this.structure = entity.structure; this.occs = this.convertOccurences(entity.occs, keepModes) || []; } } else { this.structure = {}; this.occs = []; } } /** * Checks if entity has the structure of an entity * @param entity entity to check */ Entity.isEntity = function (entity) { return entity && entity.occs ? true : false; }; /** * Gets the number of the Occurrences of this Entity */ Entity.prototype.getOccsLength = function () { return this.occs.length; }; /** * Get all Occurences of this entity. */ Entity.prototype.getOccs = function () { return this.occs; }; /** * Sets all Occurrences of the Entity to the given array. * @param occs array of the new Occurrences */ Entity.prototype.setOccs = function (occs) { this.occs = occs; }; /** * Checks if the given occurence is in this Entity * @param pk the pk of the occurrence */ Entity.prototype.hasOcc = function (pk) { return this.occs.find(function (occ) { return occ.getPk() === pk; }) != null; }; /** * Sets the given Occurence on the given value. If pk is missing, the first Occurrence is set. * @param occ the new Occurrence * @param pk the pk of the Occurrence */ Entity.prototype.setOcc = function (occ, pk) { if (pk) { this.occs = this.occs.map(function (oldOcc) { if (oldOcc.getPk() === pk) { return occ; } else { return oldOcc; } }); } else { this.occs[0] = occ; } }; /** * Gets the Occurrence with the given pk, if no pk is given it gets the first Occurence * @param pk PK of the Occurrence */ Entity.prototype.getOcc = function (pk) { if (pk) { return this.occs.find(function (occ) { return occ.getPk() === pk; }); } else { var occ = void 0; if (this.occs && this.occs.length > 0) { occ = this.occs[0]; } else { occ = new Occurrence(); this.addOcc(occ); } return occ; } }; /** * Gets the structure of the Entity */ Entity.prototype.getStructure = function () { return this.structure; }; /** * Adds an Occurrence to the Entity * @param occ the new Occurrence * @param modeFlag decides, if the add mode should be set for occ * @param isUserChange is that a User Change * @returns the pk of the new Occ */ Entity.prototype.addOcc = function (occ, add, isUserChange) { var addFlag = add !== undefined && add !== null ? add : true; if (!occ) { occ = new Occurrence(); } occ.setMode({ add: addFlag }); if (isUserChange) { occ.setModified(true, false); } if (!occ.getPk()) { var pk = 'new_'; var index_1 = 1; this.occs.forEach(function (occ) { if (occ.getPk().substr(0, 4) === 'new_' && Number(occ.getPk().substr(4)) >= index_1) { index_1 = Number(occ.getPk().substr(4)) + 1; } }); pk += index_1; occ.addPk(pk); } if (!occ.getStructure() || !Object.keys(occ.getStructure()).length) { occ.setStructure(this.structure); } var occIndex = this.occs.findIndex(function (o) { return o.getPk() === occ.getPk(); }); if (occIndex >= 0) { this.occs[occIndex] = occ; } else { this.occs.push(occ); } return occ.getPk(); }; /** * Copys an Occurrence to the Entity * @param pk pk of the occurrence that should be copied * @param modeFlag decides, if the copy mode should be set for the new occ * @param isUserChange is this a User Change? * @returns the pk of the new Occ */ Entity.prototype.copyOcc = function (pk, cpy, isUserChange) { var cpyFlag = cpy !== undefined && cpy !== null ? cpy : true; var occ = this.getOcc(pk); var addFlag = occ.getMode() === 'add'; if (addFlag) { cpyFlag = false; } var copyCount = this.occs.filter(function (o) { return o.getPk().search(new RegExp('^(?:copy_)?' + occ.getPk())) >= 0; }).length; var copyOcc = new Occurrence({ pk: 'copy_' + occ.getPk() + '#' + copyCount, data: __assign({}, occ.getData()), structure: occ.getStructure(), meta: occ.getMeta(), }, { add: addFlag, cpy: cpyFlag }); if (isUserChange) { occ.setModified(true, false); } this.occs.push(copyOcc); return copyOcc.getPk(); }; /** * Adds the Occurrences of an Entity to this Occurrences * @param entity the Entity that should be added */ Entity.prototype.addEntity = function (entity) { var _a; var _this = this; (_a = this.occs).push.apply(_a, __spread(this.convertOccurences(entity.occs).filter(function (occ) { return !_this.hasOcc(occ.getPk()); }))); }; Entity.prototype.convertOccurences = function (occs, keepModes) { var _this = this; if (keepModes === void 0) { keepModes = true; } return occs.map(function (occ) { return occ instanceof Occurrence ? occ : new Occurrence(occ.pk ? occ : { pk: occ._pk, data: occ, structure: _this.structure || {} }, keepModes ? { add: (occ.data != null ? occ.data._mode : occ._mode) === ModeFlags.ADD, cpy: (occ.data != null ? occ.data._mode : occ._mode) === ModeFlags.CPY, del: (occ.data != null ? occ.data._mode : occ._mode) === ModeFlags.DEL, } : null); }); }; /** * Sets the modified flag for all occs in the entity * @param modified occ is modified? * @param setSubEntites should the modified flag be set also in the subentites? (default: false) */ Entity.prototype.setModified = function (modified, setSubEntites) { var e_1, _a; if (setSubEntites === void 0) { setSubEntites = false; } try { for (var _b = __values(this.getOccs()), _c = _b.next(); !_c.done; _c = _b.next()) { var occ = _c.value; occ.setModified(modified, setSubEntites); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } }; /** * Has the Entity been modified? * @param checkSubEnt check Subentities (default: true) */ Entity.prototype.isModified = function (checkSubEnt) { var e_2, _a; if (checkSubEnt === void 0) { checkSubEnt = true; } try { for (var _b = __values(this.getOccs()), _c = _b.next(); !_c.done; _c = _b.next()) { var occ = _c.value; if (occ.isModified(checkSubEnt)) { return true; } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_2) throw e_2.error; } } return false; }; return Entity; }()); var EntityDef = /** @class */ (function () { function EntityDef(entityDef) { if (entityDef instanceof EntityDef) { this.fields = entityDef.getFields(); this.altdef = entityDef.getAltdef(); this.init = entityDef.getInitMode(); } else { this.fields = entityDef ? Object.entries(entityDef.fields) .map(function (_a) { var _b = __read(_a, 2), fldname = _b[0], fld = _b[1]; return [fldname, new Field(fld)]; }) .reduce(function (fields, _a) { var _b; var _c = __read(_a, 2), fldname = _c[0], fld = _c[1]; return Object.assign(fields, (_b = {}, _b[fldname] = fld, _b)); }, {}) : {}; this.altdef = entityDef ? entityDef.altdef || 0 : 0; this.init = entityDef ? entityDef.init || 0 : 0; } } /** * Gets the fields of this Entity Definition */ EntityDef.prototype.getFields = function () { return this.fields; }; /** * Get the given field from this Entity Definition * @param fld the name of the field */ EntityDef.prototype.getField = function (fld) { if (typeof fld === 'string') { return this.fields ? this.fields[fld.toUpperCase()] : undefined; } else { return undefined; } }; /** * Get a list of all fields, that can be seen. * @param type 'lst' for list views (table), 'occ' for detail views, empty for reading without filter * @param write read and write rights are needed * @returns an array with all fields that fits the rigths */ EntityDef.prototype.getFieldList = function (options) { var _this = this; if (this.fields) { var result = Object.entries(this.fields); if (options.type) { var checkType_1 = 'ar_' + options.type; if (options.write) { result = result.filter(function (_a) { var _b = __read(_a, 2), fld = _b[0], field = _b[1]; return _this.canReadWrite(fld, checkType_1, options.meta ? options.meta[fld] : undefined); }); } else { result = result.filter(function (_a) { var _b = __read(_a, 2), fld = _b[0], field = _b[1]; return _this.canRead(fld, checkType_1, options.meta ? options.meta[fld] : undefined); }); } } return result.map(function (_a) { var _b = __read(_a, 2), fld = _b[0], field = _b[1]; var bez = field.bez; if (options.meta && options.meta[fld] && options.meta[fld].bez) { bez = options.meta[fld].bez; } return { fld: fld, bez: bez }; }); } else { return []; } }; /** * Checks if the altdef flag is set. */ EntityDef.prototype.getAltdef = function () { return this.altdef != null ? this.altdef : 0; }; /** * Checks if the init flag is set. */ EntityDef.prototype.getInitMode = function () { return this.init != null ? this.init : 0; }; /** * Checks if the given field can be seen in a list * @param fld the name of the field * @param field an alternative field definition */ EntityDef.prototype.listCanRead = function (fld, field) { return this.canRead(fld, 'ar_lst', field); }; EntityDef.prototype.canRead = function (fld, checkType, field) { var defaultField = this.getField(fld); return defaultField && defaultField.canRead(checkType, field); }; EntityDef.prototype.canReadWrite = function (fld, checkType, field) { var defaultField = this.getField(fld); return defaultField && defaultField.canReadWrite(checkType, field); }; return EntityDef; }()); var ModelsMap = { ENTITY: Entity, OCCURRENCE: Occurrence, ENTITYDEF: EntityDef }; /** * Different types for sending request to the backend */ var AccessTypes; (function (AccessTypes) { /** * List of occurences or Entity */ AccessTypes["LST"] = "lst"; /** * one Occurence without any subentity */ AccessTypes["OCC"] = "occ"; /** * occurence with all the subentites */ AccessTypes["COL"] = "col"; })(AccessTypes || (AccessTypes = {})); /** * modes for reading data */ var ReadModeFlags; (function (ReadModeFlags) { /** * only non-retarded-read fields (default) */ ReadModeFlags["DEF"] = "DEF"; /** * only retarded-read fields */ ReadModeFlags["RET"] = "RET"; /** * all fields */ ReadModeFlags["ALL"] = "ALL"; })(ReadModeFlags || (ReadModeFlags = {})); /* * Public API Surface of gy-models */ /** * Generated bundle index. Do not edit. */ export { AccessTypes, Entity, EntityDef, Field, FieldDisplay, IButton, ModeFlags, ModelsMap, Occurrence, ReadModeFlags }; //# sourceMappingURL=gy-foo.js.map