diff --git a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.css b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.css index dc5595a..e937065 100644 --- a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.css +++ b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.css @@ -12,9 +12,10 @@ hr { white-space: normal; word-wrap: break-word; font-size: 16px; + margin-bottom: 10px; } -.section-color{ +.section-color { color: #771111; } @@ -43,4 +44,8 @@ hr { background-color: #eee; margin: 4px; padding: 6px; +} + +.card { + margin-bottom: 0px; } \ No newline at end of file diff --git a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.html b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.html index bd01fdb..0ad50e1 100644 --- a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.html +++ b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.html @@ -7,6 +7,29 @@
Nagrody:
{{competition.prize}}
+
+
+

Ranking konkursu

+
+
+
+ + + + + + + + + + + + + +
UżytkownikPunkty
{{position.participantName}}{{position.points}}
+
+
+
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 6bb0100..61e971b 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 @@ -6,11 +6,13 @@ import { ActivatedRoute } from '@angular/router'; import { mergeMap } from 'rxjs/operators'; import { finalize } from 'rxjs/operators'; import { forkJoin } from 'rxjs'; +import { List } from 'lodash'; import { CompetitionServiceProxy, CompetitionDto, QuestionDto, QuestionOptionDto, - CreateRankingPositionDto } from '@shared/service-proxies/service-proxies'; + CreateRankingPositionDto, + RankingPositionDto } from '@shared/service-proxies/service-proxies'; @Component({ templateUrl: './competition-detail.component.html', @@ -25,6 +27,7 @@ export class CompetitionDetailComponent extends AppComponentBase implements OnIn public competitionId: number; public competition: CompetitionDto = null; + public ranking: List = []; public competitionDetailAreaId: string = 'competition-detail-area'; public canSolveCompetition: boolean = false; @@ -61,9 +64,10 @@ export class CompetitionDetailComponent extends AppComponentBase implements OnIn this.setBusy(this.competitionDetailAreaId); this.paramSubscription = forkJoin([this._competitionService.getCompetition(this.competitionId), - this._competitionService.canSolveCompetition(this.competitionId)]) + this._competitionService.canSolveCompetition(this.competitionId), + this._competitionService.getRanking(this.competitionId)]) .pipe(finalize(() => { this.clearBusy(this.competitionDetailAreaId); })) - .subscribe((data: [CompetitionDto, boolean]) => { + .subscribe((data: [CompetitionDto, boolean, List]) => { this.competition = data[0]; this.competition.questions.forEach((x) => this.shuffleOptions(x.questionOptions)); this.pager.count = this.competition.questions.length; @@ -71,6 +75,9 @@ export class CompetitionDetailComponent extends AppComponentBase implements OnIn this.canSolveCompetition = data[1]; console.log(this.canSolveCompetition); + + this.ranking = data[2]; + console.log(this.ranking); }); } @@ -135,10 +142,12 @@ export class CompetitionDetailComponent extends AppComponentBase implements OnIn this.solveSubscription = this._competitionService.solveCompetition(rankingPosition) .pipe(mergeMap((result: number) => { const solveCompetitionStream = this._competitionService.canSolveCompetition(this.competitionId); - return solveCompetitionStream.pipe(finalize(() => { this.clearBusy(this.competitionDetailAreaId); })); + const rankingStream = this._competitionService.getRanking(this.competitionId); + return forkJoin([solveCompetitionStream, rankingStream]).pipe(finalize(() => { this.clearBusy(this.competitionDetailAreaId); })); })) - .subscribe((data: boolean) => { - this.canSolveCompetition = data; + .subscribe((data: [boolean, List]) => { + this.canSolveCompetition = data[0]; + this.ranking = data[1]; }); this.mode = 'result'; 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 2b5d962..d6d5979 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 @@ -385,6 +385,65 @@ export class CompetitionServiceProxy { return _observableOf(null); } + /** + * @competitionId (optional) + * @return Success + */ + getRanking(competitionId: number | null | undefined): Observable { + let url_ = this.baseUrl + "/api/services/app/Competition/GetRanking?"; + if (competitionId !== undefined) + url_ += "competitionId=" + encodeURIComponent("" + competitionId) + "&"; + 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.processGetRanking(response_); + })).pipe(_observableCatch((response_: any) => { + if (response_ instanceof HttpResponseBase) { + try { + return this.processGetRanking(response_); + } catch (e) { + return >_observableThrow(e); + } + } else + return >_observableThrow(response_); + })); + } + + protected processGetRanking(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(RankingPositionDto.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 @@ -2611,6 +2670,61 @@ export interface ICreateRankingPositionDto { points: number | undefined; } +export class RankingPositionDto implements IRankingPositionDto { + participantName: number | undefined; + competitionId: number | undefined; + points: number | undefined; + id: number | undefined; + + constructor(data?: IRankingPositionDto) { + if (data) { + for (var property in data) { + if (data.hasOwnProperty(property)) + (this)[property] = (data)[property]; + } + } + } + + init(data?: any) { + if (data) { + this.participantName = data["participantName"]; + this.competitionId = data["competitionId"]; + this.points = data["points"]; + this.id = data["id"]; + } + } + + static fromJS(data: any): RankingPositionDto { + data = typeof data === 'object' ? data : {}; + let result = new RankingPositionDto(); + result.init(data); + return result; + } + + toJSON(data?: any) { + data = typeof data === 'object' ? data : {}; + data["participantName"] = this.participantName; + data["competitionId"] = this.competitionId; + data["points"] = this.points; + data["id"] = this.id; + return data; + } + + clone(): RankingPositionDto { + const json = this.toJSON(); + let result = new RankingPositionDto(); + result.init(json); + return result; + } +} + +export interface IRankingPositionDto { + participantName: number | undefined; + competitionId: number | undefined; + points: number | undefined; + id: number | undefined; +} + export class ChangeUiThemeInput implements IChangeUiThemeInput { theme: string; 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 7c85371..59a484d 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 @@ -140,6 +140,19 @@ namespace SystemKonkursow.Competition.CompetitionCategory return newRankingPositionId; } + [AbpAuthorize] + public List GetRanking(int competitionId) + { + var ranking = _rankingPositionRepository.GetAll() + .Include(t => t.User) + .Where(t => t.CompetitionId == competitionId).ToList(); + + var mappedObjects = ObjectMapper.Map>(ranking + .OrderByDescending(t => t.Points)); + + return mappedObjects; + } + [AbpAuthorize] public async Task CanSolveCompetition(int competitionId) { @@ -160,13 +173,18 @@ namespace SystemKonkursow.Competition.CompetitionCategory return false; } - var rankingPosition = await _rankingPositionRepository.GetAll().Where(t => t.UserId == user.Id).FirstOrDefaultAsync(); + var rankingPosition = await _rankingPositionRepository.GetAll().Where(t => t.UserId == user.Id && t.CompetitionId == competitionId).FirstOrDefaultAsync(); if (null != rankingPosition) { return false; } + if (!DateHelper.IsBetween(competition.StartDate, competition.EndDate)) + { + return false; + } + return true; } 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 bc7b293..51d4687 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 @@ -24,6 +24,9 @@ namespace SystemKonkursow.Competition.CompetitionCategory.Dto .ForMember(dest => dest.CreatorName, opt => opt.MapFrom(src => src.Creator.UserName)); CreateMap(); + + CreateMap() + .ForMember(dest => dest.ParticipantName, opt => opt.MapFrom(src => src.User.UserName)); } } } diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/RankingPositionDto.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/RankingPositionDto.cs new file mode 100644 index 0000000..2b8bcb6 --- /dev/null +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/RankingPositionDto.cs @@ -0,0 +1,13 @@ +using Abp.Application.Services.Dto; + +namespace SystemKonkursow.Competition.CompetitionCategory.Dto +{ + public class RankingPositionDto : EntityDto + { + public string ParticipantName { get; set; } + + public long CompetitionId { get; set; } + + public int Points { get; set; } + } +} diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/DateHelper.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/DateHelper.cs index 56e852a..00ec603 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/DateHelper.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Core/DateHelper.cs @@ -9,5 +9,13 @@ namespace SystemKonkursow TimeZoneInfo timeZone = TimeZoneInfo.Local; return TimeZoneInfo.ConvertTime(dateTime, timeZone); } + + public static bool IsBetween(DateTime leftDate, DateTime rightDate) + { + DateTime today = DateTime.Today; + + return (today >= leftDate && today <= rightDate); + } + } }