Browse Source

started component data sharing

woat 6 years ago
parent
commit
e33b88b43e
35 changed files with 445 additions and 30 deletions
  1. 5
    0
      client/package-lock.json
  2. 2
    1
      client/package.json
  3. 6
    0
      client/proxy.conf.json
  4. 1
    20
      client/src/app/app.component.html
  5. 28
    8
      client/src/app/app.module.ts
  6. 0
    0
      client/src/app/home/home.component.css
  7. 7
    0
      client/src/app/home/home.component.html
  8. 25
    0
      client/src/app/home/home.component.spec.ts
  9. 15
    0
      client/src/app/home/home.component.ts
  10. 15
    0
      client/src/app/news.service.spec.ts
  11. 17
    0
      client/src/app/news.service.ts
  12. 0
    0
      client/src/app/news/article/article.component.css
  13. 22
    0
      client/src/app/news/article/article.component.html
  14. 25
    0
      client/src/app/news/article/article.component.spec.ts
  15. 21
    0
      client/src/app/news/article/article.component.ts
  16. 0
    0
      client/src/app/news/news.component.css
  17. 2
    0
      client/src/app/news/news.component.html
  18. 25
    0
      client/src/app/news/news.component.spec.ts
  19. 31
    0
      client/src/app/news/news.component.ts
  20. 15
    0
      client/src/app/search.service.spec.ts
  21. 17
    0
      client/src/app/search.service.ts
  22. 0
    0
      client/src/app/search/search.component.css
  23. 11
    0
      client/src/app/search/search.component.html
  24. 25
    0
      client/src/app/search/search.component.spec.ts
  25. 24
    0
      client/src/app/search/search.component.ts
  26. 15
    0
      client/src/app/stocks.service.spec.ts
  27. 24
    0
      client/src/app/stocks.service.ts
  28. 0
    0
      client/src/app/stocks/stocks.component.css
  29. 3
    0
      client/src/app/stocks/stocks.component.html
  30. 25
    0
      client/src/app/stocks/stocks.component.spec.ts
  31. 15
    0
      client/src/app/stocks/stocks.component.ts
  32. 1
    0
      client/src/index.html
  33. 1
    1
      client/tslint.json
  34. 5
    0
      server/pom.xml
  35. 17
    0
      server/src/main/java/com/stockr/server/WebConfig.java

+ 5
- 0
client/package-lock.json View File

6450
         "minimist": "0.0.8"
6450
         "minimist": "0.0.8"
6451
       }
6451
       }
6452
     },
6452
     },
