first commit

This commit is contained in:
Romulus21
2024-02-10 14:59:46 +01:00
commit 5bb0b25673
193 changed files with 28660 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
interface Number {
pad(n: number, char?: string): string
}
Number.prototype.pad = function(n, char = "0") {
return (new Array(n).join(char) + this).slice(-n)
}
interface Date {
toFrDate(): string,
toFrTime(): string,
toSmallFrDate(): string,
difference(start_at?: Date): string,
}
Date.prototype.toFrDate = function() {
return `${this.getDate()}/${Number(this.getMonth() + 1).pad(2)}/${this.getFullYear()}`
}
Date.prototype.toFrTime = function(separator = 'h') {
return `${this.getHours().pad(2, '0')}${separator}${Number(this.getMinutes()).pad(2)}`
}
Date.prototype.toSmallFrDate = function() {
if ((new Date(this)).toFrDate() === (new Date()).toFrDate()) {
return `${this.toFrTime()}`
}
return `${this.toFrDate()} ${this.toFrTime()}`
}
Date.prototype.difference = function (start_at) {
if (!this) {
return '--:--'
}
let end_at = this
if (!start_at) {
end_at = new Date()
start_at = this
}
let timer = Math.floor((end_at.getTime() - start_at.getTime()) / 1000)
let hours = Math.floor(timer / 3600)
let minutes = Math.floor((timer - hours * 3600) / 60)
let secondes = timer - hours * 3600 - minutes * 60
return `${hours}:${String(minutes).padStart(2, '0')}:${String(secondes).padStart(2, '0')}`
}

View File

@@ -0,0 +1,40 @@
export function displayFormErrors(error: any, form: HTMLElement|null = null) {
if (error.response && error.response.status === 422) {
let errors = error.response.data.errors
const formBase = (form) ? form : document.body
Object.keys(errors).forEach(key => {
displayError(key, errors[key], formBase)
})
}
}
export function displayError(key: string, message: string, form: HTMLElement|null = null) {
const formBase = (form) ? form : document
const input = formBase.querySelector(`input[name="${key}"], select[name="${key}"], textarea[name="${key}"]`)
if (input) {
const formControl = input.closest('.form-control')
if (formControl) {
formControl.classList.add('invalid-control')
const errorMessage: HTMLElement|null = formControl.querySelector('.error-message')
if (errorMessage) {
errorMessage.innerText = message
}
if(key === 'form_info') {
formControl.classList.remove('hidden')
}
}
}
}
export function cleanErrorsForm(form = null) {
const formBase = (form) ? form : document.body
const inputsErrors = formBase.querySelectorAll('.invalid-control')
inputsErrors.forEach(input => {
input.classList.remove('invalid-control')
const errorMessage: HTMLElement|null = input.querySelector('.error-message')
if (errorMessage) {
errorMessage.innerText = ''
}
})
}

View File

@@ -0,0 +1,15 @@
export interface toDo {
id: number,
user_id: number,
name: string,
checked: boolean,
description?: string,
}
export interface timeTracker {
id: number,
to_do_id: number,
start_at: string,
end_at: string,
to_do: toDo,
}