Compare commits
524 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d456cd3ce2 | ||
|
|
bad92d7215 | ||
|
|
16703081cd | ||
|
|
cbdf91f316 | ||
|
|
999d820d4c | ||
|
|
fe4185ae45 | ||
|
|
cad9f58703 | ||
|
|
70b4fbcae8 | ||
|
|
a0601c8cb2 | ||
|
|
5b320bf2ea | ||
|
|
15110f78d8 | ||
|
|
4154de6bd1 | ||
|
|
8094fcf5b5 | ||
|
|
77afa207e0 | ||
|
|
d9ef6dfcad | ||
|
|
ff6918fcab | ||
|
|
f376b5c8a1 | ||
|
|
b00fbd2516 | ||
|
|
d97abc3f57 | ||
|
|
3f184e42c8 | ||
|
|
4a31411d69 | ||
|
|
3925eacf9f | ||
|
|
394f377890 | ||
|
|
e8b0dc4969 | ||
|
|
d429c56687 | ||
|
|
6a86afb5fd | ||
|
|
9e87fc131b | ||
|
|
5a0c783a76 | ||
|
|
26361da873 | ||
|
|
26f8abfcc6 | ||
|
|
27c2b912f7 | ||
|
|
7e72f144cb | ||
|
|
3c3d6379a8 | ||
|
|
806bb97e60 | ||
|
|
3fcaf55d02 | ||
|
|
f0e2337d67 | ||
|
|
00d801616a | ||
|
|
afb5a0bba4 | ||
|
|
8c1ed68817 | ||
|
|
b61420d633 | ||
|
|
595b5f4b25 | ||
|
|
07ac6c308f | ||
|
|
a6766373b4 | ||
|
|
a15c1e56cb | ||
|
|
8a42c9640f | ||
|
|
8e6764b67a | ||
|
|
ea29799b89 | ||
|
|
a3ef1fd1cd | ||
|
|
1a38c7d7a3 | ||
|
|
636a51e721 | ||
|
|
cc64acf0f8 | ||
|
|
76821c24ed | ||
|
|
190b1dd4f3 | ||
|
|
7937fa281a | ||
|
|
6d78c6ba36 | ||
|
|
5d3e46cce2 | ||
|
|
1c3aac78f6 | ||
|
|
b1fb300a71 | ||
|
|
a4d658b821 | ||
|
|
4920ea5075 | ||
|
|
03dbbdc5ba | ||
|
|
023048e7c0 | ||
|
|
24778d3ffb | ||
|
|
04331420ae | ||
|
|
f3890691ce | ||
|
|
dfec807166 | ||
|
|
06b3060fe1 | ||
|
|
b6a8ae783f | ||
|
|
3d8fa3af44 | ||
|
|
59dc82351e | ||
|
|
da10099248 | ||
|
|
05aaa1950a | ||
|
|
46129c7ab9 | ||
|
|
c8b4e4eabb | ||
|
|
2f2ebd6293 | ||
|
|
594385f741 | ||
|
|
12190141d7 | ||
|
|
0420eb27c7 | ||
|
|
81107377f4 | ||
|
|
e9c172daea | ||
|
|
f42d42f512 | ||
|
|
b38c6fbb0e | ||
|
|
e2a1146670 | ||
|
|
e69ac6968b | ||
|
|
87168de4f1 | ||
|
|
7b158d57b5 | ||
|
|
1e0fbf0b73 | ||
|
|
6e26a37c4d | ||
|
|
fac5a910d8 | ||
|
|
dfd97fd6f3 | ||
|
|
452a8d9390 | ||
|
|
2a9de506a1 | ||
|
|
e663cc2b02 | ||
|
|
a70c803158 | ||
|
|
9ca69e1114 | ||
|
|
2e6b700b43 | ||
|
|
2a75cd6230 | ||
|
|
934fdeb107 | ||
|
|
14cdcd3f63 | ||
|
|
674bf3a6b5 | ||
|
|
cce49cc409 | ||
|
|
04cb403ea9 | ||
|
|
afaa845a9a | ||
|
|
928b5208e9 | ||
|
|
8a8d0503f7 | ||
|
|
b341358d0a | ||
|
|
d30166e691 | ||
|
|
b42c77a2a1 | ||
|
|
8444928ae4 | ||
|
|
b250edc2a1 | ||
|
|
4a8c2a79c9 | ||
|
|
bff72b30cc | ||
|
|
9d7b418d99 | ||
|
|
f2fb338539 | ||
|
|
1b3ff212d2 | ||
|
|
c07979e3a9 | ||
|
|
23e8dcf495 | ||
|
|
4332ef95a2 | ||
|
|
4fdfb6f478 | ||
|
|
136104d4b0 | ||
|
|
c7f0508707 | ||
|
|
9bd37fb695 | ||
|
|
21c031f2c8 | ||
|
|
17a815e5a9 | ||
|
|
648686c001 | ||
|
|
82a3b99a31 | ||
|
|
70741eebfd | ||
|
|
eb933e7021 | ||
|
|
372f3c8507 | ||
|
|
e030ff08db | ||
|
|
f13b81ede7 | ||
|
|
46c4449504 | ||
|
|
8b55cd3693 | ||
|
|
406ac7b9cb | ||
|
|
0c26a2678e | ||
|
|
49eb7068c9 | ||
|
|
dcc52f1a95 | ||
|
|
31bae44f3c | ||
|
|
84a0ca5ce6 | ||
|
|
9e736b26f6 | ||
|
|
32a1306394 | ||
|
|
96043afd6a | ||
|
|
255c7d77d6 | ||
|
|
e6d5a720bf | ||
|
|
ff9bf163ee | ||
|
|
5fac6a642c | ||
|
|
b1b81ee8a6 | ||
|
|
1ea64bf18e | ||
|
|
0c4fdda00a | ||
|
|
215bd6a01a | ||
|
|
63b8164926 | ||
|
|
8c26ff9aed | ||
|
|
921a703ea2 | ||
|
|
855a546683 | ||
|
|
52b949daa3 | ||
|
|
ee040d29b6 | ||
|
|
fb9a0dc499 | ||
|
|
40154be8f9 | ||
|
|
13649e146c | ||
|
|
4076e1c3d3 | ||
|
|
8de54e1fa7 | ||
|
|
1965c35b43 | ||
|
|
3fd770047e | ||
|
|
036b297a76 | ||
|
|
537c120ad9 | ||
|
|
3e0dadc0c8 | ||
|
|
004ac5a6b9 | ||
|
|
3204dcb03e | ||
|
|
b1903ba183 | ||
|
|
75fa7a20b8 | ||
|
|
a19426147a | ||
|
|
9d933f62c0 | ||
|
|
9e3d243b4b | ||
|
|
62047c7c01 | ||
|
|
0bcd45babe | ||
|
|
2a72815481 | ||
|
|
ff6a3e8262 | ||
|
|
0947b88d36 | ||
|
|
5de5b4fef5 | ||
|
|
cde856a9c1 | ||
|
|
6f8877a740 | ||
|
|
e7d71bff64 | ||
|
|
cca0657291 | ||
|
|
a4904d3335 | ||
|
|
b9c1036b21 | ||
|
|
818c080d28 | ||
|
|
a5a6ae065b | ||
|
|
8b06ca9d10 | ||
|
|
7e1025d61d | ||
|
|
8788311faf | ||
|
|
ce22520d7f | ||
|
|
f5d76cfd9a | ||
|
|
27f7f14539 | ||
|
|
f7c32e633a | ||
|
|
6d9055826f | ||
|
|
4627a9047e | ||
|
|
987b46bf8f | ||
|
|
8792a1df09 | ||
|
|
a8678892d6 | ||
|
|
72350b76c0 | ||
|
|
8578bbe033 | ||
|
|
93ca983e0b | ||
|
|
e29ef25581 | ||
|
|
a617eba535 | ||
|
|
0c445d1bc4 | ||
|
|
5f7114e008 | ||
|
|
e2c511cf46 | ||
|
|
e042ef6bfa | ||
|
|
c059e51b3c | ||
|
|
661bb16342 | ||
|
|
94d6b43dcc | ||
|
|
99c296a751 | ||
|
|
8f8d228fb3 | ||
|
|
1214e508fe | ||
|
|
7d394fbe56 | ||
|
|
fd4dfc6be4 | ||
|
|
9dc9c71a46 | ||
|
|
345bb6601e | ||
|
|
5c8c21d609 | ||
|
|
7219b3f421 | ||
|
|
b76a5d5c35 | ||
|
|
40a9027d34 | ||
|
|
553bd20e06 | ||
|
|
3ea5803e08 | ||
|
|
4949afb098 | ||
|
|
d328badca1 | ||
|
|
175d371ef9 | ||
|
|
6bb7b38252 | ||
|
|
afe0656502 | ||
|
|
dd51c8dfba | ||
|
|
b6c98f871d | ||
|
|
19b2d47591 | ||
|
|
a636683dee | ||
|
|
c1f5d3def4 | ||
|
|
3e88a007d0 | ||
|
|
1fdd11e94c | ||
|
|
2ac783a300 | ||
|
|
3a358b1434 | ||
|
|
216da19cc9 | ||
|
|
dee90bb15e | ||
|
|
a78e8ed8c4 | ||
|
|
e293d62aa1 | ||
|
|
f016221e8e | ||
|
|
36c578452e | ||
|
|
6e643ee99c | ||
|
|
58cbf1776f | ||
|
|
85a16a9363 | ||
|
|
7abe787778 | ||
|
|
e98732f44a | ||
|
|
c2afebbb5e | ||
|
|
49e69d1ae3 | ||
|
|
a9a32c83ac | ||
|
|
64fa67f15d | ||
|
|
df3ca9d5a9 | ||
|
|
12ef19df28 | ||
|
|
a5b4a92086 | ||
|
|
3aaaf9ffc0 | ||
|
|
3f73f2c570 | ||
|
|
46739795ff | ||
|
|
afd60a67f6 | ||
|
|
bb325888a1 | ||
|
|
fdda9841fa | ||
|
|
5acd33dd64 | ||
|
|
6531e7fe52 | ||
|
|
c6a651456e | ||
|
|
8eeb9c120a | ||
|
|
d8f89d9f3d | ||
|
|
26a89725eb | ||
|
|
9f0165ef4d | ||
|
|
3d0a35f0cd | ||
|
|
c5dcf9e0fd | ||
|
|
ad645f5b58 | ||
|
|
f86eca05ae | ||
|
|
ac2a6ba2c8 | ||
|
|
e23d0474fd | ||
|
|
2edcbcca50 | ||
|
|
5f4b6d3cfa | ||
|
|
af82fd040d | ||
|
|
e0769bc3dc | ||
|
|
8fd2e7029e | ||
|
|
f570b5506a | ||
|
|
0e1bd818bf | ||
|
|
02bcd45116 | ||
|
|
16d4a691f8 | ||
|
|
20164295f8 | ||
|
|
9d8e5ecd7a | ||
|
|
8a1059fdd1 | ||
|
|
92c6922afb | ||
|
|
2fb9ea9239 | ||
|
|
350875be2a | ||
|
|
6a828cc9bd | ||
|
|
7034066de9 | ||
|
|
2a9bdb7982 | ||
|
|
a1d9874c13 | ||
|
|
0b1625175b | ||
|
|
0f6a6e7561 | ||
|
|
7bbd497ef1 | ||
|
|
0b3f645bda | ||
|
|
c840fee911 | ||
|
|
e06acc95c5 | ||
|
|
95f15e6c88 | ||
|
|
114617a052 | ||
|
|
38e37f1c2e | ||
|
|
7a5b12762a | ||
|
|
de419350b2 | ||
|
|
a6b237936e | ||
|
|
6e1207578e | ||
|
|
31348da4c0 | ||
|
|
452de88e18 | ||
|
|
18d953e79b | ||
|
|
636422e342 | ||
|
|
20149ae765 | ||
|
|
a392f61d61 | ||
|
|
3e61e0dce6 | ||
|
|
9baa477bed | ||
|
|
4d182ad1a7 | ||
|
|
e77056c4b7 | ||
|
|
d7f1df2987 | ||
|
|
8c1a793b0a | ||
|
|
adc0779912 | ||
|
|
c7bc8fae73 | ||
|
|
0a0ffb4ac9 | ||
|
|
b831532323 | ||
|
|
385753fbc3 | ||
|
|
651f812da8 | ||
|
|
6a99ad41ca | ||
|
|
dd89363c72 | ||
|
|
983bf2c88b | ||
|
|
ce7fe67fcc | ||
|
|
053a1d9017 | ||
|
|
2e2bf986a4 | ||
|
|
6e781b59e2 | ||
|
|
0663995d06 | ||
|
|
2ba9cff281 | ||
|
|
9c1150c50e | ||
|
|
b4a4d81ca8 | ||
|
|
2681b81990 | ||
|
|
97092acae9 | ||
|
|
fdb6cf5cf8 | ||
|
|
7ab0a8cea1 | ||
|
|
2664d6117f | ||
|
|
6bdf27fc9b | ||
|
|
f0298335ee | ||
|
|
a58a33fc7d | ||
|
|
9bd5965ecd | ||
|
|
29624354a2 | ||
|
|
04422f3530 | ||
|
|
43bd7bf1ab | ||
|
|
4b2a3669e6 | ||
|
|
1099e76244 | ||
|
|
d8f72b8b88 | ||
|
|
b2314de315 | ||
|
|
66413d789c | ||
|
|
7112e932a2 | ||
|
|
01e26dca9e | ||
|
|
844062b90e | ||
|
|
f60065d089 | ||
|
|
046ed313c9 | ||
|
|
ecd8ee85f3 | ||
|
|
0c397e5080 | ||
|
|
01226a1243 | ||
|
|
7164ec126f | ||
|
|
04b5eb4c38 | ||
|
|
3a5d7a62de | ||
|
|
252652082d | ||
|
|
f007697a73 | ||
|
|
1a8c78944a | ||
|
|
8449eafcb6 | ||
|
|
1310285133 | ||
|
|
588e85d48f | ||
|
|
aebd57e311 | ||
|
|
9d503300f6 | ||
|
|
80f8f70695 | ||
|
|
c6fc06222f | ||
|
|
8926f7677e | ||
|
|
517e7eae89 | ||
|
|
8b53980ce7 | ||
|
|
d13083fc6f | ||
|
|
34a79b1e3a | ||
|
|
ea8bf6d1fa | ||
|
|
cc39f25d37 | ||
|
|
0cbf0053d2 | ||
|
|
3b93afabc8 | ||
|
|
d03fbf0ef9 | ||
|
|
5c473ad39b | ||
|
|
3f09a2674b | ||
|
|
a8b972f8a5 | ||
|
|
3c28288cac | ||
|
|
2cb29bfef5 | ||
|
|
068e9425eb | ||
|
|
a9849fc6cf | ||
|
|
266c4bad25 | ||
|
|
f04e0d92aa | ||
|
|
cca3fa6b8a | ||
|
|
1bc1fadc56 | ||
|
|
e7eb89dfd9 | ||
|
|
25469113fd | ||
|
|
e474087257 | ||
|
|
75aea7c51b | ||
|
|
a64b44a74b | ||
|
|
d481f68266 | ||
|
|
8095ae298f | ||
|
|
99ad182358 | ||
|
|
f32448b9f5 | ||
|
|
f3b4078c6a | ||
|
|
ca846b5fbf | ||
|
|
63a3ae1147 | ||
|
|
5711c15eac | ||
|
|
a705703996 | ||
|
|
326dc64f65 | ||
|
|
974e1b3b5a | ||
|
|
f7f1765c2e | ||
|
|
aae31c567c | ||
|
|
49f307d605 | ||
|
|
f93d081a88 | ||
|
|
a230be77dd | ||
|
|
b62253e1f3 | ||
|
|
0e91dd886e | ||
|
|
6e0500972e | ||
|
|
8069e332fe | ||
|
|
cbd65f1f1d | ||
|
|
90a0fd8a22 | ||
|
|
95e06746bd | ||
|
|
1e492624cc | ||
|
|
6a524f9f7c | ||
|
|
84cc65b008 | ||
|
|
b8b3a3c8ab | ||
|
|
db0e555eae | ||
|
|
58a9facc6d | ||
|
|
11dac19c8c | ||
|
|
2d82f0400d | ||
|
|
94a6b99c57 | ||
|
|
2aa5eccc7c | ||
|
|
52f5e5640e | ||
|
|
d6c15bb1cb | ||
|
|
4f698f73dc | ||
|
|
e413325337 | ||
|
|
608a45408a | ||
|
|
323baa2d65 | ||
|
|
6235d18dab | ||
|
|
3d0f480d9e | ||
|
|
642d31432a | ||
|
|
421be6835e | ||
|
|
d58720252e | ||
|
|
0461539f4b | ||
|
|
78749ad3b4 | ||
|
|
8b4828f236 | ||
|
|
e5614b92a0 | ||
|
|
f5b725e32b | ||
|
|
006de60f66 | ||
|
|
14f4530de0 | ||
|
|
2022fa54d3 | ||
|
|
73ef090b9e | ||
|
|
6d7054c18c | ||
|
|
4549d826dd | ||
|
|
7eacb1dc3c | ||
|
|
5264dd111d | ||
|
|
a4f0b6a97e | ||
|
|
46af5e8ebf | ||
|
|
35fb15fe9f | ||
|
|
662259468d | ||
|
|
1e1b9a6919 | ||
|
|
5fa10dfdf1 | ||
|
|
a5556a0c63 | ||
|
|
0cefcf0e16 | ||
|
|
1959d4d8df | ||
|
|
1d445d9eb6 | ||
|
|
6cfcbccabc | ||
|
|
de39623378 | ||
|
|
96d0d4943b | ||
|
|
bfab6f42d0 | ||
|
|
b38fc96623 | ||
|
|
b7bade20ea | ||
|
|
283ab80fc7 | ||
|
|
d705287510 | ||
|
|
47d17af593 | ||
|
|
496a74f7a3 | ||
|
|
7eded6e126 | ||
|
|
4c9d3222d7 | ||
|
|
5a2b539003 | ||
|
|
a9252701c5 | ||
|
|
2fbbbe7260 | ||
|
|
1d1f5835da | ||
|
|
a04b72e866 | ||
|
|
3f4f63dc33 | ||
|
|
1763a2efff | ||
|
|
00906851b5 | ||
|
|
844a805de6 | ||
|
|
718e0b5c1e | ||
|
|
ad20fd1c64 | ||
|
|
0eb5c0a08a | ||
|
|
7c3a08057d | ||
|
|
c3a43fe677 | ||
|
|
1c613d0a52 | ||
|
|
303ec5be11 | ||
|
|
0e33da7760 | ||
|
|
64c752bea3 | ||
|
|
cb2938b5c2 | ||
|
|
1b8a26d36b | ||
|
|
afdcc88342 | ||
|
|
7238f404f7 | ||
|
|
1b8948a086 | ||
|
|
95ab9bda2d | ||
|
|
ed7f89cfe1 | ||
|
|
8d695d03df | ||
|
|
ad880b5b97 | ||
|
|
c0f3f31095 | ||
|
|
e2ac6a0b17 | ||
|
|
0dba83d8e9 | ||
|
|
245dd47082 | ||
|
|
dc40a05ebd | ||
|
|
0616506b31 | ||
|
|
196ca4f1cb | ||
|
|
2d9677eefa | ||
|
|
cd297150ea | ||
|
|
665f0d0ca7 | ||
|
|
bd1097f7b5 | ||
|
|
f30bb89597 | ||
|
|
9f1f7b989c | ||
|
|
aa8549b633 | ||
|
|
222056f973 | ||
|
|
e431a1ad9e | ||
|
|
452cc46d67 | ||
|
|
c956d075d9 |
20
.docker/000-default.conf
Normal file
20
.docker/000-default.conf
Normal file
@@ -0,0 +1,20 @@
|
||||
<VirtualHost *:8001>
|
||||
ServerAdmin webmaster@localhost
|
||||
DocumentRoot /opt/kimai/public
|
||||
|
||||
PassEnv MAILER_FROM
|
||||
PassEnv APP_ENV
|
||||
PassEnv APP_SECRET
|
||||
PassEnv DATABASE_URL
|
||||
PassEnv MAILER_URL
|
||||
PassEnv TRUSTED_PROXIES
|
||||
|
||||
<Directory "/opt/kimai/public">
|
||||
Require all granted
|
||||
DirectoryIndex index.php
|
||||
AllowOverride All
|
||||
</Directory>
|
||||
|
||||
</VirtualHost>
|
||||
|
||||
ServerName localhost
|
||||
51
.docker/dbtest.php
Normal file
51
.docker/dbtest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
$DATABASE_HOST = urldecode($argv[1]);
|
||||
$DATABASE_BASE = urldecode($argv[2]);
|
||||
$DATABASE_PORT = $argv[3];
|
||||
$DATABASE_USER = urldecode($argv[4]);
|
||||
$DATABASE_PASS = urldecode($argv[5]);
|
||||
|
||||
echo "Testing DB:";
|
||||
|
||||
try {
|
||||
$pdo = new \PDO("mysql:host=$DATABASE_HOST;dbname=$DATABASE_BASE;port=$DATABASE_PORT", "$DATABASE_USER", "$DATABASE_PASS", [
|
||||
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
|
||||
]);
|
||||
} catch(\Exception $ex) {
|
||||
switch ($ex->getCode()) {
|
||||
case 1045:
|
||||
// we can immediately stop here and show the error message
|
||||
echo 'Access denied (1045)';
|
||||
die(1);
|
||||
case 1049:
|
||||
// error "Unknown database (1049)" can be ignored, the database will be created by Kimai
|
||||
return;
|
||||
// a lot of errors share the same meaningless error code zero
|
||||
case 0:
|
||||
// this error includes the database name, so we can only search for the static part of the error message
|
||||
if (stripos($ex->getMessage(), 'SQLSTATE[HY000] [1049] Unknown database') !== false) {
|
||||
// error "Unknown database (1049)" can be ignored, the database will be created by Kimai
|
||||
return;
|
||||
}
|
||||
switch ($ex->getMessage()) {
|
||||
// eg. no response (fw) - the startup script should retry it a couple of times
|
||||
case 'SQLSTATE[HY000] [2002] Operation timed out':
|
||||
echo 'Operation timed out (0-2002)';
|
||||
die(4);
|
||||
// special case "localhost" with a stopped db server (should not happen in docker compose setup)
|
||||
case 'SQLSTATE[HY000] [2002] No such file or directory':
|
||||
echo 'Connection could not be established (0-2002)';
|
||||
die(5);
|
||||
// using IP with stopped db server - the startup script should retry it a couple of times
|
||||
case 'SQLSTATE[HY000] [2002] Connection refused':
|
||||
echo 'Connection refused (0-2002)';
|
||||
die(5);
|
||||
}
|
||||
echo $ex->getMessage() . " (0)";
|
||||
die(7);
|
||||
default:
|
||||
// unknown error
|
||||
echo $ex->getMessage() . " (?)";
|
||||
die(10);
|
||||
}
|
||||
}
|
||||
102
.docker/entrypoint.sh
Executable file
102
.docker/entrypoint.sh
Executable file
@@ -0,0 +1,102 @@
|
||||
#!/bin/bash -x
|
||||
|
||||
KIMAI=$(cat /opt/kimai/version.txt)
|
||||
echo $KIMAI
|
||||
|
||||
function waitForDB() {
|
||||
# Parse sql connection data
|
||||
DATABASE_USER=$(awk -F '[/:@]' '{print $4}' <<< "$DATABASE_URL")
|
||||
DATABASE_PASS=$(awk -F '[/:@]' '{print $5}' <<< "$DATABASE_URL")
|
||||
DATABASE_HOST=$(awk -F '[/:@]' '{print $6}' <<< "$DATABASE_URL")
|
||||
DATABASE_PORT=$(awk -F '[/:@]' '{print $7}' <<< "$DATABASE_URL")
|
||||
DATABASE_BASE=$(awk -F '[/?]' '{print $4}' <<< "$DATABASE_URL")
|
||||
|
||||
re='^[0-9]+$'
|
||||
if ! [[ $DATABASE_PORT =~ $re ]] ; then
|
||||
DATABASE_PORT=3306
|
||||
fi
|
||||
|
||||
echo "Wait for database connection ..."
|
||||
until php /dbtest.php "$DATABASE_HOST" "$DATABASE_BASE" "$DATABASE_PORT" "$DATABASE_USER" "$DATABASE_PASS"; do
|
||||
echo Checking DB: $?
|
||||
sleep 3
|
||||
done
|
||||
echo "Connection established"
|
||||
}
|
||||
|
||||
function handleStartup() {
|
||||
# set mem limits and copy in custom logger config
|
||||
if [ -z "$memory_limit" ]; then
|
||||
memory_limit=512M
|
||||
fi
|
||||
sed -i "s/memory_limit.*/memory_limit=$memory_limit/g" /usr/local/etc/php/php.ini
|
||||
cp /assets/monolog.yaml /opt/kimai/config/packages/monolog.yaml
|
||||
|
||||
if [ -z "$USER_ID" ]; then
|
||||
USER_ID=$(id -u www-data)
|
||||
fi
|
||||
if [ -z "$GROUP_ID" ]; then
|
||||
GROUP_ID=$(id -g www-data)
|
||||
fi
|
||||
|
||||
# if group doesn't exist
|
||||
if grep -w "$GROUP_ID" /etc/group &>/dev/null; then
|
||||
echo Group already exists
|
||||
else
|
||||
echo www-kimai:x:"$GROUP_ID": >> /etc/group
|
||||
grpconv
|
||||
fi
|
||||
|
||||
# if user doesn't exist
|
||||
if id "$USER_ID" &>/dev/null; then
|
||||
echo User already exists
|
||||
else
|
||||
echo www-kimai:x:"$USER_ID":"$GROUP_ID":www-kimai:/var/www:/usr/sbin/nologin >> /etc/passwd
|
||||
pwconv
|
||||
fi
|
||||
|
||||
if [ -e /use_apache ]; then
|
||||
export APACHE_RUN_USER=$(id -nu "$USER_ID")
|
||||
# This doesn't _exactly_ run as the specified GID, it runs as the GID of the specified user but WTF
|
||||
export APACHE_RUN_GROUP=$(id -ng "$USER_ID")
|
||||
export APACHE_PID_FILE=/var/run/apache2/apache2.pid
|
||||
export APACHE_RUN_DIR=/var/run/apache2
|
||||
export APACHE_LOCK_DIR=/var/lock/apache2
|
||||
export APACHE_LOG_DIR=/var/log/apache2
|
||||
export LANG=C
|
||||
elif [ -e /use_fpm ]; then
|
||||
sed -i "s/user = .*/user = $USER_ID/g" /usr/local/etc/php-fpm.d/www.conf
|
||||
sed -i "s/group = .*/group = $GROUP_ID/g" /usr/local/etc/php-fpm.d/www.conf
|
||||
echo "Setting fpm to run as ${USER_ID}:${GROUP_ID}"
|
||||
else
|
||||
echo "Error, unknown server type"
|
||||
fi
|
||||
}
|
||||
|
||||
function prepareKimai() {
|
||||
# These are idempotent, so we can run them on every start-up
|
||||
/opt/kimai/bin/console -n kimai:install
|
||||
if [ ! -z "$ADMINPASS" ] && [ ! -a "$ADMINMAIL" ]; then
|
||||
/opt/kimai/bin/console kimai:user:create admin "$ADMINMAIL" ROLE_SUPER_ADMIN "$ADMINPASS"
|
||||
fi
|
||||
echo "$KIMAI" > /opt/kimai/var/installed
|
||||
echo "Kimai is ready"
|
||||
}
|
||||
|
||||
function runServer() {
|
||||
# Just while I'm fixing things
|
||||
/opt/kimai/bin/console kimai:reload --env="$APP_ENV"
|
||||
chown -R $USER_ID:$GROUP_ID /opt/kimai/var
|
||||
if [ -e /use_apache ]; then
|
||||
exec /usr/sbin/apache2 -D FOREGROUND
|
||||
elif [ -e /use_fpm ]; then
|
||||
exec php-fpm
|
||||
else
|
||||
echo "Error, unknown server type"
|
||||
fi
|
||||
}
|
||||
|
||||
waitForDB
|
||||
handleStartup
|
||||
prepareKimai
|
||||
runServer
|
||||
48
.docker/monolog.yaml
Normal file
48
.docker/monolog.yaml
Normal file
@@ -0,0 +1,48 @@
|
||||
when@prod:
|
||||
monolog:
|
||||
channels: ["deprecation"]
|
||||
handlers:
|
||||
main:
|
||||
type: fingers_crossed
|
||||
action_level: error
|
||||
handler: nested
|
||||
excluded_http_codes: [403, 404]
|
||||
nested:
|
||||
type: stream
|
||||
level: info
|
||||
path: php://stderr
|
||||
console:
|
||||
type: console
|
||||
process_psr_3_messages: false
|
||||
channels: ["!event", "!doctrine"]
|
||||
deprecation:
|
||||
type: stream
|
||||
channels: ["deprecation"]
|
||||
path: php://stderr
|
||||
|
||||
when@dev:
|
||||
monolog:
|
||||
channels: ["deprecation"]
|
||||
handlers:
|
||||
main:
|
||||
type: stream
|
||||
path: php://stderr
|
||||
level: info
|
||||
channels: ["!event"]
|
||||
console:
|
||||
type: console
|
||||
process_psr_3_messages: false
|
||||
channels: ["!event", "!doctrine", "!console"]
|
||||
deprecation:
|
||||
type: stream
|
||||
channels: ["deprecation"]
|
||||
path: php://stderr
|
||||
|
||||
when@test:
|
||||
monolog:
|
||||
handlers:
|
||||
main:
|
||||
type: stream
|
||||
path: php://stderr
|
||||
level: info
|
||||
channels: ["!event"]
|
||||
@@ -10,6 +10,10 @@ charset = utf-8
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.twig]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.yaml]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
49
.env.dist
49
.env.dist
@@ -1,16 +1,47 @@
|
||||
# Configure your database connection and set the correct server version:
|
||||
# for MySQL "serverVersion=5.7" and for MariaDB "serverVersion=mariadb-10.5.8"
|
||||
DATABASE_URL=mysql://user:password@127.0.0.1:3306/database?charset=utf8&serverVersion=5.7
|
||||
# Email will be sent with this address as sender
|
||||
#
|
||||
# You should NOT use this file in production, but instead move the environment variables to your webserver configuration.
|
||||
# The .env file is only existing to simplify the initial setup!
|
||||
#
|
||||
|
||||
#================================================================================
|
||||
# Configure your database connection and set the correct server version.
|
||||
#
|
||||
# You have to replace the following values with your defaults:
|
||||
# - the version "5.7" (the database server version, examples for MySQL and MariaDB below)
|
||||
# - the database username "user"
|
||||
# - the password "password" for "user"
|
||||
# - the database schema "database"
|
||||
# - you might have to adapt port "3306" and server IP "127.0.0.1" as well
|
||||
#
|
||||
# For MySQL that would be "serverVersion=5.7" as in:
|
||||
# DATABASE_URL=mysql://user:password@127.0.0.1:3306/database?charset=utf8mb4&serverVersion=5.7
|
||||
#
|
||||
# For MariaDB it would be "serverVersion=10.5.8-MariaDB":
|
||||
# DATABASE_URL=mysql://user:password@127.0.0.1:3306/database?charset=utf8mb4&serverVersion=10.5.8-MariaDB
|
||||
#
|
||||
DATABASE_URL=mysql://user:password@127.0.0.1:3306/database?charset=utf8mb4&serverVersion=10.5.8-MariaDB
|
||||
|
||||
#================================================================================
|
||||
# The full documentation can be found at https://www.kimai.org/documentation/emails.html
|
||||
#
|
||||
# Email will be sent with this address as sender:
|
||||
MAILER_FROM=kimai@example.com
|
||||
# Email connection (disabled by default) more info at https://www.kimai.org/documentation/emails.html
|
||||
# Email connection (disabled by default) - see documentation for the format
|
||||
MAILER_URL=null://null
|
||||
|
||||
#================================================================================
|
||||
# do not change, unless you are developing for Kimai
|
||||
APP_ENV=prod
|
||||
# should be changed to a unique character sequence
|
||||
|
||||
#================================================================================
|
||||
# should be changed to a unique character sequence, used for hashing cookies
|
||||
APP_SECRET=change_this_to_something_unique
|
||||
|
||||
#================================================================================
|
||||
# Running behind reverse proxies? Try these:
|
||||
# TRUSTED_PROXIES=127.0.0.1,127.0.0.2
|
||||
# TRUSTED_HOSTS=localhost|example.com
|
||||
|
||||
#================================================================================
|
||||
# unlikely, that you need to change this one
|
||||
CORS_ALLOW_ORIGIN=^https?://localhost(:[0-9]+)?$
|
||||
# Running behind reverse proxies? Use those:
|
||||
# TRUSTED_PROXIES=127.0.0.1,127.0.0.2
|
||||
# TRUSTED_HOSTS=localhost,example.com
|
||||
|
||||
20
.gitattributes
vendored
Normal file
20
.gitattributes
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
.docker export-ignore
|
||||
.github export-ignore
|
||||
assets export-ignore
|
||||
tests export-ignore
|
||||
.codecov.yml export-ignore
|
||||
.editorconfig export-ignore
|
||||
eslint.config.js export-ignore
|
||||
eslint.config.mjs export-ignore
|
||||
.gitattributes export-ignore
|
||||
.gitignore export-ignore
|
||||
.php-cs-fixer.dist.php export-ignore
|
||||
php-cs-fixer.dist.php export-ignore
|
||||
babel.config.js export-ignore
|
||||
package.json export-ignore
|
||||
php-cs-fixer.sh export-ignore
|
||||
phpstan.neon export-ignore
|
||||
phpstan.sh export-ignore
|
||||
phpunit.xml.dist export-ignore
|
||||
webpack.config.js export-ignore
|
||||
yarn.lock export-ignore
|
||||
3
.github/FUNDING.yml
vendored
3
.github/FUNDING.yml
vendored
@@ -1,2 +1,3 @@
|
||||
github: [kevinpapst]
|
||||
custom: ["https://www.kimai.org/donate/", "https://www.paypal.me/kevinpapst"]
|
||||
open_collective: kimai
|
||||
custom: ["https://www.kimai.org/", "https://www.kimai.cloud/", "https://www.kevinpapst.de/"]
|
||||
|
||||
27
.github/ISSUE_TEMPLATE/bug_report.md
vendored
27
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,27 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Found a problem? Create a report to help us improve Kimai
|
||||
title: ''
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. See error
|
||||
|
||||
**Logfile**
|
||||
```
|
||||
Add the last lines from your logfile at "var/log/prod.log" or "Doctor > Logs", around the time when the problem happened.
|
||||
```
|
||||
|
||||
**Additional context**
|
||||
- Kimai version: ?.?
|
||||
- PHP version: ?.?
|
||||
- Device: [Ubuntu Laptop 16 inch, Windows Desktop 27 inch, iPhone 6s]
|
||||
- Browser [e.g. Firefox 81, Chrome 85, Safari 14]
|
||||
75
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
75
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
name: Bug report
|
||||
description: Create a report to help us improve Kimai
|
||||
labels: [ "bug" ]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thank you for reporting an issue on Kimai! This form will guide you to create a useful issue report.
|
||||
- type: textarea
|
||||
id: what-happened
|
||||
attributes:
|
||||
label: Describe the issue
|
||||
description: "A clear and concise description of the problem you are facing. Is that a browser issue? Then add device information: Ubuntu 20.04 with Brave 1.46, Windows 10 with Chrome 85, iPhone 10, Mac with Safari 16"
|
||||
placeholder: Tell us what you see! Include the steps necessary to reproduce the behavior (e.g. go to, scroll down and click here ...)
|
||||
validations:
|
||||
required: true
|
||||
- type: checkboxes
|
||||
id: tried
|
||||
attributes:
|
||||
label: I already tried
|
||||
description: If you didn’t try already, try to search the documentation and existing issues what you wrote above.
|
||||
options:
|
||||
- label: I've read and searched [the documentation](https://www.kimai.org/documentation/).
|
||||
required: true
|
||||
- label: I've searched for similar issues in this repository.
|
||||
required: true
|
||||
- label: I've searched for similar issues in [the discussions](https://github.com/kimai/kimai/discussions).
|
||||
required: true
|
||||
- type: input
|
||||
id: version
|
||||
attributes:
|
||||
label: Kimai version
|
||||
description: Which version of Kimai are you running (see Doctor/About/Kimai-Cloud screen)
|
||||
placeholder: 1.xx.x or 2.xx.x
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: installation
|
||||
attributes:
|
||||
label: How do you run Kimai?
|
||||
options:
|
||||
- Virtual Server or alike
|
||||
- KIMAI CLOUD
|
||||
- Docker
|
||||
- Synology
|
||||
- Plesk
|
||||
- Shared-Hosting
|
||||
- Other (please mention below)
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
id: php
|
||||
attributes:
|
||||
label: Which PHP version are you using?
|
||||
options:
|
||||
- "8.5"
|
||||
- "8.4"
|
||||
- "8.2"
|
||||
- "8.3"
|
||||
- "8.1"
|
||||
- Unknown
|
||||
- Other (please mention below)
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: logs
|
||||
attributes:
|
||||
label: Logfile
|
||||
description: Please paste the last lines from your logfile at "var/log/prod.log" or "Doctor > Logs", around the time when the problem happened.
|
||||
- type: textarea
|
||||
id: screenshots
|
||||
attributes:
|
||||
label: Screenshots
|
||||
description: If applicable, add screenshots to better explain your problem.
|
||||
|
||||
12
.github/ISSUE_TEMPLATE/config.yml
vendored
12
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1,5 +1,11 @@
|
||||
blank_issues_enabled: false
|
||||
contact_links:
|
||||
- name: "Support / Questions / Discussions"
|
||||
url: https://github.com/kevinpapst/kimai2/discussions
|
||||
about: "This forum is for support questions: eg. if you need help with your Kimai installation, want to know how to use a Kimai feature or wonder where to start creating a new Kimai plugin."
|
||||
- name: Read our documentation
|
||||
url: https://www.kimai.org/documentation/
|
||||
about: Save your time! There is an instant solution for many issues in the documentation.
|
||||
- name: Ask a Question
|
||||
url: https://github.com/kimai/kimai/discussions
|
||||
about: Want to discuss something with a community? Do it in discussions!
|
||||
- name: Get Professional support
|
||||
url: https://www.kimai.org/en/support.html
|
||||
about: As a customer, you will always receive fast replies from the developer.
|
||||
|
||||
40
.github/ISSUE_TEMPLATE/docker.yml
vendored
Normal file
40
.github/ISSUE_TEMPLATE/docker.yml
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
name: Docker issue
|
||||
description: Experiencing an issue with your Docker Setup?
|
||||
labels: [ "docker" ]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thank you for reporting an issue with your docker setup! This form will guide you to create a useful issue report.
|
||||
- type: textarea
|
||||
id: describe
|
||||
attributes:
|
||||
label: Describe the problem
|
||||
description: >
|
||||
Please provide a clear and concise description of what the issue is and the steps to reproduce the behaviour:
|
||||
1. Start the container '...'
|
||||
2. Click on '....'
|
||||
3. See error xyz
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: environment
|
||||
attributes:
|
||||
label: Describe your setup and add your Docker compose file (redact your credentials)
|
||||
description: >
|
||||
Your working environment:
|
||||
- OS: [e.g. Linux, Windows, Mac]
|
||||
- Docker version: [e.g. 19.03.2]
|
||||
- Docker compose version: [e.g. 1.21.0]
|
||||
|
||||
Docker compose file:
|
||||
version: '3.5'
|
||||
services:
|
||||
image: ...
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: command
|
||||
attributes:
|
||||
label: Command used to run the container
|
||||
description: e.g. docker run -v ....
|
||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -1,20 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea to make Kimai better
|
||||
title: ''
|
||||
labels: feature request
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Screenshot**
|
||||
Add a mockup / screenshot of your idea here.
|
||||
34
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
34
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
name: Feature request
|
||||
description: Suggest an idea to make Kimai better
|
||||
labels: [ "feature request" ]
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
Thank you for reporting an issue on Kimai! This form will guide you to create a useful issue report.
|
||||
- type: textarea
|
||||
id: describe
|
||||
attributes:
|
||||
label: Describe the problem
|
||||
description: >
|
||||
Is your feature request related to a problem? If so, please provide
|
||||
a clear and concise description of what the issue is.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: solution
|
||||
attributes:
|
||||
label: Describe the solution you'd like
|
||||
description: A clear and concise description of what the new feature should do.
|
||||
validations:
|
||||
required: true
|
||||
- type: textarea
|
||||
id: alternatives
|
||||
attributes:
|
||||
label: Describe alternatives you've considered
|
||||
description: A clear and concise description of any alternative solutions or features you've considered.
|
||||
- type: textarea
|
||||
id: screenshots
|
||||
attributes:
|
||||
label: Screenshots
|
||||
description: If applicable, add screenshots to better explain your problem.
|
||||
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
2
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -9,4 +9,4 @@ A clear and concise description of what this pull request adds or changes.
|
||||
## Checklist
|
||||
- [ ] I verified that my code applies to the guidelines (`composer code-check`)
|
||||
- [ ] I updated the documentation (see [here](https://github.com/kimai/www.kimai.org/tree/master/_documentation))
|
||||
- [ ] I agree that this code is used in Kimai and will be published under the [MIT license](https://github.com/kevinpapst/kimai2/blob/master/LICENSE)
|
||||
- [ ] I agree that this code is used in Kimai (see [license](https://github.com/kimai/kimai/blob/main/LICENSE))
|
||||
|
||||
29
.github/release-drafter.yml
vendored
Normal file
29
.github/release-drafter.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
name-template: '$RESOLVED_VERSION'
|
||||
tag-template: '$RESOLVED_VERSION'
|
||||
exclude-labels:
|
||||
- 'duplicate'
|
||||
- 'invalid'
|
||||
- 'wontfix'
|
||||
- 'release'
|
||||
exclude-contributors:
|
||||
- 'dependabot'
|
||||
- 'weblate'
|
||||
change-template: '- $TITLE (#$NUMBER)'
|
||||
change-title-escapes: '\<*_&`#@'
|
||||
version-resolver:
|
||||
minor:
|
||||
labels:
|
||||
- 'feature request'
|
||||
- 'release'
|
||||
patch:
|
||||
labels:
|
||||
- 'technical debt'
|
||||
- 'bug'
|
||||
- 'translation'
|
||||
default: patch
|
||||
template: |
|
||||
**Compatible with PHP 8.1 to 8.5**
|
||||
|
||||
$CHANGES
|
||||
|
||||
Involved in this release: $CONTRIBUTORS
|
||||
69
.github/workflows/coverage.yaml
vendored
69
.github/workflows/coverage.yaml
vendored
@@ -1,69 +0,0 @@
|
||||
name: Coverage
|
||||
on:
|
||||
pull_request: null
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
tests:
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:5.7
|
||||
env:
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: false
|
||||
MYSQL_ROOT_PASSWORD: kimai
|
||||
MYSQL_DATABASE: kimai
|
||||
ports:
|
||||
- 3306/tcp
|
||||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
|
||||
strategy:
|
||||
matrix:
|
||||
php: ['8.0']
|
||||
|
||||
name: Coverage (${{ matrix.php }})
|
||||
steps:
|
||||
|
||||
- name: Clone Kimai
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
coverage: pcov
|
||||
extensions: mbstring, xml, ctype, iconv, intl, mysql, zip, gd, ldap
|
||||
|
||||
- name: Determine composer cache directory
|
||||
id: composer-cache
|
||||
run: "echo \"::set-output name=directory::$(composer config cache-dir)\""
|
||||
|
||||
- name: Cache Composer dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: "${{ steps.composer-cache.outputs.directory }}"
|
||||
key: ${{ runner.os }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install
|
||||
|
||||
- name: Install LDAP package
|
||||
run: composer require laminas/laminas-ldap
|
||||
|
||||
- name: Setup problem matchers for PHPUnit
|
||||
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
|
||||
|
||||
- name: Run tests
|
||||
run: vendor/bin/phpunit tests/ --coverage-clover=coverage.xml
|
||||
env:
|
||||
DATABASE_URL: mysql://root:kimai@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/kimai?serverVersion=5.7
|
||||
APP_ENV: dev
|
||||
MAILER_URL: null://localhost
|
||||
TEST_WITH_BUNDLES: 1
|
||||
|
||||
- name: Upload code coverage
|
||||
uses: codecov/codecov-action@v2
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
files: ./coverage.xml
|
||||
fail_ci_if_error: true
|
||||
102
.github/workflows/docker.yaml
vendored
102
.github/workflows/docker.yaml
vendored
@@ -1,17 +1,93 @@
|
||||
name: 'Docker Build'
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [released]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
kimai_tag:
|
||||
description: 'Kimai tag to build'
|
||||
required: true
|
||||
release:
|
||||
types: [released]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Dispatch release event to tobybatch
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Emit repository_dispatch
|
||||
uses: mvasigh/dispatch-action@1.1.6
|
||||
with:
|
||||
token: ${{ secrets.DOCKER_ACCESS_TOKEN }}
|
||||
repo: kimai2
|
||||
owner: tobybatch
|
||||
event_type: kimai_release
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Install buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
username: ${{secrets.DOCKERHUB_USERNAME}}
|
||||
password: ${{secrets.DOCKERHUB_PASSWORD}}
|
||||
|
||||
- name: Determine version
|
||||
run: |
|
||||
input="${{ github.event.inputs.kimai_tag }}"
|
||||
|
||||
# Determine between manual trigger and release event
|
||||
if [ -z "$input" ]; then
|
||||
echo "Using release tag: ${{ github.event.release.tag_name }}"
|
||||
version="${{ github.event.release.tag_name }}"
|
||||
else
|
||||
echo "Using tag provided: $input"
|
||||
version="$input"
|
||||
fi
|
||||
|
||||
if [[ ! $version =~ ^2\.(0|[1-9]*)(0?)\.(0|[0-9]*)(0?)$ ]]; then
|
||||
echo "Invalid version number: $version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "kimai_version=$version" >> $GITHUB_ENV
|
||||
|
||||
- name: FPM image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile
|
||||
build-args: |
|
||||
KIMAI=${{ env.kimai_version }}
|
||||
BASE=fpm
|
||||
target: prod
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: |
|
||||
kimai/kimai2:latest
|
||||
kimai/kimai2:fpm
|
||||
push: true
|
||||
|
||||
- name: Apache image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile
|
||||
build-args: |
|
||||
KIMAI=${{ env.kimai_version }}
|
||||
BASE=apache
|
||||
target: prod
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: |
|
||||
kimai/kimai2:stable
|
||||
kimai/kimai2:apache
|
||||
kimai/kimai2:apache-${{ env.kimai_version }}
|
||||
push: true
|
||||
|
||||
- name: Development image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: Dockerfile
|
||||
build-args: |
|
||||
KIMAI=${{ env.kimai_version }}
|
||||
BASE=apache
|
||||
target: dev
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: |
|
||||
kimai/kimai2:dev
|
||||
push: true
|
||||
|
||||
29
.github/workflows/lock-threads.yaml
vendored
Normal file
29
.github/workflows/lock-threads.yaml
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
name: 'Lock Threads'
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '17 1 * * *'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
issues: write
|
||||
pull-requests: write
|
||||
|
||||
concurrency:
|
||||
group: lock-threads
|
||||
|
||||
jobs:
|
||||
action:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: dessant/lock-threads@v6
|
||||
with:
|
||||
process-only: 'issues, prs'
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
issue-inactive-days: '90'
|
||||
issue-comment: >
|
||||
This thread has been automatically locked since there has not been any recent activity after it was closed.
|
||||
Please share your experience with the community and [leave a testimonial](https://love.kimai.org/) to support Kimai.
|
||||
issue-lock-reason: 'resolved'
|
||||
pr-inactive-days: '180'
|
||||
log-output: true
|
||||
56
.github/workflows/lock.yaml
vendored
56
.github/workflows/lock.yaml
vendored
@@ -1,56 +0,0 @@
|
||||
name: 'Lock Threads'
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
issues: write
|
||||
pull-requests: write
|
||||
|
||||
concurrency:
|
||||
group: lock
|
||||
|
||||
jobs:
|
||||
action:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: dessant/lock-threads@v3
|
||||
with:
|
||||
github-token: ${{ github.token }}
|
||||
issue-inactive-days: '180'
|
||||
exclude-issue-created-before: ''
|
||||
exclude-issue-created-after: ''
|
||||
exclude-issue-created-between: ''
|
||||
exclude-issue-closed-before: ''
|
||||
exclude-issue-closed-after: ''
|
||||
exclude-issue-closed-between: ''
|
||||
include-any-issue-labels: ''
|
||||
include-all-issue-labels: ''
|
||||
exclude-any-issue-labels: ''
|
||||
add-issue-labels: ''
|
||||
remove-issue-labels: ''
|
||||
issue-comment: >
|
||||
This thread has been automatically locked since there has not been
|
||||
any recent activity after it was closed. Please open a new issue for
|
||||
related bugs.
|
||||
If you use Kimai on a daily basis, please [consider donating](https://www.kimai.org/donate/) to
|
||||
support further development of Kimai.
|
||||
issue-lock-reason: 'resolved'
|
||||
pr-inactive-days: '180'
|
||||
exclude-pr-created-before: ''
|
||||
exclude-pr-created-after: ''
|
||||
exclude-pr-created-between: ''
|
||||
exclude-pr-closed-before: ''
|
||||
exclude-pr-closed-after: ''
|
||||
exclude-pr-closed-between: ''
|
||||
include-any-pr-labels: ''
|
||||
include-all-pr-labels: ''
|
||||
exclude-any-pr-labels: ''
|
||||
add-pr-labels: ''
|
||||
remove-pr-labels: ''
|
||||
pr-comment: ''
|
||||
pr-lock-reason: ''
|
||||
process-only: ''
|
||||
log-output: false
|
||||
16
.github/workflows/lockfiles.yaml
vendored
16
.github/workflows/lockfiles.yaml
vendored
@@ -1,21 +1,21 @@
|
||||
name: Check .lock files
|
||||
on:
|
||||
pull_request: null
|
||||
pull_request_target: null
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
|
||||
permissions:
|
||||
pull-requests: read
|
||||
|
||||
jobs:
|
||||
lockfiles:
|
||||
runs-on: ubuntu-latest
|
||||
name: Verify lock file integrity
|
||||
steps:
|
||||
|
||||
- name: Clone Kimai
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Prevent file change
|
||||
uses: xalvarez/prevent-file-change-action@v1
|
||||
uses: xalvarez/prevent-file-change-action@v3
|
||||
with:
|
||||
githubToken: ${{ secrets.GITHUB_TOKEN }}
|
||||
pattern: .*.lock
|
||||
pattern: .*\.lock$|^\.github\/.*$
|
||||
trustedAuthors: kevinpapst, dependabot
|
||||
|
||||
30
.github/workflows/release-drafter.yaml
vendored
Normal file
30
.github/workflows/release-drafter.yaml
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
name: Release Drafter
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
correct_repository:
|
||||
permissions:
|
||||
contents: none
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: fail on fork
|
||||
if: github.repository_owner != 'kimai'
|
||||
run: exit 1
|
||||
|
||||
update_release_draft:
|
||||
permissions:
|
||||
contents: write # for release-drafter/release-drafter to create a github release
|
||||
pull-requests: read
|
||||
needs: correct_repository
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: release-drafter/release-drafter@v7
|
||||
env:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
86
.github/workflows/testing.yaml
vendored
86
.github/workflows/testing.yaml
vendored
@@ -3,13 +3,13 @@ on:
|
||||
pull_request: null
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
jobs:
|
||||
integration:
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:5.7
|
||||
image: mysql:latest
|
||||
env:
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: false
|
||||
MYSQL_ROOT_PASSWORD: kimai
|
||||
@@ -19,75 +19,96 @@ jobs:
|
||||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
|
||||
strategy:
|
||||
matrix:
|
||||
php: ['7.4', '8.0', '8.1']
|
||||
php: ['8.1', '8.2', '8.3', '8.4', '8.5']
|
||||
|
||||
name: Integration (${{ matrix.php }})
|
||||
steps:
|
||||
|
||||
- name: Clone Kimai
|
||||
uses: actions/checkout@v2
|
||||
uses: actions/checkout@v6
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
coverage: none
|
||||
extensions: mbstring, xml, ctype, iconv, intl, mysql, zip, gd, ldap
|
||||
tools: cs2pr:1.1.0, symfony-cli
|
||||
coverage: pcov
|
||||
extensions: ctype, gd, iconv, intl, ldap, mbstring, mysql, xml, zip
|
||||
tools: cs2pr, symfony-cli
|
||||
env:
|
||||
fail-fast: true
|
||||
|
||||
- name: Determine software versions
|
||||
run: mysql --version && php --version
|
||||
|
||||
- name: Determine composer cache directory
|
||||
id: composer-cache
|
||||
run: "echo \"::set-output name=directory::$(composer config cache-dir)\""
|
||||
run: echo "composer_cache_directory=$(composer config cache-dir)" >> $GITHUB_ENV
|
||||
|
||||
- name: Cache Composer dependencies
|
||||
uses: actions/cache@v2
|
||||
uses: actions/cache@v5
|
||||
with:
|
||||
path: "${{ steps.composer-cache.outputs.directory }}"
|
||||
path: "${{ env.composer_cache_directory }}"
|
||||
key: ${{ runner.os }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install
|
||||
|
||||
- name: Validate Composer
|
||||
run: composer validate --strict
|
||||
run: composer validate --strict --no-check-all
|
||||
|
||||
- name: Warmup cache for PHPStan
|
||||
- name: Warmup cache
|
||||
run: APP_ENV=dev bin/console kimai:reload -n
|
||||
|
||||
- name: Check codestyles
|
||||
run: vendor/bin/php-cs-fixer fix --dry-run --verbose --config=.php-cs-fixer.dist.php --using-cache=no --show-progress=none --format=checkstyle | cs2pr
|
||||
|
||||
- name: Run PHPStan on Codebase
|
||||
run: vendor/bin/phpstan analyse src -c phpstan.neon --level=5 --no-progress --error-format=checkstyle | cs2pr
|
||||
- name: Run PHPStan for application
|
||||
run: vendor/bin/phpstan analyse -c phpstan.neon --no-progress --error-format=checkstyle | cs2pr
|
||||
|
||||
- name: Run PHPStan on Tests
|
||||
run: vendor/bin/phpstan analyse tests -c tests/phpstan.neon --level=5 --no-progress --error-format=checkstyle | cs2pr
|
||||
- name: Run PHPStan for tests
|
||||
run: vendor/bin/phpstan analyse -c tests/phpstan.neon --no-progress --error-format=checkstyle | cs2pr
|
||||
|
||||
- name: Lint codebase
|
||||
run: composer linting
|
||||
|
||||
- name: Check for security issues in packages
|
||||
run: symfony security:check
|
||||
|
||||
- name: Install LDAP package
|
||||
- name: Install LDAP package (for tests)
|
||||
run: composer require laminas/laminas-ldap
|
||||
|
||||
- name: Setup problem matchers for PHPUnit
|
||||
- name: Setup problem matchers (for PHPUnit)
|
||||
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
|
||||
|
||||
- name: Run unit tests
|
||||
run: composer kimai:tests-unit
|
||||
- name: Run quick unit-tests
|
||||
run: composer tests-unit
|
||||
env:
|
||||
DATABASE_URL: mysql://root:kimai@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/kimai?serverVersion=5.7
|
||||
DATABASE_URL: mysql://root:kimai@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/kimai?charset=utf8mb4&serverVersion=8.0.35
|
||||
APP_ENV: test
|
||||
MAILER_URL: null://localhost
|
||||
|
||||
- name: Full test-suite
|
||||
if: matrix.php != '8.5'
|
||||
run: vendor/bin/phpunit tests/
|
||||
env:
|
||||
DATABASE_URL: mysql://root:kimai@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/kimai?charset=utf8mb4&serverVersion=8.0.35
|
||||
APP_ENV: test
|
||||
MAILER_URL: null://localhost
|
||||
|
||||
- name: Full test-suite with coverage
|
||||
if: matrix.php == '8.5'
|
||||
run: vendor/bin/phpunit tests/ --coverage-clover=coverage.xml
|
||||
env:
|
||||
DATABASE_URL: mysql://root:kimai@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/kimai?charset=utf8mb4&serverVersion=8.0.35
|
||||
APP_ENV: dev
|
||||
MAILER_URL: null://localhost
|
||||
|
||||
- name: Run integration tests
|
||||
run: composer kimai:tests-integration
|
||||
env:
|
||||
DATABASE_URL: mysql://root:kimai@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/kimai?serverVersion=5.7
|
||||
APP_ENV: dev
|
||||
MAILER_URL: null://localhost
|
||||
- name: Upload code coverage
|
||||
if: matrix.php == '8.5'
|
||||
uses: codecov/codecov-action@v6
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
files: ./coverage.xml
|
||||
fail_ci_if_error: true
|
||||
|
||||
- name: Run migrations on MySQL
|
||||
run: |
|
||||
@@ -96,6 +117,9 @@ jobs:
|
||||
bin/console doctrine:migrations:migrate -n
|
||||
bin/console doctrine:migrations:migrate first -n
|
||||
env:
|
||||
DATABASE_URL: mysql://root:kimai@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/kimai?serverVersion=5.7
|
||||
DATABASE_URL: mysql://root:kimai@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/kimai?charset=utf8mb4&serverVersion=8.0.35
|
||||
APP_ENV: dev
|
||||
MAILER_URL: null://localhost
|
||||
|
||||
- name: Check for security issues in packages
|
||||
run: symfony security:check
|
||||
|
||||
42
.github/workflows/website.yaml
vendored
Normal file
42
.github/workflows/website.yaml
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
name: 'Website update'
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
kimai_version:
|
||||
description: 'Kimai version for the website'
|
||||
required: true
|
||||
release:
|
||||
types: [released]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Trigger version update for website
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: "Determine Version"
|
||||
run: |
|
||||
input="${{ github.event.inputs.kimai_version }}"
|
||||
|
||||
# Determine between manual trigger and release event
|
||||
if [ -z "$input" ]; then
|
||||
echo "No input provided, using release tag"
|
||||
version="${{ github.event.release.tag_name }}"
|
||||
else
|
||||
echo "Using input provided: $input"
|
||||
version="$input"
|
||||
fi
|
||||
|
||||
echo "kimai_version=$version" >> $GITHUB_ENV
|
||||
|
||||
if [[ ! $version =~ ^2\.(0|[1-9]*)(0?)\.(0|[0-9]*)(0?)$ ]]; then
|
||||
echo "Invalid version number: $version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Emit repository_dispatch
|
||||
uses: peter-evans/repository-dispatch@v4
|
||||
with:
|
||||
token: ${{ secrets.WEBSITE_ACCESS_TOKEN }}
|
||||
repository: kimai/www.kimai.org
|
||||
event-type: kimai_release
|
||||
client-payload: '{"kimai_version": "${{ env.kimai_version }}"}'
|
||||
@@ -1,5 +0,0 @@
|
||||
unreleased=true
|
||||
future-release=1.20
|
||||
exclude-labels=duplicate,support,question,invalid,wontfix,release,waiting for feedback,documentation
|
||||
enhancement_labels=>enhancement,Enhancement,feature request,translation i18n,technical debt,documentation
|
||||
issues-wo-labels=false
|
||||
63
.gitignore
vendored
63
.gitignore
vendored
@@ -1,48 +1,42 @@
|
||||
# ========== KIMAI ==========
|
||||
# some hosters require a htaccess to change the PHP version
|
||||
.htaccess
|
||||
.env-*
|
||||
.idea/
|
||||
/public/.htaccess
|
||||
/.env-*
|
||||
/.idea/
|
||||
.DS_Store
|
||||
var/templates/
|
||||
|
||||
|
||||
# custom apache rules e.g. to deactivate ioncube loader
|
||||
/public/.user.ini
|
||||
|
||||
# for symfony local webserver
|
||||
php.ini
|
||||
/php.ini
|
||||
/.php-version
|
||||
|
||||
/bin/*
|
||||
!bin/console
|
||||
# YARN 2
|
||||
/.yarnrc.yml
|
||||
/.yarn
|
||||
/.pnp.*
|
||||
|
||||
# for keeping empty directories
|
||||
/config/packages/local.yaml
|
||||
/config/packages/*-local.yaml
|
||||
/config/packages/*/local.yaml
|
||||
/config/packages/*/*-local.yaml
|
||||
/config/bundles-local.php
|
||||
|
||||
public/avatars/*.png
|
||||
|
||||
templates/invoice/renderer/.~lock*
|
||||
translations/branding.*.xlf
|
||||
|
||||
/var/dev/*
|
||||
/var/data/*
|
||||
!/var/data/.gitkeep
|
||||
/var/coverage/
|
||||
/var/cache/*
|
||||
!var/cache/.gitkeep
|
||||
|
||||
/var/invoices/*
|
||||
/var/export/*
|
||||
|
||||
/var/packages/*
|
||||
!var/packages/.gitkeep
|
||||
/var/plugins/*
|
||||
!var/plugins/.gitkeep
|
||||
|
||||
/var/invoices*
|
||||
/var/export*
|
||||
/var/log/*
|
||||
!var/log/.gitkeep
|
||||
|
||||
/var/sessions/*
|
||||
!var/sessions/.gitkeep
|
||||
# ========== KIMAI ==========
|
||||
/var/packages/*
|
||||
/var/plugins*
|
||||
/var/plugins/*/*.disabled
|
||||
|
||||
###> symfony/framework-bundle ###
|
||||
/.env.local
|
||||
/.env.local.php
|
||||
/.env.*.local
|
||||
/config/secrets/prod/prod.decrypt.private.php
|
||||
.env
|
||||
/public/bundles/
|
||||
/vendor/
|
||||
@@ -61,7 +55,6 @@ translations/branding.*.xlf
|
||||
|
||||
###> symfony/phpunit-bridge ###
|
||||
.phpunit
|
||||
/phpunit.xml
|
||||
###< symfony/phpunit-bridge ###
|
||||
|
||||
###> symfony/webpack-encore-bundle ###
|
||||
@@ -69,4 +62,6 @@ translations/branding.*.xlf
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
###< symfony/webpack-encore-bundle ###
|
||||
/nbproject/*
|
||||
/nbproject/*
|
||||
|
||||
.dockerhub.secrets
|
||||
|
||||
@@ -8,13 +8,19 @@ file that was distributed with this source code.
|
||||
COMMENT;
|
||||
|
||||
$fixer = new PhpCsFixer\Config();
|
||||
$fixer->setUnsupportedPhpVersionAllowed(true);
|
||||
$fixer
|
||||
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
|
||||
->setRiskyAllowed(true)
|
||||
->setRules([
|
||||
'encoding' => true,
|
||||
'full_opening_tag' => true,
|
||||
'blank_line_after_namespace' => true,
|
||||
'braces' => true,
|
||||
'control_structure_braces' => true,
|
||||
'control_structure_continuation_position' => ['position' => 'same_line'],
|
||||
'declare_parentheses' => true,
|
||||
'no_multiple_statements_per_line' => true,
|
||||
'statement_indentation' => true,
|
||||
'class_definition' => true,
|
||||
'elseif' => true,
|
||||
'function_declaration' => true,
|
||||
@@ -22,14 +28,14 @@ $fixer
|
||||
'line_ending' => true,
|
||||
'constant_case' => ['case' => 'lower'],
|
||||
'lowercase_keywords' => true,
|
||||
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
|
||||
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline', 'after_heredoc' => true],
|
||||
'header_comment' => ['header' => $fileHeaderComment, 'separate' => 'both'],
|
||||
'no_php4_constructor' => true,
|
||||
'ordered_imports' => true,
|
||||
'no_break_comment' => true,
|
||||
'no_closing_tag' => true,
|
||||
'no_spaces_after_function_name' => true,
|
||||
'no_spaces_inside_parenthesis' => true,
|
||||
'spaces_inside_parentheses' => ['space' => 'none'],
|
||||
'no_trailing_whitespace' => true,
|
||||
'no_trailing_whitespace_in_comment' => true,
|
||||
'single_blank_line_at_eof' => true,
|
||||
@@ -38,6 +44,7 @@ $fixer
|
||||
'single_line_after_imports' => true,
|
||||
'switch_case_semicolon_to_colon' => true,
|
||||
'switch_case_space' => true,
|
||||
'php_unit_method_casing' => true,
|
||||
'array_syntax' => [
|
||||
'syntax' => 'short'
|
||||
],
|
||||
@@ -50,13 +57,13 @@ $fixer
|
||||
'class_attributes_separation' => ['elements' => ['method' => 'one']],
|
||||
'concat_space' => ['spacing' => 'one'],
|
||||
'declare_equal_normalize' => true,
|
||||
'function_typehint_space' => true,
|
||||
'type_declaration_spaces' => ['elements' => ['function', 'property']],
|
||||
'include' => true,
|
||||
'lowercase_cast' => true,
|
||||
'lowercase_static_reference' => true,
|
||||
'magic_constant_casing' => true,
|
||||
'native_function_casing' => true,
|
||||
'new_with_braces' => true,
|
||||
'new_with_parentheses' => true,
|
||||
'no_blank_lines_after_class_opening' => true,
|
||||
'no_blank_lines_after_phpdoc' => true,
|
||||
'no_empty_comment' => true,
|
||||
@@ -77,9 +84,8 @@ $fixer
|
||||
'no_short_bool_cast' => true,
|
||||
'no_singleline_whitespace_before_semicolons' => true,
|
||||
'no_spaces_around_offset' => true,
|
||||
'no_trailing_comma_in_list_call' => true,
|
||||
'no_trailing_comma_in_singleline_array' => true,
|
||||
'no_unneeded_curly_braces' => true,
|
||||
'no_trailing_comma_in_singleline' => true,
|
||||
'no_unneeded_braces' => true,
|
||||
'no_unneeded_final_method' => true,
|
||||
'no_unused_imports' => true,
|
||||
'no_whitespace_before_comma_in_array' => true,
|
||||
@@ -120,7 +126,7 @@ $fixer
|
||||
'return_type_declaration' => true,
|
||||
'semicolon_after_instruction' => true,
|
||||
'short_scalar_cast' => true,
|
||||
'single_blank_line_before_namespace' => true,
|
||||
'blank_lines_before_namespace' => ['min_line_breaks' => 2, 'max_line_breaks' => 2],
|
||||
'single_line_comment_style' => [
|
||||
'comment_types' => ['hash'],
|
||||
],
|
||||
@@ -137,7 +143,7 @@ $fixer
|
||||
'whitespace_after_comma_in_array' => true,
|
||||
'yoda_style' => false,
|
||||
'ternary_to_null_coalescing' => true,
|
||||
'visibility_required' => ['elements' => [
|
||||
'modifier_keywords' => ['elements' => [
|
||||
'const',
|
||||
'method',
|
||||
'property',
|
||||
@@ -148,16 +154,26 @@ $fixer
|
||||
],
|
||||
'scope' => 'namespaced'
|
||||
],
|
||||
'native_function_type_declaration_casing' => true,
|
||||
'native_type_declaration_casing' => true,
|
||||
'no_alias_functions' => [
|
||||
'sets' => [
|
||||
'@internal'
|
||||
]
|
||||
],
|
||||
'list_syntax' => ['syntax' => 'short'],
|
||||
'assign_null_coalescing_to_coalesce_equal' => true,
|
||||
'non_printable_character' => true,
|
||||
'octal_notation' => true,
|
||||
'heredoc_indentation' => ['indentation' => 'start_plus_one'],
|
||||
'no_space_around_double_colon' => true,
|
||||
'no_useless_nullsafe_operator' => true,
|
||||
'clean_namespace' => true,
|
||||
'no_unset_cast' => true,
|
||||
])
|
||||
->setFinder(
|
||||
PhpCsFixer\Finder::create()
|
||||
->in([
|
||||
__DIR__ . '/migrations/',
|
||||
__DIR__ . '/src/',
|
||||
__DIR__ . '/tests/',
|
||||
])
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
# Changelog
|
||||
|
||||
See [GitHub release page](https://github.com/kevinpapst/kimai2/releases).
|
||||
See [GitHub release page](https://github.com/kimai/kimai/releases).
|
||||
|
||||
@@ -1,26 +1,16 @@
|
||||
# Contributing
|
||||
|
||||
Kimai is an open source project, contributions made by the community are welcome.
|
||||
Send your ideas, code reviews, pull requests and feature requests to help improving this project.
|
||||
Kimai is an open source project, contributions made by the community are welcome.
|
||||
But we can only accept contributions with a signed CLA (Contributor License Agreement) to prevent issues in the future (you will see a link when opening a PR).
|
||||
|
||||
Send your ideas, code reviews, pull requests and feature requests to help to improve this project.
|
||||
|
||||
## Pull request rules
|
||||
|
||||
- Use the [pre-configured codesniffer](.php_cs.dist)) to check for `composer kimai:codestyle` and fix `composer kimai:codestyle-fix` violations
|
||||
- Add PHPUnit tests for your changes!
|
||||
- Verify everything still works with `composer kimai:tests-unit` and `composer kimai:tests-integration`
|
||||
- If you contribute new files, add them with the file-header template from below (the code-style fixer can do that for you)
|
||||
- When sending in a PR, you must accept that your contributions/code will be published under MIT license (see the [LICENSE](LICENSE) file as well), otherwise your PR will be closed
|
||||
- If one of the PR checks/builds fails, fix it before asking for a review
|
||||
- Make your changes in a new git branch, based on the latest code in `main`
|
||||
- Apply our code-style by running `composer codestyle-fix`
|
||||
- Run the static code analysis with `composer phpstan`
|
||||
- Verify everything still works with `composer tests`
|
||||
- Add tests for your changes
|
||||
|
||||
Further documentation can be found in the [developer documentation](https://www.kimai.org/documentation/developers.html).
|
||||
|
||||
### File-header template
|
||||
```
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
```
|
||||
|
||||
|
||||
330
Dockerfile
Normal file
330
Dockerfile
Normal file
@@ -0,0 +1,330 @@
|
||||
# _ ___ _
|
||||
# | |/ (_)_ __ ___ __ _(_)
|
||||
# | ' /| | '_ ` _ \ / _` | |
|
||||
# | . \| | | | | | | (_| | |
|
||||
# |_|\_\_|_| |_| |_|\__,_|_|
|
||||
#
|
||||
# Kimai images for:
|
||||
# - plain PHP FPM (kimai/kimai2:fpm)
|
||||
# - Apache with PHP (kimai/kimai2:apache)
|
||||
# - Development (kimai/kimai2:dev)
|
||||
# ---------------------------------------------------------------------
|
||||
# For local testing by maintainer:
|
||||
#
|
||||
# docker build --no-cache -t kimai-fpm --build-arg BASE=fpm .
|
||||
# docker build --no-cache -t kimai-apache --build-arg BASE=apache .
|
||||
# docker run -d --name kimai-apache-app kimai-apache
|
||||
# docker exec -ti kimai-apache-app /bin/bash
|
||||
# ---------------------------------------------------------------------
|
||||
# Official PHP images: https://hub.docker.com/_/php/
|
||||
# https://github.com/docker-library/docs/blob/master/php/README.md#supported-tags-and-respective-dockerfile-links
|
||||
# Pass-through Arguments: https://benkyriakou.com/posts/docker-args-empty
|
||||
# Best practices: https://docs.docker.com/build/building/best-practices/
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
# Source base, one of: fpm, apache
|
||||
ARG BASE="fpm"
|
||||
# Kimai branch/tag to run
|
||||
ARG KIMAI="main"
|
||||
# Timezone for images
|
||||
ARG TIMEZONE="Europe/Berlin"
|
||||
|
||||
###########################
|
||||
# Shared tools
|
||||
###########################
|
||||
|
||||
# composer base image
|
||||
FROM composer:latest AS composer
|
||||
|
||||
###########################
|
||||
# PHP extensions
|
||||
###########################
|
||||
|
||||
# fpm alpine php extension base
|
||||
FROM php:8.3-fpm-alpine AS fpm-php-ext-base
|
||||
RUN apk add --no-cache \
|
||||
# build-tools
|
||||
autoconf \
|
||||
dpkg \
|
||||
dpkg-dev \
|
||||
file \
|
||||
g++ \
|
||||
gcc \
|
||||
icu-dev \
|
||||
libatomic \
|
||||
libc-dev \
|
||||
libgomp \
|
||||
libmagic \
|
||||
m4 \
|
||||
make \
|
||||
mpc1 \
|
||||
mpfr4 \
|
||||
musl-dev \
|
||||
perl \
|
||||
re2c \
|
||||
# gd
|
||||
freetype-dev \
|
||||
libpng-dev \
|
||||
# icu
|
||||
icu-dev \
|
||||
icu-data-full \
|
||||
# ldap
|
||||
openldap-dev \
|
||||
libldap \
|
||||
# zip
|
||||
libzip-dev \
|
||||
# xsl
|
||||
libxslt-dev
|
||||
|
||||
# apache debian php extension base
|
||||
FROM php:8.3-apache-bookworm AS apache-php-ext-base
|
||||
RUN apt-get update && \
|
||||
apt-get install -y \
|
||||
libldap2-dev \
|
||||
libicu-dev \
|
||||
libpng-dev \
|
||||
libzip-dev \
|
||||
libxslt1-dev \
|
||||
libfreetype6-dev
|
||||
|
||||
# php extension gd - 13.86s
|
||||
FROM ${BASE}-php-ext-base AS php-ext-gd
|
||||
RUN docker-php-ext-configure gd \
|
||||
--with-freetype && \
|
||||
docker-php-ext-install -j$(nproc) gd
|
||||
|
||||
# php extension intl : 15.26s
|
||||
FROM ${BASE}-php-ext-base AS php-ext-intl
|
||||
RUN docker-php-ext-install -j$(nproc) intl
|
||||
|
||||
# php extension ldap : 8.45s
|
||||
FROM ${BASE}-php-ext-base AS php-ext-ldap
|
||||
RUN docker-php-ext-configure ldap && \
|
||||
docker-php-ext-install -j$(nproc) ldap
|
||||
|
||||
# php extension pdo_mysql : 6.14s
|
||||
FROM ${BASE}-php-ext-base AS php-ext-pdo_mysql
|
||||
RUN docker-php-ext-install -j$(nproc) pdo_mysql
|
||||
|
||||
# php extension zip : 8.18s
|
||||
FROM ${BASE}-php-ext-base AS php-ext-zip
|
||||
RUN docker-php-ext-install -j$(nproc) zip
|
||||
|
||||
# php extension xsl : ?.?? s
|
||||
FROM ${BASE}-php-ext-base AS php-ext-xsl
|
||||
RUN docker-php-ext-install -j$(nproc) xsl
|
||||
|
||||
# php extension opcache
|
||||
FROM ${BASE}-php-ext-base AS php-ext-opcache
|
||||
RUN docker-php-ext-install -j$(nproc) opcache
|
||||
|
||||
###########################
|
||||
# fpm base build
|
||||
###########################
|
||||
|
||||
FROM php:8.3-fpm-alpine AS fpm-base
|
||||
ARG TIMEZONE
|
||||
RUN apk add --no-cache \
|
||||
bash \
|
||||
coreutils \
|
||||
freetype \
|
||||
haveged \
|
||||
icu \
|
||||
icu-data-full \
|
||||
libldap \
|
||||
libpng \
|
||||
libzip \
|
||||
libxslt-dev \
|
||||
fcgi \
|
||||
tzdata && \
|
||||
touch /use_fpm && \
|
||||
sed -i "s/;ping.path/ping.path/g" /usr/local/etc/php-fpm.d/www.conf && \
|
||||
sed -i "s/;access.suppress_path\[\] = \/ping/access.suppress_path\[\] = \/ping/g" /usr/local/etc/php-fpm.d/www.conf
|
||||
|
||||
EXPOSE 9000
|
||||
|
||||
HEALTHCHECK --interval=20s --timeout=10s --retries=3 \
|
||||
CMD \
|
||||
SCRIPT_NAME=/ping \
|
||||
SCRIPT_FILENAME=/ping \
|
||||
REQUEST_METHOD=GET \
|
||||
cgi-fcgi -bind -connect 127.0.0.1:9000 || exit 1
|
||||
|
||||
###########################
|
||||
# apache base build
|
||||
###########################
|
||||
|
||||
FROM php:8.3-apache-bookworm AS apache-base
|
||||
ARG TIMEZONE
|
||||
RUN apt-get update && \
|
||||
apt-get install -y \
|
||||
bash \
|
||||
haveged \
|
||||
libicu72 \
|
||||
libldap-common \
|
||||
libpng16-16 \
|
||||
libzip4 \
|
||||
libxslt1.1 \
|
||||
libfreetype6 \
|
||||
unzip && \
|
||||
echo "Listen 8001" > /etc/apache2/ports.conf && \
|
||||
a2enmod rewrite && \
|
||||
touch /use_apache
|
||||
|
||||
COPY .docker/000-default.conf /etc/apache2/sites-available/000-default.conf
|
||||
|
||||
EXPOSE 8001
|
||||
|
||||
HEALTHCHECK --interval=20s --timeout=10s --retries=3 \
|
||||
CMD curl -f http://127.0.0.1:8001 || exit 1
|
||||
|
||||
###########################
|
||||
# global base build
|
||||
###########################
|
||||
|
||||
FROM ${BASE}-base AS php-base
|
||||
ARG TIMEZONE
|
||||
|
||||
ENV TIMEZONE=${TIMEZONE}
|
||||
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone && \
|
||||
# make composer home dir
|
||||
mkdir /composer && \
|
||||
chown -R www-data:www-data /composer
|
||||
|
||||
# copy composer
|
||||
COPY --from=composer /usr/bin/composer /usr/bin/composer
|
||||
|
||||
# copy php extensions
|
||||
|
||||
# PHP extension xsl
|
||||
COPY --from=php-ext-xsl /usr/local/etc/php/conf.d/docker-php-ext-xsl.ini /usr/local/etc/php/conf.d/docker-php-ext-xsl.ini
|
||||
COPY --from=php-ext-xsl /usr/local/lib/php/extensions/no-debug-non-zts-20230831/xsl.so /usr/local/lib/php/extensions/no-debug-non-zts-20230831/xsl.so
|
||||
# PHP extension pdo_mysql
|
||||
COPY --from=php-ext-pdo_mysql /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini
|
||||
COPY --from=php-ext-pdo_mysql /usr/local/lib/php/extensions/no-debug-non-zts-20230831/pdo_mysql.so /usr/local/lib/php/extensions/no-debug-non-zts-20230831/pdo_mysql.so
|
||||
# PHP extension zip
|
||||
COPY --from=php-ext-zip /usr/local/etc/php/conf.d/docker-php-ext-zip.ini /usr/local/etc/php/conf.d/docker-php-ext-zip.ini
|
||||
COPY --from=php-ext-zip /usr/local/lib/php/extensions/no-debug-non-zts-20230831/zip.so /usr/local/lib/php/extensions/no-debug-non-zts-20230831/zip.so
|
||||
# PHP extension ldap
|
||||
COPY --from=php-ext-ldap /usr/local/etc/php/conf.d/docker-php-ext-ldap.ini /usr/local/etc/php/conf.d/docker-php-ext-ldap.ini
|
||||
COPY --from=php-ext-ldap /usr/local/lib/php/extensions/no-debug-non-zts-20230831/ldap.so /usr/local/lib/php/extensions/no-debug-non-zts-20230831/ldap.so
|
||||
# PHP extension gd
|
||||
COPY --from=php-ext-gd /usr/local/etc/php/conf.d/docker-php-ext-gd.ini /usr/local/etc/php/conf.d/docker-php-ext-gd.ini
|
||||
COPY --from=php-ext-gd /usr/local/lib/php/extensions/no-debug-non-zts-20230831/gd.so /usr/local/lib/php/extensions/no-debug-non-zts-20230831/gd.so
|
||||
# PHP extension intl
|
||||
COPY --from=php-ext-intl /usr/local/etc/php/conf.d/docker-php-ext-intl.ini /usr/local/etc/php/conf.d/docker-php-ext-intl.ini
|
||||
COPY --from=php-ext-intl /usr/local/lib/php/extensions/no-debug-non-zts-20230831/intl.so /usr/local/lib/php/extensions/no-debug-non-zts-20230831/intl.so
|
||||
# PHP extension opcache
|
||||
COPY --from=php-ext-opcache /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
|
||||
|
||||
###########################
|
||||
# fetch Kimai sources
|
||||
###########################
|
||||
|
||||
FROM alpine:latest AS git-prod
|
||||
ARG KIMAI
|
||||
ARG TIMEZONE
|
||||
# the convention in the Kimai repository is: tags are always version numbers, branch names always start with a letter
|
||||
# if the KIMAI variable starts with a number (e.g. 2.24.0) we assume its a tag, otherwise its a branch
|
||||
RUN [[ $KIMAI =~ ^[0-9] ]] && export REF='tags' || export REF='heads' && \
|
||||
wget -O "/opt/kimai.tar.gz" "https://github.com/kimai/kimai/archive/refs/${REF}/${KIMAI}.tar.gz" && \
|
||||
tar -xpzf /opt/kimai.tar.gz -C /opt/ && \
|
||||
mv /opt/kimai-${KIMAI} /opt/kimai
|
||||
|
||||
###########################
|
||||
# global base build
|
||||
###########################
|
||||
|
||||
FROM php-base AS base
|
||||
ARG KIMAI
|
||||
ARG TIMEZONE
|
||||
|
||||
LABEL org.opencontainers.image.title="Kimai" \
|
||||
org.opencontainers.image.description="Kimai is a time-tracking application." \
|
||||
org.opencontainers.image.authors="Kimai Community" \
|
||||
org.opencontainers.image.url="https://www.kimai.org/" \
|
||||
org.opencontainers.image.documentation="https://www.kimai.org/documentation/" \
|
||||
org.opencontainers.image.source="https://github.com/kimai/kimai" \
|
||||
org.opencontainers.image.version="${KIMAI}" \
|
||||
org.opencontainers.image.vendor="Kevin Papst" \
|
||||
org.opencontainers.image.licenses="AGPL-3.0"
|
||||
|
||||
ENV KIMAI=${KIMAI}
|
||||
ENV TIMEZONE=${TIMEZONE}
|
||||
RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone && \
|
||||
mkdir -p /composer && \
|
||||
chown -R www-data:www-data /composer
|
||||
|
||||
# copy startup script & DB checking script
|
||||
COPY .docker/dbtest.php /dbtest.php
|
||||
COPY .docker/entrypoint.sh /entrypoint.sh
|
||||
|
||||
ENV DATABASE_URL="mysql://kimai:kimai@127.0.0.1:3306/kimai?charset=utf8mb4&serverVersion=8.3"
|
||||
ENV APP_SECRET=change_this_to_something_unique
|
||||
# The default container name for nginx is nginx
|
||||
ENV TRUSTED_PROXIES=nginx,localhost,127.0.0.1
|
||||
ENV MAILER_FROM=kimai@example.com
|
||||
ENV MAILER_URL=null://localhost
|
||||
ENV ADMINPASS=
|
||||
ENV ADMINMAIL=
|
||||
ENV USER_ID=
|
||||
ENV GROUP_ID=
|
||||
# default values to configure composer behavior
|
||||
ENV COMPOSER_MEMORY_LIMIT=-1
|
||||
ENV COMPOSER_ALLOW_SUPERUSER=1
|
||||
|
||||
VOLUME [ "/opt/kimai/var" ]
|
||||
|
||||
CMD [ "/entrypoint.sh" ]
|
||||
|
||||
###########################
|
||||
# final builds
|
||||
###########################
|
||||
|
||||
# development build
|
||||
FROM base AS dev
|
||||
# copy kimai develop source
|
||||
COPY --from=git-prod --chown=www-data:www-data /opt/kimai /opt/kimai
|
||||
COPY .docker /assets
|
||||
# do the composer deps installation
|
||||
RUN \
|
||||
export COMPOSER_HOME=/composer && \
|
||||
composer --no-ansi install --working-dir=/opt/kimai --optimize-autoloader && \
|
||||
composer --no-ansi clearcache && \
|
||||
composer --no-ansi require --working-dir=/opt/kimai laminas/laminas-ldap && \
|
||||
cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini && \
|
||||
chown -R www-data:www-data /opt/kimai /usr/local/etc/php/php.ini && \
|
||||
mkdir -p /opt/kimai/var/logs && chmod 777 /opt/kimai/var/logs && \
|
||||
sed "s/128M/-1/g" /usr/local/etc/php/php.ini-development > /opt/kimai/php-cli.ini && \
|
||||
sed -i "s/env php/env -S php -c \/opt\/kimai\/php-cli.ini/g" /opt/kimai/bin/console && \
|
||||
/opt/kimai/bin/console kimai:version | awk '{print $2}' > /opt/kimai/version.txt
|
||||
ENV APP_ENV=dev
|
||||
ENV DATABASE_URL=
|
||||
ENV memory_limit=512M
|
||||
|
||||
# the "prod" stage (production build) is configured as last stage in the file, as this is the default target in BuildKit
|
||||
FROM base AS prod
|
||||
# copy kimai production source
|
||||
COPY --from=git-prod --chown=www-data:www-data /opt/kimai /opt/kimai
|
||||
COPY .docker /assets
|
||||
# do the composer deps installation
|
||||
RUN \
|
||||
export COMPOSER_HOME=/composer && \
|
||||
composer --no-ansi install --working-dir=/opt/kimai --no-dev --optimize-autoloader && \
|
||||
composer --no-ansi clearcache && \
|
||||
composer --no-ansi require --update-no-dev --working-dir=/opt/kimai laminas/laminas-ldap && \
|
||||
cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini && \
|
||||
sed -i "s/expose_php = On/expose_php = Off/g" /usr/local/etc/php/php.ini && \
|
||||
sed -i "s/;opcache.enable=1/opcache.enable=1/g" /usr/local/etc/php/php.ini && \
|
||||
sed -i "s/;opcache.memory_consumption=128/opcache.memory_consumption=256/g" /usr/local/etc/php/php.ini && \
|
||||
sed -i "s/;opcache.interned_strings_buffer=8/opcache.interned_strings_buffer=24/g" /usr/local/etc/php/php.ini && \
|
||||
sed -i "s/;opcache.max_accelerated_files=10000/opcache.max_accelerated_files=100000/g" /usr/local/etc/php/php.ini && \
|
||||
sed -i "s/opcache.validate_timestamps=1/opcache.validate_timestamps=0/g" /usr/local/etc/php/php.ini && \
|
||||
sed -i "s/session.gc_maxlifetime = 1440/session.gc_maxlifetime = 604800/g" /usr/local/etc/php/php.ini && \
|
||||
mkdir -p /opt/kimai/var/logs && chmod 777 /opt/kimai/var/logs && \
|
||||
sed "s/128M/-1/g" /usr/local/etc/php/php.ini-development > /opt/kimai/php-cli.ini && \
|
||||
chown -R www-data:www-data /opt/kimai /usr/local/etc/php/php.ini && \
|
||||
/opt/kimai/bin/console kimai:version | awk '{print $2}' > /opt/kimai/version.txt
|
||||
ENV APP_ENV=prod
|
||||
ENV DATABASE_URL=
|
||||
ENV memory_limit=512M
|
||||
674
LICENSE
674
LICENSE
@@ -1,21 +1,661 @@
|
||||
MIT License
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (c) 2017-2022 Kevin Papst @ https://www.kevinpapst.de
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Preamble
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
116
README.md
116
README.md
@@ -1,89 +1,93 @@
|
||||
<p align="center">
|
||||
<img src="https://raw.githubusercontent.com/kimai/images/master/repository-header.png" alt="Kimai logo">
|
||||
<img src="https://raw.githubusercontent.com/kimai/images/main/repository-header.png" alt="Kimai logo">
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/kevinpapst/kimai2/actions"><img alt="CI Status" src="https://github.com/kevinpapst/kimai2/workflows/CI/badge.svg"></a>
|
||||
<a href="https://codecov.io/gh/kevinpapst/kimai2"><img alt="Code Coverage" src="https://codecov.io/gh/kevinpapst/kimai2/branch/master/graph/badge.svg"></a>
|
||||
<a href="https://packagist.org/packages/kevinpapst/kimai2"><img alt="Latest stable version" src="https://poser.pugx.org/kevinpapst/kimai2/v/stable"></a>
|
||||
<a href="https://packagist.org/packages/kevinpapst/kimai2"><img alt="License" src="https://poser.pugx.org/kevinpapst/kimai2/license"></a>
|
||||
<a href="https://twitter.com/kimai_org"><img alt="Twitter" src="https://img.shields.io/badge/follow-%40kimai__org-00acee"></a>
|
||||
<a href="https://github.com/kimai/kimai/actions"><img alt="CI Status" src="https://github.com/kimai/kimai/actions/workflows/testing.yaml/badge.svg"></a>
|
||||
<a href="https://codecov.io/gh/kimai/kimai"><img alt="Code Coverage" src="https://codecov.io/gh/kimai/kimai/branch/main/graph/badge.svg"></a>
|
||||
<a href="https://packagist.org/packages/kimai/kimai"><img alt="Latest stable version" src="https://poser.pugx.org/kimai/kimai/v/stable"></a>
|
||||
</p>
|
||||
|
||||
<h1 align="center">Kimai - time-tracker</h1>
|
||||
<h1 align="center">Kimai<br>#1 Open-Source Time-Tracker</h1>
|
||||
|
||||
Kimai is a free, open source and online time-tracking software designed for small businesses and freelancers.
|
||||
It is built with modern technologies such as [Symfony](https://github.com/symfony/symfony), [Bootstrap](https://github.com/twbs/bootstrap),
|
||||
[RESTful API](https://github.com/FriendsOfSymfony/FOSRestBundle), [Doctrine](https://github.com/doctrine/),
|
||||
[AdminLTE](https://github.com/kevinpapst/AdminLTEBundle/), [Webpack](https://github.com/webpack/webpack), ES6 and [many](composer.json) [more](package.json).
|
||||
Kimai is a professional grade time-tracking application, free and open-source.
|
||||
It handles use-cases of freelancers as well as companies with dozens or hundreds of users.
|
||||
Kimai was build to track your project times and ships with many advanced features, including but not limited to:
|
||||
|
||||
## Introduction
|
||||
JSON API, invoicing, data exports, multi-timer and punch-in punch-out mode, tagging, multi-user - multi-timezones - multi-language ([over 30 translations existing](https://hosted.weblate.org/projects/kimai/)!),
|
||||
authentication via SAML/LDAP/Database, two-factor authentication (2FA) with TOTP, customizable role and team permissions, responsive design,
|
||||
user/customer/project specific rates, advanced search & filtering, money and time budgets, advanced reporting, support for [plugins](https://www.kimai.org/store/)
|
||||
and so much more.
|
||||
|
||||
- [Home](https://www.kimai.org) - Kimai project homepage
|
||||
- [Blog](https://www.kimai.org/blog/) - Read the latest news
|
||||
- [Documentation](https://www.kimai.org/documentation/) - Learn how to use Kimai
|
||||
- [Translations](https://hosted.weblate.org/projects/kimai/#languages) - Kimai in your language
|
||||
- [Migration](https://www.kimai.org/documentation/migration-v1.html) - Import data from Kimai 1
|
||||
### Links
|
||||
|
||||
- [Home](https://www.kimai.org) — Kimai project homepage
|
||||
- [Blog](https://www.kimai.org/blog/) — Read the latest news
|
||||
- [Documentation](https://www.kimai.org/documentation/) — Learn how to use Kimai
|
||||
|
||||
### Requirements
|
||||
|
||||
- PHP 7.4, 8.0 or 8.1
|
||||
- MariaDB or MySQL
|
||||
- A webserver and subdomain
|
||||
- PHP extensions: `gd`, `intl`, `json`, `mbstring`, `pdo`, `xsl`, `zip`
|
||||
|
||||
### About
|
||||
|
||||
The evolution of the most known(?) open source project time-tracker Kimai. It is stable, production ready and ships
|
||||
with many advanced features, including but not limited to:
|
||||
|
||||
JSON API, invoicing, data exports, multi-timer and punch-in punch-out mode, tagging, multi-user and multi-timezones,
|
||||
authentication via SAML/LDAP/Database, customizable role and team permissions, responsive and ready for your mobile device,
|
||||
user/customer/project specific rates, advanced search & filtering, money and time budgets, reporting, support for plugins
|
||||
and so many more.
|
||||
- PHP 8.1.3 minimum with support for 8.2, 8.3, 8.4, 8.5
|
||||
- MariaDB / MySQL: oldest maintained LTS release (MariaDB >= [10.6](https://endoflife.date/mariadb) or MySQL >= [8.4](https://endoflife.date/mysql)) or newer
|
||||
- A webserver and subdomain (subdirectory is not supported)
|
||||
- PHP extensions: `gd`, `intl`, `json`, `mbstring`, `pdo`, `tokenizer`, `xml`, `xsl`, `zip`
|
||||
|
||||
## Installation
|
||||
|
||||
- [Recommended setup](https://www.kimai.org/documentation/installation.html#recommended-setup) - with Git and Composer
|
||||
- [Docker](https://www.kimai.org/documentation/docker.html) - containerized
|
||||
- [Development](https://www.kimai.org/documentation/installation.html#development-installation) - on your local machine
|
||||
- [1-click installer](https://www.kimai.org/documentation/installation.html#hosting-and-1-click-installations) - hosted environments
|
||||
- Caddy with Docker-Compose at [Hetzner](https://www.kimai.org/documentation/hosting-hetzner-cloud.html) and [DigitalOcean](https://www.kimai.org/documentation/hosting-digital-ocean.html)
|
||||
- [SSH setup](https://www.kimai.org/documentation/installation.html) with Git and Composer
|
||||
- [Docker images](https://hub.docker.com/r/kimai/kimai2) with FPM only or incl. Apache
|
||||
- [Synology](https://www.kimai.org/documentation/synology.html) user can host the Docker version
|
||||
- [Developer setups](https://www.kimai.org/documentation/developers.html) if you want to create Kimai integrations
|
||||
|
||||
There are more documented ways for [on-premise hosting](https://www.kimai.org/documentation/chapter-on-premise.html).
|
||||
|
||||
And if you don't want to host Kimai, you can use the [Cloud version](https://www.kimai.cloud/) of it.
|
||||
|
||||
### Updating Kimai
|
||||
|
||||
- [Update Kimai](https://www.kimai.org/documentation/updates.html) - get the latest version
|
||||
- [UPGRADING guide](UPGRADING.md) - version specific steps
|
||||
- [Update Kimai](https://www.kimai.org/documentation/updates.html) — get the latest version
|
||||
- [UPGRADING guide](UPGRADING.md) — version specific steps
|
||||
|
||||
### Plugins
|
||||
|
||||
- [Plugin marketplace](https://www.kimai.org/store/) - find existing plugins here
|
||||
- [Developer documentation](https://www.kimai.org/documentation/developers.html) - how to create a plugin
|
||||
- [Plugins](https://www.kimai.org/store/) — paid and free plugin marketplace
|
||||
- [Developer documentation](https://www.kimai.org/documentation/developers.html) — how to create a plugin
|
||||
|
||||
## Roadmap and releases
|
||||
|
||||
You can see a rough development roadmap in the [Milestones](https://github.com/kevinpapst/kimai2/milestones) sections.
|
||||
It is open for changes and input from the community, your [ideas and questions](https://github.com/kevinpapst/kimai2/issues) are welcome.
|
||||
You can see a rough development [roadmap](https://github.com/orgs/kimai/projects/2), which is open for changes and input from the community, your [ideas](https://github.com/kimai/kimai/issues) are welcome.
|
||||
|
||||
> Kimai uses a rolling release concept for delivering updates.
|
||||
> You don't have to wait for the next official release, upgrade it at any time from the master branch,
|
||||
> which is always deployable - release tags are simple snapshots of the development version.
|
||||
|
||||
Release versions will be created on a regular base (approx. one release every 2 months).
|
||||
Every code change, whether it's a new feature or a bugfix, will be done on the master branch.
|
||||
Kimai is actively developed in my spare time, I put my effort into the software instead of backporting changes.
|
||||
Release versions will be created on a regular basis, every couple of weeks latest.
|
||||
Every code change, whether it's a new feature or a bugfix, will be done on the `main` branch.
|
||||
|
||||
## Contributing
|
||||
|
||||
You want to contribute to this repository? This is so great!
|
||||
The best way to start is to [open a new issue](https://github.com/kevinpapst/kimai2/issues) for bugs or feature requests or a [discussion](https://github.com/kevinpapst/kimai2/discussions) for questions, support and such.
|
||||
The best way to start is to [open a new issue](https://github.com/kimai/kimai/issues) for bugs or feature requests or a [discussion](https://github.com/kimai/kimai/discussions) for questions, support and such.
|
||||
|
||||
In case you want to contribute, but you wouldn't know how, here are some suggestions:
|
||||
|
||||
- Spread the word: More user means more people testing and contributing to Kimai - which in turn means better stability and more and better features. Please vote for Kimai on platforms like Slant, Product Hunt, Softpedia or AlternativeTo, you can tweet about it, share it on LinkedIn, reddit or any of your favorite social media platforms. Every bit helps!
|
||||
- Answer questions: You know the answer to another user's problem? Share your knowledge!
|
||||
- Make a feature request: Something can be done better? Something essential missing? Let us know!
|
||||
- Report bugs
|
||||
- You don't have to be programmer to help. The documentation and translation could use some love as well.
|
||||
- Sponsor the project, free software still costs money
|
||||
- Spread the word: Please [write a testimonial for our Wall of love](https://love.kimai.org), vote for Kimai on any software platform, you can toot or tweet about it, share it on LinkedIn, Reddit and any other social media platform!
|
||||
- [Translate Kimai into your language](https://hosted.weblate.org/engage/kimai/), or help to improve the existing translations, many languages look for a contributor
|
||||
- Answer questions: You know the answer to another user's problem? Share your knowledge.
|
||||
- Something can be done better? An essential feature is missing? Create a feature request.
|
||||
- Report bugs makes Kimai better for everyone.
|
||||
- You don't have to be programmer, the documentation and translation could always use some attention.
|
||||
- Sponsor the project: free software costs money to create!
|
||||
|
||||
There is one simple rule in our "Code of conduct": Don't be an ass!
|
||||
|
||||
## Follow Kimai
|
||||
|
||||
- Mastodon: [@kimai](https://phpc.social/@kimai)
|
||||
- Youtube: [@kimai_org](https://www.youtube.com/@kimai_org)
|
||||
- LinkedIn: [@kimai-org](https://www.linkedin.com/company/kimai-org/)
|
||||
|
||||
### Credits
|
||||
|
||||
Kimai is based on modern technologies and frameworks such as [PHP](https://www.php.net/),
|
||||
[Symfony](https://github.com/symfony/symfony) and [Doctrine](https://github.com/doctrine/),
|
||||
[Bootstrap](https://github.com/twbs/bootstrap) and [Tabler](https://tabler.io/),
|
||||
and [countless](composer.json) [others](package.json).
|
||||
|
||||
There is one simple rule in our "Code of conduct": Don't be an ass!
|
||||
|
||||
26
SECURITY.md
26
SECURITY.md
@@ -1,24 +1,10 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
As announced in the [README](README.md) security fixes will only be added to the `main` branch.
|
||||
|
||||
As announced in the [README](README.md) I only support the latest available release and master.
|
||||
| Version | Supported |
|
||||
|----------------------|--------------------|
|
||||
| main branch | :white_check_mark: |
|
||||
| older releases | :x: |
|
||||
|
||||
| Version | Supported |
|
||||
|---------|--------------------|
|
||||
| master | :white_check_mark: |
|
||||
| 1.20 | :white_check_mark: |
|
||||
| < 1.20 | :x: |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Please read the [Bughunter](https://www.kimai.org/documentation/bughunter.html) documentation before posting,
|
||||
and then you can report any security related vulnerability in the [advisories section at GitHub](https://github.com/kevinpapst/kimai2/security/advisories) or via email to kpapst@gmx.net.
|
||||
|
||||
I will work as fast as I can to fix the problem and publish a bugfix release / security update.
|
||||
Depending on the size of the required fixes, this might take a couple of hours or a couple of days.
|
||||
|
||||
You can expect that your message will be answered ASAP.
|
||||
|
||||
You will be mentioned in the release notes if your issue is valid and after it was fixed.
|
||||
I am grateful for any (discrete) disclosure of vulnerabilities!
|
||||
You find all information in our [Bughunter documentation](https://www.kimai.org/documentation/bughunter.html).
|
||||
|
||||
368
UPGRADING-1.md
Normal file
368
UPGRADING-1.md
Normal file
@@ -0,0 +1,368 @@
|
||||
# Upgrading Kimai - Version 1.x
|
||||
|
||||
_Make sure to create a backup before you start!_
|
||||
|
||||
Read the [updates documentation](https://www.kimai.org/documentation/updates.html) to find out how
|
||||
you can upgrade your Kimai installation to the latest stable release.
|
||||
|
||||
Check below if there are more version specific steps required, which need to be executed after the normal update process.
|
||||
Perform EACH version specific task between your version and the new one, otherwise you risk data inconsistency or a broken installation.
|
||||
|
||||
## [1.16](https://github.com/kimai/kimai/releases/tag/1.16)
|
||||
|
||||
If you are using MariaDB, it must be at least version 10.1, older versions are not supported any longer.
|
||||
|
||||
**DEVELOPER**
|
||||
|
||||
- Removed `formDateTime` field from API model `I18nConfig`
|
||||
- Upgraded to Doctrine DBAL 3, see [docs](https://github.com/doctrine/dbal/blob/3.1.x/UPGRADE.md) - you might have to update your bundle
|
||||
|
||||
## [1.15](https://github.com/kimai/kimai/releases/tag/1.15)
|
||||
|
||||
**Many database changes: don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
||||
|
||||
Updating the database might take quite a while, depending on the amount of timesheet entries and speed of your database server (~1 minute per 100k records).
|
||||
|
||||
**ATTENTION**
|
||||
|
||||
- This release bumps the minimum required [PHP version to 7.3](https://www.kimai.org/blog/2021/php8-support-php72-dropped/)
|
||||
- Self-registration is disabled by default
|
||||
- Self-registration now always requires email confirmation
|
||||
- All plugins that use own databases need to be updated as well
|
||||
- Removed the YearChart widget and the related configs named `userRecapThisYear`, `userRecapLastYear`, `userRecapTwoYears`, `userRecapThreeYears`
|
||||
|
||||
**LDAP & SAML**
|
||||
|
||||
Please verify your config with the [LDAP](https://www.kimai.org/documentation/ldap.html) and [SAML](https://www.kimai.org/documentation/saml.html) documentation, especially:
|
||||
|
||||
- SAML users: activate it by setting the `kimai.saml.activate: true` config key
|
||||
- LDAP users: activate it by setting the `kimai.ldap.activate: true` config key
|
||||
- LDAP and SAML users need to remove the complete `security` section from their `local.yaml`
|
||||
|
||||
**DEVELOPER**
|
||||
|
||||
PHP 8 compatibility forced to upgrade MANY libraries, including but not limited to:
|
||||
|
||||
- Removed FOSUserBundle and hslavich/oneloginsaml
|
||||
- Doctrine Migrations, whose new major version forces plugin updates
|
||||
- Gedmo v3 (which include BC breaks in definitions)
|
||||
- Doctrine DBAL and others, which required PHP 7.3 as well
|
||||
|
||||
**API BC break**: Due to team structure changes, it was impossible to keep the (writing) API structure. Please adjust your code accordingly!
|
||||
|
||||
## [1.14](https://github.com/kimai/kimai/releases/tag/1.14)
|
||||
|
||||
**CRITICAL BC break**: SQLite support was removed. If you are using SQLite, you have to [read this blog post](https://www.kimai.org/blog/2021/sqlite-and-ftp-support-removed/) and migrate to MySQL/MariaDB first!
|
||||
|
||||
**New database tables and fields: don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
||||
|
||||
Permission changes:
|
||||
- `history_invoice` - removed permission entirely
|
||||
|
||||
## [1.13](https://github.com/kimai/kimai/releases/tag/1.13)
|
||||
|
||||
- Deprecated `now` variable in export templates: create it yourself with `{% set now = create_date('now', app.user) %}`
|
||||
- Changed invoice filename generation (check if you use cronjob for invoices)
|
||||
- **BC break**: duration entered as plain numbers will now be treated as decimal duration in hours instead of seconds
|
||||
|
||||
## [1.12](https://github.com/kimai/kimai/releases/tag/1.12)
|
||||
|
||||
- Export templates can now include items from plugins (eg. Expenses).
|
||||
|
||||
## [1.10](https://github.com/kimai/kimai/releases/tag/1.10)
|
||||
|
||||
**New database tables and fields were created, don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
||||
|
||||
- Invoice renderer `CSV` was removed
|
||||
- Sessions are now stored in the database (all users have to re-login after upgrade)
|
||||
- New permissions: `lockdown_grace_timesheet`, `lockdown_override_timesheet`, `view_all_data`
|
||||
- Fixed team permissions on user queries: depending on your previous team & permission setup your users might see less data (SUPER_ADMINS see all data, but new: ADMINS only see all data if they own the `view_all_data` permission)
|
||||
- Markdown does not support headings anymore, text like `# foo` is not converted to `<h1 id="foo">foo</h1>` anymore
|
||||
|
||||
### Developer
|
||||
|
||||
- **BC break**: removed registration of `.env` with `putenv()` - do not rely on `getenv()` as it is not thread-safe
|
||||
- **BC break**: interface method signature `HtmlToPdfConverter::convertToPdf()` changed
|
||||
- **BC break**: the macros `badge` and `label` do not apply the `|trans` filter any more
|
||||
- **BC Break**: removed `getVisible()` (deprecated since 1.4) method on Customer, Project and Activity (use `isVisible()` instead, templates are still working)
|
||||
- **BC Break**: API changes
|
||||
- some representation names changed (eg. from `ActivityMetaField` to `ActivityMeta`, `TimesheetSubCollection` vs `TimesheetCollectionExpanded`), you could use `class_alias()` if you use auto-generated code from Swagger-Gen or alike
|
||||
- new result types were introduced
|
||||
- result data changed in some areas to smooth out inconsistencies (eg. TeamEntity fields changed in nested results)
|
||||
|
||||
## [1.9](https://github.com/kimai/kimai/releases/tag/1.9)
|
||||
|
||||
**New database tables and fields were created, don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
||||
|
||||
- The directory `var/data/invoices/` will be used to store archived invoice files (check file permissions)
|
||||
- The default invoice number format changed. If you want to use the old one: configure `{date}` as format - see [invoice documentation](https://www.kimai.org/documentation/invoices.html)
|
||||
- HTML invoice templates are now treated like other files and offered as download. If you are using relative URLs for including assets (CSS, images) you need to either inline them (see the default templates) or use absolute URLs
|
||||
- Invoice templates that use the templates variables `${activity.X}` or `${project.X}` should be checked and possibly adapted, as multi-select is now possible for filtering
|
||||
- Invoice templates have access to all meta-fields as variables, not only the ones marked as visible
|
||||
- Rates configuration/structure changed for customer, project and activity
|
||||
- **Invoice templates**: rates variables were removed
|
||||
|
||||
Permission changes:
|
||||
- `history_invoice` - NEW: grants all features for the new invoice archive (by default for all admins)
|
||||
|
||||
### Developer
|
||||
|
||||
- **BC break**: `InvoiceItemInterface` has new methods `getType()` and `getCategory()`
|
||||
- **BC break**: API fields changed - see new `/rates` endpoints
|
||||
|
||||
## [1.8](https://github.com/kimai/kimai/releases/tag/1.8)
|
||||
|
||||
**New database tables and fields were created, don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
||||
|
||||
- New PHP requirement: `ext-xsl` - which should be pre-installed in most environments when `ext-xml` is loaded
|
||||
- New mailer library: check if emails are still working (eg. by using the "password forgotten" function) or if you need to adjust your configuration, [see docs at symfony.com](https://symfony.com/doc/current/components/mailer.html#transport)
|
||||
- Support for line breaks in multiline invoice fields for spreadsheets (check your invoice templates after the update)
|
||||
|
||||
Permission changes:
|
||||
|
||||
- `comments_create_customer` - NEW: permission that allows to add new comments for customers
|
||||
- `comments_create_team_customer` - NEW: permission that allows to add new comments for team members of the current customer
|
||||
- `comments_create_teamlead_customer` - NEW: permission that allows to add new comments for a teamlead of the current customer
|
||||
- `comments_create_project` - NEW: permission that allows to add new comments for project
|
||||
- `comments_create_team_project` - NEW: permission that allows to add new comments for team members of the current project
|
||||
- `comments_create_teamlead_project` - NEW: permission that allows to add new comments for a teamlead of the current project
|
||||
- `edit_teamlead_project` - removed default permission from ROLE_TEAMLEAD (if you use it: change it in the Role & Permission UI)
|
||||
- `edit_teamlead_customer` - removed default permission from ROLE_TEAMLEAD (if you use it: change it in the Role & Permission UI)
|
||||
- `upload_invoice_template` - NEW: permission that allows to upload invoice documents from the UI
|
||||
|
||||
## [1.7](https://github.com/kimai/kimai/releases/tag/1.7)
|
||||
|
||||
**New database tables and fields were created, don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
||||
|
||||
New permissions:
|
||||
|
||||
- `comments_customer` - show comment list on customer detail page (new feature)
|
||||
- `details_customer` - show detail information for customers (customer number, vat, rates, meta-fields, assigned teams ...)
|
||||
- `comments_project` - show comment list on project detail page (new feature)
|
||||
- `details_project` - show detail information for projects (rates, meta-fields, assigned teams ...)
|
||||
|
||||
If you are using teams, please read on: The following list of permissions are now also available in the UI and they (can) replace the `X_project` and `X_customer` permissions.
|
||||
They are more strict, as they allow only access to team specific items, the older permissions without `_teamlead_`/`_team_` work on a global level instead.
|
||||
|
||||
- `view_teamlead_customer`, `edit_teamlead_customer`, `budget_teamlead_customer`, `permissions_teamlead_customer`, `comments_teamlead_customer`, `details_teamlead_customer` - allows access to customer data when user is teamlead of a team assigned to the customer (replaces more global permission like `view_customer` for teamleads)
|
||||
- `view_team_customer`, `edit_team_customer`, `budget_team_customer`, `comments_team_customer`, `details_team_customer` - allows access to customer data when user is member of a team assigned to the customer (replaces more global permission like `view_customer` for users)
|
||||
- `view_teamlead_project`, `edit_teamlead_project`, `budget_teamlead_project`, `permissions_teamlead_project`, `comments_teamlead_project`, `details_teamlead_project` - allows access to customer data when user is teamlead of a team assigned to the project (replaces more global permission like `view_project` for teamleads)
|
||||
- `view_team_project`, `edit_team_project`, `budget_team_project`, `comments_team_project`, `details_team_project` - allows access to customer data when user is member of a team assigned to the project (replaces more global permission like `view_project` for users)
|
||||
|
||||
### ExpenseBundle
|
||||
|
||||
**ATTENTION** due to incompatibilities in the underlying frameworks users of the ExpenseBundle need to do one more step:
|
||||
You need to delete the bundle before updating: `rm -r var/plugins/ExpenseBundle`, otherwise you will run into errors during the update.
|
||||
After the Kimai update was successful, you have to re-install the latest bundle version, which is compatible with Kimai 1.7 only.
|
||||
|
||||
### Developer
|
||||
|
||||
- Projects now have a start and end date and the API will only return those, which are either unconfigured or currently active, you might want to reload the list of projects once the user entered begin and end datetime OR use the new `ignoreDates` parameter.
|
||||
- Doctrine bundle was updated to v2, check your code for [the usage of RegistryInterface and ObjectManager](https://github.com/doctrine/DoctrineBundle/blob/master/UPGRADE-2.0.md)
|
||||
- Removed the webserver bundle and the command `server:run` - see [docs](https://www.kimai.org/documentation/developers.html)
|
||||
|
||||
## [1.6](https://github.com/kimai/kimai/releases/tag/1.6), [1.6.1](https://github.com/kimai/kimai/releases/tag/1.6.1), [1.6.2](https://github.com/kimai/kimai/releases/tag/1.6.2)
|
||||
|
||||
**New database tables and fields were created, don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
||||
|
||||
- Invoice changes:
|
||||
- Moved CSV, ODS and XSLX invoice templates to [another repository](https://github.com/Keleo/kimai2-invoice-templates). Using them? Install them manually (see [invoice documentation](https://www.kimai.org/documentation/invoices.html)).
|
||||
- Added new invoice fields (VAT, contact, payment details) and customer field (VAT). Used the twig settings before? Move them to the respective invoice template settings.
|
||||
- Permissions can be managed via Admin UI. Please move your permission settings from [local.yaml to your database](https://www.kimai.org/documentation/permissions.html).
|
||||
- Important permission change: regular users with the `view_other_timesheet` permission could see all timesheets. This was a legacy from the time before team permissions were introduced. If you rely on this behavior, you need to create a team with all users and the teamlead being the user who needs access to all timesheets.
|
||||
|
||||
### Developer
|
||||
|
||||
Please add default permissions to your [plugin](https://www.kimai.org/documentation/plugins.html).
|
||||
|
||||
## [1.5](https://github.com/kimai/kimai/releases/tag/1.5)
|
||||
|
||||
[Update as usual](https://www.kimai.org/documentation/updates.html)
|
||||
|
||||
## [1.4](https://github.com/kimai/kimai/releases/tag/1.4)
|
||||
|
||||
**There is a new directory, which needs to be writable by the webserver: `public/avatars/`.**
|
||||
|
||||
New permission (used in new dashboard widget):
|
||||
- `view_team_member` - display team assignments (names, teamleads and members) for the current user
|
||||
|
||||
Activated Javascript select component by default (check mobile devices).
|
||||
|
||||
### Developer: BC breaks
|
||||
|
||||
- Dashboard widgets and rows need to define their `type` by FQCN
|
||||
- Switched to Symfony 4.3 event types, this could fail in plugins, but only if they didn't use the official constants for event names
|
||||
|
||||
## [1.3](https://github.com/kimai/kimai/releases/tag/1.3)
|
||||
|
||||
Added `manage_tag` permission for new tag features
|
||||
|
||||
### Developer: BC breaks
|
||||
|
||||
- Refactored toolbars and search, plugins needs to be checked
|
||||
- Invoices now supports multiple repositories, some method signatures had to be changed (eg. `calculateSumIdentifier()`)
|
||||
|
||||
## [1.2](https://github.com/kimai/kimai/releases/tag/1.2)
|
||||
|
||||
**If you are still using 0.7 or below, you need to upgrade to 1.1 before upgrading to this version.**
|
||||
|
||||
- Deleted timezone conversion command.
|
||||
- Minimum password length raised from 5 to 8 character (applies only for password changes and new users)
|
||||
- Maximum customer name length lowered to 150 character
|
||||
- Maximum project name length lowered to 150 character
|
||||
- Maximum activity name length lowered to 150 character
|
||||
- Added new permission: `manage_invoice_template`
|
||||
- Removed permissions: `view_invoice_template`, `create_invoice_template`, `edit_invoice_template`, `delete_invoice_template`
|
||||
- Removed permission: `view_export` (using `create_export` only)
|
||||
|
||||
### Developer: BC breaks
|
||||
|
||||
- Custom export renderer need to check for usage of `Timesheet::getEnd()` as running entries can now be exported as well
|
||||
|
||||
## [1.1](https://github.com/kimai/kimai/releases/tag/1.1)
|
||||
|
||||
[Update as usual](https://www.kimai.org/documentation/updates.html), nothing special for this release if you upgrade from 1.0 / 1.0.1.
|
||||
|
||||
## [1.0](https://github.com/kimai/kimai/releases/tag/1.0)
|
||||
|
||||
This release contains several changes, as I still have the goal to stabilize the code base to prevent
|
||||
such "challenges" after 1.0 for a while.
|
||||
|
||||
### Changes for your local.yaml
|
||||
|
||||
New permissions are available. You have to add them to your `local.yaml` ONLY if you use a custom permission structure,
|
||||
otherwise you can't use the new features:
|
||||
- `view_tag` - view all tags
|
||||
- `delete_tag` - delete tags
|
||||
- `edit_exported_timesheet` - allows to edit records which were exported
|
||||
- `role_permissions` - view calculated permissions for user roles
|
||||
- `budget_activity` - view and edit budgets for activities
|
||||
- `budget_project` - view and edit budgets for projects
|
||||
- `budget_customer` - view and edit budgets for customers
|
||||
|
||||
Removed permission:
|
||||
- `system_actions` - removed experimental feature to flush app cache from the about screen
|
||||
|
||||
### BC BREAKS
|
||||
|
||||
- API: Format for queries including a datetime object fixed to use HTML5 format (previously `2019-03-02 14:23` - now `2019-03-02T14:23:00`)
|
||||
- **Permission config**: the `permissions` definition in your `local.yaml` needs to be verified/changed, as the internal structure was highly optimized to simplify the definition.
|
||||
Thanks to the new structure, you should be able to remove almost everything from your `local.yaml` (tip: start over from scratch!). Please read [the updated permission docu](https://www.kimai.org/documentation/permissions.html).
|
||||
- default widgets were removed from `kimai.yaml`, that shouldn't cause any issues ... but if something is odd: [look here for help](https://www.kimai.org/documentation/dashboard.html)
|
||||
|
||||
## [0.9](https://github.com/kimai/kimai/releases/tag/0.9)
|
||||
|
||||
Remember to execute the necessary timezone conversion script, if you haven't updated to 0.8 before (see below)!
|
||||
|
||||
### BC BREAKS
|
||||
|
||||
This release contains some BC breaks which were necessary before 1.0 will be released (_now or never_), to prevent those BC breaks after 1.0.
|
||||
|
||||
- **Kimai requires PHP 7.2 now => [PHP 7.1 expired 4 month ago](https://www.php.net/supported-versions.php)**
|
||||
- The `.env` variable `DATABASE_PREFIX` was removed and the table prefix is now hardcoded to `kimai2_`. If you used another prefix,
|
||||
you have to rename your tables manually before starting the update process. You can delete the row `DATABASE_PREFIX` from your `.env` file.
|
||||
- API: Format for DateTime objects changed, now including timezone identifier (previously `2019-03-02 14:23` - now `2019-03-02T14:23:00+00:00`), see [#718](https://github.com/kimai/kimai/pull/718)
|
||||
- API: changed from snake_case to camelCase (affected fields: hourlyRate vs hourly_rate / fixedRate vs fixed_rate / orderNumber vs order_number / i18n config object)
|
||||
- Plugin mechanism changed: existing Plugins have to be deleted or updated
|
||||
|
||||
### Apply necessary changes to your `local.yaml`:
|
||||
|
||||
New permissions are available:
|
||||
- `system_configuration` - for accessing the new system configuration screen
|
||||
- `system_actions` - for the experimental feature to flush your cache from the about screen
|
||||
- `plugins` - for accessing the new plugins screen
|
||||
|
||||
The setting `kimai.timesheet.mode` replaces the setting `kimai.timesheet.duration_only`. If you used the duration_only mode, you need to change your config:
|
||||
```yaml
|
||||
# Before
|
||||
kimai:
|
||||
timesheet:
|
||||
duration_only: true
|
||||
|
||||
# After
|
||||
kimai:
|
||||
timesheet:
|
||||
mode: duration_only
|
||||
```
|
||||
Or switch the mode directly in the new System configuration screen within Kimai.
|
||||
|
||||
## [0.8.1](https://github.com/kimai/kimai/releases/tag/0.8.1)
|
||||
|
||||
A bug fixing release. Remember to execute the necessary timezone conversion script, if you haven't updated to 0.8 before (see below)!
|
||||
|
||||
## [0.8](https://github.com/kimai/kimai/releases/tag/0.8)
|
||||
|
||||
After you followed the normal update and database migration process (see above), you need to execute a bash command to convert your timesheet data for timezone support:
|
||||
|
||||
- Read this [pull request](https://github.com/kimai/kimai/pull/372) BEFORE you follow the instructions to convert the
|
||||
timezones in your existing time records with `bin/console kimai:convert-timezone`. Without that, you will end up with wrong times in your database.
|
||||
|
||||
### Apply necessary changes to your `local.yaml`:
|
||||
|
||||
- A new boolean setting `kimai.timesheet.rules.allow_future_times` was introduced
|
||||
- New permissions are available:
|
||||
- `view_export` - for the new export feature
|
||||
- `create_export` - for the new export feature
|
||||
- `edit_export_own_timesheet` - for the new export feature
|
||||
- `edit_export_other_timesheet` - for the new export feature
|
||||
- `system_information` - to see the new about screen
|
||||
|
||||
## [0.7](https://github.com/kimai/kimai/releases/tag/0.7)
|
||||
|
||||
The configuration `kimai.theme.active_warning` was deprecated and should be replaced in your local.yaml,
|
||||
[read config docs for more information](https://www.kimai.org/documentation/timesheet.html#limit-active-entries).
|
||||
|
||||
## [0.6.1](https://github.com/kimai/kimai/releases/tag/0.6.1)
|
||||
|
||||
A bugfix release to address database compatibility issues with older MySQL/MariaDB versions.
|
||||
|
||||
## [0.6](https://github.com/kimai/kimai/releases/tag/0.6)
|
||||
|
||||
The API has some minor BC breaks: some fields were renamed and entities have a larger attribute set than collections.
|
||||
Be aware that the API is still is development mode and shouldn't be considered stable for now.
|
||||
|
||||
## [0.5](https://github.com/kimai/kimai/releases/tag/0.5)
|
||||
|
||||
Some configuration nodes were removed, if you have one of them in your `local.yaml` you need to delete them before you start the update:
|
||||
- `kimai.invoice.calculator`
|
||||
- `kimai.invoice.renderer`
|
||||
- `kimai.invoice.number_generator`
|
||||
|
||||
The new config `kimai.invoice.documents` was introduced, holding a list of directories ([read more](https://www.kimai.org/documentation/invoices.html)).
|
||||
|
||||
**BC break:** InvoiceTemplate name was changed from 255 characters to 60. If you used longer invoice-template names, they will be truncated when upgrading the database.
|
||||
Please make sure that they are unique in the first 60 character before you upgrade your database with `doctrine:migrations:migrate`.
|
||||
|
||||
## [0.4](https://github.com/kimai/kimai/releases/tag/0.4)
|
||||
|
||||
In the time between 0.3 and 0.4 there was a release of composer that introduced a BC break,
|
||||
which leads to problems between Composer and Symfony Flex, resulting in an error like this when running it:
|
||||
|
||||
```
|
||||
[ErrorException]
|
||||
Declaration of Symfony\Flex\ParallelDownloader::getRemoteContents($originUrl, $fileUrl, $context) should be compatible with Composer\Util\RemoteFilesystem::getRemoteContents($originUrl, $fileUrl, $context, ?array &$responseHeaders = NULL)
|
||||
```
|
||||
|
||||
This can be fixed by updating Composer and Flex before executing the Kimai update:
|
||||
```
|
||||
sudo composer self-update
|
||||
sudo -u www-data composer update symfony/flex --no-plugins --no-scripts
|
||||
```
|
||||
|
||||
## [0.3](https://github.com/kimai/kimai/releases/tag/0.3)
|
||||
|
||||
You need to adjust your `.env` file and add your `from` address for [all emails](https://www.kimai.org/documentation/emails.html) generated by Kimai 2:
|
||||
```
|
||||
MAILER_FROM=kimai@example.com
|
||||
```
|
||||
|
||||
Create a file and database backup before executing the following steps:
|
||||
|
||||
```bash
|
||||
git pull origin master
|
||||
sudo -u www-data composer install --no-dev --optimize-autoloader
|
||||
sudo -u www-data bin/console cache:clear --env=prod
|
||||
sudo -u www-data bin/console cache:warmup --env=prod
|
||||
bin/console doctrine:migrations:version --add 20180701120000
|
||||
bin/console doctrine:migrations:migrate
|
||||
```
|
||||
26
UPGRADING-3.md
Normal file
26
UPGRADING-3.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Upgrading Kimai - Version 3.x
|
||||
|
||||
_Make sure to create a backup before you start!_
|
||||
|
||||
Read the [updates documentation](https://www.kimai.org/documentation/updates.html) to find out how you can upgrade your Kimai installation to the latest stable release.
|
||||
|
||||
Check below if there are more version specific steps required, which need to be executed after the normal update process.
|
||||
Perform EACH version specific task between your version and the new one, otherwise you risk data inconsistency or a broken installation.
|
||||
|
||||
## 3.0
|
||||
|
||||
**!! This release requires minimum PHP version 8.4 !!**
|
||||
|
||||
### Developer
|
||||
|
||||
Do not use method chaining: all fluent interface, especially in Entities, are no longer supported.
|
||||
|
||||
Removed translations:
|
||||
- `action.edit`: use `edit` instead
|
||||
- `my.profile`: use `user_profile` instead
|
||||
- `stats.userAmountToday`: use `` instead
|
||||
- `stats.userAmountWeek`: use `` instead
|
||||
- `stats.userAmountMonth`: use `` instead
|
||||
- `stats.userAmountYear`: use `` instead
|
||||
- `stats.userAmountTotal`: use `` instead
|
||||
- `update_multiple`
|
||||
382
UPGRADING.md
382
UPGRADING.md
@@ -1,4 +1,4 @@
|
||||
# Upgrading Kimai 2
|
||||
# Upgrading Kimai - Version 2.x
|
||||
|
||||
_Make sure to create a backup before you start!_
|
||||
|
||||
@@ -8,359 +8,43 @@ you can upgrade your Kimai installation to the latest stable release.
|
||||
Check below if there are more version specific steps required, which need to be executed after the normal update process.
|
||||
Perform EACH version specific task between your version and the new one, otherwise you risk data inconsistency or a broken installation.
|
||||
|
||||
## [2.0.30](https://github.com/kimai/kimai/releases/tag/2.0.30)
|
||||
|
||||
## [1.16](https://github.com/kevinpapst/kimai2/releases/tag/1.16)
|
||||
The `DATABASE_URL` in your environment settings (e.g. [.env](https://github.com/kimai/kimai/issues/4246), [docker-compose.yaml](https://github.com/tobybatch/kimai2/issues/531) or webserver config)
|
||||
now requires the `charset` and `serverVersion` params, e.g.: `DATABASE_URL=mysql://user:password@127.0.0.1:3306/database?charset=utf8mb4&serverVersion=10.5.8-MariaDB` (examples in `.env`).
|
||||
|
||||
**DEVELOPER**
|
||||
## [2.0](https://github.com/kimai/kimai/releases/tag/2.0)
|
||||
|
||||
- Removed `formDateTime` field from API model `I18nConfig`
|
||||
**!! This release requires minimum PHP version to 8.1 !!**
|
||||
|
||||
## [1.15](https://github.com/kevinpapst/kimai2/releases/tag/1.15)
|
||||
### Breaking changes
|
||||
|
||||
**Many database changes: don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
||||
|
||||
Updating the database might take quite a while, depending on the amount of timesheet entries and speed of your database server (~1 minute per 100k records).
|
||||
|
||||
**ATTENTION**
|
||||
|
||||
- This release bumps the minimum required [PHP version to 7.3](https://www.kimai.org/blog/2021/php8-support-php72-dropped/)
|
||||
- Self-registration is disabled by default
|
||||
- Self-registration now always requires email confirmation
|
||||
- All plugins that use own databases need to be updated as well
|
||||
- Removed the YearChart widget and the related configs named `userRecapThisYear`, `userRecapLastYear`, `userRecapTwoYears`, `userRecapThreeYears`
|
||||
|
||||
**LDAP & SAML**
|
||||
|
||||
Please verify your config with the [LDAP](https://www.kimai.org/documentation/ldap.html) and [SAML](https://www.kimai.org/documentation/saml.html) documentation, especially:
|
||||
|
||||
- SAML users: activate it by setting the `kimai.saml.activate: true` config key
|
||||
- LDAP users: activate it by setting the `kimai.ldap.activate: true` config key
|
||||
- LDAP and SAML users need to remove the complete `security` section from their `local.yaml`
|
||||
|
||||
**DEVELOPER**
|
||||
|
||||
PHP 8 compatibility forced to upgrade MANY libraries, including but not limited to:
|
||||
|
||||
- Removed FOSUserBundle and hslavich/oneloginsaml
|
||||
- Doctrine Migrations, whose new major version forces plugin updates
|
||||
- Gedmo v3 (which include BC breaks in definitions)
|
||||
- Doctrine DBAL and others, which required PHP 7.3 as well
|
||||
|
||||
**API BC break**: Due to team structure changes, it was impossible to keep the (writing) API structure. Please adjust your code accordingly!
|
||||
|
||||
## [1.14](https://github.com/kevinpapst/kimai2/releases/tag/1.14)
|
||||
|
||||
**CRITICAL BC break**: SQLite support was removed. If you are using SQLite, you have to [read this blog post](https://www.kimai.org/blog/2021/sqlite-and-ftp-support-removed/) and migrate to MySQL/MariaDB first!
|
||||
|
||||
**New database tables and fields: don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
||||
|
||||
Permission changes:
|
||||
- `history_invoice` - removed permission entirely
|
||||
|
||||
## [1.13](https://github.com/kevinpapst/kimai2/releases/tag/1.13)
|
||||
|
||||
- Deprecated `now` variable in export templates: create it yourself with `{% set now = create_date('now', app.user) %}`
|
||||
- Changed invoice filename generation (check if you use cronjob for invoices)
|
||||
- **BC break**: duration entered as plain numbers will now be treated as decimal duration in hours instead of seconds
|
||||
|
||||
## [1.12](https://github.com/kevinpapst/kimai2/releases/tag/1.12)
|
||||
|
||||
- Export templates can now include items from plugins (eg. Expenses).
|
||||
|
||||
## [1.10](https://github.com/kevinpapst/kimai2/releases/tag/1.10)
|
||||
|
||||
**New database tables and fields were created, don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
||||
|
||||
- Invoice renderer `CSV` was removed
|
||||
- Sessions are now stored in the database (all users have to re-login after upgrade)
|
||||
- New permissions: `lockdown_grace_timesheet`, `lockdown_override_timesheet`, `view_all_data`
|
||||
- Fixed team permissions on user queries: depending on your previous team & permission setup your users might see less data (SUPER_ADMINS see all data, but new: ADMINS only see all data if they own the `view_all_data` permission)
|
||||
- Markdown does not support headings anymore, text like `# foo` is not converted to `<h1 id="foo">foo</h1>` anymore
|
||||
- All plugins need to be updated: delete all previous version from your installation (`rm -r var/plugins/*`) before updating!
|
||||
- The `local.yaml` is not compatible with old version, remove it before the update and then re-create it after everything works
|
||||
- removed: configuring the `dashboard` is not supported any longer
|
||||
- removed: custom translation files via `theme.branding.translation`
|
||||
- removed: changing the plugin directory via `kimai.plugin_dir`
|
||||
|
||||
### Developer
|
||||
|
||||
- **BC break**: removed registration of `.env` with `putenv()` - do not rely on `getenv()` as it is not thread-safe
|
||||
- **BC break**: interface method signature `HtmlToPdfConverter::convertToPdf()` changed
|
||||
- **BC break**: the macros `badge` and `label` do not apply the `|trans` filter any more
|
||||
- **BC Break**: removed `getVisible()` (deprecated since 1.4) method on Customer, Project and Activity (use `isVisible()` instead, templates are still working)
|
||||
- **BC Break**: API changes
|
||||
- some representation names changed (eg. from `ActivityMetaField` to `ActivityMeta`, `TimesheetSubCollection` vs `TimesheetCollectionExpanded`), you could use `class_alias()` if you use auto-generated code from Swagger-Gen or alike
|
||||
- new result types were introduced
|
||||
- result data changed in some areas to smooth out inconsistencies (eg. TeamEntity fields changed in nested results)
|
||||
|
||||
## [1.9](https://github.com/kevinpapst/kimai2/releases/tag/1.9)
|
||||
|
||||
**New database tables and fields were created, don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
||||
|
||||
- The directory `var/data/invoices/` will be used to store archived invoice files (check file permissions)
|
||||
- The default invoice number format changed. If you want to use the old one: configure `{date}` as format - see [invoice documentation](https://www.kimai.org/documentation/invoices.html)
|
||||
- HTML invoice templates are now treated like other files and offered as download. If you are using relative URLs for including assets (CSS, images) you need to either inline them (see the default templates) or use absolute URLs
|
||||
- Invoice templates that use the templates variables `${activity.X}` or `${project.X}` should be checked and possibly adapted, as multi-select is now possible for filtering
|
||||
- Invoice templates have access to all meta-fields as variables, not only the ones marked as visible
|
||||
- Rates configuration/structure changed for customer, project and activity
|
||||
- **Invoice templates**: rates variables were removed
|
||||
|
||||
Permission changes:
|
||||
- `history_invoice` - NEW: grants all features for the new invoice archive (by default for all admins)
|
||||
|
||||
### Developer
|
||||
|
||||
- **BC break**: `InvoiceItemInterface` has new methods `getType()` and `getCategory()`
|
||||
- **BC break**: API fields changed - see new `/rates` endpoints
|
||||
|
||||
## [1.8](https://github.com/kevinpapst/kimai2/releases/tag/1.8)
|
||||
|
||||
**New database tables and fields were created, don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
||||
|
||||
- New PHP requirement: `ext-xsl` - which should be pre-installed in most environments when `ext-xml` is loaded
|
||||
- New mailer library: check if emails are still working (eg. by using the "password forgotten" function) or if you need to adjust your configuration, [see docs at symfony.com](https://symfony.com/doc/current/components/mailer.html#transport)
|
||||
- Support for line breaks in multiline invoice fields for spreadsheets (check your invoice templates after the update)
|
||||
|
||||
Permission changes:
|
||||
|
||||
- `comments_create_customer` - NEW: permission that allows to add new comments for customers
|
||||
- `comments_create_team_customer` - NEW: permission that allows to add new comments for team members of the current customer
|
||||
- `comments_create_teamlead_customer` - NEW: permission that allows to add new comments for a teamlead of the current customer
|
||||
- `comments_create_project` - NEW: permission that allows to add new comments for project
|
||||
- `comments_create_team_project` - NEW: permission that allows to add new comments for team members of the current project
|
||||
- `comments_create_teamlead_project` - NEW: permission that allows to add new comments for a teamlead of the current project
|
||||
- `edit_teamlead_project` - removed default permission from ROLE_TEAMLEAD (if you use it: change it in the Role & Permission UI)
|
||||
- `edit_teamlead_customer` - removed default permission from ROLE_TEAMLEAD (if you use it: change it in the Role & Permission UI)
|
||||
- `upload_invoice_template` - NEW: permission that allows to upload invoice documents from the UI
|
||||
|
||||
## [1.7](https://github.com/kevinpapst/kimai2/releases/tag/1.7)
|
||||
|
||||
**New database tables and fields were created, don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
||||
|
||||
New permissions:
|
||||
|
||||
- `comments_customer` - show comment list on customer detail page (new feature)
|
||||
- `details_customer` - show detail information for customers (customer number, vat, rates, meta-fields, assigned teams ...)
|
||||
- `comments_project` - show comment list on project detail page (new feature)
|
||||
- `details_project` - show detail information for projects (rates, meta-fields, assigned teams ...)
|
||||
|
||||
If you are using teams, please read on: The following list of permissions are now also available in the UI and they (can) replace the `X_project` and `X_customer` permissions.
|
||||
They are more strict, as they allow only access to team specific items, the older permissions without `_teamlead_`/`_team_` work on a global level instead.
|
||||
|
||||
- `view_teamlead_customer`, `edit_teamlead_customer`, `budget_teamlead_customer`, `permissions_teamlead_customer`, `comments_teamlead_customer`, `details_teamlead_customer` - allows access to customer data when user is teamlead of a team assigned to the customer (replaces more global permission like `view_customer` for teamleads)
|
||||
- `view_team_customer`, `edit_team_customer`, `budget_team_customer`, `comments_team_customer`, `details_team_customer` - allows access to customer data when user is member of a team assigned to the customer (replaces more global permission like `view_customer` for users)
|
||||
- `view_teamlead_project`, `edit_teamlead_project`, `budget_teamlead_project`, `permissions_teamlead_project`, `comments_teamlead_project`, `details_teamlead_project` - allows access to customer data when user is teamlead of a team assigned to the project (replaces more global permission like `view_project` for teamleads)
|
||||
- `view_team_project`, `edit_team_project`, `budget_team_project`, `comments_team_project`, `details_team_project` - allows access to customer data when user is member of a team assigned to the project (replaces more global permission like `view_project` for users)
|
||||
|
||||
### ExpenseBundle
|
||||
|
||||
**ATTENTION** due to incompatibilities in the underlying frameworks users of the ExpenseBundle need to do one more step:
|
||||
You need to delete the bundle before updating: `rm -r var/plugins/ExpenseBundle`, otherwise you will run into errors during the update.
|
||||
After the Kimai update was successful, you have to re-install the latest bundle version, which is compatible with Kimai 1.7 only.
|
||||
|
||||
### Developer
|
||||
|
||||
- Projects now have a start and end date and the API will only return those, which are either unconfigured or currently active, you might want to reload the list of projects once the user entered begin and end datetime OR use the new `ignoreDates` parameter.
|
||||
- Doctrine bundle was updated to v2, check your code for [the usage of RegistryInterface and ObjectManager](https://github.com/doctrine/DoctrineBundle/blob/master/UPGRADE-2.0.md)
|
||||
- Removed the webserver bundle and the command `server:run` - see [docs](https://www.kimai.org/documentation/developers.html)
|
||||
|
||||
## [1.6](https://github.com/kevinpapst/kimai2/releases/tag/1.6), [1.6.1](https://github.com/kevinpapst/kimai2/releases/tag/1.6.1), [1.6.2](https://github.com/kevinpapst/kimai2/releases/tag/1.6.2)
|
||||
|
||||
**New database tables and fields were created, don't forget to [run the updater](https://www.kimai.org/documentation/updates.html).**
|
||||
|
||||
- Invoice changes:
|
||||
- Moved CSV, ODS and XSLX invoice templates to [another repository](https://github.com/Keleo/kimai2-invoice-templates). Using them? Install them manually (see [invoice documentation](https://www.kimai.org/documentation/invoices.html)).
|
||||
- Added new invoice fields (VAT, contact, payment details) and customer field (VAT). Used the twig settings before? Move them to the respective invoice template settings.
|
||||
- Permissions can be managed via Admin UI. Please move your permission settings from [local.yaml to your database](https://www.kimai.org/documentation/permissions.html).
|
||||
- Important permission change: regular users with the `view_other_timesheet` permission could see all timesheets. This was a legacy from the time before team permissions were introduced. If you rely on this behavior, you need to create a team with all users and the teamlead being the user who needs access to all timesheets.
|
||||
|
||||
### Developer
|
||||
|
||||
Please add default permissions to your [plugin](https://www.kimai.org/documentation/plugins.html).
|
||||
|
||||
## [1.5](https://github.com/kevinpapst/kimai2/releases/tag/1.5)
|
||||
|
||||
[Update as usual](https://www.kimai.org/documentation/updates.html)
|
||||
|
||||
## [1.4](https://github.com/kevinpapst/kimai2/releases/tag/1.4)
|
||||
|
||||
**There is a new directory, which needs to be writable by the webserver: `public/avatars/`.**
|
||||
|
||||
New permission (used in new dashboard widget):
|
||||
- `view_team_member` - display team assignments (names, teamleads and members) for the current user
|
||||
|
||||
Activated Javascript select component by default (check mobile devices).
|
||||
|
||||
### Developer: BC breaks
|
||||
|
||||
- Dashboard widgets and rows need to define their `type` by FQCN
|
||||
- Switched to Symfony 4.3 event types, this could fail in plugins, but only if they didn't use the official constants for event names
|
||||
|
||||
## [1.3](https://github.com/kevinpapst/kimai2/releases/tag/1.3)
|
||||
|
||||
Added `manage_tag` permission for new tag features
|
||||
|
||||
### Developer: BC breaks
|
||||
|
||||
- Refactored toolbars and search, plugins needs to be checked
|
||||
- Invoices now supports multiple repositories, some method signatures had to be changed (eg. `calculateSumIdentifier()`)
|
||||
|
||||
## [1.2](https://github.com/kevinpapst/kimai2/releases/tag/1.2)
|
||||
|
||||
**If you are still using 0.7 or below, you need to upgrade to 1.1 before upgrading to this version.**
|
||||
|
||||
- Deleted timezone conversion command.
|
||||
- Minimum password length raised from 5 to 8 character (applies only for password changes and new users)
|
||||
- Maximum customer name length lowered to 150 character
|
||||
- Maximum project name length lowered to 150 character
|
||||
- Maximum activity name length lowered to 150 character
|
||||
- Added new permission: `manage_invoice_template`
|
||||
- Removed permissions: `view_invoice_template`, `create_invoice_template`, `edit_invoice_template`, `delete_invoice_template`
|
||||
- Removed permission: `view_export` (using `create_export` only)
|
||||
|
||||
### Developer: BC breaks
|
||||
|
||||
- Custom export renderer need to check for usage of `Timesheet::getEnd()` as running entries can now be exported as well
|
||||
|
||||
## [1.1](https://github.com/kevinpapst/kimai2/releases/tag/1.1)
|
||||
|
||||
[Update as usual](https://www.kimai.org/documentation/updates.html), nothing special for this release if you upgrade from 1.0 / 1.0.1.
|
||||
|
||||
## [1.0](https://github.com/kevinpapst/kimai2/releases/tag/1.0)
|
||||
|
||||
This release contains several changes, as I still have the goal to stabilize the code base to prevent
|
||||
such "challenges" after 1.0 for a while.
|
||||
|
||||
### Changes for your local.yaml
|
||||
|
||||
New permissions are available. You have to add them to your `local.yaml` ONLY if you use a custom permission structure,
|
||||
otherwise you can't use the new features:
|
||||
- `view_tag` - view all tags
|
||||
- `delete_tag` - delete tags
|
||||
- `edit_exported_timesheet` - allows to edit records which were exported
|
||||
- `role_permissions` - view calculated permissions for user roles
|
||||
- `budget_activity` - view and edit budgets for activities
|
||||
- `budget_project` - view and edit budgets for projects
|
||||
- `budget_customer` - view and edit budgets for customers
|
||||
|
||||
Removed permission:
|
||||
- `system_actions` - removed experimental feature to flush app cache from the about screen
|
||||
|
||||
### BC BREAKS
|
||||
|
||||
- API: Format for queries including a datetime object fixed to use HTML5 format (previously `2019-03-02 14:23` - now `2019-03-02T14:23:00`)
|
||||
- **Permission config**: the `permissions` definition in your `local.yaml` needs to be verified/changed, as the internal structure was highly optimized to simplify the definition.
|
||||
Thanks to the new structure, you should be able to remove almost everything from your `local.yaml` (tip: start over from scratch!). Please read [the updated permission docu](https://www.kimai.org/documentation/permissions.html).
|
||||
- default widgets were removed from `kimai.yaml`, that shouldn't cause any issues ... but if something is odd: [look here for help](https://www.kimai.org/documentation/dashboard.html)
|
||||
|
||||
## [0.9](https://github.com/kevinpapst/kimai2/releases/tag/0.9)
|
||||
|
||||
Remember to execute the necessary timezone conversion script, if you haven't updated to 0.8 before (see below)!
|
||||
|
||||
### BC BREAKS
|
||||
|
||||
This release contains some BC breaks which were necessary before 1.0 will be released (_now or never_), to prevent those BC breaks after 1.0.
|
||||
|
||||
- **Kimai requires PHP 7.2 now => [PHP 7.1 expired 4 month ago](https://www.php.net/supported-versions.php)**
|
||||
- The `.env` variable `DATABASE_PREFIX` was removed and the table prefix is now hardcoded to `kimai2_`. If you used another prefix,
|
||||
you have to rename your tables manually before starting the update process. You can delete the row `DATABASE_PREFIX` from your `.env` file.
|
||||
- API: Format for DateTime objects changed, now including timezone identifier (previously `2019-03-02 14:23` - now `2019-03-02T14:23:00+00:00`), see [#718](https://github.com/kevinpapst/kimai2/pull/718)
|
||||
- API: changed from snake_case to camelCase (affected fields: hourlyRate vs hourly_rate / fixedRate vs fixed_rate / orderNumber vs order_number / i18n config object)
|
||||
- Plugin mechanism changed: existing Plugins have to be deleted or updated
|
||||
|
||||
### Apply necessary changes to your `local.yaml`:
|
||||
|
||||
New permissions are available:
|
||||
- `system_configuration` - for accessing the new system configuration screen
|
||||
- `system_actions` - for the experimental feature to flush your cache from the about screen
|
||||
- `plugins` - for accessing the new plugins screen
|
||||
|
||||
The setting `kimai.timesheet.mode` replaces the setting `kimai.timesheet.duration_only`. If you used the duration_only mode, you need to change your config:
|
||||
```yaml
|
||||
# Before
|
||||
kimai:
|
||||
timesheet:
|
||||
duration_only: true
|
||||
|
||||
# After
|
||||
kimai:
|
||||
timesheet:
|
||||
mode: duration_only
|
||||
```
|
||||
Or switch the mode directly in the new System configuration screen within Kimai.
|
||||
|
||||
## [0.8.1](https://github.com/kevinpapst/kimai2/releases/tag/0.8.1)
|
||||
|
||||
A bug fixing release. Remember to execute the necessary timezone conversion script, if you haven't updated to 0.8 before (see below)!
|
||||
|
||||
## [0.8](https://github.com/kevinpapst/kimai2/releases/tag/0.8)
|
||||
|
||||
After you followed the normal update and database migration process (see above), you need to execute a bash command to convert your timesheet data for timezone support:
|
||||
|
||||
- Read this [pull request](https://github.com/kevinpapst/kimai2/pull/372) BEFORE you follow the instructions to convert the
|
||||
timezones in your existing time records with `bin/console kimai:convert-timezone`. Without that, you will end up with wrong times in your database.
|
||||
|
||||
### Apply necessary changes to your `local.yaml`:
|
||||
|
||||
- A new boolean setting `kimai.timesheet.rules.allow_future_times` was introduced
|
||||
- New permissions are available:
|
||||
- `view_export` - for the new export feature
|
||||
- `create_export` - for the new export feature
|
||||
- `edit_export_own_timesheet` - for the new export feature
|
||||
- `edit_export_other_timesheet` - for the new export feature
|
||||
- `system_information` - to see the new about screen
|
||||
|
||||
## [0.7](https://github.com/kevinpapst/kimai2/releases/tag/0.7)
|
||||
|
||||
The configuration `kimai.theme.active_warning` was deprecated and should be replaced in your local.yaml,
|
||||
[read config docs for more information](https://www.kimai.org/documentation/timesheet.html#limit-active-entries).
|
||||
|
||||
## [0.6.1](https://github.com/kevinpapst/kimai2/releases/tag/0.6.1)
|
||||
|
||||
A bugfix release to address database compatibility issues with older MySQL/MariaDB versions.
|
||||
|
||||
## [0.6](https://github.com/kevinpapst/kimai2/releases/tag/0.6)
|
||||
|
||||
The API has some minor BC breaks: some fields were renamed and entities have a larger attribute set than collections.
|
||||
Be aware that the API is still is development mode and shouldn't be considered stable for now.
|
||||
|
||||
## [0.5](https://github.com/kevinpapst/kimai2/releases/tag/0.5)
|
||||
|
||||
Some configuration nodes were removed, if you have one of them in your `local.yaml` you need to delete them before you start the update:
|
||||
- `kimai.invoice.calculator`
|
||||
- `kimai.invoice.renderer`
|
||||
- `kimai.invoice.number_generator`
|
||||
|
||||
The new config `kimai.invoice.documents` was introduced, holding a list of directories ([read more](https://www.kimai.org/documentation/invoices.html)).
|
||||
|
||||
**BC break:** InvoiceTemplate name was changed from 255 characters to 60. If you used longer invoice-template names, they will be truncated when upgrading the database.
|
||||
Please make sure that they are unique in the first 60 character before you upgrade your database with `doctrine:migrations:migrate`.
|
||||
|
||||
## [0.4](https://github.com/kevinpapst/kimai2/releases/tag/0.4)
|
||||
|
||||
In the time between 0.3 and 0.4 there was a release of composer that introduced a BC break,
|
||||
which leads to problems between Composer and Symfony Flex, resulting in an error like this when running it:
|
||||
|
||||
```
|
||||
[ErrorException]
|
||||
Declaration of Symfony\Flex\ParallelDownloader::getRemoteContents($originUrl, $fileUrl, $context) should be compatible with Composer\Util\RemoteFilesystem::getRemoteContents($originUrl, $fileUrl, $context, ?array &$responseHeaders = NULL)
|
||||
```
|
||||
|
||||
This can be fixed by updating Composer and Flex before executing the Kimai update:
|
||||
```
|
||||
sudo composer self-update
|
||||
sudo -u www-data composer update symfony/flex --no-plugins --no-scripts
|
||||
```
|
||||
|
||||
## [0.3](https://github.com/kevinpapst/kimai2/releases/tag/0.3)
|
||||
|
||||
You need to adjust your `.env` file and add your `from` address for [all emails](https://www.kimai.org/documentation/emails.html) generated by Kimai 2:
|
||||
```
|
||||
MAILER_FROM=kimai@example.com
|
||||
```
|
||||
|
||||
Create a file and database backup before executing the following steps:
|
||||
|
||||
```bash
|
||||
git pull origin master
|
||||
sudo -u www-data composer install --no-dev --optimize-autoloader
|
||||
sudo -u www-data bin/console cache:clear --env=prod
|
||||
sudo -u www-data bin/console cache:warmup --env=prod
|
||||
bin/console doctrine:migrations:version --add 20180701120000
|
||||
bin/console doctrine:migrations:migrate
|
||||
```
|
||||
Developer read the full documentation at [https://www.kimai.org/documentation/migration-v2.html](https://www.kimai.org/documentation/migration-v2.html).
|
||||
|
||||
- Invoice renderer and templates for XML, JSON and TEXT were moved to the [Extended invoicing plugin](https://www.kimai.org/store/invoice-bundle.html) (install if you use one of those)
|
||||
- Moved `company.docx` to [external repo](https://github.com/kimai/invoice-templates/tree/main/docx-company) (needs to be re-uploaded if you want to keep on using it!)
|
||||
- Role names are forced to be uppercase
|
||||
- Removed unused `public/avatars/` directory
|
||||
- Time-tracking mode `duration_only` was removed, existing installations will be switched to `duration_fixed_begin`
|
||||
- Removed Twig filters. You might have to replace them in your custom export/invoice templates:
|
||||
- `date_full` => `date_time`
|
||||
- `duration_decimal` => `duration(true)`
|
||||
- `currency` => `currency_name`
|
||||
- `country` => `country_name`
|
||||
- `language` => `language_name`
|
||||
- Removed support for custom translation files (use [TranslationBundle](https://www.kimai.org/store/translation-bundle.html) instead or write your own plugin)
|
||||
- Removed all 3rd party mailer packages, you need to install them manually (ONLY if you used a short syntax to configure the `MAILER_URL` in `.env`):
|
||||
- `composer require symfony/amazon-mailer`
|
||||
- `composer require symfony/google-mailer`
|
||||
- `composer require symfony/mailchimp-mailer`
|
||||
- `composer require symfony/mailgun-mailer`
|
||||
- `composer require symfony/postmark-mailer`
|
||||
- `composer require symfony/sendgrid-mailer`
|
||||
|
||||
0
assets/.gitignore
vendored
0
assets/.gitignore
vendored
1
assets/app-rtl.js
Normal file
1
assets/app-rtl.js
Normal file
@@ -0,0 +1 @@
|
||||
require('./sass/_app-rtl.scss');
|
||||
@@ -1,103 +1,9 @@
|
||||
// ------------------- INLINED ADMIN-LTE DEFINITIONS -------------------
|
||||
// require('../vendor/kevinpapst/adminlte-bundle/Resources/assets/admin-lte');
|
||||
// this was replaced to save around 300kb by:
|
||||
// - removing moment locales which are not used
|
||||
// - removing fullcalendar locales which are not used
|
||||
// - removing icheck which is not used
|
||||
// - removing jquery-ui which is not used
|
||||
|
||||
const $ = require('jquery');
|
||||
global.$ = global.jQuery = $;
|
||||
|
||||
require('bootstrap-sass');
|
||||
require('jquery-slimscroll');
|
||||
|
||||
require('select2');
|
||||
require('select2/dist/js/i18n/ar');
|
||||
require('select2/dist/js/i18n/cs');
|
||||
require('select2/dist/js/i18n/da');
|
||||
require('select2/dist/js/i18n/de');
|
||||
require('select2/dist/js/i18n/el');
|
||||
require('select2/dist/js/i18n/es');
|
||||
require('select2/dist/js/i18n/eu');
|
||||
require('select2/dist/js/i18n/fa');
|
||||
require('select2/dist/js/i18n/fi');
|
||||
require('select2/dist/js/i18n/fr');
|
||||
require('select2/dist/js/i18n/he');
|
||||
require('select2/dist/js/i18n/hu');
|
||||
require('select2/dist/js/i18n/it');
|
||||
require('select2/dist/js/i18n/ja');
|
||||
require('select2/dist/js/i18n/ko');
|
||||
require('select2/dist/js/i18n/nb');
|
||||
require('select2/dist/js/i18n/nl');
|
||||
require('select2/dist/js/i18n/pl');
|
||||
require('select2/dist/js/i18n/pt');
|
||||
require('select2/dist/js/i18n/pt-BR');
|
||||
require('select2/dist/js/i18n/ro');
|
||||
require('select2/dist/js/i18n/ru');
|
||||
require('select2/dist/js/i18n/sk');
|
||||
require('select2/dist/js/i18n/sv');
|
||||
require('select2/dist/js/i18n/tr');
|
||||
require('select2/dist/js/i18n/vi');
|
||||
require('select2/dist/js/i18n/zh-CN');
|
||||
|
||||
const Moment = require('moment');
|
||||
global.moment = Moment;
|
||||
require('moment/locale/ar');
|
||||
require('moment/locale/cs');
|
||||
require('moment/locale/da');
|
||||
require('moment/locale/de');
|
||||
require('moment/locale/de-at');
|
||||
require('moment/locale/de-ch');
|
||||
require('moment/locale/el');
|
||||
require('moment/locale/eo');
|
||||
require('moment/locale/es');
|
||||
require('moment/locale/eu');
|
||||
require('moment/locale/fa');
|
||||
require('moment/locale/fi');
|
||||
require('moment/locale/fo');
|
||||
require('moment/locale/fr');
|
||||
require('moment/locale/he');
|
||||
require('moment/locale/hu');
|
||||
require('moment/locale/it');
|
||||
require('moment/locale/ja');
|
||||
require('moment/locale/ko');
|
||||
require('moment/locale/nb');
|
||||
require('moment/locale/nl');
|
||||
require('moment/locale/pl');
|
||||
require('moment/locale/pt');
|
||||
require('moment/locale/pt-br');
|
||||
require('moment/locale/ro');
|
||||
require('moment/locale/ru');
|
||||
require('moment/locale/sk');
|
||||
require('moment/locale/sv');
|
||||
require('moment/locale/tr');
|
||||
require('moment/locale/vi');
|
||||
require('moment/locale/zh-cn');
|
||||
|
||||
require('daterangepicker');
|
||||
|
||||
// ------ AdminLTE framework ------
|
||||
require('./sass/bootstrap.scss');
|
||||
require('./sass/fontawesome.scss');
|
||||
require('admin-lte/dist/css/AdminLTE.min.css');
|
||||
require('admin-lte/dist/css/skins/_all-skins.css');
|
||||
require('../vendor/kevinpapst/adminlte-bundle/Resources/assets/admin-lte-extensions.scss');
|
||||
|
||||
global.$.AdminLTE = {};
|
||||
global.$.AdminLTE.options = {};
|
||||
require('admin-lte/dist/js/adminlte.min');
|
||||
// ------------------- INLINED ADMIN-LTE DEFINITIONS -------------------
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
require('./sass/app.scss');
|
||||
require('./sass/_app.scss');
|
||||
|
||||
// ------ Kimai itself ------
|
||||
require('./js/KimaiWebLoader.js');
|
||||
global.KimaiPaginatedBoxWidget = require('./js/widgets/KimaiPaginatedBoxWidget').default;
|
||||
global.KimaiReloadPageWidget = require('./js/widgets/KimaiReloadPageWidget').default;
|
||||
global.KimaiCookies = require('./js/widgets/KimaiCookies').default;
|
||||
global.KimaiColor = require('./js/widgets/KimaiColor').default;
|
||||
global.KimaiStorage = require('./js/widgets/KimaiStorage').default;
|
||||
|
||||
// ------ Autocomplete for tags only ------
|
||||
require('jquery-ui/ui/widgets/autocomplete');
|
||||
|
||||
@@ -1,39 +1,2 @@
|
||||
|
||||
// can be removed, once fullcalendar was updated and works without draggable jquery ui objects
|
||||
require('jquery-ui/ui/widgets/draggable');
|
||||
|
||||
require('fullcalendar');
|
||||
require('fullcalendar/dist/gcal.min');
|
||||
|
||||
require('fullcalendar/dist/locale/ar');
|
||||
require('fullcalendar/dist/locale/cs');
|
||||
require('fullcalendar/dist/locale/da');
|
||||
require('fullcalendar/dist/locale/de');
|
||||
require('fullcalendar/dist/locale/de-at');
|
||||
require('fullcalendar/dist/locale/de-ch');
|
||||
require('fullcalendar/dist/locale/el');
|
||||
require('fullcalendar/dist/locale/es');
|
||||
require('fullcalendar/dist/locale/eu');
|
||||
require('fullcalendar/dist/locale/fa');
|
||||
require('fullcalendar/dist/locale/fi');
|
||||
require('fullcalendar/dist/locale/fr');
|
||||
require('fullcalendar/dist/locale/he');
|
||||
require('fullcalendar/dist/locale/hu');
|
||||
require('fullcalendar/dist/locale/it');
|
||||
require('fullcalendar/dist/locale/ja');
|
||||
require('fullcalendar/dist/locale/ko');
|
||||
require('fullcalendar/dist/locale/nb');
|
||||
require('fullcalendar/dist/locale/nl');
|
||||
require('fullcalendar/dist/locale/pl');
|
||||
require('fullcalendar/dist/locale/pt');
|
||||
require('fullcalendar/dist/locale/pt-br');
|
||||
require('fullcalendar/dist/locale/ro');
|
||||
require('fullcalendar/dist/locale/ru');
|
||||
require('fullcalendar/dist/locale/sk');
|
||||
require('fullcalendar/dist/locale/sv');
|
||||
require('fullcalendar/dist/locale/tr');
|
||||
require('fullcalendar/dist/locale/zh-cn');
|
||||
require('fullcalendar/dist/locale/vi');
|
||||
require('fullcalendar/dist/locale/en-gb'); // the last imported file is used as fallback for locales that do not exist (like EO)
|
||||
|
||||
require('fullcalendar/dist/fullcalendar.min.css');
|
||||
global.KimaiCalendar = require('./js/widgets/KimaiCalendar').default;
|
||||
|
||||
@@ -1,2 +1,58 @@
|
||||
import {
|
||||
Chart,
|
||||
ArcElement,
|
||||
LineElement,
|
||||
BarElement,
|
||||
PointElement,
|
||||
BarController,
|
||||
// BubbleController,
|
||||
DoughnutController,
|
||||
LineController,
|
||||
PieController,
|
||||
// PolarAreaController,
|
||||
// RadarController,
|
||||
// ScatterController,
|
||||
CategoryScale,
|
||||
LinearScale,
|
||||
// LogarithmicScale,
|
||||
// RadialLinearScale,
|
||||
// TimeScale,
|
||||
// TimeSeriesScale,
|
||||
// Decimation,
|
||||
// Filler,
|
||||
Legend,
|
||||
Title,
|
||||
Tooltip,
|
||||
Colors,
|
||||
// SubTitle
|
||||
} from 'chart.js';
|
||||
|
||||
require('chart.js/dist/Chart.min');
|
||||
Chart.register(
|
||||
ArcElement,
|
||||
LineElement,
|
||||
BarElement,
|
||||
PointElement,
|
||||
BarController,
|
||||
// BubbleController,
|
||||
DoughnutController,
|
||||
LineController,
|
||||
PieController,
|
||||
// PolarAreaController,
|
||||
// RadarController,
|
||||
// ScatterController,
|
||||
CategoryScale,
|
||||
LinearScale,
|
||||
// LogarithmicScale,
|
||||
// RadialLinearScale,
|
||||
// TimeScale,
|
||||
// TimeSeriesScale,
|
||||
// Decimation,
|
||||
// Filler,
|
||||
Legend,
|
||||
Title,
|
||||
Tooltip,
|
||||
Colors
|
||||
// SubTitle
|
||||
);
|
||||
|
||||
global.Chart = Chart;
|
||||
8
assets/dashboard.js
Normal file
8
assets/dashboard.js
Normal file
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* https://gridstackjs.com
|
||||
* https://github.com/gridstack/gridstack.js/tree/master/doc
|
||||
*/
|
||||
require('gridstack/dist/gridstack.min.css');
|
||||
require('gridstack/dist/gridstack-extra.min.css');
|
||||
import { GridStack } from 'gridstack';
|
||||
global.GridStack = GridStack;
|
||||
2
assets/export-pdf.js
Normal file
2
assets/export-pdf.js
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
require('./sass/_export-pdf.scss');
|
||||
5
assets/highlight.js
Normal file
5
assets/highlight.js
Normal file
@@ -0,0 +1,5 @@
|
||||
require('highlight.js/styles/github-dark.css');
|
||||
|
||||
const hljs = require('highlight.js/lib/common');
|
||||
|
||||
global.hljs = hljs;
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 15 KiB |
@@ -1,2 +1,2 @@
|
||||
|
||||
require('./sass/invoice-pdf.scss');
|
||||
require('./sass/_invoice-pdf.scss');
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
|
||||
require('./sass/invoice.scss');
|
||||
/**
|
||||
* @deprecated use invoice-pdf instead
|
||||
*/
|
||||
require('./sass/_invoice.scss');
|
||||
|
||||
@@ -23,4 +23,31 @@ export default class KimaiConfiguration {
|
||||
return name in this._configurations;
|
||||
}
|
||||
|
||||
isRTL() {
|
||||
return this.get('direction') === 'rtl';
|
||||
}
|
||||
|
||||
getLanguage() {
|
||||
return this.get('locale').replace('_', '-');
|
||||
}
|
||||
|
||||
is24Hours() {
|
||||
return !!this.get('twentyFourHours');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} iso
|
||||
* @return {number}
|
||||
*/
|
||||
getFirstDayOfWeek(iso = true) {
|
||||
if (iso === undefined) {
|
||||
iso = true;
|
||||
}
|
||||
let config = this.get('first_dow_iso');
|
||||
if (!iso) {
|
||||
config = config % 7;
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ export default class KimaiContainer {
|
||||
/**
|
||||
* Create a new Container with the given configurations and translations.
|
||||
*
|
||||
* @param {Object} configuration
|
||||
* @param {Object} translation
|
||||
* @param {KimaiConfiguration} configuration
|
||||
* @param {KimaiTranslation} translation
|
||||
*/
|
||||
constructor(configuration, translation) {
|
||||
if (!(configuration instanceof KimaiConfiguration)) {
|
||||
@@ -88,4 +88,11 @@ export default class KimaiContainer {
|
||||
return this._configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {KimaiUser}
|
||||
*/
|
||||
getUser() {
|
||||
return this.getPlugin('user');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,80 +9,97 @@
|
||||
* [KIMAI] KimaiLoader: bootstrap the application and all plugins
|
||||
*/
|
||||
|
||||
import moment from 'moment';
|
||||
import { Settings } from 'luxon';
|
||||
import KimaiTranslation from "./KimaiTranslation";
|
||||
import KimaiConfiguration from "./KimaiConfiguration";
|
||||
import KimaiContainer from "./KimaiContainer";
|
||||
import KimaiActiveRecordsDuration from './plugins/KimaiActiveRecordsDuration.js';
|
||||
import KimaiDatatableColumnView from './plugins/KimaiDatatableColumnView.js';
|
||||
import KimaiThemeInitializer from "./plugins/KimaiThemeInitializer";
|
||||
import KimaiDateRangePicker from "./plugins/KimaiDateRangePicker";
|
||||
import KimaiDateRangePicker from "./forms/KimaiDateRangePicker";
|
||||
import KimaiDatatable from "./plugins/KimaiDatatable";
|
||||
import KimaiToolbar from "./plugins/KimaiToolbar";
|
||||
import KimaiAPI from "./plugins/KimaiAPI";
|
||||
import KimaiSelectDataAPI from "./plugins/KimaiSelectDataAPI";
|
||||
import KimaiDateTimePicker from "./plugins/KimaiDateTimePicker";
|
||||
import KimaiAlternativeLinks from "./plugins/KimaiAlternativeLinks";
|
||||
import KimaiAjaxModalForm from "./plugins/KimaiAjaxModalForm";
|
||||
import KimaiActiveRecords from "./plugins/KimaiActiveRecords";
|
||||
import KimaiRecentActivities from "./plugins/KimaiRecentActivities";
|
||||
import KimaiEvent from "./plugins/KimaiEvent";
|
||||
import KimaiAPILink from "./plugins/KimaiAPILink";
|
||||
import KimaiAlert from "./plugins/KimaiAlert";
|
||||
import KimaiAutocomplete from "./plugins/KimaiAutocomplete";
|
||||
import KimaiFormSelect from "./plugins/KimaiFormSelect";
|
||||
import KimaiAutocomplete from "./forms/KimaiAutocomplete";
|
||||
import KimaiFormSelect from "./forms/KimaiFormSelect";
|
||||
import KimaiForm from "./plugins/KimaiForm";
|
||||
import KimaiDatePicker from "./plugins/KimaiDatePicker";
|
||||
import KimaiDatePicker from "./forms/KimaiDatePicker";
|
||||
import KimaiConfirmationLink from "./plugins/KimaiConfirmationLink";
|
||||
import KimaiMultiUpdateTable from "./plugins/KimaiMultiUpdateTable";
|
||||
import KimaiDateUtils from "./plugins/KimaiDateUtils";
|
||||
import KimaiEscape from "./plugins/KimaiEscape";
|
||||
import KimaiFetch from "./plugins/KimaiFetch";
|
||||
import KimaiTimesheetForm from "./forms/KimaiTimesheetForm";
|
||||
import KimaiTeamForm from "./forms/KimaiTeamForm";
|
||||
import KimaiCopyDataForm from "./forms/KimaiCopyDataForm";
|
||||
import KimaiDateNowForm from "./forms/KimaiDateNowForm";
|
||||
import KimaiNotification from "./plugins/KimaiNotification";
|
||||
import KimaiHotkeys from "./plugins/KimaiHotkeys";
|
||||
import KimaiRemoteModal from "./plugins/KimaiRemoteModal";
|
||||
import KimaiUser from "./plugins/KimaiUser";
|
||||
import KimaiAutocompleteTags from "./forms/KimaiAutocompleteTags";
|
||||
|
||||
export default class KimaiLoader {
|
||||
|
||||
constructor(configurations, translations) {
|
||||
// set the current locale for all javascript components
|
||||
moment.locale(configurations['locale'].replace('_', '-').toLowerCase());
|
||||
Settings.defaultLocale = configurations['locale'].replace('_', '-').toLowerCase();
|
||||
Settings.defaultZone = configurations['timezone'];
|
||||
|
||||
const kimai = new KimaiContainer(
|
||||
new KimaiConfiguration(configurations),
|
||||
new KimaiTranslation(translations)
|
||||
);
|
||||
|
||||
// GLOBAL HELPER PLUGINS
|
||||
kimai.registerPlugin(new KimaiUser());
|
||||
kimai.registerPlugin(new KimaiEscape());
|
||||
kimai.registerPlugin(new KimaiEvent());
|
||||
kimai.registerPlugin(new KimaiAPI());
|
||||
kimai.registerPlugin(new KimaiAlert());
|
||||
kimai.registerPlugin(new KimaiFetch());
|
||||
kimai.registerPlugin(new KimaiDateUtils());
|
||||
kimai.registerPlugin(new KimaiFormSelect('.selectpicker'));
|
||||
kimai.registerPlugin(new KimaiNotification());
|
||||
|
||||
// FORM PLUGINS
|
||||
kimai.registerPlugin(new KimaiFormSelect('.selectpicker', 'select[data-related-select]'));
|
||||
kimai.registerPlugin(new KimaiDateRangePicker('input[data-daterangepicker="on"]'));
|
||||
kimai.registerPlugin(new KimaiDatePicker('input[data-datepicker="on"]'));
|
||||
kimai.registerPlugin(new KimaiAutocomplete());
|
||||
kimai.registerPlugin(new KimaiAutocompleteTags());
|
||||
kimai.registerPlugin(new KimaiTimesheetForm());
|
||||
kimai.registerPlugin(new KimaiTeamForm());
|
||||
kimai.registerPlugin(new KimaiCopyDataForm());
|
||||
kimai.registerPlugin(new KimaiDateNowForm());
|
||||
kimai.registerPlugin(new KimaiForm());
|
||||
kimai.registerPlugin(new KimaiHotkeys());
|
||||
|
||||
// SPECIAL FEATURES
|
||||
kimai.registerPlugin(new KimaiConfirmationLink('confirmation-link'));
|
||||
kimai.registerPlugin(new KimaiActiveRecordsDuration());
|
||||
kimai.registerPlugin(new KimaiDatatableColumnView('data-column-visibility'));
|
||||
kimai.registerPlugin(new KimaiDateRangePicker('input[data-daterangepickerenable="on"]'));
|
||||
kimai.registerPlugin(new KimaiDateTimePicker('input[data-datetimepicker="on"]'));
|
||||
kimai.registerPlugin(new KimaiDatePicker('input[data-datepickerenable="on"]'));
|
||||
kimai.registerPlugin(new KimaiDatatable('section.content', 'table.dataTable'));
|
||||
kimai.registerPlugin(new KimaiToolbar('form.searchform', 'toolbar-action'));
|
||||
kimai.registerPlugin(new KimaiSelectDataAPI('select[data-related-select]'));
|
||||
kimai.registerPlugin(new KimaiAlternativeLinks('.alternative-link'));
|
||||
kimai.registerPlugin(new KimaiAjaxModalForm('.modal-ajax-form'));
|
||||
kimai.registerPlugin(new KimaiRecentActivities('li.notifications-menu'));
|
||||
kimai.registerPlugin(new KimaiActiveRecords('li.messages-menu', 'li.messages-menu-empty'));
|
||||
kimai.registerPlugin(new KimaiAjaxModalForm('.modal-ajax-form', ['td.multiCheckbox', 'td.actions']));
|
||||
kimai.registerPlugin(new KimaiRemoteModal());
|
||||
kimai.registerPlugin(new KimaiActiveRecords());
|
||||
kimai.registerPlugin(new KimaiAPILink('api-link'));
|
||||
kimai.registerPlugin(new KimaiAutocomplete('.js-autocomplete'));
|
||||
kimai.registerPlugin(new KimaiForm());
|
||||
kimai.registerPlugin(new KimaiThemeInitializer());
|
||||
kimai.registerPlugin(new KimaiMultiUpdateTable());
|
||||
//kimai.registerPlugin(new KimaiPauseRecord('li.messages-menu ul.menu li'));
|
||||
kimai.registerPlugin(new KimaiThemeInitializer());
|
||||
|
||||
// notify all listeners that Kimai plugins can now be registered
|
||||
kimai.getPlugin('event').trigger('kimai.pluginRegister', {'kimai': kimai});
|
||||
document.dispatchEvent(new CustomEvent('kimai.pluginRegister', {detail: {'kimai': kimai}}));
|
||||
|
||||
// initialize all plugins
|
||||
kimai.getPlugins().map(plugin => { plugin.init(); });
|
||||
|
||||
// notify all listeners that Kimai is now ready to be used
|
||||
kimai.getPlugin('event').trigger('kimai.initialized', {'kimai': kimai});
|
||||
document.dispatchEvent(new CustomEvent('kimai.initialized', {detail: {'kimai': kimai}}));
|
||||
|
||||
this.kimai = kimai;
|
||||
}
|
||||
|
||||
@@ -58,6 +58,20 @@ export default class KimaiPlugin {
|
||||
return this.getContainer().getConfiguration().get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {KimaiConfiguration}
|
||||
*/
|
||||
getConfigurations() {
|
||||
return this.getContainer().getConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {KimaiDateUtils}
|
||||
*/
|
||||
getDateUtils() {
|
||||
return this.getPlugin('date');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @returns {KimaiPlugin}
|
||||
@@ -67,10 +81,82 @@ export default class KimaiPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {KimaiTranslation}
|
||||
*/
|
||||
getTranslation() {
|
||||
return this.getContainer().getTranslation();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @returns {string}
|
||||
*/
|
||||
translate(name) {
|
||||
return this.getTranslation().get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use the plugin directly
|
||||
* @param {string} title
|
||||
* @returns {string}
|
||||
*/
|
||||
escape(title) {
|
||||
return this.getPlugin('escape').escapeForHtml(title);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {string|null} details
|
||||
*/
|
||||
trigger(name, details = null) {
|
||||
this.getPlugin('event').trigger(name, details);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @param {object} options
|
||||
* @returns {Promise<Response>}
|
||||
*/
|
||||
fetch(url, options = {}) {
|
||||
return this.getPlugin('fetch').fetch(url, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
* @param {object} options
|
||||
* @param {string|null} url
|
||||
* @returns {Promise<Response>}
|
||||
*/
|
||||
fetchForm(form, options = {}, url = null) {
|
||||
url = url || form.getAttribute('action');
|
||||
const method = form.getAttribute('method').toUpperCase();
|
||||
|
||||
if (method === 'GET') {
|
||||
const data = this.getPlugin('form').convertFormDataToQueryString(form, {}, true);
|
||||
// TODO const data = new URLSearchParams(new FormData(form)).toString();
|
||||
url = url + (url.includes('?') ? '&' : '?') + data;
|
||||
options = {...{method: 'GET'}, ...options};
|
||||
} else if (method === 'POST') {
|
||||
options = {...{
|
||||
method: 'POST',
|
||||
body: new FormData(form)
|
||||
}, ...options};
|
||||
}
|
||||
|
||||
return this.fetch(url, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current device is a mobile device (targeting the bootstrip xs breakpoint size).
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isMobile() {
|
||||
const width = Math.max(
|
||||
document.documentElement.clientWidth,
|
||||
window.innerWidth || 0
|
||||
);
|
||||
|
||||
return width < 576;
|
||||
}
|
||||
}
|
||||
|
||||
98
assets/js/forms/KimaiAutocomplete.js
Normal file
98
assets/js/forms/KimaiAutocomplete.js
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import TomSelect from 'tom-select';
|
||||
import KimaiFormTomselectPlugin from "./KimaiFormTomselectPlugin";
|
||||
|
||||
/**
|
||||
* Supporting auto-complete fields via API.
|
||||
*/
|
||||
export default class KimaiAutocomplete extends KimaiFormTomselectPlugin {
|
||||
|
||||
init()
|
||||
{
|
||||
this.selector = '[data-form-widget="autocomplete"]';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
* @return boolean
|
||||
*/
|
||||
supportsForm(form) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
loadData(apiUrl, query, callback) {
|
||||
/** @type {KimaiAPI} API */
|
||||
const API = this.getContainer().getPlugin('api');
|
||||
|
||||
API.get(apiUrl, {'name': query}, (data) => {
|
||||
let results = [];
|
||||
for (let item of data) {
|
||||
results.push({text: item.name, value: item.name});
|
||||
}
|
||||
callback(results);
|
||||
}, () => {
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
activateForm(form)
|
||||
{
|
||||
[].slice.call(form.querySelectorAll(this.selector)).map((node) => {
|
||||
const apiUrl = node.dataset['autocompleteUrl'];
|
||||
let minChars = 3;
|
||||
if (node.dataset['minimumCharacter'] !== undefined) {
|
||||
minChars = parseInt(node.dataset['minimumCharacter']);
|
||||
}
|
||||
|
||||
let options = {
|
||||
// see https://github.com/orchidjs/tom-select/issues/543#issuecomment-1664342257
|
||||
onItemAdd: function(){
|
||||
// remove remaining characters from input after selecting an item
|
||||
this.setTextboxValue('');
|
||||
},
|
||||
// if there are more than 500, they need to be found by "typing"
|
||||
maxOptions: 500,
|
||||
// the autocomplete is ONLY used, when the user can create tags
|
||||
create: node.dataset['create'] !== undefined,
|
||||
onOptionAdd: (value) => {
|
||||
node.dispatchEvent(new CustomEvent('create', {detail: {'value': value}}));
|
||||
},
|
||||
plugins: ['remove_button'],
|
||||
shouldLoad: function(query) {
|
||||
return query.length >= minChars;
|
||||
},
|
||||
load: (query, callback) => {
|
||||
this.loadData(apiUrl, query, callback);
|
||||
},
|
||||
};
|
||||
|
||||
let render = {
|
||||
// eslint-disable-next-line
|
||||
not_loading: (data, escape) => {
|
||||
// no default content
|
||||
},
|
||||
};
|
||||
|
||||
const rendererType = (node.dataset['renderer'] !== undefined) ? node.dataset['renderer'] : 'default';
|
||||
options.render = {...render, ...this.getRenderer(rendererType)};
|
||||
|
||||
new TomSelect(node, options);
|
||||
});
|
||||
}
|
||||
|
||||
destroyForm(form) {
|
||||
[].slice.call(form.querySelectorAll(this.selector)).map((node) => {
|
||||
if (node.tomselect) {
|
||||
node.tomselect.destroy();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
34
assets/js/forms/KimaiAutocompleteTags.js
Normal file
34
assets/js/forms/KimaiAutocompleteTags.js
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import KimaiAutocomplete from "./KimaiAutocomplete";
|
||||
|
||||
/**
|
||||
* Used for timesheet tagging in toolbar and edit dialogs.
|
||||
*/
|
||||
export default class KimaiAutocompleteTags extends KimaiAutocomplete {
|
||||
|
||||
init()
|
||||
{
|
||||
this.selector = '[data-form-widget="tags"]';
|
||||
}
|
||||
|
||||
loadData(apiUrl, query, callback) {
|
||||
/** @type {KimaiAPI} API */
|
||||
const API = this.getContainer().getPlugin('api');
|
||||
|
||||
API.get(apiUrl, {'name': query}, (data) => {
|
||||
let results = [];
|
||||
for (let item of data) {
|
||||
results.push({text: item.name, value: item.name, color: item['color-safe']});
|
||||
}
|
||||
callback(results);
|
||||
}, () => {
|
||||
callback();
|
||||
});
|
||||
}
|
||||
}
|
||||
71
assets/js/forms/KimaiCopyDataForm.js
Normal file
71
assets/js/forms/KimaiCopyDataForm.js
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiEditTimesheetForm: responsible for the most important form in the application
|
||||
*/
|
||||
|
||||
import KimaiFormPlugin from "./KimaiFormPlugin";
|
||||
|
||||
/**
|
||||
* Used for simple copy from link to input action, e.g. the time and duration dropdowns
|
||||
* copy the selected values into their corresponding input.
|
||||
*/
|
||||
export default class KimaiCopyDataForm extends KimaiFormPlugin {
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
* @return boolean
|
||||
*/
|
||||
supportsForm(form) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
*/
|
||||
activateForm(form)
|
||||
{
|
||||
if (this._eventHandler === undefined) {
|
||||
this._eventHandler = (event) => {
|
||||
let element = event.target;
|
||||
if (!element.matches('a[data-form-widget="copy-data"]')) {
|
||||
element = element.parentNode; // mostly for icons
|
||||
}
|
||||
if (!element.matches('a[data-form-widget="copy-data"]') || element.dataset.target === undefined) {
|
||||
return;
|
||||
}
|
||||
const target = document.querySelector(element.dataset.target);
|
||||
if (target === null) {
|
||||
return;
|
||||
}
|
||||
target.value = element.dataset.value;
|
||||
if (element.dataset.event !== undefined) {
|
||||
for (const event of element.dataset.event.split(' ')) {
|
||||
target.dispatchEvent(new Event(event));
|
||||
const form = target.closest('form');
|
||||
if (form !== null) {
|
||||
form.dispatchEvent(new Event(event));
|
||||
}
|
||||
}
|
||||
}
|
||||
event.preventDefault();
|
||||
};
|
||||
}
|
||||
form.addEventListener('click', this._eventHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
*/
|
||||
destroyForm(form)
|
||||
{
|
||||
form.removeEventListener('click', this._eventHandler);
|
||||
}
|
||||
|
||||
}
|
||||
73
assets/js/forms/KimaiDateNowForm.js
Normal file
73
assets/js/forms/KimaiDateNowForm.js
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiEditTimesheetForm: responsible for the most important form in the application
|
||||
*/
|
||||
|
||||
import KimaiFormPlugin from "./KimaiFormPlugin";
|
||||
|
||||
/**
|
||||
*/
|
||||
export default class KimaiDateNowForm extends KimaiFormPlugin {
|
||||
|
||||
init()
|
||||
{
|
||||
this.selector = 'a[data-form-widget="date-now"]';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
* @return boolean
|
||||
*/
|
||||
supportsForm(form) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
*/
|
||||
activateForm(form)
|
||||
{
|
||||
[].slice.call(form.querySelectorAll(this.selector)).map((element) => {
|
||||
if (element.dataset.format !== undefined && element.dataset.target !== undefined) {
|
||||
if (this._eventHandler === undefined) {
|
||||
this._eventHandler = (event) => {
|
||||
const linkTarget = event.currentTarget;
|
||||
|
||||
const formElement = document.getElementById(linkTarget.dataset.target);
|
||||
if (!formElement.disabled) {
|
||||
formElement.value = this.getDateUtils().format(linkTarget.dataset.format, null);
|
||||
// this should usually work
|
||||
formElement.dispatchEvent(new Event('change', {bubbles: true}));
|
||||
// this is required for Litepicker to pick the new date (with autoRefresh option)
|
||||
formElement.dispatchEvent(new Event('keyup', {bubbles: true}));
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
};
|
||||
}
|
||||
element.addEventListener('click', this._eventHandler);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
*/
|
||||
destroyForm(form)
|
||||
{
|
||||
[].slice.call(form.querySelectorAll(this.selector)).map((element) => {
|
||||
if (element.dataset.format !== undefined && element.dataset.target !== undefined) {
|
||||
element.removeEventListener('click', this._eventHandler);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
129
assets/js/forms/KimaiDatePicker.js
Normal file
129
assets/js/forms/KimaiDatePicker.js
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiDatePicker: single date selects (currently unused)
|
||||
*/
|
||||
|
||||
import { Litepicker } from 'litepicker';
|
||||
import 'litepicker/dist/plugins/mobilefriendly';
|
||||
import KimaiFormPlugin from "./KimaiFormPlugin";
|
||||
|
||||
export default class KimaiDatePicker extends KimaiFormPlugin {
|
||||
|
||||
constructor(selector)
|
||||
{
|
||||
super();
|
||||
this._selector = selector;
|
||||
}
|
||||
|
||||
init()
|
||||
{
|
||||
window.disableLitepickerStyles = true;
|
||||
this._pickers = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
* @return boolean
|
||||
*/
|
||||
supportsForm(form) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
*/
|
||||
activateForm(form)
|
||||
{
|
||||
const FIRST_DOW = this.getConfigurations().getFirstDayOfWeek(false);
|
||||
const LANGUAGE = this.getConfigurations().getLanguage();
|
||||
|
||||
let options = {
|
||||
buttonText: {
|
||||
previousMonth: `<i class="fas fa-chevron-left"></i>`,
|
||||
nextMonth: `<i class="fas fa-chevron-right"></i>`,
|
||||
apply: this.translate('confirm'),
|
||||
cancel: this.translate('cancel'),
|
||||
},
|
||||
};
|
||||
|
||||
const newPickers = [].slice.call(form.querySelectorAll(this._selector)).map((element) => {
|
||||
if (element.dataset.format === undefined) {
|
||||
console.log('Trying to bind litepicker to an element without data-format attribute');
|
||||
}
|
||||
if (element.hasAttribute('min') !== undefined) {
|
||||
options = {...options, ...{
|
||||
'minDate': element.getAttribute('min'),
|
||||
}};
|
||||
}
|
||||
if (element.hasAttribute('max') !== undefined) {
|
||||
options = {...options, ...{
|
||||
'maxDate': element.getAttribute('max'),
|
||||
}};
|
||||
}
|
||||
options = {...options, ...{
|
||||
format: element.dataset.format,
|
||||
showTooltip: false,
|
||||
element: element,
|
||||
lang: LANGUAGE,
|
||||
autoRefresh: true,
|
||||
firstDay: FIRST_DOW, // Litepicker: 0 = Sunday, 1 = Monday
|
||||
setup: (picker) => {
|
||||
// nasty hack, because litepicker does not trigger change event on the input and the available
|
||||
// event "selected" is triggered way to often, even when moving the cursor inside the input
|
||||
// element (not even typing is necessary) and so we have to make sure that the manual "click" event
|
||||
// (works for touch as well) happened before we actually dispatch the change event manually ...
|
||||
// what? report forms would be submitted upon cursor move without the "preselect” check
|
||||
picker.on('preselect', (date1, date2) => { // eslint-disable-line no-unused-vars
|
||||
picker._wasPreselected = true;
|
||||
});
|
||||
picker.on('selected', (date1, date2) => { // eslint-disable-line no-unused-vars
|
||||
if (picker._wasPreselected !== undefined) {
|
||||
element.dispatchEvent(new Event('change', {bubbles: true}));
|
||||
delete picker._wasPreselected;
|
||||
}
|
||||
});
|
||||
|
||||
// only if mobile.friendly plugin is activated
|
||||
if (picker.backdrop !== undefined) {
|
||||
// the node needs to be moved, so the flat form layout works properly (e.g. for date types)
|
||||
document.body.appendChild(picker.backdrop);
|
||||
}
|
||||
},
|
||||
}};
|
||||
|
||||
return [element, new Litepicker(this.prepareOptions(options))];
|
||||
});
|
||||
|
||||
this._pickers = this._pickers.concat(newPickers);
|
||||
}
|
||||
|
||||
prepareOptions(options)
|
||||
{
|
||||
return {...options, ...{
|
||||
plugins: ['mobilefriendly'],
|
||||
}};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
*/
|
||||
destroyForm(form)
|
||||
{
|
||||
[].slice.call(form.querySelectorAll(this._selector)).map((element) => {
|
||||
for (let i = 0; i < this._pickers.length; i++) {
|
||||
if (this._pickers[i][0] === element) {
|
||||
this._pickers[i][1].destroy();
|
||||
this._pickers.splice(i, 1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
25
assets/js/forms/KimaiDateRangePicker.js
Normal file
25
assets/js/forms/KimaiDateRangePicker.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiDateRangePicker: activate the (daterange picker) compound field in toolbar
|
||||
*/
|
||||
|
||||
import KimaiDatePicker from "./KimaiDatePicker";
|
||||
|
||||
export default class KimaiDateRangePicker extends KimaiDatePicker {
|
||||
|
||||
prepareOptions(options)
|
||||
{
|
||||
return {...options, ...{
|
||||
plugins: ['mobilefriendly'],
|
||||
singleMode: false,
|
||||
autoRefresh: true,
|
||||
}};
|
||||
}
|
||||
|
||||
}
|
||||
39
assets/js/forms/KimaiFormPlugin.js
Normal file
39
assets/js/forms/KimaiFormPlugin.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiFormPlugin: base class for all none ID plugin that handle forms
|
||||
*/
|
||||
|
||||
import KimaiPlugin from '../KimaiPlugin';
|
||||
|
||||
export default class KimaiFormPlugin extends KimaiPlugin {
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
* @return boolean
|
||||
*/
|
||||
supportsForm(form) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
*/
|
||||
activateForm(form) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
*/
|
||||
destroyForm(form) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
564
assets/js/forms/KimaiFormSelect.js
Normal file
564
assets/js/forms/KimaiFormSelect.js
Normal file
@@ -0,0 +1,564 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiFormSelect: enhanced functionality for HTMLSelectElement
|
||||
*/
|
||||
|
||||
import TomSelect from 'tom-select';
|
||||
import KimaiFormTomselectPlugin from "./KimaiFormTomselectPlugin";
|
||||
|
||||
export default class KimaiFormSelect extends KimaiFormTomselectPlugin {
|
||||
|
||||
constructor(selector, apiSelects)
|
||||
{
|
||||
super();
|
||||
this._selector = selector;
|
||||
this._apiSelects = apiSelects;
|
||||
}
|
||||
|
||||
getId()
|
||||
{
|
||||
return 'form-select';
|
||||
}
|
||||
|
||||
init()
|
||||
{
|
||||
// selects the original value inside dropdowns, as the "reset" event (the updated option)
|
||||
// is not automatically propagated to the JS element
|
||||
document.addEventListener('reset', (event) => {
|
||||
if (event.target.tagName.toUpperCase() === 'FORM') {
|
||||
setTimeout(() => {
|
||||
const fields = event.target.querySelectorAll(this._selector);
|
||||
for (let field of fields) {
|
||||
if (field.tagName.toUpperCase() === 'SELECT') {
|
||||
field.dispatchEvent(new Event('data-reloaded'));
|
||||
}
|
||||
}
|
||||
}, 10);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} node
|
||||
*/
|
||||
activateSelectPickerByElement(node)
|
||||
{
|
||||
let plugins = ['change_listener'];
|
||||
|
||||
const isMultiple = node.multiple !== undefined && node.multiple === true;
|
||||
const isRequired = node.required !== undefined && node.required === true;
|
||||
|
||||
if (isRequired) {
|
||||
plugins.push('no_backspace_delete');
|
||||
}
|
||||
|
||||
if (isMultiple) {
|
||||
plugins.push('remove_button');
|
||||
}
|
||||
|
||||
if (node.dataset['order'] !== undefined && node.dataset['order'] === '1') {
|
||||
//plugins.push('caret_position');
|
||||
plugins.push('drag_drop');
|
||||
}
|
||||
|
||||
let options = {
|
||||
// see https://github.com/orchidjs/tom-select/issues/543#issuecomment-1664342257
|
||||
onItemAdd: function(){
|
||||
// remove remaining characters from input after selecting an item
|
||||
this.setTextboxValue('');
|
||||
},
|
||||
lockOptgroupOrder: true,
|
||||
allowEmptyOption: !isRequired,
|
||||
hidePlaceholder: false,
|
||||
plugins: plugins,
|
||||
// if there are more than X entries, the other ones are hidden and can only be found
|
||||
// by typing some characters to trigger the internal option search
|
||||
// see App\Form\Type\TagsType::MAX_AMOUNT_SELECT
|
||||
// TODO make this value configurable with a data attribute
|
||||
maxOptions: 500,
|
||||
sortField:[{field: '$order'}, {field: '$score'}],
|
||||
// required so it works in table.responsive, but requires z-index 1056, because bootstrap modal would otherwise hide it
|
||||
dropdownParent: 'body',
|
||||
};
|
||||
|
||||
let render = {
|
||||
onOptionAdd: (value) => {
|
||||
node.dispatchEvent(new CustomEvent('create', {detail: {'value': value}}));
|
||||
},
|
||||
};
|
||||
|
||||
const rendererType = (node.dataset['renderer'] !== undefined) ? node.dataset['renderer'] : 'default';
|
||||
options.render = {...render, ...this.getRenderer(rendererType)};
|
||||
|
||||
if (node.dataset['create'] !== undefined) {
|
||||
options = {...options, ...{
|
||||
persist: true,
|
||||
create: true,
|
||||
}};
|
||||
} else {
|
||||
options = {...options, ...{
|
||||
persist: false,
|
||||
create: false,
|
||||
}};
|
||||
}
|
||||
|
||||
if (node.dataset.disableSearch !== undefined) {
|
||||
options = {...options, ...{
|
||||
controlInput: null,
|
||||
}};
|
||||
}
|
||||
|
||||
const select = new TomSelect(node, options);
|
||||
node.addEventListener('data-reloaded', (event) => {
|
||||
select.clear(true);
|
||||
select.clearOptionGroups();
|
||||
select.clearOptions();
|
||||
select.sync();
|
||||
select.setValue(event.detail);
|
||||
select.refreshItems();
|
||||
select.refreshOptions(false);
|
||||
});
|
||||
|
||||
// support reloading the list upon external event
|
||||
if (node.dataset['reload'] !== undefined) {
|
||||
node.addEventListener('reload', () => {
|
||||
select.disable();
|
||||
node.disabled = true;
|
||||
|
||||
/** @type {KimaiAPI} API */
|
||||
const API = this.getContainer().getPlugin('api');
|
||||
|
||||
API.get(node.dataset['reload'], {}, (data) => {
|
||||
this._updateSelect(node, data);
|
||||
select.enable();
|
||||
node.disabled = false;
|
||||
});
|
||||
|
||||
node.dispatchEvent(new Event('change'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
* @return boolean
|
||||
*/
|
||||
supportsForm(form) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
*/
|
||||
activateForm(form)
|
||||
{
|
||||
[].slice.call(form.querySelectorAll(this._selector)).map((node) => {
|
||||
this.activateSelectPickerByElement(node);
|
||||
});
|
||||
|
||||
this._activateApiSelects(this._apiSelects);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
*/
|
||||
destroyForm(form)
|
||||
{
|
||||
[].slice.call(form.querySelectorAll(this._selector)).map((node) => {
|
||||
if (node.tomselect) {
|
||||
node.tomselect.destroy();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string|Element} selectIdentifier
|
||||
* @param {object} data
|
||||
* @private
|
||||
*/
|
||||
_updateOptions(selectIdentifier, data)
|
||||
{
|
||||
let emptyOption = null;
|
||||
let node = null;
|
||||
if (selectIdentifier instanceof Element) {
|
||||
node = selectIdentifier;
|
||||
} else {
|
||||
node = document.querySelector(selectIdentifier);
|
||||
}
|
||||
if (node === null) {
|
||||
console.log('Missing select: ' + selectIdentifier);
|
||||
return;
|
||||
}
|
||||
const selectedValue = node.value;
|
||||
|
||||
for (let i = 0; i < node.options.length; i++) {
|
||||
if (node.options[i].value === '') {
|
||||
emptyOption = node.options[i];
|
||||
}
|
||||
}
|
||||
|
||||
node.options.length = 0;
|
||||
|
||||
if (emptyOption !== null) {
|
||||
node.appendChild(this._createOption(emptyOption.text, ''));
|
||||
}
|
||||
|
||||
let emptyOpts = [];
|
||||
let options = [];
|
||||
/** @type {string|null} titlePattern */
|
||||
let titlePattern = null;
|
||||
if (node.dataset !== undefined && node.dataset['optionPattern'] !== undefined) {
|
||||
titlePattern = node.dataset['optionPattern'];
|
||||
}
|
||||
if (titlePattern === null || titlePattern === '') {
|
||||
titlePattern = '{name}';
|
||||
}
|
||||
|
||||
for (const [key, value] of Object.entries(data)) {
|
||||
if (key === '__empty__') {
|
||||
for (const entity of value) {
|
||||
emptyOpts.push(this._createOption(this._getTitleFromPattern(titlePattern, entity), entity.id));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
let optGroup = this._createOptgroup(key);
|
||||
for (const entity of value) {
|
||||
optGroup.appendChild(this._createOption(this._getTitleFromPattern(titlePattern, entity), entity.id));
|
||||
}
|
||||
options.push(optGroup);
|
||||
}
|
||||
|
||||
// log the one with a group name first (e.g. non-global activities)
|
||||
options.forEach(child => node.appendChild(child));
|
||||
|
||||
// append the ones with no parent at the end (e.g. global activities)
|
||||
const optGroupEmpty = this._createOptgroup('');
|
||||
emptyOpts.forEach(child => optGroupEmpty.appendChild(child));
|
||||
node.appendChild(optGroupEmpty);
|
||||
|
||||
// if available, re-select the previous selected option (mostly usable for global activities)
|
||||
node.value = selectedValue;
|
||||
|
||||
// pre-select an option if it is the only available one
|
||||
if (node.value === '' || node.value === null) {
|
||||
const allOptions = node.options;
|
||||
const optionLength = allOptions.length;
|
||||
let selectOption = '';
|
||||
|
||||
if (optionLength === 1 && node.dataset['autoselect'] === undefined) {
|
||||
selectOption = allOptions[0].value;
|
||||
} else if (optionLength === 2 && emptyOption !== null) {
|
||||
selectOption = allOptions[1].value;
|
||||
}
|
||||
|
||||
if (selectOption !== '') {
|
||||
node.value = selectOption;
|
||||
}
|
||||
}
|
||||
|
||||
// this will update the attached javascript component
|
||||
node.dispatchEvent(new CustomEvent('data-reloaded', {detail: node.value}));
|
||||
// if we don't trigger the change, the other selects won't reset
|
||||
node.dispatchEvent(new Event('change'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} pattern
|
||||
* @param {array} entity
|
||||
* @private
|
||||
*/
|
||||
_getTitleFromPattern(pattern, entity)
|
||||
{
|
||||
const DATE_UTILS = this.getDateUtils();
|
||||
const regexp = new RegExp('{[^}]*?}','g');
|
||||
let title = pattern;
|
||||
let match = null;
|
||||
|
||||
while ((match = regexp.exec(pattern)) !== null) {
|
||||
// cutting a string like "{name}" into "name"
|
||||
const field = match[0].slice(1, -1);
|
||||
let value = entity[field] === undefined ? null : entity[field];
|
||||
if ((field === 'start' || field === 'end')) {
|
||||
if (value === null) {
|
||||
value = '?';
|
||||
} else {
|
||||
value = DATE_UTILS.getFormattedDate(value);
|
||||
}
|
||||
}
|
||||
|
||||
title = title.replace(new RegExp('{' + field + '}', 'g'), value ?? '');
|
||||
}
|
||||
title = title.replace(/- \?-\?/, '');
|
||||
title = title.replace(/\r\n|\r|\n/g, ' ');
|
||||
title = title.substring(0, 110);
|
||||
|
||||
const chars = '- ';
|
||||
let start = 0, end = title.length;
|
||||
|
||||
while (start < end && chars.indexOf(title[start]) >= 0) {
|
||||
++start;
|
||||
}
|
||||
|
||||
while (end > start && chars.indexOf(title[end - 1]) >= 0) {
|
||||
--end;
|
||||
}
|
||||
|
||||
let result = (start > 0 || end < title.length) ? title.substring(start, end) : title;
|
||||
|
||||
if (result === '' && entity['name'] !== undefined) {
|
||||
return entity['name'];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLSelectElement} select
|
||||
* @param {string} label
|
||||
* @param {string} value
|
||||
* @param {object} dataset
|
||||
*/
|
||||
addOption(select, label, value, dataset)
|
||||
{
|
||||
const option = this._createOption(label, value);
|
||||
for (const key in dataset) {
|
||||
option.dataset[key] = dataset[key];
|
||||
}
|
||||
|
||||
select.options.add(option);
|
||||
if (select.tomselect !== undefined) {
|
||||
select.tomselect.sync();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {HTMLSelectElement} select
|
||||
* @param {HTMLOptionElement} option
|
||||
*/
|
||||
removeOption(select, option)
|
||||
{
|
||||
option.remove();
|
||||
if (select.tomselect !== undefined) {
|
||||
select.tomselect.removeOption(option.value, true);
|
||||
select.tomselect.clear(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} label
|
||||
* @param {string} value
|
||||
* @returns {HTMLElement}
|
||||
* @private
|
||||
*/
|
||||
_createOption(label, value)
|
||||
{
|
||||
let option = document.createElement('option');
|
||||
option.innerText = label;
|
||||
option.value = value;
|
||||
return option;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} label
|
||||
* @returns {HTMLElement}
|
||||
* @private
|
||||
*/
|
||||
_createOptgroup(label)
|
||||
{
|
||||
let optGroup = document.createElement('optgroup');
|
||||
optGroup.label = label;
|
||||
return optGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} selector
|
||||
* @private
|
||||
*/
|
||||
_activateApiSelects(selector)
|
||||
{
|
||||
if (this._eventHandlerApiSelects === undefined) {
|
||||
this._eventHandlerApiSelects = (event) => {
|
||||
if (event.target === null || !event.target.matches(selector)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const apiSelect = event.target;
|
||||
const targetSelectId = '#' + apiSelect.dataset['relatedSelect'];
|
||||
/** @type {HTMLSelectElement} targetSelect */
|
||||
const targetSelect = document.getElementById(apiSelect.dataset['relatedSelect']);
|
||||
|
||||
// if the related target select does not exist, we do not need to load the related data
|
||||
if (targetSelect === null || targetSelect.dataset['reloading'] === '1') {
|
||||
return;
|
||||
}
|
||||
targetSelect.dataset['reloading'] = '1';
|
||||
|
||||
if (targetSelect.tomselect !== undefined) {
|
||||
targetSelect.tomselect.disable();
|
||||
}
|
||||
targetSelect.disabled = true;
|
||||
|
||||
let formPrefix = apiSelect.dataset['formPrefix'];
|
||||
if (formPrefix === undefined || formPrefix === null) {
|
||||
formPrefix = '';
|
||||
} else if (formPrefix.length > 0) {
|
||||
formPrefix += '_';
|
||||
}
|
||||
|
||||
let newApiUrl = this._buildUrlWithFormFields(apiSelect.dataset['apiUrl'], formPrefix);
|
||||
|
||||
const selectValue = apiSelect.value;
|
||||
|
||||
// Problem: select a project with activities and then select a customer that has no project
|
||||
// results in a wrong URL, it triggers "activities?project=" instead of using the "emptyUrl"
|
||||
if (selectValue === undefined || selectValue === null || selectValue === '' || (Array.isArray(selectValue) && selectValue.length === 0)) {
|
||||
if (apiSelect.dataset['emptyUrl'] === undefined) {
|
||||
this._updateSelect(targetSelectId, {});
|
||||
targetSelect.dataset['reloading'] = '0';
|
||||
return;
|
||||
}
|
||||
newApiUrl = this._buildUrlWithFormFields(apiSelect.dataset['emptyUrl'], formPrefix);
|
||||
}
|
||||
|
||||
/** @type {KimaiAPI} API */
|
||||
const API = this.getContainer().getPlugin('api');
|
||||
|
||||
API.get(newApiUrl, {}, (data) => {
|
||||
this._updateSelect(targetSelectId, data);
|
||||
if (targetSelect.tomselect !== undefined) {
|
||||
targetSelect.tomselect.enable();
|
||||
}
|
||||
targetSelect.dataset['reloading'] = '0';
|
||||
targetSelect.disabled = false;
|
||||
});
|
||||
};
|
||||
|
||||
document.addEventListener('change', this._eventHandlerApiSelects);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} apiUrl
|
||||
* @param {string} formPrefix
|
||||
* @return {string}
|
||||
* @private
|
||||
*/
|
||||
_buildUrlWithFormFields(apiUrl, formPrefix)
|
||||
{
|
||||
let newApiUrl = apiUrl;
|
||||
|
||||
apiUrl.split('?')[1].split('&').forEach(item => {
|
||||
const [key, value] = item.split('='); // eslint-disable-line no-unused-vars
|
||||
const decoded = decodeURIComponent(value);
|
||||
const test = decoded.match(/%(.*)%/);
|
||||
if (test !== null) {
|
||||
const originalFieldName = test[1];
|
||||
const targetFieldName = (formPrefix + originalFieldName).replace(/\[/, '').replace(/]/, '');
|
||||
const targetField = document.getElementById(targetFieldName);
|
||||
let newValue = '';
|
||||
if (targetField === null) {
|
||||
// happens for example:
|
||||
// - in duration only mode, when the end field is not found
|
||||
// console.log('ERROR: Cannot find field with name "' + test[1] + '" by selector: #' + formPrefix + test[1]);
|
||||
} else {
|
||||
if (targetField.value !== null) {
|
||||
newValue = targetField.value;
|
||||
if (targetField.tagName === 'SELECT' && targetField.multiple) {
|
||||
newValue = [...targetField.selectedOptions].map(o => o.value);
|
||||
} else if (newValue !== '') {
|
||||
if (targetField.type === 'date') {
|
||||
const timeId = targetField.id.replace('_date', '_time');
|
||||
const timeElement = document.getElementById(timeId);
|
||||
const time = timeElement === null ? '12:00:00' : timeElement.value;
|
||||
// using 12:00 as fallback, because timezone handling might change the date if we use 00:00
|
||||
const newDate = this.getDateUtils().fromHtml5Input(newValue, time);
|
||||
newValue = this.getDateUtils().formatForAPI(newDate, false);
|
||||
} else if (targetField.type === 'text' && targetField.name.includes('date')) {
|
||||
const timeId = targetField.id.replace('_date', '_time');
|
||||
const timeElement = document.getElementById(timeId);
|
||||
// using 12:00 as fallback, because timezone handling might change the date if we use 00:00
|
||||
let time = '12:00:00';
|
||||
let timeFormat = 'HH:mm';
|
||||
if (timeElement !== null) {
|
||||
time = timeElement.value;
|
||||
timeFormat = timeElement.dataset['format'];
|
||||
}
|
||||
const newDate = this.getDateUtils().fromFormat(newValue.trim() + ' ' + time.trim(), targetField.dataset['format'] + ' ' + timeFormat);
|
||||
newValue = this.getDateUtils().formatForAPI(newDate, false);
|
||||
} else if (targetField.dataset['format'] !== undefined) {
|
||||
// find out when this else branch is triggered and document!
|
||||
|
||||
if (this.getDateUtils().isValidDateTime(newValue, targetField.dataset['format'])) {
|
||||
newValue = this.getDateUtils().format(targetField.dataset['format'], newValue);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// happens for example:
|
||||
// - when the end date is not set on a timesheet record and the project list is loaded (as the URL contains the %end% replacer)
|
||||
// console.log('Empty value found for field with name "' + test[1] + '" by selector: #' + formPrefix + test[1]);
|
||||
}
|
||||
} else {
|
||||
// happens for example:
|
||||
// - when a customer without projects is selected
|
||||
// console.log('ERROR: Empty field with name "' + test[1] + '" by selector: #' + formPrefix + test[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (Array.isArray(newValue)) {
|
||||
let urlParams = [];
|
||||
for (let tmpValue of newValue) {
|
||||
if (tmpValue === null) {
|
||||
tmpValue = '';
|
||||
}
|
||||
urlParams.push(originalFieldName + '=' + tmpValue);
|
||||
}
|
||||
newApiUrl = newApiUrl.replace(item, urlParams.join('&'));
|
||||
} else {
|
||||
if (newValue === null) {
|
||||
newValue = '';
|
||||
}
|
||||
newApiUrl = newApiUrl.replace(value, newValue);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return newApiUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string|Element} select
|
||||
* @param {object} data
|
||||
* @private
|
||||
*/
|
||||
_updateSelect(select, data)
|
||||
{
|
||||
const options = {};
|
||||
for (const apiData of data) {
|
||||
let title = '__empty__';
|
||||
if (apiData['parentTitle'] !== undefined && apiData['parentTitle'] !== null) {
|
||||
title = apiData['parentTitle'];
|
||||
}
|
||||
if (options[title] === undefined) {
|
||||
options[title] = [];
|
||||
}
|
||||
options[title].push(apiData);
|
||||
}
|
||||
|
||||
const ordered = {};
|
||||
Object.keys(options).sort().forEach(function(key) {
|
||||
ordered[key] = options[key];
|
||||
});
|
||||
|
||||
this._updateOptions(select, ordered);
|
||||
}
|
||||
}
|
||||
80
assets/js/forms/KimaiFormTomselectPlugin.js
Normal file
80
assets/js/forms/KimaiFormTomselectPlugin.js
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiFormTomselectPlugin: base form plugin for everyone using tomselect
|
||||
*/
|
||||
|
||||
import KimaiFormPlugin from './KimaiFormPlugin';
|
||||
|
||||
export default class KimaiFormTomselectPlugin extends KimaiFormPlugin {
|
||||
|
||||
/**
|
||||
* @param {string} rendererType
|
||||
* @return array
|
||||
*/
|
||||
getRenderer(rendererType)
|
||||
{
|
||||
// default renderer
|
||||
|
||||
let render = {
|
||||
option_create: (data, escape) => {
|
||||
const name = escape(data.input);
|
||||
if (name.length < 3) {
|
||||
return null;
|
||||
}
|
||||
const tpl = this.translate('select.search.create');
|
||||
const tplReplaced = tpl.replace('%input%', '<strong>' + name + '</strong>');
|
||||
return '<div class="create">' + tplReplaced + '</div>';
|
||||
},
|
||||
no_results: (data, escape) => {
|
||||
const tpl = this.translate('select.search.notfound');
|
||||
const tplReplaced = tpl.replace('%input%', '<strong>' + escape(data.input) + '</strong>');
|
||||
return '<div class="no-results">' + tplReplaced + '</div>';
|
||||
},
|
||||
};
|
||||
|
||||
if (rendererType === 'color') {
|
||||
render = {...render, ...{
|
||||
option: function(data, escape) {
|
||||
let item = '<div class="list-group-item border-0 p-1 ps-2 text-nowrap">';
|
||||
// if no color is set, do NOT add an empty placeholder
|
||||
if (data.color !== undefined) {
|
||||
item += '<span style="background-color:' + data.color + '" class="color-choice-item me-2"> </span>';
|
||||
}
|
||||
item += escape(data.text) + '</div>';
|
||||
return item;
|
||||
},
|
||||
item: function(data, escape) {
|
||||
let item = '<div class="text-nowrap">';
|
||||
// if no color is set, do NOT add an empty placeholder
|
||||
if (data.color !== undefined) {
|
||||
item += '<span style="background-color:' + data.color + '" class="color-choice-item me-2"> </span>';
|
||||
}
|
||||
item += escape(data.text) + '</div>';
|
||||
return item;
|
||||
}
|
||||
}};
|
||||
} else {
|
||||
render = {...render, ...{
|
||||
// the empty entry would collapse and only show as a tiny 5px line if there is no content inside
|
||||
option: function(data, escape) {
|
||||
let text = data.text;
|
||||
if (text === null || text.trim() === '') {
|
||||
text = ' ';
|
||||
} else {
|
||||
text = escape(text);
|
||||
}
|
||||
return '<div>' + text + '</div>';
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
return render;
|
||||
}
|
||||
|
||||
}
|
||||
147
assets/js/forms/KimaiTeamForm.js
Normal file
147
assets/js/forms/KimaiTeamForm.js
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiEditTimesheetForm: responsible for the most important form in the application
|
||||
*/
|
||||
|
||||
import KimaiFormPlugin from "./KimaiFormPlugin";
|
||||
import KimaiColor from "../widgets/KimaiColor";
|
||||
|
||||
export default class KimaiTeamForm extends KimaiFormPlugin {
|
||||
|
||||
init()
|
||||
{
|
||||
this.usersId = 'team_edit_form_users';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
* @return boolean
|
||||
*/
|
||||
supportsForm(form)
|
||||
{
|
||||
return form.name === 'team_edit_form';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {HTMLElement}
|
||||
* @private
|
||||
*/
|
||||
_getPrototype()
|
||||
{
|
||||
return document.getElementById('team_edit_form_members');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
*/
|
||||
activateForm(form)
|
||||
{
|
||||
if (!this.supportsForm(form)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// must be attached to the form, because the button is added dynamically
|
||||
form.addEventListener('click', event => this._removeMember(event));
|
||||
|
||||
document.getElementById(this.usersId).addEventListener('change', event => {
|
||||
const select = event.target;
|
||||
const option = select.options[select.selectedIndex];
|
||||
const member = this._createMember(option);
|
||||
this._getPrototype().append(member);
|
||||
this.getPlugin('form-select').removeOption(select, option);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLOptionElement} option
|
||||
* @returns {Element}
|
||||
* @private
|
||||
*/
|
||||
_createMember(option)
|
||||
{
|
||||
/** @type {KimaiEscape} ESCAPER */
|
||||
const ESCAPER = this.getPlugin('escape');
|
||||
const prototype = this._getPrototype();
|
||||
let counter = prototype.dataset['widgetCounter'] || prototype.childNodes.length;
|
||||
let newWidget = prototype.dataset['prototype'];
|
||||
|
||||
newWidget = newWidget.replace(/__name__/g, counter);
|
||||
|
||||
newWidget = newWidget.replace(/#000000/g, KimaiColor.calculateContrastColor(option.dataset.color));
|
||||
newWidget = newWidget.replace(/__DISPLAY__/g, ESCAPER.escapeForHtml(option.dataset.display));
|
||||
newWidget = newWidget.replace(/__COLOR__/g, option.dataset.color);
|
||||
newWidget = newWidget.replace(/__INITIALS__/g, ESCAPER.escapeForHtml(option.dataset.initials));
|
||||
newWidget = newWidget.replace(/__TITLE__/g, ESCAPER.escapeForHtml(option.dataset.title));
|
||||
newWidget = newWidget.replace(/__USERNAME__/g, ESCAPER.escapeForHtml(option.text));
|
||||
|
||||
prototype.dataset['widgetCounter'] = (++counter).toString();
|
||||
|
||||
const temp = document.createElement('div');
|
||||
temp.innerHTML = ESCAPER.sanitize(newWidget);
|
||||
temp.querySelector('input[type=hidden]').value = option.value;
|
||||
|
||||
const newNode = temp.firstElementChild;
|
||||
|
||||
// copy over all initial settings, so we are able to rebuild the original option if the
|
||||
// member is removed from the list later on
|
||||
for (const key in option.dataset) {
|
||||
newNode.dataset[key] = option.dataset[key];
|
||||
}
|
||||
|
||||
return newNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Event} event
|
||||
* @private
|
||||
*/
|
||||
_removeMember(event)
|
||||
{
|
||||
let button = event.target;
|
||||
|
||||
if (button.parentNode.matches('.remove-member')) {
|
||||
button = button.parentNode;
|
||||
}
|
||||
|
||||
if (button.matches('.remove-member')) {
|
||||
// see blocks.html.twig => block team_member_widget
|
||||
const element = button.parentNode.parentNode.parentNode.parentNode.parentNode;
|
||||
|
||||
// re-adding the option to the select makes up for form validation errors
|
||||
// because the list would have to be re-ordered and indices need to be changed ...
|
||||
/*
|
||||
this.getPlugin('form-select').addOption(
|
||||
document.getElementById(this.usersId),
|
||||
element.dataset['display'],
|
||||
element.dataset['id'],
|
||||
element.dataset
|
||||
);
|
||||
const prototype = this._getPrototype();
|
||||
prototype.dataset['widgetCounter'] = (prototype.dataset['widgetCounter'] - 1).toString();
|
||||
*/
|
||||
|
||||
element.remove();
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
*/
|
||||
destroyForm(form)
|
||||
{
|
||||
if (!this.supportsForm(form)) {
|
||||
return;
|
||||
}
|
||||
|
||||
form.removeEventListener('click', this._removeMember);
|
||||
}
|
||||
|
||||
}
|
||||
698
assets/js/forms/KimaiTimesheetForm.js
Normal file
698
assets/js/forms/KimaiTimesheetForm.js
Normal file
@@ -0,0 +1,698 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiEditTimesheetForm: responsible for the most important form in the application
|
||||
*/
|
||||
|
||||
import { DateTime } from 'luxon';
|
||||
import KimaiFormPlugin from "./KimaiFormPlugin";
|
||||
|
||||
export default class KimaiTimesheetForm extends KimaiFormPlugin {
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
* @return boolean
|
||||
*/
|
||||
supportsForm(form)
|
||||
{
|
||||
return (form.name === 'timesheet_edit_form' || form.name ==='timesheet_admin_edit_form' || form.name ==='timesheet_multi_user_edit_form');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
*/
|
||||
destroyForm(form)
|
||||
{
|
||||
if (!this.supportsForm(form)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._beginDate !== undefined) {
|
||||
this._beginDate.removeEventListener('change', this._beginListener);
|
||||
delete this._beginListener;
|
||||
delete this._beginDate;
|
||||
}
|
||||
|
||||
if (this._beginTime !== undefined) {
|
||||
this._beginTime.removeEventListener('change', this._beginListener);
|
||||
delete this._beginListener;
|
||||
this._beginTime.removeEventListener('blur', this._beginBlurListener);
|
||||
delete this._beginBlurListener;
|
||||
delete this._beginTime;
|
||||
}
|
||||
|
||||
if (this._endTime !== undefined) {
|
||||
this._endTime.removeEventListener('change', this._endListener);
|
||||
delete this._endListener;
|
||||
this._endTime.removeEventListener('blur', this._endBlurListener);
|
||||
delete this._endBlurListener;
|
||||
delete this._endTime;
|
||||
}
|
||||
|
||||
if (this._duration !== undefined) {
|
||||
this._duration.removeEventListener('change', this._durationListener);
|
||||
delete this._durationListener;
|
||||
this._duration.removeEventListener('keydown', this._durationKeyListener);
|
||||
delete this._durationKeyListener;
|
||||
this._duration.removeEventListener('blur', this._durationBlurListener);
|
||||
delete this._durationBlurListener;
|
||||
delete this._duration;
|
||||
}
|
||||
|
||||
if (this._durationToggle !== undefined && this._durationToggle !== null) {
|
||||
this._durationToggle.removeEventListener('change', this._durationToggleListener);
|
||||
delete this._durationToggleListener;
|
||||
delete this._durationToggle;
|
||||
}
|
||||
|
||||
if (this._activity !== undefined) {
|
||||
this._activity.removeEventListener('create', this._activityListener);
|
||||
delete this._activityListener;
|
||||
delete this._activity;
|
||||
}
|
||||
|
||||
if (this._project !== undefined) {
|
||||
delete this._project;
|
||||
}
|
||||
}
|
||||
|
||||
activateForm(form)
|
||||
{
|
||||
if (!this.supportsForm(form)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const formPrefix = form.name;
|
||||
|
||||
this._activity = document.getElementById(formPrefix + '_activity');
|
||||
this._project = document.getElementById(formPrefix + '_project');
|
||||
|
||||
/** @param {CustomEvent} event */
|
||||
this._activityListener = (event) => {
|
||||
const project = this._project.value;
|
||||
/** @type {KimaiAPI} API */
|
||||
const API = this.getContainer().getPlugin('api');
|
||||
API.post(this._activity.dataset['create'], {
|
||||
name: event.detail.value,
|
||||
project: (project === '' ? null : project),
|
||||
visible: true,
|
||||
}, () => {
|
||||
this._project.dispatchEvent(new Event('change'));
|
||||
});
|
||||
};
|
||||
this._activity.addEventListener('create', this._activityListener);
|
||||
|
||||
this._beginDate = document.getElementById(formPrefix + '_begin_date');
|
||||
this._beginTime = document.getElementById(formPrefix + '_begin_time');
|
||||
this._endTime = document.getElementById(formPrefix + '_end_time');
|
||||
this._duration = document.getElementById(formPrefix + '_duration');
|
||||
this._durationToggle = document.getElementById(formPrefix + '_duration_toggle');
|
||||
|
||||
if (this._beginDate === null || this._beginTime === null || this._endTime === null || this._duration === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._beginListener = () => this._changedBegin();
|
||||
this._beginBlurListener = () => this._parseBeginTime();
|
||||
this._endListener = () => this._changedEnd();
|
||||
this._endBlurListener = () => this._parseEndTime();
|
||||
this._durationListener = () => this._changedDuration();
|
||||
this._durationKeyListener = (event) => this._changeDurationOnKeypress(event);
|
||||
this._durationBlurListener = () => this._parseDuration();
|
||||
|
||||
this._beginDate.addEventListener('change', this._beginListener);
|
||||
this._beginTime.addEventListener('change', this._beginListener);
|
||||
this._beginTime.addEventListener('blur', this._beginBlurListener);
|
||||
this._endTime.addEventListener('change', this._endListener);
|
||||
this._endTime.addEventListener('blur', this._endBlurListener);
|
||||
this._duration.addEventListener('change', this._durationListener);
|
||||
this._duration.addEventListener('keydown', this._durationKeyListener);
|
||||
this._duration.addEventListener('blur', this._durationBlurListener);
|
||||
|
||||
if (this._duration !== null && this._durationToggle !== null) {
|
||||
this._durationToggleListener = () => {
|
||||
this._durationToggle.classList.toggle('text-success');
|
||||
};
|
||||
this._durationToggle.addEventListener('click', this._durationToggleListener);
|
||||
}
|
||||
}
|
||||
|
||||
_parseBeginTime()
|
||||
{
|
||||
if (this._beginTime.value === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
let newBeginTime = this._formatTimeForParsing(this._beginTime.value, this._beginTime.dataset['format']);
|
||||
if (newBeginTime !== this._beginTime.value) {
|
||||
this._beginTime.value = newBeginTime;
|
||||
this._changedBegin();
|
||||
}
|
||||
}
|
||||
|
||||
_parseEndTime()
|
||||
{
|
||||
if (this._endTime.value === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
let newEndTime = this._formatTimeForParsing(this._endTime.value, this._endTime.dataset['format']);
|
||||
if (newEndTime !== this._endTime.value) {
|
||||
this._endTime.value = newEndTime;
|
||||
this._changedEnd();
|
||||
}
|
||||
}
|
||||
|
||||
_parseDuration()
|
||||
{
|
||||
if (this._duration.value === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
this._setDurationAsString(this._getParsedDuration());
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives a time, written by a human, probably in an invalid format.
|
||||
* This method supports 12-hour or 24-hour format, the format string contains an uppercase "A" in case of the 12-hour format.
|
||||
* If it is 12-hour format, then always en-US locallized with AM/PM.
|
||||
*
|
||||
* Ruleset:
|
||||
* - Some locales use a dot instead of a colon, always replace the dot in HH.mm with a colon as in HH:mm
|
||||
* - If there is an "am" or "pm", always uppercase them
|
||||
* - Split the string into time and prefix: if AM/PM is included remove it and remember for later
|
||||
* - If the time is a 1 or 2 character long number: use as hours
|
||||
* - If the time now is 3 character long: use the 1 char as hour and the 2 and 3 char as minute
|
||||
* - If the time now is 4 character long: use the 1 and 2 char as hour and the 3 and 4 char as minutes
|
||||
* - If the format is 12-hour: try to identify the correct time and suffix
|
||||
* - If the format is 12-hour and misses the AM/PM: try to detect whether it
|
||||
* - If the time contains AM or PM, make sure that it is always prefixed by a space character
|
||||
*
|
||||
* @param {string} time
|
||||
* @param {string} format
|
||||
* @returns {string}
|
||||
* @private
|
||||
*/
|
||||
_formatTimeForParsing(time, format)
|
||||
{
|
||||
let formatted = time.trim();
|
||||
|
||||
// replace invalid separators with colon
|
||||
formatted = formatted.replace(/\.|;|,/g, ':');
|
||||
// uppercase 12-hour format
|
||||
formatted = formatted.replace(/am/i, 'AM');
|
||||
formatted = formatted.replace(/pm/i, 'PM');
|
||||
|
||||
// Split time and AM/PM suffix if present
|
||||
let suffix = '';
|
||||
let hour = 0;
|
||||
let minute = 0;
|
||||
|
||||
let timePart = formatted;
|
||||
const ampmMatch = formatted.match(/\s*(AM|PM)$/i);
|
||||
if (ampmMatch) {
|
||||
suffix = ampmMatch[1].toUpperCase();
|
||||
timePart = formatted.replace(/\s*(AM|PM)$/i, '').trim();
|
||||
}
|
||||
|
||||
if (timePart.indexOf(':') !== -1) {
|
||||
const match = timePart.match(/(?:(\d+):)?(\d+)/);
|
||||
hour = parseInt(match?.[1] || 0, 10);
|
||||
minute = parseInt(match?.[2] || 0, 10);
|
||||
} else {
|
||||
timePart = timePart.replace(/:/, '');
|
||||
|
||||
if (/^\d{1,2}$/.test(timePart)) {
|
||||
hour = timePart;
|
||||
}
|
||||
|
||||
if (/^\d{3}$/.test(timePart)) {
|
||||
hour = timePart.slice(0, 1);
|
||||
minute = timePart.slice(1);
|
||||
}
|
||||
|
||||
if (/^\d{4}$/.test(timePart)) {
|
||||
hour = timePart.slice(0, 2);
|
||||
minute = timePart.slice(2);
|
||||
}
|
||||
}
|
||||
|
||||
hour = parseInt(hour);
|
||||
minute = parseInt(minute);
|
||||
|
||||
// just in case a person entered a wrong time like 35 hours
|
||||
hour = hour % 24;
|
||||
minute = minute % 60;
|
||||
|
||||
// format is 12-hour
|
||||
if (format.toUpperCase().indexOf('A') !== -1) {
|
||||
// time entered in 24-hour: convert to 12-hour format
|
||||
if (hour > 12 && hour < 24) {
|
||||
hour = hour - 12;
|
||||
suffix = 'PM';
|
||||
}
|
||||
|
||||
// if the person forgot to add a suffix, calculate it and convert time
|
||||
if (suffix === '') {
|
||||
if (hour === 0) {
|
||||
hour = 12;
|
||||
suffix = 'AM';
|
||||
} else if (hour === 12) {
|
||||
suffix = 'PM';
|
||||
} else {
|
||||
suffix = 'AM';
|
||||
}
|
||||
}
|
||||
|
||||
if (suffix === 'PM' && hour === 0) {
|
||||
hour = 12;
|
||||
}
|
||||
|
||||
} else {
|
||||
// this is the 34-hour format branch
|
||||
|
||||
// check if the person entered time in 12-hour format and convert it
|
||||
if (suffix === 'AM' && hour === 12) {
|
||||
hour = 0;
|
||||
} else if (suffix === 'PM' && hour !== 12) {
|
||||
hour = (hour + 12) % 24;
|
||||
}
|
||||
|
||||
// make sure we have no suffix
|
||||
suffix = '';
|
||||
}
|
||||
|
||||
formatted = hour + ':' + minute.toString().padStart(2, '0');
|
||||
if (suffix !== '') {
|
||||
formatted = formatted + ' ' + suffix.trim();
|
||||
}
|
||||
|
||||
return formatted;
|
||||
}
|
||||
|
||||
_isDurationConnected()
|
||||
{
|
||||
if (this._duration === null && this._durationToggle === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this._durationToggle === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return this._durationToggle.classList.contains('text-success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {DateTime|null}
|
||||
* @private
|
||||
*/
|
||||
_getBegin()
|
||||
{
|
||||
if (this._beginDate.value === '' || this._beginTime.value === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
let date = this._parseBegin(this._beginTime.dataset['format']);
|
||||
|
||||
if (date.invalid) {
|
||||
date = this._parseBegin(this._fixTimeFormat(this._beginTime.dataset['format']));
|
||||
|
||||
if (date.invalid) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
_parseBegin(timeFormat)
|
||||
{
|
||||
return this.getDateUtils().fromFormat(
|
||||
this._beginDate.value + ' ' + this._beginTime.value,
|
||||
this._beginDate.dataset['format'] + ' ' + timeFormat,
|
||||
);
|
||||
}
|
||||
|
||||
_parseEnd(endDate, timeFormat)
|
||||
{
|
||||
let date = this.getDateUtils().fromFormat(
|
||||
endDate.toFormat('yyyy-LL-dd') + ' ' + this._endTime.value,
|
||||
'yyyy-LL-dd ' + timeFormat,
|
||||
);
|
||||
|
||||
if (date.invalid) {
|
||||
date = this.getDateUtils().fromFormat(
|
||||
endDate.toFormat('yyyy-LL-dd') + ' ' + this._endTime.value,
|
||||
'yyyy-LL-dd ' + this._fixTimeFormat(timeFormat),
|
||||
);
|
||||
}
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
_fixTimeFormat(format)
|
||||
{
|
||||
return format.replace('HH', 'H').replace('hh', 'h');
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {DateTime|null}
|
||||
* @private
|
||||
*/
|
||||
_getEnd()
|
||||
{
|
||||
if (this._endTime.value === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
let date = this._parseEnd(DateTime.now(), this._endTime.dataset['format']);
|
||||
|
||||
const begin = this._getBegin();
|
||||
if (begin !== null) {
|
||||
date = this._parseEnd(begin, this._endTime.dataset['format']);
|
||||
|
||||
if (date < begin) {
|
||||
date = date.plus({days: 1});
|
||||
}
|
||||
}
|
||||
|
||||
if (date.invalid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ruleset:
|
||||
* - invalid begin => skip
|
||||
* - empty end => set end to begin (only if duration > 0 = running record)
|
||||
* - invalid end => skip
|
||||
* - calculate duration
|
||||
*/
|
||||
_changedBegin()
|
||||
{
|
||||
const begin = this._getBegin();
|
||||
if (begin === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const duration = this._getParsedDuration();
|
||||
const hasDuration = duration.as('seconds') > 0;
|
||||
const end = this._getEnd();
|
||||
|
||||
if (end === null && hasDuration) {
|
||||
this._applyDateToField(begin.plus(duration), null, this._endTime);
|
||||
} else {
|
||||
this._updateDuration();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ruleset:
|
||||
* - invalid end => skip
|
||||
* - empty begin => set begin to end
|
||||
* - invalid begin => skip
|
||||
* - calculate duration
|
||||
*/
|
||||
_changedEnd()
|
||||
{
|
||||
const end = this._getEnd();
|
||||
// empty or invalid date => reset duration and stop progress
|
||||
if (end === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const duration = this._getParsedDuration();
|
||||
const hasDuration = duration.as('seconds') > 0;
|
||||
const begin = this._getBegin();
|
||||
|
||||
if (begin === null && hasDuration) {
|
||||
this._applyDateToField(end.minus(duration), this._beginDate, this._beginTime);
|
||||
} else {
|
||||
this._updateDuration();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_updateDuration()
|
||||
{
|
||||
const begin = this._getBegin();
|
||||
const end = this._getEnd();
|
||||
let newDuration = null;
|
||||
|
||||
if (begin !== null && end !== null) {
|
||||
newDuration = end.diff(begin);
|
||||
}
|
||||
|
||||
this._setDurationAsString(newDuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ruleset:
|
||||
* - invalid or empty duration => skip
|
||||
* - if begin and end are empty: set begin to now and end to duration
|
||||
* - if begin is empty and end is not empty: set begin to end minus duration
|
||||
* - if begin is not empty and end is empty and duration is > 0 (running records = 0): set end to begin plus duration
|
||||
*/
|
||||
_changedDuration()
|
||||
{
|
||||
if (!this._isDurationConnected() || this._duration.value === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
const duration = this._getParsedDuration();
|
||||
if (!duration.isValid) {
|
||||
this._setDurationAsString(null);
|
||||
return;
|
||||
}
|
||||
|
||||
const begin = this._getBegin();
|
||||
let end = this._getEnd();
|
||||
const seconds = duration.as('seconds');
|
||||
|
||||
if (seconds < 0) {
|
||||
end = null;
|
||||
}
|
||||
|
||||
if (begin === null && end === null) {
|
||||
const newBegin = DateTime.now();
|
||||
this._applyDateToField(newBegin, this._beginDate, this._beginTime);
|
||||
this._addSecondsToEndDate(newBegin, seconds);
|
||||
} else if (begin === null && end !== null) {
|
||||
this._applyDateToField(end.minus({seconds: seconds}), this._beginDate, this._beginTime);
|
||||
} else if (begin !== null && seconds >= 0) {
|
||||
this._addSecondsToEndDate(begin, seconds);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the value of a duration object as human-readable string into the duration field
|
||||
*
|
||||
* @param {Duration|null} duration
|
||||
*/
|
||||
_setDurationAsString(duration)
|
||||
{
|
||||
if (!this._isDurationConnected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (duration === null) {
|
||||
this._duration.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!duration.isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
const seconds = duration.as('seconds');
|
||||
if (seconds < 0) {
|
||||
this._duration.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
let minutes = Math.floor((seconds - (hours * 3600)) / 60);
|
||||
|
||||
if (minutes < 10) {
|
||||
minutes = '0' + minutes;
|
||||
}
|
||||
|
||||
this._duration.value = hours + ':' + minutes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a duration object from the duration input field.
|
||||
*
|
||||
* @private
|
||||
* @return {Duration}
|
||||
*/
|
||||
_getParsedDuration()
|
||||
{
|
||||
return this.getDateUtils().parseDuration(this._duration.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {DateTime} dateTime
|
||||
* @param {int} seconds
|
||||
* @private
|
||||
*/
|
||||
_addSecondsToEndDate(dateTime, seconds)
|
||||
{
|
||||
// if the duration is longer than one day, the end field should be empty
|
||||
// so kimai can calculate it after submitting the data from start + duration
|
||||
if (seconds < 86400) {
|
||||
this._applyDateToField(dateTime.plus({seconds: seconds}), null, this._endTime);
|
||||
} else {
|
||||
this._endTime.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {DateTime|null} dateTime
|
||||
* @param {HTMLElement|null} dateField
|
||||
* @param {HTMLElement} timeField
|
||||
* @private
|
||||
*/
|
||||
_applyDateToField(dateTime, dateField, timeField)
|
||||
{
|
||||
if (dateTime === null || dateTime.invalid) {
|
||||
dateField.value = '';
|
||||
timeField.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
if (dateField !== null) {
|
||||
dateField.value = this.getDateUtils().format(dateField.dataset['format'], dateTime);
|
||||
}
|
||||
timeField.value = this.getDateUtils().format(timeField.dataset['format'], dateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {KeyboardEvent} event
|
||||
* @private
|
||||
*/
|
||||
_changeDurationOnKeypress(event)
|
||||
{
|
||||
switch (event.key) {
|
||||
case 'ArrowUp':
|
||||
case 'ArrowDown':
|
||||
case 'PageUp':
|
||||
case 'PageDown':
|
||||
case 'Home':
|
||||
case 'End':
|
||||
this._setDurationAsString(this._getParsedDuration());
|
||||
break;
|
||||
default:
|
||||
return; // Ignore other keys
|
||||
}
|
||||
|
||||
this._changeTimeOnKeypress(event, this._duration, 99999, this._durationListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method helps the user to change a duration field with simple keyboard interaction:
|
||||
* - Read the current duration from the given timeField input in format HH:MM (no seconds)
|
||||
* - Change the duration based on the rules below
|
||||
* - Write the new duration back to the field
|
||||
* - If the field is empty or invalid it uses 00:00 as start-time
|
||||
* - Duration cannot exceed maxtime (which is given in minutes)
|
||||
* - Duration cannot drop below 00:00
|
||||
* - Read the position of the cursor and decide whether to increase minutes or hours: if the cursor is in the hour section (before the colon) change hours, if the cursor is in the minute section (after the colon) change minutes
|
||||
* - It reads the pressed key from the given KeyboardEvent and changes the duration accordingly to the rules below
|
||||
*
|
||||
* Rules to apply when a key is pressed:
|
||||
* - ArrowUp key to increase the duration (either 5 minutes or 1 hour, depending on the cursor position)
|
||||
* - ArrowDown key to decrease the duration (either 5 minutes or 1 hour, depending on the cursor position)
|
||||
* - PageUp key to increase the duration by 1 hour
|
||||
* - PageDown key to decrease the duration by 1 hour
|
||||
* - Home key to set the duration to 08:00
|
||||
* - End key to set the duration to 00:00
|
||||
* - all other keys are ignored
|
||||
*
|
||||
* @param {KeyboardEvent} event
|
||||
* @param {HTMLElement} timeField
|
||||
* @param {int} maxTime
|
||||
* @param {function} changeCallback
|
||||
* @private
|
||||
*/
|
||||
_changeTimeOnKeypress(event, timeField, maxTime, changeCallback)
|
||||
{
|
||||
// Parse current value or default to 00:00
|
||||
let value = timeField.value || '00:00';
|
||||
let [hours, minutes] = value.split(':').map(Number);
|
||||
if (isNaN(hours)) { hours = 0; }
|
||||
if (isNaN(minutes)) { minutes = 0; }
|
||||
|
||||
// Cursor position: before or after colon
|
||||
const cursorPos = timeField.selectionStart || 0;
|
||||
const colonPos = value.indexOf(':');
|
||||
const inHour = cursorPos <= colonPos;
|
||||
|
||||
// Helper to clamp values
|
||||
const clamp = (h, m) => {
|
||||
let total = h * 60 + m;
|
||||
if (total < 0) { total = 0; }
|
||||
if (total > maxTime) { total = maxTime; }
|
||||
h = Math.floor(total / 60);
|
||||
m = total % 60;
|
||||
return [h, m];
|
||||
};
|
||||
|
||||
switch (event.key) {
|
||||
case 'ArrowUp':
|
||||
if (inHour) {
|
||||
[hours, minutes] = clamp(hours + 1, minutes);
|
||||
} else {
|
||||
[hours, minutes] = clamp(hours, minutes + 5);
|
||||
}
|
||||
break;
|
||||
case 'ArrowDown':
|
||||
if (inHour) {
|
||||
[hours, minutes] = clamp(hours - 1, minutes);
|
||||
} else {
|
||||
[hours, minutes] = clamp(hours, minutes - 5);
|
||||
}
|
||||
break;
|
||||
case 'PageUp':
|
||||
[hours, minutes] = clamp(hours + 1, minutes);
|
||||
event.preventDefault();
|
||||
break;
|
||||
case 'PageDown':
|
||||
[hours, minutes] = clamp(hours - 1, minutes);
|
||||
event.preventDefault();
|
||||
break;
|
||||
case 'Home':
|
||||
// TODO this should use the configured working time for today
|
||||
hours = 8;
|
||||
minutes = 0;
|
||||
event.preventDefault();
|
||||
break;
|
||||
case 'End':
|
||||
hours = 0;
|
||||
minutes = 0;
|
||||
event.preventDefault();
|
||||
break;
|
||||
default:
|
||||
return; // Ignore other keys
|
||||
}
|
||||
|
||||
// Format and set value
|
||||
timeField.value = `${hours}:${minutes.toString().padStart(2, '0')}`;
|
||||
// trigger update of linked fields
|
||||
changeCallback(timeField);
|
||||
// Move cursor to original position if possible
|
||||
setTimeout(() => {
|
||||
timeField.setSelectionRange(cursorPos, cursorPos);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@
|
||||
* [KIMAI] KimaiAPI: easy access to API methods
|
||||
*/
|
||||
|
||||
import jQuery from 'jquery';
|
||||
import KimaiPlugin from "../KimaiPlugin";
|
||||
|
||||
export default class KimaiAPI extends KimaiPlugin {
|
||||
@@ -18,135 +17,161 @@ export default class KimaiAPI extends KimaiPlugin {
|
||||
return 'api';
|
||||
}
|
||||
|
||||
_headers() {
|
||||
const headers = new Headers();
|
||||
headers.append('Content-Type', 'application/json');
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
get(url, data, callbackSuccess, callbackError) {
|
||||
jQuery.ajax({
|
||||
url: url,
|
||||
headers: {
|
||||
'X-AUTH-SESSION': true,
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
if (data !== undefined) {
|
||||
const params = (new URLSearchParams(data)).toString();
|
||||
if (params !== '') {
|
||||
url = url + (url.includes('?') ? '&' : '?') + params;
|
||||
}
|
||||
}
|
||||
|
||||
if (callbackError === undefined) {
|
||||
callbackError = (error) => {
|
||||
this.handleError('An error occurred', error);
|
||||
};
|
||||
}
|
||||
|
||||
this.fetch(url, {
|
||||
method: 'GET',
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
success: callbackSuccess,
|
||||
error: callbackError
|
||||
headers: this._headers()
|
||||
}).then((response) => {
|
||||
response.json().then((json) => {
|
||||
callbackSuccess(json);
|
||||
});
|
||||
}).catch((error) => {
|
||||
callbackError(error);
|
||||
});
|
||||
}
|
||||
|
||||
post(url, data, callbackSuccess, callbackError) {
|
||||
if (callbackError === null || callbackError === undefined) {
|
||||
callbackError = this.getPostErrorHandler();
|
||||
if (callbackError === undefined) {
|
||||
callbackError = (error) => {
|
||||
this.handleError('action.update.error', error);
|
||||
};
|
||||
}
|
||||
|
||||
jQuery.ajax({
|
||||
url: url,
|
||||
headers: {
|
||||
'X-AUTH-SESSION': true,
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
this.fetch(url, {
|
||||
method: 'POST',
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
success: callbackSuccess,
|
||||
error: callbackError
|
||||
body: this._parseData(data),
|
||||
headers: this._headers()
|
||||
}).then((response) => {
|
||||
response.json().then((json) => {
|
||||
callbackSuccess(json);
|
||||
});
|
||||
}).catch((error) => {
|
||||
callbackError(error);
|
||||
});
|
||||
}
|
||||
|
||||
patch(url, data, callbackSuccess, callbackError) {
|
||||
if (callbackError === null || callbackError === undefined) {
|
||||
callbackError = this.getPatchErrorHandler();
|
||||
if (callbackError === undefined) {
|
||||
callbackError = (error) => {
|
||||
this.handleError('action.update.error', error);
|
||||
};
|
||||
}
|
||||
|
||||
jQuery.ajax({
|
||||
url: url,
|
||||
headers: {
|
||||
'X-AUTH-SESSION': true,
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
this.fetch(url, {
|
||||
method: 'PATCH',
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
success: callbackSuccess,
|
||||
error: callbackError
|
||||
body: this._parseData(data),
|
||||
headers: this._headers()
|
||||
}).then((response) => {
|
||||
if (response.statusCode === 204) {
|
||||
callbackSuccess();
|
||||
} else {
|
||||
response.json().then((json) => {
|
||||
callbackSuccess(json);
|
||||
});
|
||||
}
|
||||
}).catch((error) => {
|
||||
callbackError(error);
|
||||
});
|
||||
}
|
||||
|
||||
delete(url, callbackSuccess, callbackError) {
|
||||
if (callbackError === null || callbackError === undefined) {
|
||||
callbackError = this.getDeleteErrorHandler();
|
||||
if (callbackError === undefined) {
|
||||
callbackError = (error) => {
|
||||
this.handleError('action.delete.error', error);
|
||||
};
|
||||
}
|
||||
|
||||
jQuery.ajax({
|
||||
url: url,
|
||||
headers: {
|
||||
'X-AUTH-SESSION': true,
|
||||
'Content-Type':'application/json'
|
||||
},
|
||||
this.fetch(url, {
|
||||
method: 'DELETE',
|
||||
dataType: 'json',
|
||||
success: callbackSuccess,
|
||||
error: callbackError
|
||||
headers: this._headers()
|
||||
}).then(() => {
|
||||
callbackSuccess();
|
||||
}).catch((error) => {
|
||||
callbackError(error);
|
||||
});
|
||||
}
|
||||
|
||||
getDeleteErrorHandler() {
|
||||
const self = this;
|
||||
return function(xhr, err) {
|
||||
self.handleError('action.delete.error', xhr, err);
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @param {string|object} data
|
||||
* @returns {string}
|
||||
* @private
|
||||
*/
|
||||
_parseData(data) {
|
||||
if (typeof data === 'object') {
|
||||
return JSON.stringify(data);
|
||||
}
|
||||
|
||||
getPatchErrorHandler() {
|
||||
const self = this;
|
||||
return function(xhr, err) {
|
||||
self.handleError('action.update.error', xhr, err);
|
||||
};
|
||||
}
|
||||
|
||||
getPostErrorHandler() {
|
||||
const self = this;
|
||||
return function(xhr, err) {
|
||||
self.handleError('action.update.error', xhr, err);
|
||||
};
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} message
|
||||
* @param {jqXHR} xhr
|
||||
* @param {string} err
|
||||
* @param {Response} response
|
||||
*/
|
||||
handleError(message, xhr, err) {
|
||||
let resultError = err;
|
||||
if (xhr.responseJSON && xhr.responseJSON.message) {
|
||||
resultError = xhr.responseJSON.message;
|
||||
// find validation errors
|
||||
if (xhr.status === 400 && xhr.responseJSON.errors) {
|
||||
let collected = ['<u>' + resultError + '</u>'];
|
||||
// form errors that are not attached to a field (like extra fields)
|
||||
if (xhr.responseJSON.errors.errors) {
|
||||
for (let error of xhr.responseJSON.errors.errors) {
|
||||
collected.push(error);
|
||||
handleError(message, response) {
|
||||
if (response.headers === undefined) {
|
||||
// this can happen if someone clicks to fast and auto running
|
||||
// requests (e.g. active records) are aborted
|
||||
return;
|
||||
}
|
||||
|
||||
const contentType = response.headers.get("content-type");
|
||||
if (contentType && contentType.indexOf("application/json") !== -1) {
|
||||
response.json().then(data => {
|
||||
let resultError = data.message;
|
||||
// find validation errors
|
||||
if (response.status === 400 && data.errors) {
|
||||
let collected = ['<u>' + resultError + '</u>'];
|
||||
// form errors that are not attached to a field (like extra fields)
|
||||
if (data.errors.errors) {
|
||||
for (let error of data.errors.errors) {
|
||||
collected.push(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (xhr.responseJSON.errors.children) {
|
||||
for (let field in xhr.responseJSON.errors.children) {
|
||||
let tmpField = xhr.responseJSON.errors.children[field];
|
||||
if (tmpField.hasOwnProperty('errors') && tmpField.errors.length > 0) {
|
||||
for (let error of tmpField.errors) {
|
||||
collected.push(error);
|
||||
if (data.errors.children) {
|
||||
for (let field in data.errors.children) {
|
||||
let tmpField = data.errors.children[field];
|
||||
if (tmpField.errors !== undefined && tmpField.errors.length > 0) {
|
||||
for (let error of tmpField.errors) {
|
||||
collected.push(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (collected.length > 0) {
|
||||
resultError = collected;
|
||||
}
|
||||
}
|
||||
if (collected.length > 0) {
|
||||
resultError = collected;
|
||||
}
|
||||
}
|
||||
} else if (xhr.status && xhr.statusText) {
|
||||
resultError = '[' + xhr.status + '] ' + xhr.statusText;
|
||||
}
|
||||
|
||||
this.getPlugin('alert').error(message, resultError);
|
||||
this.getPlugin('alert').error(message, resultError);
|
||||
|
||||
});
|
||||
} else {
|
||||
response.text().then(() => {
|
||||
const resultError = '[' + response.statusCode + '] ' + response.statusText;
|
||||
this.getPlugin('alert').error(message, resultError);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,15 +22,14 @@ export default class KimaiAPILink extends KimaiPlugin {
|
||||
|
||||
constructor(selector) {
|
||||
super();
|
||||
this.selector = selector;
|
||||
this._selector = selector;
|
||||
}
|
||||
|
||||
init() {
|
||||
const self = this;
|
||||
document.addEventListener('click', function(event) {
|
||||
document.addEventListener('click', (event) => {
|
||||
let target = event.target;
|
||||
while (target !== null && !target.matches('body')) {
|
||||
if (target.classList.contains(self.selector)) {
|
||||
while (target !== null && typeof target.matches === "function" && !target.matches('body')) {
|
||||
if (target.classList.contains(this._selector)) {
|
||||
const attributes = target.dataset;
|
||||
|
||||
let url = attributes['href'];
|
||||
@@ -39,13 +38,13 @@ export default class KimaiAPILink extends KimaiPlugin {
|
||||
}
|
||||
|
||||
if (attributes.question !== undefined) {
|
||||
self.getContainer().getPlugin('alert').question(attributes.question, function(value) {
|
||||
this.getContainer().getPlugin('alert').question(attributes.question, (value) => {
|
||||
if (value) {
|
||||
self._callApi(url, attributes);
|
||||
this._callApi(url, attributes);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
self._callApi(url, attributes);
|
||||
this._callApi(url, attributes);
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
@@ -57,41 +56,50 @@ export default class KimaiAPILink extends KimaiPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @param {DOMStringMap} attributes
|
||||
* @private
|
||||
*/
|
||||
_callApi(url, attributes)
|
||||
{
|
||||
const method = attributes['method'];
|
||||
const eventName = attributes['event'];
|
||||
/** @type {KimaiAPI} API */
|
||||
const API = this.getContainer().getPlugin('api');
|
||||
const eventing = this.getContainer().getPlugin('event');
|
||||
const alert = this.getContainer().getPlugin('alert');
|
||||
const successHandle = function(result) {
|
||||
eventing.trigger(eventName);
|
||||
if (attributes.msgSuccess) {
|
||||
alert.success(attributes.msgSuccess);
|
||||
}
|
||||
/** @type {KimaiEvent} EVENTS */
|
||||
const EVENTS = this.getContainer().getPlugin('event');
|
||||
/** @type {KimaiAlert} ALERT */
|
||||
const ALERT = this.getContainer().getPlugin('alert');
|
||||
const successHandle = () => {
|
||||
EVENTS.trigger(eventName);
|
||||
document.dispatchEvent(new CustomEvent('kimai.reloadedContent'));
|
||||
};
|
||||
const errorHandle = function(xhr, err) {
|
||||
const errorHandle = (error) => {
|
||||
let message = 'action.update.error';
|
||||
if (attributes.msgError) {
|
||||
message = attributes.msgError;
|
||||
if (attributes['msgError'] !== undefined) {
|
||||
message = attributes['msgError'];
|
||||
}
|
||||
API.handleError(message, xhr, err);
|
||||
document.dispatchEvent(new CustomEvent('kimai.reloadedContent'));
|
||||
API.handleError(message, error);
|
||||
};
|
||||
|
||||
let data = {};
|
||||
if (attributes['payload'] !== undefined) {
|
||||
data = attributes['payload'];
|
||||
}
|
||||
|
||||
document.dispatchEvent(new CustomEvent('kimai.reloadContent'));
|
||||
|
||||
if (method === 'PATCH') {
|
||||
let data = {};
|
||||
if (attributes.payload) {
|
||||
data = attributes.payload;
|
||||
}
|
||||
API.patch(url, data, successHandle, errorHandle);
|
||||
} else if (method === 'POST') {
|
||||
let data = {};
|
||||
if (attributes.payload) {
|
||||
data = attributes.payload;
|
||||
}
|
||||
API.post(url, data, successHandle, errorHandle);
|
||||
} else if (method === 'DELETE') {
|
||||
API.delete(url, successHandle, errorHandle);
|
||||
} else if (method === 'GET') {
|
||||
API.get(url, data, successHandle, errorHandle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,113 +13,221 @@ import KimaiPlugin from '../KimaiPlugin';
|
||||
|
||||
export default class KimaiActiveRecords extends KimaiPlugin {
|
||||
|
||||
constructor(selector, selectorEmpty) {
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
this.selector = selector;
|
||||
this.selectorEmpty = selectorEmpty;
|
||||
this._selector = '.ticktac-menu';
|
||||
this._selectorEmpty = '.ticktac-menu-empty';
|
||||
this._favIconUrl = null;
|
||||
}
|
||||
|
||||
getId() {
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
getId()
|
||||
{
|
||||
return 'active-records';
|
||||
}
|
||||
|
||||
init() {
|
||||
this.menu = document.querySelector(this.selector);
|
||||
|
||||
init()
|
||||
{
|
||||
// the menu can be hidden if user has no permissions to see it
|
||||
if (this.menu === null) {
|
||||
if (document.querySelector(this._selector) === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.attributes = this.menu.dataset;
|
||||
const handleUpdate = () => {
|
||||
this.reloadActiveRecords();
|
||||
};
|
||||
|
||||
const self = this;
|
||||
const handle = function() { self.reloadActiveRecords(); };
|
||||
document.addEventListener('kimai.timesheetUpdate', handleUpdate);
|
||||
document.addEventListener('kimai.timesheetDelete', handleUpdate);
|
||||
document.addEventListener('kimai.activityUpdate', handleUpdate);
|
||||
document.addEventListener('kimai.activityDelete', handleUpdate);
|
||||
document.addEventListener('kimai.projectUpdate', handleUpdate);
|
||||
document.addEventListener('kimai.projectDelete', handleUpdate);
|
||||
document.addEventListener('kimai.customerUpdate', handleUpdate);
|
||||
document.addEventListener('kimai.customerDelete', handleUpdate);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// handle duration in the visible UI
|
||||
this._updateBrowserTitle = !!this.getConfiguration('updateBrowserTitle');
|
||||
|
||||
const handle = () => {
|
||||
this._updateDuration();
|
||||
};
|
||||
this._updatesHandler = setInterval(handle, 10000);
|
||||
document.addEventListener('kimai.timesheetUpdate', handle);
|
||||
document.addEventListener('kimai.timesheetDelete', handle);
|
||||
document.addEventListener('kimai.activityUpdate', handle);
|
||||
document.addEventListener('kimai.activityDelete', handle);
|
||||
document.addEventListener('kimai.projectUpdate', handle);
|
||||
document.addEventListener('kimai.projectDelete', handle);
|
||||
document.addEventListener('kimai.customerUpdate', handle);
|
||||
document.addEventListener('kimai.customerDelete', handle);
|
||||
document.addEventListener('kimai.reloadedContent', handle);
|
||||
}
|
||||
|
||||
_toggleMenu(hasEntries) {
|
||||
this.menu.style.display = hasEntries ? 'inline-block' : 'none';
|
||||
if (!hasEntries) {
|
||||
// make sure that template entries in the menu are removed, otherwise they
|
||||
// might still be shown in the browsers title
|
||||
for (let record of this.menu.querySelectorAll('[data-since]')) {
|
||||
record.dataset['since'] = '';
|
||||
}
|
||||
// TODO we could unregister all handler and listener
|
||||
// _unregisterHandler() {
|
||||
// clearInterval(this._updatesHandler);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Updates the duration of all running entries, both in the ticktac menus and in the listing pages.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_updateDuration()
|
||||
{
|
||||
// needs to search in document, to find all running entries, both in "ticktac" and listing pages
|
||||
const activeRecords = document.querySelectorAll('[data-since]:not([data-since=""])');
|
||||
|
||||
if (this._updateBrowserTitle) {
|
||||
this._changeFavicon(activeRecords.length > 0);
|
||||
}
|
||||
|
||||
const menuEmpty = document.querySelector(this.selectorEmpty);
|
||||
if (menuEmpty !== null) {
|
||||
if (activeRecords.length === 0) {
|
||||
if (this._updateBrowserTitle) {
|
||||
if (document.body.dataset['title'] === undefined) {
|
||||
this._updateBrowserTitle = false;
|
||||
} else {
|
||||
document.title = document.body.dataset['title'];
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const DATE = this.getDateUtils();
|
||||
let durations = [];
|
||||
|
||||
for (const record of activeRecords) {
|
||||
const duration = DATE.formatDuration(record.dataset['since']);
|
||||
// only use the ones from the menu for the title
|
||||
if (record.dataset['replacer'] !== undefined && record.dataset['title'] !== null && duration !== '?') {
|
||||
durations.push(duration);
|
||||
}
|
||||
// but update all on the page (running entries in list pages)
|
||||
record.textContent = duration;
|
||||
}
|
||||
|
||||
if (durations.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._updateBrowserTitle) {
|
||||
// only show the first found record, even if we have more
|
||||
document.title = durations.shift();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapts the ticktac menus according to the given entries (amount and duration).
|
||||
* Does not influence listing pages, as those refresh themselves.
|
||||
*
|
||||
* @param {array} entries
|
||||
* @private
|
||||
*/
|
||||
_setEntries(entries)
|
||||
{
|
||||
const hasEntries = entries.length > 0;
|
||||
|
||||
// these contain the "start" button
|
||||
for (let menuEmpty of document.querySelectorAll(this._selectorEmpty)) {
|
||||
menuEmpty.style.display = !hasEntries ? 'inline-block' : 'none';
|
||||
}
|
||||
}
|
||||
|
||||
setEntries(entries) {
|
||||
this._toggleMenu(entries.length > 0);
|
||||
|
||||
const template = this.menu.querySelector('[data-template="active-record"]');
|
||||
|
||||
const label = this.menu.querySelector('a > span.label');
|
||||
if (label !== null) {
|
||||
label.innerText = entries.length === 0 ? '' : entries.length;
|
||||
}
|
||||
|
||||
if (entries.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (template === null) {
|
||||
this._replaceInNode(this.menu, entries[0]);
|
||||
} else {
|
||||
const container = template.parentElement;
|
||||
container.innerHTML = '';
|
||||
|
||||
for (let timesheet of entries) {
|
||||
const newNode = template.cloneNode(true);
|
||||
container.appendChild(this._replaceInNode(newNode, timesheet));
|
||||
// and they contain the "stop" button
|
||||
for (let menu of document.querySelectorAll(this._selector)) {
|
||||
menu.style.display = hasEntries ? 'inline-block' : 'none';
|
||||
if (!hasEntries) {
|
||||
// make sure that template entries in the menu are removed, otherwise they
|
||||
// might still be shown in the browsers title
|
||||
for (let record of menu.querySelectorAll('[data-since]')) {
|
||||
record.dataset['since'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
const stop = menu.querySelector('.ticktac-stop');
|
||||
|
||||
if (!hasEntries) {
|
||||
if (stop) {
|
||||
stop.accesskey = null;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stop) {
|
||||
stop.accesskey = 's';
|
||||
}
|
||||
this._replaceInNode(menu, entries[0]);
|
||||
}
|
||||
|
||||
this.getContainer().getPlugin('timesheet-duration').updateRecords();
|
||||
this._updateDuration();
|
||||
}
|
||||
|
||||
_replaceInNode(node, timesheet) {
|
||||
const date = this.getContainer().getPlugin('date');
|
||||
/**
|
||||
* @param {HTMLElement} node
|
||||
* @param {object} timesheet
|
||||
* @private
|
||||
*/
|
||||
_replaceInNode(node, timesheet)
|
||||
{
|
||||
const date = this.getDateUtils();
|
||||
const allReplacer = node.querySelectorAll('[data-replacer]');
|
||||
for (let node of allReplacer) {
|
||||
const replacerName = node.dataset['replacer'];
|
||||
for (let link of allReplacer) {
|
||||
const replacerName = link.dataset['replacer'];
|
||||
if (replacerName === 'url') {
|
||||
node.href = this.attributes['href'].replace('000', timesheet.id);
|
||||
link.dataset['href'] = node.dataset['href'].replace('000', timesheet.id);
|
||||
} else if (replacerName === 'activity') {
|
||||
node.innerText = timesheet.activity.name;
|
||||
link.innerText = timesheet.activity.name;
|
||||
} else if (replacerName === 'project') {
|
||||
node.innerText = timesheet.project.name;
|
||||
link.innerText = timesheet.project.name;
|
||||
} else if (replacerName === 'customer') {
|
||||
node.innerText = timesheet.project.customer.name;
|
||||
link.innerText = timesheet.project.customer.name;
|
||||
} else if (replacerName === 'duration') {
|
||||
node.dataset['since'] = timesheet.begin;
|
||||
node.innerText = date.formatDuration(timesheet.duration);
|
||||
link.dataset['since'] = timesheet.begin;
|
||||
link.innerText = date.formatDuration(timesheet.duration);
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
reloadActiveRecords() {
|
||||
const self = this;
|
||||
const API= this.getContainer().getPlugin('api');
|
||||
reloadActiveRecords()
|
||||
{
|
||||
/** @type {KimaiAPI} API */
|
||||
const API = this.getContainer().getPlugin('api');
|
||||
|
||||
API.get(this.attributes['api'], {}, function(result) {
|
||||
self.setEntries(result);
|
||||
// TODO using the first found "ticktac" menu is working, but can be done better
|
||||
const apiUrl = document.querySelector(this._selector).dataset['api'];
|
||||
|
||||
API.get(apiUrl, {}, (result) => {
|
||||
this._setEntries(result);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} running
|
||||
* @private
|
||||
*/
|
||||
_changeFavicon(running)
|
||||
{
|
||||
const canvas = document.createElement('canvas');
|
||||
const orig = document.getElementById('favicon');
|
||||
if (this._favIconUrl === null) {
|
||||
this._favIconUrl = orig.href;
|
||||
}
|
||||
const link = orig.cloneNode(true);
|
||||
|
||||
if (canvas.getContext && link) {
|
||||
const ratio = window.devicePixelRatio;
|
||||
const img = document.createElement('img');
|
||||
canvas.height = canvas.width = 16 * ratio;
|
||||
img.onload = function () {
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.drawImage(this, 0, 0, canvas.width, canvas.height);
|
||||
if (running) {
|
||||
const width = 5.5 * ratio;
|
||||
ctx.fillStyle = 'rgb(182,57,57)';
|
||||
ctx.fillRect((canvas.width / 2) - (width / 2), (canvas.height / 2) - (width / 2), width, width);
|
||||
}
|
||||
link.href = canvas.toDataURL('image/png');
|
||||
orig.remove();
|
||||
document.head.appendChild(link);
|
||||
};
|
||||
img.src = this._favIconUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiActiveRecordsDuration: activate the updates for all active timesheet records on this page
|
||||
*/
|
||||
|
||||
import KimaiPlugin from '../KimaiPlugin';
|
||||
|
||||
export default class KimaiActiveRecordsDuration extends KimaiPlugin {
|
||||
|
||||
getId() {
|
||||
return 'timesheet-duration';
|
||||
}
|
||||
|
||||
init() {
|
||||
this.updateBrowserTitle = !!this.getConfiguration('updateBrowserTitle');
|
||||
this.updateRecords();
|
||||
const self = this;
|
||||
const handle = function() { self.updateRecords(); };
|
||||
this._updatesHandler = setInterval(handle, 10000);
|
||||
// this will probably not work as expected, as other event-handler might need longer to update the DOM
|
||||
document.addEventListener('kimai.timesheetUpdate', handle);
|
||||
}
|
||||
|
||||
unregisterUpdates() {
|
||||
clearInterval(this._updatesHandler);
|
||||
}
|
||||
|
||||
updateRecords() {
|
||||
let durations = [];
|
||||
const activeRecords = document.querySelectorAll('[data-since]:not([data-since=""])');
|
||||
|
||||
if (activeRecords.length === 0) {
|
||||
if (this.updateBrowserTitle) {
|
||||
if (document.body.dataset['title'] === undefined) {
|
||||
this.updateBrowserTitle = false;
|
||||
} else {
|
||||
document.title = document.body.dataset['title'];
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const DATE = this.getPlugin('date');
|
||||
|
||||
for (let record of activeRecords) {
|
||||
const since = record.dataset['since'];
|
||||
const duration = DATE.formatDuration(since);
|
||||
// only use the ones from the menu for the title
|
||||
if (record.dataset['replacer'] !== undefined && record.dataset['title'] !== null && duration !== '?') {
|
||||
durations.push(duration);
|
||||
}
|
||||
// but update all on the page (running entries in list pages)
|
||||
record.textContent = duration;
|
||||
}
|
||||
|
||||
if (durations.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.updateBrowserTitle) {
|
||||
return;
|
||||
}
|
||||
|
||||
let title = durations.shift();
|
||||
let prefix = ' | ';
|
||||
|
||||
for (let duration of durations.slice(0, 2)) {
|
||||
title += prefix + duration;
|
||||
}
|
||||
document.title = title;
|
||||
}
|
||||
}
|
||||
@@ -12,70 +12,96 @@
|
||||
* opening a modal with the content from the URL given in the elements 'data-href' or 'href' attribute
|
||||
*/
|
||||
|
||||
import jQuery from 'jquery';
|
||||
import KimaiReducedClickHandler from "./KimaiReducedClickHandler";
|
||||
import { Modal } from 'bootstrap';
|
||||
|
||||
export default class KimaiAjaxModalForm extends KimaiReducedClickHandler {
|
||||
|
||||
constructor(selector) {
|
||||
constructor(selector, stopSelector) {
|
||||
super();
|
||||
this.selector = selector;
|
||||
this._selector = selector;
|
||||
this._stopSelector = stopSelector;
|
||||
}
|
||||
|
||||
getId() {
|
||||
getId()
|
||||
{
|
||||
return 'modal';
|
||||
}
|
||||
|
||||
init() {
|
||||
const self = this;
|
||||
this.isDirty = false;
|
||||
init()
|
||||
{
|
||||
this._isDirty = false;
|
||||
|
||||
this.modal = jQuery('#remote_form_modal');
|
||||
this.modal
|
||||
.on('hide.bs.modal', function (e) {
|
||||
if (self.isDirty) {
|
||||
if (jQuery('#remote_form_modal .modal-body .remote_modal_is_dirty_warning').length === 0) {
|
||||
const msg = self.getContainer().getTranslation().get('modal.dirty');
|
||||
jQuery('#remote_form_modal .modal-body').prepend('<p class="'+(self.modal.hasClass('modal-danger') ? 'well well-sm ' : '') + 'text-danger small remote_modal_is_dirty_warning">' + msg + '</p>');
|
||||
}
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
jQuery(self._getFormIdentifier()).off('change', self._isDirtyHandler);
|
||||
self.isDirty = false;
|
||||
self.getContainer().getPlugin('event').trigger('modal-hide');
|
||||
})
|
||||
.on('hidden.bs.modal', function () {
|
||||
// kill all references, so GC can kick in
|
||||
self.getContainer().getPlugin('form').destroyForm(self._getFormIdentifier());
|
||||
jQuery('#remote_form_modal .modal-body').replaceWith('');
|
||||
})
|
||||
.on('show.bs.modal', function () {
|
||||
self.getContainer().getPlugin('event').trigger('modal-show');
|
||||
});
|
||||
|
||||
this._addClickHandler(this.selector, function(href) {
|
||||
self.openUrlInModal(href);
|
||||
});
|
||||
}
|
||||
|
||||
openUrlInModal(url, errorHandler) {
|
||||
const self = this;
|
||||
|
||||
if (errorHandler === undefined) {
|
||||
errorHandler = function(xhr, err) {
|
||||
if (xhr.status === undefined || xhr.status !== 403) {
|
||||
window.location = url;
|
||||
}
|
||||
};
|
||||
const modalElement = this._getModalElement();
|
||||
if (modalElement === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
jQuery.ajax({
|
||||
url: url,
|
||||
success: function(html) {
|
||||
self._openFormInModal(html);
|
||||
},
|
||||
error: errorHandler
|
||||
modalElement.addEventListener('hide.bs.modal', (event) => {
|
||||
if (this._isDirty) {
|
||||
if (modalElement.querySelector('.modal-body .remote_modal_is_dirty_warning') === null) {
|
||||
const msg = this.translate('modal.dirty');
|
||||
const temp = document.createElement('div');
|
||||
temp.innerHTML = '<p class="text-danger small remote_modal_is_dirty_warning">' + msg + '</p>';
|
||||
modalElement.querySelector('.modal-body').prepend(temp.firstElementChild);
|
||||
}
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
this._isDirty = false;
|
||||
document.dispatchEvent(new Event('modal-hide'));
|
||||
});
|
||||
|
||||
modalElement.addEventListener('hidden.bs.modal', () => {
|
||||
// kill all references, so GC can kick in
|
||||
this.getContainer().getPlugin('form').destroyForm(this._getFormIdentifier());
|
||||
modalElement.querySelector('.modal-body').replaceWith('');
|
||||
});
|
||||
|
||||
modalElement.addEventListener('show.bs.modal', () => {
|
||||
document.dispatchEvent(new Event('modal-show'));
|
||||
});
|
||||
|
||||
this.addClickHandler(this._selector, (href) => {
|
||||
this.openUrlInModal(href);
|
||||
}, this._stopSelector);
|
||||
}
|
||||
|
||||
_getModal()
|
||||
{
|
||||
return Modal.getOrCreateInstance(this._getModalElement());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @param {function(Response)} error the callback to execute if the fetch failed
|
||||
*/
|
||||
openUrlInModal(url, error)
|
||||
{
|
||||
const headers = new Headers();
|
||||
headers.append('X-Requested-With', 'Kimai-Modal');
|
||||
|
||||
this.fetch(url, {
|
||||
method: 'GET',
|
||||
redirect: 'follow',
|
||||
headers: headers
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
window.location = url;
|
||||
return;
|
||||
}
|
||||
|
||||
return response.text().then(html => {
|
||||
this._openFormInModal(html);
|
||||
});
|
||||
})
|
||||
.catch((reason) => {
|
||||
if (error === undefined || error === null) {
|
||||
window.location = url;
|
||||
} else {
|
||||
error(reason);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -85,157 +111,178 @@ export default class KimaiAjaxModalForm extends KimaiReducedClickHandler {
|
||||
* @returns {string}
|
||||
* @private
|
||||
*/
|
||||
_getFormIdentifier() {
|
||||
_getFormIdentifier()
|
||||
{
|
||||
return '#remote_form_modal .modal-content form';
|
||||
}
|
||||
|
||||
_openFormInModal(html) {
|
||||
const self = this;
|
||||
/**
|
||||
* @returns {HTMLElement|null}
|
||||
* @private
|
||||
*/
|
||||
_getModalElement()
|
||||
{
|
||||
return document.getElementById('remote_form_modal');
|
||||
}
|
||||
|
||||
let formIdentifier = this._getFormIdentifier();
|
||||
// if any of these is found in a response, the form will be re-displayed
|
||||
let flashErrorIdentifier = 'div.alert-error';
|
||||
// messages to show above the form
|
||||
let flashMessageIdentifier = 'div.alert';
|
||||
let form = jQuery(formIdentifier);
|
||||
let remoteModal = this.modal;
|
||||
/**
|
||||
* @param {Element|ChildNode} node
|
||||
* @returns {Element}
|
||||
* @private
|
||||
*/
|
||||
_makeScriptExecutable(node) {
|
||||
if (node.tagName !== undefined && node.tagName === 'SCRIPT') {
|
||||
const script = document.createElement('script');
|
||||
script.text = node.innerHTML;
|
||||
node.parentNode.replaceChild(script, node);
|
||||
} else {
|
||||
for (const child of node.childNodes) {
|
||||
this._makeScriptExecutable(child);
|
||||
}
|
||||
}
|
||||
|
||||
// will be (re-)activated later
|
||||
form.off('submit');
|
||||
return node;
|
||||
}
|
||||
|
||||
_openFormInModal(html)
|
||||
{
|
||||
const formIdentifier = this._getFormIdentifier();
|
||||
let remoteModal = this._getModalElement();
|
||||
const newFormHtml = document.createElement('div');
|
||||
newFormHtml.innerHTML = html;
|
||||
const newModalContent = this._makeScriptExecutable(newFormHtml.querySelector('#form_modal .modal-content'));
|
||||
|
||||
// load new form from given content
|
||||
if (jQuery(html).find('#form_modal .modal-content').length > 0) {
|
||||
// Support changing modal importance/types
|
||||
remoteModal.on('hidden.bs.modal', function () {
|
||||
if (remoteModal.hasClass('modal-danger')) {
|
||||
remoteModal.removeClass('modal-danger');
|
||||
}
|
||||
});
|
||||
|
||||
if (jQuery(html).find('#form_modal').hasClass('modal-danger')) {
|
||||
remoteModal.addClass('modal-danger');
|
||||
}
|
||||
|
||||
if (newModalContent !== null) {
|
||||
// Support changing modal sizes
|
||||
let modalDialog = remoteModal.find('.modal-dialog');
|
||||
let largeModal = jQuery(html).find('.modal-dialog').hasClass('modal-lg');
|
||||
if (largeModal && !modalDialog.hasClass('modal-lg')) {
|
||||
modalDialog.addClass('modal-lg');
|
||||
}
|
||||
if (!largeModal && modalDialog.hasClass('modal-lg')) {
|
||||
modalDialog.removeClass('modal-lg');
|
||||
let modalDialog = remoteModal.querySelector('.modal-dialog');
|
||||
let largeModal = newFormHtml.querySelector('.modal-dialog').classList.contains('modal-lg');
|
||||
|
||||
if (largeModal && !modalDialog.classList.contains('modal-lg')) {
|
||||
modalDialog.classList.toggle('modal-lg');
|
||||
}
|
||||
|
||||
jQuery('#remote_form_modal .modal-content').replaceWith(
|
||||
jQuery(html).find('#form_modal .modal-content')
|
||||
);
|
||||
if (!largeModal && modalDialog.classList.contains('modal-lg')) {
|
||||
modalDialog.classList.toggle('modal-lg');
|
||||
}
|
||||
|
||||
jQuery('#remote_form_modal [data-dismiss=modal]').on('click', function() {
|
||||
self.isDirty = false;
|
||||
remoteModal.querySelector('.modal-content').replaceWith(newModalContent);
|
||||
[].slice.call(remoteModal.querySelectorAll('[data-bs-dismiss="modal"]')).map((element) => {
|
||||
element.addEventListener('click', () => {
|
||||
this._isDirty = false;
|
||||
this._getModal().hide();
|
||||
});
|
||||
});
|
||||
|
||||
// activate new loaded widgets
|
||||
self.getContainer().getPlugin('form').activateForm(formIdentifier);
|
||||
this.getContainer().getPlugin('form').activateForm(formIdentifier);
|
||||
}
|
||||
|
||||
// show error flash messages
|
||||
let flashMessages = jQuery(html).find(flashMessageIdentifier);
|
||||
if (flashMessages.length > 0) {
|
||||
jQuery('#remote_form_modal .modal-body').prepend(flashMessages);
|
||||
let flashMessages = newFormHtml.querySelector('div.alert');
|
||||
if (flashMessages !== null) {
|
||||
remoteModal.querySelector('.modal-body').prepend(flashMessages);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// a fix for firefox focus problems with datepicker in modal
|
||||
// see https://github.com/kevinpapst/kimai2/issues/618
|
||||
let enforceModalFocusFn = jQuery.fn.modal.Constructor.prototype.enforceFocus;
|
||||
jQuery.fn.modal.Constructor.prototype.enforceFocus = function() {};
|
||||
remoteModal.on('hidden.bs.modal', function () {
|
||||
jQuery.fn.modal.Constructor.prototype.enforceFocus = enforceModalFocusFn;
|
||||
});
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
remoteModal.modal('show');
|
||||
|
||||
// the new form that was loaded via ajax
|
||||
form = jQuery(formIdentifier);
|
||||
const form = document.querySelector(formIdentifier);
|
||||
|
||||
this._isDirtyHandler = function(e) {
|
||||
self.isDirty = true;
|
||||
}
|
||||
form.on('change', this._isDirtyHandler);
|
||||
form.addEventListener('change', () => {
|
||||
this._isDirty = true;
|
||||
});
|
||||
|
||||
// click handler for modal save button, to send forms via ajax
|
||||
form.on('submit', function(event) {
|
||||
// if the form has a target, we let the normal HTML flow happen
|
||||
if (form.attr('target') !== undefined) {
|
||||
return true;
|
||||
}
|
||||
form.addEventListener('submit', this._getEventHandler());
|
||||
|
||||
// otherwise we do some AJAX magic to process the form in the background
|
||||
const btn = jQuery(formIdentifier + ' button[type=submit]').button('loading');
|
||||
const eventName = form.attr('data-form-event');
|
||||
const events = self.getContainer().getPlugin('event');
|
||||
const alert = self.getContainer().getPlugin('alert');
|
||||
this._getModal().show();
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
_getEventHandler()
|
||||
{
|
||||
if (this.eventHandler === undefined) {
|
||||
this.eventHandler = (event) => {
|
||||
const form = event.target;
|
||||
|
||||
jQuery.ajax({
|
||||
url: form.attr('action'),
|
||||
type: form.attr('method'),
|
||||
data: form.serialize(),
|
||||
success: function(html) {
|
||||
btn.button('reset');
|
||||
let hasFieldError = jQuery(html).find('#form_modal .modal-content .has-error').length > 0;
|
||||
let hasFormError = jQuery(html).find('#form_modal .modal-content ul.list-unstyled li.text-danger').length > 0;
|
||||
let hasFlashError = jQuery(html).find(flashErrorIdentifier).length > 0;
|
||||
|
||||
if (hasFieldError || hasFormError || hasFlashError) {
|
||||
self._openFormInModal(html);
|
||||
} else {
|
||||
events.trigger(eventName);
|
||||
|
||||
// try to find form defined messages first ...
|
||||
let msg = form.attr('data-msg-success');
|
||||
if (msg === null || msg === undefined) {
|
||||
// ... but if none was available, check the response to find server rendered flash-message
|
||||
let flashMessage = jQuery(html).find('section.content div.row div.alert.alert-success');
|
||||
if (flashMessage.length > 0) {
|
||||
let flashContent = flashMessage.contents();
|
||||
if (flashContent.length === 3) {
|
||||
msg = flashContent[2].textContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ... and if even that is not available, we use a generic fallback message
|
||||
if (msg === null || msg === undefined) {
|
||||
msg = 'action.update.success';
|
||||
}
|
||||
self.isDirty = false;
|
||||
remoteModal.modal('hide');
|
||||
alert.success(msg);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
error: function(xhr, err) {
|
||||
let message = form.attr('data-msg-error');
|
||||
if (message === null || message === undefined) {
|
||||
message = 'action.update.error';
|
||||
}
|
||||
if (xhr.responseJSON && xhr.responseJSON.message) {
|
||||
err = xhr.responseJSON.message;
|
||||
} else if (xhr.status && xhr.statusText) {
|
||||
err = '[' + xhr.status +'] ' + xhr.statusText;
|
||||
}
|
||||
alert.error(message, err);
|
||||
// this is useful for changing form fields and retrying to save (and in development to test form changes)
|
||||
setTimeout(function() {
|
||||
btn.button('reset');
|
||||
}, 1500);
|
||||
// if the form has a target, we let the normal HTML flow happen
|
||||
if (form.target !== undefined && form.target !== '') {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// otherwise we do some AJAX magic to process the form in the background
|
||||
/** @type {HTMLButtonElement} btn */
|
||||
const btn = document.querySelector(this._getFormIdentifier() + ' button[type=submit]');
|
||||
btn.textContent = btn.textContent + ' …';
|
||||
btn.disabled = true;
|
||||
|
||||
const eventName = form.dataset['formEvent'];
|
||||
/** @type {KimaiEvent} alert */
|
||||
const events = this.getContainer().getPlugin('event');
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
const headers = new Headers();
|
||||
headers.append('X-Requested-With', 'Kimai-Modal');
|
||||
const options = {headers: headers};
|
||||
|
||||
this.fetchForm(form, options)
|
||||
.then(response => {
|
||||
response.text().then((html) => {
|
||||
/** @type {HTMLDivElement} responseHtml */
|
||||
const responseHtml = document.createElement('div');
|
||||
responseHtml.innerHTML = html;
|
||||
let hasFieldError = false;
|
||||
let hasFormError = false;
|
||||
let hasFlashError = false;
|
||||
|
||||
// button must be re-enabled anyway
|
||||
btn.textContent = btn.textContent.replace(' …', '');
|
||||
btn.disabled = false;
|
||||
|
||||
// if the request was successful, there will be no form
|
||||
/** @type {Element} modalContent */
|
||||
const modalContent = responseHtml.querySelector('#form_modal .modal-content');
|
||||
if (modalContent !== null) {
|
||||
hasFieldError = modalContent.querySelector('.is-invalid') !== null;
|
||||
if (!hasFieldError) {
|
||||
// happens when an error occurs for a "hidden or non-classical" form element e.g. creating team without users
|
||||
hasFieldError = modalContent.querySelector('.invalid-feedback') !== null;
|
||||
}
|
||||
hasFormError = modalContent.querySelector('ul.list-unstyled li.text-danger') !== null;
|
||||
hasFlashError = responseHtml.querySelector('div.alert-danger') !== null;
|
||||
}
|
||||
|
||||
if (hasFieldError || hasFormError || hasFlashError) {
|
||||
this._openFormInModal(html);
|
||||
} else {
|
||||
events.trigger(eventName);
|
||||
|
||||
this._isDirty = false;
|
||||
this._getModal().hide();
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
let message = form.dataset['msgError'];
|
||||
if (message === null || message === undefined || message === '') {
|
||||
message = 'action.update.error';
|
||||
}
|
||||
|
||||
/** @type {KimaiAlert} alert */
|
||||
const alert = this.getContainer().getPlugin('alert');
|
||||
alert.error(message, error.message);
|
||||
|
||||
// this is useful for changing form fields and retrying to save (and in development to test form changes)
|
||||
setTimeout(() =>{
|
||||
// critical error, allow to re-submit?
|
||||
btn.textContent = btn.textContent.replace(' …', '');
|
||||
btn.disabled = false;
|
||||
}, 1500);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
return this.eventHandler;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,108 +9,261 @@
|
||||
* [KIMAI] KimaiAlert: notifications for Kimai
|
||||
*/
|
||||
|
||||
import Swal from 'sweetalert2'
|
||||
import KimaiPlugin from "../KimaiPlugin";
|
||||
import {Modal, Toast} from "bootstrap";
|
||||
|
||||
export default class KimaiAlert extends KimaiPlugin {
|
||||
|
||||
/**
|
||||
* @return {string}
|
||||
*/
|
||||
getId() {
|
||||
return 'alert';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} title
|
||||
* @param {string|array} message
|
||||
* @param {string|array|undefined} message
|
||||
*/
|
||||
error(title, message) {
|
||||
const translation = this.getContainer().getTranslation();
|
||||
const translation = this.getTranslation();
|
||||
if (translation.has(title)) {
|
||||
title = translation.get(title);
|
||||
}
|
||||
if (translation.has(message)) {
|
||||
message = translation.get(message);
|
||||
title = title.replace('%reason%', '');
|
||||
|
||||
if (message === undefined) {
|
||||
message = null;
|
||||
}
|
||||
|
||||
if (Array.isArray(message)) {
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: title.replace('%reason%', ''),
|
||||
html: message.join('<br>'),
|
||||
});
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: title.replace('%reason%', ''),
|
||||
text: message,
|
||||
});
|
||||
if (message !== null) {
|
||||
if (translation.has(message)) {
|
||||
message = translation.get(message);
|
||||
}
|
||||
if (Array.isArray(message)) {
|
||||
message = message.join('<br>');
|
||||
}
|
||||
}
|
||||
|
||||
const id = 'alert_global_error';
|
||||
const oldModalElement = document.getElementById(id);
|
||||
if (oldModalElement !== null) {
|
||||
Modal.getOrCreateInstance(oldModalElement).hide();
|
||||
}
|
||||
|
||||
const html = `
|
||||
<div class="modal" id="` + id + `" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog modal-sm modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-status bg-` + this._mapClass('danger') + `"></div>
|
||||
<div class="modal-body text-center py-4">
|
||||
<i class="fas fa-exclamation-circle fa-3x mb-3 text-danger"></i>
|
||||
<h2>` + title + `</h2>
|
||||
` + (message !== null ? '<div class="text-muted">' + message + '</div>' : '') + `
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="w-100">
|
||||
<div class="row">
|
||||
<div class="col text-center"><a href="#" class="btn btn-primary" data-bs-dismiss="modal">` + translation.get('close') + `</a></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
this._showModal(html);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} message
|
||||
*/
|
||||
warning(message) {
|
||||
this._show('warning', message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} message
|
||||
*/
|
||||
success(message) {
|
||||
this._toast('success', message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} message
|
||||
*/
|
||||
info(message) {
|
||||
this._show('info', message);
|
||||
}
|
||||
|
||||
_show(type, message) {
|
||||
const translation = this.getContainer().getTranslation();
|
||||
/**
|
||||
* @param {string} html
|
||||
* @private
|
||||
*/
|
||||
_showModal(html) {
|
||||
const container = document.body;
|
||||
const template = document.createElement('template');
|
||||
template.innerHTML = html.trim();
|
||||
const element = template.content.firstChild;
|
||||
container.appendChild(element);
|
||||
|
||||
if (translation.has(message)) {
|
||||
message = translation.get(message);
|
||||
}
|
||||
|
||||
Swal.fire({
|
||||
icon: type,
|
||||
title: message,
|
||||
});
|
||||
}
|
||||
|
||||
_toast(type, message) {
|
||||
const translation = this.getContainer().getTranslation();
|
||||
|
||||
if (translation.has(message)) {
|
||||
message = translation.get(message);
|
||||
}
|
||||
|
||||
Swal.fire({
|
||||
timer: 2000,
|
||||
timerProgressBar: true,
|
||||
toast: true,
|
||||
position: 'top',
|
||||
showConfirmButton: false,
|
||||
icon: type,
|
||||
title: message,
|
||||
const modal = new Modal(element);
|
||||
element.addEventListener('hidden.bs.modal', function () {
|
||||
container.removeChild(element);
|
||||
});
|
||||
modal.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback receives a value and needs to decide what should happen with it
|
||||
* @param {string} type
|
||||
* @param {string} message
|
||||
* @private
|
||||
*/
|
||||
_show(type, message) {
|
||||
const translation = this.getTranslation();
|
||||
|
||||
if (translation.has(message)) {
|
||||
message = translation.get(message);
|
||||
}
|
||||
|
||||
const html = `
|
||||
<div class="modal fade" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog modal-sm modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-status bg-` + this._mapClass(type) + `"></div>
|
||||
<div class="modal-body text-center py-4">
|
||||
<i class="fas fa-exclamation-circle fa-3x mb-3 text-` + this._mapClass(type) + `"></i>
|
||||
<h2>` + message + `</h2>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="w-100">
|
||||
<div class="row">
|
||||
<div class="col text-center"><a href="#" class="btn btn-primary" data-bs-dismiss="modal">` + translation.get('close') + `</a></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
this._showModal(html);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} type
|
||||
* @return {string}
|
||||
* @private
|
||||
*/
|
||||
_mapClass(type) {
|
||||
if (type === 'info' || type === 'success' || type === 'warning' || type === 'danger') {
|
||||
return type;
|
||||
} else if (type === 'error') {
|
||||
return 'danger';
|
||||
}
|
||||
|
||||
return 'primary';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type
|
||||
* @param message
|
||||
* @private
|
||||
*/
|
||||
_toast(type, message) {
|
||||
const translation = this.getTranslation();
|
||||
|
||||
if (translation.has(message)) {
|
||||
message = translation.get(message);
|
||||
}
|
||||
|
||||
let icon = '<i class="fas fa-info me-2"></i>';
|
||||
|
||||
if (type === 'success') {
|
||||
icon = '<i class="fas fa-check me-2"></i>';
|
||||
} else if (type === 'warning') {
|
||||
icon = '<i class="fas fa-exclamation me-2"></i>';
|
||||
} else if (type === 'danger' || type === 'error') {
|
||||
icon = '<i class="fas fa-exclamation-circle me-2"></i>';
|
||||
}
|
||||
|
||||
const html =
|
||||
`<div class="toast align-items-center text-white bg-` + this._mapClass(type) + ` border-0" data-bs-delay="2000" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="d-flex">
|
||||
<div class="toast-body">
|
||||
` + icon + ' ' + message + `
|
||||
</div>
|
||||
<button type="button" class="btn-close me-2 m-auto" data-bs-dismiss="toast" aria-label="` + translation.get('close') + `"></button>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
const container = document.getElementById('toast-container');
|
||||
const template = document.createElement('template');
|
||||
|
||||
template.innerHTML = html.trim();
|
||||
const element = template.content.firstChild;
|
||||
container.appendChild(element);
|
||||
|
||||
const toast = new Toast(element);
|
||||
element.addEventListener('hidden.bs.toast', function () {
|
||||
container.removeChild(element);
|
||||
});
|
||||
toast.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback receives a bool value (true = confirm, false = cancel / close without action).
|
||||
*
|
||||
* @param message
|
||||
* @param callback
|
||||
*/
|
||||
question(message, callback) {
|
||||
const translation = this.getContainer().getTranslation();
|
||||
const translation = this.getTranslation();
|
||||
|
||||
if (translation.has(message)) {
|
||||
message = translation.get(message);
|
||||
}
|
||||
|
||||
Swal.fire({
|
||||
title: message,
|
||||
icon: 'question',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: translation.get('confirm'),
|
||||
cancelButtonText: translation.get('cancel')
|
||||
}).then((result) => {
|
||||
callback(result.value);
|
||||
});
|
||||
}
|
||||
const css = this._mapClass('info');
|
||||
const html = `
|
||||
<div class="modal fade" tabindex="-1" role="dialog" data-bs-backdrop="static">
|
||||
<div class="modal-dialog modal-sm modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-status bg-` + css + `"></div>
|
||||
<div class="modal-body text-center py-4">
|
||||
<i class="fas fa-question fa-3x mb-3 text-` + css + `"></i>
|
||||
<h2>` + message + `</h2>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="w-100">
|
||||
<div class="row">
|
||||
<div class="col"><a href="#" class="question-confirm btn btn-primary w-100" data-bs-dismiss="modal">` + translation.get('confirm') + `</a></div>
|
||||
<div class="col"><a href="#" class="question-cancel btn w-100" data-bs-dismiss="modal">` + translation.get('cancel') + `</a></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
const container = document.body;
|
||||
const template = document.createElement('template');
|
||||
template.innerHTML = html.trim();
|
||||
const element = template.content.firstChild;
|
||||
container.appendChild(element);
|
||||
element.querySelector('.question-confirm').addEventListener('click', () => {
|
||||
callback(true);
|
||||
});
|
||||
element.querySelector('.question-cancel').addEventListener('click', () => {
|
||||
callback(false);
|
||||
});
|
||||
|
||||
const modal = new Modal(element);
|
||||
element.addEventListener('hidden.bs.modal', () => {
|
||||
container.removeChild(element);
|
||||
});
|
||||
modal.show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,20 +12,19 @@
|
||||
* redirecting to the URL given in the elements 'data-href' or 'href' attribute
|
||||
*/
|
||||
|
||||
import jQuery from 'jquery';
|
||||
import KimaiReducedClickHandler from "./KimaiReducedClickHandler";
|
||||
|
||||
export default class KimaiAlternativeLinks extends KimaiReducedClickHandler {
|
||||
|
||||
constructor(selector) {
|
||||
super();
|
||||
this.selector = selector;
|
||||
this._selector = selector;
|
||||
}
|
||||
|
||||
init() {
|
||||
this._addClickHandler(this.selector, function(href) {
|
||||
this.addClickHandler(this._selector, function(href) {
|
||||
window.location = href;
|
||||
});
|
||||
}, []);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import jQuery from 'jquery';
|
||||
import KimaiPlugin from "../KimaiPlugin";
|
||||
|
||||
/**
|
||||
* Supporting auto-complete fields via API.
|
||||
* Currently used for timesheet tagging in toolbar and edit dialogs.
|
||||
*/
|
||||
export default class KimaiAutocomplete extends KimaiPlugin {
|
||||
|
||||
constructor(selector) {
|
||||
super();
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
init() {
|
||||
this.minChars = this.getConfiguration('autoComplete');
|
||||
}
|
||||
|
||||
getId() {
|
||||
return 'autocomplete';
|
||||
}
|
||||
|
||||
splitTagList(val) {
|
||||
return val.split(/,\s*/);
|
||||
}
|
||||
|
||||
extractLastTag(term) {
|
||||
return this.splitTagList(term).pop();
|
||||
}
|
||||
|
||||
activateAutocomplete(selector) {
|
||||
const self = this;
|
||||
|
||||
jQuery(selector + ' ' + this.selector).each(function(index) {
|
||||
const currentField = jQuery(this);
|
||||
const apiUrl = currentField.attr('data-autocomplete-url');
|
||||
const API = self.getContainer().getPlugin('api');
|
||||
|
||||
currentField
|
||||
// don't navigate away from the field on tab when selecting an item
|
||||
.on("keydown", function (event) {
|
||||
if (event.keyCode === jQuery.ui.keyCode.TAB &&
|
||||
jQuery(this).autocomplete("instance").menu.active) {
|
||||
event.preventDefault();
|
||||
}
|
||||
})
|
||||
.autocomplete({
|
||||
source: function (request, response) {
|
||||
const lastEntry = self.extractLastTag(request.term);
|
||||
API.get(apiUrl, {'name': lastEntry}, function(data){
|
||||
response(data);
|
||||
});
|
||||
},
|
||||
search: function () {
|
||||
// custom minLength
|
||||
var term = self.extractLastTag(this.value);
|
||||
if (term.length < self.minChars) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
focus: function () {
|
||||
// prevent value inserted on focus
|
||||
return false;
|
||||
},
|
||||
select: function (event, ui) {
|
||||
var terms = self.splitTagList(this.value);
|
||||
|
||||
// remove the current input
|
||||
terms.pop();
|
||||
|
||||
// check if selected tag is already in list
|
||||
if (!terms.includes(ui.item.value)) {
|
||||
// add the selected item
|
||||
terms.push(ui.item.value);
|
||||
}
|
||||
// add placeholder to get the comma-and-space at the end
|
||||
terms.push("");
|
||||
|
||||
this.value = terms.join(", ");
|
||||
|
||||
$(this).trigger('change');
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
)
|
||||
;
|
||||
});
|
||||
}
|
||||
|
||||
destroyAutocomplete(selector) {
|
||||
jQuery(selector + ' ' + this.selector).each(function(index) {
|
||||
const currentField = jQuery(this);
|
||||
currentField.autocomplete("destroy");
|
||||
currentField.removeData('autocomplete');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,15 +19,14 @@ export default class KimaiConfirmationLink extends KimaiPlugin {
|
||||
|
||||
constructor(selector) {
|
||||
super();
|
||||
this.selector = selector;
|
||||
this._selector = selector;
|
||||
}
|
||||
|
||||
init() {
|
||||
const self = this;
|
||||
document.addEventListener('click', function(event) {
|
||||
document.addEventListener('click', (event) => {
|
||||
let target = event.target;
|
||||
while (target !== null && !target.matches('body')) {
|
||||
if (target.classList.contains(self.selector)) {
|
||||
while (target !== null && typeof target.matches === "function" && !target.matches('body')) {
|
||||
if (target.classList.contains(this._selector)) {
|
||||
const attributes = target.dataset;
|
||||
|
||||
// is this a link?
|
||||
@@ -44,7 +43,7 @@ export default class KimaiConfirmationLink extends KimaiPlugin {
|
||||
}
|
||||
|
||||
if (attributes.question !== undefined) {
|
||||
self.getContainer().getPlugin('alert').question(attributes.question, function(value) {
|
||||
this.getContainer().getPlugin('alert').question(attributes.question, function(value) {
|
||||
if (value) {
|
||||
if (form === null) {
|
||||
document.location = url;
|
||||
|
||||
@@ -9,15 +9,15 @@
|
||||
* [KIMAI] KimaiDatatable: handles functionality for the datatable
|
||||
*/
|
||||
|
||||
import jQuery from 'jquery';
|
||||
import KimaiPlugin from "../KimaiPlugin";
|
||||
import KimaiContextMenu from "../widgets/KimaiContextMenu";
|
||||
|
||||
export default class KimaiDatatable extends KimaiPlugin {
|
||||
|
||||
constructor(contentAreaSelector, tableSelector) {
|
||||
super();
|
||||
this.contentArea = contentAreaSelector;
|
||||
this.selector = tableSelector;
|
||||
this._contentArea = contentAreaSelector;
|
||||
this._selector = tableSelector;
|
||||
}
|
||||
|
||||
getId() {
|
||||
@@ -25,24 +25,21 @@ export default class KimaiDatatable extends KimaiPlugin {
|
||||
}
|
||||
|
||||
init() {
|
||||
const dataTable = document.querySelector(this.selector);
|
||||
const dataTable = document.querySelector(this._selector);
|
||||
|
||||
// not every page contains a dataTable
|
||||
if (dataTable === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const attributes = dataTable.dataset;
|
||||
const events = attributes['reloadEvent'];
|
||||
|
||||
this.fixDropdowns();
|
||||
this.registerContextMenu(this._selector);
|
||||
|
||||
const events = dataTable.dataset['reloadEvent'];
|
||||
if (events === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
const self = this;
|
||||
const handle = function() { self.reloadDatatable(); };
|
||||
const handle = () => { this.reloadDatatable(); };
|
||||
|
||||
for (let eventName of events.split(' ')) {
|
||||
document.addEventListener(eventName, handle);
|
||||
@@ -52,55 +49,49 @@ export default class KimaiDatatable extends KimaiPlugin {
|
||||
document.addEventListener('filter-change', handle);
|
||||
}
|
||||
|
||||
reloadDatatable() {
|
||||
const self = this;
|
||||
const contentArea = this.contentArea;
|
||||
const durations = this.getContainer().getPlugin('timesheet-duration');
|
||||
const toolbarSelector = this.getContainer().getPlugin('toolbar').getSelector();
|
||||
|
||||
const form = jQuery(toolbarSelector);
|
||||
let loading = '<div class="overlay"><i class="fas fa-sync fa-spin"></i></div>';
|
||||
jQuery(contentArea).append(loading);
|
||||
|
||||
// remove the empty fields to prevent errors
|
||||
let formData = jQuery(toolbarSelector + ' :input')
|
||||
.filter(function(index, element) {
|
||||
return jQuery(element).val() !== '';
|
||||
})
|
||||
.serialize();
|
||||
|
||||
jQuery.ajax({
|
||||
url: form.attr('action'),
|
||||
type: form.attr('method'),
|
||||
data: formData,
|
||||
success: function(html) {
|
||||
jQuery(contentArea).replaceWith(
|
||||
jQuery(html).find(contentArea)
|
||||
);
|
||||
durations.updateRecords();
|
||||
self.fixDropdowns();
|
||||
},
|
||||
error: function(xhr, err) {
|
||||
form.submit();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @param {string} selector
|
||||
* @private
|
||||
*/
|
||||
registerContextMenu(selector)
|
||||
{
|
||||
KimaiContextMenu.createForDataTable(selector);
|
||||
}
|
||||
|
||||
/**
|
||||
* show dropdown menu upwards, if it is outside the visible viewport
|
||||
*/
|
||||
fixDropdowns() {
|
||||
const docHeight = jQuery(document).height();
|
||||
jQuery(this.selector + ' [data-toggle=dropdown]').each(function() {
|
||||
const parent = jQuery(this).parent();
|
||||
const menu = parent.find('.dropdown-menu');
|
||||
reloadDatatable()
|
||||
{
|
||||
const toolbarSelector = this.getContainer().getPlugin('toolbar').getSelector();
|
||||
|
||||
if (parent && menu) {
|
||||
if ((parent.offset().top + parent.outerHeight() + menu.outerHeight()) > docHeight) {
|
||||
parent.addClass('dropup').removeClass('dropdown');
|
||||
}
|
||||
}
|
||||
/** @type {HTMLFormElement} form */
|
||||
const form = document.querySelector(toolbarSelector);
|
||||
const callback = (text) => {
|
||||
const temp = document.createElement('div');
|
||||
temp.innerHTML = text;
|
||||
const newContent = temp.querySelector(this._contentArea);
|
||||
document.querySelector(this._contentArea).replaceWith(newContent);
|
||||
this.registerContextMenu(this._selector);
|
||||
document.dispatchEvent(new Event('kimai.reloadedContent'));
|
||||
};
|
||||
|
||||
document.dispatchEvent(new CustomEvent('kimai.reloadContent', {detail: this._contentArea}));
|
||||
|
||||
if (form === null) {
|
||||
this.fetch(document.location)
|
||||
.then(response => {
|
||||
response.text().then(callback);
|
||||
})
|
||||
.catch(() => {
|
||||
document.location.reload();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.fetchForm(form)
|
||||
.then(response => {
|
||||
response.text().then(callback);
|
||||
})
|
||||
.catch(() => {
|
||||
form.submit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
* [KIMAI] KimaiDatatableColumnView: manages the visibility of data-table columns in cookies
|
||||
*/
|
||||
|
||||
import Cookies from 'js-cookie';
|
||||
import jQuery from 'jquery';
|
||||
import KimaiPlugin from "../KimaiPlugin";
|
||||
|
||||
export default class KimaiDatatableColumnView extends KimaiPlugin {
|
||||
@@ -29,80 +27,110 @@ export default class KimaiDatatableColumnView extends KimaiPlugin {
|
||||
if (dataTable === null) {
|
||||
return;
|
||||
}
|
||||
this.id = dataTable.getAttribute(this.dataAttribute);
|
||||
this.modal = document.getElementById('modal_' + this.id);
|
||||
this.bindButtons();
|
||||
}
|
||||
|
||||
bindButtons() {
|
||||
let self = this;
|
||||
this.modal.querySelector('button[data-type=save]').addEventListener('click', function() {
|
||||
self.saveVisibility();
|
||||
this._id = dataTable.getAttribute(this.dataAttribute);
|
||||
this._modal = document.getElementById('modal_' + this._id);
|
||||
this._modal.addEventListener('show.bs.modal', () => {
|
||||
this._evaluateCheckboxes();
|
||||
});
|
||||
this.modal.querySelector('button[data-type=reset]').addEventListener('click', function() {
|
||||
self.resetVisibility();
|
||||
this._modal.querySelector('button[data-type=save]').addEventListener('click', () => {
|
||||
this._saveVisibility();
|
||||
});
|
||||
for (let checkbox of this.modal.querySelectorAll('form input[type=checkbox]')) {
|
||||
checkbox.addEventListener('click', function () {
|
||||
self.changeVisibility(checkbox.getAttribute('name'), checkbox.checked);
|
||||
this._modal.querySelector('button[data-type=reset]').addEventListener('click', (event) => {
|
||||
this._resetVisibility(event.currentTarget);
|
||||
});
|
||||
this._modal.querySelectorAll('input[name=datatable_profile]').forEach(element => {
|
||||
element.addEventListener('change', () => {
|
||||
const form = this._modal.getElementsByTagName('form')[0];
|
||||
this.fetchForm(form, {}, element.getAttribute('data-href'))
|
||||
.then(() => {
|
||||
// the local storage is read in the login screen to set a cookie,
|
||||
// which triggers the session switch in ProfileSubscriber
|
||||
localStorage.setItem('kimai_profile', element.getAttribute('value'));
|
||||
document.location.reload();
|
||||
})
|
||||
.catch(() => {
|
||||
form.setAttribute('action', element.getAttribute('data-href'));
|
||||
form.submit();
|
||||
});
|
||||
});
|
||||
});
|
||||
for (let checkbox of this._modal.querySelectorAll('form input[type=checkbox]')) {
|
||||
checkbox.addEventListener('change', () => {
|
||||
this._changeVisibility(checkbox.getAttribute('name'), checkbox.checked);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
saveVisibility() {
|
||||
const form = this.modal.getElementsByTagName('form')[0];
|
||||
let settings = {};
|
||||
for (let checkbox of form.querySelectorAll('input[type=checkbox]')) {
|
||||
settings[checkbox.getAttribute('name')] = checkbox.checked;
|
||||
_evaluateCheckboxes() {
|
||||
const form = this._modal.getElementsByTagName('form')[0];
|
||||
const table = document.getElementsByClassName('datatable_' + this._id)[0];
|
||||
for (let columnElement of table.getElementsByTagName('th')) {
|
||||
const fieldName = columnElement.getAttribute('data-field');
|
||||
if (fieldName === null) {
|
||||
continue;
|
||||
}
|
||||
const checkbox = form.querySelector('input[name=' + fieldName + ']');
|
||||
if (checkbox === null) {
|
||||
continue;
|
||||
}
|
||||
checkbox.checked = window.getComputedStyle(columnElement).display !== 'none';
|
||||
}
|
||||
Cookies.set(form.getAttribute('name'), JSON.stringify(settings), {expires: 365, SameSite: 'Strict'});
|
||||
jQuery(this.modal).modal('toggle');
|
||||
}
|
||||
|
||||
resetVisibility() {
|
||||
const form = this.modal.getElementsByTagName('form')[0];
|
||||
Cookies.remove(form.getAttribute('name'));
|
||||
for (let checkbox of form.querySelectorAll('input[type=checkbox]')) {
|
||||
if (!checkbox.checked) {
|
||||
checkbox.click();
|
||||
}
|
||||
}
|
||||
jQuery(this.modal).modal('toggle');
|
||||
_saveVisibility() {
|
||||
const form = this._modal.getElementsByTagName('form')[0];
|
||||
|
||||
this.fetchForm(form)
|
||||
.then(() => {
|
||||
document.location.reload();
|
||||
})
|
||||
.catch(() => {
|
||||
form.submit();
|
||||
});
|
||||
}
|
||||
|
||||
changeVisibility(columnName, checked) {
|
||||
const tables = document.getElementsByClassName('datatable_' + this.id);
|
||||
for (let tableBox of tables) {
|
||||
let column = 0;
|
||||
let foundColumn = false;
|
||||
let table = tableBox.getElementsByClassName('dataTable')[0];
|
||||
for (let columnElement of table.getElementsByTagName('th')) {
|
||||
if (columnElement.getAttribute('data-field') === columnName) {
|
||||
foundColumn = true;
|
||||
break;
|
||||
_resetVisibility(button) {
|
||||
const form = this._modal.getElementsByTagName('form')[0];
|
||||
|
||||
this.fetchForm(form, {}, button.getAttribute('formaction'))
|
||||
.then(() => {
|
||||
document.location.reload();
|
||||
})
|
||||
.catch(() => {
|
||||
form.setAttribute('action', button.getAttribute('formaction'));
|
||||
form.submit();
|
||||
});
|
||||
}
|
||||
|
||||
_changeVisibility(columnName, checked) {
|
||||
for (const tableBox of document.getElementsByClassName('datatable_' + this._id)) {
|
||||
let targetClasses = null;
|
||||
for (let element of tableBox.getElementsByClassName('col_' + columnName)) {
|
||||
// only calculate that once and re-use the cached class list
|
||||
if (targetClasses === null) {
|
||||
let removeClass = '-none';
|
||||
let addClass = 'd-table-cell';
|
||||
|
||||
if (!checked) {
|
||||
removeClass = '-table-cell';
|
||||
addClass = 'd-none';
|
||||
}
|
||||
|
||||
targetClasses = '';
|
||||
element.classList.forEach(
|
||||
function (name, index, listObj) { // eslint-disable-line no-unused-vars
|
||||
if (name.indexOf(removeClass) === -1) {
|
||||
targetClasses += ' ' + name;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (targetClasses.indexOf(addClass) === -1) {
|
||||
targetClasses += ' ' + addClass;
|
||||
}
|
||||
}
|
||||
|
||||
if (columnElement.getAttribute('colspan') !== null) {
|
||||
console.log('Tables with colspans are not supported!');
|
||||
}
|
||||
|
||||
column++;
|
||||
}
|
||||
|
||||
if (!foundColumn) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let rowElement of table.getElementsByTagName('tr')) {
|
||||
if (rowElement.children[column] === undefined) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (checked) {
|
||||
rowElement.children[column].classList.remove('hidden');
|
||||
} else {
|
||||
rowElement.children[column].classList.add('hidden');
|
||||
}
|
||||
element.className = targetClasses;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiDatePicker: single date selects (currently unused)
|
||||
*/
|
||||
|
||||
import jQuery from 'jquery';
|
||||
import KimaiPlugin from '../KimaiPlugin';
|
||||
|
||||
export default class KimaiDatePicker extends KimaiPlugin {
|
||||
|
||||
constructor(selector) {
|
||||
super();
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
getId() {
|
||||
return 'date-picker';
|
||||
}
|
||||
|
||||
activateDatePicker(selector) {
|
||||
const TRANSLATE = this.getContainer().getTranslation();
|
||||
const DATE_UTILS = this.getContainer().getPlugin('date');
|
||||
const firstDow = this.getConfiguration('first_dow_iso') % 7;
|
||||
|
||||
jQuery(selector + ' ' + this.selector).each(function(index) {
|
||||
let localeFormat = jQuery(this).data('format');
|
||||
jQuery(this).daterangepicker({
|
||||
singleDatePicker: true,
|
||||
showDropdowns: true,
|
||||
autoUpdateInput: false,
|
||||
drops: 'down',
|
||||
locale: {
|
||||
format: localeFormat,
|
||||
firstDay: firstDow,
|
||||
applyLabel: TRANSLATE.get('confirm'),
|
||||
cancelLabel: TRANSLATE.get('cancel'),
|
||||
customRangeLabel: TRANSLATE.get('customRange'),
|
||||
daysOfWeek: DATE_UTILS.getWeekDaysShort(),
|
||||
monthNames: DATE_UTILS.getMonthNames(),
|
||||
}
|
||||
});
|
||||
|
||||
jQuery(this).on('show.daterangepicker', function (ev, picker) {
|
||||
if (picker.element.offset().top - jQuery(window).scrollTop() + picker.container.outerHeight() + 30 > jQuery(window).height()) {
|
||||
// "up" is not possible here, because the code is triggered on many mobile phones and the picker then appears out of window
|
||||
picker.drops = 'auto';
|
||||
picker.move();
|
||||
}
|
||||
});
|
||||
|
||||
jQuery(this).on('apply.daterangepicker', function(ev, picker) {
|
||||
jQuery(this).val(picker.startDate.format(localeFormat));
|
||||
jQuery(this).trigger("change");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
destroyDatePicker(selector) {
|
||||
jQuery(selector + ' ' + this.selector).each(function(index) {
|
||||
if (jQuery(this).data('daterangepicker') !== undefined) {
|
||||
jQuery(this).daterangepicker('destroy');
|
||||
jQuery(this).data('daterangepicker').remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiDateRangePicker: activate the (daterange picker) compound field in toolbar
|
||||
*/
|
||||
|
||||
import jQuery from 'jquery';
|
||||
import KimaiPlugin from '../KimaiPlugin';
|
||||
import moment from 'moment';
|
||||
|
||||
export default class KimaiDateRangePicker extends KimaiPlugin {
|
||||
|
||||
constructor(selector) {
|
||||
super();
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
getId() {
|
||||
return 'date-range-picker';
|
||||
}
|
||||
|
||||
activateDateRangePicker(selector) {
|
||||
const TRANSLATE = this.getContainer().getTranslation();
|
||||
const DATE_UTILS = this.getContainer().getPlugin('date');
|
||||
const firstDow = this.getConfiguration('first_dow_iso') % 7;
|
||||
|
||||
jQuery(selector + ' ' + this.selector).each(function(index) {
|
||||
let localeFormat = jQuery(this).data('format');
|
||||
let separator = jQuery(this).data('separator');
|
||||
let rangesList = {};
|
||||
|
||||
rangesList[TRANSLATE.get('today')] = [moment(), moment()];
|
||||
rangesList[TRANSLATE.get('yesterday')] = [moment().subtract(1, 'days'), moment().subtract(1, 'days')];
|
||||
rangesList[TRANSLATE.get('thisWeek')] = [moment().startOf('isoWeek'), moment().endOf('isoWeek')];
|
||||
rangesList[TRANSLATE.get('lastWeek')] = [moment().subtract(1, 'week').startOf('isoWeek'), moment().subtract(1, 'week').endOf('isoWeek')];
|
||||
if (firstDow === 0) { // sunday = 0
|
||||
rangesList[TRANSLATE.get('thisWeek')] = [moment().startOf('isoWeek').subtract(1, 'day'), moment().endOf('isoWeek').subtract(1, 'day')];
|
||||
rangesList[TRANSLATE.get('lastWeek')] = [moment().subtract(1, 'week').startOf('isoWeek').subtract(1, 'day'), moment().subtract(1, 'week').endOf('isoWeek').subtract(1, 'day')];
|
||||
}
|
||||
rangesList[TRANSLATE.get('thisMonth')] = [moment().startOf('month'), moment().endOf('month')];
|
||||
rangesList[TRANSLATE.get('lastMonth')] = [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')];
|
||||
rangesList[TRANSLATE.get('thisYear')] = [moment().startOf('year'), moment().endOf('year')];
|
||||
rangesList[TRANSLATE.get('lastYear')] = [moment().subtract(1, 'year').startOf('year'), moment().subtract(1, 'year').endOf('year')];
|
||||
|
||||
jQuery(this).daterangepicker({
|
||||
showDropdowns: true,
|
||||
autoUpdateInput: false,
|
||||
autoApply: false,
|
||||
linkedCalendars: true,
|
||||
drops: 'down',
|
||||
locale: {
|
||||
separator: separator,
|
||||
format: localeFormat,
|
||||
firstDay: firstDow,
|
||||
applyLabel: TRANSLATE.get('confirm'),
|
||||
cancelLabel: TRANSLATE.get('cancel'),
|
||||
customRangeLabel: TRANSLATE.get('customRange'),
|
||||
daysOfWeek: DATE_UTILS.getWeekDaysShort(),
|
||||
monthNames: DATE_UTILS.getMonthNames(),
|
||||
},
|
||||
ranges: rangesList,
|
||||
alwaysShowCalendars: true
|
||||
});
|
||||
|
||||
jQuery(this).on('show.daterangepicker', function (ev, picker) {
|
||||
if (picker.element.offset().top - jQuery(window).scrollTop() + picker.container.outerHeight() + 30 > jQuery(window).height()) {
|
||||
// "up" is not possible here, because the code is triggered on many mobile phones and the picker then appears out of window
|
||||
picker.drops = 'auto';
|
||||
picker.move();
|
||||
}
|
||||
});
|
||||
|
||||
jQuery(this).on('apply.daterangepicker', function(ev, picker) {
|
||||
jQuery(this).val(picker.startDate.format(localeFormat) + ' - ' + picker.endDate.format(localeFormat));
|
||||
jQuery(this).data('begin', picker.startDate.format(localeFormat));
|
||||
jQuery(this).data('end', picker.endDate.format(localeFormat));
|
||||
jQuery(this).trigger("change");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
destroyDateRangePicker(selector) {
|
||||
jQuery(selector + ' ' + this.selector).each(function(index) {
|
||||
if (jQuery(this).data('daterangepicker') !== undefined) {
|
||||
jQuery(this).daterangepicker('destroy');
|
||||
jQuery(this).data('daterangepicker').remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiDateTimePicker: activate the (datetime picker) field in timesheet edit dialog
|
||||
*/
|
||||
|
||||
import jQuery from 'jquery';
|
||||
import KimaiPlugin from '../KimaiPlugin';
|
||||
|
||||
export default class KimaiDateTimePicker extends KimaiPlugin {
|
||||
|
||||
constructor(selector) {
|
||||
super();
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
getId() {
|
||||
return 'date-time-picker';
|
||||
}
|
||||
|
||||
activateDateTimePicker(selector) {
|
||||
const TRANSLATE = this.getContainer().getTranslation();
|
||||
const DATE_UTILS = this.getContainer().getPlugin('date');
|
||||
const firstDow = this.getConfiguration('first_dow_iso') % 7;
|
||||
const is24hours = this.getConfiguration('twentyFourHours');
|
||||
|
||||
jQuery(selector + ' ' + this.selector).each(function(index) {
|
||||
let localeFormat = jQuery(this).data('format');
|
||||
jQuery(this).daterangepicker({
|
||||
singleDatePicker: true,
|
||||
timePicker: true,
|
||||
timePicker24Hour: is24hours,
|
||||
showDropdowns: true,
|
||||
autoUpdateInput: false,
|
||||
drops: 'down',
|
||||
locale: {
|
||||
format: localeFormat,
|
||||
firstDay: firstDow,
|
||||
applyLabel: TRANSLATE.get('confirm'),
|
||||
cancelLabel: TRANSLATE.get('cancel'),
|
||||
customRangeLabel: TRANSLATE.get('customRange'),
|
||||
daysOfWeek: DATE_UTILS.getWeekDaysShort(),
|
||||
monthNames: DATE_UTILS.getMonthNames(),
|
||||
}
|
||||
});
|
||||
|
||||
jQuery(this).on('show.daterangepicker', function (ev, picker) {
|
||||
if (picker.element.offset().top - jQuery(window).scrollTop() + picker.container.outerHeight() + 30 > jQuery(window).height()) {
|
||||
// "up" is not possible here, because the code is triggered on many mobile phones and the picker then appears out of window
|
||||
picker.drops = 'auto';
|
||||
picker.move();
|
||||
}
|
||||
});
|
||||
|
||||
jQuery(this).on('apply.daterangepicker', function(ev, picker) {
|
||||
jQuery(this).val(picker.startDate.format(localeFormat));
|
||||
jQuery(this).trigger("change");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
destroyDateTimePicker(selector) {
|
||||
jQuery(selector + ' ' + this.selector).each(function(index) {
|
||||
if (jQuery(this).data('daterangepicker') !== undefined) {
|
||||
jQuery(this).daterangepicker('destroy');
|
||||
jQuery(this).data('daterangepicker').remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,67 +10,238 @@
|
||||
*/
|
||||
|
||||
import KimaiPlugin from '../KimaiPlugin';
|
||||
import moment from 'moment';
|
||||
import { DateTime, Duration } from 'luxon';
|
||||
|
||||
export default class KimaiDateUtils extends KimaiPlugin {
|
||||
|
||||
getId() {
|
||||
getId()
|
||||
{
|
||||
return 'date';
|
||||
}
|
||||
|
||||
init()
|
||||
{
|
||||
if (this.getConfigurations().is24Hours()) {
|
||||
this.timeFormat = 'HH:mm';
|
||||
} else {
|
||||
this.timeFormat = 'hh:mm a';
|
||||
}
|
||||
this.durationFormat = this.getConfiguration('formatDuration');
|
||||
this.dateFormat = this.getConfiguration('formatDate');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} dateTime
|
||||
* @see https://moment.github.io/luxon/#/formatting?id=table-of-tokens
|
||||
* @param {string} format
|
||||
* @returns {string}
|
||||
* @private
|
||||
*/
|
||||
_parseFormat(format)
|
||||
{
|
||||
format = format.replace('DD', 'dd');
|
||||
format = format.replace('D', 'd');
|
||||
format = format.replace('MM', 'LL');
|
||||
format = format.replace('M', 'L');
|
||||
format = format.replace('YYYY', 'yyyy');
|
||||
format = format.replace('YY', 'yy');
|
||||
format = format.replace('A', 'a');
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} format
|
||||
* @param {string|Date|null|undefined} dateTime
|
||||
* @returns {string}
|
||||
*/
|
||||
getFormattedDate(dateTime) {
|
||||
return moment(dateTime).format(this.getConfiguration('formatDate'));
|
||||
}
|
||||
format(format, dateTime)
|
||||
{
|
||||
let newDate = null;
|
||||
|
||||
getWeekDaysShort() {
|
||||
return moment.localeData().weekdaysShort();
|
||||
}
|
||||
if (dateTime === null || dateTime === undefined) {
|
||||
newDate = DateTime.now();
|
||||
} else if (dateTime instanceof Date) {
|
||||
newDate = DateTime.fromJSDate(dateTime);
|
||||
} else {
|
||||
newDate = DateTime.fromISO(dateTime);
|
||||
}
|
||||
|
||||
getMonthNames() {
|
||||
return moment.localeData().months();
|
||||
}
|
||||
|
||||
formatDuration(since) {
|
||||
const duration = moment.duration(moment(new Date()).diff(moment(since)));
|
||||
|
||||
return this.formatMomentDuration(duration);
|
||||
}
|
||||
|
||||
formatSeconds(seconds) {
|
||||
const duration = moment.duration('PT' + seconds + 'S');
|
||||
|
||||
return this.formatMomentDuration(duration);
|
||||
// using locale english here prevents that that AM/PM is translated to the
|
||||
// locale variant: e.g. "ko" translates it to 오후 / 오전
|
||||
return newDate.toFormat(this._parseFormat(format), { locale: 'en-us' });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {moment.Duration} duration
|
||||
* @returns {string|*}
|
||||
* @param {string|Date} dateTime
|
||||
* @returns {string}
|
||||
*/
|
||||
formatMomentDuration(duration) {
|
||||
const hours = parseInt(duration.asHours()).toString();
|
||||
const minutes = duration.minutes();
|
||||
const seconds = duration.seconds();
|
||||
|
||||
return this.formatTime(hours, minutes, seconds);
|
||||
getFormattedDate(dateTime)
|
||||
{
|
||||
return this.format(this._parseFormat(this.dateFormat), dateTime);
|
||||
}
|
||||
|
||||
formatTime(hours, minutes, seconds) {
|
||||
if (hours < 0 || minutes < 0 || seconds < 0) {
|
||||
return '?';
|
||||
/**
|
||||
* Returns a "YYYY-MM-DDTHH:mm:ss" formatted string in local time.
|
||||
* This can take Date objects (e.g. from FullCalendar) and turn them into the correct format.
|
||||
*
|
||||
* @param {Date|DateTime} date
|
||||
* @param {boolean|undefined} isUtc
|
||||
* @return {string}
|
||||
*/
|
||||
formatForAPI(date, isUtc = false)
|
||||
{
|
||||
if (date instanceof Date) {
|
||||
date = DateTime.fromJSDate(date);
|
||||
}
|
||||
|
||||
// special case for hours, as they can overflow the 24h barrier - Kimai does not support days as duration unit
|
||||
if (hours.length === 1) {
|
||||
hours = '0' + hours;
|
||||
if (isUtc === undefined || !isUtc) {
|
||||
date = date.toUTC();
|
||||
}
|
||||
|
||||
const format = this.getConfiguration('formatDuration');
|
||||
return date.toISO({ includeOffset: false, suppressMilliseconds: true });
|
||||
}
|
||||
|
||||
return format.replace('%h', hours).replace('%m', ('0' + minutes).substr(-2)).replace('%s', ('0' + seconds).substr(-2));
|
||||
/**
|
||||
* @param {string} date
|
||||
* @param {string} format
|
||||
* @return {DateTime}
|
||||
*/
|
||||
fromFormat(date, format)
|
||||
{
|
||||
// using locale en-us here prevents that Luxon expects the localized
|
||||
// version of AM/PM (e.g. 오후 / 오전 for locale "ko")
|
||||
return DateTime.fromFormat(date, this._parseFormat(format), { locale: 'en-us' });
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string|null} date
|
||||
* @param {string|null} time
|
||||
* @return {DateTime}
|
||||
*/
|
||||
fromHtml5Input(date, time)
|
||||
{
|
||||
date = date ?? '';
|
||||
time = time ?? '';
|
||||
|
||||
if (date === '' && time === '') {
|
||||
return DateTime.invalid('Empty date and time given');
|
||||
}
|
||||
|
||||
if (date !== '' && time !== '') {
|
||||
date = date + 'T' + time;
|
||||
}
|
||||
|
||||
return DateTime.fromISO(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} date
|
||||
* @param {string} format
|
||||
* @return {boolean}
|
||||
*/
|
||||
isValidDateTime(date, format)
|
||||
{
|
||||
return this.fromFormat(date, format).isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a string like "00:30:00" or "01:15" to a given date.
|
||||
*
|
||||
* @param {Date} date
|
||||
* @param {string} duration
|
||||
* @return {Date}
|
||||
*/
|
||||
addHumanDuration(date, duration)
|
||||
{
|
||||
/** @type {DateTime} newDate */
|
||||
let newDate = null;
|
||||
|
||||
if (date instanceof Date) {
|
||||
newDate = DateTime.fromJSDate(date);
|
||||
} else if (date instanceof DateTime) {
|
||||
newDate = date;
|
||||
} else {
|
||||
throw 'addHumanDuration() needs a JS Date';
|
||||
}
|
||||
|
||||
const parsed = DateTime.fromISO(duration);
|
||||
const today = DateTime.now().startOf('day');
|
||||
const timeOfDay = parsed.diff(today);
|
||||
|
||||
return newDate.plus(timeOfDay).toJSDate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string|integer|null} since
|
||||
* @return {string}
|
||||
*/
|
||||
formatDuration(since)
|
||||
{
|
||||
let duration = null;
|
||||
|
||||
if (typeof since === 'string') {
|
||||
duration = DateTime.now().diff(DateTime.fromISO(since));
|
||||
} else {
|
||||
duration = Duration.fromISO('PT' + (since === null ? 0 : since) + 'S');
|
||||
}
|
||||
|
||||
return this.formatLuxonDuration(duration);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {integer} seconds
|
||||
* @return {string}
|
||||
*/
|
||||
formatSeconds(seconds)
|
||||
{
|
||||
return this.formatLuxonDuration(Duration.fromObject({seconds: seconds}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Duration} duration
|
||||
* @returns {string}
|
||||
* @private
|
||||
*/
|
||||
formatLuxonDuration(duration)
|
||||
{
|
||||
duration = duration.shiftTo('hours', 'minutes', 'seconds');
|
||||
|
||||
return this.formatAsDuration(duration.hours, duration.minutes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Date} date
|
||||
* @param {boolean|undefined} isUtc
|
||||
* @return {string}
|
||||
*/
|
||||
formatTime(date, isUtc = false)
|
||||
{
|
||||
let newDate = DateTime.fromJSDate(date);
|
||||
|
||||
if (isUtc === undefined || !isUtc) {
|
||||
newDate = newDate.toUTC();
|
||||
}
|
||||
|
||||
// .utc() is required for calendar
|
||||
return newDate.toFormat(this.timeFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {int} hours
|
||||
* @param {int} minutes
|
||||
* @return {string}
|
||||
*/
|
||||
formatAsDuration(hours, minutes)
|
||||
{
|
||||
let format = this.durationFormat;
|
||||
|
||||
if (hours < 0 || minutes < 0) {
|
||||
hours = Math.abs(hours);
|
||||
minutes = Math.abs(minutes);
|
||||
format = '-' + format;
|
||||
}
|
||||
|
||||
return format.replace('%h', hours.toString()).replace('%m', ('0' + minutes).slice(-2));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,32 +250,60 @@ export default class KimaiDateUtils extends KimaiPlugin {
|
||||
*/
|
||||
getSecondsFromDurationString(duration)
|
||||
{
|
||||
duration = duration.trim().toUpperCase();
|
||||
let momentDuration = moment.duration(NaN);
|
||||
const luxonDuration = this.parseDuration(duration);
|
||||
|
||||
if (duration.indexOf(':') !== -1) {
|
||||
momentDuration = moment.duration(duration);
|
||||
} else if (duration.indexOf('.') !== -1 || duration.indexOf(',') !== -1) {
|
||||
duration = duration.replace(/,/, '.');
|
||||
duration = (parseFloat(duration) * 3600).toString();
|
||||
momentDuration = moment.duration('PT' + duration + 'S');
|
||||
} else if (duration.indexOf('H') !== -1 || duration.indexOf('M') !== -1 || duration.indexOf('S') !== -1) {
|
||||
/* D for days does not work, because 'PT1H' but with days 'P1D' is used */
|
||||
momentDuration = moment.duration('PT' + duration);
|
||||
} else {
|
||||
let c = parseInt(duration);
|
||||
let d = parseInt(duration).toFixed();
|
||||
if (!isNaN(c) && duration === d) {
|
||||
duration = (c * 3600).toString();
|
||||
momentDuration = moment.duration('PT' + duration + 'S');
|
||||
}
|
||||
}
|
||||
|
||||
if (!momentDuration.isValid()) {
|
||||
if (luxonDuration === null || !luxonDuration.isValid) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return momentDuration.asSeconds();
|
||||
return luxonDuration.as('seconds');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} duration
|
||||
* @returns {Duration}
|
||||
*/
|
||||
parseDuration(duration)
|
||||
{
|
||||
if (duration === undefined || duration === null || duration === '') {
|
||||
return new Duration({seconds: 0});
|
||||
}
|
||||
|
||||
duration = duration.trim().toUpperCase();
|
||||
let luxonDuration = null;
|
||||
|
||||
if (duration.indexOf(':') !== -1) {
|
||||
const match = duration.match(/(?:(\d+):)?(\d+)(?::(\d+))?/);
|
||||
const hours = parseInt(match?.[1] || 0, 10);
|
||||
const minutes = parseInt(match?.[2] || 0, 10);
|
||||
const seconds = parseInt(match?.[3] || 0, 10);
|
||||
luxonDuration = Duration.fromObject({hours: hours, minutes: minutes, seconds: seconds});
|
||||
} else if (duration.indexOf('.') !== -1 || duration.indexOf(',') !== -1) {
|
||||
duration = duration.replace(/,/, '.');
|
||||
duration = (parseFloat(duration) * 3600).toString();
|
||||
luxonDuration = Duration.fromISO('PT' + duration + 'S');
|
||||
} else if (duration.indexOf('H') !== -1 || duration.indexOf('M') !== -1 || duration.indexOf('S') !== -1) {
|
||||
/* D for days does not work, because 'PT1H' but with days 'P1D' is used */
|
||||
luxonDuration = Duration.fromISO('PT' + duration);
|
||||
} else {
|
||||
let c = parseInt(duration);
|
||||
const d = parseInt(duration).toFixed();
|
||||
if (!isNaN(c) && duration === d) {
|
||||
duration = (c * 3600).toString();
|
||||
luxonDuration = Duration.fromISO('PT' + duration + 'S');
|
||||
}
|
||||
}
|
||||
|
||||
if (luxonDuration === null || !luxonDuration.isValid) {
|
||||
return new Duration({seconds: 0});
|
||||
}
|
||||
|
||||
// actually, the parsing above should be improved, but that works as well
|
||||
if (duration[0] === '-' && luxonDuration.valueOf() > 0) {
|
||||
return luxonDuration.negate();
|
||||
}
|
||||
|
||||
return luxonDuration;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
import KimaiPlugin from "../KimaiPlugin";
|
||||
import DOMPurify from "dompurify";
|
||||
|
||||
export default class KimaiEscape extends KimaiPlugin {
|
||||
|
||||
@@ -22,14 +23,27 @@ export default class KimaiEscape extends KimaiPlugin {
|
||||
* @returns {string}
|
||||
*/
|
||||
escapeForHtml(title) {
|
||||
const tagsToReplace = {
|
||||
if (title === undefined || title === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const charToReplace = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
};
|
||||
|
||||
return title.replace(/[&<>]/g, function(tag) {
|
||||
return tagsToReplace[tag] || tag;
|
||||
return title.replace(/[&<>"]/g, function(tag) {
|
||||
return charToReplace[tag] || tag;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} html
|
||||
* @returns {string}
|
||||
*/
|
||||
sanitize(html) {
|
||||
return DOMPurify.sanitize(html);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,18 +13,24 @@ import KimaiPlugin from "../KimaiPlugin";
|
||||
|
||||
export default class KimaiEvent extends KimaiPlugin {
|
||||
|
||||
getId() {
|
||||
getId()
|
||||
{
|
||||
return 'event';
|
||||
}
|
||||
|
||||
trigger(name, details) {
|
||||
if (name === null || name === undefined) {
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {string|array|object|null} details
|
||||
*/
|
||||
trigger(name, details = null)
|
||||
{
|
||||
if (name === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
for(let event of name.split(' ')) {
|
||||
for (const event of name.split(' ')) {
|
||||
let triggerEvent = new Event(event);
|
||||
if (details !== undefined) {
|
||||
if (details !== null) {
|
||||
triggerEvent = new CustomEvent(event, {detail: details});
|
||||
}
|
||||
document.dispatchEvent(triggerEvent);
|
||||
|
||||
80
assets/js/plugins/KimaiFetch.js
Normal file
80
assets/js/plugins/KimaiFetch.js
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiEscape: sanitize strings
|
||||
*/
|
||||
|
||||
import KimaiPlugin from "../KimaiPlugin";
|
||||
|
||||
export default class KimaiFetch extends KimaiPlugin {
|
||||
|
||||
getId() {
|
||||
return 'fetch';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} url
|
||||
* @param {object} options
|
||||
* @returns {Promise<Response>}
|
||||
*/
|
||||
fetch(url, options = {}) {
|
||||
if (options.headers === undefined) {
|
||||
options.headers = new Headers();
|
||||
}
|
||||
options.headers.append('X-Requested-With', 'Kimai');
|
||||
|
||||
options = {...{
|
||||
redirect: 'follow',
|
||||
}, ...options};
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(url, options).then(response => {
|
||||
if (response.ok) {
|
||||
if (response.status === 201 && response.headers.has('x-modal-redirect')) {
|
||||
window.location = response.headers.get('x-modal-redirect');
|
||||
return;
|
||||
}
|
||||
|
||||
// "ok" is only in status code range of 2xx
|
||||
resolve(response);
|
||||
return;
|
||||
}
|
||||
|
||||
let stopPropagation = false;
|
||||
switch (response.status) {
|
||||
case 403: {
|
||||
if (response.headers.has('login-required')) {
|
||||
const loginUrl = this.getConfiguration('login').toString();
|
||||
/** @type {KimaiAlert} alert */
|
||||
const alert = this.getContainer().getPlugin('alert');
|
||||
alert.question(this.translate('login.required'), (result) => {
|
||||
if (result === true) {
|
||||
window.location.replace(loginUrl);
|
||||
}
|
||||
});
|
||||
stopPropagation = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
console.log('Some error occurred');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!stopPropagation) {
|
||||
reject(response);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('Error occurred while talking to Kimai backend', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -10,35 +10,44 @@
|
||||
*/
|
||||
|
||||
import KimaiPlugin from "../KimaiPlugin";
|
||||
import KimaiFormPlugin from "../forms/KimaiFormPlugin";
|
||||
|
||||
export default class KimaiForm extends KimaiPlugin {
|
||||
|
||||
getId() {
|
||||
getId()
|
||||
{
|
||||
return 'form';
|
||||
}
|
||||
|
||||
activateForm(formSelector, container) {
|
||||
this.getContainer().getPlugin('date-range-picker').activateDateRangePicker(formSelector);
|
||||
this.getContainer().getPlugin('date-time-picker').activateDateTimePicker(formSelector);
|
||||
this.getContainer().getPlugin('date-picker').activateDatePicker(formSelector);
|
||||
this.getContainer().getPlugin('autocomplete').activateAutocomplete(formSelector);
|
||||
this.getContainer().getPlugin('form-select').activateSelectPicker(formSelector, container);
|
||||
activateForm(formSelector)
|
||||
{
|
||||
[].slice.call(document.querySelectorAll(formSelector)).map((form) => {
|
||||
for (const plugin of this.getContainer().getPlugins()) {
|
||||
if (plugin instanceof KimaiFormPlugin && plugin.supportsForm(form)) {
|
||||
plugin.activateForm(form);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
destroyForm(formSelector) {
|
||||
this.getContainer().getPlugin('form-select').destroySelectPicker(formSelector);
|
||||
this.getContainer().getPlugin('autocomplete').destroyAutocomplete(formSelector);
|
||||
this.getContainer().getPlugin('date-picker').destroyDatePicker(formSelector);
|
||||
this.getContainer().getPlugin('date-time-picker').destroyDateTimePicker(formSelector);
|
||||
this.getContainer().getPlugin('date-range-picker').destroyDateRangePicker(formSelector);
|
||||
|
||||
destroyForm(formSelector)
|
||||
{
|
||||
[].slice.call(document.querySelectorAll(formSelector)).map((form) => {
|
||||
for (const plugin of this.getContainer().getPlugins()) {
|
||||
if (plugin instanceof KimaiFormPlugin && plugin.supportsForm(form)) {
|
||||
plugin.destroyForm(form);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLFormElement} form
|
||||
* @param {Object} overwrites
|
||||
* @param {boolean} removeEmpty
|
||||
* @returns {string}
|
||||
*/
|
||||
convertFormDataToQueryString(form, overwrites = {})
|
||||
convertFormDataToQueryString(form, overwrites = {}, removeEmpty = false)
|
||||
{
|
||||
let serialized = [];
|
||||
let data = new FormData(form);
|
||||
@@ -48,7 +57,9 @@ export default class KimaiForm extends KimaiPlugin {
|
||||
}
|
||||
|
||||
for (let row of data) {
|
||||
serialized.push(encodeURIComponent(row[0]) + "=" + encodeURIComponent(row[1]));
|
||||
if (!removeEmpty || row[1] !== '') {
|
||||
serialized.push(encodeURIComponent(row[0]) + "=" + encodeURIComponent(row[1]));
|
||||
}
|
||||
}
|
||||
|
||||
return serialized.join('&');
|
||||
|
||||
@@ -1,298 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiFormSelect: enhanced functionality for HTML select's
|
||||
*/
|
||||
|
||||
import KimaiPlugin from "../KimaiPlugin";
|
||||
import jQuery from "jquery";
|
||||
|
||||
export default class KimaiFormSelect extends KimaiPlugin {
|
||||
|
||||
constructor(selector) {
|
||||
super();
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
getId() {
|
||||
return 'form-select';
|
||||
}
|
||||
|
||||
init() {
|
||||
// selects the original value inside select2 dropdowns, as the "reset" event (the updated option)
|
||||
// is not automatically catched by select2
|
||||
jQuery('body').on('reset', 'form', function(event) {
|
||||
setTimeout(function() {
|
||||
jQuery(event.target).find(this.selector).trigger('change');
|
||||
}, 10);
|
||||
});
|
||||
|
||||
const self = this;
|
||||
|
||||
// Function to match the name of the parent and not only the names of the children
|
||||
// Based on the original matcher function of Select2: https://github.com/select2/select2/blob/5765090318c4d382ae56463cfa25ba8ca7bdd495/src/js/select2/defaults.js#L272
|
||||
// More information: https://select2.org/searching | https://github.com/select2/docs/blob/develop/pages/11.searching/docs.md
|
||||
this.matcher = function (params, data) {
|
||||
// Always return the object if there is nothing to compare
|
||||
if (jQuery.trim(params.term) === '') {
|
||||
return data;
|
||||
}
|
||||
|
||||
// Check whether options has children
|
||||
let hasChildren = data.children && data.children.length > 0;
|
||||
|
||||
// Split search param by space to search for all terms and convert all to uppercase
|
||||
let terms = params.term.toUpperCase().split(' ');
|
||||
let original = data.text.toUpperCase();
|
||||
|
||||
// Always return the parent option including its children, when the name matches one of the params
|
||||
// Check if the text contains all or at least one of the terms
|
||||
let foundAll = true;
|
||||
let foundOne = false;
|
||||
let missingTerms = [];
|
||||
terms.forEach(function(item, index) {
|
||||
if (original.indexOf(item) > -1) {
|
||||
foundOne = true;
|
||||
} else {
|
||||
foundAll = false;
|
||||
missingTerms.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
// If the option element contains all terms, return it
|
||||
if (foundAll) {
|
||||
return data;
|
||||
}
|
||||
|
||||
// Do a recursive check for options with children
|
||||
if (hasChildren) {
|
||||
// If the parent already contains one or more search terms, proceed only with the missing ones
|
||||
// First: Clone the original params object...
|
||||
let newParams = jQuery.extend(true, {}, params);
|
||||
if (foundOne) {
|
||||
newParams.term = missingTerms.join(' ');
|
||||
} else {
|
||||
newParams.term = params.term;
|
||||
}
|
||||
|
||||
// Clone the data object if there are children
|
||||
// This is required as we modify the object to remove any non-matches
|
||||
let match = jQuery.extend(true, {}, data);
|
||||
|
||||
// Check each child of the option
|
||||
for (let c = data.children.length - 1; c >= 0; c--) {
|
||||
let child = data.children[c];
|
||||
|
||||
let matches = self.matcher(newParams, child);
|
||||
|
||||
// If there wasn't a match, remove the object in the array
|
||||
if (matches === null) {
|
||||
match.children.splice(c, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// If any children matched, return the new object
|
||||
if (match.children.length > 0) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
|
||||
// If the option or its children do not contain the term, don't return anything
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
activateSelectPickerByElement(node, container) {
|
||||
let options = {};
|
||||
if (container !== undefined) {
|
||||
options = {
|
||||
dropdownParent: jQuery(container),
|
||||
};
|
||||
}
|
||||
|
||||
options = {...options, ...{
|
||||
language: this.getConfiguration('locale').replace('_', '-'),
|
||||
theme: "bootstrap",
|
||||
matcher: this.matcher,
|
||||
dropdownAutoWidth: true,
|
||||
width: "resolve"
|
||||
}};
|
||||
|
||||
const element = jQuery(node);
|
||||
|
||||
if (node.dataset['renderer'] !== undefined && node.dataset['renderer'] === 'color') {
|
||||
const templateResultFunc = function (state) {
|
||||
return jQuery('<span><span style="background-color:'+state.id+'; width: 20px; height: 20px; display: inline-block; margin-right: 10px;"> </span>' + state.text + '</span>');
|
||||
};
|
||||
|
||||
const colorOptions = {...options, ...{
|
||||
templateSelection: templateResultFunc,
|
||||
templateResult: templateResultFunc
|
||||
}};
|
||||
|
||||
element.select2(colorOptions);
|
||||
} else {
|
||||
element.select2(options);
|
||||
}
|
||||
|
||||
// this is a bugfix for safari, which does render the dropdown only with correct width upon the second opening
|
||||
// see https://github.com/select2/select2/issues/4678
|
||||
element.on('select2:open', function (ev) {
|
||||
if (element.data('performing-reopen') === undefined || element.data('performing-reopen') === null) {
|
||||
element.data('performing-reopen', true);
|
||||
element.select2('close');
|
||||
element.select2('open');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
activateSelectPicker(selector, container) {
|
||||
const self = this;
|
||||
jQuery(selector + ' ' + this.selector).each(function(i, el) {
|
||||
self.activateSelectPickerByElement(el, container);
|
||||
});
|
||||
}
|
||||
|
||||
destroySelectPicker(selector) {
|
||||
jQuery(selector + ' ' + this.selector).select2('destroy');
|
||||
}
|
||||
|
||||
updateOptions(selectIdentifier, data) {
|
||||
let select = jQuery(selectIdentifier);
|
||||
let emptyOption = jQuery(selectIdentifier + ' option[value=""]');
|
||||
const selectedValue = select.val();
|
||||
|
||||
select.find('option').remove().end().find('optgroup').remove().end();
|
||||
|
||||
if (emptyOption.length !== 0) {
|
||||
select.append(this._createOption(emptyOption.text(), ''));
|
||||
}
|
||||
|
||||
let emptyOpts = [];
|
||||
let options = [];
|
||||
let titlePattern = null;
|
||||
if (select[0] !== undefined && select[0].dataset !== undefined && select[0].dataset['optionPattern'] !== undefined) {
|
||||
titlePattern = select[0].dataset['optionPattern'];
|
||||
}
|
||||
if (titlePattern === null || titlePattern === '') {
|
||||
titlePattern = '{name}';
|
||||
}
|
||||
|
||||
for (const [key, value] of Object.entries(data)) {
|
||||
if (key === '__empty__') {
|
||||
for (const entity of value) {
|
||||
emptyOpts.push(this._createOption(this._getTitleFromPattern(titlePattern, entity), entity.id));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
let optGroup = this._createOptgroup(key);
|
||||
for (const entity of value) {
|
||||
optGroup.appendChild(this._createOption(this._getTitleFromPattern(titlePattern, entity), entity.id));
|
||||
}
|
||||
options.push(optGroup);
|
||||
}
|
||||
|
||||
select.append(options);
|
||||
select.append(emptyOpts);
|
||||
|
||||
// if available, re-select the previous selected option (mostly usable for global activities)
|
||||
select.val(selectedValue);
|
||||
|
||||
// pre-select an option if it is the only available one
|
||||
if (select.val() === '' || select.val() === null) {
|
||||
const allOptions = select.find('option');
|
||||
const optionLength = allOptions.length;
|
||||
let selectOption = '';
|
||||
|
||||
if (optionLength === 1) {
|
||||
selectOption = allOptions[0].value;
|
||||
} else if (optionLength === 2 && emptyOption.length === 1) {
|
||||
selectOption = allOptions[1].value;
|
||||
}
|
||||
|
||||
if (selectOption !== '') {
|
||||
select.val(selectOption);
|
||||
}
|
||||
}
|
||||
|
||||
// if we don't trigger the change, the other selects won't reset
|
||||
select.trigger('change');
|
||||
|
||||
// if select2 is active, this will tell the select to refresh
|
||||
if (select.hasClass('selectpicker')) {
|
||||
select.trigger('change.select2');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} pattern
|
||||
* @param {array} entity
|
||||
* @private
|
||||
*/
|
||||
_getTitleFromPattern(pattern, entity) {
|
||||
const DATE_UTILS = this.getPlugin('date');
|
||||
const regexp = new RegExp('{[^}]*?}','g');
|
||||
let title = pattern;
|
||||
let match = null;
|
||||
|
||||
while ((match = regexp.exec(pattern)) !== null) {
|
||||
const field = match[0].substr(1, match[0].length - 2);
|
||||
let value = entity[field] === undefined ? null : entity[field];
|
||||
if ((field === 'start' || field === 'end')) {
|
||||
if (value === null) {
|
||||
value = '?';
|
||||
} else {
|
||||
value = DATE_UTILS.getFormattedDate(value);
|
||||
}
|
||||
}
|
||||
|
||||
title = title.replace(new RegExp('{' + field + '}', 'g'), value ?? '');
|
||||
}
|
||||
title = title.replace(/- \?-\?/, '');
|
||||
title = title.replace(/\r\n|\r|\n/g, ' ');
|
||||
title = title.substr(0, 110);
|
||||
|
||||
const chars = '- ';
|
||||
let start = 0, end = title.length;
|
||||
|
||||
while (start < end && chars.indexOf(title[start]) >= 0) {
|
||||
++start;
|
||||
}
|
||||
|
||||
while (end > start && chars.indexOf(title[end - 1]) >= 0) {
|
||||
--end;
|
||||
}
|
||||
|
||||
return (start > 0 || end < title.length) ? title.substring(start, end) : title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} label
|
||||
* @param {string} value
|
||||
* @returns {HTMLElement}
|
||||
* @private
|
||||
*/
|
||||
_createOption(label, value) {
|
||||
let option = document.createElement('option');
|
||||
option.innerText = label;
|
||||
option.value = value;
|
||||
return option;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} label
|
||||
* @returns {HTMLElement}
|
||||
* @private
|
||||
*/
|
||||
_createOptgroup(label) {
|
||||
let optGroup = document.createElement('optgroup');
|
||||
optGroup.label = label;
|
||||
return optGroup;
|
||||
}
|
||||
}
|
||||
51
assets/js/plugins/KimaiHotkeys.js
Normal file
51
assets/js/plugins/KimaiHotkeys.js
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
import KimaiPlugin from "../KimaiPlugin";
|
||||
|
||||
export default class KimaiHotkeys extends KimaiPlugin {
|
||||
|
||||
getId()
|
||||
{
|
||||
return 'hotkeys';
|
||||
}
|
||||
|
||||
init()
|
||||
{
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
|
||||
|
||||
const selector = '[data-hotkey="ctrl+Enter"]';
|
||||
|
||||
window.addEventListener('keyup', (ev) => {
|
||||
if (ev.ctrlKey && ev.key === 'Enter') {
|
||||
const elements = [...document.querySelectorAll(selector)].filter(element => this.isVisible(element));
|
||||
|
||||
if (elements.length > 1) {
|
||||
console.warn('KimaiHotkeys: More than one visible element matches ${selector}. No action triggered.');
|
||||
}
|
||||
|
||||
if (elements.length === 1) {
|
||||
ev.stopPropagation();
|
||||
ev.preventDefault();
|
||||
|
||||
elements[0].click();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// adopted from Bootstrap 5.1.1, MIT
|
||||
isVisible (element)
|
||||
{
|
||||
if (!element || element.getClientRects().length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getComputedStyle(element).getPropertyValue('visibility') === 'visible';
|
||||
}
|
||||
}
|
||||
@@ -10,63 +10,121 @@
|
||||
*/
|
||||
|
||||
import KimaiPlugin from '../KimaiPlugin';
|
||||
import jQuery from "jquery";
|
||||
|
||||
export default class KimaiMultiUpdateTable extends KimaiPlugin {
|
||||
|
||||
init() {
|
||||
const self = this;
|
||||
|
||||
jQuery('body').
|
||||
on('change', '#multi_update_all', function(event) {
|
||||
jQuery('.multi_update_single').prop('checked', jQuery(event.target).prop('checked'));
|
||||
self.toggleForm();
|
||||
})
|
||||
.on('change', '.multi_update_single', function(event) {
|
||||
self.toggleForm();
|
||||
})
|
||||
.on('change', '#multi_update_table_action', function(event) {
|
||||
const selectedItem = jQuery('#multi_update_table_action option:selected');
|
||||
const selectedVal = selectedItem.val();
|
||||
|
||||
if (selectedVal === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
const form = jQuery('#multi_update_form form');
|
||||
const selectedText = selectedItem.text();
|
||||
const ids = self.getSelectedIds();
|
||||
const question = form.attr('data-question').replace(/%action%/, selectedText).replace(/%count%/, ids.length);
|
||||
|
||||
self.getContainer().getPlugin('alert').question(question, function(value) {
|
||||
if (value) {
|
||||
form.attr('action', selectedVal).submit();
|
||||
} else {
|
||||
jQuery('#multi_update_table_action').val('').trigger('change');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getSelectedIds()
|
||||
getId()
|
||||
{
|
||||
let ids = [];
|
||||
jQuery('.multi_update_single:checked').each(function(i){
|
||||
ids[i] = $(this).val();
|
||||
return 'datatable-batch-action';
|
||||
}
|
||||
|
||||
init()
|
||||
{
|
||||
if (document.getElementsByClassName('multi_update_all').length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we have to attach it to the "page-body" div, because section.content can be replaced
|
||||
// via KimaiDatable and everything inside will be removed, including event listeners
|
||||
const element = document.querySelector('div.page-body');
|
||||
element.addEventListener('change', (event) => {
|
||||
if (event.target.matches('.multi_update_all')) {
|
||||
this.toggle(event.target.checked, event.target.closest('table'));
|
||||
event.stopPropagation();
|
||||
} else if (event.target.matches('.multi_update_single')) {
|
||||
// single checkboxes in front of each row
|
||||
this._toggleDatatable(event.target.closest('table'));
|
||||
event.stopPropagation();
|
||||
}
|
||||
});
|
||||
|
||||
return ids;
|
||||
element.addEventListener('click', (event) => {
|
||||
if (event.target.matches('.multi_update_table_action')) {
|
||||
const selectedButton = event.target;
|
||||
const form = selectedButton.form;
|
||||
const ids = form.querySelector('.multi_update_ids').value.split(',');
|
||||
const question = form.dataset['question'].replace(/%action%/, selectedButton.textContent).replace(/%count%/, ids.length.toString());
|
||||
|
||||
/** @type {KimaiAlert} ALERT */
|
||||
const ALERT = this.getPlugin('alert');
|
||||
ALERT.question(question, function(value) {
|
||||
if (value) {
|
||||
form.action = selectedButton.dataset['href'];
|
||||
form.submit();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleForm()
|
||||
|
||||
/**
|
||||
* @param {boolean} checked
|
||||
* @param {HTMLTableElement} table
|
||||
*/
|
||||
toggle(checked, table)
|
||||
{
|
||||
const ids = this.getSelectedIds();
|
||||
jQuery('#multi_update_table_entities').val(ids.join(','));
|
||||
for (const element of table.querySelectorAll('.multi_update_single')) {
|
||||
element.checked = checked;
|
||||
}
|
||||
this._toggleDatatable(table);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} checked
|
||||
*/
|
||||
toggleAll(checked)
|
||||
{
|
||||
for (const element of document.querySelectorAll('.multi_update_all')) {
|
||||
this._toggleAll(checked, element);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} checked
|
||||
* @param {string} name
|
||||
*/
|
||||
toggleByName(checked, name)
|
||||
{
|
||||
for (const element of document.querySelectorAll('#multi_update_all_' + name)) {
|
||||
this._toggleAll(checked, element);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {boolean} checked
|
||||
* @param {Element} name
|
||||
*/
|
||||
_toggleAll(checked, element)
|
||||
{
|
||||
element.checked = checked;
|
||||
this.toggle(checked, element.closest('table'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLTableElement} table
|
||||
* @private
|
||||
*/
|
||||
_toggleDatatable(table)
|
||||
{
|
||||
const card = table.closest('div.card.data_table');
|
||||
|
||||
let ids = [];
|
||||
for (const box of table.querySelectorAll('input.multi_update_single:checked')) {
|
||||
ids.push(box.value);
|
||||
}
|
||||
|
||||
card.querySelector('.multi_update_ids').value = ids.join(',');
|
||||
|
||||
if (ids.length > 0) {
|
||||
jQuery('#multi_update_form').show();
|
||||
for (const element of card.querySelectorAll('.multi_update_form_hide')) {
|
||||
element.style.setProperty('display', 'none', 'important');
|
||||
}
|
||||
card.querySelector('form.multi_update_form').style.display = null;//'block';
|
||||
} else {
|
||||
jQuery('#multi_update_form').hide();
|
||||
card.querySelector('form.multi_update_form').style.setProperty('display', 'none', 'important');
|
||||
for (const element of card.querySelectorAll('.multi_update_form_hide')) {
|
||||
element.style.display = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
101
assets/js/plugins/KimaiNotification.js
Normal file
101
assets/js/plugins/KimaiNotification.js
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] Notification: notifications for Kimai
|
||||
*/
|
||||
|
||||
import KimaiPlugin from '../KimaiPlugin';
|
||||
|
||||
export default class KimaiNotification extends KimaiPlugin {
|
||||
|
||||
getId()
|
||||
{
|
||||
return 'notification';
|
||||
}
|
||||
|
||||
isSupported()
|
||||
{
|
||||
if (!window.Notification) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Notification.permission === 'denied') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Notification.permission === "granted";
|
||||
}
|
||||
|
||||
request(callback)
|
||||
{
|
||||
try {
|
||||
Notification.requestPermission().then((permission) => {
|
||||
if (permission === "granted") {
|
||||
callback(true);
|
||||
} else if (permission === "default") {
|
||||
callback(null);
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
});
|
||||
} catch (e) { // eslint-disable-line no-unused-vars
|
||||
Notification.requestPermission((permission) => {
|
||||
if (permission === "granted") {
|
||||
callback(true);
|
||||
} else if (permission === "default") {
|
||||
callback(null);
|
||||
} else {
|
||||
callback(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
notify(title, message, icon, options)
|
||||
{
|
||||
this.request((permission) => {
|
||||
|
||||
if (permission !== true) {
|
||||
/** @type KimaiAlert */
|
||||
const ALERT = this.getPlugin('alert');
|
||||
ALERT.info(message);
|
||||
}
|
||||
|
||||
let opts = {
|
||||
body: message,
|
||||
dir: this.getConfigurations().isRTL() ? 'rtl' : 'ltr',
|
||||
};
|
||||
//opts.requireInteraction = true;
|
||||
//opts.renotify = true;
|
||||
/*
|
||||
if (options.tag === undefined) {
|
||||
opts.tag = 'kimai';
|
||||
}
|
||||
*/
|
||||
if (icon !== undefined && icon !== null) {
|
||||
opts.icon = icon;
|
||||
}
|
||||
|
||||
let nTitle = 'Kimai';
|
||||
if (title !== null) {
|
||||
nTitle = nTitle + ': ' + title;
|
||||
}
|
||||
|
||||
if (options !== undefined && options !== null) {
|
||||
opts = { ...opts, ...options};
|
||||
}
|
||||
|
||||
const notification = new window.Notification(nTitle, opts);
|
||||
|
||||
notification.onclick = function () {
|
||||
window.focus();
|
||||
notification.close();
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiPauseRecord
|
||||
*
|
||||
* allows to pause records
|
||||
* THIS IS JUST A DRAFT FOR THE DOM, IT IS NOT SUPPORTED IN KIMAI ITSELF!
|
||||
*/
|
||||
|
||||
import jQuery from 'jquery';
|
||||
import KimaiPlugin from '../KimaiPlugin';
|
||||
|
||||
export default class KimaiPauseRecord extends KimaiPlugin {
|
||||
|
||||
constructor(selector) {
|
||||
super();
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
init() {
|
||||
this.activate(this.selector);
|
||||
}
|
||||
|
||||
activate(selector) {
|
||||
jQuery(selector + ' .pull-left i').hover(function () {
|
||||
let link = jQuery(this).parents('a');
|
||||
link.attr('href', link.attr('href').replace('/stop', '/pause'));
|
||||
jQuery(this).removeClass('fa-stop-circle').addClass('fa-pause-circle').addClass('text-orange');
|
||||
},function () {
|
||||
let link = jQuery(this).parents('a');
|
||||
link.attr('href', link.attr('href').replace('/pause', '/stop'));
|
||||
jQuery(this).removeClass('fa-pause-circle').removeClass('text-orange').addClass('fa-stop-circle');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiRecentActivities: responsible to reload the users recent activities
|
||||
*/
|
||||
|
||||
import KimaiPlugin from '../KimaiPlugin';
|
||||
|
||||
export default class KimaiRecentActivities extends KimaiPlugin {
|
||||
|
||||
constructor(selector) {
|
||||
super();
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
getId() {
|
||||
return 'recent-activities';
|
||||
}
|
||||
|
||||
init() {
|
||||
const menu = document.querySelector(this.selector);
|
||||
// the menu can be hidden if user has no permissions to see it
|
||||
if (menu === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const dropdown = menu.querySelector('ul.dropdown-menu');
|
||||
|
||||
this.attributes = dropdown.dataset;
|
||||
this.itemList = dropdown.querySelector('li > ul.menu');
|
||||
|
||||
const self = this;
|
||||
const handle = function() { self.reloadRecentActivities(); };
|
||||
|
||||
// don't block initial browser rendering
|
||||
setTimeout(handle, 500);
|
||||
|
||||
document.addEventListener('kimai.recentActivities', handle);
|
||||
document.addEventListener('kimai.timesheetUpdate', handle);
|
||||
document.addEventListener('kimai.timesheetDelete', handle);
|
||||
document.addEventListener('kimai.activityUpdate', handle);
|
||||
document.addEventListener('kimai.activityDelete', handle);
|
||||
document.addEventListener('kimai.projectUpdate', handle);
|
||||
document.addEventListener('kimai.projectDelete', handle);
|
||||
document.addEventListener('kimai.customerUpdate', handle);
|
||||
document.addEventListener('kimai.customerDelete', handle);
|
||||
}
|
||||
|
||||
emptyList() {
|
||||
this.itemList.innerHTML = '';
|
||||
}
|
||||
|
||||
setEntries(entries) {
|
||||
if (entries.length === 0) {
|
||||
this.emptyList();
|
||||
return;
|
||||
}
|
||||
|
||||
let htmlToInsert = '';
|
||||
|
||||
for (let timesheet of entries) {
|
||||
let label = this.attributes['template']
|
||||
.replace('%customer%', this.escape(timesheet.project.customer.name))
|
||||
.replace('%project%', this.escape(timesheet.project.name))
|
||||
.replace('%activity%', this.escape(timesheet.activity.name))
|
||||
;
|
||||
|
||||
htmlToInsert +=
|
||||
`<li>` +
|
||||
`<a href="${ this.attributes['href'].replace('000', timesheet.id) }" data-event="kimai.timesheetStart kimai.timesheetUpdate" class="api-link" data-method="PATCH" data-msg-error="timesheet.start.error" data-msg-success="timesheet.start.success">` +
|
||||
`<i class="${ this.attributes['icon'] }"></i> ${ label }` +
|
||||
`</a>` +
|
||||
`</li>`;
|
||||
}
|
||||
|
||||
this.itemList.innerHTML = htmlToInsert;
|
||||
}
|
||||
|
||||
reloadRecentActivities() {
|
||||
const self = this;
|
||||
const API = this.getContainer().getPlugin('api');
|
||||
|
||||
API.get(this.attributes['api'], {}, function(result) {
|
||||
self.setEntries(result);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,37 +9,70 @@
|
||||
* [KIMAI] KimaiReducedClickHandler: abstract class
|
||||
*/
|
||||
|
||||
import jQuery from 'jquery';
|
||||
import KimaiPlugin from "../KimaiPlugin";
|
||||
|
||||
export default class KimaiReducedClickHandler extends KimaiPlugin {
|
||||
|
||||
_addClickHandler(selector, callback) {
|
||||
jQuery('body').on('click', selector, function(event) {
|
||||
// just in case an inner element is editable, than this should not be triggered
|
||||
if (event.target.parentNode.isContentEditable || event.target.isContentEditable) {
|
||||
/**
|
||||
* No _underscore naming for now, as it would be mangled otherwise
|
||||
* @param {string} selector
|
||||
* @param {callback} callback
|
||||
* @param {array<string>} stopSelector
|
||||
*/
|
||||
addClickHandler(selector, callback, stopSelector) {
|
||||
document.body.addEventListener('click', (event) => {
|
||||
// event.currentTarget is ALWAYS the body
|
||||
|
||||
let target = event.target;
|
||||
while (target !== null) {
|
||||
const tagName = target.tagName.toUpperCase();
|
||||
if (tagName === 'BODY') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.matches(selector)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// when an element is clicked, which can trigger stuff itself, we don't want the event to be processed
|
||||
if (tagName === 'A' || tagName === 'BUTTON' || tagName === 'INPUT' || tagName === 'LABEL') {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let x of stopSelector) {
|
||||
if (target.matches(x)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
target = target.parentNode;
|
||||
}
|
||||
|
||||
if (target === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// handles the "click" on table rows or list elements
|
||||
let target = event.target;
|
||||
if (event.currentTarget.matches('tr') || event.currentTarget.matches('li')) {
|
||||
while (target !== null && !target.matches('body')) {
|
||||
// when an element within the row is clicked, that can trigger stuff itself, we don't want the event to be processed
|
||||
// don't act if a link, button or form element was clicked
|
||||
if (target.matches('a') || target.matches ('button') || target.matches ('input')) {
|
||||
return;
|
||||
}
|
||||
target = target.parentNode;
|
||||
// just in case an inner element is editable, then this should not be triggered
|
||||
if (target.isContentEditable || target.parentNode.isContentEditable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!target.matches(selector)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let x of stopSelector) {
|
||||
if (target.matches(x)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
let href = jQuery(this).attr('data-href');
|
||||
if (!href) {
|
||||
href = jQuery(this).attr('href');
|
||||
let href = target.dataset['href'];
|
||||
if (href === undefined || href === null) {
|
||||
href = target.href;
|
||||
}
|
||||
|
||||
if (href === undefined || href === null || href === '') {
|
||||
|
||||
94
assets/js/plugins/KimaiRemoteModal.js
Normal file
94
assets/js/plugins/KimaiRemoteModal.js
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiRemoteModal: load remote content (without forms) into a modal
|
||||
*/
|
||||
|
||||
import KimaiPlugin from '../KimaiPlugin';
|
||||
import { Modal } from 'bootstrap';
|
||||
|
||||
/**
|
||||
* Use like this:
|
||||
* <a href="{{ path('your-route') }}" class="remote-modal-load" data-modal-id="remote_modal" data-modal-class="p-0" data-modal-title="Some title" title="Some title">Modal</a>
|
||||
* <a href="{{ path('your-route') }}" class="remote-modal-load" data-modal-title="Some title" title="Some title">Modal</a>
|
||||
*/
|
||||
export default class KimaiRemoteModal extends KimaiPlugin {
|
||||
|
||||
constructor()
|
||||
{
|
||||
super();
|
||||
this._selector = 'a.remote-modal-load';
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
getId()
|
||||
{
|
||||
return 'remote-modal';
|
||||
}
|
||||
|
||||
init()
|
||||
{
|
||||
this.handle = (event) => {
|
||||
this._showModal(event.currentTarget);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
for (let link of document.querySelectorAll(this._selector)) {
|
||||
link.addEventListener('click', this.handle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLLinkElement} element
|
||||
* @private
|
||||
*/
|
||||
_showModal(element)
|
||||
{
|
||||
this.fetch(element.href, {method: 'GET'})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
let modalSelector = 'remote_modal';
|
||||
if (element.dataset['modalId'] !== undefined) {
|
||||
modalSelector = element.dataset['modalId'];
|
||||
}
|
||||
const modalElement = document.getElementById(modalSelector);
|
||||
if (modalElement === null) {
|
||||
console.log('Could not find modal with ID: ' + modalSelector);
|
||||
}
|
||||
|
||||
return response.text().then(html => {
|
||||
const modalBody = document.createElement('div');
|
||||
modalBody.classList.add('modal-body');
|
||||
if (element.dataset['modalClass'] !== undefined) {
|
||||
modalBody.classList.add(element.dataset['modalClass']);
|
||||
}
|
||||
modalBody.innerHTML = html;
|
||||
|
||||
for (let link of modalBody.querySelectorAll('a.remote-modal-reload')) {
|
||||
link.addEventListener('click', this.handle);
|
||||
}
|
||||
|
||||
modalElement.querySelector('.modal-body').replaceWith(modalBody);
|
||||
if (element.dataset['modalTitle'] !== undefined) {
|
||||
modalElement.querySelector('.modal-title').textContent = element.dataset['modalTitle'];
|
||||
}
|
||||
|
||||
Modal.getOrCreateInstance(modalElement).show();
|
||||
});
|
||||
})
|
||||
.catch((reason) => {
|
||||
console.log('Failed to load remote modal', reason);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiSelectDataAPI: <select> boxes with dynamic data from API
|
||||
*/
|
||||
|
||||
import jQuery from 'jquery';
|
||||
import KimaiPlugin from "../KimaiPlugin";
|
||||
import moment from 'moment';
|
||||
|
||||
export default class KimaiSelectDataAPI extends KimaiPlugin {
|
||||
|
||||
constructor(selector) {
|
||||
super();
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
getId() {
|
||||
return 'select-data-api';
|
||||
}
|
||||
|
||||
init() {
|
||||
this.activateApiSelects(this.selector);
|
||||
}
|
||||
|
||||
activateApiSelects(selector) {
|
||||
const self = this;
|
||||
const API = this.getContainer().getPlugin('api');
|
||||
|
||||
jQuery('body').on('change', selector, function(event) {
|
||||
const targetSelect = '#' + this.dataset['relatedSelect'];
|
||||
|
||||
// if the related target select does not exist, we do not need to load the related data
|
||||
if (jQuery(targetSelect).length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
let formPrefix = this.dataset['formPrefix'];
|
||||
if (formPrefix === undefined || formPrefix === null) {
|
||||
formPrefix = '';
|
||||
} else if (formPrefix.length > 0) {
|
||||
formPrefix += '_';
|
||||
}
|
||||
|
||||
let newApiUrl = self._buildUrlWithFormFields(this.dataset['apiUrl'], formPrefix);
|
||||
|
||||
const selectValue = jQuery(this).val();
|
||||
|
||||
// Problem: select a project with activities and then select a customer that has no project
|
||||
// results in a wrong URL, it triggers "activities?project=" instead of using the "emptyUrl"
|
||||
if (selectValue === undefined || selectValue === null || selectValue === '' || (Array.isArray(selectValue) && selectValue.length === 0)) {
|
||||
if (this.dataset['emptyUrl'] === undefined) {
|
||||
self._updateSelect(targetSelect, {});
|
||||
jQuery(targetSelect).attr('disabled', 'disabled');
|
||||
return;
|
||||
}
|
||||
newApiUrl = self._buildUrlWithFormFields(this.dataset['emptyUrl'], formPrefix);
|
||||
}
|
||||
|
||||
jQuery(targetSelect).removeAttr('disabled');
|
||||
|
||||
API.get(newApiUrl, {}, function(data){
|
||||
self._updateSelect(targetSelect, data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_buildUrlWithFormFields(apiUrl, formPrefix) {
|
||||
let newApiUrl = apiUrl;
|
||||
|
||||
apiUrl.split('?')[1].split('&').forEach(item => {
|
||||
const [key, value] = item.split('=');
|
||||
const decoded = decodeURIComponent(value);
|
||||
const test = decoded.match(/%(.*)%/);
|
||||
if (test !== null) {
|
||||
const targetField = jQuery('#' + formPrefix + test[1]);
|
||||
let newValue = '';
|
||||
if (targetField.length === 0) {
|
||||
// happens for example:
|
||||
// - in duration only mode, when the end field is not found
|
||||
// console.log('ERROR: Cannot find field with name "' + test[1] + '" by selector: #' + formPrefix + test[1]);
|
||||
} else {
|
||||
if (targetField.val() !== null) {
|
||||
newValue = targetField.val();
|
||||
|
||||
if (newValue !== '') {
|
||||
// having that special case here is far from being perfect... but for now it works ;-)
|
||||
if (targetField.data('daterangepicker') !== undefined) {
|
||||
if (key === 'begin' || key === 'start' || targetField.data('daterangepicker').singleDatePicker) {
|
||||
newValue = targetField.data('daterangepicker').startDate.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
|
||||
} else if (key === 'end') {
|
||||
newValue = targetField.data('daterangepicker').endDate.format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
|
||||
}
|
||||
} else if (targetField.data('format') !== undefined) {
|
||||
if (moment(newValue, targetField.data('format')).isValid()) {
|
||||
newValue = moment(newValue, targetField.data('format')).format(moment.HTML5_FMT.DATETIME_LOCAL_SECONDS);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// happens for example:
|
||||
// - when the end date is not set on a timesheet record and the project list is loaded (as the URL contains the %end% replacer)
|
||||
// console.log('Empty value found for field with name "' + test[1] + '" by selector: #' + formPrefix + test[1]);
|
||||
}
|
||||
} else {
|
||||
// happens for example:
|
||||
// - when a customer without projects is selected
|
||||
// console.log('ERROR: Empty field with name "' + test[1] + '" by selector: #' + formPrefix + test[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(newValue)) {
|
||||
newValue = newValue.join(',');
|
||||
}
|
||||
|
||||
newApiUrl = newApiUrl.replace(value, newValue);
|
||||
}
|
||||
});
|
||||
|
||||
return newApiUrl;
|
||||
}
|
||||
|
||||
_updateSelect(selectName, data) {
|
||||
const options = {};
|
||||
for (const apiData of data) {
|
||||
let title = '__empty__';
|
||||
if (apiData.hasOwnProperty('parentTitle') && apiData.parentTitle !== null) {
|
||||
title = apiData.parentTitle;
|
||||
}
|
||||
if (!options.hasOwnProperty(title)) {
|
||||
options[title] = [];
|
||||
}
|
||||
options[title].push(apiData);
|
||||
}
|
||||
|
||||
const ordered = {};
|
||||
Object.keys(options).sort().forEach(function(key) {
|
||||
ordered[key] = options[key];
|
||||
});
|
||||
|
||||
/** @var {KimaiFormSelect} select */
|
||||
const select = this.getContainer().getPlugin('form-select');
|
||||
select.updateOptions(selectName, ordered);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,93 +9,84 @@
|
||||
* [KIMAI] KimaiThemeInitializer: initialize theme functionality
|
||||
*/
|
||||
|
||||
import jQuery from 'jquery';
|
||||
import { Tooltip, Offcanvas } from 'bootstrap';
|
||||
import KimaiPlugin from '../KimaiPlugin';
|
||||
|
||||
export default class KimaiThemeInitializer extends KimaiPlugin {
|
||||
|
||||
init() {
|
||||
this.registerGlobalAjaxErrorHandler();
|
||||
this.registerAutomaticAlertRemove('div.alert-success', 5000);
|
||||
// activate the dropdown functionality
|
||||
jQuery('.dropdown-toggle').dropdown();
|
||||
// activate the tooltip functionality
|
||||
jQuery('[data-toggle="tooltip"]').tooltip();
|
||||
// activate all form plugins
|
||||
this.getContainer().getPlugin('form').activateForm('.content-wrapper form', 'body');
|
||||
this.getContainer().getPlugin('form').activateForm('form.searchform', 'body');
|
||||
init()
|
||||
{
|
||||
// the tooltip do not use data-bs-toggle="tooltip" so they can be mixed with data-toggle="modal"
|
||||
[].slice.call(document.querySelectorAll('[data-toggle="tooltip"]')).map(function (tooltipTriggerEl) {
|
||||
return new Tooltip(tooltipTriggerEl);
|
||||
});
|
||||
|
||||
this.registerModalAutofocus('#modal_search');
|
||||
this.registerModalAutofocus('#remote_form_modal');
|
||||
// support for offcanvas elements
|
||||
const offcanvasElementList = document.querySelectorAll('.offcanvas');
|
||||
[...offcanvasElementList].map(offcanvasEl => new Offcanvas(offcanvasEl));
|
||||
|
||||
// activate all form plugins
|
||||
/** @type {KimaiForm} FORMS */
|
||||
const FORMS = this.getContainer().getPlugin('form');
|
||||
FORMS.activateForm('div.page-wrapper form');
|
||||
|
||||
this._registerModalAutofocus('#remote_form_modal');
|
||||
|
||||
this.overlay = null;
|
||||
|
||||
// register a global event listener, which displays an overlays upon notification
|
||||
document.addEventListener('kimai.reloadContent', (event) => {
|
||||
// do not allow more than one loading screen at a time
|
||||
if (this.overlay !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// at which element we append the loading screen
|
||||
let container = 'div.page-wrapper';
|
||||
if (event.detail !== undefined && event.detail !== null) {
|
||||
container = event.detail;
|
||||
}
|
||||
|
||||
const temp = document.createElement('div');
|
||||
temp.innerHTML = '<div class="overlay"><div class="progress progress-sm"><div class="progress-bar progress-bar-indeterminate"></div></div></div>';
|
||||
this.overlay = temp.firstElementChild;
|
||||
document.querySelector(container).append(this.overlay);
|
||||
});
|
||||
|
||||
// register a global event listener, which hides an overlay upon notification
|
||||
document.addEventListener('kimai.reloadedContent', () => {
|
||||
if (this.overlay !== null) {
|
||||
this.overlay.remove();
|
||||
this.overlay = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* workaround for autofocus attribute, as the modal "steals" it
|
||||
* Helps to set the autofocus on modals.
|
||||
*
|
||||
* @param {string} selector
|
||||
*/
|
||||
registerModalAutofocus(selector) {
|
||||
let modal = jQuery(selector);
|
||||
if (modal.length === 0) {
|
||||
_registerModalAutofocus(selector) {
|
||||
// on mobile you do not want to trigger the virtual keyboard upon modal open
|
||||
if (this.isMobile()) {
|
||||
return;
|
||||
}
|
||||
|
||||
modal.on('shown.bs.modal', function () {
|
||||
let form = modal.find('form');
|
||||
let formAutofocus = form.find('[autofocus]');
|
||||
const modal = document.querySelector(selector);
|
||||
if (modal === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
modal.addEventListener('shown.bs.modal', () => {
|
||||
const form = modal.querySelector('form');
|
||||
let formAutofocus = form.querySelectorAll('[autofocus]');
|
||||
if (formAutofocus.length < 1) {
|
||||
formAutofocus = form.find('input[type=text],textarea,select');
|
||||
formAutofocus = form.querySelectorAll('input[type=text],input[type=date],textarea,select');
|
||||
}
|
||||
formAutofocus.filter(':not("[data-datetimepicker=on]")').filter(':visible:first').focus().delay(1000).focus();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* redirect access denied / session timeouts to login page
|
||||
*/
|
||||
registerGlobalAjaxErrorHandler() {
|
||||
const loginUrl = this.getConfiguration('login');
|
||||
const alert = this.getContainer().getPlugin('alert');
|
||||
const translation = this.getContainer().getTranslation().get('login.required');
|
||||
jQuery(document).ajaxError(function(event, jqxhr, settings, thrownError) {
|
||||
if (jqxhr.status !== undefined && jqxhr.status === 403) {
|
||||
const loginRequired = jqxhr.getResponseHeader('login-required');
|
||||
if (loginRequired !== null) {
|
||||
alert.question(translation, function (result) {
|
||||
if (result === true) {
|
||||
window.location.replace(loginUrl);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (formAutofocus.length > 0) {
|
||||
formAutofocus[0].focus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* auto hide success messages, as they are just meant as user feedback and not as a permanent information
|
||||
*
|
||||
* @param {string} selector
|
||||
* @param {integer} interval
|
||||
*/
|
||||
registerAutomaticAlertRemove(selector, interval) {
|
||||
const self = this;
|
||||
this._alertRemoveHandler = setInterval(
|
||||
function() {
|
||||
self.hideAlert(selector);
|
||||
},
|
||||
interval
|
||||
);
|
||||
}
|
||||
|
||||
unregisterAutomaticAlertRemove() {
|
||||
clearInterval(this._alertRemoveHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} selector
|
||||
*/
|
||||
hideAlert(selector) {
|
||||
jQuery(selector).alert('close');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,15 +9,14 @@
|
||||
* [KIMAI] KimaiToolbar: some event listener to handle the toolbar/data-table filter, toolbar and navigation
|
||||
*/
|
||||
|
||||
import jQuery from 'jquery';
|
||||
import KimaiPlugin from "../KimaiPlugin";
|
||||
|
||||
export default class KimaiToolbar extends KimaiPlugin {
|
||||
|
||||
constructor(formSelector, formSubmitActionClass) {
|
||||
super();
|
||||
this.formSelector = formSelector;
|
||||
this.actionClass = formSubmitActionClass;
|
||||
this._formSelector = formSelector;
|
||||
this._actionClass = formSubmitActionClass;
|
||||
}
|
||||
|
||||
getId() {
|
||||
@@ -26,50 +25,52 @@ export default class KimaiToolbar extends KimaiPlugin {
|
||||
|
||||
init() {
|
||||
const formSelector = this.getSelector();
|
||||
const self = this;
|
||||
const EVENT = self.getContainer().getPlugin('event');
|
||||
|
||||
this._registerPagination(formSelector, EVENT);
|
||||
this._registerSortableTables(formSelector, EVENT);
|
||||
this._registerAlternativeSubmitActions(formSelector, this.actionClass);
|
||||
this._registerPagination(formSelector);
|
||||
this._registerSortableTables(formSelector);
|
||||
this._registerAlternativeSubmitActions(formSelector, this._actionClass);
|
||||
|
||||
// Reset the page if filter values are changed, otherwise we might end up with a limited set of data,
|
||||
// which does not support the given page - and it would be just wrong to stay in the same page
|
||||
jQuery(formSelector +' input').change(function (event) {
|
||||
switch (event.target.id) {
|
||||
case 'order':
|
||||
case 'orderBy':
|
||||
case 'page':
|
||||
break;
|
||||
default:
|
||||
jQuery(formSelector + ' input#page').val(1);
|
||||
break;
|
||||
}
|
||||
self.triggerChange();
|
||||
[].slice.call(document.querySelectorAll(formSelector + ' input')).map((element) => {
|
||||
element.addEventListener('change', (event) => {
|
||||
switch (event.target.id) {
|
||||
case 'order':
|
||||
case 'orderBy':
|
||||
case 'page':
|
||||
break;
|
||||
default:
|
||||
document.querySelector(formSelector + ' input#page').value = 1;
|
||||
break;
|
||||
}
|
||||
});
|
||||
this.triggerChange();
|
||||
});
|
||||
|
||||
|
||||
// when user selected a new customer or project, reset the pagination back to 1
|
||||
// and then find out if the results should be reloaded
|
||||
jQuery(formSelector + ' select').change(function (event) {
|
||||
let reload = true;
|
||||
switch (event.target.id) {
|
||||
case 'customer':
|
||||
if (jQuery(formSelector + ' select#project').length > 0) {
|
||||
reload = false;
|
||||
}
|
||||
break;
|
||||
[].slice.call(document.querySelectorAll(formSelector + ' select')).map((element) => {
|
||||
element.addEventListener('change', (event) => {
|
||||
let reload = true;
|
||||
switch (event.target.id) {
|
||||
case 'customer':
|
||||
if (document.querySelector(formSelector + ' select#project') !== null) {
|
||||
reload = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'project':
|
||||
if (jQuery(formSelector + ' select#activity').length > 0) {
|
||||
reload = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
jQuery(formSelector + ' input#page').val(1);
|
||||
case 'project':
|
||||
if (document.querySelector(formSelector + ' select#activity') !== null) {
|
||||
reload = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
document.querySelector(formSelector + ' input#page').value = 1;
|
||||
|
||||
if (reload) {
|
||||
self.triggerChange();
|
||||
}
|
||||
if (reload) {
|
||||
this.triggerChange();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -80,15 +81,17 @@ export default class KimaiToolbar extends KimaiPlugin {
|
||||
_registerAlternativeSubmitActions(toolbarSelector, actionBtnClass) {
|
||||
document.addEventListener('click', function(event) {
|
||||
let target = event.target;
|
||||
while (target !== null && !target.matches('body')) {
|
||||
while (target !== null && typeof target.matches === "function" && !target.matches('body')) {
|
||||
if (target.classList.contains(actionBtnClass)) {
|
||||
const form = document.querySelector(toolbarSelector);
|
||||
if (form === null) {
|
||||
return;
|
||||
}
|
||||
const prevAction = form.action;
|
||||
const prevMethod = form.method;
|
||||
form.target = '_blank';
|
||||
const prevAction = form.getAttribute('action');
|
||||
const prevMethod = form.getAttribute('method');
|
||||
if (target.dataset.target !== undefined) {
|
||||
form.target = target.dataset.target;
|
||||
}
|
||||
form.action = target.href;
|
||||
if (target.dataset.method !== undefined) {
|
||||
form.method = target.dataset.method;
|
||||
@@ -104,51 +107,70 @@ export default class KimaiToolbar extends KimaiPlugin {
|
||||
|
||||
target = target.parentNode;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sortable datatables use hidden fields in the toolbar filter/search form
|
||||
* @private
|
||||
*/
|
||||
_registerSortableTables(formSelector, EVENT) {
|
||||
jQuery('body').on('click', 'th.sortable', function(event){
|
||||
var $header = jQuery(event.target);
|
||||
var order = 'DESC';
|
||||
var orderBy = $header.data('order');
|
||||
if ($header.hasClass('sorting_desc')) {
|
||||
_registerSortableTables(formSelector) {
|
||||
document.body.addEventListener('click', (event) => {
|
||||
if (!event.target.matches('th.sortable')) {
|
||||
return;
|
||||
}
|
||||
let order = 'DESC';
|
||||
let orderBy = event.target.dataset['order'];
|
||||
if (event.target.classList.contains('sorting_desc')) {
|
||||
order = 'ASC';
|
||||
}
|
||||
|
||||
jQuery(formSelector + ' #orderBy').val(orderBy);
|
||||
jQuery(formSelector + ' #order').val(order);
|
||||
document.querySelector(formSelector + ' #orderBy').value = orderBy;
|
||||
document.querySelector(formSelector + ' #order').value = order;
|
||||
|
||||
// re-render the selectboxes
|
||||
jQuery(formSelector + ' #orderBy').trigger('change');
|
||||
jQuery(formSelector + ' #order').trigger('change');
|
||||
// re-render the selectbox
|
||||
document.querySelector(formSelector + ' #orderBy').dispatchEvent(new Event('change'));
|
||||
document.querySelector(formSelector + ' #order').dispatchEvent(new Event('change'));
|
||||
|
||||
// triggers the datatable reload - search for the event name
|
||||
EVENT.trigger('filter-change');
|
||||
document.dispatchEvent(new Event('filter-change'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This catches all clicks on the pagination and prevents the default action, as we want to reload the page via JS
|
||||
* This catches all clicks on the pagination and prevents the default action,
|
||||
* as we want to reload the page via JS.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_registerPagination(formSelector, EVENT) {
|
||||
jQuery('body').on('click', 'div.navigation ul.pagination li a', function(event) {
|
||||
let pager = jQuery(formSelector + " input#page");
|
||||
if (pager.length === 0) {
|
||||
_registerPagination(formSelector) {
|
||||
document.body.addEventListener('click', (event) => {
|
||||
if (!event.target.matches('ul.pagination li a') && (event.target.parentNode === null || !event.target.parentNode.matches('ul.pagination li a'))) {
|
||||
return;
|
||||
}
|
||||
|
||||
let pager = document.querySelector(formSelector + " input#page");
|
||||
if (pager === null) {
|
||||
return;
|
||||
}
|
||||
let target = event.target;
|
||||
|
||||
// this happens for the arrows, which can be an icon <i> element
|
||||
if (!target.matches('a')) {
|
||||
target = target.parentNode;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
let urlParts = jQuery(this).attr('href').split('/');
|
||||
let page = urlParts[urlParts.length-1];
|
||||
pager.val(page);
|
||||
pager.trigger('change');
|
||||
EVENT.trigger('pagination-change');
|
||||
let urlParts = target.href.split('/');
|
||||
let pageNumber = urlParts[urlParts.length - 1];
|
||||
// page number usually is the default value and is therefor missing from the URL
|
||||
if (!/\d/.test(pageNumber)) {
|
||||
pageNumber = 1;
|
||||
}
|
||||
pager.value = pageNumber;
|
||||
pager.dispatchEvent(new Event('change'));
|
||||
document.dispatchEvent(new Event('pagination-change'));
|
||||
return false;
|
||||
});
|
||||
|
||||
@@ -158,7 +180,7 @@ export default class KimaiToolbar extends KimaiPlugin {
|
||||
* Triggers an event, that everyone can listen for.
|
||||
*/
|
||||
triggerChange() {
|
||||
this.getContainer().getPlugin('event').trigger('toolbar-change');
|
||||
document.dispatchEvent(new Event('toolbar-change'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,7 +189,7 @@ export default class KimaiToolbar extends KimaiPlugin {
|
||||
* @returns {string}
|
||||
*/
|
||||
getSelector() {
|
||||
return this.formSelector;
|
||||
return this._formSelector;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
59
assets/js/plugins/KimaiUser.js
Normal file
59
assets/js/plugins/KimaiUser.js
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiUser: information about the current user
|
||||
*/
|
||||
|
||||
import KimaiPlugin from "../KimaiPlugin";
|
||||
|
||||
export default class KimaiUser extends KimaiPlugin {
|
||||
|
||||
getId() {
|
||||
return 'user';
|
||||
}
|
||||
|
||||
init() {
|
||||
this.user = this.getConfigurations().get('user');
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
getUserId() {
|
||||
return this.user.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {string}
|
||||
*/
|
||||
getName() {
|
||||
return this.user.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isAdmin() {
|
||||
return this.user.admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean}
|
||||
*/
|
||||
isSuperAdmin() {
|
||||
return this.user.superAdmin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {array}
|
||||
*/
|
||||
getRoles() {
|
||||
return this.user.roles;
|
||||
}
|
||||
|
||||
}
|
||||
797
assets/js/widgets/KimaiCalendar.js
Normal file
797
assets/js/widgets/KimaiCalendar.js
Normal file
@@ -0,0 +1,797 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiCalendar: wrapping Fullcalendar.io
|
||||
*/
|
||||
import { Popover } from 'bootstrap';
|
||||
import { Calendar } from '@fullcalendar/core';
|
||||
import dayGridPlugin from '@fullcalendar/daygrid';
|
||||
import timeGridPlugin from '@fullcalendar/timegrid';
|
||||
import bootstrap5Plugin, { BootstrapTheme } from '@fullcalendar/bootstrap5';
|
||||
import googlePlugin from '@fullcalendar/google-calendar';
|
||||
import iCalendarPlugin from '@fullcalendar/icalendar';
|
||||
import interactionPlugin, { Draggable } from '@fullcalendar/interaction';
|
||||
import arLocale from '@fullcalendar/core/locales/ar';
|
||||
import csLocale from '@fullcalendar/core/locales/cs';
|
||||
import daLocale from '@fullcalendar/core/locales/da';
|
||||
import deLocale from '@fullcalendar/core/locales/de';
|
||||
import deAtLocale from '@fullcalendar/core/locales/de-at';
|
||||
import elLocale from '@fullcalendar/core/locales/el';
|
||||
import esLocale from '@fullcalendar/core/locales/es';
|
||||
import euLocale from '@fullcalendar/core/locales/eu';
|
||||
import faLocale from '@fullcalendar/core/locales/fa';
|
||||
import fiLocale from '@fullcalendar/core/locales/fi';
|
||||
import frLocale from '@fullcalendar/core/locales/fr';
|
||||
import heLocale from '@fullcalendar/core/locales/he';
|
||||
import hrLocale from '@fullcalendar/core/locales/hr';
|
||||
import huLocale from '@fullcalendar/core/locales/hu';
|
||||
import itLocale from '@fullcalendar/core/locales/it';
|
||||
import jaLocale from '@fullcalendar/core/locales/ja';
|
||||
import koLocale from '@fullcalendar/core/locales/ko';
|
||||
import nbLocale from '@fullcalendar/core/locales/nb';
|
||||
import nlLocale from '@fullcalendar/core/locales/nl';
|
||||
import plLocale from '@fullcalendar/core/locales/pl';
|
||||
import ptLocale from '@fullcalendar/core/locales/pt';
|
||||
import ptBrLocale from '@fullcalendar/core/locales/pt-br';
|
||||
import roLocale from '@fullcalendar/core/locales/ro';
|
||||
import ruLocale from '@fullcalendar/core/locales/ru';
|
||||
import skLocale from '@fullcalendar/core/locales/sk';
|
||||
import svLocale from '@fullcalendar/core/locales/sv';
|
||||
import trLocale from '@fullcalendar/core/locales/tr';
|
||||
import zhLocale from '@fullcalendar/core/locales/zh-cn';
|
||||
import viLocale from '@fullcalendar/core/locales/vi';
|
||||
import enGbLocale from '@fullcalendar/core/locales/en-gb';
|
||||
import enUsLocale from '@fullcalendar/core/locales/en-gb';
|
||||
import KimaiColor from './KimaiColor';
|
||||
import KimaiContextMenu from "./KimaiContextMenu";
|
||||
import { DateTime } from 'luxon';
|
||||
|
||||
export default class KimaiCalendar {
|
||||
|
||||
/**
|
||||
* Options is a huge JSON object.
|
||||
*
|
||||
* @param {KimaiContainer} kimai
|
||||
* @param {HTMLElement} element
|
||||
* @param {Object} options
|
||||
*/
|
||||
constructor(kimai, element, options) {
|
||||
this.kimai = kimai;
|
||||
this.options = options;
|
||||
|
||||
/** @type {KimaiAPI} API */
|
||||
const API = this.kimai.getPlugin('api');
|
||||
/** @type {KimaiDateUtils} DATES */
|
||||
const DATES = this.kimai.getPlugin('date');
|
||||
/** @type {KimaiAjaxModalForm} MODAL */
|
||||
const MODAL = this.kimai.getPlugin('modal');
|
||||
|
||||
// Instead of using "buttonIcons" the theme needs to be adjusted directly
|
||||
// https://fullcalendar.io/docs/buttonIcons
|
||||
BootstrapTheme.prototype.classes = {
|
||||
root: 'fc-theme-bootstrap5',
|
||||
tableCellShaded: 'fc-theme-bootstrap5-shaded',
|
||||
buttonGroup: 'btn-group',
|
||||
button: 'btn btn-primary btn-icon', // required for Tabler
|
||||
buttonActive: 'active',
|
||||
popover: 'popover',
|
||||
popoverHeader: 'popover-header',
|
||||
popoverContent: 'popover-body',
|
||||
};
|
||||
BootstrapTheme.prototype.baseIconClass = ''; // required for Fontawesome
|
||||
BootstrapTheme.prototype.iconOverridePrefix = ''; // required for Fontawesome
|
||||
BootstrapTheme.prototype.iconClasses = {
|
||||
close: 'fa-times',
|
||||
prev: this.options['icons']['previous'],
|
||||
next: this.options['icons']['next'],
|
||||
prevYear: this.options['icons']['previousYear'],
|
||||
nextYear: this.options['icons']['nextYear'],
|
||||
};
|
||||
BootstrapTheme.prototype.rtlIconClasses = {
|
||||
prev: this.options['icons']['previous'],
|
||||
next: this.options['icons']['next'],
|
||||
prevYear: this.options['icons']['previousYear'],
|
||||
nextYear: this.options['icons']['nextYear'],
|
||||
};
|
||||
let calendarOptions = {
|
||||
locales: [ enGbLocale, enUsLocale, arLocale, csLocale, daLocale, deLocale, deAtLocale, elLocale,
|
||||
esLocale, euLocale, faLocale, fiLocale, frLocale, heLocale, hrLocale, huLocale, itLocale, jaLocale, koLocale,
|
||||
nbLocale, nlLocale, plLocale, ptLocale, ptBrLocale, roLocale, ruLocale, skLocale, svLocale, trLocale, zhLocale, viLocale ],
|
||||
plugins: [ bootstrap5Plugin, dayGridPlugin, timeGridPlugin, googlePlugin, iCalendarPlugin, interactionPlugin ],
|
||||
initialView: this.toInternalViewName(this.options['initialView']),
|
||||
initialDate: this.options['initialDate'],
|
||||
// https://fullcalendar.io/docs/theming
|
||||
themeSystem: 'bootstrap5',
|
||||
// https://fullcalendar.io/docs/headerToolbar
|
||||
headerToolbar: {
|
||||
start: 'title',
|
||||
center: 'dayGridMonth,timeGridWeek,timeGridDay',
|
||||
end: 'today prev,next'
|
||||
},
|
||||
direction: this.kimai.getConfiguration().get('direction'),
|
||||
locale: this.kimai.getConfiguration().getLanguage().toLowerCase(),
|
||||
|
||||
// https://fullcalendar.io/docs/height
|
||||
// auto makes the calendar too small
|
||||
// height: 'auto',
|
||||
height: '80vh',
|
||||
|
||||
// allow clicking e.g. week-numbers to change the view to this week
|
||||
navLinks: true,
|
||||
nowIndicator: true,
|
||||
weekends: this.options['showWeekends'],
|
||||
weekNumbers: this.options['showWeekNumbers'],
|
||||
weekNumberCalculation: 'ISO',
|
||||
firstDay: this.kimai.getConfiguration().getFirstDayOfWeek(true),
|
||||
|
||||
now: this.options['now'],
|
||||
businessHours: {
|
||||
daysOfWeek: [0, 1, 2, 3, 4, 5, 6],
|
||||
startTime: this.options['businessTimeBegin'],
|
||||
endTime: this.options['businessTimeEnd']
|
||||
},
|
||||
slotDuration: this.options['slotDuration'],
|
||||
slotMinTime: this.options['timeframeBegin'] + ':00',
|
||||
slotMaxTime: this.options['timeframeEnd'] === '23:59' ? '24:00:00' : (this.options['timeframeEnd'] + ':59'),
|
||||
|
||||
// deactivate for auto calculation, which does a good job.
|
||||
// but 1h seems to be a "normal distance" for calendar apps (like Google and Apple)
|
||||
slotLabelInterval: '1:00',
|
||||
|
||||
// how long should entries look like when they don't have an end
|
||||
defaultTimedEventDuration: this.options['slotDuration'],
|
||||
|
||||
// https://fullcalendar.io/docs/timeZone
|
||||
timeZone: this.options['timezone'],
|
||||
|
||||
// TODO implement me later on
|
||||
// https://fullcalendar.io/docs/validRange
|
||||
// limit to the users registration date or a configuration for the first day in job
|
||||
|
||||
// https://fullcalendar.io/docs/hiddenDays
|
||||
// once we can configure working days
|
||||
// hiddenDays: [ 2, 4 ]
|
||||
|
||||
// dropAccept
|
||||
|
||||
dayMaxEventRows: true,
|
||||
eventMaxStack: this.options['dayLimit'],
|
||||
dayMaxEvents: this.options['dayLimit'],
|
||||
|
||||
// the callbacks "viewDidMount" and "viewWillUnmount" are only called when switching between month and others, not between week and day
|
||||
datesSet: (dateInfo) => {
|
||||
document.dispatchEvent(new CustomEvent('kimai.calendar.changeDate', {detail: {
|
||||
view: this.toExternalViewName(dateInfo.view.type),
|
||||
date: dateInfo.start.toISOString().split('T')[0],
|
||||
}}));
|
||||
},
|
||||
|
||||
views: {
|
||||
dayGrid: {
|
||||
dayMaxEventRows: this.options['dayLimit']
|
||||
}
|
||||
},
|
||||
|
||||
// ============= POPOVER =============
|
||||
viewClassNames: () => {
|
||||
document.querySelector('.fc-dayGridMonth-button').classList.remove('btn-icon');
|
||||
document.querySelector('.fc-timeGridWeek-button').classList.remove('btn-icon');
|
||||
document.querySelector('.fc-timeGridDay-button').classList.remove('btn-icon');
|
||||
},
|
||||
|
||||
// DESTROY TO PREVENT MEMORY LEAKS
|
||||
eventWillUnmount: (unmountInfo) => {
|
||||
// this happens when a user drags an external event to the calendar (view: week and day) and moves it around
|
||||
// for some reason the "eventWillUnmount" is triggered for this "potential but not yet existing event"
|
||||
if (unmountInfo.event.source === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.isKimaiSource(unmountInfo.event)) {
|
||||
return;
|
||||
}
|
||||
const popover = Popover.getInstance(unmountInfo.el);
|
||||
if (popover !== null) {
|
||||
popover.dispose();
|
||||
}
|
||||
},
|
||||
|
||||
// SHOW POPOVER FOR TIMESHEETS
|
||||
eventMouseEnter: (mouseEnterInfo) => {
|
||||
const event = mouseEnterInfo.event;
|
||||
|
||||
if (!this.isKimaiSource(event)) {
|
||||
// TODO allow to copy into kimai
|
||||
return;
|
||||
}
|
||||
|
||||
const element = mouseEnterInfo.el;
|
||||
const popoverTitle = DATES.getFormattedDate(event.start) + ' | ' + DATES.formatTime(event.start) + ' - ' + (event.end ? DATES.formatTime(event.end) : '');
|
||||
const popoverContent = this.renderEventPopoverContent(event);
|
||||
|
||||
let popover = Popover.getInstance(element);
|
||||
if (popover !== null) {
|
||||
// see https://github.com/kimai/kimai/issues/4043
|
||||
popover.setContent({
|
||||
'.popover-header': popoverTitle,
|
||||
'.popover-body': popoverContent
|
||||
});
|
||||
} else {
|
||||
// https://getbootstrap.com/docs/5.0/components/popovers/#options
|
||||
popover = new Popover(element, {
|
||||
title: popoverTitle,
|
||||
placement: 'top',
|
||||
html: true,
|
||||
content: popoverContent,
|
||||
trigger: 'focus',
|
||||
});
|
||||
}
|
||||
|
||||
popover.show();
|
||||
},
|
||||
|
||||
// HIDE POPOVER
|
||||
eventMouseLeave: (mouseLeaveInfo) => {
|
||||
if (!this.isKimaiSource(mouseLeaveInfo.event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.hidePopover(mouseLeaveInfo.el);
|
||||
},
|
||||
|
||||
// ContextMenu
|
||||
eventDidMount: (arg) => {
|
||||
arg.el.addEventListener('contextmenu', (jsEvent) => {
|
||||
jsEvent.preventDefault();
|
||||
const event = arg.event;
|
||||
if (!event.allDay) {
|
||||
const url = this.options.url.actions(event.extendedProps.timesheet);
|
||||
API.get(url, {}, result => {
|
||||
const contextMenu = new KimaiContextMenu('calendar_contextMenu');
|
||||
contextMenu.createFromApi(jsEvent, result);
|
||||
}, (e) => { console.log('Failed to load actions for context menu', e); });
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// called after all events of one source were set, so this can
|
||||
// and will be called multiple times before the calendar is initialized
|
||||
eventsSet: (events) => {
|
||||
this._renderDayAndWeekSum(this.getCalendar().getCurrentData().viewSpec.type, events);
|
||||
}
|
||||
};
|
||||
|
||||
// ============= DRAG & DROP =============
|
||||
|
||||
if (!this.hasPermission('punch') && this.hasPermission('create') && this.options.dragdrop !== undefined) {
|
||||
const draggableList = [].slice.call(document.querySelectorAll(this.options.dragdrop.container));
|
||||
draggableList.map((containerEl) => {
|
||||
return new Draggable(containerEl, {
|
||||
itemSelector: this.options.dragdrop.items
|
||||
});
|
||||
});
|
||||
|
||||
calendarOptions = {...calendarOptions, ...{
|
||||
droppable: true,
|
||||
// drop function handles external draggable events
|
||||
drop: (dropInfo) => {
|
||||
document.dispatchEvent(new CustomEvent('kimai.reloadContent'));
|
||||
const entry = dropInfo.draggedEl;
|
||||
const source = entry.parentElement;
|
||||
let data = JSON.parse(entry.dataset.entry);
|
||||
|
||||
const urlReplacer = JSON.parse(source.dataset.routeReplacer);
|
||||
let apiUrl = source.dataset.route;
|
||||
|
||||
for (const [key, value] of Object.entries(urlReplacer)) {
|
||||
apiUrl = apiUrl.replace(key, data[value]);
|
||||
}
|
||||
|
||||
let begin = dropInfo.date;
|
||||
|
||||
if (dropInfo.view.type === 'dayGridMonth') {
|
||||
let defaultStartTime = this.options.defaultStartTime;
|
||||
if (defaultStartTime === null) {
|
||||
const now = new Date();
|
||||
defaultStartTime = (now.getHours() < 10 ? '0' : '') + now.getHours() + ':' + (now.getMinutes() < 10 ? '0' : '') + now.getMinutes();
|
||||
}
|
||||
begin = DATES.addHumanDuration(begin, defaultStartTime);
|
||||
}
|
||||
|
||||
let end = DATES.addHumanDuration(begin, this.options['slotDuration']);
|
||||
|
||||
if (!this.hasPermission('punch')) {
|
||||
if (this.hasPermission('edit_begin')) {
|
||||
data.begin = DATES.formatForAPI(begin);
|
||||
}
|
||||
if (this.hasPermission('edit_end')) {
|
||||
data.end = DATES.formatForAPI(end);
|
||||
}
|
||||
}
|
||||
|
||||
data = this.options.preparePayloadForUpdate(data);
|
||||
|
||||
if (source.dataset.method === 'PATCH') {
|
||||
API.patch(
|
||||
apiUrl,
|
||||
JSON.stringify(data),
|
||||
(result) => {
|
||||
const newItem = this.convertSourceForCalendar(result);
|
||||
this.getCalendar().addEvent(newItem, true);
|
||||
document.dispatchEvent(new CustomEvent('kimai.reloadedContent'));
|
||||
}
|
||||
);
|
||||
} else {
|
||||
API.post(
|
||||
apiUrl,
|
||||
JSON.stringify(data),
|
||||
(result) => {
|
||||
const newItem = this.convertSourceForCalendar(result);
|
||||
this.getCalendar().addEvent(newItem, true);
|
||||
document.dispatchEvent(new CustomEvent('kimai.reloadedContent'));
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
}};
|
||||
}
|
||||
|
||||
// ============= CREATE NEW RECORDS =============
|
||||
|
||||
// After click or selection, not allowed for everyone
|
||||
if (!this.hasPermission('punch') && this.hasPermission('create')) {
|
||||
calendarOptions = {...calendarOptions, ...{
|
||||
dateClick: (dateClickInfo) => {
|
||||
// Day-clicks are always triggered, unless a selection was created.
|
||||
// So clicking in a day (month view) or any slot (week and day view) will trigger a dayClick
|
||||
// BEFORE triggering a select - make sure not two create dialogs are requested
|
||||
if (dateClickInfo.view.type !== 'dayGridMonth') {
|
||||
return;
|
||||
}
|
||||
|
||||
const createUrl = this.options.url.create(dateClickInfo.dateStr);
|
||||
MODAL.openUrlInModal(createUrl);
|
||||
},
|
||||
selectable: true,
|
||||
select: (selectionInfo) => {
|
||||
if(selectionInfo.view.type === 'dayGridMonth') {
|
||||
// Multi-day clicks are NOT allowed in the month view, as simple day clicks would also trigger
|
||||
// a select - there is no way to distinguish a simple click and a two-day selection
|
||||
return;
|
||||
}
|
||||
|
||||
const createUrl = this.options.url.create(selectionInfo.startStr, selectionInfo.endStr);
|
||||
MODAL.openUrlInModal(createUrl);
|
||||
},
|
||||
}};
|
||||
}
|
||||
|
||||
// ============= EDIT TIMESHEET =============
|
||||
|
||||
if (this.hasPermission('edit')) {
|
||||
calendarOptions = {...calendarOptions, ...{
|
||||
eventClick: (eventClickInfo) => {
|
||||
const event = eventClickInfo.event;
|
||||
if (!this.isKimaiSource(event)) {
|
||||
eventClickInfo.jsEvent.preventDefault();
|
||||
return;
|
||||
}
|
||||
this.hidePopover(eventClickInfo.el);
|
||||
|
||||
if (!event.extendedProps.exported || this.hasPermission('edit_exported')) {
|
||||
MODAL.openUrlInModal(
|
||||
this.options.url.edit(event.id), (reason) => {
|
||||
// 403 = user is not allowed to edit the entry (e.g. lockdown mode)
|
||||
if (reason.status !== 403) {
|
||||
// keep the log, it might help with debugging
|
||||
console.log(reason);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
}};
|
||||
|
||||
// UPDATE TIMESHEET - MOVE THEM OR EXTEND THEM
|
||||
if (!this.hasPermission('punch')) {
|
||||
calendarOptions = {...calendarOptions, ...{
|
||||
// https://fullcalendar.io/docs/event-dragging-resizing
|
||||
dragRevertDuration: 0,
|
||||
eventStartEditable: this.hasPermission('edit_begin'),
|
||||
eventDurationEditable: this.hasPermission('edit_end') || this.hasPermission('edit_duration'),
|
||||
eventDragStart: (info) => {
|
||||
this.hidePopover(info.el);
|
||||
},
|
||||
eventDrop: (eventDropInfo) => {
|
||||
this.changeHandler(eventDropInfo);
|
||||
},
|
||||
eventResizeStart: (info) => {
|
||||
this.hidePopover(info.el);
|
||||
},
|
||||
eventResize: (eventResizeInfo) => {
|
||||
this.changeHandler(eventResizeInfo);
|
||||
},
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
||||
// ============= GOOGLE CALENDAR =============
|
||||
|
||||
if (this.options['googleCalendarApiKey'] !== undefined) {
|
||||
calendarOptions = {...calendarOptions, ...{
|
||||
// https://fullcalendar.io/docs/google-calendar
|
||||
googleCalendarApiKey: this.options['googleCalendarApiKey'],
|
||||
}};
|
||||
}
|
||||
|
||||
// ============= EVENT SOURCES =============
|
||||
|
||||
let eventSources = [];
|
||||
for (const source of this.options['eventSources']) {
|
||||
let calendarSource = {};
|
||||
if (source.type === 'timesheet') {
|
||||
calendarSource = {...calendarSource, ...{
|
||||
id: 'kimai-' + source.id,
|
||||
events: (fetchInfo, successCallback, failureCallback) => {
|
||||
const targetFrom = DATES.formatForAPI(fetchInfo.start);
|
||||
const targetTo = DATES.formatForAPI(fetchInfo.end);
|
||||
|
||||
let url = source.url;
|
||||
url = url.replace('{from}', targetFrom);
|
||||
url = url.replace('__FROM__', targetFrom);
|
||||
url = url.replace('{to}', targetTo);
|
||||
url = url.replace('__TO__', targetTo);
|
||||
|
||||
API.get(url, {}, result => {
|
||||
let apiEvents = [];
|
||||
for (const record of result) {
|
||||
apiEvents.push(this.convertSourceForCalendar(record));
|
||||
}
|
||||
successCallback(apiEvents);
|
||||
}, failureCallback);
|
||||
},
|
||||
}};
|
||||
} else if (source.type === 'google') {
|
||||
calendarSource = {...calendarSource, ...{
|
||||
id: 'google-' + source.id,
|
||||
name: 'google',
|
||||
editable: false,
|
||||
}};
|
||||
} else if (source.type === 'json') {
|
||||
calendarSource = {...calendarSource, ...{
|
||||
id: 'json-' + source.id,
|
||||
editable: false,
|
||||
events: (fetchInfo, successCallback, failureCallback) => {
|
||||
const targetFrom = DATES.formatForAPI(fetchInfo.start);
|
||||
const targetTo = DATES.formatForAPI(fetchInfo.end);
|
||||
|
||||
let url = source.url;
|
||||
url = url.replace('{from}', targetFrom);
|
||||
url = url.replace('__FROM__', targetFrom);
|
||||
url = url.replace('{to}', targetTo);
|
||||
url = url.replace('__TO__', targetTo);
|
||||
|
||||
API.get(url, {}, result => {
|
||||
let apiEvents = [];
|
||||
for (const record of result) {
|
||||
apiEvents.push(record);
|
||||
}
|
||||
successCallback(apiEvents);
|
||||
}, failureCallback);
|
||||
},
|
||||
}};
|
||||
} else if (source.type === 'ical') {
|
||||
calendarSource = {...calendarSource, ...{
|
||||
id: 'ical-' + source.id,
|
||||
url: source.url,
|
||||
format: 'ics',
|
||||
editable: false,
|
||||
}};
|
||||
} else {
|
||||
console.log('Unknown source type given, skipping to load events from: ' + source.id);
|
||||
continue;
|
||||
}
|
||||
if (source.options !== undefined) {
|
||||
calendarSource = {...calendarSource, ...source.options};
|
||||
}
|
||||
eventSources.push(calendarSource);
|
||||
}
|
||||
|
||||
if (eventSources.length > 0) {
|
||||
calendarOptions = {...calendarOptions, ...{
|
||||
eventSources: eventSources,
|
||||
}};
|
||||
}
|
||||
|
||||
// INITIALIZE CALENDAR
|
||||
this.calendar = new Calendar(element, calendarOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {EventApi} event
|
||||
* @return {boolean}
|
||||
* @private
|
||||
*/
|
||||
isKimaiSource(event) {
|
||||
if (event === null) {
|
||||
return false;
|
||||
}
|
||||
if (event.source === null) {
|
||||
return false;
|
||||
}
|
||||
return (event.source.id.indexOf('kimai-') === 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} viewName
|
||||
* @returns {string}
|
||||
*/
|
||||
toExternalViewName(viewName) {
|
||||
switch(viewName) {
|
||||
case 'timeGridDay':
|
||||
return 'day';
|
||||
case 'timeGridWeek':
|
||||
return 'week';
|
||||
case 'dayGridMonth':
|
||||
default:
|
||||
return 'month';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} viewName
|
||||
* @returns {string}
|
||||
*/
|
||||
toInternalViewName(viewName) {
|
||||
switch(viewName) {
|
||||
case 'day':
|
||||
case 'agendaDay':
|
||||
case 'timeGridDay':
|
||||
return 'timeGridDay';
|
||||
case 'week':
|
||||
case 'agendaWeek':
|
||||
case 'timeGridWeek':
|
||||
return 'timeGridWeek';
|
||||
case 'month':
|
||||
case 'agendaMonth':
|
||||
case 'dayGridMonth':
|
||||
default:
|
||||
return 'dayGridMonth';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} name
|
||||
* @return {boolean}
|
||||
* @private
|
||||
*/
|
||||
hasPermission(name) {
|
||||
return this.options['permissions'][name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Calendar}
|
||||
*/
|
||||
getCalendar() {
|
||||
return this.calendar;
|
||||
}
|
||||
|
||||
render() {
|
||||
this.calendar.render();
|
||||
}
|
||||
|
||||
reloadEvents() {
|
||||
this.calendar.getEventSources().forEach(source => source.refetch());
|
||||
}
|
||||
|
||||
/**
|
||||
* Only used on manipulated timesheets!
|
||||
*
|
||||
* @param {object} apiItem
|
||||
* @return {{activity, color: *, start, description, project, end, id, title: *, textColor: *, customer, tags: ([number,number,[],string,string]|*)}}
|
||||
* @private
|
||||
*/
|
||||
convertSourceForCalendar(apiItem) {
|
||||
const defaultColor = this.kimai.getConfiguration().get('defaultColor');
|
||||
let color = apiItem.activity.color;
|
||||
if (color === null || color === defaultColor) {
|
||||
color = apiItem.project.color;
|
||||
if (color === null || color === defaultColor) {
|
||||
color = apiItem.project.customer.color;
|
||||
}
|
||||
}
|
||||
if (color === null) {
|
||||
color = defaultColor;
|
||||
}
|
||||
|
||||
/** @type {KimaiDateUtils} DATES */
|
||||
const DATES = this.kimai.getPlugin('date');
|
||||
|
||||
let title = this.options['patterns']['title'];
|
||||
title = title.replace('{project}', apiItem.project.name);
|
||||
title = title.replace('{customer}', apiItem.project.customer.name);
|
||||
title = title.replace('{description}', apiItem.description ?? '');
|
||||
title = title.replace('{activity}', apiItem.activity.name ?? '');
|
||||
|
||||
if (apiItem.end === null) {
|
||||
// duration = 0 and end = null => is a running entry
|
||||
title = title.replace('{duration}', '');
|
||||
} else {
|
||||
title = title.replace('{duration}', DATES.formatDuration(apiItem.duration));
|
||||
}
|
||||
|
||||
if (title === '' || title === null) {
|
||||
title = apiItem.activity.name;
|
||||
}
|
||||
|
||||
return {
|
||||
id: apiItem.id,
|
||||
timesheet: apiItem.id,
|
||||
title: title,
|
||||
description: apiItem.description,
|
||||
exported: apiItem.exported,
|
||||
start: apiItem.begin,
|
||||
end: apiItem.end,
|
||||
activity: apiItem.activity.name,
|
||||
project: apiItem.project.name,
|
||||
customer: apiItem.project.customer.name,
|
||||
tags: apiItem.tags,
|
||||
color: color,
|
||||
textColor: KimaiColor.calculateContrastColor(color),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {EventApi} event
|
||||
* @return {string}
|
||||
* @private
|
||||
*/
|
||||
renderEventPopoverContent(event) {
|
||||
const eventObj = event.extendedProps;
|
||||
/** @type {KimaiEscape} escaper */
|
||||
const escaper = this.kimai.getPlugin('escape');
|
||||
|
||||
let tags = '';
|
||||
if (eventObj.tags !== null && eventObj.tags.length > 0) {
|
||||
for (let tag of eventObj.tags) {
|
||||
tags += '<span class="badge bg-green">' + escaper.escapeForHtml(tag) + '</span>';
|
||||
}
|
||||
}
|
||||
|
||||
return escaper.sanitize(`
|
||||
<div class="calendar-entry">
|
||||
<ul>
|
||||
<li>` + this.options['translations']['customer'] + `: ` + escaper.escapeForHtml(eventObj.customer) + `</li>
|
||||
<li>` + this.options['translations']['project'] + `: ` + escaper.escapeForHtml(eventObj.project) + `</li>
|
||||
<li>` + this.options['translations']['activity'] + `: ` + escaper.escapeForHtml(eventObj.activity) + `</li>
|
||||
</ul>` +
|
||||
(eventObj.description !== null || eventObj.tags.length > 0 ? '<hr>' : '') +
|
||||
(eventObj.description ? '<div>' + escaper.escapeForHtml(eventObj.description) + '</div>' : '') + tags + `
|
||||
</div>`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLElement} element
|
||||
* @private
|
||||
*/
|
||||
hidePopover(element) {
|
||||
let popover = Popover.getInstance(element);
|
||||
|
||||
if (popover !== null) {
|
||||
popover.hide();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {EventDropArg} eventArg
|
||||
* @private
|
||||
*/
|
||||
changeHandler(eventArg) {
|
||||
/** @type {EventApi} event */
|
||||
const event = eventArg.event;
|
||||
|
||||
if (event.extendedProps.exported && !this.hasPermission('edit_exported')) {
|
||||
eventArg.revert();
|
||||
return;
|
||||
}
|
||||
|
||||
/** @type {KimaiAPI} API */
|
||||
const API = this.kimai.getPlugin('api');
|
||||
/** @type {KimaiDateUtils} DATE */
|
||||
const DATES = this.kimai.getPlugin('date');
|
||||
|
||||
let payload = {'begin': DATES.formatForAPI(event.start)};
|
||||
|
||||
if (event.end !== null && event.end !== undefined) {
|
||||
payload.end = DATES.formatForAPI(event.end);
|
||||
} else {
|
||||
payload.end = null;
|
||||
}
|
||||
|
||||
document.dispatchEvent(new CustomEvent('kimai.reloadContent'));
|
||||
|
||||
const updateUrl = this.options.url.update(event.id);
|
||||
API.patch(updateUrl, JSON.stringify(payload), () => {
|
||||
document.dispatchEvent(new CustomEvent('kimai.reloadedContent'));
|
||||
}, (error) => {
|
||||
eventArg.revert();
|
||||
document.dispatchEvent(new CustomEvent('kimai.reloadedContent'));
|
||||
API.handleError('action.update.error', error);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} view
|
||||
* @param {EventApi[]} events
|
||||
* @private
|
||||
*/
|
||||
_renderDayAndWeekSum(view, events) {
|
||||
if (view === 'dayGridMonth') {
|
||||
// currently we do not display totals in month view
|
||||
return;
|
||||
}
|
||||
|
||||
/** @type {KimaiDateUtils} DATES */
|
||||
const DATES = this.kimai.getPlugin('date');
|
||||
|
||||
const durations = {};
|
||||
|
||||
if (view === 'timeGridWeek') {
|
||||
// make sure we have an entry for every day of the week, even days without timesheets
|
||||
document.querySelectorAll(`th.fc-col-header-cell[data-date]`).forEach(cell => {
|
||||
durations[cell.dataset.date] = 0;
|
||||
});
|
||||
}
|
||||
|
||||
events.forEach(item => {
|
||||
const start = DateTime.fromJSDate(item.start).toUTC();
|
||||
const dateStr = start.toFormat('yyyy-MM-dd');
|
||||
|
||||
if (!durations[dateStr]) {
|
||||
durations[dateStr] = 0;
|
||||
}
|
||||
|
||||
// absences or public holidays are all day
|
||||
if (item.end !== null) {
|
||||
const end = DateTime.fromJSDate(item.end).toUTC();
|
||||
const duration = end.diff(start, 'hours').as('seconds');
|
||||
durations[dateStr] += duration;
|
||||
}
|
||||
});
|
||||
|
||||
const dailyTotals = document.querySelectorAll('.fc-dailytotal');
|
||||
dailyTotals.forEach(element => element.remove());
|
||||
for (const dateValue in durations) {
|
||||
const durationValue = durations[dateValue];
|
||||
|
||||
if (view === 'timeGridWeek') { // this is the week view
|
||||
const headerCells = document.querySelectorAll(`th.fc-col-header-cell[data-date="${dateValue}"]`);
|
||||
|
||||
headerCells.forEach(cell => {
|
||||
const newElement = document.createElement('div');
|
||||
newElement.classList.add('fc-dailytotal');
|
||||
newElement.textContent = DATES.formatSeconds(durationValue);
|
||||
cell.appendChild(newElement);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// this is the day view
|
||||
if (view === 'timeGridDay') {
|
||||
const dayEl = document.querySelector('th.fc-day');
|
||||
const dayDate = dayEl.dataset.date;
|
||||
const dayTotal = document.querySelectorAll('.fc-dailytotal');
|
||||
dayTotal.forEach(element => element.remove());
|
||||
|
||||
const newElement = document.createElement('div');
|
||||
newElement.classList.add('fc-dailytotal');
|
||||
newElement.textContent = DATES.formatSeconds(durations[dayDate]);
|
||||
dayEl.appendChild(newElement);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
assets/js/widgets/KimaiColor.js
Normal file
38
assets/js/widgets/KimaiColor.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiColor: handle colors
|
||||
*/
|
||||
|
||||
export default class KimaiColor {
|
||||
|
||||
/**
|
||||
* @param {string} hexcolor
|
||||
* @return {string}
|
||||
*/
|
||||
static calculateContrastColor(hexcolor)
|
||||
{
|
||||
if (hexcolor.slice(0, 1) === '#') {
|
||||
hexcolor = hexcolor.slice(1);
|
||||
}
|
||||
|
||||
if (hexcolor.length === 3) {
|
||||
hexcolor = hexcolor.split('').map(function (hex) { return hex + hex; }).join('');
|
||||
}
|
||||
|
||||
const r = parseInt(hexcolor.substring(0,2),16);
|
||||
const g = parseInt(hexcolor.substring(2,4),16);
|
||||
const b = parseInt(hexcolor.substring(4,6),16);
|
||||
|
||||
// https://gomakethings.com/dynamically-changing-the-text-color-based-on-background-color-contrast-with-vanilla-js/
|
||||
const yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000;
|
||||
|
||||
return (yiq >= 128) ? '#000000' : '#ffffff';
|
||||
}
|
||||
|
||||
}
|
||||
145
assets/js/widgets/KimaiContextMenu.js
Normal file
145
assets/js/widgets/KimaiContextMenu.js
Normal file
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiContextMenu: help to create, position and display context menus
|
||||
*/
|
||||
|
||||
export default class KimaiContextMenu {
|
||||
|
||||
/**
|
||||
* @param {string} id
|
||||
*/
|
||||
constructor(id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {HTMLElement}
|
||||
*/
|
||||
getContextMenuElement()
|
||||
{
|
||||
if (document.getElementById(this.id) === null) {
|
||||
const temp = document.createElement('div');
|
||||
temp.id = this.id;
|
||||
temp.classList.add('dropdown-menu', 'd-none');
|
||||
document.body.appendChild(temp);
|
||||
}
|
||||
|
||||
return document.getElementById(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {MouseEvent} event
|
||||
* @param {object} json
|
||||
*/
|
||||
createFromApi(event, json)
|
||||
{
|
||||
let html = '';
|
||||
|
||||
for (const options of json) {
|
||||
if (options['divider'] === true) {
|
||||
html += '<div class="dropdown-divider"></div>';
|
||||
}
|
||||
|
||||
if (options['url'] !== null) {
|
||||
html += '<a class="dropdown-item ' + (options['class'] !== null ? options['class'] : '') + '" href="' + options['url'] + '"';
|
||||
|
||||
if (options['attr'] !== undefined) {
|
||||
for (const attrName in options['attr']) {
|
||||
html += ' ' + attrName + '="' + options['attr'][attrName].replaceAll('"', '"') + '"';
|
||||
}
|
||||
}
|
||||
html += '>' + options['title'] + '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
this.createFromClickEvent(event, html);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {MouseEvent} event
|
||||
* @param {string} html
|
||||
*/
|
||||
createFromClickEvent(event, html)
|
||||
{
|
||||
const dropdownElement = this.getContextMenuElement();
|
||||
|
||||
if (!dropdownElement.classList.contains('action-dropdown')) {
|
||||
dropdownElement.classList.add('action-dropdown');
|
||||
}
|
||||
|
||||
dropdownElement.innerHTML = html;
|
||||
dropdownElement.style.position = 'fixed';
|
||||
dropdownElement.style.top = (event.clientY) + 'px';
|
||||
dropdownElement.style.left = (event.clientX) + 'px';
|
||||
|
||||
const dropdownListener = (event) => {
|
||||
if (event.target.classList.contains('dropdown-toggle') || event.target.classList.contains('dropdown-divider')) {
|
||||
return;
|
||||
}
|
||||
dropdownElement.classList.remove('d-block');
|
||||
if (!dropdownElement.classList.contains('d-none')) {
|
||||
dropdownElement.classList.add('d-none');
|
||||
}
|
||||
dropdownElement.removeEventListener('click', dropdownListener);
|
||||
document.removeEventListener('click', dropdownListener);
|
||||
};
|
||||
|
||||
dropdownElement.addEventListener('click', dropdownListener);
|
||||
document.addEventListener('click', dropdownListener);
|
||||
|
||||
dropdownElement.classList.remove('d-none');
|
||||
if (!dropdownElement.classList.contains('d-block')) {
|
||||
dropdownElement.classList.add('d-block');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} selector
|
||||
*/
|
||||
static createForDataTable(selector)
|
||||
{
|
||||
[].slice.call(document.querySelectorAll(selector)).map((dataTable) => {
|
||||
const actions = dataTable.querySelector('td.actions div.dropdown-menu');
|
||||
if (actions === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
dataTable.addEventListener('contextmenu', (jsEvent) => {
|
||||
let target = jsEvent.target;
|
||||
while (target !== null) {
|
||||
const tagName = target.tagName.toUpperCase();
|
||||
if (tagName === 'TH' || tagName === 'TABLE' || tagName === 'BODY') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (tagName === 'TR') {
|
||||
break;
|
||||
}
|
||||
|
||||
target = target.parentNode;
|
||||
}
|
||||
|
||||
if (target === null || !target.matches('table.dataTable tbody tr')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const actions = target.querySelector('td.actions div.dropdown-menu');
|
||||
if (actions === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
jsEvent.preventDefault();
|
||||
|
||||
const contextMenu = new KimaiContextMenu(dataTable.dataset['contextMenu']);
|
||||
contextMenu.createFromClickEvent(jsEvent, actions.innerHTML);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* [KIMAI] KimaiCookies: simple wrapper to handle cookies
|
||||
*/
|
||||
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
export default class KimaiCookies {
|
||||
|
||||
static set(name, values, options) {
|
||||
Cookies.set(name, values, options);
|
||||
}
|
||||
|
||||
static get(name) {
|
||||
return Cookies.getJSON(name);
|
||||
}
|
||||
|
||||
static remove(name) {
|
||||
Cookies.remove(name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,32 +9,41 @@
|
||||
* [KIMAI] KimaiPaginatedBoxWidget: handles box widgets that have a pagination
|
||||
*/
|
||||
|
||||
import jQuery from "jquery";
|
||||
import KimaiContextMenu from "./KimaiContextMenu";
|
||||
|
||||
export default class KimaiPaginatedBoxWidget {
|
||||
|
||||
constructor(boxId) {
|
||||
this.selector = boxId;
|
||||
this.overlay = jQuery('<div class="overlay"><div class="fas fa-sync fa-spin"></div></div>');
|
||||
this.widget = jQuery(this.selector);
|
||||
this.href = this.widget.data('href');
|
||||
this.events = this.widget.data('reload').split(' ');
|
||||
const widget = document.querySelector(this.selector);
|
||||
|
||||
const self = this;
|
||||
if (widget.dataset['reload'] !== undefined) {
|
||||
this.events = widget.dataset['reload'].split(' ');
|
||||
const reloadPage = () => {
|
||||
let url = null;
|
||||
if (document.querySelector(this.selector).dataset['reloadHref'] !== undefined) {
|
||||
url = document.querySelector(this.selector).dataset['reloadHref'];
|
||||
} else {
|
||||
url = document.querySelector(this.selector + ' ul.pagination li.active a').href;
|
||||
}
|
||||
this.loadPage(url);
|
||||
};
|
||||
|
||||
const reloadPage = function (event) {
|
||||
const page = jQuery(self.selector + ' .box-tools').data('page');
|
||||
const url = self._buildUrl(page);
|
||||
self.loadPage(url);
|
||||
};
|
||||
|
||||
for (const eventName of this.events) {
|
||||
document.addEventListener(eventName, reloadPage);
|
||||
for (const eventName of this.events) {
|
||||
document.addEventListener(eventName, reloadPage);
|
||||
}
|
||||
}
|
||||
|
||||
this.widget.on('click', '.box-tools ul.pagination a', function (event) {
|
||||
event.preventDefault();
|
||||
self.loadPage(jQuery(event.currentTarget).attr('href'));
|
||||
document.body.addEventListener('click', (event) => {
|
||||
let link = event.target;
|
||||
// could be an icon
|
||||
if (!link.matches(this.selector + ' a.pagination-link')) {
|
||||
link = link.parentNode;
|
||||
}
|
||||
if (link.matches(this.selector + ' a.pagination-link')) {
|
||||
event.preventDefault();
|
||||
this.loadPage(link.href);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -42,56 +51,54 @@ export default class KimaiPaginatedBoxWidget {
|
||||
return new KimaiPaginatedBoxWidget(elementId);
|
||||
}
|
||||
|
||||
_showOverlay() {
|
||||
this.widget.append(this.overlay);
|
||||
}
|
||||
|
||||
_hideOverlay() {
|
||||
jQuery(this.overlay).remove();
|
||||
}
|
||||
|
||||
loadPage(url) {
|
||||
const self = this;
|
||||
const selector = this.selector;
|
||||
|
||||
self._showOverlay();
|
||||
|
||||
jQuery.ajax({
|
||||
url: url,
|
||||
data: {},
|
||||
success: function (response) {
|
||||
const html = jQuery(response);
|
||||
jQuery(selector + ' .box-tools').replaceWith(html.find('.box-tools'));
|
||||
jQuery(selector + ' .box-body').replaceWith(html.find('.box-body'));
|
||||
jQuery(selector + ' .box-title').replaceWith(html.find('.box-title'));
|
||||
if (jQuery(selector + ' .box-footer').length > 0) {
|
||||
jQuery(selector + ' .box-footer').replaceWith(html.find('.box-footer'));
|
||||
}
|
||||
jQuery(selector + ' .box-body [data-toggle="tooltip"]').tooltip();
|
||||
self.widget.removeData('error-retry');
|
||||
self._hideOverlay();
|
||||
},
|
||||
dataType: 'html',
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
if (jqXHR.status !== undefined && jqXHR.status === 500) {
|
||||
if (self.widget.data('error-retry') !== undefined) {
|
||||
// TODO show error message ?
|
||||
return;
|
||||
}
|
||||
const page = jQuery(selector + ' .box-tools').data('page');
|
||||
if (page > 1) {
|
||||
self.widget.data('error-retry', 1);
|
||||
var url = self._buildUrl(page - 1);
|
||||
self.loadPage(url);
|
||||
}
|
||||
}
|
||||
self._hideOverlay();
|
||||
// this event will render a spinning loader
|
||||
document.dispatchEvent(new CustomEvent('kimai.reloadContent', {detail: this.selector}));
|
||||
|
||||
// and this event will hide it afterwards
|
||||
const hideOverlay = () => {
|
||||
document.dispatchEvent(new Event('kimai.reloadedContent'));
|
||||
};
|
||||
|
||||
window.kimai.getPlugin('fetch').fetch(url)
|
||||
.then(response => {
|
||||
response.text().then((text) => {
|
||||
const temp = document.createElement('div');
|
||||
temp.innerHTML = text;
|
||||
// previously the parts .card-header .card-body .card-title .card-footer were replaced
|
||||
// but the layout allows eg. ".list-group .list-group-flush" instead of .card-body
|
||||
// so we directly replace the entire HTML
|
||||
// the HTML needs to be parsed for script tags, which can be included (e.g. paginated chart widget)
|
||||
document.querySelector(selector).replaceWith(this._makeScriptExecutable(temp.firstElementChild));
|
||||
KimaiContextMenu.createForDataTable(selector + ' table.dataTable');
|
||||
hideOverlay();
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
// this is not yet a plugin, so the alert is not available here
|
||||
window.kimai.getPlugin('alert').error('Failed loading selected page');
|
||||
hideOverlay();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Element|ChildNode} node
|
||||
* @returns {Element}
|
||||
* @private
|
||||
*/
|
||||
_makeScriptExecutable(node) {
|
||||
if (node.tagName !== undefined && node.tagName === 'SCRIPT') {
|
||||
const script = document.createElement('script');
|
||||
script.text = node.innerHTML;
|
||||
node.parentNode.replaceChild(script, node);
|
||||
} else {
|
||||
for (const child of node.childNodes) {
|
||||
this._makeScriptExecutable(child);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
_buildUrl(page) {
|
||||
return this.href.replace('1', page);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,21 +9,14 @@
|
||||
* [KIMAI] KimaiReloadPageWidget: a simple helper to reload the page on events
|
||||
*/
|
||||
|
||||
import jQuery from "jquery";
|
||||
|
||||
export default class KimaiReloadPageWidget {
|
||||
|
||||
constructor(events, fullReload) {
|
||||
this.overlay = jQuery('<div class="overlay-wrapper"><div class="overlay"><div class="fas fa-sync fa-spin"></div></div></div>');
|
||||
this.widget = jQuery('div.content-wrapper');
|
||||
|
||||
const self = this;
|
||||
|
||||
const reloadPage = function (event) {
|
||||
const reloadPage = () => {
|
||||
if (fullReload) {
|
||||
document.location.reload(true);
|
||||
document.location.reload();
|
||||
} else {
|
||||
self.loadPage(document.location);
|
||||
this._loadPage(document.location);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -40,34 +33,31 @@ export default class KimaiReloadPageWidget {
|
||||
}
|
||||
|
||||
_showOverlay() {
|
||||
this.widget.append(this.overlay);
|
||||
document.dispatchEvent(new CustomEvent('kimai.reloadContent', {detail: 'div.page-wrapper'}));
|
||||
}
|
||||
|
||||
_hideOverlay() {
|
||||
jQuery(this.overlay).remove();
|
||||
}
|
||||
|
||||
loadPage(url) {
|
||||
const self = this;
|
||||
|
||||
self._showOverlay();
|
||||
|
||||
jQuery.ajax({
|
||||
url: url,
|
||||
data: {},
|
||||
success: function (response) {
|
||||
jQuery('section.content').replaceWith(
|
||||
jQuery(response).find('section.content')
|
||||
);
|
||||
document.dispatchEvent(new Event('kimai.reloadPage'));
|
||||
self._hideOverlay();
|
||||
},
|
||||
dataType: 'html',
|
||||
error: function(jqXHR, textStatus, errorThrown) {
|
||||
self._hideOverlay();
|
||||
_hideOverlay() {
|
||||
document.dispatchEvent(new Event('kimai.reloadedContent'));
|
||||
}
|
||||
|
||||
_loadPage(url) {
|
||||
this._showOverlay();
|
||||
|
||||
window.kimai.getPlugin('fetch').fetch(url)
|
||||
.then(response => {
|
||||
response.text().then((text) => {
|
||||
const temp = document.createElement('div');
|
||||
temp.innerHTML = text;
|
||||
const newContent = temp.querySelector('section.content');
|
||||
document.querySelector('section.content').replaceWith(newContent);
|
||||
document.dispatchEvent(new Event('kimai.reloadPage'));
|
||||
this._hideOverlay();
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
this._hideOverlay();
|
||||
document.location = url;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user