Skip to content

Commit

Permalink
Merge pull request #327 from SharebookBR/develop
Browse files Browse the repository at this point in the history
Promote develop to master
  • Loading branch information
raffacabofrio authored May 5, 2021
2 parents de12565 + adf41c8 commit c2db8d1
Show file tree
Hide file tree
Showing 27 changed files with 828 additions and 209 deletions.
53 changes: 31 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,16 @@ import { RequestComponent } from './components/book/request/request.component';
import { TrackingComponent } from './components/book/tracking/tracking.component';
import { FacilitatorNotesComponent } from './components/book/facilitator-notes/facilitator-notes.component';
import { MainUsersComponent } from './components/book/main-users/main-users.component';
import { WinnerUsersComponent } from './components/book/winner-users/winner-users.component';
import { ConfirmationDialogComponent } from './core/directives/confirmation-dialog/confirmation-dialog.component';
import { ConfirmationDialogService } from './core/services/confirmation-dialog/confirmation-dialog.service';

import { RouteReuseStrategy } from '@angular/router';
import { CustomReuseStrategy } from './core/router/custom-reuse-strategy';
import { InputSearchModule } from './components/input-search/input-search.module';
import { DonatePageComponent } from './components/book/donate-page/donate-page.component';
import { TermsOfUseComponent } from './components/terms-of-use/terms-of-use.component';
import { DonorModalComponent } from './components/book/donor-modal/donor-modal.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -100,8 +103,11 @@ import { DonatePageComponent } from './components/book/donate-page/donate-page.c
TrackingComponent,
FacilitatorNotesComponent,
MainUsersComponent,
WinnerUsersComponent,
PrivacyPolicyComponent,
CookieConsentComponent,
TermsOfUseComponent,
DonorModalComponent,
],
imports: [
BrowserModule,
Expand Down Expand Up @@ -152,9 +158,11 @@ import { DonatePageComponent } from './components/book/donate-page/donate-page.c
TrackingComponent,
FacilitatorNotesComponent,
MainUsersComponent,
WinnerUsersComponent,
DonorModalComponent
],
bootstrap: [AppComponent],
})
export class AppModule {
constructor(protected _googleAnalyticsService: GoogleAnalyticsService) {} // <-- We inject the service here to keep it alive whole time
constructor(protected _googleAnalyticsService: GoogleAnalyticsService) { } // <-- We inject the service here to keep it alive whole time
}
31 changes: 30 additions & 1 deletion src/app/components/book/donations/donations.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { BookService } from '../../../core/services/book/book.service';
import { BookDonationStatus } from '../../../core/models/BookDonationStatus';
import { TrackingComponent } from '../tracking/tracking.component';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { DonateComponent } from '../donate/donate.component';
import { ConfirmationDialogService } from 'src/app/core/services/confirmation-dialog/confirmation-dialog.service';
import { ToastrService } from 'ngx-toastr';
import { getStatusDescription } from 'src/app/core/utils/getStatusDescription';
import { WinnerUsersComponent } from '../winner-users/winner-users.component';

