Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typescript #475

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
112 changes: 101 additions & 11 deletions frontend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,107 @@
"use-strict";

module.exports = {
extends: ["@adfinis/eslint-config/ember-app"],
root: true,
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: "latest",
},
plugins: ["ember", "@typescript-eslint", "import"],
extends: [
"eslint:recommended",
"plugin:ember/recommended",
"plugin:prettier/recommended",
],
env: {
browser: true,
},
rules: {
"ember/no-actions-hash": "warn",
"ember/no-component-lifecycle-hooks": "warn",
"ember/no-mixins": "warn",
"ember/no-new-mixins": "warn",
"ember/no-classic-classes": "warn",
"ember/no-classic-components": "warn",
"ember/no-get": "warn",
"ember/no-observers": "warn",
"qunit/no-assert-equal": "warn",
"ember/require-tagless-components": "warn",
// possible errors
"no-await-in-loop": "error",

// best practices
"array-callback-return": "error",
"dot-notation": "error",
eqeqeq: "error",
"no-alert": "error",
"no-else-return": "error",
"no-eval": "error",
"no-extend-native": "error",
"no-extra-bind": "error",
"no-floating-decimal": "error",
"one-var": ["error", "never"],
curly: ["error", "multi-line"],

// ES6
"no-var": "error",
"object-shorthand": "error",
"prefer-const": "error",
"prefer-destructuring": [
"error",
{ AssignmentExpression: { array: false, object: false } },
],
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "error",

// import
"import/no-duplicates": "error",
"import/no-unresolved": "off",
"import/order": [
"error",
{
"newlines-between": "always",
alphabetize: { order: "asc", caseInsensitive: true },
},
],

// tooling
"no-console": ["error", { allow: ["warn", "error"] }],
"no-debugger": "error",
},
overrides: [
// js files
{
files: ["**/*.js"],
extends: [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
],
rules: {},
},
// ts files
{
files: ["**/*.ts"],
extends: [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
],
rules: {},
},
// node files
{
files: [
"./.eslintrc.js",
"./.prettierrc.js",
"./.stylelintrc.js",
"./.template-lintrc.js",
"./ember-cli-build.js",
"./testem.js",
"./blueprints/*/index.js",
"./config/**/*.js",
"./lib/*/index.js",
"./server/**/*.js",
],
env: {
browser: false,
node: true,
},
extends: ["plugin:n/recommended"],
},
{
// test files
files: ["tests/**/*-test.{js,ts}"],
extends: ["plugin:qunit/recommended"],
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ApplicationAdapter from "timed/adapters/application";
* @extends ApplicationAdapter
* @public
*/
export default ApplicationAdapter.extend({
export default class ActivityBlockAdapter extends ApplicationAdapter {
/**
* Custom url for updating records
*
Expand All @@ -24,8 +24,8 @@ export default ApplicationAdapter.extend({
* @public
*/
urlForUpdateRecord(...args) {
return `${this._super(...args)}?include=activity`;
},
return `${super.urlForUpdateRecord(...args)}?include=activity`;
}

/**
* Custom url for creating records
Expand All @@ -38,6 +38,12 @@ export default ApplicationAdapter.extend({
* @public
*/
urlForCreateRecord(...args) {
return `${this._super(...args)}?include=activity`;
},
});
return `${super.urlForCreateRecord(...args)}?include=activity`;
}
}

declare module "ember-data/types/registries/adapter" {
export default interface AdapterRegistry {
"activity-block": ActivityBlockAdapter;
}
}
14 changes: 14 additions & 0 deletions frontend/app/config/environment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Type declarations for
* import config from 'timed/config/environment'
*/
declare const config: {
environment: string;
modulePrefix: string;
podModulePrefix: string;
locationType: "history" | "hash" | "none";
rootURL: string;
APP: Record<string, unknown>;
};

export default config;
12 changes: 0 additions & 12 deletions frontend/app/models/absence-balance.js

This file was deleted.

29 changes: 29 additions & 0 deletions frontend/app/models/absence-balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { AsyncHasMany } from "@ember-data/model";
import Model, { attr, belongsTo, hasMany } from "@ember-data/model";
import type { Duration } from "moment";
import type AbsenceCredit from "timed/models/absence-credit";
import type AbsenceType from "timed/models/absence-type";
import type User from "timed/models/user";

export default class AbsenceBalance extends Model {
@attr("number")
declare credit?: number;
@attr("number")
declare usedDays?: number;
@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<AbsenceCredit>;
}

