Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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,19 +5,20 @@ 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 { MatDialogModule } from '@angular/material/dialog';
import { MatDivider } from '@angular/material/divider';
import { Component as WISEComponent } from '../../../assets/wise5/common/Component';
import { components } from '../../../assets/wise5/components/Components';

@Component({
encapsulation: ViewEncapsulation.None,
imports: [MatDivider, MatDialogModule, MatButtonModule],
selector: 'edit-component-advanced',
styles: [
`
.edit-component-advanced {
Expand All @@ -39,29 +40,25 @@ import { components } from '../../../assets/wise5/components/Components';
}
`
],
templateUrl: './edit-component-advanced.component.html'
template: '<div #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
Expand Up @@ -17,6 +17,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,14 @@ export class ComponentAuthoringComponent {
this.nodeId
);
}

protected editComponent(): void {
this.dialog.open(EditComponentDialogComponent, {
data: {
componentContent: this.componentContent,
nodeId: this.nodeId
},
panelClass: 'dialog-xl'
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Component, inject, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
import { EditComponentComponent } from '../edit-component/edit-component.component';
import { MatButtonModule } from '@angular/material/button';
import { MatDividerModule } from '@angular/material/divider';
import { ComponentTypeService } from '../../../services/componentTypeService';
import { MatSlideToggle } from '@angular/material/slide-toggle';
import { FormsModule } from '@angular/forms';
import { Component as WISEComponent } from '../../../common/Component';
import { EditComponentAdvancedComponent } from '../../../../../app/authoring-tool/edit-component-advanced/edit-component-advanced.component';

@Component({
imports: [
EditComponentComponent,
EditComponentAdvancedComponent,
FormsModule,
MatButtonModule,
MatDialogModule,
MatDividerModule,
MatSlideToggle
],
template: `
<div class="flex flex-row items-center">
<h2 mat-dialog-title i18n>Edit Activity ({{ componentTypeLabel }})</h2>
<mat-slide-toggle [(ngModel)]="advancedMode" i18n>Advanced mode</mat-slide-toggle>
</div>
<mat-divider />
<div mat-dialog-content>
@if (advancedMode) {
<edit-component-advanced [component]="component" />
} @else {
<edit-component [componentContent]="data.componentContent" [nodeId]="data.nodeId" />
}
</div>
<mat-divider />
<mat-dialog-actions align="end">
<button class="enable-in-translation" mat-button mat-dialog-close cdkFocusRegionstart i18n>
Close
</button>
</mat-dialog-actions>
`
})
export class EditComponentDialogComponent {
protected advancedMode = false;
protected component: WISEComponent;
protected componentTypeLabel: string;

constructor(
private componentTypeService: ComponentTypeService,
@Inject(MAT_DIALOG_DATA) public data: any
) {
this.component = new WISEComponent(this.data.componentContent, this.data.nodeId);
this.componentTypeLabel = this.componentTypeService.getComponentTypeLabel(
this.data.componentContent.type
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,8 @@
@for (component of components; track component.id; let i = $index; let last = $last) {
<div cdkDrag [cdkDragDisabled]="components.length < 2">
<div class="flex flex-row">
<mat-card
[id]="component.id"
class="component w-full"
[ngClass]="{ 'component-editing': component.id === editingComponentId }"
>
<div
class="component-header flex flex-row justify-start items-center"
[ngClass]="{ 'selected-bg-bg': component.id === editingComponentId }"
>
<mat-card [id]="component.id" class="component w-full">
<div class="component-header flex flex-row justify-start items-center">
<div class="flex flex-row justify-start items-center gap-2">
@if (components.length > 1) {
<mat-icon class="drag-handle" cdkDragHandle title="Drag to reorder" i18n-title
Expand All @@ -44,9 +37,6 @@
}
<span class="flex grow"></span>
<div class="text flex justify-end items-center">
@if (component.id === editingComponentId) {
<edit-component-advanced-button [componentContent]="component" [nodeId]="nodeId" />
}
<copy-component-button
[node]="node"
[componentId]="component.id"
Expand All @@ -66,12 +56,7 @@
</div>
<mat-divider />
<div>
<component-authoring
[nodeId]="nodeId"
[componentContent]="component"
[editing]="component.id === editingComponentId"
(editComponentEvent)="editComponent(component.id)"
/>
<component-authoring [nodeId]="nodeId" [componentContent]="component" />
</div>
</mat-card>
<div class="flex flex-col">
Expand Down
Loading
Loading