Skip to content

Commit

Permalink
added a print service
Browse files Browse the repository at this point in the history
printservice sets printlock from subject-pair-dialog.component.ts
printlock is read from main.component.html.
This needs a timeout in the print function call, hoping to resolve that still.
  • Loading branch information
Bdegraaf1234 committed Sep 15, 2023
1 parent 1a376b2 commit e156b65
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div *ngIf="project$ | async as project" class="not-print">
<div *ngIf="project$ | async as project">
<h2>
<span>
<span [translate]="'managementPortalApp.project.detail.title'"></span>:
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/app/layouts/footer/footer.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="footer not-print" style="align-content: center">
<div class="footer" style="align-content: center">
<p [innerHTML]="'footer' | translate"></p>
</div>
18 changes: 10 additions & 8 deletions src/main/webapp/app/layouts/main/main.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<div [ngClass]="(this.isPrintLocked$ | async) ? 'not-print' : ''">
<jhi-page-ribbon></jhi-page-ribbon>
<div>
<router-outlet name="navbar"></router-outlet>
</div>
<div class="container-fluid">
<div class="card jh-card">
<router-outlet></router-outlet>
<router-outlet name="popup"></router-outlet>
<div>
<router-outlet name="navbar"></router-outlet>
</div>
<div class="container-fluid">
<div class="card jh-card">
<router-outlet></router-outlet>
<router-outlet name="popup"></router-outlet>
</div>
<jhi-footer></jhi-footer>
</div>
<jhi-footer></jhi-footer>
</div>
7 changes: 7 additions & 0 deletions src/main/webapp/app/layouts/main/main.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRouteSnapshot, NavigationEnd, Router } from '@angular/router';
import { Observable } from 'rxjs';

import { JhiLanguageHelper } from '../../shared';
import {PrintService} from "../../shared/util/print.service";

@Component({
selector: 'jhi-main',
Expand All @@ -12,15 +14,20 @@ export class JhiMainComponent implements OnInit {

constructor(
private jhiLanguageHelper: JhiLanguageHelper,
private printService: PrintService,
private router: Router,
) {
}

public isPrintLocked$: Observable<boolean>;

ngOnInit() {
this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) {
this.jhiLanguageHelper.updateTitle();
}
});
this.isPrintLocked$ = this.printService.isPrintLocked$;
//this.isPrintLocked$.subscribe(setTo => console.log("now we updated main.html"));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<form name="pairForm" role="form" novalidate #editForm="ngForm">

<div class="modal-header not-print">
<div class="modal-header">
<h4 class="modal-title" id="mySubjectLabel"
[translate]="'managementPortalApp.subject.home.pairAppLabel'">
</h4>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import { SubjectPopupService } from './subject-popup.service';
import { Subject } from './subject.model';
import { ObservablePopupComponent } from '../util/observable-popup.component';
import { map, switchMap, tap } from 'rxjs/operators';
import { JhiMainComponent } from '../../layouts/main/main.component';
import { PrintService } from '../util/print.service';

@Component({
selector: 'jhi-subject-pair-dialog',
templateUrl: './subject-pair-dialog.component.html',
styleUrls: ['subject-pair-dialog.component.scss', '../../../content/scss/_print.scss'],
styleUrls: ['subject-pair-dialog.component.scss'],
})
export class SubjectPairDialogComponent implements OnInit, OnDestroy {
readonly authorities: string[];
Expand All @@ -35,12 +37,24 @@ export class SubjectPairDialogComponent implements OnInit, OnDestroy {
private oauthClientService: OAuthClientService,
private pairInfoService: OAuthClientPairInfoService,
private datePipe: DatePipe,
private printService: PrintService,
@Inject(DOCUMENT) private doc) {
this.authorities = ['ROLE_USER', 'ROLE_SYS_ADMIN'];
}
exportHtmlToPDF() {
window.print();
async exportHtmlToPDF() {
// let pp: PrintService = this.printService;
// window.onafterprint = function(){
// console.log("Printing completed...");
// //pp.togglePrintLock().then(_ => {})
// }

this.printService.setPrintLockTo(true);
await new Promise(r => setTimeout(r, 0.000000000000000000000000000000000000000000000000000001));
window.print()
this.printService.setPrintLockTo(false);

}

ngOnInit() {
if (this.subject.project && this.subject.project.persistentTokenTimeout) {
this.allowPersistentToken = true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/app/shared/subject/subject.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="subject-wrapper not-print" xmlns="http://www.w3.org/1999/html">
<div class="subject-wrapper" xmlns="http://www.w3.org/1999/html">
<div class="subject-filter">
<div class="subject-filter-header">
<h5 [translate]="'managementPortalApp.subject.filter.title'"></h5>
Expand Down
19 changes: 19 additions & 0 deletions src/main/webapp/app/shared/util/print.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject } from "rxjs";

@Injectable({ providedIn: 'root' })
export class PrintService {

public isPrintLocked$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);

constructor(
) {
this.isPrintLocked$.subscribe(isPrintLocked => {
//console.log(`isPrintlocked: ${isPrintLocked}`)
})
}

setPrintLockTo(setTo: boolean) {
this.isPrintLocked$.next(setTo)
}
}
2 changes: 0 additions & 2 deletions src/main/webapp/content/scss/_print.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


@media print {

* {
Expand Down

0 comments on commit e156b65

Please sign in to comment.