declare module "ember-data/types/registries/model" {
export default interface ModelRegistry {
"absence-balance": AbsenceBalance;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import Model, { attr, belongsTo } from "@ember-data/model";
import type { Moment } from "moment";
import type AbsenceType from "timed/models/absence-type";
import type User from "timed/models/user";
/**
* @module timed
* @submodule timed-models
* @public
*/
import Model, { attr, belongsTo } from "@ember-data/model";

/**
* The absence credit model
Expand All @@ -19,37 +22,48 @@ export default class AbsenceCredit extends Model {
* @property {Number} days
* @public
*/
@attr("number") days;
@attr("number")
declare days?: number;

/**
* The date
*
* @property {moment} date
* @public
*/
@attr("django-date") date;
@attr("django-date")
declare date?: Moment;

/**
* The comment
*
* @property {String} comment
* @public
*/
@attr("string", { defaultValue: "" }) comment;
@attr("string", { defaultValue: "" })
declare comment: string;

/**
* The absence type for which this credit counts
*
* @property {AbsenceType} absenceType
* @public
*/
@belongsTo("absence-type", { async: false, inverse: null }) absenceType;
@belongsTo("absence-type", { async: false, inverse: null })
declare absenceType: AbsenceType;

/**
* The user to which this credit belongs to
*
* @property {User} user
* @public
*/
@belongsTo("user", { async: false, inverse: null }) user;
@belongsTo("user", { async: false, inverse: null })
declare user: User;
}

declare module "ember-data/types/registries/model" {
export default interface ModelRegistry {
"absence-credit": AbsenceCredit;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { AsyncHasMany } from "@ember-data/model";
/**
* @module timed
* @submodule timed-models
* @public
*/
import Model, { attr, hasMany } from "@ember-data/model";
import type AbsenceBalance from "timed/models/absence-balance";

/**
* The absence type model
Expand All @@ -21,15 +23,17 @@ export default class AbsenceType extends Model {
* @property {String} name
* @public
*/
@attr("string") name;
@attr("string")
declare name?: string;

/**
* Whether the absence type only fills the worktime
*
* @property {Boolean} fillWorktime
* @public
*/
@attr("boolean") fillWorktime;
@attr("boolean")
declare fillWorktime?: boolean;

/**
* The balances for this type
Expand All @@ -38,5 +42,11 @@ export default class AbsenceType extends Model {
* @public
*/
@hasMany("absence-balance", { async: true, inverse: "absenceType" })
absenceBalances;
declare absenceBalances: AsyncHasMany<AbsenceBalance>;
}

declare module "ember-data/types/registries/model" {
export default interface ModelRegistry {
"absence-type": AbsenceType;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import type { AsyncBelongsTo } from "@ember-data/model";
import Model, { attr, belongsTo } from "@ember-data/model";
import type { Moment, Duration } from "moment";
/**
* @module timed
* @submodule timed-models
* @public
*/
import Model, { attr, belongsTo } from "@ember-data/model";
import moment from "moment";
import type AbsenceType from "timed/models/absence-type";
import type User from "timed/models/user";

/**
* The report model
Expand All @@ -20,37 +24,48 @@ export default class Absence extends Model {
* @property {String} comment
* @public
*/
@attr("string", { defaultValue: "" }) comment;
@attr("string", { defaultValue: "" })
declare comment: string;

/**
* The duration
*
* @property {moment.duration} duration
* @public
*/
@attr("django-duration", { defaultValue: () => moment.duration() }) duration;
@attr("django-duration", { defaultValue: () => moment.duration() })
declare duration: Duration;

/**
* The date
*
* @property {moment} date
* @public
*/
@attr("django-date") date;
@attr("django-date")
declare date?: Moment;

/**
* The type of the absence
*
* @property {AbsenceType} absenceType
* @public
*/
@belongsTo("absence-type", { async: false, inverse: null }) absenceType;
@belongsTo("absence-type", { async: false, inverse: null })
declare absenceType: AbsenceType;

/**
* The user
*
* @property {User} user
* @public
*/
@belongsTo("user", { async: true, inverse: null }) user;
@belongsTo("user", { async: true, inverse: null })
declare user: AsyncBelongsTo<User>;
}

declare module "ember-data/types/registries/model" {
export default interface ModelRegistry {
absence: Absence;
}
}
Loading
Loading