6453
+    "moment": {
6454
+      "version": "2.22.2",
6455
+      "resolved": "https://registry.npmjs.org/moment/-/moment-2.22.2.tgz",
6456
+      "integrity": "sha1-PCV/mDn8DpP/UxSWMiOeuQeD/2Y="
6457
+    },
6453
     "move-concurrently": {
6458
     "move-concurrently": {
6454
       "version": "1.0.1",
6459
       "version": "1.0.1",
6455
       "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz",
6460
       "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz",

+ 2
- 1
client/package.json View File

3
   "version": "0.0.0",
3
   "version": "0.0.0",
4
   "scripts": {
4
   "scripts": {
5
     "ng": "ng",
5
     "ng": "ng",
6
-    "start": "ng serve",
6
+    "start": "ng serve --proxy-config proxy.conf.json --port 8081",
7
     "build": "ng build",
7
     "build": "ng build",
8
     "test": "ng test",
8
     "test": "ng test",
9
     "lint": "ng lint",
9
     "lint": "ng lint",
21
     "@angular/platform-browser-dynamic": "^6.0.3",
21
     "@angular/platform-browser-dynamic": "^6.0.3",
22
     "@angular/router": "^6.0.3",
22
     "@angular/router": "^6.0.3",
23
     "core-js": "^2.5.4",
23
     "core-js": "^2.5.4",
24
+    "moment": "^2.22.2",
24
     "rxjs": "^6.0.0",
25
     "rxjs": "^6.0.0",
25
     "zone.js": "^0.8.26"
26
     "zone.js": "^0.8.26"
26
   },
27
   },

+ 6
- 0
client/proxy.conf.json View File

1
+{
2
+	"/api/*": {
3
+		"target": "http://localhost:8080",
4
+		"pathRewrite": {"^/api" : ""}
5
+	}
6
+}

+ 1
- 20
client/src/app/app.component.html View File

1
-<!--The content below is only a placeholder and can be replaced.-->
2
-<div style="text-align:center">
3
-  <h1>
4
-    Welcome to {{ title }}!
5
-  </h1>
6
-  <img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
7
-</div>
8
-<h2>Here are some links to help you start: </h2>
9
-<ul>
10
-  <li>
11
-    <h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
12
-  </li>
13
-  <li>
14
-    <h2><a target="_blank" rel="noopener" href="https://github.com/angular/angular-cli/wiki">CLI Documentation</a></h2>
15
-  </li>
16
-  <li>
17
-    <h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
18
-  </li>
19
-</ul>
20
-
1
+<router-outlet></router-outlet>

+ 28
- 8
client/src/app/app.module.ts View File

1
 import { BrowserModule } from '@angular/platform-browser';
1
 import { BrowserModule } from '@angular/platform-browser';
2
 import { NgModule } from '@angular/core';
2
 import { NgModule } from '@angular/core';
3
+import { HttpClientModule } from '@angular/common/http';
4
+import { RouterModule, Routes } from '@angular/router';
5
+import { FormsModule } from '@angular/forms';
3
 
6
 
4
 import { AppComponent } from './app.component';
7
 import { AppComponent } from './app.component';
8
+import { NewsComponent } from './news/news.component';
9
+import { ArticleComponent } from './news/article/article.component';
10
+import { HomeComponent } from './home/home.component';
11
+import { StocksComponent } from './stocks/stocks.component';
12
+import { SearchComponent } from './search/search.component';
13
+
14
+const appRoutes: Routes = [
15
+	{ path: 'home', component: HomeComponent }
16
+];
5
 
17
 
6
 @NgModule({
18
 @NgModule({
7
-  declarations: [
8
-    AppComponent
9
-  ],
10
-  imports: [
11
-    BrowserModule
12
-  ],
13
-  providers: [],
14
-  bootstrap: [AppComponent]
19
+	declarations: [
20
+		AppComponent,
21
+		NewsComponent,
22
+		HomeComponent,
23
+		StocksComponent,
24
+		ArticleComponent,
25
+		SearchComponent
26
+	],
27
+	imports: [
28
+		BrowserModule,
29
+		HttpClientModule,
30
+		FormsModule,
31
+		RouterModule.forRoot( appRoutes )
32
+	],
33
+	providers: [],
34
+	bootstrap: [AppComponent]
15
 })
35
 })
16
 export class AppModule { }
36
 export class AppModule { }

+ 0
- 0
client/src/app/home/home.component.css View File


+ 7
- 0
client/src/app/home/home.component.html View File

1
+<p>
2
+  home works!
3
+</p>
4
+
5
+<app-search></app-search>
6
+<app-news (searchEvent)="app-search.test()"></app-news>
7
+<app-stocks></app-stocks>

+ 25
- 0
client/src/app/home/home.component.spec.ts View File

1
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+import { HomeComponent } from './home.component';
4
+
5
+describe('HomeComponent', () => {
6
+  let component: HomeComponent;
7
+  let fixture: ComponentFixture<HomeComponent>;
8
+
9
+  beforeEach(async(() => {
10
+    TestBed.configureTestingModule({
11
+      declarations: [ HomeComponent ]
12
+    })
13
+    .compileComponents();
14
+  }));
15
+
16
+  beforeEach(() => {
17
+    fixture = TestBed.createComponent(HomeComponent);
18
+    component = fixture.componentInstance;
19
+    fixture.detectChanges();
20
+  });
21
+
22
+  it('should create', () => {
23
+    expect(component).toBeTruthy();
24
+  });
25
+});

+ 15
- 0
client/src/app/home/home.component.ts View File

1
+import { Component, OnInit } from '@angular/core';
2
+
3
+@Component({
4
+  selector: 'app-home',
5
+  templateUrl: './home.component.html',
6
+  styleUrls: ['./home.component.css']
7
+})
8
+export class HomeComponent implements OnInit {
9
+
10
+  constructor() { }
11
+
12
+  ngOnInit() {
13
+  }
14
+
15
+}

+ 15
- 0
client/src/app/news.service.spec.ts View File

1
+import { TestBed, inject } from '@angular/core/testing';
2
+
3
+import { NewsService } from './news.service';
4
+
5
+describe('NewsService', () => {
6
+  beforeEach(() => {
7
+    TestBed.configureTestingModule({
8
+      providers: [NewsService]
9
+    });
10
+  });
11
+
12
+  it('should be created', inject([NewsService], (service: NewsService) => {
13
+    expect(service).toBeTruthy();
14
+  }));
15
+});

+ 17
- 0
client/src/app/news.service.ts View File

1
+import { Injectable } from '@angular/core';
2
+import { HttpClient } from '@angular/common/http';
3
+import { Observable } from 'rxjs';
4
+
5
+@Injectable({
6
+	providedIn: 'root'
7
+})
8
+
9
+export class NewsService {
10
+	constructor(
11
+		private http: HttpClient,
12
+	) { }
13
+
14
+	getNews(query: string) {
15
+		return this.http.get(`/api/news?query=${query}`);
16
+	}
17
+}

+ 0
- 0
client/src/app/news/article/article.component.css View File


+ 22
- 0
client/src/app/news/article/article.component.html View File

1
+<table class="table">
2
+	<thead>
3
+		<tr>
4
+			<th>Source Name</th>
5
+			<th>Title</th>
6
+			<th>Published</th>
7
+			<th>Img</th>
8
+		</tr>
9
+	</thead>
10
+	<tbody>
11
+		<tr *ngFor="let article of articles">
12
+			<td>{{ article.sourceName }}</td>
13
+			<td><a [href]="article.url">{{ article.title }}</a></td>
14
+			<td>{{ computeDate(article.publishedAt) }}</td>
15
+			<td>
16
+				<figure class="image is-128x128">
17
+					<img [src]="article.urlToImage" />
18
+				</figure>
19
+			</td>
20
+		</tr>
21
+	</tbody>
22
+</table>

+ 25
- 0
client/src/app/news/article/article.component.spec.ts View File

1
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+import { ArticleComponent } from './article.component';
4
+
5
+describe('ArticleComponent', () => {
6
+  let component: ArticleComponent;
7
+  let fixture: ComponentFixture<ArticleComponent>;
8
+
9
+  beforeEach(async(() => {
10
+    TestBed.configureTestingModule({
11
+      declarations: [ ArticleComponent ]
12
+    })
13
+    .compileComponents();
14
+  }));
15
+
16
+  beforeEach(() => {
17
+    fixture = TestBed.createComponent(ArticleComponent);
18
+    component = fixture.componentInstance;
19
+    fixture.detectChanges();
20
+  });
21
+
22
+  it('should create', () => {
23
+    expect(component).toBeTruthy();
24
+  });
25
+});

+ 21
- 0
client/src/app/news/article/article.component.ts View File

1
+import { Component, Input, OnInit } from '@angular/core';
2
+import * as moment from 'moment';
3
+
4
+@Component({
5
+	selector: 'app-article',
6
+	templateUrl: './article.component.html',
7
+	styleUrls: ['./article.component.css']
8
+})
9
+
10
+export class ArticleComponent implements OnInit {
11
+	@Input()articles;
12
+
13
+	constructor() { }
14
+
15
+	ngOnInit() {
16
+	}
17
+
18
+	computeDate(publishedAt) {
19
+		return moment(publishedAt).format('DD MMMM YYYY');
20
+	}
21
+}

+ 0
- 0
client/src/app/news/news.component.css View File


+ 2
- 0
client/src/app/news/news.component.html View File

1
+<p>news works!</p>
2
+<app-article *ngIf="news" [articles]="news"></app-article>

+ 25
- 0
client/src/app/news/news.component.spec.ts View File

1
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+import { NewsComponent } from './news.component';
4
+
5
+describe('NewsComponent', () => {
6
+  let component: NewsComponent;
7
+  let fixture: ComponentFixture<NewsComponent>;
8
+
9
+  beforeEach(async(() => {
10
+    TestBed.configureTestingModule({
11
+      declarations: [ NewsComponent ]
12
+    })
13
+    .compileComponents();
14
+  }));
15
+
16
+  beforeEach(() => {
17
+    fixture = TestBed.createComponent(NewsComponent);
18
+    component = fixture.componentInstance;
19
+    fixture.detectChanges();
20
+  });
21
+
22
+  it('should create', () => {
23
+    expect(component).toBeTruthy();
24
+  });
25
+});

+ 31
- 0
client/src/app/news/news.component.ts View File

1
+import { Component, Input, OnInit } from '@angular/core';
2
+import { NewsService } from '../news.service';
3
+
4
+@Component({
5
+	selector: 'app-news',
6
+	templateUrl: './news.component.html',
7
+	styleUrls: ['./news.component.css']
8
+})
9
+
10
+export class NewsComponent implements OnInit {
11
+	query: string;
12
+	news: any;
13
+
14
+	constructor(private newsService: NewsService) { }
15
+
16
+	ngOnInit() {
17
+	}
18
+
19
+	getNews() {
20
+		console.log(this.news);
21
+		this.newsService.getNews(this.query)
22
+			.subscribe(articles => {
23
+				this.news = articles;
24
+			});
25
+	}
26
+
27
+	displayNews() {
28
+
29
+	}
30
+
31
+}

+ 15
- 0
client/src/app/search.service.spec.ts View File

1
+import { TestBed, inject } from '@angular/core/testing';
2
+
3
+import { SearchService } from './search.service';
4
+
5
+describe('SearchService', () => {
6
+  beforeEach(() => {
7
+    TestBed.configureTestingModule({
8
+      providers: [SearchService]
9
+    });
10
+  });
11
+
12
+  it('should be created', inject([SearchService], (service: SearchService) => {
13
+    expect(service).toBeTruthy();
14
+  }));
15
+});

+ 17
- 0
client/src/app/search.service.ts View File

1
+import { Injectable } from '@angular/core';
2
+import { BehaviorSubject } from 'rxjs';
3
+
4
+@Injectable({
5
+	providedIn: 'root'
6
+})
7
+
8
+export class SearchService {
9
+	private query = new BehaviorSubject('');
10
+	currentQuery = this.query.asObservable();
11
+
12
+	constructor() { }
13
+
14
+	changeQuery(query: string) {
15
+		this.query.next(query);
16
+	}
17
+}

+ 0
- 0
client/src/app/search/search.component.css View File


+ 11
- 0
client/src/app/search/search.component.html View File

1
+<div class="columns">
2
+	<div class="column is-offset-4 is-4">
3
+		<div class="field">
4
+			<label>Ticker</label>
5
+			<div class="control">
6
+				<input [(ngModel)]="query" class="input" type="text" placeholder="Enter ticker" />
7
+			</div>
8
+			<button class="button" (click)="submit()">submit</button>
9
+		</div>
10
+	</div>
11
+</div>

+ 25
- 0
client/src/app/search/search.component.spec.ts View File

1
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+import { SearchComponent } from './search.component';
4
+
5
+describe('SearchComponent', () => {
6
+  let component: SearchComponent;
7
+  let fixture: ComponentFixture<SearchComponent>;
8
+
9
+  beforeEach(async(() => {
10
+    TestBed.configureTestingModule({
11
+      declarations: [ SearchComponent ]
12
+    })
13
+    .compileComponents();
14
+  }));
15
+
16
+  beforeEach(() => {
17
+    fixture = TestBed.createComponent(SearchComponent);
18
+    component = fixture.componentInstance;
19
+    fixture.detectChanges();
20
+  });
21
+
22
+  it('should create', () => {
23
+    expect(component).toBeTruthy();
24
+  });
25
+});

+ 24
- 0
client/src/app/search/search.component.ts View File

1
+import { Component, OnInit } from '@angular/core';
2
+
3
+import { SearchService } from '../search.service';
4
+
5
+@Component({
6
+	selector: 'app-search',
7
+	templateUrl: './search.component.html',
8
+	styleUrls: ['./search.component.css']
9
+})
10
+
11
+export class SearchComponent implements OnInit {
12
+	query: string;
13
+
14
+	constructor(
15
+		private searchService: SearchService,
16
+	) { }
17
+
18
+	ngOnInit() {
19
+	}
20
+
21
+	submit() {
22
+		this.searchService.setQuery(this.query);
23
+	}
24
+}

+ 15
- 0
client/src/app/stocks.service.spec.ts View File

1
+import { TestBed, inject } from '@angular/core/testing';
2
+
3
+import { StocksService } from './stocks.service';
4
+
5
+describe('StocksService', () => {
6
+  beforeEach(() => {
7
+    TestBed.configureTestingModule({
8
+      providers: [StocksService]
9
+    });
10
+  });
11
+
12
+  it('should be created', inject([StocksService], (service: StocksService) => {
13
+    expect(service).toBeTruthy();
14
+  }));
15
+});

+ 24
- 0
client/src/app/stocks.service.ts View File

1
+import { Injectable } from '@angular/core';
2
+import { HttpClient } from '@angular/common/http';
3
+
4
+import { SearchService } from './search.service';
5
+
6
+@Injectable({
7
+	providedIn: 'root'
8
+})
9
+
10
+export class StocksService {
11
+
12
+	constructor(
13
+		private http: HttpClient,
14
+		private searchService: SearchService
15
+	) { }
16
+
17
+	getStocks(ticker) {
18
+		return this.http.get(`/api/stocks?ticker=${ticker}`);
19
+	}
20
+
21
+	getSearch() {
22
+		console.log(this.searchService);
23
+	}
24
+}

+ 0
- 0
client/src/app/stocks/stocks.component.css View File


+ 3
- 0
client/src/app/stocks/stocks.component.html View File

1
+<p>
2
+  stocks works!
3
+</p>

+ 25
- 0
client/src/app/stocks/stocks.component.spec.ts View File

1
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2
+
3
+import { StocksComponent } from './stocks.component';
4
+
5
+describe('StocksComponent', () => {
6
+  let component: StocksComponent;
7
+  let fixture: ComponentFixture<StocksComponent>;
8
+
9
+  beforeEach(async(() => {
10
+    TestBed.configureTestingModule({
11
+      declarations: [ StocksComponent ]
12
+    })
13
+    .compileComponents();
14
+  }));
15
+
16
+  beforeEach(() => {
17
+    fixture = TestBed.createComponent(StocksComponent);
18
+    component = fixture.componentInstance;
19
+    fixture.detectChanges();
20
+  });
21
+
22
+  it('should create', () => {
23
+    expect(component).toBeTruthy();
24
+  });
25
+});

+ 15
- 0
client/src/app/stocks/stocks.component.ts View File

1
+import { Component, OnInit } from '@angular/core';
2
+
3
+@Component({
4
+  selector: 'app-stocks',
5
+  templateUrl: './stocks.component.html',
6
+  styleUrls: ['./stocks.component.css']
7
+})
8
+export class StocksComponent implements OnInit {
9
+
10
+  constructor() { }
11
+
12
+  ngOnInit() {
13
+  }
14
+
15
+}

+ 1
- 0
client/src/index.html View File

7
 
7
 
8
   <meta name="viewport" content="width=device-width, initial-scale=1">
8
   <meta name="viewport" content="width=device-width, initial-scale=1">
9
   <link rel="icon" type="image/x-icon" href="favicon.ico">
9
   <link rel="icon" type="image/x-icon" href="favicon.ico">
10
+	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.css" />
10
 </head>
11
 </head>
11
 <body>
12
 <body>
12
   <app-root></app-root>
13
   <app-root></app-root>

+ 1
- 1
client/tslint.json View File

23
     "import-spacing": true,
23
     "import-spacing": true,
24
     "indent": [
24
     "indent": [
25
       true,
25
       true,
26
-      "spaces"
26
+      "tabs"
27
     ],
27
     ],
28
     "interface-over-type-literal": true,
28
     "interface-over-type-literal": true,
29
     "label-position": true,
29
     "label-position": true,

+ 5
- 0
server/pom.xml View File

65
 			<scope>test</scope>
65
 			<scope>test</scope>
66
 		</dependency>
66
 		</dependency>
67
 
67
 
68
+		<dependency>
69
+			<groupId>org.springframework.boot</groupId>
70
+			<artifactId>spring-boot-devtools</artifactId>
71
+			<version>2.0.3.RELEASE</version>
72
+		</dependency>
68
 	</dependencies>
73
 	</dependencies>
69
 
74
 
70
 	<build>
75
 	<build>

+ 17
- 0
server/src/main/java/com/stockr/server/WebConfig.java View File

1
+package com.stockr.server;
2
+
3
+import org.springframework.context.annotation.Configuration;
4
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
5
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
6
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
7
+
8
+@Configuration
9
+@EnableWebMvc
10
+public class WebConfig implements WebMvcConfigurer {
11
+
12
+    @Override
13
+    public void addCorsMappings(CorsRegistry registry) {
14
+        registry.addMapping("/**")
15
+                .allowedOrigins("http://localhost:8081");
16
+    }
17
+}