Skip to content

Commit 265a14b

Browse files
Completo tabela + Inserir+Excluir
1 parent bd3a0f2 commit 265a14b

5 files changed

Lines changed: 46 additions & 6 deletions

File tree

Pratico/Backend/main.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ app.post("/demanda", (req,resp) =>{
4747
}else{
4848
resp.status(200);
4949

50-
resp.json(result.userId)
50+
resp.json(result.insertId)
5151

5252
}
5353
} );
@@ -81,6 +81,7 @@ app.put("/demanda/:demaId",(req,resp) => {
8181
var demaId= req.params.demaId
8282
// resp.send("Successful Operation")
8383
console.log("PUT - Demanda ID: "+demaId);
84+
console.log(demaId)
8485
var demanda = req.body;
8586

8687
connection.query("UPDATE demandas SET ? WHARE iddemandas=?",[demanda,demaId],(err,result) =>{
@@ -139,7 +140,7 @@ app.get("/gerirdemandas:gerirId", (req,resp) =>{
139140
app.path("/gerirdemandas:gerirId",(req,resp) =>{
140141
var gerirdemandas = req.params.gerirId
141142
resp.send("Successful Operation");
142-
console.log("PUT - Gerencair Demanda ID: "+gerirId);
143+
console.log("PATH - Gerencair Demanda ID: "+gerirId);
143144

144145
});
145146

Pratico/Frontend-Um-Problema/src/app/app.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import {MatFormFieldModule} from '@angular/material/form-field';
2626
DemandasComponent,
2727
UsuariosComponent,
2828
GestaoComponent,
29-
MngDemandaDialog
29+
MngDemandaDialog,
30+
3031
],
3132
imports: [
3233
BrowserModule,

Pratico/Frontend-Um-Problema/src/app/demandas.service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@ export class DemandasService {
1717
}
1818
getDemanda(demaId: number): Observable<Demanda>{
1919
console.log(demaId)
20-
return this.http.get<Demanda>("http://localhost:3000/demanda" + demaId);
20+
return this.http.get<Demanda>("http://localhost:3000/demanda/" + demaId);
2121
}
2222

2323
setDemanda(demanda: Demanda):Observable<any>{
2424
return this.http.post("http://localhost:3000/demanda",demanda);
2525
}
26+
27+
updateDemanda(demanda: Demanda):Observable<any>{
28+
return this.http.put("http://localhost:3000/demanda/"+ demanda.iddemandas,demanda);
29+
}
30+
deleteDemanda(demaId: number): Observable<any>{
31+
console.log(demaId)
32+
return this.http.delete("http://localhost:3000/demanda/" + demaId);
33+
}
2634
}

Pratico/Frontend-Um-Problema/src/app/demandas/demandas.component.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,14 @@ <h1>Demandas</h1>
4141
<th mat-header-cell *matHeaderCellDef>Status</th>
4242
<td mat-cell *matCellDef="let demandas">{{demandas.status}}</td>
4343
</ng-container>
44-
44+
45+
<ng-container matColumnDef="acoes">
46+
<th mat-header-cell *matHeaderCellDef></th>
47+
<td mat-cell *matCellDef="let demandas">
48+
<button mat-stroked-button class="float-right" color="primary" (click)="openEditDialog(demandas)" >Editar</button>
49+
<button mat-stroked-button class="float-right" color="primary" (click)="openExcluirDialog(demandas)" >Excluir</button>
50+
</td>
51+
</ng-container>
4552

4653

4754
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>

Pratico/Frontend-Um-Problema/src/app/demandas/demandas.component.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class Demanda{
2828
styleUrls: ['./demandas.component.css']
2929
})
3030
export class DemandasComponent implements OnInit {
31-
displayedColumns: string[]=['iddemandas','categorias','local','resumo','usuario_idusuario','status']
31+
displayedColumns: string[]=['iddemandas','categorias','local','resumo','usuario_idusuario','status','acoes']
3232
// dataSource:Demanda[];
3333
dataSource = new MatTableDataSource<Demanda>();
3434
constructor( private service:DemandasService, public dialog:MatDialog) { }
@@ -55,6 +55,29 @@ export class DemandasComponent implements OnInit {
5555

5656

5757
}
58+
59+
openEditDialog(demanda:Demanda): void{
60+
const dialogRef = this.dialog.open(MngDemandaDialog,{
61+
width:'750px',
62+
data:demanda
63+
});
64+
65+
dialogRef.afterClosed().subscribe(demanda =>{
66+
console.log(demanda);
67+
this.service.updateDemanda(demanda).subscribe(_ =>{
68+
this.dataSource.data = this.dataSource.data.map(oldDemanda =>{
69+
if(oldDemanda.iddemandas=demanda.iddemandas) return demanda;
70+
});
71+
});
72+
});
73+
}
74+
75+
openExcluirDialog(demanda:Demanda): void{
76+
this.service.deleteDemanda(demanda.iddemandas).subscribe(_ =>{
77+
this.dataSource.data = this.dataSource.data.filter(oldDemanda => oldDemanda.iddemandas != demanda.iddemandas)
78+
79+
});
80+
}
5881
}
5982

6083
@Component({

0 commit comments

Comments
 (0)