Skip to content
This repository was archived by the owner on Jun 22, 2021. It is now read-only.

Commit fcb5108

Browse files
committed
talk - client
1 parent 3207a59 commit fcb5108

46 files changed

Lines changed: 814 additions & 107 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ElectronNetAngular/ClientApp/app/app.shared.module.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ import { NgModule } from "@angular/core";
44
import { MatSidenavModule } from "@angular/material";
55
import { RouterModule } from "@angular/router";
66
import { CoreModule } from "@dotnetru/core";
7-
import { SpeakerEditorModule } from "@dotnetru/speaker-editor";
7+
import { SearchPageModule } from "@dotnetru/pages/search";
8+
import { SpeakerEditorModule } from "@dotnetru/pages/speaker-editor";
9+
import { TalkEditorModule } from "@dotnetru/pages/talk-editor";
10+
import { AutocompleteModule } from "@dotnetru/shared/autocomplete";
811
import { SpeakerListModule } from "@dotnetru/speaker-list";
912

1013
import { AppComponent } from "./app.component";
11-
import { HomeComponent } from "./components/home/home.component";
1214
import { NavMenuModule } from "./components/navmenu/navmenu.module";
1315
import { ToolbarModule } from "./components/toolbar/toolbar.module";
16+
import { SearchPageComponent } from "./pages/search/search.component";
1417

1518
@NgModule({
1619
declarations: [
1720
AppComponent,
18-
HomeComponent,
1921
],
2022
imports: [
2123
CommonModule,
@@ -26,14 +28,21 @@ import { ToolbarModule } from "./components/toolbar/toolbar.module";
2628
NavMenuModule,
2729

2830
CoreModule,
31+
32+
AutocompleteModule,
33+
2934
SpeakerEditorModule,
3035
SpeakerListModule,
36+
37+
TalkEditorModule,
38+
39+
SearchPageModule,
40+
3141
RouterModule.forRoot([
32-
{ path: "", redirectTo: "home", pathMatch: "full" },
33-
{ path: "home", component: HomeComponent },
34-
{ path: "**", redirectTo: "home" },
42+
{ path: "", redirectTo: "search", pathMatch: "full" },
43+
{ path: "search", component: SearchPageComponent },
44+
{ path: "**", redirectTo: "search" },
3545
]),
3646
],
3747
})
38-
export class AppModuleShared {
39-
}
48+
export class AppModuleShared { }

ElectronNetAngular/ClientApp/app/components/home/home.component.html

Lines changed: 0 additions & 2 deletions
This file was deleted.

ElectronNetAngular/ClientApp/app/components/home/home.component.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

ElectronNetAngular/ClientApp/app/components/speaker-list/speaker-list.component.css

Whitespace-only changes.
Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,7 @@
1-
<div class="base-component-container">
2-
3-
<mat-form-field class="full-width">
4-
<input type="text"
5-
placeholder="Поиск спикера"
6-
matInput
7-
[formControl]="speakersControl"
8-
[matAutocomplete]="auto">
9-
10-
<mat-autocomplete autoActiveFirstOption
11-
#auto="matAutocomplete"
12-
(optionSelected)="onSelected($event.option.value)">
13-
<mat-option *ngFor="let speaker of speakers$ | async"
14-
[value]="speaker">
15-
{{ speaker.name }}
16-
</mat-option>
17-
</mat-autocomplete>
18-
19-
<a [routerLink]="['/speaker-creator']"
20-
color="primary"
21-
mat-button
22-
matSuffix>
23-
<mat-icon>add</mat-icon>
24-
<span>Добавить</span>
25-
</a>
26-
27-
</mat-form-field>
28-
29-
</div>
1+
<mtp-autocomplete #autocomplete
2+
[title]="title"
3+
[data]="speakers"
4+
[iconName]="iconName"
5+
[iconText]="iconText"
6+
(selected)="onSelected($event)"
7+
(iconClicked)="onIconClicked()"></mtp-autocomplete>
Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,70 @@
1-
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit } from "@angular/core";
2-
import { FormBuilder, FormControl } from "@angular/forms";
3-
import { Router } from "@angular/router";
4-
import { Observable, Subscription } from "rxjs";
5-
import { debounceTime, filter, map } from "rxjs/operators";
1+
import {
2+
ChangeDetectionStrategy,
3+
ChangeDetectorRef,
4+
Component,
5+
EventEmitter,
6+
Input,
7+
OnDestroy,
8+
OnInit,
9+
Output,
10+
ViewChild,
11+
} from "@angular/core";
12+
import { AutocompleteComponent, IAutocompleteRow } from "@dotnetru/shared/autocomplete";
13+
import { BehaviorSubject, Subscription } from "rxjs";
14+
import { debounceTime, switchMap } from "rxjs/operators";
615