@Component({
selector: 'app-donations',
Expand All @@ -23,6 +23,7 @@ export class DonationsComponent implements OnInit, OnDestroy {
donatedBooks = new Array<any>();
tableSettings: any;
isLoading: boolean;
statusBtnWinner: boolean;

private _destroySubscribes$ = new Subject<void>();

Expand Down Expand Up @@ -61,6 +62,10 @@ export class DonationsComponent implements OnInit, OnDestroy {
'<span class="btn btn-danger btn-sm ml-1 mb-1" data-toggle="tooltip" title="Cancelar Doação">' +
' <i class="fa fa-trash"></i> </span>';

const btnShowWinnerInfo =
'<span class="btn btn-light btn-sm ml-1 mb-1" data-toggle="tooltip" title="Ver ganhador">' +
' <i class="fa fa-user"></i> </span>';

this.tableSettings = {
columns: {
title: {
Expand Down Expand Up @@ -129,6 +134,10 @@ export class DonationsComponent implements OnInit, OnDestroy {
name: 'CancelDonation',
title: btnCancelDonation,
},
{
name: 'ShowWinnerInfo',
title: btnShowWinnerInfo,
},
],
position: 'right', // left|right
},
Expand Down Expand Up @@ -283,6 +292,26 @@ export class DonationsComponent implements OnInit, OnDestroy {

break;
}
case 'ShowWinnerInfo': {

if (event.data.status !== BookDonationStatus.WAITING_SEND &&
event.data.status !== BookDonationStatus.SENT &&
event.data.status !== BookDonationStatus.RECEIVED) {
alert(
`Você ainda não escolheu o ganhador.`
);
return;
}
const modalRef = this._modalService.open(WinnerUsersComponent, {
backdropClass: 'light-blue-backdrop',
centered: true,
});

modalRef.componentInstance.bookId = event.data.id;
modalRef.componentInstance.bookTitle = event.data.title;
break;
}

}
}

Expand Down
3 changes: 3 additions & 0 deletions src/app/components/book/donor-modal/donor-modal.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
section {
text-align: center;
}
34 changes: 34 additions & 0 deletions src/app/components/book/donor-modal/donor-modal.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div class="modal-header">
<h4 class="modal-title">Informações do doador do livro: <br> {{ bookTitle }}</h4>

<button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')">
<span aria-hidden="true">&times;</span>
</button>
</div>

<div class="modal-body">

<section class="card-body">

<div [hidden]="!loading">
<div class="text-center"><em class="fa fa-spinner fa-spin"></em> Aguarde...</div>
</div>

<ng-container *ngIf="messageBody !== ''">
<h5 class="card-title">{{messageBody}}</h5>
</ng-container>

<ng-container *ngIf="(userInfo$ | async)?.donor as donor">
<h5 class="card-title">Doador</h5>
<p class="card-text">Nome: {{ donor.name }}</p>
<p class="card-text">E-mail: {{ donor.email }}</p>
<p class="card-text">LinkedIn: {{ donor.linkedin }}</p>
<p class="card-text">Telefone: {{ donor.phone }}</p>
</ng-container>

</section>
</div>

<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" (click)="activeModal.dismiss('Cross click')">Cancelar</button>
</div>
25 changes: 25 additions & 0 deletions src/app/components/book/donor-modal/donor-modal.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { DonorModalComponent } from './donor-modal.component';

describe('DonorModalComponent', () => {
let component: DonorModalComponent;
let fixture: ComponentFixture<DonorModalComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DonorModalComponent ]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(DonorModalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
44 changes: 44 additions & 0 deletions src/app/components/book/donor-modal/donor-modal.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Component, Input, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';

import { BookService } from 'src/app/core/services/book/book.service';
import { UserInfoBook } from 'src/app/core/models/UserInfoBook';

@Component({
selector: 'app-donor-modal',
templateUrl: './donor-modal.component.html',
styleUrls: ['./donor-modal.component.css']
})
export class DonorModalComponent implements OnInit {
@Input() bookId;
@Input() bookTitle;
@Input() messageBody;
loading: boolean;

userInfo$: Observable<UserInfoBook>;

constructor(public activeModal: NgbActiveModal,
private readonly _bookService: BookService) { }

ngOnInit() {
this.loading = true;
if (this.messageBody === '') {
this.getDonor();
} else {
this.loading = false;
}
}

private getDonor() {

this.userInfo$ = this._bookService.getMainUsers(this.bookId).pipe(
map(userInfo => {
this.loading = false;
return userInfo;
})
);
}
}
33 changes: 17 additions & 16 deletions src/app/components/book/main-users/main-users.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,27 @@ export class MainUsersComponent implements OnInit, OnDestroy {

private _destroySubscribes$ = new Subject<void>();

constructor(public activeModal: NgbActiveModal, private _scBook: BookService) {}
constructor(public activeModal: NgbActiveModal, private _scBook: BookService) { }

ngOnInit() {
this.isLoading = true;
this._scBook.getMainUsers(this.bookId)
.pipe(
takeUntil(this._destroySubscribes$)
)
.subscribe(
resp => {
this.isLoading = false;

this.mainUsers[0] = !!resp.donor ? resp.donor : '';
this.mainUsers[1] = !!resp.facilitator ? resp.facilitator : '';
this.mainUsers[2] = !!resp.winner ? resp.winner : '';
},
error => {
this.isLoading = false;
}
);
.pipe(
takeUntil(this._destroySubscribes$)
)
.subscribe(
resp => {
this.isLoading = false;
const emptyUserInfo = new UserInfo();
this.mainUsers[0] = !!resp.donor ? resp.donor : emptyUserInfo;
this.mainUsers[1] = !!resp.facilitator ? resp.facilitator : emptyUserInfo;
this.mainUsers[2] = !!resp.winner ? resp.winner : emptyUserInfo;

},
error => {
this.isLoading = false;
}
);
}

ngOnDestroy() {
Expand Down
11 changes: 7 additions & 4 deletions src/app/components/book/requesteds/requesteds.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<div class="container">
<h1 class="text-center display-4">Meus Pedidos</h1>
<div [hidden]="!isLoading">

<ng-template #loading>
<i class="fa fa-spinner fa-spin" style="position: absolute; left: 50%;"></i>
</div>
<div class="container mt-5 table-responsive" [hidden]="isLoading">
<ng2-smart-table [settings]="tableSettings" [source]="requestedBooks"></ng2-smart-table>
</ng-template>

<div class="container mt-5 table-responsive" *ngIf="(requestedBooks$ | async)?.items as items; else loading">
<ng2-smart-table [settings]="tableSettings" [source]="items" (custom)="onCustomActionColum($event)">
</ng2-smart-table>
<p class="mt-2">
<a routerLink="/panel" class="btn btn-link">Voltar</a>
</p>
</div>

</div>
Loading

0 comments on commit c2db8d1

Please sign in to comment.