diff --git a/src/app/workspace/resource/representation/document/document.component.html b/src/app/workspace/resource/representation/document/document.component.html
index 896ab7ceff..96226bb3ae 100644
--- a/src/app/workspace/resource/representation/document/document.component.html
+++ b/src/app/workspace/resource/representation/document/document.component.html
@@ -1,21 +1,34 @@
-
diff --git a/src/app/workspace/resource/representation/document/document.component.scss b/src/app/workspace/resource/representation/document/document.component.scss
index 43475e0ecd..fad80cdb72 100644
--- a/src/app/workspace/resource/representation/document/document.component.scss
+++ b/src/app/workspace/resource/representation/document/document.component.scss
@@ -36,7 +36,8 @@ $osd-height: 460px;
.pdf-searchbox {
border-radius: $border-radius;
border: none;
- padding: 4px;
+ padding: 4px 12px;
+ margin: 4px;
&:active {
border: none;
diff --git a/src/app/workspace/resource/representation/document/document.component.ts b/src/app/workspace/resource/representation/document/document.component.ts
index c12782cf29..51951d0752 100644
--- a/src/app/workspace/resource/representation/document/document.component.ts
+++ b/src/app/workspace/resource/representation/document/document.component.ts
@@ -19,6 +19,8 @@ import { ErrorHandlerService } from 'src/app/main/services/error-handler.service
import { EmitEvent, Events, UpdatedFileEventValue, ValueOperationEventService } from '../../services/value-operation-event.service';
import { FileRepresentation } from '../file-representation';
import { RepresentationService } from '../representation.service';
+import { HttpClient, HttpHeaders } from '@angular/common/http';
+import { DOCUMENT } from '@angular/common';
@Component({
selector: 'app-document',
@@ -35,14 +37,20 @@ export class DocumentComponent implements OnInit, AfterViewInit {
@ViewChild(PdfViewerComponent) private _pdfComponent: PdfViewerComponent;
+ originalFilename: string;
+
zoomFactor = 1.0;
pdfQuery = '';
failedToLoad = false;
+ elem: any;
+
constructor(
+ @Inject(DOCUMENT) private document: any,
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
+ private readonly _http: HttpClient,
private _dialog: MatDialog,
private _errorHandler: ErrorHandlerService,
private _rs: RepresentationService,
@@ -50,6 +58,8 @@ export class DocumentComponent implements OnInit, AfterViewInit {
) { }
ngOnInit(): void {
+ this.elem = document.getElementsByClassName('pdf-viewer')[0];
+ this._getOriginalFilename();
this.failedToLoad = !this._rs.doesFileExist(this.src.fileValue.fileUrl);
}
@@ -72,6 +82,32 @@ export class DocumentComponent implements OnInit, AfterViewInit {
}
}
+ async downloadDocument(url: string) {
+ try {
+ const res = await this._http.get(url, { responseType: 'blob' }).toPromise();
+ this.downloadFile(res);
+ } catch (e) {
+ this._errorHandler.showMessage(e);
+ }
+ }
+
+ downloadFile(data) {
+ const url = window.URL.createObjectURL(data);
+ const e = document.createElement('a');
+ e.href = url;
+
+ // set filename
+ if (this.originalFilename === undefined) {
+ e.download = url.substr(url.lastIndexOf('/') + 1);
+ } else {
+ e.download = this.originalFilename;
+ }
+
+ document.body.appendChild(e);
+ e.click();
+ document.body.removeChild(e);
+ }
+
openReplaceFileDialog(){
const propId = this.parentResource.properties[Constants.HasDocumentFileValue][0].id;
@@ -96,6 +132,36 @@ export class DocumentComponent implements OnInit, AfterViewInit {
});
}
+ openFullscreen() {
+ if (this.elem.requestFullscreen) {
+ this.elem.requestFullscreen();
+ } else if (this.elem.mozRequestFullScreen) {
+ // firefox
+ this.elem.mozRequestFullScreen();
+ } else if (this.elem.webkitRequestFullscreen) {
+ // chrome, safari and opera
+ this.elem.webkitRequestFullscreen();
+ } else if (this.elem.msRequestFullscreen) {
+ // edge, ie
+ this.elem.msRequestFullscreen();
+ }
+ }
+
+ private _getOriginalFilename() {
+ const requestOptions = {
+ headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
+ withCredentials: true
+ };
+
+ const pathToJson = this.src.fileValue.fileUrl.substring(0, this.src.fileValue.fileUrl.lastIndexOf('/')) + '/knora.json';
+
+ this._http.get(pathToJson, requestOptions).subscribe(
+ res => {
+ this.originalFilename = res['originalFilename'];
+ }
+ );
+ }
+
private _replaceFile(file: UpdateFileValue) {
const updateRes = new UpdateResource();
updateRes.id = this.parentResource.id;
@@ -113,6 +179,8 @@ export class DocumentComponent implements OnInit, AfterViewInit {
this.src.fileValue.strval = (res2.properties[Constants.HasDocumentFileValue][0] as ReadDocumentFileValue).strval;
this.src.fileValue.valueCreationDate = (res2.properties[Constants.HasDocumentFileValue][0] as ReadDocumentFileValue).valueCreationDate;
+ this._getOriginalFilename();
+
this.zoomFactor = 1.0;
this.pdfQuery = '';