2019-01-18 20:25:06 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
|
2019-01-31 13:40:27 +01:00
|
|
|
import { ConfigService } from 'app/core/ui-services/config.service';
|
2019-07-26 11:46:59 +02:00
|
|
|
import { PdfDocumentService } from 'app/core/ui-services/pdf-document.service';
|
2019-02-06 13:13:19 +01:00
|
|
|
import { PersonalNoteContent } from 'app/shared/models/users/personal-note';
|
2019-07-03 16:42:08 +02:00
|
|
|
import { ExportFormData } from '../modules/motion-list/components/motion-export-dialog/motion-export-dialog.component';
|
2019-07-26 11:46:59 +02:00
|
|
|
import { MotionPdfCatalogService } from './motion-pdf-catalog.service';
|
|
|
|
import { MotionPdfService } from './motion-pdf.service';
|
|
|
|
import { ViewMotion } from '../models/view-motion';
|
|
|
|
import { ViewMotionCommentSection } from '../models/view-motion-comment-section';
|
2019-01-18 20:25:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Export service to handle various kind of exporting necessities.
|
|
|
|
*/
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class MotionPdfExportService {
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param translate handle translations
|
2019-01-24 14:40:05 +01:00
|
|
|
* @param configService Read out Config variables
|
2019-01-18 20:25:06 +01:00
|
|
|
* @param motionPdfService Converting actual motions to PDF
|
|
|
|
* @param pdfDocumentService Actual pdfmake functions and global doc definitions
|
|
|
|
*/
|
|
|
|
public constructor(
|
|
|
|
private translate: TranslateService,
|
2019-01-24 14:40:05 +01:00
|
|
|
private configService: ConfigService,
|
2019-01-18 20:25:06 +01:00
|
|
|
private motionPdfService: MotionPdfService,
|
2019-01-24 14:40:05 +01:00
|
|
|
private pdfCatalogService: MotionPdfCatalogService,
|
2019-01-18 20:25:06 +01:00
|
|
|
private pdfDocumentService: PdfDocumentService
|
|
|
|
) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Exports a single motions to PDF
|
|
|
|
*
|
|
|
|
* @param motion The motion to export
|
|
|
|
* @param lnMode the desired line numbering mode
|
|
|
|
* @param crMode the desired change recomendation mode
|
|
|
|
*/
|
2019-07-03 16:42:08 +02:00
|
|
|
public exportSingleMotion(motion: ViewMotion, exportInfo?: ExportFormData): void {
|
|
|
|
const doc = this.motionPdfService.motionToDocDef(motion, exportInfo);
|
2019-01-18 20:25:06 +01:00
|
|
|
const filename = `${this.translate.instant('Motion')} ${motion.identifierOrTitle}`;
|
|
|
|
const metadata = {
|
|
|
|
title: filename
|
|
|
|
};
|
|
|
|
this.pdfDocumentService.download(doc, filename, metadata);
|
|
|
|
}
|
2019-01-24 14:40:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Exports multiple motions to a collection of PDFs
|
|
|
|
*
|
2019-01-25 17:03:05 +01:00
|
|
|
* @param motions the motions to export
|
|
|
|
* @param lnMode lineNumbering Mode
|
|
|
|
* @param crMode Change Recommendation Mode
|
|
|
|
* @param contentToExport Determine to determine with text and/or reason
|
|
|
|
* @param infoToExport Determine the meta info to export
|
2019-02-11 17:11:35 +01:00
|
|
|
* @param commentsToExport Comments (by id) to export
|
2019-01-24 14:40:05 +01:00
|
|
|
*/
|
2019-07-03 16:42:08 +02:00
|
|
|
public exportMotionCatalog(motions: ViewMotion[], exportInfo: ExportFormData): void {
|
|
|
|
const doc = this.pdfCatalogService.motionListToDocDef(motions, exportInfo);
|
2019-01-24 14:40:05 +01:00
|
|
|
const filename = this.translate.instant(this.configService.instant<string>('motions_export_title'));
|
|
|
|
const metadata = {
|
|
|
|
title: filename
|
|
|
|
};
|
2019-07-03 16:42:08 +02:00
|
|
|
this.pdfDocumentService.download(doc, filename, metadata, exportInfo);
|
2019-01-24 14:40:05 +01:00
|
|
|
}
|
2019-01-31 19:18:58 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Exports a table of the motions in order of their call list
|
|
|
|
*
|
|
|
|
* @param motions the motions to export
|
|
|
|
*/
|
|
|
|
public exportPdfCallList(motions: ViewMotion[]): void {
|
|
|
|
const doc = this.motionPdfService.callListToDoc(motions);
|
|
|
|
const filename = this.translate.instant('Call list');
|
|
|
|
const metadata = {
|
|
|
|
title: filename
|
|
|
|
};
|
|
|
|
this.pdfDocumentService.downloadLandscape(doc, filename, metadata);
|
|
|
|
}
|
2019-02-06 13:13:19 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Exports the given personalNote with some short information about the
|
|
|
|
* motion the note refers to
|
|
|
|
*
|
|
|
|
* @param note
|
|
|
|
* @param motion
|
|
|
|
*/
|
|
|
|
public exportPersonalNote(note: PersonalNoteContent, motion: ViewMotion): void {
|
|
|
|
const doc = this.motionPdfService.textToDocDef(note.note, motion, 'Personal note');
|
|
|
|
const filename = `${motion.identifierOrTitle} - ${this.translate.instant('Personal note')}`;
|
|
|
|
const metadata = {
|
|
|
|
title: filename
|
|
|
|
};
|
|
|
|
this.pdfDocumentService.download(doc, filename, metadata);
|
|
|
|
}
|
2019-02-11 17:11:35 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Exports the given comment with some short information about the
|
|
|
|
* motion the note refers to
|
|
|
|
*
|
|
|
|
* @param comment
|
|
|
|
* @param motion
|
|
|
|
*/
|
|
|
|
public exportComment(comment: ViewMotionCommentSection, motion: ViewMotion): void {
|
|
|
|
const motionComment = motion.getCommentForSection(comment);
|
|
|
|
if (motionComment && motionComment.comment) {
|
|
|
|
const doc = this.motionPdfService.textToDocDef(motionComment.comment, motion, comment.name);
|
|
|
|
const filename = `${motion.identifierOrTitle} - ${comment.name}`;
|
|
|
|
const metadata = { title: filename };
|
|
|
|
this.pdfDocumentService.download(doc, filename, metadata);
|
|
|
|
}
|
|
|
|
}
|
2019-01-18 20:25:06 +01:00
|
|
|
}
|