-
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(Teacher): Implement apply tags button (#1687)
- Loading branch information
1 parent
5bfd1fb
commit 65c80ee
Showing
13 changed files
with
210 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export interface Tag { | ||
checked?: boolean; | ||
id: number; | ||
text: string; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/app/teacher/apply-tags-button/apply-tags-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,23 @@ | ||
<button | ||
mat-icon-button | ||
[matMenuTriggerFor]="applyTagsMenu" | ||
matTooltip="Apply tags" | ||
matTooltipPosition="above" | ||
i18n-matTooltip | ||
> | ||
<mat-icon>sell</mat-icon> | ||
</button> | ||
<mat-menu #applyTagsMenu> | ||
<div class="menu-info secondary-text" i18n>Apply tags</div> | ||
<mat-divider></mat-divider> | ||
<div *ngFor="let tag of tags" mat-menu-item> | ||
<mat-checkbox | ||
color="primary" | ||
[checked]="tag.checked" | ||
(change)="toggleTagOnProjects(tag, $event.checked)" | ||
(click)="$event.stopPropagation()" | ||
> | ||
{{ tag.text }} | ||
</mat-checkbox> | ||
</div> | ||
</mat-menu> |
3 changes: 3 additions & 0 deletions
3
src/app/teacher/apply-tags-button/apply-tags-button.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.menu-info { | ||
margin: 0 16px; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/app/teacher/apply-tags-button/apply-tags-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,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { ApplyTagsButtonComponent } from './apply-tags-button.component'; | ||
import { ApplyTagsButtonModule } from './apply-tags-button.module'; | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
|
||
describe('ApplyTagsButtonComponent', () => { | ||
let component: ApplyTagsButtonComponent; | ||
let fixture: ComponentFixture<ApplyTagsButtonComponent>; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ApplyTagsButtonComponent], | ||
imports: [ApplyTagsButtonModule, HttpClientTestingModule] | ||
}); | ||
fixture = TestBed.createComponent(ApplyTagsButtonComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
58 changes: 58 additions & 0 deletions
58
src/app/teacher/apply-tags-button/apply-tags-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,58 @@ | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
import { Project } from '../../domain/project'; | ||
import { TagService } from '../../../assets/wise5/services/tagService'; | ||
import { Tag } from '../../domain/tag'; | ||
|
||
@Component({ | ||
selector: 'apply-tags-button', | ||
templateUrl: './apply-tags-button.component.html', | ||
styleUrls: ['./apply-tags-button.component.scss'] | ||
}) | ||
export class ApplyTagsButtonComponent implements OnInit { | ||
@Input() selectedProjects: Project[] = []; | ||
protected tags: Tag[] = []; | ||
|
||
constructor(private tagService: TagService) {} | ||
|
||
ngOnInit(): void { | ||
this.tagService.retrieveUserTags().subscribe((tags: Tag[]) => { | ||
for (const tag of tags) { | ||
tag.checked = this.doesAnyProjectHaveTag(tag); | ||
} | ||
this.tags = tags; | ||
}); | ||
} | ||
|
||
private doesAnyProjectHaveTag(tag: Tag): boolean { | ||
for (const project of this.selectedProjects) { | ||
if (project.tags.includes(tag.text)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
protected toggleTagOnProjects(tag: Tag, addTag: boolean): void { | ||
if (addTag) { | ||
this.addTagToProjects(tag, this.selectedProjects); | ||
this.tagService.applyTagToProjects(tag, this.selectedProjects); | ||
} else { | ||
this.removeTagFromProjects(tag, this.selectedProjects); | ||
this.tagService.removeTagFromProjects(tag, this.selectedProjects); | ||
} | ||
} | ||
|
||
private addTagToProjects(tag: Tag, projects: Project[]): void { | ||
for (const project of projects) { | ||
project.tags.push(tag.text); | ||
project.tags.sort(); | ||
} | ||
} | ||
|
||
private removeTagFromProjects(tag: Tag, projects: Project[]): void { | ||
for (const project of projects) { | ||
project.tags = project.tags.filter((projectTag: string) => projectTag !== tag.text); | ||
project.tags.sort(); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/app/teacher/apply-tags-button/apply-tags-button.module.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 { NgModule } from '@angular/core'; | ||
import { ApplyTagsButtonComponent } from './apply-tags-button.component'; | ||
import { MatButtonModule } from '@angular/material/button'; | ||
import { MatIconModule } from '@angular/material/icon'; | ||
import { MatTooltipModule } from '@angular/material/tooltip'; | ||
import { MatMenuModule } from '@angular/material/menu'; | ||
import { MatCheckboxModule } from '@angular/material/checkbox'; | ||
import { TagService } from '../../../assets/wise5/services/tagService'; | ||
import { StudentTeacherCommonServicesModule } from '../../student-teacher-common-services.module'; | ||
import { CommonModule } from '@angular/common'; | ||
import { FlexLayoutModule } from '@angular/flex-layout'; | ||
import { FormsModule } from '@angular/forms'; | ||
import { MatDividerModule } from '@angular/material/divider'; | ||
|
||
@NgModule({ | ||
declarations: [ApplyTagsButtonComponent], | ||
exports: [ApplyTagsButtonComponent], | ||
imports: [ | ||
CommonModule, | ||
FlexLayoutModule, | ||
FormsModule, | ||
MatButtonModule, | ||
MatCheckboxModule, | ||
MatDividerModule, | ||
MatIconModule, | ||
MatMenuModule, | ||
MatTooltipModule, | ||
StudentTeacherCommonServicesModule | ||
], | ||
providers: [TagService] | ||
}) | ||
export class ApplyTagsButtonModule {} |
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
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
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