Repository navigation
Expand file tree
/
Copy pathindex.php
More file actions
585 lines (548 loc) · 16.1 KB
/
Copy pathindex.php
File metadata and controls
585 lines (548 loc) · 16.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
<?php include'auth.php';?>
<!doctype html><html><head>
<meta charset=utf8>
<title>ICRA Paret Verda</title>
<script src="lib/vue.global.prod.js"></script>
<style>
table{
border-collapse:collapse;
width:100%;
}
a[current=true]{
background:yellow;
}
textarea{
width:98%;
field-sizing:content;
}
button[pestanya_actual]{
border:1px solid #ccc;
border-bottom:none;
border-radius:5px 5px 0 0;
cursor:pointer;
padding:0.618em 1em;
color:#666;
}
button[pestanya_actual=true]{
color:black;
background:linear-gradient(#f8f8f8,white);
}
.warning{
color:red;
font-weight:bold;
}
input[type=number]{
text-align:right;
}
summary{
font-weight:bold;
cursor:pointer;
}
summary:hover{
text-decoration:underline;
}
</style>
</head><body>
<h1>icra: manteniment paret verda (en desenvolupament)</h1><hr>
<div id=app>
<div>
<button @click="nou()" :disabled="metadata_sistemes==null">nou</button> |
<button @click="guardar()" :disabled="sistema==null">guardar</button>
</div><hr>
<details v-if="metadata_sistemes" open>
<summary>
Sistemes guardats ({{metadata_sistemes.length}})
</summary>
<table border=1>
<tr v-for="sis in metadata_sistemes">
<td>
<button @click="carregar(sis.id)">CARREGAR</button> |
<b>{{sis.nom}}</b> |
<small>{{sis.lloc}}</small> |
(id:{{sis.id}})
<p>{{sis.descripcio}}</p>
<div style="text-align:right">
<button @click="esborrar(sis.id)">esborrar</button>
</div>
</td>
</tr>
</table>
</details>
<div v-if="sistema"><hr>
<!--selector pestanyes-->
<div
id=selector_pestanyes
style="
display:flex;
flex-wrap:wrap;
margin:5px 0;
"
>
<div v-for="p in pestanyes">
<button
@click="pestanya_actual=p"
:pestanya_actual="p==pestanya_actual"
>{{p.replaceAll("_"," ")}}</button>
</div>
</div>
<!--pestanya general-->
<div
v-if="pestanya_actual=='inici'"
style="
display:grid;
grid-template-columns:33% 33% 33%;
grid-gap:2px;
"
>
<div>
<h2>Sistema</h2>
<table border=1>
<tr>
<th>Nom sistema<td><input v-model.text="sistema.nom">
</tr>
<tr>
<th>Lloc<td><input v-model.text="sistema.lloc" style="width:90%">
</tr>
<tr>
<th>Descripció
<td>
<textarea v-model.text="sistema.descripcio"></textarea>
</td>
</tr>
<tr>
<th>Dimensionament</th>
<td>
<div v-for="_,i in sistema.dimensioning">
<div
style="
display:flex;
justify-content:space-between;
"
>
<input v-model="sistema.dimensioning[i]">
<button @click="sistema.dimensioning.splice(i,1)">eliminar característica</button>
</div>
</div>
<button @click="sistema.dimensioning.push('característica: valor unitat')">afegir característica</button>
</td>
</tr>
<tr>
<th>Aparells</th>
<td>
<div>
<div v-for="ap,i in sistema.aparells">
<div
style="
display:flex;
justify-content:space-between;
"
>
<div style="font-size:larger">
<a href="#" @click="aparell=ap;tasca=null" :current="aparell==ap">{{ap.nom}}</a>
</div>
<button @click="sistema.aparells.splice(i,1);tasca=null;aparell=null">eliminar aparell</button>
</div>
</div>
</div>
<button @click="afegir_aparell(sistema)">afegir aparell</button>
</td>
</tr>
</table>
</div>
<div v-if="aparell">
<h2>Aparell</h2>
<table border=1>
<tr>
<td colspan=2 style="text-align:right">
<button @click="tasca=null;aparell=null">X</button>
</td>
</tr>
<tr>
<th>Nom aparell<td><input v-model.text="aparell.nom">
</tr>
<tr>
<th>Dimensionament</th>
<td>
<div v-for="token,i in aparell.dimensioning">
<div
style="
display:flex;
justify-content:space-between;
"
>
<input v-model="aparell.dimensioning[i]">
<button @click="aparell.dimensioning.splice(i,1)">eliminar característica</button>
</div>
</div>
<button @click="aparell.dimensioning.push('característica: valor unitat')">afegir característica</button>
</td>
</tr>
<tr>
<th>Tasques</th>
<td>
<div>
<div v-for="ta,i in aparell.tasques">
<div style="
display:flex;
justify-content:space-between;
">
<div style="font-size:larger">
<a href="#" @click="tasca=ta;" :current="tasca==ta">{{ta.nom}}</a>
</div>
<button @click="aparell.tasques.splice(i,1)">eliminar tasca</button>
</div>
</div>
</div>
<button @click="afegir_tasca(aparell)">afegir tasca</button>
</td>
</tr>
</table>
</div>
<div v-if="aparell && tasca">
<h2>Tasca</h2>
<table border=1>
<tr>
<td colspan=2 style="text-align:right">
<button @click="tasca=null">X</button>
</td>
</tr>
<tr><th>Nom tasca<td><input v-model.text="tasca.nom"></tr>
<tr><th>Descripció<td><textarea v-model.text="tasca.descripcio"></textarea></tr>
<tr><th>Responsable<td><input v-model.text="tasca.responsable"></tr>
<tr>
<th>Material necessari</th>
<td>
<div>
<div v-for="ma,i in tasca.necessary_material">
<div
style="
display:flex;
justify-content:space-between;
"
>
<input v-model="tasca.necessary_material[i]">
<button @click="tasca.necessary_material.splice(i,1)">eliminar material</button>
</div>
</div>
</div>
<button @click="afegir_material(tasca)">afegir material</button>
</td>
</tr>
<tr>
<th>Accions</th>
<td>
<div>
<div v-for="ac,i in tasca.actions_to_do"
style="
display:flex;
justify-content:space-between;
"
>
<div style="display:flex">
<span>{{i+1}}:</span>
<textarea v-model="tasca.actions_to_do[i]"></textarea>
</div>
<button @click="tasca.actions_to_do.splice(i,1)">eliminar acció</button>
</div>
</div>
<button @click="tasca.actions_to_do.push('acció sense nom')">afegir acció</button>
</td>
</tr>
<tr><th>Cost (eur)<td><input type=number v-model.number="tasca.cost_eur" step="0.01"></tr>
<tr><th>Periodicitat (dies)<td><input type=number v-model.number="tasca.periodicitat_dies"></tr>
<tr>
<th>Historial</th>
<td>
<div>
<div v-for="hi,i in tasca.historial">
<input type=date v-model="tasca.historial[i]">
<button @click="tasca.historial.splice(i,1)">eliminar historial</button>
</div>
</div>
<button @click="tasca.historial.push(new Date().toISOString().substring(0,10))">afegir historial</button>
</td>
</tr>
<tbody v-if="tasca.periodicitat_dies">
<tr v-for="um in [get_manteniment(tasca)]">
<th>Següent manteniment</th>
<td>
<div v-if="um.next">
{{um.next}}
<span v-for="dies in [days_to(um.next)]">
(d'aquí {{dies}} dies)
<span v-if="dies<0" class=warning>
PASSAT
</span>
</span>
</div>
<div v-if="!um.next" class=warning>
Quant abans
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<!--pestanya resum_tasques_periodiques-->
<div v-if="pestanya_actual=='resum_tasques_periodiques'">
<h3>Resum tasques periòdiques</h3>
<div>
<table border=1 style="text-align:center">
<thead>
<tr>
<th>Aparell</th>
<th>Tasca</th>
<th>Periodicitat (dies)</th>
<th>Últim manteniment</th>
<th>Següent manteniment</th>
</tr>
</thead>
<tr v-for="row in taula_resum_tasques_periodiques">
<td>
<a href="#"
@click="
tasca=row.tasca;
aparell=row.aparell;
pestanya_actual='inici';
"
>
{{row.aparell.nom}}
</a>
</td>
<td>
<a href="#"
@click="
tasca=row.tasca;
aparell=row.aparell;
pestanya_actual='inici';
"
>
{{row.tasca.nom}}
</a>
</td>
<td>{{row.tasca.periodicitat_dies}}</td>
<td>
<div v-for="um in [get_manteniment(row.tasca)]">
<div v-if="um.ultim">
{{um.ultim}}
</div>
<div v-if="!um.ultim" class=warning>
Mai
</div>
</div>
</td>
<td>
<div v-for="um in [get_manteniment(row.tasca)]">
<div v-if="um.next">
{{um.next}}
<span v-for="dies in [days_to(um.next)]">
(d'aquí {{dies}} dies)
<span v-if="dies<0" class=warning>
PASSAT
</span>
</span>
</div>
<div v-if="!um.next" class=warning>
Quant abans
</div>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<script>//Estructura
class Sistema{
constructor(){
this.nom="Sistema sense nom";
this.lloc="carrer, ciutat";
this.descripcio="comentaris";
this.dimensioning=[
"caracteristíca: valor unitat",
];
this.aparells=[
new Aparell(),
];
}
}
class Aparell{
constructor(){
this.nom="Aparell sense nom";
this.dimensioning=[
"caracteristíca: valor unitat",
];
this.tasques=[
new Tasca(),
];
}
}
class Tasca{
constructor(){
this.nom="Tasca sense nom";
this.descripcio="Descripció de la tasca";
this.responsable="ICRA";
this.necessary_material=[
"material necessari sense nom",
];
this.actions_to_do=[
"acció sense nom",
];
this.cost_eur=0;
this.periodicitat_dies=0;
this.historial=[];
}
}
</script>
<script>//Vue
let app = Vue.createApp({
data(){return{
//tots els sistemes de la base de dades
metadata_sistemes:null,
//sistema carregat
id:0,
sistema:null,
aparell:null,
tasca:null,
//gui
pestanyes:[
"inici",
"resum_tasques_periodiques",
],
pestanya_actual:"inici",
}},
methods:{
days_to(time_str){
let dn = new Date(); //date now
let df = new Date(time_str); //date future
let dd = (df.getTime()-dn.getTime())/1000/86400; //dies
return Math.ceil(dd);
},
//class methods here for easy parsing from json
afegir_aparell(sistema){
let ap = new Aparell();
sistema.aparells.push(ap);
this.aparell = ap;
this.tasca = null;
},
afegir_tasca(aparell){
let ta = new Tasca();
aparell.tasques.push(ta);
this.tasca = ta;
},
afegir_material(tasca){
tasca.necessary_material.push("material necessari sense nom");
},
get_manteniment(tasca){
let ultim = false;
let next = false;
if(tasca.historial.length){
ultim = tasca.historial.at(-1);
let du = new Date(ultim);
let dn = new Date(du.getTime()+tasca.periodicitat_dies*86400e3);
next = dn.toISOString().substring(0,10);
}
return {ultim,next};
},
//file managing
nou(){
this.sistema = new Sistema();
this.aparell = null;
this.tasca = null;
//nova id
let id = Math.max(0,...this.metadata_sistemes.map(sis=>sis.id))+1;
this.id = id;
},
//carrega un sistema concret
carregar(id){
fetch(`db/get_sistema.php?id=${id}`).then(r=>r.json()).then(r=>{
r = r[0];
this.id=r.id;
this.sistema=JSON.parse(r.json);
this.aparell=null;
this.tasca=null;
if(this.sistema.aparells && this.sistema.aparells.length){
this.aparell = this.sistema.aparells[0];
if(this.aparell.tasques && this.aparell.tasques.length){
this.tasca=this.aparell.tasques[0];
}
}
});
},
//guardar sistema actual (o crear un de nou)
guardar(){
if(!confirm("guardar el sistema actual?")){
return;
}
let payload = JSON.stringify(this.sistema);
let body = new FormData();
body.append('id',this.id);
body.append('json',payload);
fetch(
'db/guardar.php',
{method:'POST',body},
).then(r=>
r.text()
).then(success=>{
console.log(success);
alert(success); //"OK"
if(success!="OK"){
throw(success);
}
fetch_metadata_sistemes();
}).catch(err=>{
alert(err);
});
},
//esborrar un sistema
esborrar(id){
if(!confirm(`Esborrar el sistema (id:${id}) (NO ES POT DESFER!)?`)){
return;
}
fetch(
`db/esborrar.php?id=${id}`,
).then(r=>
r.text()
).then(success=>{
console.log(success);
alert(success); //"OK"
if(success!="OK"){
throw(success);
}
fetch_metadata_sistemes();
}).catch(err=>{
alert(err);
});
},
},
computed:{
taula_resum_tasques_periodiques(){
let taula=[];
let aparells = this.sistema.aparells.forEach(aparell=>{
aparell.tasques.forEach(tasca=>{
if(tasca.periodicitat_dies){
let fila={
tasca,
aparell,
};
taula.push(fila);
}
});
});
return taula;
},
},
mounted(){
//this.carregar(0);
fetch_metadata_sistemes();
},
}).mount("#app");
//carrega un sistema concret
function fetch_metadata_sistemes(){
fetch(`db/metadata_sistemes.php`).then(r=>r.json()).then(arr=>{
app.metadata_sistemes = arr;
});
}
</script>