Skip to content
Snippets Groups Projects
Commit 062e995b authored by jojohoch's avatar jojohoch
Browse files

Add custom reset button to GeoGebra element

- This allows to reset Geogebra to the state defined in the unit
definition
parent 463f5e34
No related branches found
No related tags found
No related merge requests found
...@@ -13,12 +13,23 @@ declare const GGBApplet: any; ...@@ -13,12 +13,23 @@ declare const GGBApplet: any;
@Component({ @Component({
selector: 'aspect-geometry', selector: 'aspect-geometry',
template: ` template: `
<div [id]="elementModel.id" class="geogebra-applet"></div> <div class="geogebra-container">
<div [id]="elementModel.id" class="geogebra-applet"></div>
<button *ngIf="this.elementModel.showResetIcon"
mat-icon-button
class="reset-button"
(click)="reset()">
<mat-icon class="reset-icon">restart_alt</mat-icon>
</button>
</div>
<aspect-spinner [isLoaded]="isLoaded"></aspect-spinner> <aspect-spinner [isLoaded]="isLoaded"></aspect-spinner>
`, `,
styles: [ styles: [
':host {display: block; width: 100%; height: 100%;}', ':host {display: block; width: 100%; height: 100%;}',
'.geogebra-applet {margin: auto;}' '.geogebra-applet {margin: auto;}',
'.geogebra-container {position: relative;}',
'.reset-button {position: absolute; top: 0; right: 0; z-index: 100; margin: 5px;}',
'.reset-icon {font-size: 30px !important;}'
] ]
}) })
export class GeometryComponent extends ElementComponent implements AfterViewInit, OnDestroy { export class GeometryComponent extends ElementComponent implements AfterViewInit, OnDestroy {
...@@ -27,9 +38,10 @@ export class GeometryComponent extends ElementComponent implements AfterViewInit ...@@ -27,9 +38,10 @@ export class GeometryComponent extends ElementComponent implements AfterViewInit
@Output() elementValueChanged = new EventEmitter<ValueChangeElement>(); @Output() elementValueChanged = new EventEmitter<ValueChangeElement>();
isLoaded: Subject<boolean> = new Subject(); isLoaded: Subject<boolean> = new Subject();
geoGebraApi!: any;
private ngUnsubscribe = new Subject<void>(); private ngUnsubscribe = new Subject<void>();
private geometryUpdated = new EventEmitter<any>(); private geometryUpdated = new EventEmitter<void>();
constructor(public elementRef: ElementRef, constructor(public elementRef: ElementRef,
private renderer: Renderer2, private renderer: Renderer2,
...@@ -39,10 +51,10 @@ export class GeometryComponent extends ElementComponent implements AfterViewInit ...@@ -39,10 +51,10 @@ export class GeometryComponent extends ElementComponent implements AfterViewInit
.pipe( .pipe(
debounceTime(500), debounceTime(500),
takeUntil(this.ngUnsubscribe) takeUntil(this.ngUnsubscribe)
).subscribe((api): void => this.elementValueChanged ).subscribe((): void => this.elementValueChanged
.emit({ .emit({
id: this.elementModel.id, id: this.elementModel.id,
value: api.getBase64() value: this.geoGebraApi.getBase64()
})); }));
} }
...@@ -59,6 +71,12 @@ export class GeometryComponent extends ElementComponent implements AfterViewInit ...@@ -59,6 +71,12 @@ export class GeometryComponent extends ElementComponent implements AfterViewInit
this.initApplet(); this.initApplet();
} }
reset(): void {
this.appDefinition = this.elementModel.appDefinition;
this.initApplet();
this.geometryUpdated.next();
}
private initApplet(): void { private initApplet(): void {
console.log('Initializing GeoGebra applet'); console.log('Initializing GeoGebra applet');
if (!this.appDefinition) { if (!this.appDefinition) {
...@@ -70,11 +88,12 @@ export class GeometryComponent extends ElementComponent implements AfterViewInit ...@@ -70,11 +88,12 @@ export class GeometryComponent extends ElementComponent implements AfterViewInit
width: this.elementModel.width, width: this.elementModel.width,
height: this.elementModel.height, height: this.elementModel.height,
showToolBar: this.elementModel.showToolbar, showToolBar: this.elementModel.showToolbar,
showResetIcon: this.elementModel.showResetIcon, showResetIcon: false,
enableShiftDragZoom: this.elementModel.enableShiftDragZoom, enableShiftDragZoom: this.elementModel.enableShiftDragZoom,
showZoomButtons: this.elementModel.showZoomButtons, showZoomButtons: this.elementModel.showZoomButtons,
showFullscreenButton: this.elementModel.showFullscreenButton, showFullscreenButton: this.elementModel.showFullscreenButton,
customToolBar: this.elementModel.customToolBar, customToolBar: this.elementModel.customToolBar,
enableUndoRedo: false,
showMenuBar: false, showMenuBar: false,
showAlgebraInput: false, showAlgebraInput: false,
enableLabelDrags: false, enableLabelDrags: false,
...@@ -84,25 +103,26 @@ export class GeometryComponent extends ElementComponent implements AfterViewInit ...@@ -84,25 +103,26 @@ export class GeometryComponent extends ElementComponent implements AfterViewInit
showLogging: false, showLogging: false,
useBrowserForJS: false, useBrowserForJS: false,
ggbBase64: this.appDefinition, ggbBase64: this.appDefinition,
appletOnLoad: (api: any) => { appletOnLoad: (geoGebraApi: any) => {
this.geoGebraApi = geoGebraApi;
this.isLoaded.next(true); this.isLoaded.next(true);
api.registerAddListener(() => { this.geoGebraApi.registerAddListener(() => {
this.geometryUpdated.emit(api); this.geometryUpdated.emit();
}); });
api.registerRemoveListener(() => { this.geoGebraApi.registerRemoveListener(() => {
this.geometryUpdated.emit(api); this.geometryUpdated.emit();
}); });
api.registerUpdateListener(() => { this.geoGebraApi.registerUpdateListener(() => {
this.geometryUpdated.emit(api); this.geometryUpdated.emit();
}); });
api.registerRenameListener(() => { this.geoGebraApi.registerRenameListener(() => {
this.geometryUpdated.emit(api); this.geometryUpdated.emit();
}); });
api.registerClearListener(() => { this.geoGebraApi.registerClearListener(() => {
this.geometryUpdated.emit(api); this.geometryUpdated.emit();
}); });
api.registerStoreUndoListener(() => { this.geoGebraApi.registerStoreUndoListener(() => {
this.geometryUpdated.emit(api); this.geometryUpdated.emit();
}); });
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment