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

707 add print button to pair dialog #718

Merged
merged 5 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -15,7 +15,7 @@ interface TabOptions {
selector: 'jhi-project-detail',
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './project-detail.component.html',
styleUrls: ['project-detail.component.scss'],
styleUrls: ['project-detail.component.scss', '../../../content/scss/_print.scss'],
Bdegraaf1234 marked this conversation as resolved.
Show resolved Hide resolved
})
export class ProjectDetailComponent implements OnInit, OnDestroy {
private subscription = new Subscription();
Expand Down
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>;
Bdegraaf1234 marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Up @@ -8,7 +8,7 @@
(click)="clear()">&times;
</button>
</div>
<div class="modal-body">
<div class="modal-body print">
<div class="form-group">
<div>
<label for="login" class="form-control-label"
Expand Down Expand Up @@ -66,6 +66,9 @@
<span class="fa fa-save"></span> <span
[translate]="'managementPortalApp.subject.generatePersistentToken'"></span>
</button>
<button type="button" class="btn btn-default" data-dismiss="modal" (click)="exportHtmlToPDF()">
<span class="fa fa-print"></span><span>Print</span>
</button>
</div>

<div class="form-group" *ngIf="pairInfo !== null">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ 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',
Expand All @@ -35,9 +37,23 @@ 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'];
}
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));
Bdegraaf1234 marked this conversation as resolved.
Show resolved Hide resolved
window.print()
this.printService.setPrintLockTo(false);

}

ngOnInit() {
if (this.subject.project && this.subject.project.persistentTokenTimeout) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/app/shared/subject/subject.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { regularSortOrder, SortOrder, SortOrderImpl } from '../util/sort-util';
selector: 'jhi-subjects',
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './subject.component.html',
styleUrls: ['./subject.component.scss'],
styleUrls: ['./subject.component.scss', '../../../content/scss/_print.scss'],
Bdegraaf1234 marked this conversation as resolved.
Show resolved Hide resolved
})
export class SubjectComponent implements OnInit, OnDestroy, OnChanges {
private subscriptions: Subscription = new Subscription();
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}`)
})
Bdegraaf1234 marked this conversation as resolved.
Show resolved Hide resolved
}

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

* {
-webkit-print-color-adjust: exact;
}

.not-print {
display: none !important;
}

.modal-backdrop {
display: none !important;
}
}
1 change: 1 addition & 0 deletions src/main/webapp/content/scss/global.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

@import '~bootstrap/scss/bootstrap';
@import '~font-awesome/css/font-awesome';
@import "print";

/* ==============================================================
Bootstrap tweaks
Expand Down