-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
13 changed files
with
154 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
:host { | ||
|
||
.view-container { | ||
display: grid; | ||
grid-template-columns: repeat(auto-fit, minmax(10px, 1fr)); | ||
grid-template-rows: 1fr; | ||
grid-column-gap: 1rem; | ||
|
||
> * { | ||
overflow-y: auto; | ||
} | ||
|
||
} | ||
|
||
planet-resources-viewer * { | ||
max-width: 100%; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/app/resources/view-resources/resources-viewer.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div [ngSwitch]="mediaType"> | ||
<img [src]="resourceSrc" *ngSwitchCase="'image'"> | ||
<video controls *ngSwitchCase="'video'"> | ||
<source [src]="resourceSrc" [type]="contentType" /> | ||
Browser not supported | ||
</video> | ||
<audio controls *ngSwitchCase="'audio'"> | ||
<source [src]="resourceSrc" [type]="contentType" /> | ||
Browser not supported | ||
</audio> | ||
<iframe [src]="pdfSrc" *ngSwitchCase="'pdf'" width="100%" height="100%" allowfullscreen mozallowfullscreen webkitallowfullscreen | ||
oallowfullscreen msallowfullscreen ></iframe> | ||
<div *ngSwitchCase="'other'"><a mat-button-raised href={{resourceSrc}}>Open File</a></div> | ||
<iframe *ngSwitchCase="'HTML'" [src]="pdfSrc"></iframe> | ||
</div> |
66 changes: 66 additions & 0 deletions
66
src/app/resources/view-resources/resources-viewer.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Component, Input, OnChanges, OnDestroy, EventEmitter, Output } from '@angular/core'; | ||
|
||
import { DomSanitizer } from '@angular/platform-browser'; | ||
import { environment } from '../../../environments/environment'; | ||
import { takeUntil } from 'rxjs/operators'; | ||
import { Subject } from 'rxjs/Subject'; | ||
import { ResourcesService } from '../resources.service'; | ||
|
||
@Component({ | ||
selector: 'planet-resources-viewer', | ||
templateUrl: './resources-viewer.component.html', | ||
styleUrls: [ './resources-viewer.scss' ] | ||
}) | ||
export class ResourcesViewerComponent implements OnChanges, OnDestroy { | ||
|
||
@Input() resourceId: string; | ||
@Input() resource: any; | ||
@Output() resourceUrl = new EventEmitter<any>(); | ||
mediaType: string; | ||
contentType: string; | ||
resourceSrc: string; | ||
urlPrefix = environment.couchAddress + 'resources/'; | ||
pdfSrc: any; | ||
private onDestroy$ = new Subject<void>(); | ||
|
||
constructor( | ||
private sanitizer: DomSanitizer, | ||
private resourcesService: ResourcesService | ||
) { } | ||
|
||
ngOnChanges() { | ||
if (this.resource === undefined || this.resource._id !== this.resourceId) { | ||
this.resourcesService.resourcesUpdated$.pipe(takeUntil(this.onDestroy$)) | ||
.subscribe((resourceArr) => { | ||
this.setResource(resourceArr[0]); | ||
}); | ||
this.resourcesService.updateResources({ resourceIds: [ this.resourceId ] }); | ||
} else { | ||
this.setResource(this.resource); | ||
} | ||
} | ||
|
||
ngOnDestroy() { | ||
this.onDestroy$.next(); | ||
this.onDestroy$.complete(); | ||
} | ||
|
||
setResource(resource: any) { | ||
this.resource = resource; | ||
// openWhichFile is used to label which file to start with for HTML resources | ||
const filename = resource.openWhichFile || Object.keys(resource._attachments)[0]; | ||
this.mediaType = resource.mediaType; | ||
this.contentType = resource._attachments[filename].content_type; | ||
this.resourceSrc = this.urlPrefix + resource._id + '/' + filename; | ||
if (!this.mediaType) { | ||
const mediaTypes = [ 'image', 'pdf', 'audio', 'video', 'zip' ]; | ||
this.mediaType = mediaTypes.find((type) => this.contentType.indexOf(type) > -1) || 'other'; | ||
} | ||
if (this.mediaType === 'pdf' || this.mediaType === 'HTML') { | ||
this.pdfSrc = this.sanitizer.bypassSecurityTrustResourceUrl(this.resourceSrc); | ||
} | ||
// Emit resource src so parent component can use for links | ||
this.resourceUrl.emit(this.resourceSrc); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@import '../../variables'; | ||
|
||
:host { | ||
* { | ||
max-width: 100%; | ||
} | ||
|
||
iframe { | ||
display: block; | ||
border: none; | ||
width: 100%; | ||
height: $view-container-height; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters