Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"useEditorConfig": false,
"singleQuote": true
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some 'suggested' standards here, happy to update or change as needed

5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@angular/platform-browser": "~13.0.3",
"@angular/platform-browser-dynamic": "~13.0.3",
"@angular/router": "~13.0.3",
"prettier": "^2.5.1",
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add prettier package to start standardising code format to help make code easier to read and also eliminate formatting conflicts

"rxjs": "~6.6.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
Expand Down
2 changes: 2 additions & 0 deletions src/ChangeStructure.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# October 24 2021 Restructure App

## Relocation of Services

## Make Services more loosely coupled
8 changes: 4 additions & 4 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { BrowserModule } from '@angular/platform-browser';
import {HttpClientModule} from '@angular/common/http';
import { HttpClientModule } from '@angular/common/http';

const routes: Routes = [];

@NgModule({
imports: [RouterModule.forRoot(routes), BrowserModule, HttpClientModule],
exports: [RouterModule]
imports: [RouterModule.forRoot(routes), BrowserModule, HttpClientModule],
exports: [RouterModule],
})
export class AppRoutingModule { }
export class AppRoutingModule {}
22 changes: 9 additions & 13 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { AppComponent } from './app.component';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import {
HttpClientTestingModule,
HttpTestingController,
} from '@angular/common/http/testing';
// Other imports

import { HttpClient, HttpErrorResponse } from '@angular/common/http';
Expand All @@ -13,17 +16,12 @@ describe('AppComponent', () => {
let httpTestingController: HttpTestingController;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
RouterTestingModule,
HttpClientTestingModule
],
declarations: [
AppComponent
],
imports: [RouterTestingModule, HttpClientTestingModule],
declarations: [AppComponent],
}).compileComponents();
// Inject the http service and test controller for each test
httpClient = TestBed.get(HttpClient);
httpTestingController = TestBed.get(HttpTestingController);
// Inject the http service and test controller for each test
httpClient = TestBed.get(HttpClient);
httpTestingController = TestBed.get(HttpTestingController);
});

it('should create the app', () => {
Expand All @@ -37,6 +35,4 @@ describe('AppComponent', () => {
const app = fixture.componentInstance;
expect(app.title).toEqual('WeatherApp');
});


});
10 changes: 2 additions & 8 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ import { HttpService } from '../app/services/http/http.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
styleUrls: ['./app.component.css'],
})
export class AppComponent {
title = 'WeatherApp';
currentWeather: any;
/**
*
*/
constructor(private httpService: HttpService) {


}



constructor(private httpService: HttpService) {}
}
137 changes: 99 additions & 38 deletions src/app/city-search/city-search.component.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,117 @@
import {Component} from '@angular/core';
import {from, Observable, of, OperatorFunction} from 'rxjs';
import {debounceTime, distinctUntilChanged, map, tap} from 'rxjs/operators';
import { Component } from '@angular/core';
import { from, Observable, of, OperatorFunction } from 'rxjs';
import { debounceTime, distinctUntilChanged, map, tap } from 'rxjs/operators';
import { HttpService } from '../services/http/http.service';
import { WeatherInfo , CityLocation} from '../response-interfaces/response-interfaces';
import {
WeatherInfo,
CityLocation,
} from '../response-interfaces/response-interfaces';


const states = ['Alabama', 'Alaska', 'American Samoa', 'Arizona', 'Arkansas', 'California', 'Colorado',
'Connecticut', 'Delaware', 'District Of Columbia', 'Federated States Of Micronesia', 'Florida', 'Georgia',
'Guam', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine',
'Marshall Islands', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana',
'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
'Northern Mariana Islands', 'Ohio', 'Oklahoma', 'Oregon', 'Palau', 'Pennsylvania', 'Puerto Rico', 'Rhode Island',
'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virgin Islands', 'Virginia',
'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'];
const states = [
'Alabama',
'Alaska',
'American Samoa',
'Arizona',
'Arkansas',
'California',
'Colorado',
'Connecticut',
'Delaware',
'District Of Columbia',
'Federated States Of Micronesia',
'Florida',
'Georgia',
'Guam',
'Hawaii',
'Idaho',
'Illinois',
'Indiana',
'Iowa',
'Kansas',
'Kentucky',
'Louisiana',
'Maine',
'Marshall Islands',
'Maryland',
'Massachusetts',
'Michigan',
'Minnesota',
'Mississippi',
'Missouri',
'Montana',
'Nebraska',
'Nevada',
'New Hampshire',
'New Jersey',
'New Mexico',
'New York',
'North Carolina',
'North Dakota',
'Northern Mariana Islands',
'Ohio',
'Oklahoma',
'Oregon',
'Palau',
'Pennsylvania',
'Puerto Rico',
'Rhode Island',
'South Carolina',
'South Dakota',
'Tennessee',
'Texas',
'Utah',
'Vermont',
'Virgin Islands',
'Virginia',
'Washington',
'West Virginia',
'Wisconsin',
'Wyoming',
];

