Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ <h1 class="mock-h2" translate>Agenda export</h1>
<mat-tab label="CSV">
<ng-container [ngTemplateOutlet]="exportPdf"></ng-container>
</mat-tab>
<mat-tab label="XML">
<ng-container [ngTemplateOutlet]="exportXML"></ng-container>
</mat-tab>
</mat-tab-group>
</div>

Expand Down Expand Up @@ -216,3 +219,8 @@ <h1 class="mock-h2" translate>Agenda export</h1>
</div>
</form>
</ng-template>
<ng-template #exportXML>
<form [formGroup]="dialogForm">
<div class="export-wrapper"></div>
</form>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ export class AgendaExportComponent extends BaseComponent implements OnDestroy, A
return this.fileFormats[this.tabIndex] === ExportFileFormat.CSV;
}

public get isXMLFormat(): boolean {
return this.fileFormats[this.tabIndex] === ExportFileFormat.XML;
}

public agendaItems: Id[] = [];

private pdfDefaults = {
Expand All @@ -112,12 +116,17 @@ export class AgendaExportComponent extends BaseComponent implements OnDestroy, A
metaInfo: [`duration`]
};

private xmlDefaults = {
content: ['item_nuber', 'title', 'text', 'attachments', 'moderation_notes'],
metaInfo: ['duration']
};

private tabIndex = 0;
// Store fileformats with corresponding tab group index
private fileFormats: ExportFileFormat[] = [ExportFileFormat.PDF, ExportFileFormat.CSV];
private fileFormats: ExportFileFormat[] = [ExportFileFormat.PDF, ExportFileFormat.CSV, ExportFileFormat.XML];
private savedSelections: SavedSelections = {
tab_index: 0,
tab_selections: [this.pdfDefaults, this.csvDefaults]
tab_selections: [this.pdfDefaults, this.csvDefaults, this.xmlDefaults]
};

private backNr: string;
Expand Down Expand Up @@ -173,11 +182,14 @@ export class AgendaExportComponent extends BaseComponent implements OnDestroy, A
...(this.dialogForm.get(`headerFooter`).value ?? [])
];
this.agendaExportService.exportAsPdf(views, info, pdfMeta);
} else if (this.isCSVFormat) {
}
if (this.isCSVFormat) {
const csvMetaInfo = this.dialogForm.get(`metaInfo`).value ?? [];
this.agendaExportService.exportAsCsv(views, info, csvMetaInfo);
} else if (this.isXMLFormat) {
this.agendaExportService.exportAsXML(views);
}
this.router.navigate([this.activeMeetingIdService.meetingId, `agenda`]);
// this.router.navigate([this.activeMeetingIdService.meetingId, `agenda`]);
}

