From 91081b8185a00d3bcf6514c71bfa502fd8a07f24 Mon Sep 17 00:00:00 2001 From: Gautam Jajoo Date: Mon, 30 Aug 2021 12:31:38 +0530 Subject: [PATCH] Frontend_V2: Fix linting issues in codebase(#3583) * fix linting issues and remove deprecated params * add param --- frontend_v2/src/app/app-routing.module.ts | 5 +- frontend_v2/src/app/app.component.ts | 1 - .../auth/signup/signup.component.ts | 2 +- .../challengeleaderboard.component.ts | 89 +++-- .../challengeoverview.component.ts | 6 +- .../challengesettings.component.ts | 348 +++++++++--------- .../challengesubmissions.component.ts | 26 +- .../challengesubmit.component.ts | 29 +- .../challengeviewallsubmissions.component.ts | 44 ++- .../src/app/components/home/home.component.ts | 32 +- .../header-static/header-static.component.ts | 48 +-- .../components/profile/profile.component.ts | 13 +- .../challengelist/challengelist.component.ts | 2 +- .../publiclists/publiclists.component.ts | 12 +- .../teamlist/teamlist.component.ts | 22 +- .../templatechallengelist.component.ts | 20 +- .../template-challenge-create.component.ts | 154 ++++---- .../template-challenge-create.module.ts | 11 +- .../selectphase/selectphase.component.ts | 30 +- .../utility/side-bar/side-bar.component.ts | 60 ++- frontend_v2/src/app/services/api.service.ts | 1 - frontend_v2/src/app/services/auth.service.ts | 4 +- .../src/app/services/challenge.service.ts | 8 +- frontend_v2/tslint.json | 2 - 24 files changed, 468 insertions(+), 501 deletions(-) diff --git a/frontend_v2/src/app/app-routing.module.ts b/frontend_v2/src/app/app-routing.module.ts index 67a96eba26..d9a9f6aad6 100644 --- a/frontend_v2/src/app/app-routing.module.ts +++ b/frontend_v2/src/app/app-routing.module.ts @@ -1,5 +1,5 @@ import { NgModule } from '@angular/core'; -import { RouterModule, Routes, PreloadAllModules } from '@angular/router'; +import { RouterModule, Routes } from '@angular/router'; // import component import { NotFoundComponent } from './components/not-found/not-found.component'; @@ -66,7 +66,8 @@ const routes: Routes = [ }, { path: 'template-challenge-create/:id/:phases', - loadChildren: './components/template-challenge-create/template-challenge-create.module#TemplateChallengeCreateModule', + loadChildren: + './components/template-challenge-create/template-challenge-create.module#TemplateChallengeCreateModule', }, { path: '404', diff --git a/frontend_v2/src/app/app.component.ts b/frontend_v2/src/app/app.component.ts index 105bcb616d..4c6c19a9b6 100644 --- a/frontend_v2/src/app/app.component.ts +++ b/frontend_v2/src/app/app.component.ts @@ -51,7 +51,6 @@ export class AppComponent implements OnInit, OnDestroy { */ @HostListener('window:scroll', []) onWindowScroll(): void { - const HEADER_ELE = document.getElementById('header-static'); if (this.document.documentElement.scrollTop > 50) { if (this.scrolledState === false) { this.globalService.scrolledStateChange(true); diff --git a/frontend_v2/src/app/components/auth/signup/signup.component.ts b/frontend_v2/src/app/components/auth/signup/signup.component.ts index 68c5542844..53fd2e991d 100644 --- a/frontend_v2/src/app/components/auth/signup/signup.component.ts +++ b/frontend_v2/src/app/components/auth/signup/signup.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Inject } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { AfterViewInit } from '@angular/core'; import { ApiService } from '../../../services/api.service'; import { EndpointsService } from '../../../services/endpoints.service'; diff --git a/frontend_v2/src/app/components/challenge/challengeleaderboard/challengeleaderboard.component.ts b/frontend_v2/src/app/components/challenge/challengeleaderboard/challengeleaderboard.component.ts index 2f9815aa8e..52efeeeadb 100644 --- a/frontend_v2/src/app/components/challenge/challengeleaderboard/challengeleaderboard.component.ts +++ b/frontend_v2/src/app/components/challenge/challengeleaderboard/challengeleaderboard.component.ts @@ -1,7 +1,6 @@ import { Component, OnInit, QueryList, ViewChildren, AfterViewInit, OnDestroy } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { Router, ActivatedRoute } from '@angular/router'; -import { NGXLogger } from 'ngx-logger'; // import component import { SelectphaseComponent } from '../../utility/selectphase/selectphase.component'; @@ -147,7 +146,7 @@ export class ChallengeleaderboardComponent implements OnInit, AfterViewInit, OnD /** * Number of entries on complete leaderboard */ - numberOfAllEntries:number = 0; + numberOfAllEntries = 0; /** * Current state of whether private leaderboard @@ -221,8 +220,7 @@ export class ChallengeleaderboardComponent implements OnInit, AfterViewInit, OnD private globalService: GlobalService, private apiService: ApiService, private endpointsService: EndpointsService, - public dialog: MatDialog, - private logger: NGXLogger + public dialog: MatDialog ) {} /** @@ -265,8 +263,7 @@ export class ChallengeleaderboardComponent implements OnInit, AfterViewInit, OnD if (this.phaseSplits[i].visibility !== this.challengePhaseVisibility.public) { this.phaseSplits[i].showPrivate = true; this.showPrivateIds.push(this.phaseSplits[i].id); - } - else { + } else { this.phaseSplits[i].showPrivate = false; } } @@ -303,8 +300,8 @@ export class ChallengeleaderboardComponent implements OnInit, AfterViewInit, OnD if (self.viewInit) { self.components.map((item) => { item.selectPhaseSplit(self.selectedPhaseSplit, 'selectBox', 'phaseSplit'); - }) - this.phaseSplitSelected(self.selectedPhaseSplit) + }); + this.phaseSplitSelected(self.selectedPhaseSplit); } else { setTimeout(() => { checkViewInit(); @@ -324,52 +321,52 @@ export class ChallengeleaderboardComponent implements OnInit, AfterViewInit, OnD * This is called when a phase split is selected (from child components) * Updates the router URL with phase-split-id */ - selectedPhaseSplitUrlChange = (phaseSplit) => { + selectedPhaseSplitUrlChange = (phaseSplit) => { const SELF = this; - if (SELF.router.url.endsWith('leaderboard')) { - SELF.router.navigate([phaseSplit['id']], { relativeTo: this.route }); - } else if (SELF.router.url.split('/').length === 5) { - SELF.router.navigate(['../' + phaseSplit['id']], { relativeTo: this.route }); - } else if (SELF.router.url.split('/').length === 6) { - SELF.router.navigate(['../../' + phaseSplit['id']], { relativeTo: this.route }); - } + if (SELF.router.url.endsWith('leaderboard')) { + SELF.router.navigate([phaseSplit['id']], { relativeTo: this.route }); + } else if (SELF.router.url.split('/').length === 5) { + SELF.router.navigate(['../' + phaseSplit['id']], { relativeTo: this.route }); + } else if (SELF.router.url.split('/').length === 6) { + SELF.router.navigate(['../../' + phaseSplit['id']], { relativeTo: this.route }); } + }; /** * This is called when a phase split is selected */ - phaseSplitSelected(phaseSplit) { - const SELF = this; - SELF.selectedPhaseSplit = phaseSplit; + phaseSplitSelected(phaseSplit) { + const SELF = this; + SELF.selectedPhaseSplit = phaseSplit; - SELF.fetchNumberOfAllEnteriesOnPublicLeaderboard(SELF.selectedPhaseSplit['id']); - - const API_PATH = SELF.endpointsService.particularChallengePhaseSplitUrl(SELF.selectedPhaseSplit['id']); - SELF.apiService.getUrl(API_PATH).subscribe( - (data) => { - SELF.leaderboardPrecisionValue = data.leaderboard_decimal_precision; - SELF.setLeaderboardPrecisionValue = `1.${ SELF.leaderboardPrecisionValue }-${ SELF.leaderboardPrecisionValue }`; - }, - (err) => { - SELF.globalService.handleApiError(err); - }, - () => {} - ); + SELF.fetchNumberOfAllEnteriesOnPublicLeaderboard(SELF.selectedPhaseSplit['id']); - if (SELF.selectedPhaseSplit && SELF.router.url.endsWith('leaderboard/' + phaseSplit['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) => { - return phase.id === SELF.selectedPhaseSplit.challenge_phase - }) - SELF.isSelectedPhaseLeaderboardPublic = selectedPhase.leaderboard_public + const API_PATH = SELF.endpointsService.particularChallengePhaseSplitUrl(SELF.selectedPhaseSplit['id']); + SELF.apiService.getUrl(API_PATH).subscribe( + (data) => { + SELF.leaderboardPrecisionValue = data.leaderboard_decimal_precision; + SELF.setLeaderboardPrecisionValue = `1.${SELF.leaderboardPrecisionValue}-${SELF.leaderboardPrecisionValue}`; + }, + (err) => { + SELF.globalService.handleApiError(err); + }, + () => {} + ); + + if (SELF.selectedPhaseSplit && SELF.router.url.endsWith('leaderboard/' + phaseSplit['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'; + const selectedPhase = SELF.phases.find((phase) => { + return phase.id === SELF.selectedPhaseSplit.challenge_phase; + }); + SELF.isSelectedPhaseLeaderboardPublic = selectedPhase.leaderboard_public; + } + } /** * This updates the leaderboard results after fetching them from API @@ -556,7 +553,7 @@ export class ChallengeleaderboardComponent implements OnInit, AfterViewInit, OnD */ startLeaderboard(phaseSplitId) { let API_PATH; - if(this.getAllEntriesTextOption == 'Exclude private submissions') { + if (this.getAllEntriesTextOption === 'Exclude private submissions') { API_PATH = this.endpointsService.challengeCompleteLeaderboardURL(phaseSplitId); } else { API_PATH = this.endpointsService.challengeLeaderboardURL(phaseSplitId); diff --git a/frontend_v2/src/app/components/challenge/challengeoverview/challengeoverview.component.ts b/frontend_v2/src/app/components/challenge/challengeoverview/challengeoverview.component.ts index ad0debfd69..20d26d4cf1 100644 --- a/frontend_v2/src/app/components/challenge/challengeoverview/challengeoverview.component.ts +++ b/frontend_v2/src/app/components/challenge/challengeoverview/challengeoverview.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Inject } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; // import service import { ChallengeService } from '../../../services/challenge.service'; @@ -26,9 +26,7 @@ export class ChallengeoverviewComponent implements OnInit { * Constructor. * @param challengeService ChallengeService Injection. */ - constructor( - private challengeService: ChallengeService - ) {} + constructor(private challengeService: ChallengeService) {} /** * Component on initialized. diff --git a/frontend_v2/src/app/components/challenge/challengesettings/challengesettings.component.ts b/frontend_v2/src/app/components/challenge/challengesettings/challengesettings.component.ts index ad99ad7f5d..fcb7813f23 100644 --- a/frontend_v2/src/app/components/challenge/challengesettings/challengesettings.component.ts +++ b/frontend_v2/src/app/components/challenge/challengesettings/challengesettings.component.ts @@ -18,7 +18,6 @@ import { SelectphaseComponent } from '../../utility/selectphase/selectphase.comp styleUrls: ['./challengesettings.component.scss'], }) export class ChallengesettingsComponent implements OnInit, OnDestroy { - /** * Phase select card components */ @@ -55,11 +54,11 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { */ filteredPhases = []; - /** - * Phase splits filtered - */ + /** + * Phase splits filtered + */ filteredPhaseSplits = []; - + /** * Currently selected phase */ @@ -70,25 +69,25 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { */ phaseSelectionType = 'selectBox'; - /** - * Select box list type - */ + /** + * Select box list type + */ phaseSelectionListType = 'phase'; /** * If the submission is public */ - isSubmissionPublic : boolean = false; + isSubmissionPublic = false; - /** - * If the phase is public - */ - isPhasePublic : boolean = false; + /** + * If the phase is public + */ + isPhasePublic = false; /** * If leaderboard is public */ - isLeaderboardPublic : boolean = false; + isLeaderboardPublic = false; /** * Currently selected phase split @@ -100,9 +99,9 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { */ phaseLeaderboardSelectionType = 'selectBox'; - /** - * Select box list type - */ + /** + * Select box list type + */ phaseLeaderboardSelectionListType = 'settingsPhaseSplit'; /** @@ -110,16 +109,16 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { * 1 -> private * 3 -> public */ - isPhaseSplitLeaderboardPublic: number = 1; + isPhaseSplitLeaderboardPublic = 1; /** * Leaderboard precision value */ leaderboardPrecisionValue = 2; - /** - * Set leaderboard precision value - */ + /** + * Set leaderboard precision value + */ setLeaderboardPrecisionValue = '1.2-2'; /** @@ -127,11 +126,11 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { */ minusDisabled = false; - /** - * If leaderboard precision value is equal to 20 - */ + /** + * If leaderboard precision value is equal to 20 + */ plusDisabled = false; - + /** * store worker logs */ @@ -176,7 +175,7 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { submissionVisibility = { state: 'Private', icon: 'fa fa-toggle-off grey-text text-darken-1', - }; + }; /** * phase visibility state and it's icon @@ -229,37 +228,35 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { this.challengeService.isChallengeHost.subscribe((status) => { this.isChallengeHost = status; }); - + this.challengeService.currentChallengePublishState.subscribe((publishChallenge) => { this.publishChallenge.state = publishChallenge.state; this.publishChallenge.icon = publishChallenge.icon; }); - if (!this.challenge["remote_evaluation"]) { + if (!this.challenge['remote_evaluation']) { this.fetchWorkerLogs(); this.startLoadingLogs(); } - + this.challengeService.currentPhases.subscribe((phases) => { this.phases = phases; for (let i = 0; i < this.phases.length; i++) { if (this.phases[i].is_public === false) { this.phases[i].showPrivate = true; - } - else { + } else { this.phases[i].showPrivate = false; } } this.filteredPhases = this.phases; - }); + }); this.challengeService.currentPhaseSplit.subscribe((phaseSplits) => { this.phaseSplits = phaseSplits; for (let i = 0; i < this.phaseSplits.length; i++) { if (this.phaseSplits[i].visibility !== 3) { this.phaseSplits[i].showPrivate = true; - } - else { + } else { this.phaseSplits[i].showPrivate = false; } } @@ -476,7 +473,7 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { }; SELF.globalService.showModal(PARAMS); } - + /** * Edit challenge start and end date function */ @@ -734,21 +731,19 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { if (SELF.isPhasePublic) { SELF.phaseVisibility.state = 'Public'; SELF.phaseVisibility.icon = 'fa fa-toggle-on green-text'; - } - else { + } else { SELF.phaseVisibility.state = 'Private'; SELF.phaseVisibility.icon = 'fa fa-toggle-off grey-text text-darken-1'; } if (SELF.isSubmissionPublic) { SELF.submissionVisibility.state = 'Public'; SELF.submissionVisibility.icon = 'fa fa-toggle-on green-text'; - } - else { + } else { SELF.submissionVisibility.state = 'Private'; SELF.submissionVisibility.icon = 'fa fa-toggle-off grey-text text-darken-1'; } }; - } + } /** * Edit Phase Details function @@ -769,15 +764,17 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { ) .subscribe( (data) => { - for (var attrname in data) { - SELF.selectedPhase[attrname] = data[attrname]; + for (const attrname of Object.keys(data)) { + SELF.selectedPhase[attrname] = data[attrname]; } SELF.globalService.showToast('success', 'The challenge phase details are successfully updated!'); }, (err) => { SELF.globalService.showToast('error', err); }, - () => {this.logger.info('PHASE-UPDATE-FINISHED')} + () => { + this.logger.info('PHASE-UPDATE-FINISHED'); + } ); }; @@ -792,13 +789,13 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { maxSubmissionsPerMonth: SELF.selectedPhase['max_submissions_per_month'], maxSubmissions: SELF.selectedPhase['max_submissions'], maxConcurrentSubmissionsAllowed: SELF.selectedPhase['max_concurrent_submissions_allowed'], - allowedSubmissionFileTypes: SELF.selectedPhase['allowed_submission_file_types'], + allowedSubmissionFileTypes: SELF.selectedPhase['allowed_submission_file_types'], confirm: 'Submit', deny: 'Cancel', confirmCallback: SELF.apiCall, }; SELF.globalService.showEditPhaseModal(PARAMS); -} + } /** * Phase Visibility toggle function @@ -817,68 +814,64 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { SELF.phaseVisibility.state = 'Public'; SELF.phaseVisibility.icon = 'fa fa-toggle-on green-text'; } - const BODY: FormData = new FormData(); - BODY.append("is_public", isPublic); - SELF.apiService + const BODY: FormData = new FormData(); + BODY.append('is_public', isPublic); + SELF.apiService .patchFileUrl( SELF.endpointsService.updateChallengePhaseDetailsURL(SELF.selectedPhase['challenge'], SELF.selectedPhase['id']), BODY ) - .subscribe( - (data) => { - SELF.selectedPhase['is_public'] = data.is_public; - SELF.selectedPhase['showPrivate'] = !data.is_public; - SELF.challengeService.changePhaseSelected(true); - if(!SELF.selectedPhase['is_public']) { - for(let i = 0; i < SELF.phaseSplits.length; i++) { - if(SELF.phaseSplits[i]['challenge_phase_name'] === SELF.selectedPhase['name'] && SELF.phaseSplits[i]['visibility'] == 3) { - let visibility: any = 1; - const BODY: FormData = new FormData(); - BODY.append("visibility", visibility); - SELF.apiService - .patchFileUrl( - SELF.endpointsService.particularChallengePhaseSplitUrl(SELF.phaseSplits[i]['id']), - BODY - ) - .subscribe( - (data) => { - SELF.phaseSplits[i]['visibility'] = data.visibility; - SELF.challengeService.changePhaseSplitSelected(true); - SELF.phaseSplits[i]['showPrivate'] = true; - if(SELF.selectedPhaseSplit === SELF.phaseSplits[i]) { - SELF.leaderboardVisibility.state = 'Private'; - SELF.leaderboardVisibility.icon = 'fa fa-toggle-off grey-text text-darken-1'; - } - }, - (err) => { - SELF.globalService.handleApiError(err, true); - SELF.globalService.showToast('error', err); - }, - () => this.logger.info('Change leaderboard visibility after phase is updated') - ); - } + .subscribe( + (data) => { + SELF.selectedPhase['is_public'] = data.is_public; + SELF.selectedPhase['showPrivate'] = !data.is_public; + SELF.challengeService.changePhaseSelected(true); + if (!SELF.selectedPhase['is_public']) { + for (let i = 0; i < SELF.phaseSplits.length; i++) { + if ( + SELF.phaseSplits[i]['challenge_phase_name'] === SELF.selectedPhase['name'] && + SELF.phaseSplits[i]['visibility'] === 3 + ) { + const visibility: any = 1; + const FORM: FormData = new FormData(); + FORM.append('visibility', visibility); + SELF.apiService + .patchFileUrl(SELF.endpointsService.particularChallengePhaseSplitUrl(SELF.phaseSplits[i]['id']), FORM) + .subscribe( + (dataPhaseSplit) => { + SELF.phaseSplits[i]['visibility'] = dataPhaseSplit.visibility; + SELF.challengeService.changePhaseSplitSelected(true); + SELF.phaseSplits[i]['showPrivate'] = true; + if (SELF.selectedPhaseSplit === SELF.phaseSplits[i]) { + SELF.leaderboardVisibility.state = 'Private'; + SELF.leaderboardVisibility.icon = 'fa fa-toggle-off grey-text text-darken-1'; + } + }, + (err) => { + SELF.globalService.handleApiError(err, true); + SELF.globalService.showToast('error', err); + }, + () => this.logger.info('Change leaderboard visibility after phase is updated') + ); } } + } - SELF.globalService.showToast( - 'success', - 'The phase was successfully made ' + togglePhaseVisibilityState, - 5 - ); - }, - (err) => { - SELF.globalService.handleApiError(err, true); - SELF.globalService.showToast('error', err); - if (isPublic) { - SELF.phaseVisibility.state = 'Private'; - SELF.phaseVisibility.icon = 'fa fa-toggle-off grey-text text-darken-1'; - } else { - SELF.phaseVisibility.state = 'Public'; - SELF.phaseVisibility.icon = 'fa fa-toggle-on green-text'; - } - }, - () => this.logger.info('PHASE-VISIBILITY-UPDATE-FINISHED') - ); + SELF.globalService.showToast('success', 'The phase was successfully made ' + togglePhaseVisibilityState, 5); + }, + (err) => { + SELF.globalService.handleApiError(err, true); + SELF.globalService.showToast('error', err); + if (isPublic) { + SELF.phaseVisibility.state = 'Private'; + SELF.phaseVisibility.icon = 'fa fa-toggle-off grey-text text-darken-1'; + } else { + SELF.phaseVisibility.state = 'Public'; + SELF.phaseVisibility.icon = 'fa fa-toggle-on green-text'; + } + }, + () => this.logger.info('PHASE-VISIBILITY-UPDATE-FINISHED') + ); } /** @@ -886,7 +879,7 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { */ toggleSubmissionVisibility() { const SELF = this; - if(SELF.isLeaderboardPublic == true) { + if (SELF.isLeaderboardPublic === true) { let toggleSubmissionVisibilityState, isSubmissionPublic; if (SELF.submissionVisibility.state === 'Public') { toggleSubmissionVisibilityState = 'private'; @@ -899,38 +892,40 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { SELF.submissionVisibility.state = 'Public'; SELF.submissionVisibility.icon = 'fa fa-toggle-on green-text'; } - const BODY: FormData = new FormData(); - BODY.append("is_submission_public", isSubmissionPublic); - SELF.apiService + const BODY: FormData = new FormData(); + BODY.append('is_submission_public', isSubmissionPublic); + SELF.apiService .patchFileUrl( - SELF.endpointsService.updateChallengePhaseDetailsURL(SELF.selectedPhase['challenge'], SELF.selectedPhase['id']), + SELF.endpointsService.updateChallengePhaseDetailsURL( + SELF.selectedPhase['challenge'], + SELF.selectedPhase['id'] + ), BODY ) - .subscribe( - (data) => { - SELF.selectedPhase['is_submission_public'] = data.is_submission_public; - SELF.globalService.showToast( - 'success', - 'The submissions were successfully made ' + toggleSubmissionVisibilityState, - 5 - ); - }, - (err) => { - SELF.globalService.handleApiError(err, true); - SELF.globalService.showToast('error', err); - if (isSubmissionPublic) { - SELF.submissionVisibility.state = 'Private'; - SELF.submissionVisibility.icon = 'fa fa-toggle-off grey-text text-darken-1'; - } else { - SELF.submissionVisibility.state = 'Public'; - SELF.submissionVisibility.icon = 'fa fa-toggle-on green-text'; - } - }, - () => this.logger.info('SUBMISSION-VISIBILITY-UPDATE-FINISHED') - ); - } - else { - SELF.globalService.showToast('error', "Leaderboard is private, please make the leaderbaord public"); + .subscribe( + (data) => { + SELF.selectedPhase['is_submission_public'] = data.is_submission_public; + SELF.globalService.showToast( + 'success', + 'The submissions were successfully made ' + toggleSubmissionVisibilityState, + 5 + ); + }, + (err) => { + SELF.globalService.handleApiError(err, true); + SELF.globalService.showToast('error', err); + if (isSubmissionPublic) { + SELF.submissionVisibility.state = 'Private'; + SELF.submissionVisibility.icon = 'fa fa-toggle-off grey-text text-darken-1'; + } else { + SELF.submissionVisibility.state = 'Public'; + SELF.submissionVisibility.icon = 'fa fa-toggle-on green-text'; + } + }, + () => this.logger.info('SUBMISSION-VISIBILITY-UPDATE-FINISHED') + ); + } else { + SELF.globalService.showToast('error', 'Leaderboard is private, please make the leaderbaord public'); } } @@ -939,16 +934,15 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { /** * This is called when a phase split is selected (from child components) */ - phaseSplitSelected () { + phaseSplitSelected() { const SELF = this; return (phaseSplit) => { SELF.selectedPhaseSplit = phaseSplit; SELF.isPhaseSplitLeaderboardPublic = SELF.selectedPhaseSplit['visibility']; - if(SELF.isPhaseSplitLeaderboardPublic == 3) { + if (SELF.isPhaseSplitLeaderboardPublic === 3) { SELF.leaderboardVisibility.state = 'Public'; SELF.leaderboardVisibility.icon = 'fa fa-toggle-on green-text'; - } - else { + } else { SELF.leaderboardVisibility.state = 'Private'; SELF.leaderboardVisibility.icon = 'fa fa fa-toggle-off grey-text text-darken-1'; } @@ -956,14 +950,14 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { SELF.apiService.getUrl(API_PATH).subscribe( (data) => { SELF.leaderboardPrecisionValue = data.leaderboard_decimal_precision; - SELF.setLeaderboardPrecisionValue = `1.${ SELF.leaderboardPrecisionValue }-${ SELF.leaderboardPrecisionValue }`; + SELF.setLeaderboardPrecisionValue = `1.${SELF.leaderboardPrecisionValue}-${SELF.leaderboardPrecisionValue}`; }, (err) => { SELF.globalService.handleApiError(err); }, () => {} ); - } + }; } /** @@ -972,12 +966,12 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { toggleLeaderboardVisibility() { const SELF = this; let toggleLeaderboardVisibilityState, visibility, phaseIsPublic; - for(let i = 0; i < SELF.filteredPhases.length; i++) { - if(SELF.filteredPhases[i]['name'] === SELF.selectedPhaseSplit['challenge_phase_name']) { + for (let i = 0; i < SELF.filteredPhases.length; i++) { + if (SELF.filteredPhases[i]['name'] === SELF.selectedPhaseSplit['challenge_phase_name']) { phaseIsPublic = SELF.filteredPhases[i]['is_public']; } } - if(phaseIsPublic) { + if (phaseIsPublic) { if (SELF.leaderboardVisibility.state === 'Public') { toggleLeaderboardVisibilityState = 'private'; visibility = 1; @@ -990,43 +984,42 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { SELF.leaderboardVisibility.icon = 'fa fa-toggle-on green-text'; } const BODY: FormData = new FormData(); - BODY.append("visibility", visibility); + BODY.append('visibility', visibility); SELF.apiService - .patchFileUrl(SELF.endpointsService.particularChallengePhaseSplitUrl(SELF.selectedPhaseSplit['id']),BODY) - .subscribe( - (data) => { - SELF.selectedPhaseSplit['visibility'] = data.visibility; - SELF.challengeService.changePhaseSplitSelected(true); - if (visibility == 3) { - SELF.selectedPhaseSplit['showPrivate'] = false; - SELF.leaderboardVisibility.state = 'Public'; - SELF.leaderboardVisibility.icon = 'fa fa-toggle-on green-text'; - } else { - SELF.selectedPhaseSplit['showPrivate'] = true; - SELF.leaderboardVisibility.state = 'Private'; - SELF.leaderboardVisibility.icon = 'fa fa-toggle-off grey-text text-darken-1'; - } - SELF.globalService.showToast( - 'success', - 'The phase split was successfully made ' + toggleLeaderboardVisibilityState, - 5 - ); - }, - (err) => { - SELF.globalService.handleApiError(err, true); - SELF.globalService.showToast('error', err); - if (visibility == 3) { - SELF.leaderboardVisibility.state = 'Private'; - SELF.leaderboardVisibility.icon = 'fa fa-toggle-off grey-text text-darken-1'; - } else { - SELF.leaderboardVisibility.state = 'Public'; - SELF.leaderboardVisibility.icon = 'fa fa-toggle-on green-text'; - } - }, - () => this.logger.info('LEADERBOARD-VISIBILITY-UPDATE-FINISHED') - ); - } - else { + .patchFileUrl(SELF.endpointsService.particularChallengePhaseSplitUrl(SELF.selectedPhaseSplit['id']), BODY) + .subscribe( + (data) => { + SELF.selectedPhaseSplit['visibility'] = data.visibility; + SELF.challengeService.changePhaseSplitSelected(true); + if (visibility === 3) { + SELF.selectedPhaseSplit['showPrivate'] = false; + SELF.leaderboardVisibility.state = 'Public'; + SELF.leaderboardVisibility.icon = 'fa fa-toggle-on green-text'; + } else { + SELF.selectedPhaseSplit['showPrivate'] = true; + SELF.leaderboardVisibility.state = 'Private'; + SELF.leaderboardVisibility.icon = 'fa fa-toggle-off grey-text text-darken-1'; + } + SELF.globalService.showToast( + 'success', + 'The phase split was successfully made ' + toggleLeaderboardVisibilityState, + 5 + ); + }, + (err) => { + SELF.globalService.handleApiError(err, true); + SELF.globalService.showToast('error', err); + if (visibility === 3) { + SELF.leaderboardVisibility.state = 'Private'; + SELF.leaderboardVisibility.icon = 'fa fa-toggle-off grey-text text-darken-1'; + } else { + SELF.leaderboardVisibility.state = 'Public'; + SELF.leaderboardVisibility.icon = 'fa fa-toggle-on green-text'; + } + }, + () => this.logger.info('LEADERBOARD-VISIBILITY-UPDATE-FINISHED') + ); + } else { SELF.globalService.showToast('error', 'The phase is private, please make the phase public'); } } @@ -1168,7 +1161,7 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { // Get the logs from worker if submissions are failing. fetchWorkerLogs() { - if(this.challenge['id']) { + if (this.challenge['id']) { const API_PATH = this.endpointsService.getLogsURL(this.challenge['id']); const SELF = this; SELF.apiService.getUrl(API_PATH, true, false).subscribe( @@ -1193,12 +1186,11 @@ export class ChallengesettingsComponent implements OnInit, OnDestroy { SELF.fetchWorkerLogs(); }, 5000); } - + /** * Component on destroyed. */ ngOnDestroy() { clearInterval(this.pollingInterval); } - } diff --git a/frontend_v2/src/app/components/challenge/challengesubmissions/challengesubmissions.component.ts b/frontend_v2/src/app/components/challenge/challengesubmissions/challengesubmissions.component.ts index bef9851841..1c379bcb50 100644 --- a/frontend_v2/src/app/components/challenge/challengesubmissions/challengesubmissions.component.ts +++ b/frontend_v2/src/app/components/challenge/challengesubmissions/challengesubmissions.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, QueryList, ViewChildren, ViewChild, Input, AfterViewInit } from '@angular/core'; +import { Component, OnInit, QueryList, ViewChildren, Input, AfterViewInit } from '@angular/core'; import { Router, ActivatedRoute } from '@angular/router'; import { NGXLogger } from 'ngx-logger'; @@ -152,10 +152,17 @@ export class ChallengesubmissionsComponent implements OnInit, AfterViewInit { */ apiCall: any; - columnsToDisplay = ['s_no', 'status', 'execution_time', 'submission_result_file', 'stdout_file', 'stderr_file', 'submitted_at']; + columnsToDisplay = [ + 's_no', + 'status', + 'execution_time', + 'submission_result_file', + 'stdout_file', + 'stderr_file', + 'submitted_at', + ]; columnsHeadings = ['S.No.', 'Status', 'Execution Time', 'Result File', 'Stdout File', 'Stderr File', 'Submitted At']; - expandedElement: null; /** @@ -226,8 +233,7 @@ export class ChallengesubmissionsComponent implements OnInit, AfterViewInit { for (let i = 0; i < this.phases.length; i++) { if (this.phases[i].is_public === false) { this.phases[i].showPrivate = true; - } - else { + } else { this.phases[i].showPrivate = false; } } @@ -262,7 +268,7 @@ export class ChallengesubmissionsComponent implements OnInit, AfterViewInit { fetchSubmissions(challenge, phase) { const SELF = this; let API_PATH; - API_PATH = SELF.endpointsService.challengeSubmissionURL(challenge, phase); + API_PATH = SELF.endpointsService.challengeSubmissionURL(challenge, phase); SELF.apiService.getUrl(API_PATH).subscribe( (data) => { SELF.submissionCount = data['count']; @@ -360,7 +366,7 @@ export class ChallengesubmissionsComponent implements OnInit, AfterViewInit { SELF.paginationDetails.currentPage = Math.ceil(data.next.split('page=')[1] - 1); } - let index = (SELF.paginationDetails.currentPage-1)*10; + let index = (SELF.paginationDetails.currentPage - 1) * 10; SELF.submissions.forEach((submission) => { submission['s_no'] = index + 1; index += 1; @@ -489,7 +495,7 @@ export class ChallengesubmissionsComponent implements OnInit, AfterViewInit { ); } } - + /** * Display Edit Submission Modal. * @param submission Submission being edited @@ -570,7 +576,7 @@ export class ChallengesubmissionsComponent implements OnInit, AfterViewInit { */ fetchParticipated_team(challengeId) { const SELF = this; - if(challengeId != undefined){ + if (challengeId !== undefined) { const API_PATH = SELF.endpointsService.getParticipatedTeamNameURL(challengeId); this.apiService.getUrl(API_PATH, true, false).subscribe( (data) => { @@ -582,5 +588,5 @@ export class ChallengesubmissionsComponent implements OnInit, AfterViewInit { () => {} ); } - } + } } diff --git a/frontend_v2/src/app/components/challenge/challengesubmit/challengesubmit.component.ts b/frontend_v2/src/app/components/challenge/challengesubmit/challengesubmit.component.ts index f3cc067088..a98d0b70f1 100644 --- a/frontend_v2/src/app/components/challenge/challengesubmit/challengesubmit.component.ts +++ b/frontend_v2/src/app/components/challenge/challengesubmit/challengesubmit.component.ts @@ -41,7 +41,7 @@ export class ChallengesubmitComponent implements OnInit { /** * If phase has been selected */ - isPhaseSelected:boolean = false; + isPhaseSelected = false; /** * Is user logged in @@ -56,12 +56,12 @@ export class ChallengesubmitComponent implements OnInit { /** * Is submission submitted */ - isPublicSubmission:boolean = true; + isPublicSubmission = true; /** * Is submission allowed by host */ - isLeaderboardPublic:boolean = false; + isLeaderboardPublic = false; /** * Challenge object @@ -265,8 +265,7 @@ export class ChallengesubmitComponent implements OnInit { for (let j = 0; j < this.phases.length; j++) { if (phases[j].is_public === false) { this.phases[j].showPrivate = true; - } - else { + } else { this.phases[j].showPrivate = false; } } @@ -488,7 +487,7 @@ export class ChallengesubmitComponent implements OnInit { SELF.fetchRemainingSubmissions(SELF.challenge['id'], phase['id']); SELF.clearMetaAttributeValues(); SELF.submissionError = ''; - if(SELF.components) { + if (SELF.components) { SELF.components['_results'].forEach((element) => { element.value = ''; element.message = ''; @@ -542,17 +541,17 @@ export class ChallengesubmitComponent implements OnInit { } if (self.metaAttributesforCurrentSubmission != null) { self.metaAttributesforCurrentSubmission.forEach((attribute) => { - if (attribute.required == true) { - if (attribute.type == "checkbox") { - if (attribute.values.length === 0) { - metaValue = false; - } + if (attribute.required === true) { + if (attribute.type === 'checkbox') { + if (attribute.values.length === 0) { + metaValue = false; + } } else { - if (attribute.value === null || attribute.value === undefined) { - metaValue = false; - } + if (attribute.value === null || attribute.value === undefined) { + metaValue = false; + } } - } + } }); } if (metaValue !== true) { diff --git a/frontend_v2/src/app/components/challenge/challengeviewallsubmissions/challengeviewallsubmissions.component.ts b/frontend_v2/src/app/components/challenge/challengeviewallsubmissions/challengeviewallsubmissions.component.ts index 30c072aa3f..3351982227 100644 --- a/frontend_v2/src/app/components/challenge/challengeviewallsubmissions/challengeviewallsubmissions.component.ts +++ b/frontend_v2/src/app/components/challenge/challengeviewallsubmissions/challengeviewallsubmissions.component.ts @@ -133,8 +133,7 @@ export class ChallengeviewallsubmissionsComponent implements OnInit, AfterViewIn /** *Check whether team name is filtered */ - isTeamFiltered: boolean = true; - + isTeamFiltered = true; /** * @param showPagination Is pagination @@ -159,7 +158,15 @@ export class ChallengeviewallsubmissionsComponent implements OnInit, AfterViewIn 'submitted_file', 'submission_result_file', ]; - columnsHeadings = ['S.No.', 'Team Name', 'Created By', 'Status', 'Execution Time(sec)', 'Submitted File', 'Result File']; + columnsHeadings = [ + 'S.No.', + 'Team Name', + 'Created By', + 'Status', + 'Execution Time(sec)', + 'Submitted File', + 'Result File', + ]; expandedElement: null; @@ -224,8 +231,7 @@ export class ChallengeviewallsubmissionsComponent implements OnInit, AfterViewIn for (let i = 0; i < this.phases.length; i++) { if (this.phases[i].is_public === false) { this.phases[i].showPrivate = true; - } - else { + } else { this.phases[i].showPrivate = false; } } @@ -272,10 +278,10 @@ export class ChallengeviewallsubmissionsComponent implements OnInit, AfterViewIn this.isTeamFiltered = true; } - let name = SELF.filterSubmissionsQuery; + const name = SELF.filterSubmissionsQuery; SELF.apiService.getUrl(API_PATH).subscribe( (data) => { - if(name == SELF.filterSubmissionsQuery) { + if (name === SELF.filterSubmissionsQuery) { SELF.submissionCount = data['count']; SELF.submissions = data['results']; let index = 0; @@ -293,11 +299,11 @@ export class ChallengeviewallsubmissionsComponent implements OnInit, AfterViewIn SELF.submissions[i].submissionFlagIcon = SELF.submissions[i].is_flagged ? 'flag' : 'outlined_flag'; SELF.submissions[i].submissionFlagText = SELF.submissions[i].is_flagged ? 'Flagged' : 'UnFlagged'; } - + SELF.paginationDetails.next = data.next; SELF.paginationDetails.previous = data.previous; SELF.paginationDetails.totalPage = Math.ceil(data.count / 100); - + if (data.count === 0) { SELF.paginationDetails.showPagination = false; SELF.paginationDetails.paginationMessage = 'No results found'; @@ -311,12 +317,11 @@ export class ChallengeviewallsubmissionsComponent implements OnInit, AfterViewIn SELF.paginationDetails.currentPage = 1; } else { SELF.paginationDetails.isNext = ''; - if(this.isTeamFiltered) { - SELF.paginationDetails.currentPage = Math.ceil(data.next.split('page=').join('&').split('&')[1] - 1); - } - else { - SELF.paginationDetails.currentPage = Math.ceil(data.next.split('page=')[1] - 1); - } + if (this.isTeamFiltered) { + SELF.paginationDetails.currentPage = Math.ceil(data.next.split('page=').join('&').split('&')[1] - 1); + } else { + SELF.paginationDetails.currentPage = Math.ceil(data.next.split('page=')[1] - 1); + } } if (data.previous === null) { SELF.paginationDetails.isPrev = 'disabled'; @@ -395,15 +400,14 @@ export class ChallengeviewallsubmissionsComponent implements OnInit, AfterViewIn SELF.paginationDetails.currentPage = Math.ceil(data.count / 100); } else { SELF.paginationDetails.isNext = ''; - if(this.isTeamFiltered) { - SELF.paginationDetails.currentPage = Math.ceil(data.next.split('page=').join('&').split('&')[1] -1); - } - else { + if (this.isTeamFiltered) { + SELF.paginationDetails.currentPage = Math.ceil(data.next.split('page=').join('&').split('&')[1] - 1); + } else { SELF.paginationDetails.currentPage = Math.ceil(data.next.split('page=')[1] - 1); } } - let index = (SELF.paginationDetails.currentPage-1)*10; + let index = (SELF.paginationDetails.currentPage - 1) * 10; SELF.submissions.forEach((submission) => { submission['s_no'] = index + 1; index += 1; diff --git a/frontend_v2/src/app/components/home/home.component.ts b/frontend_v2/src/app/components/home/home.component.ts index 9e2885c1db..9a317275bf 100644 --- a/frontend_v2/src/app/components/home/home.component.ts +++ b/frontend_v2/src/app/components/home/home.component.ts @@ -27,34 +27,34 @@ export class HomeComponent implements OnInit, AfterViewInit, OnDestroy { selected = 0; /** - * Placeholder text Lorem Ipsum - */ + * Placeholder text Lorem Ipsum + */ ipsum: any = 'Lorem ipsum dolor sit amet,\ consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'; /** - * Sample testimonials till the API comes up - */ + * Sample testimonials till the API comes up + */ testimonials = [ - { text: '1-' + this.ipsum, author: 'Lorem', org: 'Georgia Tech', image:'' }, - { text: '2-' + this.ipsum, author: 'Octopus', org: 'Google', image:'' }, - { text: '3-' + this.ipsum, author: 'Penguin', org: 'Facebook', image:'' }, + { text: '1-' + this.ipsum, author: 'Lorem', org: 'Georgia Tech', image: '' }, + { text: '2-' + this.ipsum, author: 'Octopus', org: 'Google', image: '' }, + { text: '3-' + this.ipsum, author: 'Penguin', org: 'Facebook', image: '' }, ]; /** - * Selected testimonial text - */ + * Selected testimonial text + */ testimonialbody = this.testimonials[this.selected]['text']; /** - * Selected testimonial author - */ + * Selected testimonial author + */ testimonialauthor = this.testimonials[this.selected]['author']; /** - * Selected testimonial orgName - */ + * Selected testimonial orgName + */ testimonialorg = this.testimonials[this.selected]['org']; /** @@ -110,7 +110,7 @@ export class HomeComponent implements OnInit, AfterViewInit, OnDestroy { getChallenge() { this.apiService.getUrl(this.endpointService.featuredChallengesURL()).subscribe( (response) => { - this.challengeList = response.results.slice(0,4); + this.challengeList = response.results.slice(0, 4); }, (err) => { this.globalService.handleApiError(err); @@ -150,7 +150,7 @@ export class HomeComponent implements OnInit, AfterViewInit, OnDestroy { }, // Show Form Error on Failure (err) => { - if(err.status == 400) { + if (err.status === 400) { setTimeout(() => self.globalService.showToast('info', err.error.message, 5), 1000); } else if (err.error.message) { setTimeout(() => self.globalService.showToast('error', err.error.message, 5), 1000); @@ -165,7 +165,7 @@ export class HomeComponent implements OnInit, AfterViewInit, OnDestroy { /** * Right arrow clicked */ - testimonialRight() { + testimonialRight() { this.selected = this.selected + 1; if (this.selected >= this.testimonials.length) { this.selected = 0; diff --git a/frontend_v2/src/app/components/nav/header-static/header-static.component.ts b/frontend_v2/src/app/components/nav/header-static/header-static.component.ts index a35411f778..3341482f9a 100644 --- a/frontend_v2/src/app/components/nav/header-static/header-static.component.ts +++ b/frontend_v2/src/app/components/nav/header-static/header-static.component.ts @@ -1,18 +1,8 @@ -import { - Component, - OnInit, - OnDestroy, - ChangeDetectorRef, - Inject, - HostListener, - ViewChild, - ElementRef, -} from '@angular/core'; +import { Component, OnInit, OnDestroy, ChangeDetectorRef, HostListener, ViewChild, ElementRef } from '@angular/core'; import { GlobalService } from '../../../services/global.service'; import { AuthService } from '../../../services/auth.service'; -import { filter } from "rxjs/internal/operators"; +import { filter } from 'rxjs/internal/operators'; import { Router, NavigationEnd } from '@angular/router'; -import { DOCUMENT } from '@angular/common'; /** * Component Class @@ -63,12 +53,12 @@ export class HeaderStaticComponent implements OnInit, OnDestroy { /** * Current name of tab which needs to be active */ - tabHighlight: string = "allChallenges"; + tabHighlight = 'allChallenges'; /** * Returns true if the string is not a number */ - isChallengeComponent : boolean = false; + isChallengeComponent = false; /** * Inner width @@ -89,10 +79,9 @@ export class HeaderStaticComponent implements OnInit, OnDestroy { private globalService: GlobalService, private router: Router, private ref: ChangeDetectorRef, - public authService: AuthService, - @Inject(DOCUMENT) private document: Document + public authService: AuthService ) { - this.authState = authService.authState; + this.authState = authService.authState; } /** @@ -112,22 +101,19 @@ export class HeaderStaticComponent implements OnInit, OnDestroy { this.updateElements(); this.checkInnerWidth(); - this.router.events - .pipe(filter(event => event instanceof NavigationEnd)) - .subscribe((event) => { - if(event) { - if(this.router.url.split('/')[length] == "all") { - this.tabHighlight = "allChallenges"; - this.globalService.changeTabActiveStatus("allChallenges"); - } - else if(this.router.url.split('/')[1] == "profile") { - this.tabHighlight = "profile"; - this.globalService.changeTabActiveStatus("profile"); - } + this.router.events.pipe(filter((event) => event instanceof NavigationEnd)).subscribe((event) => { + if (event) { + if (this.router.url.split('/')[length] === 'all') { + this.tabHighlight = 'allChallenges'; + this.globalService.changeTabActiveStatus('allChallenges'); + } else if (this.router.url.split('/')[1] === 'profile') { + this.tabHighlight = 'profile'; + this.globalService.changeTabActiveStatus('profile'); + } } }); - this.isChallengeComponent = isNaN(parseInt(this.router.url.split('/')[length])); - + this.isChallengeComponent = isNaN(parseInt(this.router.url.split('/')[length], 10)); + this.globalService.nameTabHighlight.subscribe((tabHighlight) => { this.tabHighlight = tabHighlight; }); diff --git a/frontend_v2/src/app/components/profile/profile.component.ts b/frontend_v2/src/app/components/profile/profile.component.ts index a524270c81..0612054056 100644 --- a/frontend_v2/src/app/components/profile/profile.component.ts +++ b/frontend_v2/src/app/components/profile/profile.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { Router, ActivatedRoute } from '@angular/router'; -import { ViewChildren, QueryList, AfterViewInit } from '@angular/core'; +import { Router } from '@angular/router'; +import { ViewChildren, QueryList } from '@angular/core'; import { NGXLogger } from 'ngx-logger'; // import service @@ -76,7 +76,6 @@ export class ProfileComponent implements OnInit { private authService: AuthService, private globalService: GlobalService, private router: Router, - private route: ActivatedRoute, private endpointsService: EndpointsService, private windowService: WindowService, private logger: NGXLogger @@ -255,11 +254,9 @@ export class ProfileComponent implements OnInit { */ downloadToken() { this.isTokenModalVisible = false; - this.windowService.downloadFile( - { body: JSON.stringify({ token: this.token }) }, - 'token.json', - { type: 'text/json' } - ); + this.windowService.downloadFile({ body: JSON.stringify({ token: this.token }) }, 'token.json', { + type: 'text/json', + }); } /** diff --git a/frontend_v2/src/app/components/publiclists/challengelist/challengelist.component.ts b/frontend_v2/src/app/components/publiclists/challengelist/challengelist.component.ts index d6efda8c64..445c42adea 100644 --- a/frontend_v2/src/app/components/publiclists/challengelist/challengelist.component.ts +++ b/frontend_v2/src/app/components/publiclists/challengelist/challengelist.component.ts @@ -229,7 +229,7 @@ export class ChallengelistComponent implements OnInit { */ @HostListener('window:scroll', []) onWindowScroll(): void { - if(this.document.getElementById('ongoing-challenges')) { + if (this.document.getElementById('ongoing-challenges')) { const RECT = this.document.getElementById('ongoing-challenges').getBoundingClientRect(); this.isScrollbtnVisible = RECT.top < 0; } diff --git a/frontend_v2/src/app/components/publiclists/publiclists.component.ts b/frontend_v2/src/app/components/publiclists/publiclists.component.ts index 2c8524442e..475e95205b 100644 --- a/frontend_v2/src/app/components/publiclists/publiclists.component.ts +++ b/frontend_v2/src/app/components/publiclists/publiclists.component.ts @@ -10,7 +10,6 @@ import { AuthService } from '../../services/auth.service'; styleUrls: ['./publiclists.component.scss'], }) export class PubliclistsComponent implements OnInit, AfterViewChecked { - isAuth = false; /** @@ -18,11 +17,8 @@ export class PubliclistsComponent implements OnInit, AfterViewChecked { * @param authService * @param changeDetector */ - constructor( - public authService: AuthService, - private cdRef : ChangeDetectorRef - ) {} - + constructor(public authService: AuthService, private cdRef: ChangeDetectorRef) {} + /** * Component on Initialization. */ @@ -35,8 +31,8 @@ export class PubliclistsComponent implements OnInit, AfterViewChecked { * For resolving change in expression value after it is checked */ ngAfterViewChecked() { - let isAuth = this.authService.isAuth; - if(isAuth != this.isAuth) { + const isAuth = this.authService.isAuth; + if (isAuth !== this.isAuth) { this.isAuth = isAuth; this.cdRef.detectChanges(); } diff --git a/frontend_v2/src/app/components/publiclists/teamlist/teamlist.component.ts b/frontend_v2/src/app/components/publiclists/teamlist/teamlist.component.ts index cf197bacec..5ca6b305f9 100644 --- a/frontend_v2/src/app/components/publiclists/teamlist/teamlist.component.ts +++ b/frontend_v2/src/app/components/publiclists/teamlist/teamlist.component.ts @@ -168,7 +168,7 @@ export class TeamlistComponent implements OnInit, OnDestroy { * Route path for create challenge */ createChallengeRoutePath = '/challenge-create'; - + /** * Route path for create template challenge page */ @@ -263,15 +263,13 @@ export class TeamlistComponent implements OnInit, OnDestroy { } }); - this.teamListRouteQueryParamSub = this.route - .queryParams - .subscribe(params => { - this.isTemplateChallenge = params['template'] || false; - if(this.isTemplateChallenge){ - this.templateId = params['templateId']; - this.templatePhases = params['templatePhases']; - } - }); + this.teamListRouteQueryParamSub = this.route.queryParams.subscribe((params) => { + this.isTemplateChallenge = params['template'] || false; + if (this.isTemplateChallenge) { + this.templateId = params['templateId']; + this.templatePhases = params['templatePhases']; + } + }); if (this.router.url === this.hostTeamRoutePath || this.isTemplateChallenge) { this.isHost = true; @@ -669,10 +667,10 @@ export class TeamlistComponent implements OnInit, OnDestroy { } else { API_PATH = SELF.endpointsService.FilteredParticipantTeamURL(teamName); } - let name = SELF.filterTeamsQuery; + const name = SELF.filterTeamsQuery; SELF.apiService.getUrl(API_PATH).subscribe( (data) => { - if(name == SELF.filterTeamsQuery) { + if (name === SELF.filterTeamsQuery) { SELF.updateTeamsData(data); } }, diff --git a/frontend_v2/src/app/components/publiclists/templatechallengelist/templatechallengelist.component.ts b/frontend_v2/src/app/components/publiclists/templatechallengelist/templatechallengelist.component.ts index 7daa9fd72d..6496ca82e8 100644 --- a/frontend_v2/src/app/components/publiclists/templatechallengelist/templatechallengelist.component.ts +++ b/frontend_v2/src/app/components/publiclists/templatechallengelist/templatechallengelist.component.ts @@ -3,7 +3,6 @@ import { ApiService } from '../../../services/api.service'; import { GlobalService } from '../../../services/global.service'; import { AuthService } from '../../../services/auth.service'; - /** * Component Class */ @@ -13,7 +12,6 @@ import { AuthService } from '../../../services/auth.service'; styleUrls: ['./templatechallengelist.component.scss'], }) export class TemplateChallengeListComponent implements OnInit { - /** * Is the user logged in? */ @@ -32,7 +30,7 @@ export class TemplateChallengeListComponent implements OnInit { /** * Path to fetch all challenge templates */ - templateChallengesFetchPath = 'challenges/get_all_challenge_templates/' + templateChallengesFetchPath = 'challenges/get_all_challenge_templates/'; /** * Constructor. @@ -40,11 +38,7 @@ export class TemplateChallengeListComponent implements OnInit { * @param globalService GlobalService Injection. * @param apiService ApiService Injection. */ - constructor( - public authService: AuthService, - private globalService: GlobalService, - private apiService: ApiService - ) {} + constructor(public authService: AuthService, private globalService: GlobalService, private apiService: ApiService) {} ngOnInit() { if (this.authService.isLoggedIn()) { @@ -66,15 +60,17 @@ export class TemplateChallengeListComponent implements OnInit { } */ fetchChallengeTemplates(callback = null) { - this.apiService.getUrl(this.templateChallengesFetchPath, true, false).subscribe( (data) => { - for(var i = 0; i { - this.globalService.showToast('error', 'Sorry, something went wrong when fetching the templates. Please try again later.'); + (err) => { + this.globalService.showToast( + 'error', + 'Sorry, something went wrong when fetching the templates. Please try again later.' + ); }, () => {} ); diff --git a/frontend_v2/src/app/components/template-challenge-create/template-challenge-create.component.ts b/frontend_v2/src/app/components/template-challenge-create/template-challenge-create.component.ts index fce08e9f17..126c44e09a 100644 --- a/frontend_v2/src/app/components/template-challenge-create/template-challenge-create.component.ts +++ b/frontend_v2/src/app/components/template-challenge-create/template-challenge-create.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, OnDestroy } from '@angular/core'; import { AuthService } from '../../services/auth.service'; import { GlobalService } from '../../services/global.service'; @@ -13,7 +13,7 @@ import { Router, ActivatedRoute } from '@angular/router'; templateUrl: './template-challenge-create.component.html', styleUrls: ['./template-challenge-create.component.scss'], }) -export class TemplateChallengeCreateComponent implements OnInit { +export class TemplateChallengeCreateComponent implements OnInit, OnDestroy { /** * Is the user logged in? */ @@ -38,27 +38,27 @@ export class TemplateChallengeCreateComponent implements OnInit { * Challenge values loaded by host */ challengeData = { - 'title': null, - 'start_date': null, - 'end_date': null, - 'description': null, - 'evaluation_script': null, - 'challenge_phases': null - } + title: null, + start_date: null, + end_date: null, + description: null, + evaluation_script: null, + challenge_phases: null, + }; /** * Challenge phase data loaded by hosts */ - challenge_phases = [] + challenge_phases = []; /** * Challenge phase data model used to fill challenge_phases above */ challengePhaseData = { - 'name': null, - 'start_date': null, - 'end_date': null - } + name: null, + start_date: null, + end_date: null, + }; /** * Route for hosted challenges @@ -70,7 +70,6 @@ export class TemplateChallengeCreateComponent implements OnInit { */ hostTeamsRoute = '/teams/hosts'; - constructor( public authService: AuthService, private router: Router, @@ -80,64 +79,71 @@ export class TemplateChallengeCreateComponent implements OnInit { ) {} ngOnInit() { - if (this.authService.isLoggedIn()) { - this.isLoggedIn = true; - } - - this.route.params.subscribe((params) => { - if (params['id']) { - this.id = params['id']; - } - - if (params['phases']){ - this.phases = params['phases']; - } - - this.challengeService.currentHostTeam.subscribe((hostTeam) => { - this.hostTeam = hostTeam; - if (!this.hostTeam) { - this.router.navigate([this.hostTeamsRoute], { queryParams: { template: true, templateId: this.id, templatePhases: this.phases } }); - } - }); - }); - - for(var i = 0; i { + if (params['id']) { + this.id = params['id']; + } + + if (params['phases']) { + this.phases = params['phases']; + } + + this.challengeService.currentHostTeam.subscribe((hostTeam) => { + this.hostTeam = hostTeam; + if (!this.hostTeam) { + this.router.navigate([this.hostTeamsRoute], { + queryParams: { template: true, templateId: this.id, templatePhases: this.phases }, + }); + } + }); + }); + + for (let i = 0; i < this.phases; i++) { + this.challengePhaseData['id'] = i + 1; + this.challenge_phases.push(Object.assign({}, this.challengePhaseData)); + } + } + + ngOnDestroy() { + this.hostTeam = null; + } + + createTemplateChallenge() { + if (this.challengeData != null) { + const FORM_DATA: FormData = new FormData(); + this.challengeData['is_challenge_template'] = true; + this.challengeData['template_id'] = this.id; + this.challengeData.challenge_phases = JSON.stringify(this.challenge_phases); + for (const key of Object.keys(this.challengeData)) { FORM_DATA.append(key, this.challengeData[key]); - } - this.globalService.startLoader('Creating Challenge'); - this.challengeService.challengeCreate(this.hostTeam['id'], FORM_DATA).subscribe( - (data) => { - this.globalService.stopLoader(); - this.globalService.showToast('success', 'Challenge created and successfuly sent to EvalAI admin for approval.'); - this.router.navigate([this.hostedChallengesRoute]); - }, - (err) => { - console.log(err.error); - this.globalService.stopLoader(); - this.globalService.showToast('error', "Sorry, something went wrong when creating the challenge. Please try again later: " + JSON.stringify(err.error) ); - }, - () => {} - ); - } - else { - this.globalService.showToast('error', 'Please fill all the given challenge details'); - } - } + } + this.globalService.startLoader('Creating Challenge'); + this.challengeService.challengeCreate(this.hostTeam['id'], FORM_DATA).subscribe( + (data) => { + this.globalService.stopLoader(); + this.globalService.showToast( + 'success', + 'Challenge created and successfuly sent to EvalAI admin for approval.' + ); + this.router.navigate([this.hostedChallengesRoute]); + }, + (err) => { + console.log(err.error); + this.globalService.stopLoader(); + this.globalService.showToast( + 'error', + 'Sorry, something went wrong when creating the challenge. Please try again later: ' + + JSON.stringify(err.error) + ); + }, + () => {} + ); + } else { + this.globalService.showToast('error', 'Please fill all the given challenge details'); + } + } } diff --git a/frontend_v2/src/app/components/template-challenge-create/template-challenge-create.module.ts b/frontend_v2/src/app/components/template-challenge-create/template-challenge-create.module.ts index f91c85194c..77510d6bce 100644 --- a/frontend_v2/src/app/components/template-challenge-create/template-challenge-create.module.ts +++ b/frontend_v2/src/app/components/template-challenge-create/template-challenge-create.module.ts @@ -1,6 +1,6 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { MatDatepickerModule, MatInputModule,MatNativeDateModule} from '@angular/material'; +import { MatDatepickerModule, MatInputModule, MatNativeDateModule } from '@angular/material'; // import component import { TemplateChallengeCreateComponent } from './template-challenge-create.component'; @@ -11,7 +11,14 @@ import { SharedModule } from '../../shared/shared.module'; @NgModule({ declarations: [TemplateChallengeCreateComponent], - imports: [CommonModule, TemplateChallengeCreateRoutingModule, SharedModule, MatDatepickerModule, MatInputModule,MatNativeDateModule,], + imports: [ + CommonModule, + TemplateChallengeCreateRoutingModule, + SharedModule, + MatDatepickerModule, + MatInputModule, + MatNativeDateModule, + ], exports: [TemplateChallengeCreateComponent], }) export class TemplateChallengeCreateModule {} diff --git a/frontend_v2/src/app/components/utility/selectphase/selectphase.component.ts b/frontend_v2/src/app/components/utility/selectphase/selectphase.component.ts index 0936782f59..988bcc7f7f 100644 --- a/frontend_v2/src/app/components/utility/selectphase/selectphase.component.ts +++ b/frontend_v2/src/app/components/utility/selectphase/selectphase.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Input, Output, OnChanges } from '@angular/core'; +import { Component, OnInit, Input, OnChanges } from '@angular/core'; import { ChallengeService } from '../../../services/challenge.service'; import { GlobalService } from '../../../services/global.service'; @@ -19,12 +19,12 @@ export class SelectphaseComponent implements OnInit, OnChanges { /** * Phase Splits list for settings tab */ - @Input() settingsPhaseSplits: any; + @Input() settingsPhaseSplits: any; /** * Phase Splits list */ - @Input() phaseSplits: any; + @Input() phaseSplits: any; /** * Selected phase callback @@ -37,7 +37,7 @@ export class SelectphaseComponent implements OnInit, OnChanges { @Input() selectedPhaseSplitUrlChange: any; /** - * Selected phase split + * Selected phase split */ @Input() phaseSplitSelected: any; @@ -64,7 +64,7 @@ export class SelectphaseComponent implements OnInit, OnChanges { /** * If phase selected */ - isPhaseSelected : boolean = false; + isPhaseSelected = false; /** * Currently selected phase @@ -89,7 +89,7 @@ export class SelectphaseComponent implements OnInit, OnChanges { /** * If phase selected */ - isPhaseSplitSelected : boolean = false; + isPhaseSplitSelected = false; /** * Challenge object @@ -116,18 +116,16 @@ export class SelectphaseComponent implements OnInit, OnChanges { this.challenge = challenge; }); - if(Array.isArray(this.phases) && this.phases.length) { + if (Array.isArray(this.phases) && this.phases.length) { this.selectedPhase = this.phases[0]; this.radioSelected = this.phases[0].id; this.selectPhase(this.phases[0]); - } - else if(Array.isArray(this.settingsPhaseSplits) && this.settingsPhaseSplits.length) { + } else if (Array.isArray(this.settingsPhaseSplits) && this.settingsPhaseSplits.length) { this.selectedPhaseSplit = this.settingsPhaseSplits[0]; - this.selectSettingsPhaseSplit(this.settingsPhaseSplits[0], "selectBox", "settingsPhaseSplit"); - } - else if(Array.isArray(this.phaseSplits) && this.phaseSplits.length) { + this.selectSettingsPhaseSplit(this.settingsPhaseSplits[0], 'selectBox', 'settingsPhaseSplit'); + } else if (Array.isArray(this.phaseSplits) && this.phaseSplits.length) { this.selectedPhaseSplit = this.phaseSplits[0]; - this.selectPhaseSplit(this.phaseSplits[0], "selectBox", "phaseSplit"); + this.selectPhaseSplit(this.phaseSplits[0], 'selectBox', 'phaseSplit'); } } @@ -140,7 +138,7 @@ export class SelectphaseComponent implements OnInit, OnChanges { this.isPhaseSelected = isPhaseSelected; }); - if(this.isPhaseSelected == true && this.phaseSelected) { + if (this.isPhaseSelected === true && this.phaseSelected) { this.challengeService.changePhaseSelected(false); this.selectPhase(this.selectedPhase); } @@ -149,11 +147,11 @@ export class SelectphaseComponent implements OnInit, OnChanges { this.isPhaseSplitSelected = isPhaseSplitSelected; }); - if(this.phaseSplitSelected && this.isPhaseSplitSelected) { + if (this.phaseSplitSelected && this.isPhaseSplitSelected) { this.challengeService.changePhaseSplitSelected(false); this.selectSettingsPhaseSplit(this.selectedPhaseSplit, this.phaseSelectionType, this.phaseSelectionListType); } - } + } /** * Select a particular phase. diff --git a/frontend_v2/src/app/components/utility/side-bar/side-bar.component.ts b/frontend_v2/src/app/components/utility/side-bar/side-bar.component.ts index 943212da8a..2eef877312 100644 --- a/frontend_v2/src/app/components/utility/side-bar/side-bar.component.ts +++ b/frontend_v2/src/app/components/utility/side-bar/side-bar.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { Router, NavigationEnd } from '@angular/router'; -import { filter } from "rxjs/internal/operators"; +import { filter } from 'rxjs/internal/operators'; import { GlobalService } from '../../../services/global.service'; @Component({ @@ -9,58 +9,48 @@ import { GlobalService } from '../../../services/global.service'; styleUrls: ['./side-bar.component.scss'], }) export class SideBarComponent implements OnInit { - /** * Current name of tab which needs to be active */ - tabHighlight: string = "allChallenges"; + tabHighlight = 'allChallenges'; /** * Returns true if the string is not a number */ - isChallengeComponent : boolean = false; + isChallengeComponent = false; - /** + /** * Constructor * @param globalService GlobalService Injection. * @param router Router */ - constructor( - private globalService: GlobalService, - private router: Router - ) { } + constructor(private globalService: GlobalService, private router: Router) {} ngOnInit() { this.globalService.nameTabHighlight.subscribe((tabHighlight) => { this.tabHighlight = tabHighlight; }); - this.router.events - .pipe(filter(event => event instanceof NavigationEnd)) - .subscribe((event) => { - if(event) { - if(this.router.url.split('/')[2] == "me") { - this.tabHighlight = "hostedChallenges"; - this.globalService.changeTabActiveStatus("hostedChallenges"); - } - else if(this.router.url.split('/')[2] == "hosts") { - this.tabHighlight = "createChallenge"; - this.globalService.changeTabActiveStatus("createChallenge"); - } - else if(this.router.url.split('/')[2] == "participants") { - this.tabHighlight = "myParticipantTeams"; - this.globalService.changeTabActiveStatus("myParticipantTeams"); - } - else if(this.router.url.split('/')[2] == "participated") { - this.tabHighlight = "participatedChallenges"; - this.globalService.changeTabActiveStatus("participatedChallenges"); - } - else if(this.router.url.split('/')[2] == "all") { - this.tabHighlight = "allChallenges"; - this.globalService.changeTabActiveStatus("allChallenges"); - } - this.isChallengeComponent = isNaN(parseInt(this.router.url.split('/')[length])); + this.router.events.pipe(filter((event) => event instanceof NavigationEnd)).subscribe((event) => { + if (event) { + if (this.router.url.split('/')[2] === 'me') { + this.tabHighlight = 'hostedChallenges'; + this.globalService.changeTabActiveStatus('hostedChallenges'); + } else if (this.router.url.split('/')[2] === 'hosts') { + this.tabHighlight = 'createChallenge'; + this.globalService.changeTabActiveStatus('createChallenge'); + } else if (this.router.url.split('/')[2] === 'participants') { + this.tabHighlight = 'myParticipantTeams'; + this.globalService.changeTabActiveStatus('myParticipantTeams'); + } else if (this.router.url.split('/')[2] === 'participated') { + this.tabHighlight = 'participatedChallenges'; + this.globalService.changeTabActiveStatus('participatedChallenges'); + } else if (this.router.url.split('/')[2] === 'all') { + this.tabHighlight = 'allChallenges'; + this.globalService.changeTabActiveStatus('allChallenges'); + } + this.isChallengeComponent = isNaN(parseInt(this.router.url.split('/')[length], 10)); } - }); + }); } } diff --git a/frontend_v2/src/app/services/api.service.ts b/frontend_v2/src/app/services/api.service.ts index f66b9d0f66..b5ff3574c6 100644 --- a/frontend_v2/src/app/services/api.service.ts +++ b/frontend_v2/src/app/services/api.service.ts @@ -118,7 +118,6 @@ export class ApiService { * @param body stringified json body. */ loadingWrapper(httpCall, isLoader = true) { - const SELF = this; if (isLoader) { setTimeout(() => { this.globalService.toggleLoading(true); diff --git a/frontend_v2/src/app/services/auth.service.ts b/frontend_v2/src/app/services/auth.service.ts index 8f51245a52..68bc14af30 100644 --- a/frontend_v2/src/app/services/auth.service.ts +++ b/frontend_v2/src/app/services/auth.service.ts @@ -1,4 +1,4 @@ -import { Injectable, Output, EventEmitter, ElementRef } from '@angular/core'; +import { Injectable } from '@angular/core'; import { GlobalService } from './global.service'; import { EndpointsService } from './endpoints.service'; import { ApiService } from './api.service'; @@ -197,7 +197,7 @@ export class AuthService { return false; }, () => {} - ) + ); } // toggle password visibility diff --git a/frontend_v2/src/app/services/challenge.service.ts b/frontend_v2/src/app/services/challenge.service.ts index e6813f65bd..bc63cd3a3e 100644 --- a/frontend_v2/src/app/services/challenge.service.ts +++ b/frontend_v2/src/app/services/challenge.service.ts @@ -104,7 +104,7 @@ export class ChallengeService { } /** - * Update the status for selectPhase component after details are updated + * Update the status for selectPhase component after details are updated * @param selectedPhase new updated phase details status */ changePhaseSelected(selectedPhase: boolean) { @@ -128,10 +128,10 @@ export class ChallengeService { } /** - * Update the status for selectPhase component after details are updated + * Update the status for selectPhase component after details are updated * @param selectedPhase new updated phase details status */ - changePhaseSplitSelected(selectedPhaseSplit: boolean) { + changePhaseSplitSelected(selectedPhaseSplit: boolean) { this.phaseSplitSelected.next(selectedPhaseSplit); } @@ -185,7 +185,7 @@ export class ChallengeService { }, (err) => { SELF.globalService.handleApiError(err); - if(err.error.error == "Challenge does not exist!") { + if (err.error.error === 'Challenge does not exist!') { this.router.navigate(['not-found']); } }, diff --git a/frontend_v2/tslint.json b/frontend_v2/tslint.json index b66f76a483..2c7cc88920 100644 --- a/frontend_v2/tslint.json +++ b/frontend_v2/tslint.json @@ -36,8 +36,6 @@ "no-switch-case-fall-through": true, "no-unnecessary-initializer": true, "no-unused-expression": true, - "no-unused-variable": true, - "noUnusedLocals": true, "no-use-before-declare": true, "no-var-keyword": true, "object-literal-sort-keys": false,