diff --git a/package-lock.json b/package-lock.json index a7340ddffc..8dbac616db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "wise", - "version": "5.16.2", + "version": "5.16.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 284901bc71..ad90e9250b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wise", - "version": "5.16.2", + "version": "5.16.3", "description": "Web-based Inquiry Science Environment", "main": "app.js", "browserslist": [ diff --git a/pom.xml b/pom.xml index 2580a45cc4..cc65aea6b5 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ wise war Web-based Inquiry Science Environment - 5.16.2 + 5.16.3 http://wise5.org diff --git a/src/main/resources/version.txt b/src/main/resources/version.txt index 9aa54ea304..01419b8122 100644 --- a/src/main/resources/version.txt +++ b/src/main/resources/version.txt @@ -1 +1 @@ -5.16.2 +5.16.3 diff --git a/src/main/webapp/site/src/app/services/data.service.spec.ts b/src/main/webapp/site/src/app/services/data.service.spec.ts index 38e8d9ec63..6281663081 100644 --- a/src/main/webapp/site/src/app/services/data.service.spec.ts +++ b/src/main/webapp/site/src/app/services/data.service.spec.ts @@ -1,16 +1,46 @@ +import { HttpClientTestingModule } from '@angular/common/http/testing'; import { TestBed } from '@angular/core/testing'; +import { UpgradeModule } from '@angular/upgrade/static'; +import { ConfigService } from '../../../../wise5/services/configService'; +import { ProjectService } from '../../../../wise5/services/projectService'; +import { SessionService } from '../../../../wise5/services/sessionService'; +import { UtilService } from '../../../../wise5/services/utilService'; import { DataService } from './data.service'; +let service: DataService; +let projectService: ProjectService; + describe('DataService', () => { - let service: DataService; beforeEach(() => { - TestBed.configureTestingModule({}); + TestBed.configureTestingModule({ + imports: [ HttpClientTestingModule, UpgradeModule ], + providers: [ ConfigService, ProjectService, SessionService, UtilService ] + }); service = TestBed.inject(DataService); + projectService = TestBed.inject(ProjectService); }); - it('should be created', () => { - expect(service).toBeTruthy(); - }); + setCurrentNode(); }); + +function setCurrentNode() { + it('should set the new current node when there is no current node', () => { + const node = { id: 'node1' }; + expect(service.currentNode).toEqual(null); + service.setCurrentNode(node); + expect(service.currentNode).toEqual(node); + }); + it('should set the new current node when there is a current node', () => { + const node1 = { id: 'node1' }; + const node2 = { id: 'node2' }; + service.setCurrentNode(node1); + expect(service.currentNode).toEqual(node1); + spyOn(projectService, 'isGroupNode').and.callFake(() => { return false }); + spyOn(service, 'broadcastCurrentNodeChanged').and.callFake(() => {}); + service.setCurrentNode(node2); + expect(service.previousStep).toEqual(node1); + expect(service.currentNode).toEqual(node2); + }) +} diff --git a/src/main/webapp/site/src/app/services/data.service.ts b/src/main/webapp/site/src/app/services/data.service.ts index 97949956d9..633383301c 100644 --- a/src/main/webapp/site/src/app/services/data.service.ts +++ b/src/main/webapp/site/src/app/services/data.service.ts @@ -1,4 +1,7 @@ import { Injectable } from '@angular/core'; +import { UpgradeModule } from '@angular/upgrade/static'; +import { Subject } from 'rxjs'; +import { ProjectService } from '../../../../wise5/services/projectService'; @Injectable({ providedIn: 'root' @@ -6,8 +9,13 @@ import { Injectable } from '@angular/core'; export class DataService { currentNode = null; + previousStep = null; + private currentNodeChangedSource: Subject = new Subject(); + public currentNodeChanged$ = this.currentNodeChangedSource.asObservable(); - constructor() { } + constructor( + protected upgrade: UpgradeModule, + protected ProjectService: ProjectService) { } isCompleted(nodeId, componentId) { @@ -43,4 +51,34 @@ export class DataService { saveVLEEvent(nodeId, componentId, componentType, category, event, eventData) { } + + setCurrentNodeByNodeId(nodeId) { + this.setCurrentNode(this.ProjectService.getNodeById(nodeId)); + } + + setCurrentNode(node) { + const previousCurrentNode = this.currentNode; + this.currentNode = node; + if (previousCurrentNode !== node) { + if (previousCurrentNode && !this.ProjectService.isGroupNode(previousCurrentNode.id)) { + this.previousStep = previousCurrentNode; + } + this.broadcastCurrentNodeChanged({ + previousNode: previousCurrentNode, + currentNode: this.currentNode + }); + } + } + + broadcastCurrentNodeChanged(previousAndCurrentNode: any) { + this.currentNodeChangedSource.next(previousAndCurrentNode); + } + + endCurrentNode() { + if (this.currentNode != null) { + this.upgrade.$injector.get('$rootScope').$broadcast('exitNode', + { nodeToExit: this.currentNode }); + } + } + } diff --git a/src/main/webapp/wise5/authoringTool/authoringToolController.ts b/src/main/webapp/wise5/authoringTool/authoringToolController.ts index f0f9d3d169..9ca418318e 100644 --- a/src/main/webapp/wise5/authoringTool/authoringToolController.ts +++ b/src/main/webapp/wise5/authoringTool/authoringToolController.ts @@ -252,23 +252,6 @@ class AuthoringToolController { this.setGlobalMessage(this.$translate('notAllowedToEditThisProject'), false, null); }); - this.$scope.$on('openWISELinkChooser', (event, params) => { - const stateParams = { - projectId: params.projectId, - nodeId: params.nodeId, - componentId: params.componentId, - target: params.target - }; - this.$mdDialog.show({ - templateUrl: 'wise5/authoringTool/wiseLink/wiseLinkAuthoring.html', - controller: 'WISELinkAuthoringController', - controllerAs: 'wiseLinkAuthoringController', - $stateParams: stateParams, - clickOutsideToClose: true, - escapeToClose: true - }); - }); - if (this.$state.current.name === 'root.at.main') { this.saveEvent('projectListViewed', 'Navigation'); } diff --git a/src/main/webapp/wise5/authoringTool/wiseLink/wiseLinkAuthoring.html b/src/main/webapp/wise5/authoringTool/wiseLink/wiseLinkAuthoring.html index 922027dbe6..d2b54f8342 100644 --- a/src/main/webapp/wise5/authoringTool/wiseLink/wiseLinkAuthoring.html +++ b/src/main/webapp/wise5/authoringTool/wiseLink/wiseLinkAuthoring.html @@ -51,7 +51,7 @@
{{ ::'createAWISELink' | translate }}

diff --git a/src/main/webapp/wise5/authoringTool/wiseLink/wiseLinkAuthoringController.ts b/src/main/webapp/wise5/authoringTool/wiseLink/wiseLinkAuthoringController.ts index a573c85720..e230023998 100644 --- a/src/main/webapp/wise5/authoringTool/wiseLink/wiseLinkAuthoringController.ts +++ b/src/main/webapp/wise5/authoringTool/wiseLink/wiseLinkAuthoringController.ts @@ -58,9 +58,6 @@ class WISELinkAuthoringController { } /** - * Fire an event to create the WISE Link. Listeners will be the ones that - * actually create the WISE Link. The event that is fired will provide - * the parameters for the WISE Link. * TODO: i18n */ createWISELink() { @@ -80,12 +77,12 @@ class WISELinkAuthoringController { wiseLinkText: this.wiseLinkText, wiseLinkClass: this.wiseLinkClass }; - this.$rootScope.$broadcast('createWISELink', params); + this.$mdDialog.hide(params); } } cancelWISELinkAuthoring() { - this.$mdDialog.hide(); + this.$mdDialog.cancel(); } } diff --git a/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/milestones/milestoneDetails/milestoneDetails.ts b/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/milestones/milestoneDetails/milestoneDetails.ts index 0ab8cb6a9d..fb9f57df61 100644 --- a/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/milestones/milestoneDetails/milestoneDetails.ts +++ b/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/milestones/milestoneDetails/milestoneDetails.ts @@ -13,6 +13,7 @@ class MilestoneDetailsController { milestone: any; periodId: number; requirements: any; + currentPeriodChangedSubscription: any; static $inject = [ '$filter', @@ -24,7 +25,7 @@ class MilestoneDetailsController { ]; constructor( $filter, - $scope, + private $scope, private ConfigService: ConfigService, private NodeService: NodeService, private ProjectService: TeacherProjectService, @@ -32,10 +33,22 @@ class MilestoneDetailsController { ) { this.$translate = $filter('translate'); this.periodId = this.TeacherDataService.getCurrentPeriod().periodId; - $scope.$on('currentPeriodChanged', (event, { currentPeriod }) => { + this.currentPeriodChangedSubscription = this.TeacherDataService.currentPeriodChanged$ + .subscribe(({ currentPeriod }) => { this.periodId = currentPeriod.periodId; this.saveMilestoneCurrentPeriodSelectedEvent(currentPeriod); }); + this.$scope.$on('$destroy', () => { + this.ngOnDestroy(); + }); + } + + ngOnDestroy() { + this.unsubscribeAll(); + } + + unsubscribeAll() { + this.currentPeriodChangedSubscription.unsubscribe(); } $onInit() { diff --git a/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/nodeGrading/nodeGradingView/nodeGradingView.ts b/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/nodeGrading/nodeGradingView/nodeGradingView.ts index b1cacca0fa..f22f8d6e90 100644 --- a/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/nodeGrading/nodeGradingView/nodeGradingView.ts +++ b/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/nodeGrading/nodeGradingView/nodeGradingView.ts @@ -37,6 +37,7 @@ class NodeGradingViewController { workgroups: any; workgroupsById: any; workVisibilityById: any; + currentPeriodChangedSubscription: any; static $inject = [ '$filter', @@ -130,7 +131,8 @@ class NodeGradingViewController { } }); - this.$scope.$on('currentPeriodChanged', () => { + this.currentPeriodChangedSubscription = this.TeacherDataService.currentPeriodChanged$ + .subscribe(() => { if (!this.milestone) { this.milestoneReport = this.MilestoneService.getMilestoneReportByNodeId(this.nodeId); } @@ -139,6 +141,18 @@ class NodeGradingViewController { if (!this.isDisplayInMilestone()) { this.saveNodeGradingViewDisplayedEvent(); } + + this.$scope.$on('$destroy', () => { + this.ngOnDestroy(); + }); + } + + ngOnDestroy() { + this.unsubscribeAll(); + } + + unsubscribeAll() { + this.currentPeriodChangedSubscription.unsubscribe(); } saveNodeGradingViewDisplayedEvent() { diff --git a/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/nodeProgress/navItem/navItem.ts b/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/nodeProgress/navItem/navItem.ts index f2bdf6526f..e036a09892 100644 --- a/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/nodeProgress/navItem/navItem.ts +++ b/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/nodeProgress/navItem/navItem.ts @@ -38,6 +38,7 @@ class NavItemController { rubricIconName: string; showPosition: any; workgroupsOnNodeData: any; + currentPeriodChangedSubscription: any; static $inject = [ '$element', @@ -70,7 +71,6 @@ class NavItemController { ) { this.$element = $element; this.$rootScope = $rootScope; - this.$scope = $scope; this.AnnotationService = AnnotationService; this.ConfigService = ConfigService; this.NotificationService = NotificationService; @@ -191,11 +191,24 @@ class NavItemController { this.getAlertNotifications(); }); - this.$rootScope.$on('currentPeriodChanged', (event, args) => { - this.currentPeriod = args.currentPeriod; + this.currentPeriodChangedSubscription = this.TeacherDataService.currentPeriodChanged$ + .subscribe(({ currentPeriod }) => { + this.currentPeriod = currentPeriod; this.setWorkgroupsOnNodeData(); this.getAlertNotifications(); }); + + this.$scope.$on('$destroy', () => { + this.ngOnDestroy(); + }); + } + + ngOnDestroy() { + this.unsubscribeAll(); + } + + unsubscribeAll() { + this.currentPeriodChangedSubscription.unsubscribe(); } zoomToElement() { diff --git a/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/shared/periodSelect/periodSelect.ts b/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/shared/periodSelect/periodSelect.ts index bd51166a60..b59eaa4f10 100644 --- a/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/shared/periodSelect/periodSelect.ts +++ b/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/shared/periodSelect/periodSelect.ts @@ -9,6 +9,7 @@ class PeriodSelectController { currentPeriod: any; periods: any; rootNodeId: string; + currentPeriodChangedSubscription: any; static $inject = [ '$filter', '$scope', @@ -19,7 +20,7 @@ class PeriodSelectController { constructor( $filter: any, - $scope: any, + private $scope: any, private ProjectService: TeacherProjectService, private StudentStatusService: StudentStatusService, private TeacherDataService: TeacherDataService @@ -35,9 +36,21 @@ class PeriodSelectController { this.currentPeriod = null; this.periods = []; this.initializePeriods(); - $scope.$on('currentPeriodChanged', (event, args) => { - this.currentPeriod = args.currentPeriod; + this.currentPeriodChangedSubscription = this.TeacherDataService.currentPeriodChanged$ + .subscribe(({ currentPeriod }) => { + this.currentPeriod = currentPeriod; }); + this.$scope.$on('$destroy', () => { + this.ngOnDestroy(); + }); + } + + ngOnDestroy() { + this.unsubscribeAll(); + } + + unsubscribeAll() { + this.currentPeriodChangedSubscription.unsubscribe(); } initializePeriods() { diff --git a/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/shared/workgroupSelect/workgroupSelect.ts b/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/shared/workgroupSelect/workgroupSelect.ts index e68609fae7..100f1b782b 100644 --- a/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/shared/workgroupSelect/workgroupSelect.ts +++ b/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/shared/workgroupSelect/workgroupSelect.ts @@ -14,28 +14,40 @@ class WorkgroupSelectController { searchTerm: string; selectedItem: any; workgroups: any; + currentPeriodChangedSubscription: any; static $inject = ['$filter', '$scope', 'orderByFilter', 'ConfigService', 'TeacherDataService']; constructor( $filter: any, - $scope: any, + private $scope: any, private orderBy: any, private ConfigService: ConfigService, private TeacherDataService: TeacherDataService ) { this.$translate = $filter('translate'); - $scope.$on('currentWorkgroupChanged', (event, args) => { + this.$scope.$on('currentWorkgroupChanged', (event, args) => { let workgroup = args.currentWorkgroup; if (workgroup != null) { this.setWorkgroups(); } }); - - $scope.$on('currentPeriodChanged', (event, args) => { - this.periodId = args.currentPeriod.periodId; + this.currentPeriodChangedSubscription = this.TeacherDataService.currentPeriodChanged$ + .subscribe(({ currentPeriod }) => { + this.periodId = currentPeriod.periodId; this.setWorkgroups(); }); + this.$scope.$on('$destroy', () => { + this.ngOnDestroy(); + }); + } + + ngOnDestroy() { + this.unsubscribeAll(); + } + + unsubscribeAll() { + this.currentPeriodChangedSubscription.unsubscribe(); } $onInit() { diff --git a/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/studentGrading/studentGradingTools/studentGradingTools.ts b/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/studentGrading/studentGradingTools/studentGradingTools.ts index f4a3f3c08f..f1baf10cad 100644 --- a/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/studentGrading/studentGradingTools/studentGradingTools.ts +++ b/src/main/webapp/wise5/classroomMonitor/classroomMonitorComponents/studentGrading/studentGradingTools/studentGradingTools.ts @@ -16,6 +16,7 @@ class StudentGradingToolsController { selectTeamPlaceholder: string; workgroupId: number; workgroups: any; + currentPeriodChangedSubscription: any; static $inject = [ '$filter', @@ -28,7 +29,7 @@ class StudentGradingToolsController { constructor( $filter: any, - $scope: any, + private $scope: any, private $state: any, private orderBy: any, private ConfigService: ConfigService, @@ -42,10 +43,22 @@ class StudentGradingToolsController { this.icons = { prev: 'chevron_right', next: 'chevron_left' }; } - $scope.$on('currentPeriodChanged', (event, args) => { - this.periodId = args.currentPeriod.periodId; + this.currentPeriodChangedSubscription = this.TeacherDataService.currentPeriodChanged$ + .subscribe(({ currentPeriod }) => { + this.periodId = currentPeriod.periodId; this.filterForPeriod(); }); + this.$scope.$on('$destroy', () => { + this.ngOnDestroy(); + }); + } + + ngOnDestroy() { + this.unsubscribeAll(); + } + + unsubscribeAll() { + this.currentPeriodChangedSubscription.unsubscribe(); } $onInit() { diff --git a/src/main/webapp/wise5/classroomMonitor/milestones/milestonesController.ts b/src/main/webapp/wise5/classroomMonitor/milestones/milestonesController.ts index 6b68cea031..b2404c67d2 100644 --- a/src/main/webapp/wise5/classroomMonitor/milestones/milestonesController.ts +++ b/src/main/webapp/wise5/classroomMonitor/milestones/milestonesController.ts @@ -3,10 +3,12 @@ import * as angular from 'angular'; import { AchievementService } from '../../services/achievementService'; import { MilestoneService } from '../../services/milestoneService'; +import { TeacherDataService } from '../../services/teacherDataService'; class MilestonesController { $translate: any; milestones: any[]; + currentPeriodChangedSubscription: any; static $inject = [ '$filter', '$mdDialog', @@ -14,6 +16,7 @@ class MilestonesController { '$scope', 'AchievementService', 'MilestoneService', + 'TeacherDataService', 'moment' ]; constructor( @@ -23,6 +26,7 @@ class MilestonesController { private $scope: any, private AchievementService: AchievementService, private MilestoneService: MilestoneService, + private TeacherDataService: TeacherDataService, private moment: any ) { this.$translate = this.$filter('translate'); @@ -36,7 +40,8 @@ class MilestonesController { } }); - this.$scope.$on('currentPeriodChanged', () => { + this.currentPeriodChangedSubscription = this.TeacherDataService.currentPeriodChanged$ + .subscribe(() => { for (let milestone of this.milestones) { this.updateMilestoneStatus(milestone.id); } @@ -60,6 +65,18 @@ class MilestonesController { this.$scope.$on('milestoneDeleted', () => { this.loadProjectMilestones(); }); + + this.$scope.$on('$destroy', () => { + this.ngOnDestroy(); + }); + } + + ngOnDestroy() { + this.unsubscribeAll(); + } + + unsubscribeAll() { + this.currentPeriodChangedSubscription.unsubscribe(); } loadProjectMilestones() { diff --git a/src/main/webapp/wise5/classroomMonitor/studentGrading/studentGradingController.ts b/src/main/webapp/wise5/classroomMonitor/studentGrading/studentGradingController.ts index 8436246507..d50baddbdb 100644 --- a/src/main/webapp/wise5/classroomMonitor/studentGrading/studentGradingController.ts +++ b/src/main/webapp/wise5/classroomMonitor/studentGrading/studentGradingController.ts @@ -31,7 +31,8 @@ class StudentGradingController { sort: any; totalScore: number; workgroupId: number; - + currentPeriodChangedSubscription: any; + static $inject = [ '$filter', '$mdMedia', @@ -61,7 +62,7 @@ class StudentGradingController { private StudentStatusService: StudentStatusService, private TeacherDataService: TeacherDataService ) { - $scope.$mdMedia = $mdMedia; + this.$scope.$mdMedia = $mdMedia; this.$translate = $filter('translate'); this.$scope.$on('projectSaved', (event, args) => { @@ -113,8 +114,9 @@ class StudentGradingController { } }); - this.$scope.$on('currentPeriodChanged', (event, args) => { - let periodId = args.currentPeriod.periodId; + this.currentPeriodChangedSubscription = this.TeacherDataService.currentPeriodChanged$ + .subscribe(({ currentPeriod }) => { + let periodId = currentPeriod.periodId; let currentWorkgroup = this.TeacherDataService.getCurrentWorkgroup(); if (!currentWorkgroup) { let workgroups = angular.copy(this.ConfigService.getClassmateUserInfos()); @@ -132,6 +134,7 @@ class StudentGradingController { this.$scope.$on('$destroy', () => { this.TeacherDataService.setCurrentWorkgroup(null); + this.ngOnDestroy(); }); const context = 'ClassroomMonitor', @@ -152,6 +155,14 @@ class StudentGradingController { ); } + ngOnDestroy() { + this.unsubscribeAll(); + } + + unsubscribeAll() { + this.currentPeriodChangedSubscription.unsubscribe(); + } + $onInit() { document.body.scrollTop = document.documentElement.scrollTop = 0; this.sort = this.TeacherDataService.studentGradingSort; diff --git a/src/main/webapp/wise5/components/html/htmlAuthoringController.ts b/src/main/webapp/wise5/components/html/htmlAuthoringController.ts index 6e921a8376..76da427413 100644 --- a/src/main/webapp/wise5/components/html/htmlAuthoringController.ts +++ b/src/main/webapp/wise5/components/html/htmlAuthoringController.ts @@ -91,7 +91,8 @@ class HTMLAuthoringController extends HTMLController { this.nodeId, this.componentId, 'prompt', - this.$translate('INSERT_WISE_LINK') + this.$translate('INSERT_WISE_LINK'), + this.createOpenWISELinkChooserFunction() ), insertAssetButton: this.UtilService.createInsertAssetButton( null, @@ -118,8 +119,72 @@ class HTMLAuthoringController extends HTMLController { ); } - $onInit() { - this.registerWISELinkListener(); + createOpenWISELinkChooserFunction() { + return (params: any) => { + this.openWISELinkChooser(params).then((linkParams: any) => { + this.createWISELink(linkParams) + }); + } + } + + openWISELinkChooser({ projectId, nodeId, componentId, target }) { + const stateParams = { + projectId: projectId, + nodeId: nodeId, + componentId: componentId, + target: target + }; + return this.$mdDialog.show({ + templateUrl: 'wise5/authoringTool/wiseLink/wiseLinkAuthoring.html', + controller: 'WISELinkAuthoringController', + controllerAs: 'wiseLinkAuthoringController', + $stateParams: stateParams, + clickOutsideToClose: true, + escapeToClose: true + }); + } + + createWISELink({ nodeId, componentId, wiseLinkNodeId, wiseLinkComponentId, wiseLinkType, + wiseLinkText, target }) { + if (nodeId === this.nodeId && componentId === this.componentId && target === 'prompt') { + this.injectWISELinkToPrompt( + this.createWISELinkElement(wiseLinkType, wiseLinkNodeId, wiseLinkComponentId, wiseLinkText) + ); + } + } + + injectWISELinkToPrompt(wiseLinkElement) { + const summernoteId = 'summernotePrompt_' + this.nodeId + '_' + this.componentId; + angular.element(document.querySelector(`#${summernoteId}`)).summernote('editor.restoreRange'); + angular.element(document.querySelector(`#${summernoteId}`)).summernote('editor.focus'); + angular + .element(document.querySelector(`#${summernoteId}`)) + .summernote('insertNode', wiseLinkElement); + angular + .element(document.querySelector(`#${summernoteId}`)) + .summernote('insertNode', document.createElement('br')); + } + + /** + * @param type Allowed values are 'link' or 'button'. + */ + createWISELinkElement(type: string, wiseLinkNodeId: string, wiseLinkComponentId: string = '', + wiseLinkText: string) { + let wiseLinkElement: any; + if (type === 'link') { + wiseLinkElement = document.createElement('a'); + } else { + wiseLinkElement = document.createElement('button'); + } + wiseLinkElement.setAttribute('type', type); + wiseLinkElement.setAttribute('wiselink', true); + wiseLinkElement.setAttribute('node-id', wiseLinkNodeId); + if (wiseLinkComponentId != '') { + wiseLinkElement.setAttribute('component-id', wiseLinkComponentId); + } + wiseLinkElement.setAttribute('link-text', wiseLinkText); + wiseLinkElement.innerHTML = wiseLinkText; + return wiseLinkElement; } createOpenAssetChooserFunction() { @@ -148,75 +213,6 @@ class HTMLAuthoringController extends HTMLController { } } - registerWISELinkListener() { - this.$scope.$on( - 'createWISELink', - ( - event, - { - nodeId, - componentId, - wiseLinkNodeId, - wiseLinkComponentId, - wiseLinkType, - wiseLinkText, - target - } - ) => { - if (nodeId === this.nodeId && componentId === this.componentId && target === 'prompt') { - if (wiseLinkType === 'link') { - this.injectWISELinkToPrompt( - this.createWISELinkLinkElement(wiseLinkNodeId, wiseLinkComponentId, wiseLinkText) - ); - } else { - this.injectWISELinkToPrompt( - this.createWISELinkButtonElement(wiseLinkNodeId, wiseLinkComponentId, wiseLinkText) - ); - } - } - this.$mdDialog.hide(); - } - ); - } - - createWISELinkLinkElement(wiseLinkNodeId, wiseLinkComponentId = '', wiseLinkText) { - const wiseLinkElement: any = document.createElement('a'); - wiseLinkElement.innerHTML = wiseLinkText; - wiseLinkElement.setAttribute('wiselink', true); - wiseLinkElement.setAttribute('node-id', wiseLinkNodeId); - if (wiseLinkComponentId != '') { - wiseLinkElement.setAttribute('component-id', wiseLinkComponentId); - } - wiseLinkElement.setAttribute('type', 'link'); - wiseLinkElement.setAttribute('link-text', wiseLinkText); - return wiseLinkElement; - } - - createWISELinkButtonElement(wiseLinkNodeId, wiseLinkComponentId = '', wiseLinkText) { - const wiseLinkElement: any = document.createElement('button'); - wiseLinkElement.innerHTML = wiseLinkText; - wiseLinkElement.setAttribute('wiselink', true); - wiseLinkElement.setAttribute('node-id', wiseLinkNodeId); - if (wiseLinkComponentId != '') { - wiseLinkElement.setAttribute('component-id', wiseLinkComponentId); - } - wiseLinkElement.setAttribute('type', 'button'); - wiseLinkElement.setAttribute('link-text', wiseLinkText); - return wiseLinkElement; - } - - injectWISELinkToPrompt(wiseLinkElement) { - const summernoteId = 'summernotePrompt_' + this.nodeId + '_' + this.componentId; - angular.element(document.querySelector(`#${summernoteId}`)).summernote('editor.restoreRange'); - angular.element(document.querySelector(`#${summernoteId}`)).summernote('editor.focus'); - angular - .element(document.querySelector(`#${summernoteId}`)) - .summernote('insertNode', wiseLinkElement); - angular - .element(document.querySelector(`#${summernoteId}`)) - .summernote('insertNode', document.createElement('br')); - } - summernotePromptHTMLChanged() { this.authoringComponentContent.html = this.UtilService.insertWISELinks( this.ConfigService.removeAbsoluteAssetPaths(this.summernotePromptHTML) diff --git a/src/main/webapp/wise5/directives/wiselink/wiselink.js b/src/main/webapp/wise5/directives/wiselink/wiselink.js index 4c1a915429..3b1e7c1399 100644 --- a/src/main/webapp/wise5/directives/wiselink/wiselink.js +++ b/src/main/webapp/wise5/directives/wiselink/wiselink.js @@ -18,7 +18,9 @@ class WiselinkController { } unsubscribeAll() { - this.currentNodeChangedSubscription.unsubscribe(); + if (this.currentNodeChangedSubscription != null) { + this.currentNodeChangedSubscription.unsubscribe(); + } } $onInit() { diff --git a/src/main/webapp/wise5/services/studentDataService.ts b/src/main/webapp/wise5/services/studentDataService.ts index f2d0d20438..f903516525 100644 --- a/src/main/webapp/wise5/services/studentDataService.ts +++ b/src/main/webapp/wise5/services/studentDataService.ts @@ -88,17 +88,16 @@ export class StudentDataService extends DataService { public pauseScreen$ = this.pauseScreenSource.asObservable(); private componentStudentDataSource: Subject = new Subject(); public componentStudentData$ = this.componentStudentDataSource.asObservable(); - private currentNodeChangedSource: Subject = new Subject(); - public currentNodeChanged$ = this.currentNodeChangedSource.asObservable(); - constructor(private upgrade: UpgradeModule, + constructor( + upgrade: UpgradeModule, public http: HttpClient, private AnnotationService: AnnotationService, private ConfigService: ConfigService, - private ProjectService: ProjectService, + ProjectService: ProjectService, private TagService: TagService, private UtilService: UtilService) { - super(); + super(upgrade, ProjectService); } pauseScreen(doPause: boolean) { @@ -1345,36 +1344,6 @@ export class StudentDataService extends DataService { return result; } - setCurrentNodeByNodeId(nodeId) { - const node = this.ProjectService.getNodeById(nodeId); - this.setCurrentNode(node); - } - - setCurrentNode(node) { - const previousCurrentNode = this.currentNode; - if (previousCurrentNode !== node) { - if (previousCurrentNode && !this.ProjectService.isGroupNode(previousCurrentNode.id)) { - this.previousStep = previousCurrentNode; - } - this.currentNode = node; - this.broadcastCurrentNodeChanged({ - previousNode: previousCurrentNode, - currentNode: this.currentNode - }); - } - } - - broadcastCurrentNodeChanged(previousAndCurrentNode: any) { - this.currentNodeChangedSource.next(previousAndCurrentNode); - } - - endCurrentNode() { - const previousCurrentNode = this.currentNode; - if (previousCurrentNode != null) { - this.upgrade.$injector.get('$rootScope').$broadcast('exitNode', { nodeToExit: previousCurrentNode }); - } - } - endCurrentNodeAndSetCurrentNodeByNodeId(nodeId) { if (this.nodeStatuses[nodeId].isVisitable) { this.endCurrentNode(); diff --git a/src/main/webapp/wise5/services/teacherDataService.ts b/src/main/webapp/wise5/services/teacherDataService.ts index 800f65fa47..31ce8c5bdf 100644 --- a/src/main/webapp/wise5/services/teacherDataService.ts +++ b/src/main/webapp/wise5/services/teacherDataService.ts @@ -25,19 +25,19 @@ export class TeacherDataService extends DataService { nodeGradingSort = 'team'; studentGradingSort = 'step'; studentProgressSort = 'team'; - private currentNodeChangedSource: Subject = new Subject(); - public currentNodeChanged$ = this.currentNodeChangedSource.asObservable(); + private currentPeriodChangedSource: Subject = new Subject(); + public currentPeriodChanged$ = this.currentPeriodChangedSource.asObservable(); constructor( - private upgrade: UpgradeModule, + upgrade: UpgradeModule, private http: HttpClient, private AnnotationService: AnnotationService, private ConfigService: ConfigService, - private ProjectService: TeacherProjectService, + ProjectService: TeacherProjectService, private TeacherWebSocketService: TeacherWebSocketService, private UtilService: UtilService ) { - super(); + super(upgrade, ProjectService); this.studentData = { componentStatesByWorkgroupId: {}, componentStatesByNodeId: {}, @@ -303,7 +303,8 @@ export class TeacherDataService extends DataService { } getAllRelatedComponents(nodeId) { - const components = this.ProjectService.getNodeIdsAndComponentIds(nodeId); + const components = (this.ProjectService) + .getNodeIdsAndComponentIds(nodeId); return components.concat(this.getConnectedComponentsIfNecessary(components)); } @@ -827,13 +828,17 @@ export class TeacherDataService extends DataService { this.currentPeriod = period; this.clearCurrentWorkgroupIfNecessary(this.currentPeriod.periodId); if (previousPeriod == null || previousPeriod.periodId != this.currentPeriod.periodId) { - this.getRootScope().$broadcast('currentPeriodChanged', { + this.broadcastCurrentPeriodChanged({ previousPeriod: previousPeriod, currentPeriod: this.currentPeriod }); } } + broadcastCurrentPeriodChanged(previousAndCurrentPeriod: any) { + this.currentPeriodChangedSource.next(previousAndCurrentPeriod); + } + clearCurrentWorkgroupIfNecessary(periodId) { const currentWorkgroup = this.getCurrentWorkgroup(); if (currentWorkgroup) { @@ -874,37 +879,6 @@ export class TeacherDataService extends DataService { return this.currentStep; } - setCurrentNodeByNodeId(nodeId) { - if (nodeId != null) { - this.setCurrentNode(this.ProjectService.getNodeById(nodeId)); - } - } - - setCurrentNode(node) { - const previousCurrentNode = this.currentNode; - if (previousCurrentNode !== node) { - if (previousCurrentNode && !this.ProjectService.isGroupNode(previousCurrentNode.id)) { - this.previousStep = previousCurrentNode; - } - this.currentNode = node; - this.broadcastCurrentNodeChanged({ - previousNode: previousCurrentNode, - currentNode: this.currentNode - }); - } - } - - broadcastCurrentNodeChanged(previousAndCurrentNode: any) { - this.currentNodeChangedSource.next(previousAndCurrentNode); - } - - endCurrentNode() { - const previousCurrentNode = this.currentNode; - if (previousCurrentNode != null) { - this.getRootScope().$broadcast('exitNode', { nodeToExit: previousCurrentNode }); - } - } - /** * @param nodeId the node id of the new current node */ diff --git a/src/main/webapp/wise5/services/utilService.ts b/src/main/webapp/wise5/services/utilService.ts index fbe31c3e04..b0e33f459a 100644 --- a/src/main/webapp/wise5/services/utilService.ts +++ b/src/main/webapp/wise5/services/utilService.ts @@ -343,8 +343,8 @@ export class UtilService { * @param tooltip the tooltip text for the custom button * @return custom summernote button */ - createInsertWISELinkButton(projectId, nodeId, componentId, target, tooltip) { - const thisRootScope = this.upgrade.$injector.get('$rootScope'); + createInsertWISELinkButton(projectId, nodeId, componentId, target, tooltip, + openWISELinkChooserFunction) { const InsertWISELinkButton = function(context) { const ui = ($ as any).summernote.ui; const button = ui.button({ @@ -363,7 +363,7 @@ export class UtilService { params.componentId = componentId; } params.target = target; - thisRootScope.$broadcast('openWISELinkChooser', params); + openWISELinkChooserFunction(params); } }); return button.render(); // return button as jquery object