public afterTabChanged(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { inject, Service } from '@angular/core';
import { ViewAgendaItem } from '@app/site/pages/meetings/pages/agenda';
import { MeetingPdfExportService } from '@app/site/pages/meetings/services/export';
import { MeetingCsvExportForBackendService } from '@app/site/pages/meetings/services/export/meeting-csv-export-for-backend.service';
import { MeetingXmlExportService } from '@app/site/pages/meetings/services/export/meeting-xml-export.service';
import { TranslateService } from '@ngx-translate/core';

import { AgendaPdfCatalogExportService } from '../../../../services/agenda-pdf-catalog-export.service/agenda-pdf-catalog-export.service';

export enum ExportFileFormat {
PDF = 0,
CSV
CSV = 1,
XML = 2
}

export type InfoToExport =
Expand All @@ -25,12 +27,15 @@ export type pdfMetaInfo = `table_of_content` | `line_break` | `header` | `footer

export type csvMetaInfo = `duration` | `tags` | `agenda_visibility` | `done`;

export type xmlMetaInfo = `test_info`;

@Service()
export class AgendaItemExportService {
private translate = inject(TranslateService);
private csvExportService = inject(MeetingCsvExportForBackendService);
private pdfExportService = inject(MeetingPdfExportService);
private agendaPdfExportService = inject(AgendaPdfCatalogExportService);
private xmlExportService = inject(MeetingXmlExportService);

public exportAsCsv(source: ViewAgendaItem[], info: InfoToExport[], csvMeta: csvMetaInfo): void {
const config = [];
Expand Down Expand Up @@ -93,9 +98,14 @@ export class AgendaItemExportService {
const filename = this.translate.instant(`Agenda`);
const metaExportInfo = { pdfOptions: [...meta] };
this.pdfExportService.download({
docDefinition: this.agendaPdfExportService.agendaListToDocDef(source, info, meta),
docDefinition: this.agendaPdfExportService.agendaListToDocDef([...source], info, meta),
exportInfo: metaExportInfo,
filename
});
}

public exportAsXML(source: ViewAgendaItem[]): void {
const filename = this.translate.instant(`Agenda`) + `.xml`;
this.xmlExportService.export(source, filename);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { inject, Service } from '@angular/core';
import { FileExportService } from '@app/gateways/export/file-export.service';

import { ViewAgendaItem } from '../../pages/agenda';

@Service()
export class MeetingXmlExportService {
private exporter = inject(FileExportService);
private serializer = new XMLSerializer();

public export(source: ViewAgendaItem[], filename: string): void {
const xml = this.generateXML(source);
this.exporter.saveFile(xml, filename, 'application/xml');
}

private generateXML(source: ViewAgendaItem[]): string {
const doc = document.implementation.createDocument('', 'Agenda-Export', null);
const root = doc.documentElement;
const itemMap = new Map(source.map(item => [item.id, item]));
const mainAgendaTopics = source.filter(item => !item.parent_id);
for (const item of mainAgendaTopics) {
root.appendChild(this.createAgendaTopic(item, doc, itemMap, false));
}
return this.serializer.serializeToString(doc);
}

private createAgendaTopic(
item: ViewAgendaItem,
doc,
itemMap: Map<number, ViewAgendaItem<any>>,
isNested = false
): HTMLElement {
const agendaItem = doc.createElement(isNested ? 'Sub-Agenda-Item' : 'Agenda-Item');

if (item.item_number) {
const item_number = doc.createElement('item-number');
item_number.textContent = item.item_number;
agendaItem.appendChild(item_number);
}
if (item.content_object?.title) {
const title = doc.createElement('title');
title.textContent = item.content_object.title;
agendaItem.appendChild(title);
}
if (item.content_object?.text) {
const text = doc.createElement('text');
text.textContent = item.content_object.text;
agendaItem.appendChild(text);
}
if (item.content_object?.list_of_speakers.moderator_notes) {
const moderator_notes = doc.createElement('moderation_notes');
moderator_notes.textContent = item.content_object?.list_of_speakers.moderator_notes;
agendaItem.appendChild(moderator_notes);
}
if (item.content_object?.list_of_speakers?.speaker_ids) {
const list_of_speakers = doc.createElement('list_of_speakers');
list_of_speakers.textContent = String(item.content_object.list_of_speakers?.speaker_ids?.length);
agendaItem.appendChild(list_of_speakers);
}
if (item.comment) {
const agenda_comment = doc.createElement('agenda_comment');
agenda_comment.textContent = String(item.comment);
agendaItem.appendChild(agenda_comment);
}
if (item.duration) {
const agenda_duration = doc.createElement('agenda_duration');
agenda_duration.textContent = String(item.duration);
agendaItem.appendChild(agenda_duration);
}
if (item.type) {
const agenda_type = doc.createElement('agenda_type');
agenda_type.textContent = String(item.type);
agendaItem.appendChild(agenda_type);
}
if (item.tags?.length) {
const tags = doc.createElement('tags');
item.tags.filter(t => {
const tag = doc.createElement('tag');
tag.textContent = t.tag.name;
tags.appendChild(tag);
});
agendaItem.appendChild(tags);
}
if (item.closed) {
const agenda_closed = doc.createElement('agenda_closed');
agenda_closed.textContent = String(item.closed);
agendaItem.appendChild(agenda_closed);
}

for (const childId of item.child_ids ?? []) {
const child = itemMap.get(childId);
if (child) {
agendaItem.appendChild(this.createAgendaTopic(child, doc, itemMap, true));
}
}

return agendaItem;
}
}
Loading