-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
the data from app component is now passed correctly from app to dialo…
…g, which opens correctly
- Loading branch information
Showing
8 changed files
with
143 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,63 @@ | ||
import { Component } from '@angular/core'; | ||
import {Component, OnDestroy} from '@angular/core'; | ||
import {ArticleService} from "./ArticleService"; | ||
import {ArticleDialogComponent} from "./article-dialog/aricle-dialog.component"; | ||
import {DialogService, DynamicDialogRef} from "primeng/dynamicdialog"; | ||
import {ArticleDisplayComponent} from "./article-display/article-display.component"; | ||
import {Article} from "./Interfaces"; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
template: ` | ||
<p-dataView [value]="articleService.articles"> | ||
<p-dataView #dv [value]="articleService.articles"> | ||
<ng-template let-article pTemplate="listItem"> | ||
<div class="col-12"> | ||
<p>{{article.headline}}</p> | ||
<div class="flex flex-column xl:flex-row xl:align-items-start p-4 gap-4"> | ||
<img class="w-9 sm:w-16rem xl:w-10rem shadow-2 block xl:block mx-auto border-round" | ||
[src]="article.articleImgUrl" [alt]="article.headline"/> | ||
<div | ||
class="flex flex-column sm:flex-row justify-content-between align-items-center xl:align-items-start flex-1 gap-4"> | ||
<div class="flex flex-column align-items-center sm:align-items-start gap-3"> | ||
<div class="text-2xl font-bold text-900">{{ article.headline }}</div> | ||
<div class="flex align-items-center gap-3"> {{ article.body }}</div> | ||
</div> | ||
<div class="flex flex-column align-items-center sm:align-items-start gap-3"> | ||
<p-button (onClick)="showArticleDialog(article.articleId)">Show more</p-button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</ng-template> | ||
</p-dataView>`, | ||
styleUrls: ['./app.component.css'] | ||
}) | ||
export class AppComponent { | ||
export class AppComponent implements OnDestroy { | ||
title = 'NewsfeedFrontend'; | ||
ref: DynamicDialogRef | undefined; | ||
article: Article | undefined; | ||
|
||
constructor(public articleService: ArticleService, private dialogService: DialogService) { | ||
|
||
constructor(public articleService: ArticleService) { | ||
} | ||
|
||
ngOnDestroy(): void { | ||
if (this.ref) { | ||
this.ref.close(); | ||
} | ||
} | ||
|
||
async showArticleDialog(articleId: number) { | ||
this.article = await this.articleService.getArticle(articleId); | ||
this.ref = this.dialogService.open( ArticleDisplayComponent, { | ||
data: { | ||
articleId: this.article.articleId, | ||
}, | ||
header: 'Article', | ||
width: '70%', | ||
contentStyle: {'max-height': '70%', 'overflow': 'auto'}, | ||
baseZIndex: 10000, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
NewsfeedFrontend/src/app/article-dialog/aricle-dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Component, OnDestroy } from '@angular/core'; | ||
import { DialogService, DynamicDialogRef } from 'primeng/dynamicdialog'; | ||
import {ArticleService} from "../ArticleService"; | ||
import {Article} from "../Interfaces"; | ||
import {ArticleDisplayComponent} from "../article-display/article-display.component"; | ||
|
||
@Component({ | ||
template: `<p>{{article?.headline}}</p>`, | ||
providers: [DialogService, ArticleService] | ||
}) | ||
export class ArticleDialogComponent implements OnDestroy { | ||
article: Article | undefined; | ||
ref: DynamicDialogRef | undefined; | ||
|
||
constructor(private dialogService: DialogService, private articleService : ArticleService) { | ||
//TODO: figure out how to call this from the parent component | ||
|
||
|
||
} | ||
|
||
ngOnDestroy(): void { | ||
if (this.ref) { | ||
this.ref.close(); | ||
} | ||
} | ||
|
||
async show(articleId: number) { | ||
this.article = await this.articleService.getArticle(articleId); | ||
this.ref = this.dialogService.open( ArticleDisplayComponent, { header: 'Article', width: '70%', contentStyle: {'max-height': '500px', 'overflow': 'auto'}, baseZIndex: 10000 }); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
NewsfeedFrontend/src/app/article-dialog/article-dialog.component.specs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {ComponentFixture, TestBed} from "@angular/core/testing"; | ||
import {ArticleDialogComponent} from "./aricle-dialog.component"; | ||
|
||
describe('ArticleDialogComponent', () => { | ||
let component: ArticleDialogComponent; | ||
let fixture: ComponentFixture<ArticleDialogComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ArticleDialogComponent] | ||
}); | ||
fixture = TestBed.createComponent(ArticleDialogComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
34 changes: 22 additions & 12 deletions
34
NewsfeedFrontend/src/app/article-display/article-display.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,31 @@ | ||
import { Component } from '@angular/core'; | ||
import {Component, Input, OnInit} from '@angular/core'; | ||
import {ArticleService} from "../ArticleService"; | ||
import {Article} from "../Interfaces"; | ||
import {DynamicDialogConfig} from "primeng/dynamicdialog"; | ||
|
||
@Component({ | ||
selector: 'app-article-display', | ||
template: ` | ||
<p-dataView [value]="articleService.articles"> | ||
<ng-template let-article pTemplate="listItem"> | ||
<div class="col-12"> | ||
<p>IDK what im doing</p> | ||
</div> | ||
</ng-template> | ||
</p-dataView> | ||
`, | ||
<h2>{{article?.headline || "Headline"}}</h2> | ||
<h4>By {{article?.author || "Author"}}</h4> | ||
<img style="width: 50%; height: auto" [src]="article?.articleImgUrl" [alt]="article?.headline"> | ||
<p>{{article?.body}}</p> | ||
`, | ||
styleUrls: ['./article-display.component.css'] | ||
}) | ||
export class ArticleDisplayComponent { | ||
constructor(public articleService: ArticleService) { | ||
articleService.getArticles().then(r => console.log(r)); | ||
|
||
export class ArticleDisplayComponent implements OnInit { | ||
articleId: number = 0; | ||
article: Article | undefined; | ||
|
||
constructor(public articleService: ArticleService, public config: DynamicDialogConfig) { | ||
} | ||
|
||
ngOnInit() { | ||
this.articleId = this.config.data.articleId; | ||
|
||
this.articleService.getArticle(this.articleId).then((article) => { | ||
this.article = article; | ||
}); | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
NewsfeedFrontend/src/app/article-display/article-display.module.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters