-
Notifications
You must be signed in to change notification settings - Fork 7
feat(Home Page): Admin news on home #2324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
807d109
Created admin latest news component
Aaron-Detre 3cea440
Moved content of DiscourseLatestNews to new generic LatestNews compon…
Aaron-Detre 58eb109
Fixed isDiscourseNewsAvailable always truthy bug
Aaron-Detre 4f8d8e9
Max 3 admin news
Aaron-Detre fd19255
Only show news if there are news topics and fixed bug with dot divide…
Aaron-Detre bdfbb34
Dialog for more admin news
Aaron-Detre 92154a7
Sort admin news descending by date and input all to LatestNews instea…
Aaron-Detre b06b338
Dialog for individual news items
Aaron-Detre 2521030
Only show public news
Aaron-Detre f2357c6
Added date posted to news dialogs
Aaron-Detre 0ca44c9
Dialog styling
Aaron-Detre bec328a
Wrote tests
Aaron-Detre 247cc57
Switched to using existing /news page instead of dialogs
Aaron-Detre a39d181
Removed method no longer used
Aaron-Detre e8d71bf
Revert changes in NewsService test file
Aaron-Detre 5aad158
Fixed tests
Aaron-Detre e054567
Updated messages
github-actions[bot] 687a5e9
Clean code and return DomSanitizer
Aaron-Detre 40c8d91
Merge branch 'admin-news-on-home' of https://github.com/WISE-Communit…
Aaron-Detre cbea455
Updated messages
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
src/app/home/admin-latest-news/admin-latest-news.component.html
This file contains hidden or 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 @@ | ||
| <latest-news [isDiscourseNewsAvailable]="false" [topics]="topics" [isLoaded]="isLoaded" /> |
Empty file.
64 changes: 64 additions & 0 deletions
64
src/app/home/admin-latest-news/admin-latest-news.component.spec.ts
This file contains hidden or 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,64 @@ | ||
| import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; | ||
|
|
||
| import { AdminLatestNewsComponent } from './admin-latest-news.component'; | ||
| import { NewsService } from '../../services/news.service'; | ||
| import { News } from '../../domain/news'; | ||
| import { of } from 'rxjs'; | ||
| import { MockProvider } from 'ng-mocks'; | ||
| import { ActivatedRoute } from '@angular/router'; | ||
|
|
||
| describe('AdminLatestNewsComponent', () => { | ||
| let component: AdminLatestNewsComponent; | ||
| let fixture: ComponentFixture<AdminLatestNewsComponent>; | ||
|
|
||
| beforeEach(async () => { | ||
| const newsServiceSpy = jasmine.createSpyObj<NewsService>(['getAllNews']); | ||
| const news1 = new News({ | ||
| id: 1, | ||
| date: '2026-02-01 19:14:23.0', | ||
| type: 'public', | ||
| title: 'Test News', | ||
| news: 'news content', | ||
| owner: undefined | ||
| }); | ||
| const news2 = new News({ | ||
| id: 2, | ||
| date: '2026-01-02 19:14:23.0', | ||
| type: 'teacherOnly', | ||
| title: 'Test News 2', | ||
| news: 'news content 2', | ||
| owner: undefined | ||
| }); | ||
| const news3 = new News({ | ||
| id: 3, | ||
| date: '2026-02-01 19:15:00.0', | ||
| type: 'public', | ||
| title: 'Test News 3', | ||
| news: 'news content 3', | ||
| owner: undefined | ||
| }); | ||
|
|
||
| newsServiceSpy.getAllNews.and.callFake(() => of<News[]>([news1, news2, news3])); | ||
|
|
||
| await TestBed.configureTestingModule({ | ||
| imports: [AdminLatestNewsComponent], | ||
| providers: [{ provide: NewsService, useValue: newsServiceSpy }, MockProvider(ActivatedRoute)] | ||
| }).compileComponents(); | ||
|
|
||
| fixture = TestBed.createComponent(AdminLatestNewsComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should create', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should filter and sort topics', fakeAsync(() => { | ||
| component.ngOnInit(); | ||
| tick(); | ||
| expect(component['topics']).toBeTruthy(); | ||
| expect(component['topics'].length).toBe(2); | ||
| expect(component['topics'][0].title).toBe('Test News 3'); | ||
| })); | ||
| }); |
26 changes: 26 additions & 0 deletions
26
src/app/home/admin-latest-news/admin-latest-news.component.ts
This file contains hidden or 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,26 @@ | ||
| import { Component } from '@angular/core'; | ||
| import { LatestNewsComponent } from '../latest-news/latest-news.component'; | ||
| import { News } from '../../domain/news'; | ||
| import { NewsService } from '../../services/news.service'; | ||
|
|
||
| @Component({ | ||
| selector: 'admin-latest-news', | ||
| imports: [LatestNewsComponent], | ||
| templateUrl: './admin-latest-news.component.html', | ||
| styleUrl: './admin-latest-news.component.scss' | ||
| }) | ||
| export class AdminLatestNewsComponent { | ||
| protected topics: News[] = []; | ||
| protected isLoaded: boolean = false; | ||
|
Aaron-Detre marked this conversation as resolved.
Outdated
|
||
|
|
||
| constructor(private newsService: NewsService) {} | ||
|
|
||
| ngOnInit(): void { | ||
| this.newsService.getAllNews().subscribe((news) => { | ||
| this.topics = news | ||
| .filter((news) => news.type === 'public') | ||
| .sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()); | ||
| this.isLoaded = true; | ||
| }); | ||
| } | ||
| } | ||
33 changes: 7 additions & 26 deletions
33
src/app/home/discourse-latest-news/discourse-latest-news.component.html
This file contains hidden or 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,26 +1,7 @@ | ||
| <div class="latest-news dark-theme primary-border" [ngClass]="{ loaded: isLoaded }"> | ||
| <h2 | ||
| class="flex items-center" | ||
| [ngClass]="{ 'mat-small': xsScreen, 'mat-body-1': smallScreen && !xsScreen }" | ||
| > | ||
| <mat-icon>rss_feed</mat-icon> | ||
| <ng-container i18n>What's New?</ng-container> | ||
| </h2> | ||
| <ul> | ||
| @for (topic of topics; track topic; let index = $index) { | ||
| @if (!xsScreen || index === 0) { | ||
| <li [ngClass]="{ 'mat-small': smallScreen, 'mat-body-1': !smallScreen }"> | ||
| <a href="{{ baseUrl }}/t/{{ topic.slug }}/{{ topic.id }}"> | ||
| {{ topic.title }} | ||
| </a> | ||
| @if (smallScreen) { | ||
| • | ||
| } | ||
| </li> | ||
| } | ||
| } | ||
| </ul> | ||
| <div [ngClass]="{ 'mat-small': smallScreen, 'mat-body-1': !smallScreen }"> | ||
| <a href="{{ baseUrl }}/{{ category }}" i18n>More news</a> | ||
| </div> | ||
| </div> | ||
| <latest-news | ||
| [isDiscourseNewsAvailable]="true" | ||
| [topics]="topics" | ||
| [baseUrl]="baseUrl" | ||
| [category]="category" | ||
| [isLoaded]="isLoaded" | ||
| /> |
61 changes: 0 additions & 61 deletions
61
src/app/home/discourse-latest-news/discourse-latest-news.component.scss
This file contains hidden or 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,61 +0,0 @@ | ||
| @use 'style/abstracts/functions'; | ||
|
|
||
| .latest-news { | ||
| padding: 8px; | ||
| background-color: rgba(0,0,0,0.8); | ||
| border-style: solid; | ||
| border-width: 0 0 0 8px; | ||
| display: none; | ||
|
|
||
| [dir=rtl] & { | ||
| border-width: 0 8px 0 0; | ||
| } | ||
|
|
||
| @media (min-width: functions.breakpoint('md.min')) { | ||
| padding: 24px; | ||
| } | ||
|
|
||
| &.loaded { | ||
| display: block; | ||
| } | ||
|
|
||
| > * { | ||
| @media (max-width: functions.breakpoint('sm.max')) { | ||
| display: inline; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .mat-icon { | ||
| vertical-align: sub; | ||
| } | ||
|
|
||
| ul { | ||
| padding: 0; | ||
|
|
||
| @media (min-width: functions.breakpoint('md.min')) { | ||
| padding: 0 0 0 16px; | ||
| } | ||
| } | ||
|
|
||
| li { | ||
| &:not(:last-of-type) { | ||
| margin-bottom: 4px; | ||
| } | ||
|
|
||
| @media (max-width: functions.breakpoint('sm.max')) { | ||
| display: inline; | ||
| list-style-type: none; | ||
| } | ||
|
|
||
| @media (min-width: functions.breakpoint('md.min')) { | ||
| a { | ||
| max-width: 100%; | ||
| vertical-align: middle; | ||
| display: inline-block; | ||
| overflow: hidden; | ||
| white-space: nowrap; | ||
| text-overflow: ellipsis; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
27 changes: 3 additions & 24 deletions
27
src/app/home/discourse-latest-news/discourse-latest-news.component.ts
This file contains hidden or 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,32 +1,11 @@ | ||
| import { HttpClient } from '@angular/common/http'; | ||
| import { Component } from '@angular/core'; | ||
| import { BreakpointObserver } from '@angular/cdk/layout'; | ||
| import { DiscourseFeedComponent } from '../../discourse-feed/discourse-feed.component'; | ||
| import { CommonModule } from '@angular/common'; | ||
| import { MatIconModule } from '@angular/material/icon'; | ||
| import { LatestNewsComponent } from '../latest-news/latest-news.component'; | ||
|
|
||
| @Component({ | ||
| imports: [CommonModule, MatIconModule], | ||
| imports: [LatestNewsComponent], | ||
| selector: 'discourse-latest-news', | ||
| styleUrl: 'discourse-latest-news.component.scss', | ||
|
Aaron-Detre marked this conversation as resolved.
Outdated
|
||
| templateUrl: 'discourse-latest-news.component.html' | ||
| }) | ||
| export class DiscourseLatestNewsComponent extends DiscourseFeedComponent { | ||
| protected smallScreen: boolean; | ||
| protected xsScreen: boolean; | ||
|
|
||
| constructor( | ||
| protected http: HttpClient, | ||
| private breakpointObserver: BreakpointObserver | ||
| ) { | ||
| super(http); | ||
| this.breakpointObserver | ||
| .observe(['(max-width: 40rem)', '(max-width: 48rem)']) | ||
| .subscribe((result) => { | ||
| this.smallScreen = result.matches; | ||
| }); | ||
| this.breakpointObserver.observe(['(max-width: 40rem)']).subscribe((result) => { | ||
| this.xsScreen = result.matches; | ||
| }); | ||
| } | ||
| } | ||
| export class DiscourseLatestNewsComponent extends DiscourseFeedComponent {} | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,36 @@ | ||
| @if (topics) { | ||
| <div class="latest-news dark-theme primary-border" [ngClass]="{ loaded: isLoaded }"> | ||
| <h2 | ||
| class="flex items-center" | ||
| [ngClass]="{ 'mat-small': xsScreen, 'mat-body-1': smallScreen && !xsScreen }" | ||
| > | ||
| <mat-icon>rss_feed</mat-icon> | ||
| <ng-container i18n>What's New?</ng-container> | ||
| </h2> | ||
| <ul> | ||
| @for (topic of threeTopics; track topic; let index = $index) { | ||
| @if (!xsScreen || index === 0) { | ||
| <li [ngClass]="{ 'mat-small': smallScreen, 'mat-body-1': !smallScreen }"> | ||
| @if (isDiscourseNewsAvailable) { | ||
| <a href="{{ baseUrl }}/t/{{ topic.slug }}/{{ topic.id }}"> | ||
| {{ topic.title }} | ||
| </a> | ||
| } @else { | ||
| <a routerLink="/news" fragment="{{ topic.id }}" i18n> | ||
| {{ topic.title }} | ||
| </a> | ||
| } | ||
| <span class="divider"> • </span> | ||
| </li> | ||
| } | ||
| } | ||
| </ul> | ||
| <div [ngClass]="{ 'mat-small': smallScreen, 'mat-body-1': !smallScreen }"> | ||
| @if (isDiscourseNewsAvailable) { | ||
| <a href="{{ baseUrl }}/{{ category }}" i18n>More news</a> | ||
| } @else { | ||
| <a routerLink="/news" i18n>More news</a> | ||
| } | ||
| </div> | ||
| </div> | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.