refactor: ♻️ Refactor generale

This commit is contained in:
Maicol Battistini 2023-06-26 10:15:46 +02:00
parent 28261ac889
commit 0c213c8aed
No known key found for this signature in database
3 changed files with 8 additions and 15 deletions

View File

@ -210,12 +210,6 @@
<inspection_tool class="IfStatementWithTooManyBranchesJS" enabled="true" level="WARNING" enabled_by_default="true">
<option name="m_limit" value="3" />
</inspection_tool>
<inspection_tool class="IgnoreCoverEntry" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="IgnoreDuplicateEntry" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="IgnoreIncorrectEntry" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="IgnoreRelativeEntry" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="IgnoreSyntaxEntry" enabled="false" level="ERROR" enabled_by_default="false" />
<inspection_tool class="IgnoreUnusedEntry" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="InconsistentLineSeparators" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="IncrementDecrementResultUsedJS" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="InvertedIfElseConstructsInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />

View File

@ -4,6 +4,7 @@ import {mdiChevronLeft} from '@mdi/js';
import MdIcon from '@osm/Components/MdIcon';
import Page, {PageAttributes} from '@osm/Components/Page';
import Model from '@osm/Models/Model';
import {showSnackbar} from '@osm/utils/misc';
import {Builder} from 'coloquent';
import {
Children,
@ -20,14 +21,8 @@ export default abstract class RecordPage<M extends Model<any, any>, A extends Re
abstract recordType: Class<M> & typeof Model<any, any>;
record?: M;
public oninit(vnode: Vnode<A, this>): void {
async oninit(vnode: Vnode<A, this>) {
super.oninit(vnode);
m.redraw();
}
async onbeforeupdate(vnode: VnodeDOM<A, this>) {
super.onbeforeupdate(vnode);
const {id: recordId} = route().params as {id: number | string};
if (recordId !== this.record?.getId()) {
await this.loadRecord(recordId);
@ -39,7 +34,9 @@ export default abstract class RecordPage<M extends Model<any, any>, A extends Re
try {
const response = await this.modelQuery().find(recordId);
this.record = response.getData() || undefined;
} catch {
} catch (e) {
console.error(e);
void showSnackbar(__('Errore durante il caricamento del record'));
// Do nothing
}
}

View File

@ -103,6 +103,7 @@ export default abstract class RecordsPage<
}
modelQuery() {
// @ts-ignore
let query = this.modelType.query<M>();
for (const [attribute, value] of this.filters) {
@ -323,8 +324,9 @@ export default abstract class RecordsPage<
return this.recordDialogsStates.get(key)!;
}
protected cellValueModifier(value: unknown, attribute: string, record: M): Match<string, unknown> {
protected cellValueModifier(value: unknown, attribute: string, record: M): Match<string, unknown, string[], string> {
return match(attribute)
.returnType()
.with('createdAt', 'updatedAt', () => dayjs(value as Date).format('DD/MM/YYYY HH:mm'));
}
}