7-
import { ISpeakerRow } from "./interfaces";
816
import { SpeakerListService } from "./speaker-list.service";
917

1018
@Component({
1119
changeDetection: ChangeDetectionStrategy.OnPush,
1220
selector: "mtp-speaker-list",
13-
styleUrls: ["./speaker-list.component.css"],
1421
templateUrl: "./speaker-list.component.html",
1522
})
1623
export class SpeakerListComponent implements OnInit, OnDestroy {
17-
public speakers: ISpeakerRow[] = [];
18-
public speakers$: Observable<ISpeakerRow[]>;
19-
public speakersControl: FormControl;
24+
@Input() public title: string = "Поиск спикера";
25+
@Input() public iconName: string = "add";
26+
@Input() public iconText: string = "Добавить";
2027

28+
@Input() public set speakerLink(value: { speakerId?: string }) {
29+
if (value && value.speakerId) {
30+
this._speakerId$.next(value.speakerId);
31+
}
32+
}
33+
34+
@ViewChild("autocomplete") public autocomplete!: AutocompleteComponent;
35+
36+
@Output() public readonly selected: EventEmitter<IAutocompleteRow> = new EventEmitter<IAutocompleteRow>();
37+
@Output() public readonly iconClicked: EventEmitter<void> = new EventEmitter<void>();
38+
39+
public speakers: IAutocompleteRow[] = [];
40+
41+
private _speakerId$: BehaviorSubject<string> = new BehaviorSubject("");
2142
private _subs: Subscription[] = [];
2243

2344
constructor(
2445
private _speakerListService: SpeakerListService,
25-
private _router: Router,
2646
private _changeDetectorRef: ChangeDetectorRef,
27-
fb: FormBuilder,
28-
) {
29-
this.speakersControl = fb.control(undefined);
30-
this.speakers$ = this.speakersControl.valueChanges
31-
.pipe(
32-
filter((val) => typeof val === "string"),
33-
debounceTime(300),
34-
map((query: string) => {
35-
const searchPhrases: string[] = (query || "")
36-
.toLowerCase()
37-
.replace(/\s+/, " ")
38-
.split(" ")
39-
.map((x) => x.replace(/[^а-яёa-z\d]/gi, ""));
40-
return this.speakers.filter((x) => {
41-
const lowerName: string = x.name.toLowerCase();
42-
let ix: number = 0;
43-
for (const searchPhrase of searchPhrases) {
44-
// important order
45-
ix = lowerName/* .substring(ix) */.indexOf(searchPhrase);
46-
if (ix < 0) {
47-
return false;
48-
}
49-
}
50-
51-
return true;
52-
});
53-
}),
54-
);
55-
}
47+
) { }
5648

