-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Authoring): Implement add button next to lessons and steps (#1675)
- Loading branch information
1 parent
5b5a951
commit 67dd348
Showing
17 changed files
with
576 additions
and
30 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
20 changes: 20 additions & 0 deletions
20
src/assets/wise5/authoringTool/add-lesson-button/add-lesson-button.component.html
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<button | ||
mat-icon-button | ||
color="primary" | ||
(click)="addLesson()" | ||
[matMenuTriggerFor]="lessonId == null ? null : lessonMenu" | ||
#menuTrigger | ||
matTooltip="Add lesson" | ||
matTooltipPosition="above" | ||
i18n-matTooltip | ||
> | ||
<mat-icon>add_circle</mat-icon> | ||
</button> | ||
<mat-menu #lessonMenu="matMenu"> | ||
<button mat-menu-item (click)="addLessonBefore()"> | ||
<mat-icon>add_circle</mat-icon><span i18n>Add Lesson Before</span> | ||
</button> | ||
<button mat-menu-item (click)="addLessonAfter()"> | ||
<mat-icon>add_circle</mat-icon><span i18n>Add Lesson After</span> | ||
</button> | ||
</mat-menu> |
Empty file.
32 changes: 32 additions & 0 deletions
32
src/assets/wise5/authoringTool/add-lesson-button/add-lesson-button.component.spec.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { AddLessonButtonComponent } from './add-lesson-button.component'; | ||
import { TeacherProjectService } from '../../services/teacherProjectService'; | ||
import { StudentTeacherCommonServicesModule } from '../../../../app/student-teacher-common-services.module'; | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { MatMenuModule } from '@angular/material/menu'; | ||
import { MatIconModule } from '@angular/material/icon'; | ||
|
||
describe('AddLessonButtonComponent', () => { | ||
let component: AddLessonButtonComponent; | ||
let fixture: ComponentFixture<AddLessonButtonComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [AddLessonButtonComponent], | ||
imports: [ | ||
HttpClientTestingModule, | ||
StudentTeacherCommonServicesModule, | ||
MatIconModule, | ||
MatMenuModule | ||
], | ||
providers: [TeacherProjectService] | ||
}); | ||
fixture = TestBed.createComponent(AddLessonButtonComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
src/assets/wise5/authoringTool/add-lesson-button/add-lesson-button.component.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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Component, Input, ViewChild } from '@angular/core'; | ||
import { TeacherProjectService } from '../../services/teacherProjectService'; | ||
import { temporarilyHighlightElement } from '../../common/dom/dom'; | ||
import { MatMenuTrigger } from '@angular/material/menu'; | ||
|
||
@Component({ | ||
selector: 'add-lesson-button', | ||
templateUrl: './add-lesson-button.component.html', | ||
styleUrls: ['./add-lesson-button.component.scss'] | ||
}) | ||
export class AddLessonButtonComponent { | ||
@Input() active: boolean; | ||
@Input() lessonId: string; | ||
@ViewChild(MatMenuTrigger) menuTrigger: MatMenuTrigger; | ||
|
||
constructor(private projectService: TeacherProjectService) {} | ||
|
||
protected addLesson(): void { | ||
if (this.lessonId == null) { | ||
this.addFirstLesson(); | ||
} else { | ||
this.menuTrigger.openMenu(); | ||
} | ||
} | ||
|
||
protected addLessonBefore(): void { | ||
const previousLessonId = this.projectService.getPreviousNodeId(this.lessonId); | ||
if (previousLessonId == null) { | ||
this.addFirstLesson(); | ||
} else { | ||
const newLesson = this.createNewLesson(); | ||
this.projectService.createNodeAfter(newLesson, previousLessonId); | ||
this.updateProject(newLesson.id); | ||
} | ||
} | ||
|
||
private addFirstLesson(): void { | ||
const newLesson = this.createNewLesson(); | ||
const insertLocation = this.active ? 'group0' : 'inactiveGroups'; | ||
this.projectService.createNodeInside(newLesson, insertLocation); | ||
this.updateProject(newLesson.id); | ||
} | ||
|
||
protected addLessonAfter(): void { | ||
const newLesson = this.createNewLesson(); | ||
this.projectService.createNodeAfter(newLesson, this.lessonId); | ||
this.updateProject(newLesson.id); | ||
} | ||
|
||
private createNewLesson(): any { | ||
return this.projectService.createGroup($localize`New Lesson`); | ||
} | ||
|
||
private updateProject(newNodeId: string): void { | ||
this.projectService.checkPotentialStartNodeIdChangeThenSaveProject().then(() => { | ||
this.projectService.refreshProject(); | ||
// This timeout is used to allow the lesson to be added to the DOM before we highlight it | ||
setTimeout(() => { | ||
temporarilyHighlightElement(newNodeId); | ||
}); | ||
}); | ||
} | ||
} |
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
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
2 changes: 1 addition & 1 deletion
2
src/assets/wise5/authoringTool/project-authoring-step/project-authoring-step.component.scss
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
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 |
---|---|---|
|
@@ -36,3 +36,7 @@ | |
.mat-icon { | ||
margin: 0px; | ||
} | ||
|
||
.add-lesson-button-next-to-lesson { | ||
margin-top: 20px; | ||
} |
Oops, something went wrong.