-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcomponent-authoring.component.ts
More file actions
103 lines (97 loc) · 3.05 KB
/
Copy pathcomponent-authoring.component.ts
File metadata and controls
103 lines (97 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { Component, effect, Input } from '@angular/core';
import { ComponentContent } from '../../common/ComponentContent';
import { PreviewComponentComponent } from './preview-component/preview-component.component';
import { ComponentFactory } from '../../common/ComponentFactory';
import { Component as WISEComponent } from '../../common/Component';
import { TeacherProjectService } from '../../services/teacherProjectService';
import { MatTooltipModule } from '@angular/material/tooltip';
import { TeacherProjectTranslationService } from '../../services/teacherProjectTranslationService';
import { copy } from '../../common/object/object';
import { MatDialog } from '@angular/material/dialog';
import { EditComponentDialogComponent } from './edit-component-dialog/edit-component-dialog.component';
import { Subscription } from 'rxjs';
@Component({
imports: [PreviewComponentComponent, EditComponentDialogComponent, MatTooltipModule],
selector: 'component-authoring',
styles: [
`
preview-component {
display: block;
position: relative;
cursor: pointer;
}
preview-component:hover {
outline: 3px dashed #aaaaaa;
outline-offset: 8px;
}
preview-component:after {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
`
],
template: `
<preview-component
role="button"
tabindex="0"
(click)="editComponent()"
(keyup.enter)="editComponent()"
[component]="component"
[disabled]="true"
matTooltip="Edit content"
i18n-matTooltip
/>
`
})
export class ComponentAuthoringComponent {
protected component: WISEComponent;
@Input() componentContent: ComponentContent;
@Input() nodeId: string;
private subscriptions = new Subscription();
constructor(
private dialog: MatDialog,
private projectService: TeacherProjectService,
private projectTranslationService: TeacherProjectTranslationService
) {
effect(() => {
this.setComponent();
});
this.subscriptions.add(
this.projectService.projectSaved$.subscribe(() => {
this.setComponent();
})
);
}
ngOnChanges(): void {
this.setComponent();
}
ngOnDestroy(): void {
this.subscriptions.unsubscribe();
}
private setComponent(): void {
// when current translations change, apply translations to a copy of the component content
// so the original component content is not modified for subsequent use.
const componentContent = copy(this.componentContent);
this.projectTranslationService.applyTranslations(
componentContent,
this.projectTranslationService.currentTranslations()
);
this.component = new ComponentFactory().getComponent(
this.projectService.injectAssetPaths(componentContent),
this.nodeId
);
}
protected editComponent(): void {
this.dialog.open(EditComponentDialogComponent, {
data: {
componentContent: this.componentContent,
nodeId: this.nodeId
},
panelClass: 'dialog-xl'
});
}
}