Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions requests-http/db.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"cursos": [
{
"nome": "Java",
"id": 2
"id": 2,
"nome": "Java"
},
{
"nome": "VB6",
Expand All @@ -12,10 +12,6 @@
"nome": "ADVPL",
"id": 4
},
{
"nome": "PORTINARI",
"id": 5
},
{
"nome": "karajo",
"id": 7
Expand All @@ -36,10 +32,6 @@
"nome": "night",
"id": 13
},
{
"nome": "gregorian",
"id": 14
},
{
"nome": "teste",
"id": 15
Expand Down Expand Up @@ -73,8 +65,8 @@
"id": 22
},
{
"nome": "la la la la la ",
"id": 23
"id": 23,
"nome": "dddddddddd"
},
{
"nome": "jfhfoli",
Expand All @@ -84,10 +76,6 @@
"nome": "Eduar",
"id": 25
},
{
"nome": "dddd",
"id": 26
},
{
"nome": "ffffff",
"id": 27
Expand Down Expand Up @@ -120,10 +108,6 @@
"nome": "ddd",
"id": 34
},
{
"nome": ".ljsahgdl",
"id": 35
},
{
"nome": "alo alo alo ",
"id": 36
Expand Down Expand Up @@ -162,7 +146,7 @@
},
{
"id": 45,
"nome": "ssssssssssssssssssssssf"
"nome": "aloha"
},
{
"id": 46,
Expand Down
123 changes: 69 additions & 54 deletions requests-http/src/app/cursos/cursos-lista/cursos-lista.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CursosService } from './../cursos.service';
import { Component, OnInit, ViewChild } from '@angular/core';
import { Curso } from '../curso';
import { Observable, empty, EMPTY, Subject } from 'rxjs';
import { catchError, switchMap } from 'rxjs/operators';
import { catchError, switchMap, take } from 'rxjs/operators';

@Component({
selector: 'app-cursos-lista',
Expand All @@ -14,17 +14,17 @@ import { catchError, switchMap } from 'rxjs/operators';
})
export class CursosListaComponent implements OnInit {

// cursos: Curso[];
// bsmodalRef: BsModalRef;
// cursos: Curso[];
// bsmodalRef: BsModalRef;

deletebsmodalRef: BsModalRef;
@ViewChild('deleteModal') deleteModal;

cursos$: Observable<Curso[]>;
error$ = new Subject <boolean>();
config = {
backdrop: true,
ignoreBackdropClick: true
cursos$: Observable<Curso[]>;
error$ = new Subject<boolean>();
config = {
backdrop: true,
ignoreBackdropClick: true
};

selectedCourse: Curso;
Expand All @@ -34,53 +34,53 @@ export class CursosListaComponent implements OnInit {
private alertModalService: AlertModalService,
private router: Router,
private route: ActivatedRoute
) { }
) { }

ngOnInit() {
// this.cursoService.list()
// .subscribe(resultado => this.cursos = resultado);
this.onRefresh();
// this.cursoService.list()
// .subscribe(resultado => this.cursos = resultado);
this.onRefresh();
}

onRefresh() {
this.cursos$ = this.cursoService.list()
.pipe(
catchError(error => {
console.error(error);
this.error$.next(true);
this.handleError();
return EMPTY;
})
);
// example how to use with subscrible
/*/this.cursoService.list().subscribe(
dados => {
console.log(dados) ; // Sucesso
},
error => {
console.error(); // Erro
},
() => {
console.log('Observable completo'); // Observable completo
});/*/
// example how to use with subscrible and pipe
/*/ this.cursoService.list()
.pipe(
map()
tap()
switchMap()
catchError(error => EMPTY)
)
.subscribe(
dados => {
console.log(dados) ; // Sucesso
},
error => {
console.error(); // Erro
},
() => {
console.log('Observable completo'); // Observable completo
});/*/
.pipe(
catchError(error => {
console.error(error);
this.error$.next(true);
this.handleError();
return EMPTY;
})
);
// example how to use with subscrible
/*/this.cursoService.list().subscribe(
dados => {
console.log(dados) ; // Sucesso
},
error => {
console.error(); // Erro
},
() => {
console.log('Observable completo'); // Observable completo
});/*/
// example how to use with subscrible and pipe
/*/ this.cursoService.list()
.pipe(
map()
tap()
switchMap()
catchError(error => EMPTY)
)
.subscribe(
dados => {
console.log(dados) ; // Sucesso
},
error => {
console.error(); // Erro
},
() => {
console.log('Observable completo'); // Observable completo
});/*/


}
Expand All @@ -97,18 +97,33 @@ export class CursosListaComponent implements OnInit {
}

viewReg(id) {
this.router.navigate(['view', id], {relativeTo: this.route});
this.router.navigate(['view', id], { relativeTo: this.route });
}

onEdit(id) {
this.router.navigate(['editar', id], {relativeTo: this.route});
this.router.navigate(['editar', id], { relativeTo: this.route });


}

onDelete(curso) {
this.selectedCourse = curso;
this.deletebsmodalRef = this.modalService.show(this.deleteModal, {class: 'modal-sm'});
// this.deletebsmodalRef = this.modalService.show(this.deleteModal, {class: 'modal-sm'});
const result$ = this.alertModalService.showConfirm();
result$.asObservable().
pipe(
take(1),
switchMap(result => result ? this.cursoService.praVala(curso.id) : EMPTY)
).subscribe(success => {
this.onRefresh();
this.alertModalService.showAllertSuccess('Removido com sucesso');

},
erro => {
this.alertModalService.showAllertDanger('Erro ao remover curso tente novamente mais tarde');

}
);
}

onConfirmDelete() {
Expand All @@ -119,13 +134,13 @@ export class CursosListaComponent implements OnInit {
this.alertModalService.showAllertSuccess('Removido com sucesso');

},
erro => {
erro => {
this.alertModalService.showAllertDanger('Erro ao remover curso tente novamente mais tarde');

}

);
// this.deletebsmodalRef = this.modalService.show(this.deleteModal, {class: 'modal-sm'});
// this.deletebsmodalRef = this.modalService.show(this.deleteModal, {class: 'modal-sm'});
}

onDeclineDelete() {
Expand Down
24 changes: 24 additions & 0 deletions requests-http/src/app/shared/alert-modal.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ConfirmModalComponent } from './confirm-modal/confirm-modal.component';
import { AlertModalComponent } from './alert-modal/alert-modal.component';
import { BsModalService, BsModalRef } from 'ngx-bootstrap/modal';
import { Injectable } from '@angular/core';
Expand Down Expand Up @@ -48,6 +49,29 @@ export class AlertModalService {
setTimeout(() => bsmodalRef.hide(), dissmisstimeOut);
}
}
showConfirm( message = 'Posso perguntar',
backdrop = true,
ignoreBackdropClick = true,
img = this.defalutcErrorImg,
title = 'Esta certo Disso ?',
oktxt= 'Sim Silvio',
canctxt= 'Vou pular silvio Silvio',
) {
const bsmodalRef: BsModalRef = this.modalService.show(ConfirmModalComponent);
const oModal = <ConfirmModalComponent>bsmodalRef.content;
oModal.title = title;
oModal.msg = message;
oModal.btnOK = oktxt;
oModal.btnCanc = canctxt;
// bsmodalRef.content.title = title;
// bsmodalRef.content.msg = message;
// bsmodalRef.content.btnOK = oktxt;
// bsmodalRef.content.btnCanc = canctxt;

return oModal.confirmResult ;


}

showAllertDanger(
message: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{{ title }}</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>{{ msg }}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" (click)="onClose()" >{{ btnCanc }}</button>
<button type="button" class="btn btn-primary" (click)="onConfirm()">{{ btnOK }}</button>
</div>
</div>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Subject } from 'rxjs';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { Component, OnInit, Input } from '@angular/core';

@Component({
selector: 'app-confirm-modal',
templateUrl: './confirm-modal.component.html',
styleUrls: ['./confirm-modal.component.scss']
})
export class ConfirmModalComponent implements OnInit {

@Input() title: string;
@Input() msg: string;
@Input() btnOK = 'OK';
@Input() btnCanc = 'Cancel';

confirmResult: Subject<boolean>;


constructor(public bsModalRef: BsModalRef) { }

ngOnInit() {
this.confirmResult = new Subject();
}

onClose() {
this.confimrAndClose(false);
}

onConfirm() {
this.confimrAndClose(true);
}

private confimrAndClose(value: boolean){
this.confirmResult.next(value);
this.bsModalRef.hide();

}

}
5 changes: 3 additions & 2 deletions requests-http/src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import { CommonModule } from '@angular/common';
import { SharedRoutingModule } from './shared-routing.module';
import { AlertModalComponent } from './alert-modal/alert-modal.component';
import { PageErrorComponent } from './page-error/page-error.component';
import { ConfirmModalComponent } from './confirm-modal/confirm-modal.component';

@NgModule({
imports: [
CommonModule,
SharedRoutingModule
],
declarations: [AlertModalComponent, PageErrorComponent],
declarations: [AlertModalComponent, PageErrorComponent, ConfirmModalComponent],
exports: [AlertModalComponent, PageErrorComponent],
entryComponents: [AlertModalComponent]
entryComponents: [AlertModalComponent, ConfirmModalComponent]

})
export class SharedModule { }