Add discussion display
This commit is contained in:
parent
b029d38145
commit
f14b023c3a
10
frontend/src/app/_interfaces/customforumdata.ts
Normal file
10
frontend/src/app/_interfaces/customforumdata.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
export interface CustomForumData {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
discussions: [
|
||||||
|
{
|
||||||
|
title: string;
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
7
frontend/src/app/_interfaces/predictedposts.ts
Normal file
7
frontend/src/app/_interfaces/predictedposts.ts
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export interface PredictedPost {
|
||||||
|
author: string;
|
||||||
|
id: number;
|
||||||
|
label: string[];
|
||||||
|
message: string[];
|
||||||
|
para_id: number[];
|
||||||
|
}
|
@ -6,27 +6,25 @@ import { map } from 'rxjs/operators';
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
export class GetDiscussionService {
|
export class GetDiscussionService {
|
||||||
private discussionObservableCache$: {
|
private discussionObservableCache$: {
|
||||||
[id: string]: Observable<string>;
|
[id: string]: Observable<any>;
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
private discussionCache$: {
|
private discussionCache$: {
|
||||||
[id: string]: string;
|
[id: string]: any;
|
||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
constructor(private http: HttpClient) {}
|
constructor(private http: HttpClient) {}
|
||||||
|
|
||||||
getDiscussion(id: string): Observable<string> {
|
getDiscussion(id: string): Observable<any> {
|
||||||
if (this.discussionCache$[id]) {
|
if (this.discussionCache$[id]) {
|
||||||
console.log('Cached');
|
|
||||||
return of(this.discussionCache$[id]);
|
return of(this.discussionCache$[id]);
|
||||||
} else {
|
} else {
|
||||||
console.log('Not cached');
|
|
||||||
this.discussionObservableCache$[id] = this.requestDiscussion(id);
|
this.discussionObservableCache$[id] = this.requestDiscussion(id);
|
||||||
return this.discussionObservableCache$[id];
|
return this.discussionObservableCache$[id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private requestDiscussion(id: string): Observable<string> {
|
private requestDiscussion(id: string): Observable<any> {
|
||||||
return this.http
|
return this.http
|
||||||
.get<any>(`http://127.0.0.1:8000/discussions/${id}`)
|
.get<any>(`http://127.0.0.1:8000/discussions/${id}`)
|
||||||
.pipe(map((data) => this.mapData(id, data)));
|
.pipe(map((data) => this.mapData(id, data)));
|
||||||
|
@ -3,24 +3,23 @@ import {
|
|||||||
OnInit,
|
OnInit,
|
||||||
OnDestroy,
|
OnDestroy,
|
||||||
ChangeDetectionStrategy,
|
ChangeDetectionStrategy,
|
||||||
EventEmitter,
|
|
||||||
Output,
|
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { SharedDataService } from '../../_services/shared-data.service';
|
import { SharedDataService } from '../../_services/shared-data.service';
|
||||||
import { Colors } from '../../_types/color';
|
import { Colors } from '../../_types/color';
|
||||||
|
import { CustomForumData } from '../../_interfaces/customforumdata';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
import { NbMenuItem } from '@nebular/theme';
|
import { NbMenuItem } from '@nebular/theme';
|
||||||
|
|
||||||
interface CustomForumData {
|
// interface CustomForumData {
|
||||||
id: string;
|
// id: string;
|
||||||
name: string;
|
// name: string;
|
||||||
discussions: [
|
// discussions: [
|
||||||
{
|
// {
|
||||||
title: string;
|
// title: string;
|
||||||
id: string;
|
// id: string;
|
||||||
}
|
// }
|
||||||
];
|
// ];
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-discussion-chooser',
|
selector: 'app-discussion-chooser',
|
||||||
|
@ -1 +1,14 @@
|
|||||||
<div class="discussion-viewer"></div>
|
<div class="discussion-viewer">
|
||||||
|
<nb-card *ngFor="let item of data">
|
||||||
|
<nb-card-header>
|
||||||
|
{{ item.author }}
|
||||||
|
</nb-card-header>
|
||||||
|
<nb-card-body>
|
||||||
|
<app-styled-paragraph
|
||||||
|
*ngFor="let paragraph of item.message; let i = index"
|
||||||
|
[message]="paragraph"
|
||||||
|
[label]="item.label[i]"
|
||||||
|
></app-styled-paragraph>
|
||||||
|
</nb-card-body>
|
||||||
|
</nb-card>
|
||||||
|
</div>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute } from '@angular/router';
|
import { ActivatedRoute } from '@angular/router';
|
||||||
import { GetDiscussionService } from '../../_services/get-discussion.service';
|
import { GetDiscussionService } from '../../_services/get-discussion.service';
|
||||||
|
import { PredictedPost } from '../../_interfaces/predictedposts';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -9,7 +10,7 @@ import { Subscription } from 'rxjs';
|
|||||||
styleUrls: ['./discussion-viewer.component.scss'],
|
styleUrls: ['./discussion-viewer.component.scss'],
|
||||||
})
|
})
|
||||||
export class DiscussionViewerComponent implements OnInit {
|
export class DiscussionViewerComponent implements OnInit {
|
||||||
data: any;
|
data: PredictedPost[];
|
||||||
id: string;
|
id: string;
|
||||||
paramSub: Subscription;
|
paramSub: Subscription;
|
||||||
discussionSub: Subscription;
|
discussionSub: Subscription;
|
||||||
@ -22,11 +23,11 @@ export class DiscussionViewerComponent implements OnInit {
|
|||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.paramSub = this.router.params.subscribe((params) => {
|
this.paramSub = this.router.params.subscribe((params) => {
|
||||||
this.id = params.id;
|
this.id = params.id;
|
||||||
|
|
||||||
this.discussionSub = this.getDiscussionService
|
this.discussionSub = this.getDiscussionService
|
||||||
.getDiscussion(this.id)
|
.getDiscussion(this.id)
|
||||||
.subscribe((res) => {
|
.subscribe((res) => {
|
||||||
console.log(res);
|
this.data = res.posts;
|
||||||
|
console.log(this.data);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
import {
|
import { Component, AfterContentInit } from '@angular/core';
|
||||||
Component,
|
|
||||||
AfterViewInit,
|
|
||||||
ChangeDetectionStrategy,
|
|
||||||
} from '@angular/core';
|
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
import { SharedDataService } from '../_services/shared-data.service';
|
import { SharedDataService } from '../_services/shared-data.service';
|
||||||
@ -11,11 +7,10 @@ import { NbSidebarService, NbMenuItem } from '@nebular/theme';
|
|||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-main-view',
|
selector: 'app-main-view',
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
||||||
templateUrl: './main-view.component.html',
|
templateUrl: './main-view.component.html',
|
||||||
styleUrls: ['./main-view.component.scss'],
|
styleUrls: ['./main-view.component.scss'],
|
||||||
})
|
})
|
||||||
export class MainViewComponent implements AfterViewInit {
|
export class MainViewComponent implements AfterContentInit {
|
||||||
items: NbMenuItem[] = [
|
items: NbMenuItem[] = [
|
||||||
{
|
{
|
||||||
title: 'Dyskusje',
|
title: 'Dyskusje',
|
||||||
@ -36,7 +31,7 @@ export class MainViewComponent implements AfterViewInit {
|
|||||||
this.router.navigate(['/']);
|
this.router.navigate(['/']);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit(): void {
|
ngAfterContentInit(): void {
|
||||||
this.sharedDataService.getDiscussions().subscribe((res) => {
|
this.sharedDataService.getDiscussions().subscribe((res) => {
|
||||||
this.items[0].children = res;
|
this.items[0].children = res;
|
||||||
});
|
});
|
||||||
|
@ -15,12 +15,14 @@ import {
|
|||||||
} from '@nebular/theme';
|
} from '@nebular/theme';
|
||||||
import { DiscussionViewerComponent } from './discussion-viewer/discussion-viewer.component';
|
import { DiscussionViewerComponent } from './discussion-viewer/discussion-viewer.component';
|
||||||
import { GetDiscussionService } from '../_services/get-discussion.service';
|
import { GetDiscussionService } from '../_services/get-discussion.service';
|
||||||
|
import { StyledParagraphComponent } from './styled-paragraph/styled-paragraph.component';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
MainViewComponent,
|
MainViewComponent,
|
||||||
DiscussionChooserComponent,
|
DiscussionChooserComponent,
|
||||||
DiscussionViewerComponent,
|
DiscussionViewerComponent,
|
||||||
|
StyledParagraphComponent,
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
<span class="border paragraph" [ngClass]="label" [nbTooltip]="label">{{
|
||||||
|
message
|
||||||
|
}}</span>
|
@ -0,0 +1,30 @@
|
|||||||
|
@import "../../../themes";
|
||||||
|
|
||||||
|
.border {
|
||||||
|
border-width: medium;
|
||||||
|
border-style: solid;
|
||||||
|
padding: 4px;
|
||||||
|
-webkit-border-radius: 10px;
|
||||||
|
-moz-border-radius: 10px;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pozytywna {
|
||||||
|
border-color: nb-theme(color-success-100);
|
||||||
|
}
|
||||||
|
|
||||||
|
.negatywna {
|
||||||
|
border-color: nb-theme(color-danger-500);
|
||||||
|
}
|
||||||
|
|
||||||
|
.mieszana {
|
||||||
|
border-color: nb-theme(color-info-500);
|
||||||
|
}
|
||||||
|
|
||||||
|
.fakt {
|
||||||
|
border-color: orange;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nieistotna {
|
||||||
|
border-color: black;
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
import {
|
||||||
|
Component,
|
||||||
|
OnInit,
|
||||||
|
Input,
|
||||||
|
ChangeDetectionStrategy,
|
||||||
|
} from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-styled-paragraph',
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
|
templateUrl: './styled-paragraph.component.html',
|
||||||
|
styleUrls: ['./styled-paragraph.component.scss'],
|
||||||
|
})
|
||||||
|
export class StyledParagraphComponent implements OnInit {
|
||||||
|
@Input() message: string;
|
||||||
|
@Input() label: string;
|
||||||
|
constructor() {}
|
||||||
|
ngOnInit(): void {}
|
||||||
|
public getLabel() {
|
||||||
|
return this.label;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user