This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
132 lines (130 loc) · 6.36 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Timesheet</title>
<link rel="shortcut icon" href="favicon.svg" type="image/x-icon">
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Lily+Script+One&display=swap&text=timesheet" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;700&display=swap" rel="stylesheet">
<style>
.font-lily{
font-family: 'Lily Script One';
}
.font-sans{
font-family: 'Open Sans', sans-serif;
}
input[type="time"]::-webkit-calendar-picker-indicator {
display: none;
}
</style>
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js" defer></script>
<script src="https://unpkg.com/localbase/dist/localbase.min.js"></script>
</head>
<body class="bg-white font-sans flex flex-col h-100 min-h-sreen" x-data="app()" x-init="init()">
<header class="p-3 bg-red-500 shadow-lg">
<h1 class="font-lily text-3xl text-white">timesheet</h1>
</header>
<main>
<div class="py-8 flex container mx-auto items-end" @keydown.enter="add()">
<div class="input-group flex flex-col">
<label for="from" class="uppercase font-bold text-gray-800 text-xs">Desde</label>
<input x-model="newEntry.from" required class="p-2 bg-gray-200 text-gray-800 focus:outline-none text-xl appearance-none h-12" type="time" name="from" id="from" step="900">
</div>
<div class="input-group flex flex-col">
<label for="to" class="uppercase font-bold text-gray-800 text-xs">Hasta</label>
<input x-model="newEntry.to" required class="p-2 bg-gray-200 text-gray-800 focus:outline-none text-xl appearance-none h-12" type="time" name="to" id="to" step="900">
</div>
<div class="input-group flex flex-col flex-auto">
<label for="to" class="uppercase font-bold text-gray-800 text-xs">Tarea</label>
<input x-model="newEntry.subject" required class="p-2 bg-gray-200 text-gray-800 flex-auto focus:outline-none text-xl h-12" type="text" name="subject" id="subject" placeholder="Introduce una tarea">
</div>
<button @click.prevent="add()" type="submit" class="bg-red-500 hover:bg-red-400 text-white p-2 focus:outline-none h-12">Añadir</button>
</div>
<template x-show="data.length > 0" x-for="timesheet in data" :key="timesheet">
<section class="container mx-auto py-8">
<h2 x-text="timesheet.date" class="font-bold text-gray-700 text-xl"></h2>
<table class="my-5">
<template x-for="entry in timesheet.entries">
<tr>
<td class="p-2 text-xl"><input class="w-6 h-6 align-middle" type="checkbox" name="" id=""></td>
<td class="p-2 text-xl"><span x-text="entry.from"></span></td>
<td class="p-2 text-xl"><span x-text="entry.to"></span></td>
<td class="p-2 text-xl"><span x-text="entry.subject"></span></td>
</tr>
</template>
</table>
</section>
</template>
<section x-show="data.length == 0" class="container mx-auto py-8 text-center">
Actualmente no hay ningún registro almacenado
</section>
</main>
<script>
function app(){
return {
newEntry: {
'from': '',
'to': '',
'subject': '',
},
data: [],
init() {
if(!this.data.length > 0){
let now = new Date()
this.newEntry.from = this.formatTime(now,15)
now.setHours(now.getHours() + 1)
this.newEntry.to = this.formatTime(now,15)
}else{
let entries = this.data[0].entries
this.newEntry.from = entries[entries.length-1].to
this.newEntry.to = this.formatTime(now, 15)
}
},
add(){
let now = new Date()
let year = now.getFullYear()
let month = (now.getMonth() + 1).toString().padStart(2,'0')
let day = now.getDate().toString().padStart(2,'0')
let date = year+'-'+month+'-'+day
if(this.data.length > 0 && this.data[0].date == date){
let newEntry = {
'from': this.newEntry.from,
'to': this.newEntry.to,
'subject': this.newEntry.subject
}
this.data[0].entries.unshift(newEntry)
}else{
let timesheet = {
'date': date,
'entries': [
{
'from': this.newEntry.from,
'to': this.newEntry.to,
'subject': this.newEntry.subject
}
]
}
this.data.unshift(timesheet)
}
this.newEntry.from = this.newEntry.to
this.newEntry.top = this.formatTime(new Date(),15)
this.newEntry.subject = ''
return 0
},
formatTime(time, base){
let hours = time.getHours().toString()
let minutes = time.getMinutes()
let roundedMinutes = base * Math.round(minutes/base)
if (roundedMinutes == 60){
roundedMinutes = 00
hours = (time.getHours() + 1).toString()
}
return hours.padStart(2, '0')+':'+roundedMinutes.toString().padStart(2, '0')
}
}
}
</script>
</body>
</html>