OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Adding summary to news widget (#8234)
bsatarnejad43675e9928ed
diff --git a/frontend/src/app/modules/grids/widgets/abstract-widget.component.ts b/frontend/src/app/modules/grids/widgets/abstract-widget.component.tsindex 45d8d1c9288..432bbff3ac3 100644--- a/frontend/src/app/modules/grids/widgets/abstract-widget.component.ts+++ b/frontend/src/app/modules/grids/widgets/abstract-widget.component.ts@@ -16,8 +16,8 @@ export abstract class AbstractWidgetComponent extends UntilDestroyedMixin {@Output() resourceChanged = new EventEmitter<WidgetChangeset>();public get widgetName():string {- let editableName = this.resource.options.name as string;- let widgetIdentifier = this.resource.identifier;+ let editableName = this.resource?.options.name as string;+ let widgetIdentifier = this.resource?.identifier;if (this.isEditable) {return editableName;diff --git a/frontend/src/app/modules/grids/widgets/news/news.component.html b/frontend/src/app/modules/grids/widgets/news/news.component.htmlindex 9af6da20678..48ea7e6e854 100644--- a/frontend/src/app/modules/grids/widgets/news/news.component.html+++ b/frontend/src/app/modules/grids/widgets/news/news.component.html@@ -1,35 +1,28 @@-<widget-header- [name]="widgetName"- [editable]="isEditable">+<widget-header [name]="widgetName" [editable]="isEditable">- <widget-menu- [resource]="resource">+ <widget-menu [resource]="resource"></widget-menu>+</widget-header>-<div class="grid--widget-content">- <no-results *ngIf="noEntries"- [title]="text.noResults">+ <no-results *ngIf="noEntries" [title]="text.noResults"></no-results><ul class="widget-box--arrow-links"><li class="-widget-box--arrow-multiline" *ngFor="let news of entries"><div>- <user-avatar *ngIf="news.author"- [user]="news.author"- data-class-list="avatar avatar-medium -spaced">+ <user-avatar *ngIf="news.author" [user]="news.author" data-class-list="avatar avatar-medium -spaced"></user-avatar>- <a [href]="newsProjectPath(news)"- [textContent]="newsProjectName(news)">+ <a [href]="newsProjectPath(news)" [textContent]="newsProjectName(news)"></a>:- <a [href]="newsPath(news)"- [textContent]="news.title">+ <a [href]="newsPath(news)" [textContent]="news.title"></a>- <p *ngIf="news.author"+ <p *ngIf="news.summary" [textContent]="news.summary" class="widget-box--additional-info"></p>++ <p *ngIf="news.author"class="widget-box--additional-info">{{text.createdBy}}- <a [href]="newsAuthorPath(news)"- [textContent]="newsAuthorName(news)">+ <a [href]="newsAuthorPath(news)" [textContent]="newsAuthorName(news)"></a>{{text.at}}{{newsCreated(news)}}@@ -37,4 +30,4 @@</div></li></ul>-</div>+</div>\ No newline at end of filediff --git a/frontend/src/app/modules/grids/widgets/news/news.component.spec.ts b/frontend/src/app/modules/grids/widgets/news/news.component.spec.tsnew file mode 100644index 00000000000..65544860082--- /dev/null+++ b/frontend/src/app/modules/grids/widgets/news/news.component.spec.ts@@ -0,0 +1,117 @@+import { NewsDmService } from "core-app/modules/hal/dm-services/news-dm.service";+import { ComponentFixture, fakeAsync, TestBed, tick, async } from '@angular/core/testing';+import { WidgetNewsComponent } from './news.component';+import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core';+import { TimezoneService } from 'core-app/components/datetime/timezone.service';+import { ConfigurationService } from 'core-app/modules/common/config/configuration.service';+import { States } from 'core-app/components/states.service';+import { UserDmService } from 'core-app/modules/hal/dm-services/user-dm.service';+import { HalResourceService } from "core-app/modules/hal/services/hal-resource.service";+import { HttpClientModule } from "@angular/common/http";+import { By } from '@angular/platform-browser';++describe('shows news', () => {+ let app:WidgetNewsComponent;+ let fixture:ComponentFixture<WidgetNewsComponent>;+ let element:DebugElement;++ let newsStub = {+ id: 1,+ title: 'Welcome to your demo project',+ author: {+ href: '/api/v3/users/1',+ name: 'Foo Bar'+ },+ summary: 'We are glad you joined. In this module you can communicate project news to your team members.\n',+ description: {+ format: 'markdown',+ raw: 'The actual news',+ html: '<p>The actual news</p>'+ },+ createdAt: '2020-03-26T10:42:14Z',+ updatedAt: '2020-03-26T10:42:14Z',+ };++ let newsDmServiceStub = {+ list: (_params:any) => {+ return Promise.resolve({ elements: [newsStub] });+ }+ };++ let configurationServiceStub = {+ isTimezoneSet: () => false,+ dateFormatPresent: () => false,+ timeFormatPresent: () => false+ };+ beforeEach(() => {+ TestBed.configureTestingModule({+ declarations: [+ WidgetNewsComponent],+ providers: [+ TimezoneService,+ { provide: ConfigurationService, useValue: configurationServiceStub },+ States,+ UserDmService,+ { provide: NewsDmService, useValue: newsDmServiceStub },+ HalResourceService,+ ],+ imports: [HttpClientModule],+ schemas: [NO_ERRORS_SCHEMA]+ }).compileComponents();++ fixture = TestBed.createComponent(WidgetNewsComponent);+ app = fixture.debugElement.componentInstance;+ element = fixture.debugElement;+ });++ it('should load news from the server', fakeAsync(() => {+ fixture.detectChanges();+ tick();+ expect(app.entries.length).toBe(1);+ }));+++ it('should render the componenet successfully to show the news', async(() => {+ fixture.detectChanges();+ fixture.whenStable().then(() => {+ let newsItem = document.querySelector('li');+ expect(document.contains(newsItem)).toBeTruthy();+ });+ }));++ it('should Not add the no-results component into DOM', async(() => {+ fixture.detectChanges();+ fixture.whenStable().then(() => {+ let newsItem = document.querySelector('no-results');+ expect(document.contains(newsItem)).not.toBeTruthy();+ });+ }));++ it('should add the widget-header component into DOM', async(() => {+ fixture.detectChanges();+ fixture.whenStable().then(() => {+ let newsItem = document.querySelector('widget-header');+ expect(document.contains(newsItem)).toBeTruthy();+ });+ }));++ it('should show summary of news', async(() => {+ fixture.detectChanges();++ fixture.whenStable().then(() => {+ let newsItem:HTMLElement = element.query(By.css('.widget-box--additional-info')).nativeElement;+ expect(newsItem.innerText).toContain('We are glad you joined.');++ });+ }));++ it('should Not add the user-avatar component into DOM', async(() => {+ fixture.detectChanges();++ fixture.whenStable().then(() => {+ let newsItem = document.querySelector('user-avatar');+ expect(document.contains(newsItem)).toBeTruthy();++ });+ }));+});\ No newline at end of filediff --git a/frontend/src/app/modules/grids/widgets/news/news.component.ts b/frontend/src/app/modules/grids/widgets/news/news.component.tsindex 68ef51fc1df..60bac74a35b 100644--- a/frontend/src/app/modules/grids/widgets/news/news.component.ts+++ b/frontend/src/app/modules/grids/widgets/news/news.component.ts@@ -1,15 +1,12 @@-import {AbstractWidgetComponent} from "core-app/modules/grids/widgets/abstract-widget.component";-import {Component, OnInit, ChangeDetectorRef, Injector, ChangeDetectionStrategy} from '@angular/core';-import {I18nService} from "core-app/modules/common/i18n/i18n.service";-import {HalResourceService} from "core-app/modules/hal/services/hal-resource.service";-import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";-import {TimezoneService} from "core-components/datetime/timezone.service";-import {NewsResource} from "core-app/modules/hal/resources/news-resource";-import {UserCacheService} from "core-components/user/user-cache.service";-import {UserResource} from "core-app/modules/hal/resources/user-resource";-import {NewsDmService} from "core-app/modules/hal/dm-services/news-dm.service";-import {CurrentProjectService} from "core-components/projects/current-project.service";-import {DmListParameter} from "core-app/modules/hal/dm-services/dm.service.interface";+import { AbstractWidgetComponent } from "core-app/modules/grids/widgets/abstract-widget.component";+import { ChangeDetectionStrategy, Component, Injector, OnInit, ChangeDetectorRef } from '@angular/core';+import { I18nService } from "core-app/modules/common/i18n/i18n.service";+import { PathHelperService } from "core-app/modules/common/path-helper/path-helper.service";+import { TimezoneService } from "core-components/datetime/timezone.service";+import { NewsResource } from "core-app/modules/hal/resources/news-resource";+import { NewsDmService } from "core-app/modules/hal/dm-services/news-dm.service";+import { CurrentProjectService } from "core-components/projects/current-project.service";+import { DmListParameter } from "core-app/modules/hal/dm-services/dm.service.interface";@Component({templateUrl: './news.component.html',@@ -25,30 +22,30 @@ export class WidgetNewsComponent extends AbstractWidgetComponent implements OnInpublic entries:NewsResource[] = [];private entriesLoaded = false;- constructor(readonly halResource:HalResourceService,- readonly pathHelper:PathHelperService,- readonly i18n:I18nService,- protected readonly injector:Injector,- readonly timezone:TimezoneService,- readonly userCache:UserCacheService,- readonly newsDm:NewsDmService,- readonly currentProject:CurrentProjectService,- readonly cdr:ChangeDetectorRef) {+ constructor(++ readonly pathHelper:PathHelperService,+ readonly i18n:I18nService,+ protected readonly injector:Injector,+ readonly timezone:TimezoneService,+ readonly newsDm:NewsDmService,+ readonly currentProject:CurrentProjectService,+ readonly cdr:ChangeDetectorRef+ ) {super(i18n, injector);}ngOnInit() {this.newsDm.list(this.newsDmParams)- .then((collection) => {- this.entries = collection.elements as NewsResource[];- this.entriesLoaded = true;+ .then(collection => this.setupNews(collection.elements));+ }- const users_loaded = this.setAuthors();+ public setupNews(news:any[]) {- Promise.all(users_loaded)- .then(() => this.cdr.detectChanges());- });+ this.entries = news;+ this.entriesLoaded = true;+ this.cdr.detectChanges();}public get isEditable() {@@ -56,23 +53,25 @@ export class WidgetNewsComponent extends AbstractWidgetComponent implements OnIn}public newsPath(news:NewsResource) {+return this.pathHelper.newsPath(news.id!);}public newsProjectPath(news:NewsResource) {- return this.pathHelper.projectPath(news.project.idFromLink);+ return this.pathHelper.projectPath(news.project?.idFromLink);}public newsProjectName(news:NewsResource) {- return news.project.name;+ return news.project?.name;}public newsAuthorName(news:NewsResource) {- return news.author.name;+ return news.author?.name;}public newsAuthorPath(news:NewsResource) {- return this.pathHelper.userPath(news.author.id);+ return this.pathHelper.userPath(news.author?.id);+}public newsCreated(news:NewsResource) {@@ -83,23 +82,11 @@ export class WidgetNewsComponent extends AbstractWidgetComponent implements OnInreturn !this.entries.length && this.entriesLoaded;}- public setAuthors() {- return this.entries.map((entry) => {- if (!entry.author) {- return Promise.resolve();- }-- return this.userCache- .require(entry.author.idFromLink)- .then((user:UserResource) => {- entry.author = user;- });- });- }-private get newsDmParams() {- let params:DmListParameter = { sortBy: [['created_at', 'desc']],- pageSize: 3 };+ let params:DmListParameter = {+ sortBy: [['created_at', 'desc']],+ pageSize: 3+ };if (this.currentProject.id) {params['filters'] = [['project_id', '=', [this.currentProject.id]]];