Skip to content

Commit

Permalink
Frontend_V2: Fetch private submissions after polling when checkbox ti…
Browse files Browse the repository at this point in the history
…cked (Cloud-CV#3557)

* fix leaderboard private checkbox

* remove console statements

* show checkbox only when public+private>0

Co-authored-by: Rishabh Jain <[email protected]>
  • Loading branch information
gautamjajoo and RishabhJain2018 authored Aug 17, 2021
1 parent 4f5d3b2 commit cb98fc4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,14 @@ <h5 class="fw-light">Leaderboard</h5>
<div *ngIf="leaderboard.length <= 0 && selectedPhaseSplit == null" class="fw-light result-wrn">
No phase selected.
</div>
<div *ngIf="leaderboard.length > 0 && selectedPhaseSplit" class="result-wrn content fw-light">
<mat-chip-list> <mat-chip>B</mat-chip> - Baseline submission </mat-chip-list>
<mat-chip-list class="leaderboard-description-span private">
<mat-chip>P</mat-chip> - Private submission
</mat-chip-list>
<div *ngIf="selectedPhaseSplit" class="result-wrn content fw-light">
<div *ngIf="leaderboard.length > 0">
<mat-chip-list>
<mat-chip>B</mat-chip> - Baseline submission
</mat-chip-list>
<mat-chip-list class="leaderboard-description-span private">
<mat-chip>P</mat-chip> - Private submission
</mat-chip-list>
<!-- <mat-chip-list class="pull-right" *ngIf="isChallengeHost">
<div
(click)="showLeaderboardByLatestOrBest()"
Expand All @@ -59,14 +62,15 @@ <h5 class="fw-light">Leaderboard</h5>
</div>
<span class="w-400"> {{ sortLeaderboardTextOption }}</span>
</mat-chip-list> -->
<mat-checkbox
class="pull-right complete-leaderboard"
*ngIf="isChallengeHost && showLeaderboardToggle"
(change)="toggleLeaderboard(getAllEntries)"
[(ngModel)]="getAllEntries"
>
<label class="fw-light complete-leaderboard-text"> {{ getAllEntriesTextOption }}</label>
</mat-checkbox>
</div>
<mat-checkbox
class="pull-right complete-leaderboard"
*ngIf="isChallengeHost && showLeaderboardToggle && numberOfAllEntries > 0"
(change)="toggleLeaderboard(getAllEntries)"
[(ngModel)]="getAllEntries"
>
<label class="fw-light complete-leaderboard-text"> {{ getAllEntriesTextOption }}</label>
</mat-checkbox>
</div>

<table *ngIf="leaderboard.length > 0 && selectedPhaseSplit" class="centered highlight fw-light">
Expand Down Expand Up @@ -161,7 +165,7 @@ <h5 class="fw-light">Leaderboard</h5>
<span *ngIf="key.submission__is_public === false && isSelectedPhaseLeaderboardPublic" class="private">
<mat-chip-list>
<mat-chip>P</mat-chip>
</mat-chip-list>
</mat-chip-list>&nbsp;
</span>
<span *ngIf="key.submission__is_baseline">
<mat-chip-list>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
}
}

.pull-right {
margin-left: auto;
margin-top: -3%;
}

.btn-switch {
position: relative;
display: block;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ export class ChallengeleaderboardComponent implements OnInit, AfterViewInit, OnD
*/
getAllEntries = false;

/**
* Number of entries on complete leaderboard
*/
numberOfAllEntries:number = 0;

/**
* Current state of whether private leaderboard
*/
Expand Down Expand Up @@ -336,8 +341,10 @@ export class ChallengeleaderboardComponent implements OnInit, AfterViewInit, OnD
phaseSplitSelected(phaseSplit) {
const SELF = this;
SELF.selectedPhaseSplit = phaseSplit;

SELF.fetchNumberOfAllEnteriesOnPublicLeaderboard(SELF.selectedPhaseSplit['id']);

const API_PATH = SELF.endpointsService.particularChallengePhaseSplitUrl(this.selectedPhaseSplit['id']);
const API_PATH = SELF.endpointsService.particularChallengePhaseSplitUrl(SELF.selectedPhaseSplit['id']);
SELF.apiService.getUrl(API_PATH).subscribe(
(data) => {
SELF.leaderboardPrecisionValue = data.leaderboard_decimal_precision;
Expand All @@ -350,7 +357,11 @@ export class ChallengeleaderboardComponent implements OnInit, AfterViewInit, OnD
);

if (SELF.selectedPhaseSplit && SELF.router.url.endsWith('leaderboard/' + phaseSplit['id'])) {
SELF.fetchLeaderboard(SELF.selectedPhaseSplit['id']);
if(SELF.getAllEntriesTextOption == 'Exclude private submissions') {
SELF.fetchAllEnteriesOnPublicLeaderboard(SELF.selectedPhaseSplit['id']);
} else {
SELF.fetchLeaderboard(SELF.selectedPhaseSplit['id']);
}
SELF.showLeaderboardByLatest = SELF.selectedPhaseSplit.show_leaderboard_by_latest_submission;
SELF.sortLeaderboardTextOption = SELF.showLeaderboardByLatest ? 'Sort by best' : 'Sort by latest';
let selectedPhase = SELF.phases.find((phase) => {
Expand Down Expand Up @@ -507,6 +518,24 @@ export class ChallengeleaderboardComponent implements OnInit, AfterViewInit, OnD
);
}

/**
* Fetch number of entries of complete leaderboard for a phase split public/private
* @param phaseSplitId id of the phase split
*/
fetchNumberOfAllEnteriesOnPublicLeaderboard(phaseSplitId) {
const API_PATH = this.endpointsService.challengeCompleteLeaderboardURL(phaseSplitId);
const SELF = this;
this.apiService.getUrl(API_PATH).subscribe(
(data) => {
this.numberOfAllEntries = data['results'].length;
},
(err) => {
SELF.globalService.handleApiError(err);
},
() => {}
);
}

/**
* function for toggeling between public leaderboard and complete leaderboard [public/private]
*/
Expand All @@ -526,7 +555,12 @@ export class ChallengeleaderboardComponent implements OnInit, AfterViewInit, OnD
* @param phaseSplitId id of the phase split
*/
startLeaderboard(phaseSplitId) {
const API_PATH = this.endpointsService.challengeLeaderboardURL(phaseSplitId);
let API_PATH;
if(this.getAllEntriesTextOption == 'Exclude private submissions') {
API_PATH = this.endpointsService.challengeCompleteLeaderboardURL(phaseSplitId);
} else {
API_PATH = this.endpointsService.challengeLeaderboardURL(phaseSplitId);
}
const SELF = this;
clearInterval(SELF.pollingInterval);
SELF.pollingInterval = setInterval(function () {
Expand Down

0 comments on commit cb98fc4

Please sign in to comment.