Skip to content
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

feat(print): print Ionic service #685

Merged
merged 26 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
930cf17
Merge pull request #5 from infra-geo-ouverte/1.0.0-alpha
drekss Aug 9, 2019
e1e5d45
Merge pull request #8 from infra-geo-ouverte/1.0.0-alpha
drekss Aug 13, 2019
aa8c4e3
Merge pull request #12 from infra-geo-ouverte/1.0.0-alpha
drekss Aug 28, 2019
74ca893
Merge pull request #16 from infra-geo-ouverte/master
drekss Sep 29, 2019
e04d3b8
Merge pull request #17 from infra-geo-ouverte/master
drekss Oct 4, 2019
ce783db
Merge pull request #18 from infra-geo-ouverte/master
drekss Oct 11, 2019
af80ed7
Merge pull request #19 from infra-geo-ouverte/master
drekss Oct 29, 2019
197663e
Merge pull request #20 from infra-geo-ouverte/master
drekss Oct 29, 2019
16532c1
Merge pull request #21 from infra-geo-ouverte/master
drekss Oct 30, 2019
f2a365a
Merge pull request #22 from infra-geo-ouverte/master
drekss Oct 31, 2019
776658c
Merge pull request #25 from infra-geo-ouverte/master
drekss Nov 9, 2019
dafec8a
Merge pull request #26 from infra-geo-ouverte/master
drekss Nov 15, 2019
2765fef
Merge pull request #28 from infra-geo-ouverte/master
drekss Dec 5, 2019
1d3547b
Merge pull request #30 from infra-geo-ouverte/master
drekss Dec 18, 2019
2b7387a
Merge pull request #32 from infra-geo-ouverte/master
drekss Feb 28, 2020
72587a3
add params to clusterStyle
May 5, 2020
46d3481
Merge pull request #39 from infra-geo-ouverte/next
drekss May 11, 2020
d309ca3
Merge pull request #40 from infra-geo-ouverte/next
drekss May 25, 2020
83102ba
Merge pull request #41 from infra-geo-ouverte/next
drekss Jun 4, 2020
d098469
Merge pull request #42 from infra-geo-ouverte/next
drekss Jun 10, 2020
aac0c7e
Merge pull request #43 from infra-geo-ouverte/next
drekss Jun 18, 2020
fc55364
print with ionic
Jun 18, 2020
d215637
commit lock
Jun 22, 2020
39b8ead
print service extends
Jul 8, 2020
47511fc
Update index.ts
mbarbeau Jul 8, 2020
8d8c1b9
Update print-ionic.service.ts
mbarbeau Jul 8, 2020
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
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
"@ionic-native/core": "^5.10.0",
"@ionic-native/network": "^5.12.0",
"@ionic/angular": "^4.6.2",
"@ionic-native/file": "^5.6.0",
"@ionic-native/file-opener": "^5.6.0",
"@mat-datetimepicker/core": "^3.0.0-beta.0",
"@mdi/angular-material": "^4.7.95",
"@ngx-translate/core": "^10.0.1",
Expand Down
62 changes: 62 additions & 0 deletions packages/geo/src/lib/print/shared/print-ionic.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Injectable } from '@angular/core';
import * as jsPDF from 'jspdf';
import { Platform } from '@ionic/angular';
import { File } from '@ionic-native/file/ngx';
import { FileOpener } from '@ionic-native/file-opener/ngx';

import { MessageService, ActivityService, LanguageService } from '@igo2/core';
import { PrintService } from './print.service';

@Injectable({
providedIn: 'root'
})
export class PrintIonicService extends PrintService {
date: Date;
day: string;
month: any;
hour: string;
minute: string;
year: string;

constructor(
messageService: MessageService,
activityService: ActivityService,
languageService: LanguageService,
private platform: Platform,
private fileOpener: FileOpener,
private file: File
) {
super(messageService, activityService, languageService);
}

protected saveDoc(doc: jsPDF) {
if (this.platform.is('cordova')) {
const docOutput = doc.output();
const buffer = new ArrayBuffer(docOutput.length);
const array = new Uint8Array(buffer);
this.setDate();
for (let i = 0; i < docOutput.length; i++) {
array[i] = docOutput.charCodeAt(i);
}
const fileName = 'map' + this.year + '-' + this.month + '-' + this.day + '-' + this.hour + '-' + this.minute + '.pdf';
const directory = this.file.externalRootDirectory + 'Download';
this.file.writeFile(directory, fileName, buffer, { replace: true }).then((success) =>
this.fileOpener.open(directory + '/' + fileName, 'application/pdf'));
} else {
super.saveDoc(doc);
}
}
private setDate() {
this.date = new Date();
this.day = this.date.getDate().toString();
this.month = this.date.getMonth() + 1;
if (this.month < 10) {
this.month = '0' + this.month.toString();
} else {
this.month = this.month.toString();
}
this.year = this.date.getFullYear().toString();
this.hour = this.date.getHours().toString();
this.minute = this.date.getMinutes().toString();
}
}
2 changes: 1 addition & 1 deletion packages/geo/src/lib/print/shared/print.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ export class PrintService {
* Save document
* @param doc - Document to save
*/
private saveDoc(doc: jsPDF) {
protected saveDoc(doc: jsPDF) {
doc.save('map.pdf');
}

Expand Down