@Component({
selector: 'app-city-search',
templateUrl: './city-search.component.html',
styles: [`.form-control { width: 300px; }`]
styles: [
`
.form-control {
width: 300px;
}
`,
],
})
export class CitySearchComponent {
public model: any;
public location!: CityLocation[];

constructor(private httpService: HttpService) {

}
constructor(private httpService: HttpService) {}

search: OperatorFunction<string, readonly string[]> = (text$: Observable<string>) =>
search: OperatorFunction<string, readonly string[]> = (
text$: Observable<string>
) =>
text$.pipe(
debounceTime(300),
distinctUntilChanged(),
tap(r=> this.getCity()),
map(term => term.length < 2 ? []
: this.handleArryOfLocationData(term) ) // TODO: investigate slice amount //
)

handleArryOfLocationData(term : string):string[]{
let cities = [this.location[0].name];
return cities.filter(v => v.toLowerCase().indexOf(term.toLowerCase()) > -1).slice(0, 10)
// return [""];
}
tap((r) => this.getCity()),
map((term) =>
term.length < 2 ? [] : this.handleArryOfLocationData(term)
) // TODO: investigate slice amount //
);

getCity() {
// TODO have to change httpservice to take url
// const weatherInfo$ = this.httpService.getWeather('c19fda244ae14731aa532946210710') ; // TODo hide westher key
// weatherInfo$.subscribe( w => {
// console.log(w.location);
// this.location = [w.location] ;
// });


}
handleArryOfLocationData(term: string): string[] {
let cities = [this.location[0].name];
return cities
.filter((v) => v.toLowerCase().indexOf(term.toLowerCase()) > -1)
.slice(0, 10);
// return [""];
}

getCity() {
// TODO have to change httpservice to take url
// const weatherInfo$ = this.httpService.getWeather('c19fda244ae14731aa532946210710') ; // TODo hide westher key
// weatherInfo$.subscribe( w => {
// console.log(w.location);
// this.location = [w.location] ;
// });
}
}
5 changes: 2 additions & 3 deletions src/app/config/config.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ describe('ConfigComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ConfigComponent ]
})
.compileComponents();
declarations: [ConfigComponent],
}).compileComponents();
});

beforeEach(() => {
Expand Down
7 changes: 2 additions & 5 deletions src/app/config/config.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { Component, OnInit } from '@angular/core';
templateUrl: './config.component.html',
})
export class ConfigComponent implements OnInit {
constructor() {}

constructor() { }

ngOnInit(): void {
}

ngOnInit(): void {}
}
24 changes: 11 additions & 13 deletions src/app/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,22 @@ export interface Config {
heroesUrl: string;
textfile: string;
date: any;
weatherKey:string;
weatherKey: string;
}

@Injectable({
providedIn: 'root'
providedIn: 'root',
})
export class ConfigService {
/**
*
*/
// inject the HttpClient service as a dependency of an application class, as shown in the following
constructor(private http:HttpClient) {
/**
*
*/
// inject the HttpClient service as a dependency of an application class, as shown in the following
constructor(private http: HttpClient) {}

}
configUrl = 'assets/config.json';

configUrl = 'assets/config.json';

getConfig(){
return this.http.get<Config>(this.configUrl);
}
getConfig() {
return this.http.get<Config>(this.configUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';

/* tslint:disable:no-unused-variable */
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import {
HttpClientTestingModule,
HttpTestingController,
} from '@angular/common/http/testing';
// Other imports

import { HttpClient, HttpErrorResponse } from '@angular/common/http';
Expand All @@ -21,10 +24,9 @@ describe('DisplayForecastComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DisplayCurrentWeatherComponent ],
imports: [ HttpClientTestingModule ]
})
.compileComponents();
declarations: [DisplayCurrentWeatherComponent],
imports: [HttpClientTestingModule],
}).compileComponents();
httpClient = TestBed.get(HttpClient);
httpTestingController = TestBed.get(HttpTestingController);
}));
Expand Down
Loading