|
1 |
| -import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; |
2 |
| -import { UntypedFormControl, Validators, ReactiveFormsModule } from '@angular/forms'; |
3 |
| -import { Topic } from 'src/app/services/pubsub.service'; |
| 1 | +import { CdkTextareaAutosize } from '@angular/cdk/text-field'; |
| 2 | +import { Component, EventEmitter, inject, Input, OnInit, Output } from '@angular/core'; |
| 3 | +import { ReactiveFormsModule, UntypedFormControl, Validators } from '@angular/forms'; |
4 | 4 | import { MatButton } from '@angular/material/button';
|
5 |
| -import { MatIcon } from '@angular/material/icon'; |
| 5 | +import { MatDialog } from '@angular/material/dialog'; |
6 | 6 | import { MatFormField } from '@angular/material/form-field';
|
| 7 | +import { MatIcon } from '@angular/material/icon'; |
7 | 8 | import { MatInput } from '@angular/material/input';
|
8 |
| -import { CdkTextareaAutosize } from '@angular/cdk/text-field'; |
| 9 | +import { Topic } from 'src/app/services/pubsub.service'; |
| 10 | +import { AttributeEditorComponent } from './attribute-editor/attribute-editor.component'; |
9 | 11 |
|
10 | 12 | @Component({
|
11 |
| - selector: 'app-topic-details', |
12 |
| - templateUrl: './topic-details.component.html', |
13 |
| - styleUrls: ['./topic-details.component.scss'], |
14 |
| - standalone: true, |
15 |
| - imports: [MatButton, MatIcon, MatFormField, MatInput, CdkTextareaAutosize, ReactiveFormsModule] |
| 13 | + selector: 'app-topic-details', |
| 14 | + templateUrl: './topic-details.component.html', |
| 15 | + styleUrls: ['./topic-details.component.scss'], |
| 16 | + standalone: true, |
| 17 | + imports: [MatButton, MatIcon, MatFormField, MatInput, CdkTextareaAutosize, ReactiveFormsModule] |
16 | 18 | })
|
17 | 19 | export class TopicDetailsComponent implements OnInit {
|
18 | 20 |
|
19 | 21 | @Input() topic?: Topic
|
| 22 | + @Output() onMessagePublish = new EventEmitter<{ topic: Topic, message: string, attributes: { [key: string]: string } }>() |
20 | 23 |
|
21 |
| - @Output() onMessagePublish = new EventEmitter<{ topic: Topic, message: string }>() |
22 |
| - |
| 24 | + _dialog = inject(MatDialog) |
23 | 25 | public inputField = new UntypedFormControl('', Validators.required)
|
| 26 | + attributes: { [key: string]: string } = {} |
| 27 | + attributeCount = 0 |
24 | 28 | constructor() { }
|
25 | 29 |
|
26 | 30 | ngOnInit(): void {
|
27 | 31 | }
|
28 | 32 |
|
| 33 | + editAttributes() { |
| 34 | + let dialogRef = this._dialog.open(AttributeEditorComponent, { data: { attributes: this.attributes } }) |
| 35 | + |
| 36 | + dialogRef.afterClosed().subscribe(result => { |
| 37 | + if (result) { |
| 38 | + this.attributes = result |
| 39 | + this.attributeCount = Object.keys(this.attributes).length |
| 40 | + } |
| 41 | + }) |
| 42 | + } |
| 43 | + |
29 | 44 | publishMessage() {
|
30 | 45 | console.log("this value was found", this.inputField.value)
|
31 | 46 |
|
32 |
| - this.onMessagePublish.emit({ topic: this.topic!, message: this.inputField.value }) |
| 47 | + this.onMessagePublish.emit({ topic: this.topic!, message: this.inputField.value, attributes: this.attributes }) |
33 | 48 | this.inputField.reset()
|
| 49 | + this.attributes = {} |
| 50 | + this.attributeCount = 0 |
34 | 51 | }
|
35 | 52 |
|
36 | 53 | }
|
0 commit comments