File
Implements
Metadata
selector |
div[action-panel] |
styleUrls |
./action-panel.component.scss |
templateUrl |
./action-panel.component.html |
Index
Properties
|
|
Methods
|
|
Inputs
|
|
Constructor
constructor(keycloakService: KeycloakService, http: HttpClient)
|
|
Parameters :
Name |
Type |
Optional |
keycloakService |
KeycloakService
|
No
|
http |
HttpClient
|
No
|
|
disabled
|
Default value : false
|
|
isDownload
|
Default value : false
|
|
loginRequired
|
Default value : false
|
|
Methods
Public
downloadResource
|
downloadResource()
|
|
Returns : Observable<Blob>
|
Public
downloadZip
|
downloadZip()
|
|
|
Private
downloadZipLink
|
Type : ElementRef
|
Decorators :
@ViewChild('downloadZipLink')
|
|
openOrDownloadObj
|
Type : any
|
|
import { Component, OnInit, Input, ViewChild, ElementRef } from '@angular/core';
import { KeycloakService } from 'keycloak-angular';
import { AppConfig } from '../../app.config';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
@Component({
selector: 'div[action-panel]',
templateUrl: './action-panel.component.html',
styleUrls: ['./action-panel.component.scss']
})
export class ActionPanelComponent implements OnInit {
@Input() buttonText;
@Input() openOrDownloadUrl;
@Input() newWindow;
@Input() disabled = false;
@Input() loginRequired = false;
@Input() isDownload = false;
@ViewChild('downloadZipLink') private downloadZipLink: ElementRef;
openOrDownloadObj: any;
constructor(private keycloakService: KeycloakService, private http: HttpClient) { }
ngOnInit() {
this.openOrDownloadObj = (this.disabled || this.loginRequired) ? '#' : this.openOrDownloadUrl;
}
public login() {
this.keycloakService.login();
return false;
}
public downloadResource(): Observable<Blob> {
return this.http.get<Blob>(this.openOrDownloadObj.Url, {responseType: 'blob' as 'json'});
}
public downloadZip(): void {
const downloadObserver = this.downloadResource().pipe( map( res => {
return {
filename: (this.openOrDownloadObj.toolFileName.match(/\.zip/i)) ? this.openOrDownloadObj.toolFileName : this.openOrDownloadObj.toolFileName + '.zip',
data: res
};
})).subscribe((res) => {
const url = window.URL.createObjectURL(res.data);
{
const link = document.createElement('a');
document.body.appendChild(link);
link.setAttribute('style', 'display: none');
link.href = url;
link.download = res.filename;
link.click();
link.remove();
}
window.URL.revokeObjectURL(url);
}, ((err) => {
console.log(err);
}), () => downloadObserver.unsubscribe());
}
}
<div class="action-panel">
<div class="text-area">
<ng-content select=[action-text]></ng-content>
</div>
<ng-container [ngSwitch]=isDownload>
<span #downloadZipLink *ngSwitchCase="true" class="btn btn-green" [ngClass]="{'disabled': disabled}"
(click)="loginRequired ? login() : downloadZip()">{{buttonText}}</span>
<a *ngSwitchCase="false" [href]="openOrDownloadObj.ExternalLink" [target]="newWindow ? '_blank' : '_self'"
class="btn btn-green" [ngClass]="{'disabled': disabled}"
(click)="loginRequired ? login() : true">{{buttonText}}</a>
</ng-container>
</div>
@import "src/app/styles/helpers";
:host {
background-color: $cool-grey;
}
.action-panel {
display: flex;
justify-content: center;
align-items: center;
background-color: $cool-grey;
flex-direction: column;
padding: calc-rem(20);
.text-area {
color: white;
display: flex;
flex-direction: column;
text-align: center;
margin-bottom: calc-rem(20);
@include media-breakpoint-up(md) {
text-align: start;
}
}
a, span {
@include media-breakpoint-up(md) {
margin-left: calc-rem(25);
}
padding: calc-rem(10) calc-rem(35);
&[target=_blank]:after {
content: none;
}
&.disabled {
color: $white;
opacity: .3;
}
cursor: pointer;
}
@include media-breakpoint-up(md) {
flex-direction: row;
.text-area {
margin: 0;
}
}
}
Legend
Html element with directive