Remove dialog, add simple selector
This commit is contained in:
parent
b584298a26
commit
7e28b5aee4
4
frontend/src/app/_interfaces/labeldata.ts
Normal file
4
frontend/src/app/_interfaces/labeldata.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
export interface LabelData {
|
||||||
|
para_id: number;
|
||||||
|
label: string;
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { BehaviorSubject, Observable } from 'rxjs';
|
import { BehaviorSubject, Observable } from 'rxjs';
|
||||||
import { NbMenuItem } from '@nebular/theme';
|
import { NbMenuItem } from '@nebular/theme';
|
||||||
|
import { LabelData } from '../_interfaces/labeldata';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SharedDataService {
|
export class SharedDataService {
|
||||||
@ -8,6 +9,9 @@ export class SharedDataService {
|
|||||||
private discussionsBS: BehaviorSubject<NbMenuItem[]> = new BehaviorSubject(
|
private discussionsBS: BehaviorSubject<NbMenuItem[]> = new BehaviorSubject(
|
||||||
[] as NbMenuItem[]
|
[] as NbMenuItem[]
|
||||||
);
|
);
|
||||||
|
private paragraphsBS: BehaviorSubject<LabelData[]> = new BehaviorSubject(
|
||||||
|
[] as LabelData[]
|
||||||
|
);
|
||||||
|
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
@ -26,4 +30,21 @@ export class SharedDataService {
|
|||||||
public getData(): Observable<string> {
|
public getData(): Observable<string> {
|
||||||
return this.dataBS.asObservable();
|
return this.dataBS.asObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public addParagraph(paragraph: LabelData) {
|
||||||
|
const paragraphs = this.paragraphsBS.getValue();
|
||||||
|
console.log(paragraphs);
|
||||||
|
if (paragraphs.find((p) => p.para_id === paragraph.para_id)) {
|
||||||
|
const updatedParagraphs = paragraphs.map((element) => {
|
||||||
|
if (element.para_id === paragraph.para_id) {
|
||||||
|
element.label = paragraph.label;
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
});
|
||||||
|
this.paragraphsBS.next(updatedParagraphs);
|
||||||
|
} else {
|
||||||
|
paragraphs.push(paragraph);
|
||||||
|
this.paragraphsBS.next(paragraphs);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,22 @@
|
|||||||
<div class="discussion-viewer">
|
<div class="discussion-viewer">
|
||||||
<nb-card *ngFor="let item of data">
|
<div class="discussion-viewer__buttons-container">
|
||||||
<nb-card-header>
|
<button nbButton status="primary" class="discussion-viewer__save-button">
|
||||||
{{ item.author }}
|
Zapisz zmiany
|
||||||
</nb-card-header>
|
</button>
|
||||||
<nb-card-body>
|
</div>
|
||||||
<div class="discussion-viewer__container">
|
<div class="discussion-viewer__posts-container">
|
||||||
|
<nb-card *ngFor="let item of data">
|
||||||
|
<nb-card-header>
|
||||||
|
{{ item.author }}
|
||||||
|
</nb-card-header>
|
||||||
|
<nb-card-body>
|
||||||
<app-styled-paragraph
|
<app-styled-paragraph
|
||||||
*ngFor="let paragraph of item.message; let i = index"
|
*ngFor="let paragraph of item.message; let i = index"
|
||||||
[message]="paragraph"
|
[message]="paragraph"
|
||||||
[loadedLabel]="item.label[i]"
|
[loadedLabel]="item.label[i]"
|
||||||
|
[paragraphId]="item.para_id[i]"
|
||||||
></app-styled-paragraph>
|
></app-styled-paragraph>
|
||||||
</div>
|
</nb-card-body>
|
||||||
</nb-card-body>
|
</nb-card>
|
||||||
</nb-card>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
.discussion-viewer {
|
||||||
|
display: flex;
|
||||||
|
flex-flow: column nowrap;
|
||||||
|
}
|
@ -5,6 +5,10 @@ import { MainViewComponent } from './main-view.component';
|
|||||||
import { DiscussionChooserComponent } from './discussion-chooser/discussion-chooser.component';
|
import { DiscussionChooserComponent } from './discussion-chooser/discussion-chooser.component';
|
||||||
import { MainViewRoutingModule } from './main-view-routing.module';
|
import { MainViewRoutingModule } from './main-view-routing.module';
|
||||||
|
|
||||||
|
import { DiscussionViewerComponent } from './discussion-viewer/discussion-viewer.component';
|
||||||
|
import { GetDiscussionService } from '../_services/get-discussion.service';
|
||||||
|
import { StyledParagraphComponent } from './styled-paragraph/styled-paragraph.component';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
NbLayoutModule,
|
NbLayoutModule,
|
||||||
NbActionsModule,
|
NbActionsModule,
|
||||||
@ -13,13 +17,9 @@ import {
|
|||||||
NbCardModule,
|
NbCardModule,
|
||||||
NbMenuModule,
|
NbMenuModule,
|
||||||
NbButtonModule,
|
NbButtonModule,
|
||||||
NbDialogModule,
|
|
||||||
NbSelectModule,
|
NbSelectModule,
|
||||||
} from '@nebular/theme';
|
} from '@nebular/theme';
|
||||||
import { DiscussionViewerComponent } from './discussion-viewer/discussion-viewer.component';
|
|
||||||
import { GetDiscussionService } from '../_services/get-discussion.service';
|
|
||||||
import { StyledParagraphComponent } from './styled-paragraph/styled-paragraph.component';
|
|
||||||
import { FormsModule } from '@angular/forms';
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
MainViewComponent,
|
MainViewComponent,
|
||||||
@ -37,7 +37,6 @@ import { FormsModule } from '@angular/forms';
|
|||||||
NbCardModule,
|
NbCardModule,
|
||||||
NbMenuModule,
|
NbMenuModule,
|
||||||
NbButtonModule,
|
NbButtonModule,
|
||||||
NbDialogModule.forChild(),
|
|
||||||
NbSelectModule,
|
NbSelectModule,
|
||||||
],
|
],
|
||||||
providers: [GetDiscussionService],
|
providers: [GetDiscussionService],
|
||||||
|
@ -6,43 +6,13 @@
|
|||||||
>
|
>
|
||||||
{{ message }}
|
{{ message }}
|
||||||
</span>
|
</span>
|
||||||
<button nbButton (click)="openDialog(editLabel)" size="small">
|
<nb-select
|
||||||
Edytuj etykietę
|
placeholder="Wybierz etykietę"
|
||||||
</button>
|
(selectedChange)="fetchLabel($event, paragraphId)"
|
||||||
|
[selected]="loadedLabel"
|
||||||
|
>
|
||||||
|
<nb-option *ngFor="let _label of availableLabels" [value]="_label">{{
|
||||||
|
_label
|
||||||
|
}}</nb-option>
|
||||||
|
</nb-select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ng-template #editLabel>
|
|
||||||
<nb-card class="dialog">
|
|
||||||
<nb-card-header>Edytuj etykietę</nb-card-header>
|
|
||||||
<nb-card-body class="dialog__body">
|
|
||||||
<div class="dialog__element">
|
|
||||||
<label class="label">Paragraf</label>
|
|
||||||
<span class="paragraph dialog__message">{{ message }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="dialog__element">
|
|
||||||
<label class="label">Etykieta</label>
|
|
||||||
<nb-select placeholder="Wybierz etykietę" [(selected)]="selectedLabel">
|
|
||||||
<nb-option
|
|
||||||
*ngFor="let _label of availableLabels"
|
|
||||||
[value]="_label"
|
|
||||||
[disabled]="loadedLabel === _label"
|
|
||||||
>{{ _label }}</nb-option
|
|
||||||
>
|
|
||||||
</nb-select>
|
|
||||||
</div>
|
|
||||||
<div class="dialog__buttons">
|
|
||||||
<button
|
|
||||||
nbButton
|
|
||||||
status="success"
|
|
||||||
(click)="updateLabel($event, selectedLabel)"
|
|
||||||
[disabled]="selectedLabel === loadedLabel || selectedLabel === ''"
|
|
||||||
>
|
|
||||||
Zapisz
|
|
||||||
</button>
|
|
||||||
<button nbButton status="danger" (click)="closeDialog(editLabel)">
|
|
||||||
Anuluj
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</nb-card-body>
|
|
||||||
</nb-card>
|
|
||||||
</ng-template>
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Component, Input, TemplateRef } from '@angular/core';
|
import { Component, Input } from '@angular/core';
|
||||||
import { NbDialogService, NbDialogRef } from '@nebular/theme';
|
import { SharedDataService } from '../../_services/shared-data.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-styled-paragraph',
|
selector: 'app-styled-paragraph',
|
||||||
@ -9,6 +9,7 @@ import { NbDialogService, NbDialogRef } from '@nebular/theme';
|
|||||||
export class StyledParagraphComponent {
|
export class StyledParagraphComponent {
|
||||||
@Input() message: string;
|
@Input() message: string;
|
||||||
@Input() loadedLabel: string;
|
@Input() loadedLabel: string;
|
||||||
|
@Input() paragraphId: number;
|
||||||
availableLabels: string[] = [
|
availableLabels: string[] = [
|
||||||
'pozytywna',
|
'pozytywna',
|
||||||
'negatywna',
|
'negatywna',
|
||||||
@ -16,20 +17,14 @@ export class StyledParagraphComponent {
|
|||||||
'fakt',
|
'fakt',
|
||||||
'nieistotna',
|
'nieistotna',
|
||||||
];
|
];
|
||||||
dialogRef: NbDialogRef<any>;
|
|
||||||
selectedLabel = '';
|
selectedLabel = '';
|
||||||
|
|
||||||
constructor(private dialogService: NbDialogService) {}
|
constructor(private sharedDataService: SharedDataService) {}
|
||||||
|
|
||||||
public openDialog(ref: TemplateRef<any>) {
|
fetchLabel(label: any, id: number) {
|
||||||
this.dialogRef = this.dialogService.open(ref);
|
this.sharedDataService.addParagraph({
|
||||||
}
|
para_id: id,
|
||||||
|
label,
|
||||||
public closeDialog(ref: TemplateRef<any>) {
|
});
|
||||||
this.dialogRef.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public updateLabel(event: any, label: string) {
|
|
||||||
console.log(label);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user