This repository has been archived by the owner on Feb 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix accordion display and ordering bug
More than one accordion block could not be displayed. Furthermore, the order of the blocks was not implemented.
- Loading branch information
Nicolas Märchy
committed
May 1, 2018
1 parent
c977ea8
commit 9da3a41
Showing
10 changed files
with
234 additions
and
315 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
<ion-card class="accordion" *ngIf="accordion.visible"> | ||
|
||
<ion-card-content> | ||
<ion-card-content> | ||
|
||
<ion-card-title (click)="toggle()"> | ||
<ion-card-title (click)="toggle()"> | ||
|
||
<ion-icon *ngIf="!expanded" name="arrow-forward"></ion-icon> | ||
<ion-icon *ngIf="expanded" name="arrow-down"></ion-icon> | ||
<ion-icon *ngIf="!expanded" name="arrow-forward"></ion-icon> | ||
<ion-icon *ngIf="expanded" name="arrow-down"></ion-icon> | ||
|
||
{{accordion.title}} | ||
</ion-card-title> | ||
{{accordion.title}} | ||
</ion-card-title> | ||
|
||
|
||
<div #expandWrapper [@expanded]="expanded"> | ||
<div #expandWrapper [@expanded]="expanded"> | ||
|
||
<div *ngFor="let block of accordion.blocks"> | ||
<text-block *ngIf="(block | async).isRichtext()" [value]="block"></text-block> | ||
<picture-block *ngIf="(block | async).isPicture()" [value]="block"></picture-block> | ||
<video-block *ngIf="(block | async).isVideo()" [value]="block"></video-block> | ||
<link-block *ngIf="(block | async).isLink()" [value]="block"></link-block> | ||
</div> | ||
<div *ngFor="let block of (accordion.blocks | async)"> | ||
<text-block *ngIf="block.isRichtext()" [value]="block"></text-block> | ||
<picture-block *ngIf="block.isPicture()" [value]="block"></picture-block> | ||
<video-block *ngIf="block.isVideo()" [value]="block"></video-block> | ||
<link-block *ngIf="block.isLink()" [value]="block"></link-block> | ||
</div> | ||
|
||
</div> | ||
</div> | ||
|
||
</ion-card-content> | ||
</ion-card-content> | ||
|
||
</ion-card> | ||
|
||
<ion-card *ngIf="!accordion.visible" color=primary> | ||
|
||
<ion-card-content> | ||
{{"learnplace.block.accordion.too_far_away" | translate}} | ||
</ion-card-content> | ||
<ion-card-content> | ||
{{"learnplace.block.accordion.too_far_away" | translate}} | ||
</ion-card-content> | ||
|
||
</ion-card> |
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
92 changes: 36 additions & 56 deletions
92
src/learnplace/directives/pictureblock/pictureblock.directive.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 |
---|---|---|
@@ -1,78 +1,58 @@ | ||
import {ChangeDetectorRef, Component, Input, OnDestroy, OnInit} from "@angular/core"; | ||
import {Component, Input, OnDestroy, OnInit} from "@angular/core"; | ||
import {PictureBlockModel} from "../../services/block.model"; | ||
import {Platform} from "ionic-angular"; | ||
import {File} from "@ionic-native/file"; | ||
import {PhotoViewer, PhotoViewerOptions} from "@ionic-native/photo-viewer"; | ||
import {DomSanitizer, SafeUrl} from "@angular/platform-browser"; | ||
import {Logger} from "../../../services/logging/logging.api"; | ||
import {Logging} from "../../../services/logging/logging.service"; | ||
import {Observable} from "rxjs/Observable"; | ||
import {Subscription} from "rxjs/Subscription"; | ||
import {isDefined} from "ionic-angular/es2015/util/util"; | ||
|
||
@Component({ | ||
selector: "picture-block", | ||
templateUrl: "picture-block.html" | ||
selector: "picture-block", | ||
templateUrl: "picture-block.html" | ||
}) | ||
export class PictureBlock implements OnInit, OnDestroy { | ||
export class PictureBlock implements OnInit { | ||
|
||
@Input("value") | ||
readonly observablePicture: Observable<PictureBlockModel>; | ||
@Input("value") | ||
readonly pictureBlock: PictureBlockModel; | ||
|
||
pictureBlock: PictureBlockModel | undefined = undefined; | ||
embeddedSrc?: SafeUrl; | ||
|
||
embeddedSrc: SafeUrl | undefined = undefined; | ||
private readonly log: Logger = Logging.getLogger(PictureBlock.name); | ||
|
||
private pictureBlockSubscription: Subscription | undefined = undefined; | ||
|
||
private readonly log: Logger = Logging.getLogger(PictureBlock.name); | ||
|
||
constructor( | ||
private readonly platform: Platform, | ||
private readonly file: File, | ||
private readonly photoViewer: PhotoViewer, | ||
private readonly sanitizer: DomSanitizer, | ||
private readonly detectorRef: ChangeDetectorRef | ||
) {} | ||
|
||
ngOnInit(): void { | ||
constructor( | ||
private readonly platform: Platform, | ||
private readonly file: File, | ||
private readonly photoViewer: PhotoViewer, | ||
private readonly sanitizer: DomSanitizer | ||
) { | ||
} | ||
|
||
this.pictureBlockSubscription = this.observablePicture.subscribe(it => { | ||
this.pictureBlock = it; | ||
this.detectorRef.detectChanges(); | ||
}); | ||
ngOnInit(): void { | ||
|
||
// because the thumbnail is immutable, we only use the first picture block to encode it | ||
this.observablePicture.first().subscribe(it => { | ||
const fileName: string = it.thumbnail.split("/").pop(); | ||
const path: string = it.thumbnail.replace(fileName, ""); | ||
const fileName: string = this.pictureBlock.thumbnail.split("/").pop(); | ||
const path: string = this.pictureBlock.thumbnail.replace(fileName, ""); | ||
|
||
this.file.readAsDataURL(`${this.getStorageLocation()}${path}`, fileName).then(data => { | ||
this.embeddedSrc = this.sanitizer.bypassSecurityTrustUrl(data); | ||
}).catch(error => { | ||
this.log.warn(() => `Could not load thumbnail: url: ${it.thumbnail}`); | ||
this.log.debug(() => `Thumbnail load error: ${JSON.stringify(error)}`); | ||
}); | ||
}); | ||
} | ||
this.file.readAsDataURL(`${this.getStorageLocation()}${path}`, fileName).then(data => { | ||
this.embeddedSrc = this.sanitizer.bypassSecurityTrustUrl(data); | ||
}).catch(error => { | ||
this.log.warn(() => `Could not load thumbnail: url: ${this.pictureBlock.thumbnail}`); | ||
this.log.debug(() => `Thumbnail load error: ${JSON.stringify(error)}`); | ||
}); | ||
} | ||
|
||
ngOnDestroy(): void { | ||
if(isDefined(this.pictureBlockSubscription)) | ||
this.pictureBlockSubscription.unsubscribe(); | ||
} | ||
show(): void { | ||
this.photoViewer.show(`${this.getStorageLocation()}${this.pictureBlock.url}`, this.pictureBlock.title, <PhotoViewerOptions>{share: false}); | ||
} | ||
|
||
show(): void { | ||
this.photoViewer.show(`${this.getStorageLocation()}${this.pictureBlock.url}`, this.pictureBlock.title, <PhotoViewerOptions>{share:false}); | ||
} | ||
private getStorageLocation(): string { | ||
if (this.platform.is("android")) { | ||
return this.file.externalApplicationStorageDirectory; | ||
} | ||
if (this.platform.is("ios")) { | ||
return this.file.dataDirectory; | ||
} | ||
|
||
private getStorageLocation(): string { | ||
if (this.platform.is("android")) { | ||
return this.file.externalApplicationStorageDirectory; | ||
throw new Error("Unsupported platform. Can not return a storage location."); | ||
} | ||
if (this.platform.is("ios")) { | ||
return this.file.dataDirectory; | ||
} | ||
|
||
throw new Error("Unsupported platform. Can not return a storage location."); | ||
} | ||
} |
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
Oops, something went wrong.