Skip to content

Commit

Permalink
Standings query added
Browse files Browse the repository at this point in the history
  • Loading branch information
fattazzo committed Jan 24, 2019
1 parent 4bc1d56 commit 65271ba
Show file tree
Hide file tree
Showing 31 changed files with 755 additions and 78 deletions.
15 changes: 7 additions & 8 deletions src/app/domain/constructor-standing.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Constructor } from "./constructor";
import { Constructor } from './constructor';

export class ConstructorStanding {
position: string;
positionText: string;
points: string;
wins: string;

position: string;
positionText: string;
points: string;
wins: string;

Constructor: Constructor;
}
Constructor: Constructor;
}
19 changes: 9 additions & 10 deletions src/app/domain/driver-standing.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Driver } from "./driver";
import { Constructor } from "./constructor";
import { Driver } from './driver';
import { Constructor } from './constructor';

export class DriverStanding {
position: string;
positionText: string;
points: string;
wins: string;

position: string;
positionText: string;
points: string;
wins: string;
Driver: Driver;

Driver: Driver;

constructors: Constructor[];
}
Constructors: Constructor[];
}
8 changes: 5 additions & 3 deletions src/app/pages/query/params/query-params.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
</nb-accordion-item-body>
</nb-accordion-item>

<!--
<nb-accordion-item>
<nb-accordion-item-header>{{
'search.standings' | translate | ngxCapitalize
}}</nb-accordion-item-header>
<nb-accordion-item-body> </nb-accordion-item-body>
<nb-accordion-item-body>
<query-standings
(resultsUrlChange)="resultsSearchUrlChange($event)"
></query-standings>
</nb-accordion-item-body>
</nb-accordion-item>
-->
</nb-accordion>
</nb-card-body>
</nb-card>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RaceResultsModel } from '../race-results/models/race-results-model';
import { environment } from '../../../../../environments/environment.prod';
import { SearchType } from '../race-results/models/search-type';
import { RaceResultsModel } from '../../race-results/models/race-results-model';
import { environment } from '../../../../../../environments/environment.prod';
import { SearchType } from '../../race-results/models/search-type';
export class QueryBuilder {
buildUrl(model: RaceResultsModel): string {
// Remove last char ( last char = '/' )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import { Observable } from 'rxjs';
import { Driver } from '../../../../domain/driver';
import { ConstructorsService } from '../../../../services/constructors.service';
import { CircuitsService } from '../../../../services/circuits.service';
import { QueryBuilder } from '../query-builder/query-builder';
import { QueryBuilder } from './query-builder/query-builder';
import { SearchType } from './models/search-type';
import { TranslateService } from '@ngx-translate/core';
import { CapitalizePipe } from '../../../../@theme/pipes/capitalize.pipe';
import { NbThemeService } from '@nebular/theme';
import { AppSettingsService } from '../../../../services/app-settings.service';
import { Constructor } from '../../../../domain/constructor';
import { Circuit } from '../../../../domain/circuit';
Expand Down
32 changes: 32 additions & 0 deletions src/app/pages/query/params/standings/models/search-type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export class SearchType {
static readonly KEY_DRIVER_STANDINGS = 'driver-standings';
static readonly KEY_DRIVER_INFORMATION = 'driver-information';

static readonly KEY_CONSTRUCTOR_STANDINGS = 'constructor-standings';
static readonly KEY_CONSTRUCTOR_INFORMATION = 'constructor-information';

static readonly resultsSearchTypes = [
{ key: SearchType.KEY_DRIVER_STANDINGS, endPointName: 'driverStandings' },
{
key: SearchType.KEY_CONSTRUCTOR_STANDINGS,
endPointName: 'constructorStandings',
},
{ key: SearchType.KEY_DRIVER_INFORMATION, endPointName: 'drivers' },
{
key: SearchType.KEY_CONSTRUCTOR_INFORMATION,
endPointName: 'constructors',
},
{ key: 'season-list', endPointName: 'seasons' },
];

key: string;
endPointName: string;

public static getRsultsSearchTypes(): SearchType[] {
return SearchType.resultsSearchTypes;
}

public static findByKey(key: string): SearchType {
return SearchType.resultsSearchTypes.find(st => st.key === key);
}
}
17 changes: 17 additions & 0 deletions src/app/pages/query/params/standings/models/standings-model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { SearchType } from './search-type';

export class StandingsModel {
public type: string = null;
public season: string = null;
public round: string = null;
public driverStanding: string = null;
public driverId: string = null;
public constructorStanding: string = null;
public constructorId: string = null;
public resultPerPage: number = null;

constructor() {
this.type = SearchType.getRsultsSearchTypes()[0].key;
this.resultPerPage = 20;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { environment } from '../../../../../../environments/environment.prod';
import { StandingsModel } from '../models/standings-model';
import { SearchType } from '../models/search-type';
export class QueryBuilder {
buildUrl(model: StandingsModel): string {
// Remove last char ( last char = '/' )
let url = environment.ergastApiUrl.slice(0, -1);

// append url generated from model params
url += this.getUrlFromModel(model);

// append resource to retreive
url += `/${SearchType.findByKey(model.type).endPointName}.json`;

// add query limit
url += `?limit=${model.resultPerPage}`;

return url;
}

private getUrlFromModel(model: StandingsModel): string {
let url = '';

if (model.season !== null) {
url += `/${model.season}`;
}
if (model.round !== null) {
url += `/${model.round}`;
}
if (model.driverId !== null) {
url += `/drivers/${model.driverId}`;
}
if (model.driverStanding !== null) {
url += `/driverStandings/${model.driverStanding}`;
}
if (model.constructorId !== null) {
url += `/constructors/${model.constructorId}`;
}
if (model.constructorStanding !== null) {
url += `/constructorStanding/${model.constructorStanding}`;
}

return url;
}
}
166 changes: 166 additions & 0 deletions src/app/pages/query/params/standings/standings.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
<div class="container">
<form #paramsStandingsForm="ngForm" (ngSubmit)="onSubmit()">
<!-- Type -->
<div class="form-group">
<label for="type">{{ 'type.sing' | translate | ngxCapitalize }}</label>

<p-dropdown
[options]="types"
id="type"
required
[(ngModel)]="model.type"
(onChange)="onTypeChange()"
name="type"
#type="ngModel"
appendTo="body"
[style]="{ width: '100%' }"
[filter]="appSettings.filterVisible"
></p-dropdown>
</div>

<!-- Season -->
<div class="form-group">
<label for="season">{{
'season.sing' | translate | ngxCapitalize
}}</label>

<p-dropdown
[options]="seasons"
id="season"
[(ngModel)]="model.season"
(onChange)="onSeasonChange($event.value)"
name="season"
#season="ngModel"
appendTo="body"
[style]="{ width: '100%' }"
[filter]="appSettings.filterVisible"
></p-dropdown>
</div>

<!-- Round -->
<div class="form-group">
<label for="round">{{ 'round.sing' | translate | ngxCapitalize }}</label>

<p-dropdown
[options]="rounds"
id="round"
[(ngModel)]="model.round"
name="round"
#round="ngModel"
appendTo="body"
[style]="{ width: '100%' }"
[filter]="appSettings.filterVisible"
[disabled]="roundsDisable"
></p-dropdown>
</div>

<!-- Driver standings -->
<div class="form-group">
<label for="drStandings">{{
'driver-standings' | translate | ngxCapitalize
}}</label>

<p-dropdown
[options]="driverStandings"
id="drStandings"
[(ngModel)]="model.driverStandings"
name="drStandings"
#drStandings="ngModel"
appendTo="body"
[style]="{ width: '100%' }"
[filter]="appSettings.filterVisible"
[disabled]="driversDisable"
></p-dropdown>
</div>

<!-- Driver -->
<div class="form-group">
<label for="driverId">{{
'driver.sing' | translate | ngxCapitalize
}}</label>

<p-dropdown
[options]="drivers"
id="driverId"
[(ngModel)]="model.driverId"
name="driverId"
#driverId="ngModel"
appendTo="body"
autoWidth="false"
[style]="{ width: '100%' }"
[filter]="appSettings.filterVisible"
[disabled]="driversDisable"
></p-dropdown>
</div>

<!-- Constructor standings -->
<div class="form-group">
<label for="csStandings">{{
'constructor-standings' | translate | ngxCapitalize
}}</label>

<p-dropdown
[options]="constructorStandings"
id="csStandings"
[(ngModel)]="model.constructorStandings"
name="csStandings"
#csStandings="ngModel"
appendTo="body"
[style]="{ width: '100%' }"
[filter]="appSettings.filterVisible"
[disabled]="constructorDisable"
></p-dropdown>
</div>

<!-- Constructor -->
<div class="form-group">
<label for="constructorId">{{
'constructor.sing' | translate | ngxCapitalize
}}</label>

<p-dropdown
[options]="constructors"
id="constructorId"
[(ngModel)]="model.constructorId"
name="constructorId"
#constructorId="ngModel"
appendTo="body"
[style]="{ width: '100%' }"
[filter]="appSettings.filterVisible"
[disabled]="constructorDisable"
></p-dropdown>
</div>

<!-- Result per page -->
<div class="form-group">
<label for="resultPerPage">{{
'result.per-page' | translate | ngxCapitalize
}}</label>

<p-dropdown
[options]="resultsPerPage"
id="resultPerPage"
required
[(ngModel)]="model.resultPerPage"
name="resultPerPage"
#resultPerPage="ngModel"
appendTo="body"
[style]="{ width: '100%' }"
></p-dropdown>
</div>

<div style="width: 100%;display:flex;justify-content:space-around;">
<button
nbButton
type="button"
class="btn btn-default form-button"
(click)="paramsStandingsForm.reset(); newModel()"
>
{{ 'cancel' | translate | ngxCapitalize }}
</button>
<button nbButton type="submit" class="btn btn-success form-button">
{{ 'search.sing' | translate | ngxCapitalize }}
</button>
</div>
</form>
</div>
9 changes: 9 additions & 0 deletions src/app/pages/query/params/standings/standings.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@import "../../../../@theme/styles/themes";
@import "~@nebular/theme/components/card/card.component.theme";

@include nb-install-component() {
.form-button {
width: 100%;
margin: 0px 5px 0px 5px;
}
}
Loading

0 comments on commit 65271ba

Please sign in to comment.