diff --git a/SystemKonkursow/4.2.1/angular/src/app/app-routing.module.ts b/SystemKonkursow/4.2.1/angular/src/app/app-routing.module.ts index 5f5b874..47fd4cc 100644 --- a/SystemKonkursow/4.2.1/angular/src/app/app-routing.module.ts +++ b/SystemKonkursow/4.2.1/angular/src/app/app-routing.module.ts @@ -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] }, ] } diff --git a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.ts b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.ts index 54db851..bb40ec1 100644 --- a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.ts +++ b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.ts @@ -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(); }) diff --git a/SystemKonkursow/4.2.1/angular/src/app/competitions-list/competitions-list.component.ts b/SystemKonkursow/4.2.1/angular/src/app/competitions-list/competitions-list.component.ts index 44a1e2c..b6cbe1e 100644 --- a/SystemKonkursow/4.2.1/angular/src/app/competitions-list/competitions-list.component.ts +++ b/SystemKonkursow/4.2.1/angular/src/app/competitions-list/competitions-list.component.ts @@ -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]); } diff --git a/SystemKonkursow/4.2.1/angular/src/app/home/home.component.css b/SystemKonkursow/4.2.1/angular/src/app/home/home.component.css index 24e5a3e..de16683 100644 --- a/SystemKonkursow/4.2.1/angular/src/app/home/home.component.css +++ b/SystemKonkursow/4.2.1/angular/src/app/home/home.component.css @@ -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; } \ No newline at end of file diff --git a/SystemKonkursow/4.2.1/angular/src/app/home/home.component.html b/SystemKonkursow/4.2.1/angular/src/app/home/home.component.html index 31edcd7..c3273ea 100644 --- a/SystemKonkursow/4.2.1/angular/src/app/home/home.component.html +++ b/SystemKonkursow/4.2.1/angular/src/app/home/home.component.html @@ -4,4 +4,19 @@

MOJE KONKURSY

+
+
+

{{ competition.name }}

+
Organizowany przez: {{ competition.creatorName }}
+ +
+

Czas trwania: {{ competition.startDate | date:"dd/MM/yyyy" }} - {{ competition.endDate | date:"dd/MM/yyyy" }}

+

Przedział klasowy: {{ competition.minClass }}-{{ competition.maxClass }}

+
+
+
+
+ Brak konkursów +
+ \ No newline at end of file diff --git a/SystemKonkursow/4.2.1/angular/src/app/home/home.component.ts b/SystemKonkursow/4.2.1/angular/src/app/home/home.component.ts index b1deef7..ee70539 100644 --- a/SystemKonkursow/4.2.1/angular/src/app/home/home.component.ts +++ b/SystemKonkursow/4.2.1/angular/src/app/home/home.component.ts @@ -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 = []; + 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) => { + this.myCompetitionsList = result; + }); + } + + public goToDetail(competition: CompetitionDto): void { + const route: string = `app/categories-list/${competition.categoryId}/competitions/${competition.id}`; + this.router.navigate([route]); + } + } diff --git a/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxies.ts b/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxies.ts index 6e35199..72cfe72 100644 --- a/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxies.ts +++ b/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxies.ts @@ -274,6 +274,62 @@ export class CompetitionServiceProxy { return _observableOf(null); } + /** + * @return Success + */ + getAllCompetitionsForUser(): Observable { + 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(response_); + } catch (e) { + return >_observableThrow(e); + } + } else + return >_observableThrow(response_); + })); + } + + protected processGetAllCompetitionsForUser(response: HttpResponseBase): Observable { + const status = response.status; + const responseBlob = + response instanceof HttpResponse ? response.body : + (response).error instanceof Blob ? (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(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()) : 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() : 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; } diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionAppService.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionAppService.cs index 59a484d..12e1110 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionAppService.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionAppService.cs @@ -104,6 +104,40 @@ namespace SystemKonkursow.Competition.CompetitionCategory return newCompetitionId; } + [AbpAuthorize] + public async Task> 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>(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>(organizerCompetitions + .OrderBy(t => t.Name)); + + return mappedObjects; + } + + } + [AbpAuthorize] public CompetitionDto GetCompetition(int competitionId) { diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionCategoryMapProfile.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionCategoryMapProfile.cs index 51d4687..d799fbe 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionCategoryMapProfile.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionCategoryMapProfile.cs @@ -1,4 +1,5 @@ using AutoMapper; +using System.Linq; namespace SystemKonkursow.Competition.CompetitionCategory.Dto { @@ -21,12 +22,27 @@ namespace SystemKonkursow.Competition.CompetitionCategory.Dto CreateMap(); CreateMap() - .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(); CreateMap() .ForMember(dest => dest.ParticipantName, opt => opt.MapFrom(src => src.User.UserName)); + + CreateMap() + .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)); + } } } diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionDto.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionDto.cs index a686bf3..383d27f 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionDto.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/CompetitionDto.cs @@ -24,6 +24,8 @@ namespace SystemKonkursow.Competition.CompetitionCategory.Dto public string CreatorName { get; set; } + public int CategoryId { get; set; } + public List Questions { get; set; } } } diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/Competition.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/Competition.cs index b2a75e4..a414bd4 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/Competition.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/Domain/Competition.cs @@ -31,6 +31,8 @@ namespace SystemKonkursow.Domain [ForeignKey(nameof(CreatorUserId))] public virtual User Creator { get; set; } + public virtual List CompetitionCategories { get; set; } + public virtual List Questions { get; set; } } }