SKE-69 SKE-70 home component

This commit is contained in:
Przemysław Stawujak 2019-01-12 18:29:39 +01:00
parent 77b0c99296
commit 7cf0245b43
11 changed files with 211 additions and 10 deletions

View File

@ -25,8 +25,8 @@ import { CompetitionCreateComponent } from '@app/competition-create/competition-
{ path: 'tenants', component: TenantsComponent, data: { permission: 'Pages.Tenants' }, canActivate: [AppRouteGuard] },
{ path: 'about', component: AboutComponent },
{ path: 'categories-list', component: CategoriesListComponent, canActivate: [AppRouteGuard] },
{ path: 'categories-list/:id', component: CompetitionsListComponent, canActivate: [AppRouteGuard] },
{ path: 'categories-list/:id/competitions/:id', component: CompetitionDetailComponent, canActivate: [AppRouteGuard] },
{ path: 'categories-list/:categoryId', component: CompetitionsListComponent, canActivate: [AppRouteGuard] },
{ path: 'categories-list/:categoryId/competitions/:competitionId', component: CompetitionDetailComponent, canActivate: [AppRouteGuard] },
{ path: 'competition-create', component: CompetitionCreateComponent, data: { permission: 'Pages.Create.Competition' }, canActivate: [AppRouteGuard] },
]
}

View File

@ -53,7 +53,7 @@ export class CompetitionDetailComponent extends AppComponentBase implements OnIn
this.routeSubscription = this.route.params
.subscribe(params => {
this.competitionId = +params['id'];
this.competitionId = +params['competitionId'];
this.getCompetition();
})

View File

@ -59,7 +59,7 @@ export class CompetitionsListComponent extends AppComponentBase implements OnIni
private getCompetitions(): void {
this.paramSubscription = this.route.params
.pipe(mergeMap(params => {
this.categoryId = +params['id'];
this.categoryId = +params['categoryId'];
this.setBusy(this.competitionsListAreaId);
const competitionListStream = this._competitionCategoryService
.getAllCompetitionsForCategory(this.categoryId)
@ -72,7 +72,6 @@ export class CompetitionsListComponent extends AppComponentBase implements OnIni
public goToDetail(competition: CompetitionDto): void {
const route: string = this.router.url + `/competitions/${competition.id}`;
//const route: string = `app/competitions/${competition.id}`;
this.router.navigate([route]);
}

View File

@ -1,3 +1,42 @@
h2 {
color: #771111;
}
.flex-container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
.flex-item {
background-color: #DED4F4;
width: 450px;
margin: 10px;
text-align: center;
font-size: 20px;
border-radius: 5px;
border: 1px solid gray;
border-left: 10px #739CB9 solid;
color: darkblue;
text-shadow: 0px 0px 1px #ab93ab;
font-weight: bold;
cursor: pointer;
}
.flex-item:hover {
box-shadow: 0px 0px 10px #2196F3;
}
.organizer {
font-size: 14px;
color: #f44336;
font-weight: bold;
margin-bottom: 6px;
}
.bottom-flex {
color: white;
background-color: #2196F3;
}

View File

@ -4,4 +4,19 @@
<h2 class="text-center font-weight-normal">MOJE KONKURSY</h2>
</div>
<div class="flex-container">
<div class="flex-item" (click)="goToDetail(competition)" *ngFor="let competition of myCompetitionsList">
<p><u>{{ competition.name }}</u></p>
<div class="organizer">Organizowany przez: {{ competition.creatorName }}</div>
<div class="bottom-flex">
<p>Czas trwania: {{ competition.startDate | date:"dd/MM/yyyy" }} - {{ competition.endDate | date:"dd/MM/yyyy" }}</p>
<p>Przedział klasowy: {{ competition.minClass }}-{{ competition.maxClass }}</p>
</div>
</div>
</div>
<div *ngIf="myCompetitionsList?.length === 0">
Brak konkursów
</div>
</div>

View File

@ -1,21 +1,55 @@
import { Component, Injector, OnInit } from '@angular/core';
import { Component, Injector, OnInit, OnDestroy } from '@angular/core';
import { AppComponentBase } from '@shared/app-component-base';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { CompetitionServiceProxy, CompetitionDto } from '@shared/service-proxies/service-proxies';
import { List } from 'lodash';
import { Subscription } from 'rxjs/Rx';
import { finalize } from 'rxjs/operators';
import { Router } from '@angular/router';
@Component({
templateUrl: './home.component.html',
styleUrls: ['./home.component.css'],
animations: [appModuleAnimation()]
})
export class HomeComponent extends AppComponentBase implements OnInit {
export class HomeComponent extends AppComponentBase implements OnInit, OnDestroy {
public myCompetitionsList: List<CompetitionDto> = [];
public homeAreaId: string = 'home-area';
private myCompetitionsListSubscription: Subscription;
constructor(
injector: Injector
injector: Injector,
private _competitionService: CompetitionServiceProxy,
private router: Router
) {
super(injector);
}
public ngOnInit(): void {
this.getCompetitionsForUser();
}
public ngOnDestroy(): void {
if (this.myCompetitionsListSubscription) {
this.myCompetitionsListSubscription.unsubscribe();
}
}
private getCompetitionsForUser(): void {
this.setBusy(this.homeAreaId);
this.myCompetitionsListSubscription = this._competitionService.getAllCompetitionsForUser()
.pipe(finalize(() => { this.clearBusy(this.homeAreaId); }))
.subscribe((result: List<CompetitionDto>) => {
this.myCompetitionsList = result;
});
}
public goToDetail(competition: CompetitionDto): void {
const route: string = `app/categories-list/${competition.categoryId}/competitions/${competition.id}`;
this.router.navigate([route]);
}
}

View File

@ -274,6 +274,62 @@ export class CompetitionServiceProxy {
return _observableOf<number>(<any>null);
}
/**
* @return Success
*/
getAllCompetitionsForUser(): Observable<CompetitionDto[]> {
let url_ = this.baseUrl + "/api/services/app/Competition/GetAllCompetitionsForUser";
url_ = url_.replace(/[?&]$/, "");
let options_ : any = {
observe: "response",
responseType: "blob",
headers: new HttpHeaders({
"Content-Type": "application/json",
"Accept": "application/json"
})
};
return this.http.request("get", url_, options_).pipe(_observableMergeMap((response_ : any) => {
return this.processGetAllCompetitionsForUser(response_);
})).pipe(_observableCatch((response_: any) => {
if (response_ instanceof HttpResponseBase) {
try {
return this.processGetAllCompetitionsForUser(<any>response_);
} catch (e) {
return <Observable<CompetitionDto[]>><any>_observableThrow(e);
}
} else
return <Observable<CompetitionDto[]>><any>_observableThrow(response_);
}));
}
protected processGetAllCompetitionsForUser(response: HttpResponseBase): Observable<CompetitionDto[]> {
const status = response.status;
const responseBlob =
response instanceof HttpResponse ? response.body :
(<any>response).error instanceof Blob ? (<any>response).error : undefined;
let _headers: any = {}; if (response.headers) { for (let key of response.headers.keys()) { _headers[key] = response.headers.get(key); }};
if (status === 200) {
return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => {
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
if (resultData200 && resultData200.constructor === Array) {
result200 = [];
for (let item of resultData200)
result200.push(CompetitionDto.fromJS(item));
}
return _observableOf(result200);
}));
} else if (status !== 200 && status !== 204) {
return blobToText(responseBlob).pipe(_observableMergeMap(_responseText => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}));
}
return _observableOf<CompetitionDto[]>(<any>null);
}
/**
* @competitionId (optional)
* @return Success
@ -2420,6 +2476,7 @@ export class CompetitionDto implements ICompetitionDto {
maxClass: number | undefined;
creationTime: moment.Moment | undefined;
creatorName: string | undefined;
categoryId: number | undefined;
questions: QuestionDto[] | undefined;
id: number | undefined;
@ -2443,6 +2500,7 @@ export class CompetitionDto implements ICompetitionDto {
this.maxClass = data["maxClass"];
this.creationTime = data["creationTime"] ? moment(data["creationTime"].toString()) : <any>undefined;
this.creatorName = data["creatorName"];
this.categoryId = data["categoryId"];
if (data["questions"] && data["questions"].constructor === Array) {
this.questions = [];
for (let item of data["questions"])
@ -2470,6 +2528,7 @@ export class CompetitionDto implements ICompetitionDto {
data["maxClass"] = this.maxClass;
data["creationTime"] = this.creationTime ? this.creationTime.toISOString() : <any>undefined;
data["creatorName"] = this.creatorName;
data["categoryId"] = this.categoryId;
if (this.questions && this.questions.constructor === Array) {
data["questions"] = [];
for (let item of this.questions)
@ -2497,6 +2556,7 @@ export interface ICompetitionDto {
maxClass: number | undefined;
creationTime: moment.Moment | undefined;
creatorName: string | undefined;
categoryId: number | undefined;
questions: QuestionDto[] | undefined;
id: number | undefined;
}

View File

@ -104,6 +104,40 @@ namespace SystemKonkursow.Competition.CompetitionCategory
return newCompetitionId;
}
[AbpAuthorize]
public async Task<List<CompetitionDto>> GetAllCompetitionsForUser()
{
var user = await GetCurrentUserAsync();
var isParticipant = await _userManager.IsParticipantUserAsync(user);
if (isParticipant)
{
var participantCompetitions = await _rankingPositionRepository.GetAll()
.Include(t => t.Competition).ThenInclude(x => x.Creator)
.Include(t => t.Competition).ThenInclude(x => x.CompetitionCategories)
.Where(t => t.UserId == user.Id).ToListAsync();
var mappedObjects = ObjectMapper.Map<List<CompetitionDto>>(participantCompetitions
.OrderBy(t => t.Competition.Name));
return mappedObjects;
}
else
{
var organizerCompetitions = await _competitionRepository.GetAll()
.Include(t => t.Creator)
.Include(t => t.CompetitionCategories)
.Where(t => t.CreatorUserId == user.Id).ToListAsync();
var mappedObjects = ObjectMapper.Map<List<CompetitionDto>>(organizerCompetitions
.OrderBy(t => t.Name));
return mappedObjects;
}
}
[AbpAuthorize]
public CompetitionDto GetCompetition(int competitionId)
{

View File

@ -1,4 +1,5 @@
using AutoMapper;
using System.Linq;
namespace SystemKonkursow.Competition.CompetitionCategory.Dto
{
@ -21,12 +22,27 @@ namespace SystemKonkursow.Competition.CompetitionCategory.Dto
CreateMap<CreateCompetitionDto, Domain.Competition>();
CreateMap<Domain.Competition, CompetitionDto>()
.ForMember(dest => dest.CreatorName, opt => opt.MapFrom(src => src.Creator.UserName));
.ForMember(dest => dest.CreatorName, opt => opt.MapFrom(src => src.Creator.UserName))
.ForMember(dest => dest.CategoryId, opt => opt.MapFrom(src => src.CompetitionCategories.FirstOrDefault().CategoryId));
CreateMap<CreateRankingPositionDto, Domain.RankingPosition>();
CreateMap<Domain.RankingPosition, RankingPositionDto>()
.ForMember(dest => dest.ParticipantName, opt => opt.MapFrom(src => src.User.UserName));
CreateMap<Domain.RankingPosition, CompetitionDto>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.CompetitionId))
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Competition.Name))
.ForMember(dest => dest.StartDate, opt => opt.MapFrom(src => src.Competition.StartDate))
.ForMember(dest => dest.EndDate, opt => opt.MapFrom(src => src.Competition.EndDate))
.ForMember(dest => dest.Description, opt => opt.MapFrom(src => src.Competition.Description))
.ForMember(dest => dest.Prize, opt => opt.MapFrom(src => src.Competition.Prize))
.ForMember(dest => dest.MinClass, opt => opt.MapFrom(src => src.Competition.MinClass))
.ForMember(dest => dest.MaxClass, opt => opt.MapFrom(src => src.Competition.MaxClass))
.ForMember(dest => dest.CreationTime, opt => opt.MapFrom(src => src.Competition.CreationTime))
.ForMember(dest => dest.CreatorName, opt => opt.MapFrom(src => src.Competition.Creator.UserName))
.ForMember(dest => dest.CategoryId, opt => opt.MapFrom(src => src.Competition.CompetitionCategories.FirstOrDefault().CategoryId));
}
}
}

View File

@ -24,6 +24,8 @@ namespace SystemKonkursow.Competition.CompetitionCategory.Dto
public string CreatorName { get; set; }
public int CategoryId { get; set; }
public List<QuestionDto> Questions { get; set; }
}
}

View File

@ -31,6 +31,8 @@ namespace SystemKonkursow.Domain
[ForeignKey(nameof(CreatorUserId))]
public virtual User Creator { get; set; }
public virtual List<CompetitionCategory> CompetitionCategories { get; set; }
public virtual List<Question> Questions { get; set; }
}
}