5749
public ngOnInit(): void {
5850
this._subs = [
5951
this._speakerListService.speakers$
6052
.subscribe(
61-
(speakers: ISpeakerRow[]) => {
53+
(speakers: IAutocompleteRow[]) => {
6254
this.speakers = speakers;
63-
this.speakersControl.setValue("");
6455
this._changeDetectorRef.detectChanges();
6556
},
66-
(error) => console.warn(error),
6757
),
58+
this._speakerListService.speakers$.pipe(switchMap((_) => this._speakerId$.pipe()))
59+
.pipe(debounceTime(100))
60+
.subscribe((speakerId: string) => {
61+
const speaker = this.speakers.find((x) => x.id === speakerId);
62+
if (speaker) {
63+
this.autocomplete.queryControl.patchValue(speaker.name);
64+
} else {
65+
console.warn("speaker not found", speakerId);
66+
}
67+
}),
6868
];
6969

7070
this._speakerListService.fetchSpeakers();
@@ -74,7 +74,11 @@ export class SpeakerListComponent implements OnInit, OnDestroy {
7474
this._subs.forEach((x) => x.unsubscribe());
7575
}
7676

77-
public onSelected(speaker: ISpeakerRow): void {
78-
this._router.navigateByUrl(`speaker-editor/${speaker.id}`);
77+
public onSelected(row: IAutocompleteRow): void {
78+
this.selected.emit(row);
79+
}
80+
81+
public onIconClicked(): void {
82+
this.iconClicked.emit();
7983
}
8084
}

ElectronNetAngular/ClientApp/app/components/speaker-list/speaker-list.module.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
MatIconModule,
99
MatInputModule,
1010
} from "@angular/material";
11-
import { RouterModule } from "@angular/router";
11+
import { AutocompleteModule } from "@dotnetru/shared/autocomplete";
1212

1313
import { SpeakerListComponent } from "./speaker-list.component";
1414
import { SpeakerListService } from "./speaker-list.service";
@@ -24,12 +24,11 @@ import { SpeakerListService } from "./speaker-list.service";
2424
SpeakerListComponent,
2525
],
2626
imports: [
27-
RouterModule.forChild([
28-
{ path: "speaker-list", component: SpeakerListComponent },
29-
]),
3027
CommonModule,
3128
ReactiveFormsModule,
3229

30+
AutocompleteModule,
31+
3332
MatAutocompleteModule,
3433
MatButtonModule,
3534
MatFormFieldModule,

ElectronNetAngular/ClientApp/app/components/speaker-list/speaker-list.service.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { API_ENDPOINTS, HttpService } from "@dotnetru/core";
33
import { BehaviorSubject, Observable } from "rxjs";
44
import { filter } from "rxjs/operators";
55

6-
import { ISpeakerRow } from "./interfaces";
6+
import { IAutocompleteRow } from "@dotnetru/shared/autocomplete";
77

88
@Injectable()
99
export class SpeakerListService {
10-
private _speakers$: BehaviorSubject<ISpeakerRow[]> = new BehaviorSubject<ISpeakerRow[]>([]);
10+
private _speakers$: BehaviorSubject<IAutocompleteRow[]> = new BehaviorSubject<IAutocompleteRow[]>([]);
1111

12-
public get speakers$(): Observable<ISpeakerRow[]> {
12+
public get speakers$(): Observable<IAutocompleteRow[]> {
1313
return this._speakers$.pipe(filter((x) => x.length > 0));
1414
}
1515

@@ -18,9 +18,9 @@ export class SpeakerListService {
1818
) { }
1919

2020
public fetchSpeakers(): void {
21-
this._httpService.get<ISpeakerRow[]>(
21+
this._httpService.get<IAutocompleteRow[]>(
2222
API_ENDPOINTS.getSpeakersUrl,
23-
(speakers: ISpeakerRow[]) => this._speakers$.next(speakers),
23+
(speakers: IAutocompleteRow[]) => this._speakers$.next(speakers),
2424
);
2525
}
2626
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { TalkListComponent } from "./talk-list.component";
2+
export { TalkListModule } from "./talk-list.module";
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<mtp-autocomplete #autocomplete
2+
[title]="title"
3+
[data]="talks"
4+
[iconName]="iconName"
5+
[iconText]="iconText"
6+
(selected)="onSelected($event)"
7+
(iconClicked)="onIconClicked()"></mtp-autocomplete>

0 commit comments

Comments
 (0)