Skip to content
Open

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { MockComponent, MockProviders } from 'ng-mocks';
import { ComponentContent } from '../../../assets/wise5/common/ComponentContent';
import { EditShowMyWorkAdvancedComponent } from '../../../assets/wise5/components/showMyWork/edit-show-my-work-advanced/edit-show-my-work-advanced.component';
Expand All @@ -9,6 +8,7 @@ import { TeacherNodeService } from '../../../assets/wise5/services/teacherNodeSe
import { TeacherProjectService } from '../../../assets/wise5/services/teacherProjectService';
import { EditComponentAdvancedComponent } from './edit-component-advanced.component';
import { ComponentServiceLookupService } from '../../../assets/wise5/services/componentServiceLookupService';
import { Component } from '../../../assets/wise5/common/Component';

let component: EditComponentAdvancedComponent;
let fixture: ComponentFixture<EditComponentAdvancedComponent>;
Expand All @@ -17,23 +17,6 @@ describe('EditComponentAdvancedComponent', () => {
await TestBed.configureTestingModule({
imports: [MockComponent(EditShowMyWorkAdvancedComponent), EditComponentAdvancedComponent],
providers: [
{
provide: MAT_DIALOG_DATA,
useValue: {
component: {
content: { type: 'ShowMyWork' },
id: 'component1',
nodeId: 'node1'
},
tab: 'general'
}
},
{
provide: MatDialogRef,
useValue: {
close: () => {}
}
},
MockProviders(
ComponentServiceLookupService,
TeacherNodeService,
Expand All @@ -46,6 +29,11 @@ describe('EditComponentAdvancedComponent', () => {

fixture = TestBed.createComponent(EditComponentAdvancedComponent);
component = fixture.componentInstance;
component.component = {
id: 'component1',
nodeId: 'node1',
content: { type: 'ShowMyWork' }
} as Component;
spyOn(TestBed.inject(TeacherProjectService), 'getComponent').and.returnValue({
type: 'ShowMyWork'
} as ComponentContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,60 @@ import {
createComponent,
ElementRef,
EnvironmentInjector,
Inject,
Input,
ViewChild,
ViewEncapsulation
} from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
import { MatDivider } from '@angular/material/divider';
import { MatDialogModule } from '@angular/material/dialog';
import { Component as WISEComponent } from '../../../assets/wise5/common/Component';
import { components } from '../../../assets/wise5/components/Components';

@Component({
encapsulation: ViewEncapsulation.None,
imports: [MatDivider, MatDialogModule, MatButtonModule],
imports: [MatDialogModule, MatButtonModule],
selector: 'edit-component-advanced',
styles: [
`
.edit-component-advanced {
--mat-tab-divider-color: var(--mat-divider-color);
--mat-tab-divider-height: 1px;
.mat-divider {
margin: 0 -16px;
height: 100%;
.mat-mdc-tab-group,
.mat-mdc-tab-body-wrapper {
height: 100%;
}
.mat-mdc-tab-body-content {
padding: 16px 0;
padding: 16px;
}
.mat-mdc-tab-header {
position: sticky;
top: 0;
z-index: 2;
background-color: white;
margin: 0 -16px;
}
}
`
],
templateUrl: './edit-component-advanced.component.html'
template: '<div class="edit-component-advanced" #component></div>'
})
export class EditComponentAdvancedComponent {
@Input() component: WISEComponent;
@ViewChild('component') private componentElementRef: ElementRef;
private componentRef: ComponentRef<WISEComponent>;
constructor(
private applicationRef: ApplicationRef,
@Inject(MAT_DIALOG_DATA) protected data: { component: WISEComponent; tab?: string },
private injector: EnvironmentInjector
) {}

ngAfterViewInit(): void {
this.componentRef = createComponent(
components[this.data.component.content.type].authoringAdvanced,
{
hostElement: this.componentElementRef.nativeElement,
environmentInjector: this.injector
}
);
this.componentRef = createComponent(components[this.component.content.type].authoringAdvanced, {
hostElement: this.componentElementRef.nativeElement,
environmentInjector: this.injector
});
Object.assign(this.componentRef.instance, {
nodeId: this.data.component.nodeId,
componentId: this.data.component.id,
tab: this.data.tab
nodeId: this.component.nodeId,
componentId: this.component.id
});
this.applicationRef.attachView(this.componentRef.hostView);
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/authoring-tool/edit-component-field.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export abstract class EditComponentFieldComponent {
this.inputChangedSubscription = this.inputChanged
.pipe(debounceTime(1000), distinctUntilChanged())
.subscribe(() => {
this.projectService.componentChanged();
this.projectService.saveProject();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class EditComponentJsonComponent {
this.projectService
.getNode(this.component.nodeId)
.replaceComponent(this.component.id, JSON.parse(this.componentContentJSONString));
this.projectService.componentChanged();
this.projectService.saveProject();
this.notificationService.showJSONValidMessage();
} catch (e) {
this.notificationService.showJSONInvalidMessage();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { Component, Input } from '@angular/core';
import { Component, Input, ViewEncapsulation } from '@angular/core';
import { TeacherProjectService } from '../../../assets/wise5/services/teacherProjectService';
import { TranslatableRichTextEditorComponent } from '../../../assets/wise5/authoringTool/components/translatable-rich-text-editor/translatable-rich-text-editor.component';

@Component({
encapsulation: ViewEncapsulation.None,
imports: [TranslatableRichTextEditorComponent],
selector: 'edit-component-rubric',
styles: `
translatable-rich-text-editor editor {
height: 100% !important;
}
`,
template: `<translatable-rich-text-editor
[content]="componentContent"
key="rubric"
Expand All @@ -17,6 +23,6 @@ export class EditComponentRubricComponent {
constructor(private projectService: TeacherProjectService) {}

protected save(): void {
this.projectService.componentChanged();
this.projectService.saveProject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class EditComponentTagsComponent {
.pipe(debounceTime(1000), distinctUntilChanged())
.subscribe(({ tagIndex, tag }) => {
this.componentContent.tags[tagIndex] = tag;
this.projectService.componentChanged();
this.projectService.saveProject();
});
}

Expand All @@ -60,15 +60,15 @@ export class EditComponentTagsComponent {
this.componentContent.tags = [];
}
this.componentContent.tags.push('');
this.projectService.componentChanged();
this.projectService.saveProject();
}

moveTagUp(index: number): void {
if (index > 0) {
const tag = this.componentContent.tags[index];
this.componentContent.tags.splice(index, 1);
this.componentContent.tags.splice(index - 1, 0, tag);
this.projectService.componentChanged();
this.projectService.saveProject();
}
}

Expand All @@ -77,14 +77,14 @@ export class EditComponentTagsComponent {
const tag = this.componentContent.tags[index];
this.componentContent.tags.splice(index, 1);
this.componentContent.tags.splice(index + 1, 0, tag);
this.projectService.componentChanged();
this.projectService.saveProject();
}
}

deleteTag(indexOfTagToDelete: number): void {
if (confirm($localize`Are you sure you want to delete this tag?`)) {
this.componentContent.tags.splice(indexOfTagToDelete, 1);
this.projectService.componentChanged();
this.projectService.saveProject();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { Component, effect, EventEmitter, Input, Output } from '@angular/core';
import { Component, effect, Input } from '@angular/core';
import { ComponentContent } from '../../common/ComponentContent';
import { PreviewComponentComponent } from './preview-component/preview-component.component';
import { EditComponentComponent } from './edit-component/edit-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, EditComponentComponent, MatTooltipModule],
imports: [PreviewComponentComponent, EditComponentDialogComponent, MatTooltipModule],
selector: 'component-authoring',
styles: [
`
Expand All @@ -33,41 +35,48 @@ import { copy } from '../../common/object/object';
}
`
],
template: `@if (editing) {
<edit-component [componentContent]="componentContent" [nodeId]="nodeId" />
} @else {
<preview-component
role="button"
tabindex="0"
(click)="editComponentEvent.emit()"
(keyup.enter)="editComponentEvent.emit()"
[component]="component"
[disabled]="true"
matTooltip="Edit content"
i18n-matTooltip
/>
}`
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() editing: boolean;
@Output() editComponentEvent: EventEmitter<void> = new EventEmitter<void>();
@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.
Expand All @@ -81,4 +90,15 @@ export class ComponentAuthoringComponent {
this.nodeId
);
}

protected editComponent(): void {
this.dialog.open(EditComponentDialogComponent, {
data: {
componentContent: this.componentContent,
nodeId: this.nodeId
},
height: '90vh',
panelClass: 'dialog-xl'
});
}
}
Loading
Loading