Merge pull request #4056 from MaximilianKrambach/os3/agendaexport

agenda csv export
This commit is contained in:
Jochen Saalfeld 2018-12-17 11:48:29 +01:00 committed by GitHub
commit 6c9fb713e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 112 additions and 13 deletions

View File

@ -62,14 +62,15 @@ export class Item extends ProjectableBaseModel {
}
/**
* Return the type as string
* Gets the string representation of the item type
* @returns The visibility for this item, as defined in {@link itemVisibilityChoices}
*/
public get verboseType(): string {
if (this.type) {
return itemVisibilityChoices.find(visibilityType => visibilityType.key === this.type).name;
} else {
if (!this.type) {
return '';
}
const type = itemVisibilityChoices.find(choice => choice.key === this.type);
return type ? type.name : '';
}
public getTitle(): string {

View File

@ -33,11 +33,20 @@ export abstract class AgendaBaseModel extends ProjectableBaseModel implements Ag
return this.getAgendaTitle() + ' (' + this.getVerboseName() + ')';
}
/**
* @returns the (optional) descriptive text to be exported in the CSV.
* May be overridden by inheriting classes
*/
public getCSVExportText(): string {
return '';
}
/**
* Should return a string representation of the object, so there can be searched for.
*/
public abstract formatForSearch(): SearchRepresentation;
/**
* Should return the URL to the detail view. Used for the agenda, that the
* user can navigate to the content object.

View File

@ -37,4 +37,12 @@ export class Topic extends AgendaBaseModel {
public getDetailStateURL(): string {
return `/agenda/topics/${this.id}`;
}
/**
* Returns the text to be inserted in csv exports
* @override
*/
public getCSVExportText(): string {
return this.text;
}
}

View File

@ -103,6 +103,10 @@
<span translate>Numbering</span>
</button>
</div>
<button mat-menu-item (click)="csvExportItemList();">
<mat-icon>archive</mat-icon>
<span translate>Export as CSV</span>
</button>
</div>
<div *ngIf="isMultiSelect">

View File

@ -8,6 +8,8 @@ import { ViewItem } from '../../models/view-item';
import { ListViewBaseComponent } from 'app/site/base/list-view-base';
import { AgendaRepositoryService } from '../../services/agenda-repository.service';
import { PromptService } from '../../../../core/services/prompt.service';
import { AgendaCsvExportService } from '../../services/agenda-csv-export.service';
import { ItemInfoDialogComponent } from '../item-info-dialog/item-info-dialog.component';
import { ViewportService } from 'app/core/services/viewport.service';
import { DurationService } from 'app/site/core/services/duration.service';
@ -47,6 +49,7 @@ export class AgendaListComponent extends ListViewBaseComponent<ViewItem> impleme
* @param config read out config values
* @param vp determine the viewport
* @param durationService Converts numbers to readable duration strings
* @param csvExport Handles the exporting into csv
*/
public constructor(
titleService: Title,
@ -59,7 +62,8 @@ export class AgendaListComponent extends ListViewBaseComponent<ViewItem> impleme
private dialog: MatDialog,
private config: ConfigService,
public vp: ViewportService,
public durationService: DurationService
public durationService: DurationService,
private csvExport: AgendaCsvExportService
) {
super(titleService, translate, matSnackBar);
@ -213,4 +217,11 @@ export class AgendaListComponent extends ListViewBaseComponent<ViewItem> impleme
}
return list;
}
/**
* Export all items as CSV
*/
public csvExportItemList(): void {
this.csvExport.exportItemList(this.dataSource.data);
}
}

View File

@ -34,17 +34,22 @@ export class ViewItem extends BaseViewModel {
return this.item ? this.item.type : null;
}
public get verboseType(): string {
return this.item.verboseType;
}
public get comment(): string {
return this.item ? this.item.comment : null;
}
public get closed(): boolean {
return this.item ? this.item.closed : null;
}
public get comment(): string {
if (this.item && this.item.comment) {
return this.item.comment;
}
return '';
}
public get verboseType() : string {
if (this.item && this.item.verboseType) {
return this.item.verboseType;
}
return '';
}
public constructor(item: Item, contentObject: AgendaBaseModel) {
super();

View File

@ -0,0 +1,20 @@
import { TestBed, inject } from '@angular/core/testing';
import { E2EImportsModule } from 'e2e-imports.module';
import { AgendaCsvExportService } from './agenda-csv-export.service';
describe('AgendaCsvExportService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [E2EImportsModule],
providers: [AgendaCsvExportService]
});
});
it('should be created', inject(
[AgendaCsvExportService],
(service: AgendaCsvExportService) => {
expect(service).toBeTruthy();
}
));
});

View File

@ -0,0 +1,41 @@
import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { CsvExportService } from 'app/core/services/csv-export.service';
import { ViewItem } from '../models/view-item';
/**
* Exports CSVs for Agendas. Collect all CSV types here to have them in one place.
*/
@Injectable({
providedIn: 'root'
})
export class AgendaCsvExportService {
/**
* Does nothing.
*
* @param csvExport CsvExportService
* @param translate TranslateService
*/
public constructor(private csvExport: CsvExportService, private translate: TranslateService) {}
/**
* Export all Agendas as CSV
*
* @param Agendas Agendas to export
*/
public exportItemList(items: ViewItem[]): void {
this.csvExport.export(items,
[
{ label: 'Title', map: viewItem => viewItem.getTitle() },
{ label: 'Text', map: viewItem => viewItem.contentObject ? viewItem.contentObject.getCSVExportText() : '' },
{ label: 'Duration', property: 'duration' },
{ label: 'Comment', property: 'comment' },
{ label: 'Item type', property: 'verboseType' }
],
this.translate.instant('Agenda') + '.csv'
);
}
}