Cannot set filter in User Manager
Issue #893
resolved
When selecting a filter type, the list of options is not populated in the ‘filter value’ md-select
Comments (3)
-
reporter -
reporter In the end, giving up on a general solution to this problem of getter/setters: the closest is to add this:
public toJSON = () => { // start with the plain object const jsonObj = _.clone((<any>this).plain ? (<any>this).plain() : this); // add all properties const proto = Object.getPrototypeOf(this); for (const key of Object.getOwnPropertyNames(proto)) { const desc = Object.getOwnPropertyDescriptor(proto, key); const hasGetter = desc && typeof desc.get === 'function'; if (hasGetter) { jsonObj[key] = this[key]; } } return jsonObj; }
to
Editable
base class, but then any activity in_beforeSave
is lost.So solution is: whenever a class such as User has a property implemented as a getter/setter that needs to be persisted, set its value in
_beforesave
-
reporter - changed status to resolved
- Log in to comment
Also, it does not save the filter when it is set. This is becuase of issues converting to JSON when the value is a getter/setter.
see
https://stackoverflow.com/questions/42107492/json-stringify-es6-class-property-with-getter-setter
for a discussion. If we really want to use getter/setters for properties, we may need to provide a custom toJSON implementation.
Note that angularjs does quite a bit more than call `JSON.stringify() when sending an object to the server:
see angularjs.js
toJson