Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Orientation } from '@js/common';
import type NotifyScheduler from '@ts/scheduler/base/m_widget_notify_scheduler';
import type NotifyScheduler from '@ts/scheduler/base/widget_notify_scheduler';
import type { TimeZoneCalculator } from '@ts/scheduler/r1/timezone_calculator/calculator';
import type { SafeAppointment } from '@ts/scheduler/types';
import type { AppointmentDataAccessor } from '@ts/scheduler/utils/data_accessor/appointment_data_accessor';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class NotifyScheduler {
funcName: Subject,
...args: Parameters<SubscribeMethods[Subject]>
): ReturnType<SubscribeMethods[Subject]> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return this.scheduler.fire(funcName, ...args);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { AppointmentPopup } from './appointment_popup/m_popup';
import AppointmentCollection from './appointments/m_appointment_collection';
import type { AppointmentsProperties } from './appointments_new/appointments';
import { Appointments } from './appointments_new/appointments';
import NotifyScheduler from './base/m_widget_notify_scheduler';
import NotifyScheduler from './base/widget_notify_scheduler';
import { SchedulerHeader } from './header/header';
import type { HeaderOptions } from './header/types';
import { CompactAppointmentsHelper } from './m_compact_appointments_helper';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,61 @@
import type { DataSource } from '@js/common/data';
import type { DeferredObj } from '@js/core/utils/deferred';
import { Deferred } from '@js/core/utils/deferred';
import type { StoreEventName } from '@js/data/store';

const STORE_EVENTS = {
import type { SafeAppointment } from '../types';

const STORE_EVENTS: Record<string, StoreEventName> = {
updating: 'updating',
push: 'push',
};

interface UpdatedAppointmentKey {
key: string;
value: unknown;
}

export class AppointmentDataSource {
protected updatedAppointmentKeys: any[];
protected updatedAppointmentKeys: UpdatedAppointmentKey[] = [];

protected dataSource: any;
protected dataSource?: DataSource;

protected updatedAppointment: any;
protected updatedAppointment: SafeAppointment | null = null;

constructor(dataSource) {
constructor(dataSource: DataSource) {
this.setDataSource(dataSource);
this.updatedAppointmentKeys = [];
}

get keyName() {
const store = this.dataSource.store();
return store.key();
get keyName(): string {
const store = this.dataSource?.store();
return store?.key() as string;
}

get isDataSourceInit() {
get isDataSourceInit(): boolean {
return Boolean(this.dataSource);
}

private getStoreKey(target) {
const store = this.dataSource.store();
private getStoreKey(target: SafeAppointment): unknown {
const store = this.dataSource?.store();

return store.keyOf(target);
return store?.keyOf(target);
}

setDataSource(dataSource) {
setDataSource(dataSource: DataSource): void {
this.dataSource = dataSource;

this.cleanState();
this.initStoreChangeHandlers();
}

private initStoreChangeHandlers() {
private initStoreChangeHandlers(): void {
const { dataSource } = this;
const store = dataSource?.store();

if (store) {
if (dataSource && store) {
store.on(STORE_EVENTS.updating, (key) => {
const keyName = store.key();
const keyName = store.key() as string;
if (keyName) {
this.updatedAppointmentKeys.push({
key: keyName,
Expand All @@ -58,7 +68,7 @@ export class AppointmentDataSource {

store.on(STORE_EVENTS.push, (pushItems) => {
const items = dataSource.items();
const keyName = store.key();
const keyName = store.key() as string;

pushItems.forEach((pushItem) => {
const itemExists = items.filter((item) => item[keyName] === pushItem.key).length !== 0;
Expand All @@ -70,52 +80,62 @@ export class AppointmentDataSource {
});
} else {
const { data } = pushItem;
data && items.push(data);
if (data) {
items.push(data);
}
}
});

// eslint-disable-next-line @typescript-eslint/no-floating-promises
dataSource.load();
});
}
}

getUpdatedAppointment() {
getUpdatedAppointment(): SafeAppointment | null {
return this.updatedAppointment;
}

getUpdatedAppointmentKeys() {
getUpdatedAppointmentKeys(): UpdatedAppointmentKey[] {
return this.updatedAppointmentKeys;
}

cleanState() {
cleanState(): void {
this.updatedAppointment = null;
this.updatedAppointmentKeys = [];
}

add(rawAppointment) {
return this.dataSource.store().insert(rawAppointment).done(() => this.dataSource.load());
add(rawAppointment: SafeAppointment): DeferredObj<SafeAppointment> {
// @eslint-disable-next-line
return this.dataSource!.store().insert(rawAppointment)
// @ts-expect-error
.done(() => this.dataSource.load());
}

update(target, data) {
update(target: SafeAppointment, data: SafeAppointment): DeferredObj<SafeAppointment | undefined> {
const key = this.getStoreKey(target);
// @ts-expect-error
const d = new Deferred();

this.dataSource.store().update(key, data)
this.dataSource!.store().update(key, data)
// @ts-expect-error
.done((result) => this.dataSource.load()
// @ts-expect-error
.done(() => d.resolve(result))
.fail(d.reject))
.fail(d.reject);

return d.promise();
}

remove(rawAppointment) {
remove(rawAppointment: SafeAppointment): DeferredObj<SafeAppointment | undefined> {
const key = this.getStoreKey(rawAppointment);
return this.dataSource.store().remove(key).done(() => this.dataSource.load());
return this.dataSource!.store().remove(key)
// @ts-expect-error
.done(() => this.dataSource.load());
}

destroy() {
destroy(): void {
const store = this.dataSource?.store();

if (store) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import {
import type { ViewType } from '@ts/scheduler/types';
import Scrollable from '@ts/ui/scroll_view/scrollable';

import type NotifyScheduler from '../base/m_widget_notify_scheduler';
import type NotifyScheduler from '../base/widget_notify_scheduler';
import { APPOINTMENT_SETTINGS_KEY } from '../constants';
import { Cache } from '../global_cache';
import AppointmentDragBehavior from '../m_appointment_drag_behavior';
Expand Down
Loading