Skip to content

Commit c320ded

Browse files
committed
OCP-DEMO Invoke full-text query on body message
1 parent 23ff018 commit c320ded

File tree

6 files changed

+94
-0
lines changed

6 files changed

+94
-0
lines changed

openshift/message-board/message-board-web/src/app/app-routing.module.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {CommonModule} from '@angular/common';
44

55
import {MessageComponent} from './message/message.component';
66
import {TagComponent} from './tag/tag.component';
7+
import {TermComponent} from './term/term.component';
78
import {TimeComponent} from './time/time.component';
89
import {CreateAccountComponent} from './create-account/create-account.component';
910

@@ -14,6 +15,8 @@ const routes: Routes = [
1415
{ path: 'createAccount', component: CreateAccountComponent },
1516
{ path: 'tag', component: TagComponent },
1617
{ path: 'tag/:tag', component: TagComponent },
18+
{ path: 'term', component: TermComponent },
19+
{ path: 'term/:term', component: TermComponent },
1720
{ path: 'time', component: TimeComponent }
1821
];
1922

openshift/message-board/message-board-web/src/app/app.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
<li class="nav-item" routerLinkActive="active">
1010
<a class="nav-link" routerLink="/tag">Search by Tag</a>
1111
</li>
12+
<li class="nav-item" routerLinkActive="active">
13+
<a class="nav-link" routerLink="/term">Search by Term</a>
14+
</li>
1215
<li class="nav-item" routerLinkActive="active">
1316
<a class="nav-link" routerLink="/time">Search by Time</a>
1417
</li>

openshift/message-board/message-board-web/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { PostMessageComponent } from './post-message/post-message.component';
1919
import { MessageComponent } from './message/message.component';
2020
import { EventComponent } from './event/event.component';
2121
import { TagComponent } from './tag/tag.component';
22+
import { TermComponent } from './term/term.component';
2223
import { TimeComponent } from './time/time.component';
2324

2425
@NgModule({
@@ -37,6 +38,7 @@ import { TimeComponent } from './time/time.component';
3738
MessageComponent,
3839
EventComponent,
3940
TagComponent,
41+
TermComponent,
4042
TimeComponent
4143
],
4244
providers: [MessageService, AccountService, EventService, WebSocketService],

openshift/message-board/message-board-web/src/app/message.service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ export class MessageService {
3838
.pipe( catchError( this.handleError<Message[]>('findMessagesByTag', []) ) );
3939
}
4040

41+
findMessagesByTerm(term: string): Observable<Message[]> {
42+
if (!term || !term.trim()) {
43+
// if not search term, return empty message array.
44+
return of([]);
45+
}
46+
return this.http.get<Message[]>(`message-service/messages/term/${term}`)
47+
.pipe( catchError( this.handleError<Message[]>('findMessagesByTerm', []) ) );
48+
}
49+
4150
findMessagesByTime(startDate: NgbDateStruct, endDate: NgbDateStruct, startTime: NgbTimeStruct, endTime: NgbTimeStruct): Observable<Message[]> {
4251
if (!startDate || !endDate || !startTime || !endTime) {
4352
return of([]);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<div class="container-fluid">
2+
<div class="row">
3+
<div class="col-lg-3">
4+
<div class="float-right">
5+
<label>Term:
6+
<input [(ngModel)]="term" placeholder="term">
7+
</label>
8+
</div>
9+
</div>
10+
<div class="col-lg-9">
11+
<div class="container-fluid">
12+
<div *ngFor="let message of messages" class="container-fluid">
13+
<div class="card">
14+
<div class="card-body">
15+
<p class="card-text">{{ message.body }}</p>
16+
<div class="row">
17+
<div class="col-lg-2">
18+
<a routerLink="/message/{{message.username}}" class="card-link text-danger">{{ message.username }}</a>
19+
</div>
20+
<div class="col-lg-5">
21+
<span class="card-text text-success">{{ message.moment }}</span>
22+
</div>
23+
<div class="col-lg-5">
24+
<a *ngFor="let tag of message.tags" (click)="onSelect(tag)" routerLink="/tag/{{tag.name}}" class="card-link text-info">{{ tag.name }}</a>
25+
</div>
26+
</div>
27+
</div>
28+
</div>
29+
</div>
30+
</div>
31+
</div>
32+
</div>
33+
</div>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { Component, OnInit, Input } from '@angular/core';
2+
import { ActivatedRoute } from '@angular/router';
3+
4+
import { Message } from '../message';
5+
import { MessageService } from '../message.service';
6+
7+
@Component({
8+
selector: 'app-term',
9+
templateUrl: './term.component.html'
10+
})
11+
export class TermComponent implements OnInit {
12+
13+
private _term: string;
14+
15+
messages: Message[];
16+
17+
constructor( private route: ActivatedRoute, private service: MessageService ) { }
18+
19+
ngOnInit() {
20+
this.term = this.route.snapshot.paramMap.get('term');
21+
}
22+
23+
get term(): string {
24+
return this._term;
25+
}
26+
27+
@Input()
28+
set term(term: string) {
29+
this._term = term;
30+
this.getMessages();
31+
}
32+
33+
getMessages(): void {
34+
this.service.findMessagesByTerm(this.term)
35+
.subscribe(messages => {
36+
this.messages = messages;
37+
console.log(messages);
38+
});
39+
}
40+
41+
onSelect(term: string): void {
42+
this.term = term;
43+
}
44+
}

0 commit comments

Comments
 (0)