-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Format TypeScript with Prettier (#130)
- Loading branch information
Showing
14 changed files
with
352 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
arrowParens: always | ||
endOfLine: lf | ||
printWidth: 80 | ||
quoteProps: as-needed | ||
semi: false | ||
singleQuote: true | ||
tabWidth: 2 | ||
trailingComma: all | ||
useTabs: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,16 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"plugins": ["@typescript-eslint"], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"rules": { | ||
"no-var": 0, | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-empty-function": "off", | ||
"@typescript-eslint/no-unused-vars": "off", | ||
"@typescript-eslint/ban-types": "off", | ||
"@typescript-eslint/no-this-alias": [ | ||
"error", | ||
{ | ||
"allowedNames": ["that"] | ||
} | ||
] | ||
"@typescript-eslint/no-this-alias": ["error", { "allowedNames": ["that"] }] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
declare module "stimulus-flatpickr"; | ||
declare module 'stimulus-flatpickr' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,28 @@ | ||
// Setup | ||
|
||
declare module "@hotwired/stimulus"; | ||
declare module '@hotwired/stimulus' | ||
|
||
declare global { | ||
interface Window { | ||
Stimulus?: any; | ||
TimerInterval?: any; | ||
RedmineTracky?: any; | ||
} | ||
interface Window { | ||
Stimulus?: any | ||
TimerInterval?: any | ||
RedmineTracky?: any | ||
} | ||
} | ||
|
||
// Styles | ||
|
||
require('./redmine-tracky.scss'); | ||
require('./redmine-tracky.scss') | ||
|
||
// Controllers | ||
import { Application } from "@hotwired/stimulus"; | ||
import FormController from '@controllers/form-controller'; | ||
import TimerController from '@controllers/timer-controller'; | ||
import ListController from '@controllers/list-controller'; | ||
import IssueCompletionController from '@controllers/issue-completion-controller'; | ||
import FlatpickrController from '@controllers/flatpickr-controller'; | ||
import { Application } from '@hotwired/stimulus' | ||
import FormController from '@controllers/form-controller' | ||
import TimerController from '@controllers/timer-controller' | ||
import ListController from '@controllers/list-controller' | ||
import IssueCompletionController from '@controllers/issue-completion-controller' | ||
import FlatpickrController from '@controllers/flatpickr-controller' | ||
|
||
window.Stimulus = Application.start(); | ||
window.Stimulus.register("form", FormController); | ||
window.Stimulus.register("timer", TimerController); | ||
window.Stimulus.register("list", ListController); | ||
window.Stimulus.register("issue-completion", IssueCompletionController); | ||
window.Stimulus = Application.start() | ||
window.Stimulus.register('form', FormController) | ||
window.Stimulus.register('timer', TimerController) | ||
window.Stimulus.register('list', ListController) | ||
window.Stimulus.register('issue-completion', IssueCompletionController) | ||
window.Stimulus.register('flatpickr', FlatpickrController) |
10 changes: 5 additions & 5 deletions
10
assets.src/src/redmine-tracky/controllers/flatpickr-controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import Flatpickr from 'stimulus-flatpickr'; | ||
import Flatpickr from 'stimulus-flatpickr' | ||
|
||
export default class extends Flatpickr { | ||
open(_selectedDates: Array<Date>, dateStr: String, instance: any) { | ||
if (!dateStr) { | ||
instance.setDate(Date.now()); | ||
} | ||
open(_selectedDates: Date[], dateStr: String, instance: any) { | ||
if (!dateStr) { | ||
instance.setDate(Date.now()) | ||
} | ||
} | ||
} |
170 changes: 84 additions & 86 deletions
170
assets.src/src/redmine-tracky/controllers/form-controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,95 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
import { DateTime, DurationUnits, Duration } from 'luxon'; | ||
import { FormData } from '@interfaces/form-data'; | ||
import { Controller } from '@hotwired/stimulus' | ||
import { DateTime } from 'luxon' | ||
import { FormData } from '@interfaces/form-data' | ||
|
||
export default class extends Controller { | ||
readonly startTarget!: Element; | ||
declare readonly hasStopButtonTarget: boolean | ||
readonly endTarget!: Element; | ||
readonly absolutInputTarget!: Element; | ||
readonly descriptionTarget!: Element; | ||
readonly issueTargets!: Array<Element>; | ||
|
||
private connected = false; | ||
|
||
static targets = ['description', 'start', 'stopButton', 'end', 'issue', 'absolutInput']; | ||
|
||
public connect(): void { | ||
this.connected = true; | ||
} | ||
|
||
public disconnect(): void { | ||
this.connected = false; | ||
} | ||
|
||
public absoluteTime(event: Event): void { | ||
try { | ||
const value = parseFloat((this.absolutInputTarget as HTMLInputElement).value); | ||
const startDate: DateTime = this.convertToDateTime(this.valueForInput(this.startTarget)); | ||
|
||
if (value && startDate.isValid) { | ||
const newEndDate: DateTime = startDate.plus({ hours: value }); | ||
console.log(newEndDate); | ||
|
||
(this.endTarget as HTMLInputElement).value = newEndDate.toFormat( | ||
'dd.LL.yyyy HH:mm' | ||
); | ||
|
||
this.endTarget.dispatchEvent(new Event('change')); | ||
} | ||
} finally { | ||
(this.absolutInputTarget as HTMLInputElement).value = ''; | ||
} | ||
declare readonly startTarget: HTMLInputElement | ||
declare readonly hasStopButtonTarget: boolean | ||
declare readonly endTarget: HTMLInputElement | ||
declare readonly absolutInputTarget: HTMLInputElement | ||
declare readonly descriptionTarget: HTMLInputElement | ||
declare readonly issueTargets: Element[] | ||
|
||
private connected = false | ||
|
||
static targets = [ | ||
'description', | ||
'start', | ||
'stopButton', | ||
'end', | ||
'issue', | ||
'absolutInput', | ||
] | ||
|
||
public connect() { | ||
this.connected = true | ||
} | ||
|
||
public disconnect() { | ||
this.connected = false | ||
} | ||
|
||
public absoluteTime(_event: Event) { | ||
try { | ||
const value = parseFloat(this.absolutInputTarget.value) | ||
const startDate = this.convertToDateTime(this.startTarget.value) | ||
|
||
if (value && startDate.isValid) { | ||
const newEndDate = startDate.plus({ hours: value }) | ||
this.endTarget.value = newEndDate.toFormat('dd.LL.yyyy HH:mm') | ||
this.endTarget.dispatchEvent(new Event('change')) | ||
} | ||
} finally { | ||
this.absolutInputTarget.value = '' | ||
} | ||
} | ||
|
||
public issueTargetConnected(_: Element) { | ||
if (this.connected) { | ||
this.change(); | ||
} | ||
public issueTargetConnected(_: Element) { | ||
if (this.connected) { | ||
this.change() | ||
} | ||
} | ||
|
||
public issueTargetDisconnected(_: Element) { | ||
if (this.connected) { | ||
this.change(); | ||
} | ||
public issueTargetDisconnected(_: Element) { | ||
if (this.connected) { | ||
this.change() | ||
} | ||
|
||
public change(): void { | ||
const form: FormData = { | ||
timer_start: (this.startTarget as HTMLInputElement).value, | ||
timer_end: (this.endTarget as HTMLInputElement).value, | ||
comments: (this.descriptionTarget as HTMLInputElement).value, | ||
issue_ids: this.extractIssueIds() || [] | ||
}; | ||
|
||
this.dispatchUpdate(form); | ||
} | ||
|
||
private extractIssueIds(): Array<string> { | ||
return this.issueTargets.map((element: Element) => { | ||
return element.getAttribute('data-issue-id') || ''; | ||
}).filter((value: string) => value !== null) || []; | ||
} | ||
|
||
private dispatchUpdate(form: FormData) { | ||
if (this.hasStopButtonTarget) { | ||
$.ajax({ | ||
type: "POST", | ||
url: window.RedmineTracky.trackerUpdatePath, | ||
data: { | ||
timer_session: form, | ||
}, | ||
async: true, | ||
}); | ||
} | ||
} | ||
|
||
private valueForInput(element: Element): any { | ||
return (element as HTMLInputElement).value; | ||
} | ||
|
||
public change() { | ||
const form: FormData = { | ||
timer_start: this.startTarget.value, | ||
timer_end: this.endTarget.value, | ||
comments: this.descriptionTarget.value, | ||
issue_ids: this.extractIssueIds() || [], | ||
} | ||
|
||
private convertToDateTime(value: string): DateTime { | ||
return DateTime.fromFormat( | ||
value, | ||
window.RedmineTracky.datetimeFormatJavascript | ||
); | ||
this.dispatchUpdate(form) | ||
} | ||
|
||
private extractIssueIds(): string[] { | ||
return ( | ||
this.issueTargets | ||
.map((element) => element.getAttribute('data-issue-id') || '') | ||
.filter((value) => value !== null) || [] | ||
) | ||
} | ||
|
||
private dispatchUpdate(form: FormData) { | ||
if (this.hasStopButtonTarget) { | ||
$.ajax({ | ||
type: 'POST', | ||
url: window.RedmineTracky.trackerUpdatePath, | ||
data: { timer_session: form }, | ||
async: true, | ||
}) | ||
} | ||
} | ||
|
||
private convertToDateTime(value: string) { | ||
return DateTime.fromFormat( | ||
value, | ||
window.RedmineTracky.datetimeFormatJavascript, | ||
) | ||
} | ||
} |
Oops, something went wrong.