diff --git a/.idea/cssdialects.xml b/.idea/cssdialects.xml
deleted file mode 100644
index 67d0d0e99..000000000
--- a/.idea/cssdialects.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/resources/js/Models/Model.ts b/resources/js/Models/Model.ts
index cf23e13db..3dc4afd72 100644
--- a/resources/js/Models/Model.ts
+++ b/resources/js/Models/Model.ts
@@ -4,8 +4,13 @@ import {
} from 'coloquent';
import {snakeCase} from 'lodash-es';
+import {
+ hasGetter,
+ hasSetter
+} from '../utils';
+
export interface InstantiableModel {
- new (): (Model | T) & {[prop: string]: any};
+ new(): (Model | T) & {[prop: string]: any};
}
export type IModel = InstanceType>;
@@ -24,6 +29,10 @@ export abstract class Model extends BaseModel {
// eslint-disable-next-line no-constructor-return
return new Proxy(this, {
get(target, property: string, receiver): any {
+ if (hasGetter(target, property)) {
+ return Reflect.get(target, property, receiver);
+ }
+
const snakeCasedProperty = snakeCase(property);
if (snakeCasedProperty in target.getAttributes()) {
return target.getAttribute(snakeCasedProperty);
@@ -32,6 +41,10 @@ export abstract class Model extends BaseModel {
return Reflect.get(target, property, receiver);
},
set(target, property: string, value) {
+ if (hasSetter(target, property)) {
+ return Reflect.set(target, property, value);
+ }
+
target.setAttribute(snakeCase(property), value);
return true;
}
diff --git a/resources/js/utils.ts b/resources/js/utils.ts
index 66d098833..316fef270 100644
--- a/resources/js/utils.ts
+++ b/resources/js/utils.ts
@@ -1,4 +1,5 @@
// noinspection JSUnusedGlobalSymbols
+
import '@material/mwc-snackbar';
import 'mithril';
@@ -7,6 +8,7 @@ import type {Vnode} from 'mithril';
import {sync as render} from 'mithril-node-render';
type GenericObject = object & {prototype: any};
+
/**
* Check if class/object A is the same as or a subclass of class B.
*/
@@ -44,12 +46,12 @@ export async function showSnackbar(
if (closeOtherSnackbars) {
const snackbars = document.querySelectorAll('mwc-snackbar');
- for (const snackbar of snackbars) {
- if (snackbar.open) {
- snackbar.close();
+ for (const snackbar1 of snackbars) {
+ if (snackbar1.open) {
+ snackbar1.close();
}
- snackbar.remove();
+ snackbar1.remove();
}
}
@@ -120,8 +122,6 @@ type ReplaceObject = Record;
* @param {Object|boolean} replace Eventuali parametri da rimpiazzare.
* Se il parametro è "true" (valore booleano), verrà ritornato il valore come stringa
* (stesso funzionamento del parametro dedicato (sotto ↓))
- * @param {boolean} returnAsString Se impostato a "true" vien ritornata una stringa invece di
- * un Vnode di Mithril
*
* @returns {string} Stringa se non contiene HTML, altrimenti Vnode
*
@@ -147,3 +147,15 @@ export function __(key: string, replace: ReplaceObject = {}): string {
return translation;
}
+
+export function getPropertyDescriptor(object: object, property: string) {
+ return Object.getOwnPropertyDescriptor(Object.getPrototypeOf(object), property);
+}
+
+export function hasGetter(object: object, property: string): boolean {
+ return getPropertyDescriptor(object, property)?.get !== undefined;
+}
+
+export function hasSetter(object: object, property: string): boolean {
+ return getPropertyDescriptor(object, property)?.set !== undefined;
+}