From 077d4bed37ad6d27ee5c274720b99a974d7a8efa Mon Sep 17 00:00:00 2001 From: Arthur Deierlein Date: Wed, 4 Sep 2024 18:29:16 +0200 Subject: [PATCH] draft: stuff --- frontend/app/models/absence-balance.js | 12 ----- frontend/app/models/absence-balance.ts | 47 +++++++++++++++++++ .../{absence-credit.js => absence-credit.ts} | 30 ++++++++++++ .../{absence-type.js => absence-type.ts} | 23 +++++++++ .../app/models/{absence.js => absence.ts} | 26 ++++++++++ .../app/models/{activity.js => activity.ts} | 14 ++++++ .../models/{attendance.js => attendance.ts} | 0 .../{billing-type.js => billing-type.ts} | 0 .../models/{cost-center.js => cost-center.ts} | 0 ...tomer-assignee.js => customer-assignee.ts} | 0 ...mer-statistic.js => customer-statistic.ts} | 0 .../app/models/{customer.js => customer.ts} | 0 .../models/{employment.js => employment.ts} | 0 .../app/models/{location.js => location.ts} | 0 ...{month-statistic.js => month-statistic.ts} | 0 ...{overtime-credit.js => overtime-credit.ts} | 0 ...roject-assignee.js => project-assignee.ts} | 0 ...ject-statistic.js => project-statistic.ts} | 0 .../app/models/{project.js => project.ts} | 0 .../{public-holiday.js => public-holiday.ts} | 0 ...intersection.js => report-intersection.ts} | 0 frontend/app/models/{report.js => report.ts} | 0 .../{task-assignee.js => task-assignee.ts} | 0 .../{task-statistic.js => task-statistic.ts} | 0 frontend/app/models/{task.js => task.ts} | 0 .../{user-statistic.js => user-statistic.ts} | 0 frontend/app/models/{user.js => user.ts} | 0 ...orktime-balance.js => worktime-balance.ts} | 0 .../{year-statistic.js => year-statistic.ts} | 0 .../{django-date.js => django-date.ts} | 8 +++- ...{django-datetime.js => django-datetime.ts} | 8 +++- ...{django-duration.js => django-duration.ts} | 10 +++- .../{django-time.js => django-time.ts} | 6 +++ ...{django-workdays.js => django-workdays.ts} | 20 ++++---- .../app/transforms/{moment.js => moment.ts} | 22 ++++----- frontend/tsconfig.json | 1 + 36 files changed, 186 insertions(+), 41 deletions(-) delete mode 100644 frontend/app/models/absence-balance.js create mode 100644 frontend/app/models/absence-balance.ts rename frontend/app/models/{absence-credit.js => absence-credit.ts} (58%) rename frontend/app/models/{absence-type.js => absence-type.ts} (60%) rename frontend/app/models/{absence.js => absence.ts} (55%) rename frontend/app/models/{activity.js => activity.ts} (90%) rename frontend/app/models/{attendance.js => attendance.ts} (100%) rename frontend/app/models/{billing-type.js => billing-type.ts} (100%) rename frontend/app/models/{cost-center.js => cost-center.ts} (100%) rename frontend/app/models/{customer-assignee.js => customer-assignee.ts} (100%) rename frontend/app/models/{customer-statistic.js => customer-statistic.ts} (100%) rename frontend/app/models/{customer.js => customer.ts} (100%) rename frontend/app/models/{employment.js => employment.ts} (100%) rename frontend/app/models/{location.js => location.ts} (100%) rename frontend/app/models/{month-statistic.js => month-statistic.ts} (100%) rename frontend/app/models/{overtime-credit.js => overtime-credit.ts} (100%) rename frontend/app/models/{project-assignee.js => project-assignee.ts} (100%) rename frontend/app/models/{project-statistic.js => project-statistic.ts} (100%) rename frontend/app/models/{project.js => project.ts} (100%) rename frontend/app/models/{public-holiday.js => public-holiday.ts} (100%) rename frontend/app/models/{report-intersection.js => report-intersection.ts} (100%) rename frontend/app/models/{report.js => report.ts} (100%) rename frontend/app/models/{task-assignee.js => task-assignee.ts} (100%) rename frontend/app/models/{task-statistic.js => task-statistic.ts} (100%) rename frontend/app/models/{task.js => task.ts} (100%) rename frontend/app/models/{user-statistic.js => user-statistic.ts} (100%) rename frontend/app/models/{user.js => user.ts} (100%) rename frontend/app/models/{worktime-balance.js => worktime-balance.ts} (100%) rename frontend/app/models/{year-statistic.js => year-statistic.ts} (100%) rename frontend/app/transforms/{django-date.js => django-date.ts} (66%) rename frontend/app/transforms/{django-datetime.js => django-datetime.ts} (65%) rename frontend/app/transforms/{django-duration.js => django-duration.ts} (90%) rename frontend/app/transforms/{django-time.js => django-time.ts} (72%) rename frontend/app/transforms/{django-workdays.js => django-workdays.ts} (63%) rename frontend/app/transforms/{moment.js => moment.ts} (64%) diff --git a/frontend/app/models/absence-balance.js b/frontend/app/models/absence-balance.js deleted file mode 100644 index ad425b658..000000000 --- a/frontend/app/models/absence-balance.js +++ /dev/null @@ -1,12 +0,0 @@ -import Model, { attr, belongsTo, hasMany } from "@ember-data/model"; - -export default class AbsenceBalance extends Model { - @attr("number") credit; - @attr("number") usedDays; - @attr("django-duration") usedDuration; - @attr("number") balance; - @belongsTo("user", { async: false, inverse: "absenceBalances" }) user; - @belongsTo("absence-type", { async: false, inverse: "absenceBalances" }) - absenceType; - @hasMany("absence-credit", { async: true, inverse: null }) absenceCredits; -} diff --git a/frontend/app/models/absence-balance.ts b/frontend/app/models/absence-balance.ts new file mode 100644 index 000000000..029e35c65 --- /dev/null +++ b/frontend/app/models/absence-balance.ts @@ -0,0 +1,47 @@ +<<<<<<< HEAD +import Model, { + attr, + belongsTo, + hasMany, + type AsyncHasMany, +} from "@ember-data/model"; +import type { Duration } from "moment"; + +import type AbsenceCredit from "./absence-credit"; +import type AbsenceType from "./absence-type"; +import type User from "./user"; +======= +import Model, { attr, belongsTo, hasMany } from "@ember-data/model"; +>>>>>>> 5c1741fc (cheklflasdjf) + +export default class AbsenceBalance extends Model { + @attr("number") + declare credit: number; + + @attr("number") + declare usedDays: number; + +<<<<<<< HEAD + @attr("django-duration") + declare usedDuration: Duration; + + @attr("number") + declare balance: number; + + @belongsTo("user", { async: false, inverse: "absenceBalances" }) + declare user: User; + + @belongsTo("absence-type", { async: false, inverse: "absenceBalances" }) + declare absenceType: AbsenceType; + + @hasMany("absence-credit", { async: true, inverse: null }) + declare absenceCredits: AsyncHasMany; +======= + @attr("django-duration") usedDuration; + @attr("number") balance; + @belongsTo("user", { async: false, inverse: "absenceBalances" }) user; + @belongsTo("absence-type", { async: false, inverse: "absenceBalances" }) + absenceType; + @hasMany("absence-credit", { async: true, inverse: null }) absenceCredits; +>>>>>>> 5c1741fc (cheklflasdjf) +} diff --git a/frontend/app/models/absence-credit.js b/frontend/app/models/absence-credit.ts similarity index 58% rename from frontend/app/models/absence-credit.js rename to frontend/app/models/absence-credit.ts index 417c3960c..8921490e1 100644 --- a/frontend/app/models/absence-credit.js +++ b/frontend/app/models/absence-credit.ts @@ -4,6 +4,13 @@ * @public */ import Model, { attr, belongsTo } from "@ember-data/model"; +<<<<<<< HEAD +import type { Moment } from "moment"; + +import type AbsenceType from "./absence-type"; +import type User from "./user"; +======= +>>>>>>> 5c1741fc (cheklflasdjf) /** * The absence credit model @@ -13,6 +20,28 @@ import Model, { attr, belongsTo } from "@ember-data/model"; * @public */ export default class AbsenceCredit extends Model { +<<<<<<< HEAD + @attr("number") + declare days: number; + + @attr("django-date") + declare date: Moment; + + @attr("string", { defaultValue: "" }) + declare comment: string; + + /** + * The absence type for which this credit counts + */ + @belongsTo("absence-type", { async: false, inverse: null }) + declare absenceType: AbsenceType; + + /** + * The user to which this credit belongs to + */ + @belongsTo("user", { async: false, inverse: null }) + declare user: User; +======= /** * The days * @@ -52,4 +81,5 @@ export default class AbsenceCredit extends Model { * @public */ @belongsTo("user", { async: false, inverse: null }) user; +>>>>>>> 5c1741fc (cheklflasdjf) } diff --git a/frontend/app/models/absence-type.js b/frontend/app/models/absence-type.ts similarity index 60% rename from frontend/app/models/absence-type.js rename to frontend/app/models/absence-type.ts index 21b97249e..edce18f89 100644 --- a/frontend/app/models/absence-type.js +++ b/frontend/app/models/absence-type.ts @@ -3,6 +3,12 @@ * @submodule timed-models * @public */ +<<<<<<< HEAD +import Model, { attr, hasMany, type AsyncHasMany } from "@ember-data/model"; + +import type AbsenceBalance from "./absence-balance"; + +======= import Model, { attr, hasMany } from "@ember-data/model"; /** @@ -12,11 +18,23 @@ import Model, { attr, hasMany } from "@ember-data/model"; * @extends DS.Model * @public */ +>>>>>>> 5c1741fc (cheklflasdjf) export default class AbsenceType extends Model { /** * The name of the absence type * * E.g Military, Holiday or Sickness +<<<<<<< HEAD + */ + @attr("string") + declare name: string; + + /** + * Whether the absence type only fills the worktime + */ + @attr("boolean") + declare fillWorktime: boolean; +======= * * @property {String} name * @public @@ -30,6 +48,7 @@ export default class AbsenceType extends Model { * @public */ @attr("boolean") fillWorktime; +>>>>>>> 5c1741fc (cheklflasdjf) /** * The balances for this type @@ -38,5 +57,9 @@ export default class AbsenceType extends Model { * @public */ @hasMany("absence-balance", { async: true, inverse: "absenceType" }) +<<<<<<< HEAD + declare absenceBalances: AsyncHasMany; +======= absenceBalances; +>>>>>>> 5c1741fc (cheklflasdjf) } diff --git a/frontend/app/models/absence.js b/frontend/app/models/absence.ts similarity index 55% rename from frontend/app/models/absence.js rename to frontend/app/models/absence.ts index 630f1b91c..2ea5c1f67 100644 --- a/frontend/app/models/absence.js +++ b/frontend/app/models/absence.ts @@ -3,6 +3,20 @@ * @submodule timed-models * @public */ +<<<<<<< HEAD +import Model, { attr, belongsTo, type AsyncBelongsTo } from "@ember-data/model"; +import moment, { type Duration, type Moment } from "moment"; + +import type AbsenceType from "./absence-type"; +import type User from "./user"; + +export default class Absence extends Model { + @attr("string", { defaultValue: "" }) + declare comment: string; + + @attr("django-duration", { defaultValue: () => moment.duration() }) + declare duration: Duration; +======= import Model, { attr, belongsTo } from "@ember-data/model"; import moment from "moment"; @@ -29,6 +43,7 @@ export default class Absence extends Model { * @public */ @attr("django-duration", { defaultValue: () => moment.duration() }) duration; +>>>>>>> 5c1741fc (cheklflasdjf) /** * The date @@ -36,6 +51,16 @@ export default class Absence extends Model { * @property {moment} date * @public */ +<<<<<<< HEAD + @attr("django-date") + declare date: Moment; + + @belongsTo("absence-type", { async: false, inverse: null }) + declare absenceType: AbsenceType; + + @belongsTo("user", { async: true, inverse: null }) + declare user: AsyncBelongsTo; +======= @attr("django-date") date; /** @@ -53,4 +78,5 @@ export default class Absence extends Model { * @public */ @belongsTo("user", { async: true, inverse: null }) user; +>>>>>>> 5c1741fc (cheklflasdjf) } diff --git a/frontend/app/models/activity.js b/frontend/app/models/activity.ts similarity index 90% rename from frontend/app/models/activity.js rename to frontend/app/models/activity.ts index e92782c43..c9fae16fd 100644 --- a/frontend/app/models/activity.js +++ b/frontend/app/models/activity.ts @@ -1,5 +1,18 @@ import { service } from "@ember/service"; import Model, { attr, belongsTo } from "@ember-data/model"; +<<<<<<< HEAD +import moment, { type Moment } from "moment"; +import { all } from "rsvp"; + +export default class Activity extends Model { + @attr("django-time") + declare fromTime: Moment; + @attr("django-time") + declare toTime: Moment; + + @attr("string", { defaultValue: "" }) comment; + +======= import moment from "moment"; import { all } from "rsvp"; @@ -7,6 +20,7 @@ export default class Activity extends Model { @attr("django-time") fromTime; @attr("django-time") toTime; @attr("string", { defaultValue: "" }) comment; +>>>>>>> 5c1741fc (cheklflasdjf) @attr("django-date") date; @attr("boolean", { defaultValue: false }) transferred; @attr("boolean", { defaultValue: false }) review; diff --git a/frontend/app/models/attendance.js b/frontend/app/models/attendance.ts similarity index 100% rename from frontend/app/models/attendance.js rename to frontend/app/models/attendance.ts diff --git a/frontend/app/models/billing-type.js b/frontend/app/models/billing-type.ts similarity index 100% rename from frontend/app/models/billing-type.js rename to frontend/app/models/billing-type.ts diff --git a/frontend/app/models/cost-center.js b/frontend/app/models/cost-center.ts similarity index 100% rename from frontend/app/models/cost-center.js rename to frontend/app/models/cost-center.ts diff --git a/frontend/app/models/customer-assignee.js b/frontend/app/models/customer-assignee.ts similarity index 100% rename from frontend/app/models/customer-assignee.js rename to frontend/app/models/customer-assignee.ts diff --git a/frontend/app/models/customer-statistic.js b/frontend/app/models/customer-statistic.ts similarity index 100% rename from frontend/app/models/customer-statistic.js rename to frontend/app/models/customer-statistic.ts diff --git a/frontend/app/models/customer.js b/frontend/app/models/customer.ts similarity index 100% rename from frontend/app/models/customer.js rename to frontend/app/models/customer.ts diff --git a/frontend/app/models/employment.js b/frontend/app/models/employment.ts similarity index 100% rename from frontend/app/models/employment.js rename to frontend/app/models/employment.ts diff --git a/frontend/app/models/location.js b/frontend/app/models/location.ts similarity index 100% rename from frontend/app/models/location.js rename to frontend/app/models/location.ts diff --git a/frontend/app/models/month-statistic.js b/frontend/app/models/month-statistic.ts similarity index 100% rename from frontend/app/models/month-statistic.js rename to frontend/app/models/month-statistic.ts diff --git a/frontend/app/models/overtime-credit.js b/frontend/app/models/overtime-credit.ts similarity index 100% rename from frontend/app/models/overtime-credit.js rename to frontend/app/models/overtime-credit.ts diff --git a/frontend/app/models/project-assignee.js b/frontend/app/models/project-assignee.ts similarity index 100% rename from frontend/app/models/project-assignee.js rename to frontend/app/models/project-assignee.ts diff --git a/frontend/app/models/project-statistic.js b/frontend/app/models/project-statistic.ts similarity index 100% rename from frontend/app/models/project-statistic.js rename to frontend/app/models/project-statistic.ts diff --git a/frontend/app/models/project.js b/frontend/app/models/project.ts similarity index 100% rename from frontend/app/models/project.js rename to frontend/app/models/project.ts diff --git a/frontend/app/models/public-holiday.js b/frontend/app/models/public-holiday.ts similarity index 100% rename from frontend/app/models/public-holiday.js rename to frontend/app/models/public-holiday.ts diff --git a/frontend/app/models/report-intersection.js b/frontend/app/models/report-intersection.ts similarity index 100% rename from frontend/app/models/report-intersection.js rename to frontend/app/models/report-intersection.ts diff --git a/frontend/app/models/report.js b/frontend/app/models/report.ts similarity index 100% rename from frontend/app/models/report.js rename to frontend/app/models/report.ts diff --git a/frontend/app/models/task-assignee.js b/frontend/app/models/task-assignee.ts similarity index 100% rename from frontend/app/models/task-assignee.js rename to frontend/app/models/task-assignee.ts diff --git a/frontend/app/models/task-statistic.js b/frontend/app/models/task-statistic.ts similarity index 100% rename from frontend/app/models/task-statistic.js rename to frontend/app/models/task-statistic.ts diff --git a/frontend/app/models/task.js b/frontend/app/models/task.ts similarity index 100% rename from frontend/app/models/task.js rename to frontend/app/models/task.ts diff --git a/frontend/app/models/user-statistic.js b/frontend/app/models/user-statistic.ts similarity index 100% rename from frontend/app/models/user-statistic.js rename to frontend/app/models/user-statistic.ts diff --git a/frontend/app/models/user.js b/frontend/app/models/user.ts similarity index 100% rename from frontend/app/models/user.js rename to frontend/app/models/user.ts diff --git a/frontend/app/models/worktime-balance.js b/frontend/app/models/worktime-balance.ts similarity index 100% rename from frontend/app/models/worktime-balance.js rename to frontend/app/models/worktime-balance.ts diff --git a/frontend/app/models/year-statistic.js b/frontend/app/models/year-statistic.ts similarity index 100% rename from frontend/app/models/year-statistic.js rename to frontend/app/models/year-statistic.ts diff --git a/frontend/app/transforms/django-date.js b/frontend/app/transforms/django-date.ts similarity index 66% rename from frontend/app/transforms/django-date.js rename to frontend/app/transforms/django-date.ts index 7d1764609..881fd2673 100644 --- a/frontend/app/transforms/django-date.js +++ b/frontend/app/transforms/django-date.ts @@ -16,5 +16,11 @@ export default class DjangoDateTransform extends MomentTransform { * @property {String} format * @public */ - format = "YYYY-MM-DD"; + override format = "YYYY-MM-DD"; +} + +declare module "ember-data/types/registries/transform" { + export default interface TransformRegistry { + "django-date": DjangoDateTransform; + } } diff --git a/frontend/app/transforms/django-datetime.js b/frontend/app/transforms/django-datetime.ts similarity index 65% rename from frontend/app/transforms/django-datetime.js rename to frontend/app/transforms/django-datetime.ts index fdbfd2ed5..fb32d7fcd 100644 --- a/frontend/app/transforms/django-datetime.js +++ b/frontend/app/transforms/django-datetime.ts @@ -16,5 +16,11 @@ export default class DjangoDatetimeTransform extends MomentTransform { * @property {String} format * @public */ - format = "YYYY-MM-DDTHH:mm:ss.SSSSZ"; + override format = "YYYY-MM-DDTHH:mm:ss.SSSSZ"; +} + +declare module "ember-data/types/registries/transform" { + export default interface TransformRegistry { + "django-datetime": DjangoDatetimeTransform; + } } diff --git a/frontend/app/transforms/django-duration.js b/frontend/app/transforms/django-duration.ts similarity index 90% rename from frontend/app/transforms/django-duration.js rename to frontend/app/transforms/django-duration.ts index c607ba709..aca8513a7 100644 --- a/frontend/app/transforms/django-duration.js +++ b/frontend/app/transforms/django-duration.ts @@ -29,7 +29,7 @@ export default class DjangoDurationTransform extends Transform { * @return {moment.duration} The deserialized moment duration * @public */ - deserialize(serialized) { + deserialize(serialized: string) { return parseDjangoDuration(serialized); } @@ -46,7 +46,7 @@ export default class DjangoDurationTransform extends Transform { * @returns {Object} An object containing all needed components as number * @private */ - _getDurationComponentsTimedeltaLike(duration) { + _getDurationComponentsTimedeltaLike(duration: Duration): object { const days = Math.floor(duration.asDays()); const milliseconds = Math.abs(moment.duration({ days }) - duration); @@ -90,3 +90,9 @@ export default class DjangoDurationTransform extends Transform { return string; } } + +declare module "ember-data/types/registries/transform" { + export default interface TransformRegistry { + "django-duration": DjangoDurationTransform; + } +} diff --git a/frontend/app/transforms/django-time.js b/frontend/app/transforms/django-time.ts similarity index 72% rename from frontend/app/transforms/django-time.js rename to frontend/app/transforms/django-time.ts index 465159bec..86b26e98c 100644 --- a/frontend/app/transforms/django-time.js +++ b/frontend/app/transforms/django-time.ts @@ -18,3 +18,9 @@ export default class DjangoTimeTransform extends MomentTransform { */ format = "HH:mm:ss"; } + +declare module "ember-data/types/registries/transform" { + export default interface TransformRegistry { + "django-time": DjangoTimeTransform; + } +} diff --git a/frontend/app/transforms/django-workdays.js b/frontend/app/transforms/django-workdays.ts similarity index 63% rename from frontend/app/transforms/django-workdays.js rename to frontend/app/transforms/django-workdays.ts index 243146a30..16dd78ff6 100644 --- a/frontend/app/transforms/django-workdays.js +++ b/frontend/app/transforms/django-workdays.ts @@ -12,25 +12,21 @@ import Transform from "@ember-data/serializer/transform"; export default class DjangoWorkdaysTransform extends Transform { /** * Deserialize the string separated by comma into an array of numbers - * - * @method deserialize - * @param {String} serialized The string - * @return {Number[]} The deserialized array - * @public */ - deserialize(serialized) { + deserialize(serialized: string) { return serialized.split(",").map(Number); } /** * Serialize the array of numbers into a string separated by comma - * - * @method serialize - * @param {Number[]} deserialized The number array - * @return {String} The serialized string - * @public */ - serialize(deserialized) { + serialize(deserialized: number[]) { return deserialized.join(); } } + +declare module "ember-data/types/registries/transform" { + export default interface TransformRegistry { + "django-workdays": DjangoWorkdaysTransform; + } +} diff --git a/frontend/app/transforms/moment.js b/frontend/app/transforms/moment.ts similarity index 64% rename from frontend/app/transforms/moment.js rename to frontend/app/transforms/moment.ts index 2720cd6fc..c422bb9ce 100644 --- a/frontend/app/transforms/moment.js +++ b/frontend/app/transforms/moment.ts @@ -1,5 +1,5 @@ import Transform from "@ember-data/serializer/transform"; -import moment from "moment"; +import moment, { type Moment } from "moment"; /** * The moment transform @@ -21,27 +21,23 @@ export default class MomentTransform extends Transform { /** * Deserialize the string into a moment object - * - * @method deserialize - * @param {String} serialized The date string - * @return {moment.duration} The deserialized moment object - * @public */ - deserialize(serialized) { + deserialize(serialized: string) { return serialized ? moment(serialized, this.format) : null; } /** * Serialize the moment object into a string - * - * @method serialize - * @param {String} deserialized The moment object - * @return {moment.duration} The serialized date string - * @public */ - serialize(deserialized) { + serialize(deserialized: Moment) { return deserialized && deserialized.isValid() ? deserialized.format(this.format) : null; } } + +declare module "ember-data/types/registries/transform" { + export default interface TransformRegistry { + "django-workdays": MomentTransform; + } +} diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index 79f0e7826..45e83c142 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -8,6 +8,7 @@ // layout, which is not resolvable with the Node resolution algorithm, to // work with TypeScript. "allowJs": true, + "noImplicitOverride": false, "baseUrl": ".", "paths": { "timed/tests/*": [