Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace openAssetChooser and assetSelected events #2615

Merged
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
11 changes: 11 additions & 0 deletions src/main/webapp/site/src/app/services/projectAssetService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,4 +215,15 @@ export class ProjectAssetService {
isProjectAssetsAvailable() {
return this.getProjectAssets().getValue() != null;
}

openAssetChooser(params: any) {
return this.upgrade.$injector.get('$mdDialog').show({
templateUrl: 'wise5/authoringTool/asset/asset.html',
controller: 'ProjectAssetController',
controllerAs: 'projectAssetController',
$stateParams: params,
clickOutsideToClose: true,
escapeToClose: true
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ConfigService } from '../../services/configService';
import { TeacherProjectService } from '../../services/teacherProjectService';
import { UtilService } from '../../services/utilService';
import * as angular from 'angular';
import { ProjectAssetService } from '../../../site/src/app/services/projectAssetService';

class AdvancedAuthoringController {
$translate: any;
Expand All @@ -17,6 +18,7 @@ class AdvancedAuthoringController {
'$state',
'$stateParams',
'ConfigService',
'ProjectAssetService',
'ProjectService',
'UtilService'
];
Expand All @@ -28,6 +30,7 @@ class AdvancedAuthoringController {
private $state,
$stateParams: any,
private ConfigService: ConfigService,
private ProjectAssetService: ProjectAssetService,
private ProjectService: TeacherProjectService,
private UtilService: UtilService
) {
Expand All @@ -36,19 +39,14 @@ class AdvancedAuthoringController {
this.$state = $state;
this.$translate = $filter('translate');
this.ConfigService = ConfigService;
this.ProjectAssetService = ProjectAssetService;
this.ProjectService = ProjectService;
this.UtilService = UtilService;
this.projectId = $stateParams.projectId;
}

$onInit() {
this.setProjectScriptFilename();
this.$scope.$on('assetSelected', (event, { assetItem, target }) => {
if (target === 'scriptFilename') {
this.projectScriptFilename = assetItem.fileName;
this.projectScriptFilenameChanged();
}
});
}

showJSONClicked() {
Expand Down Expand Up @@ -96,12 +94,21 @@ class AdvancedAuthoringController {
}

chooseProjectScriptFile() {
const openAssetChooserParams = {
const params = {
isPopup: true,
projectId: this.projectId,
target: 'scriptFilename'
};
this.$rootScope.$broadcast('openAssetChooser', openAssetChooserParams);
this.ProjectAssetService.openAssetChooser(params).then(
(data: any) => { this.assetSelected(data) }
);
}

assetSelected({ assetItem, target }) {
if (target === 'scriptFilename') {
this.projectScriptFilename = assetItem.fileName;
this.projectScriptFilenameChanged();
}
}

downloadProject() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class ProjectAssetController {
target: this.target,
targetObject: this.targetObject
};
this.$rootScope.$broadcast('assetSelected', params);
this.$mdDialog.hide(params);
}

/**
Expand Down
19 changes: 0 additions & 19 deletions src/main/webapp/wise5/authoringTool/authoringToolController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,25 +252,6 @@ class AuthoringToolController {
this.setGlobalMessage(this.$translate('notAllowedToEditThisProject'), false, null);
});

this.$scope.$on('openAssetChooser', (event, params) => {
const stateParams = {
isPopup: params.isPopup,
projectId: params.projectId,
nodeId: params.nodeId,
componentId: params.componentId,
target: params.target,
targetObject: params.targetObject
};
this.$mdDialog.show({
templateUrl: 'wise5/authoringTool/asset/asset.html',
controller: 'ProjectAssetController',
controllerAs: 'projectAssetController',
$stateParams: stateParams,
clickOutsideToClose: true,
escapeToClose: true
});
});

this.$scope.$on('openWISELinkChooser', (event, params) => {
const stateParams = {
projectId: params.projectId,
Expand Down
24 changes: 13 additions & 11 deletions src/main/webapp/wise5/authoringTool/info/projectInfoController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

import { ProjectAssetService } from '../../../site/src/app/services/projectAssetService';
import { ConfigService } from '../../services/configService';
import { TeacherProjectService } from '../../services/teacherProjectService';

Expand All @@ -21,6 +22,7 @@ class ProjectInfoController {
'$scope',
'$timeout',
'ConfigService',
'ProjectAssetService',
'ProjectService'
];

Expand All @@ -31,6 +33,7 @@ class ProjectInfoController {
private $scope: any,
private $timeout: any,
private ConfigService: ConfigService,
private ProjectAssetService: ProjectAssetService,
private ProjectService: TeacherProjectService
) {
this.$translate = $filter('translate');
Expand All @@ -40,16 +43,6 @@ class ProjectInfoController {
);
this.loadProjectIcon();
this.processMetadata();
this.registerListeners();
}

registerListeners() {
this.$scope.$on('assetSelected', (event, args) => {
if (args.target === 'projectIcon') {
this.setCustomProjectIcon(args.assetItem.fileName);
this.$mdDialog.hide();
}
});
}

processMetadata() {
Expand Down Expand Up @@ -155,7 +148,16 @@ class ProjectInfoController {
isPopup: true,
target: 'projectIcon'
};
this.$rootScope.$broadcast('openAssetChooser', params);
this.ProjectAssetService.openAssetChooser(params).then(
(data: any) => { this.assetSelected(data) }
);
}

assetSelected(args) {
if (args.target === 'projectIcon') {
this.setCustomProjectIcon(args.assetItem.fileName);
this.$mdDialog.hide();
}
}

setCustomProjectIcon(projectIcon) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ProjectAssetService } from "../../../../site/src/app/services/projectAssetService";
import { ConfigService } from "../../../services/configService";
import { ProjectService } from "../../../services/projectService";
import { TeacherDataService } from "../../../services/teacherDataService";
Expand All @@ -11,13 +12,13 @@ class EditRubricComponentController {
summernoteRubricId: string;
summernoteRubricOptions: any;

static $inject = ['$filter', '$mdDialog', '$scope', '$state', 'ConfigService', 'ProjectService',
'TeacherDataService', 'UtilService'];
static $inject = ['$filter', '$mdDialog', '$scope', '$state', 'ConfigService',
'ProjectAssetService', 'ProjectService', 'TeacherDataService', 'UtilService'];

constructor(private $filter: any, private $mdDialog: any, private $scope: any,
private $state: any, private ConfigService: ConfigService,
private ProjectService: ProjectService, private TeacherDataService: TeacherDataService,
private UtilService: UtilService) {
private ProjectAssetService: ProjectAssetService, private ProjectService: ProjectService,
private TeacherDataService: TeacherDataService, private UtilService: UtilService) {
}

$onInit() {
Expand All @@ -41,21 +42,30 @@ class EditRubricComponentController {
disableDragAndDrop: true,
buttons: {
insertAssetButton: this.UtilService.createInsertAssetButton(null, this.nodeId, null,
'rubric', this.$filter('translate')('INSERT_ASSET'))
'rubric', this.$filter('translate')('INSERT_ASSET'),
this.createOpenAssetChooserFunction())
},
dialogsInBody: true
};
this.summernoteRubricHTML = this.ProjectService.replaceAssetPaths(this.node.rubric);
this.$scope.$on('assetSelected', (event, { assetItem, target }) => {
if (target === 'rubric') {
this.UtilService.insertFileInSummernoteEditor(
`summernoteRubric_${this.nodeId}`,
`${this.ConfigService.getProjectAssetsDirectoryPath()}/${assetItem.fileName}`,
assetItem.fileName
);
}
this.$mdDialog.hide();
});
}

createOpenAssetChooserFunction() {
return (params: any) => {
this.ProjectAssetService.openAssetChooser(params).then(
(data: any) => { this.assetSelected(data) }
);
}
}

assetSelected({ assetItem, target }) {
if (target === 'rubric') {
this.UtilService.insertFileInSummernoteEditor(
`summernoteRubric_${this.nodeId}`,
`${this.ConfigService.getProjectAssetsDirectoryPath()}/${assetItem.fileName}`,
assetItem.fileName
);
}
}

summernoteRubricHTMLChanged() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

import { ProjectAssetService } from '../../../site/src/app/services/projectAssetService';
import { ConfigService } from '../../services/configService';
import { SpaceService } from '../../services/spaceService';
import { TeacherProjectService } from '../../services/teacherProjectService';
Expand All @@ -18,6 +19,7 @@ class AuthorNotebookController {
'$stateParams',
'$scope',
'ConfigService',
'ProjectAssetService',
'ProjectService',
'SpaceService',
'UtilService'
Expand All @@ -29,6 +31,7 @@ class AuthorNotebookController {
$stateParams,
private $scope,
private ConfigService: ConfigService,
private ProjectAssetService: ProjectAssetService,
private ProjectService: TeacherProjectService,
private SpaceService: SpaceService,
private UtilService: UtilService
Expand All @@ -52,28 +55,6 @@ class AuthorNotebookController {
this.initializeStudentNotesAuthoring();
this.initializeTeacherNotesAuthoring();

this.$scope.$on('assetSelected', (event, args) => {
if (
args.projectId == this.projectId &&
args.assetItem != null &&
args.assetItem.fileName != null &&
args.target != null
) {
const assetsDirectoryPath = this.ConfigService.getProjectAssetsDirectoryPath();
const fileName = args.assetItem.fileName;
const fullAssetPath = assetsDirectoryPath + '/' + fileName;
const reportId = args.target;
const summernoteId = 'summernoteNotebook_' + reportId;
if (this.UtilService.isImage(fileName)) {
this.UtilService.restoreSummernoteCursorPosition(summernoteId);
this.UtilService.insertImageIntoSummernote(summernoteId, fullAssetPath, fileName);
} else if (this.UtilService.isVideo(fileName)) {
this.UtilService.restoreSummernoteCursorPosition(summernoteId);
this.UtilService.insertVideoIntoSummernote(summernoteId, fullAssetPath);
}
}
this.$mdDialog.hide();
});
this.isPublicNotebookEnabled = this.ProjectService.isSpaceExists('public');
}

Expand Down Expand Up @@ -118,7 +99,8 @@ class AuthorNotebookController {
null,
null,
note.reportId,
this.$translate('INSERT_ASSET')
this.$translate('INSERT_ASSET'),
this.createOpenAssetChooserFunction()
)
},
dialogsInBody: true
Expand All @@ -127,6 +109,29 @@ class AuthorNotebookController {
this.setReportIdToAuthoringNote(note.reportId, authoringReportNote);
}

createOpenAssetChooserFunction() {
return (params: any) => {
this.ProjectAssetService.openAssetChooser(params).then(
(data: any) => { this.assetSelected(data) }
);
}
}

assetSelected(args: any) {
const assetsDirectoryPath = this.ConfigService.getProjectAssetsDirectoryPath();
const fileName = args.assetItem.fileName;
const fullAssetPath = assetsDirectoryPath + '/' + fileName;
const reportId = args.target;
const summernoteId = 'summernoteNotebook_' + reportId;
if (this.UtilService.isImage(fileName)) {
this.UtilService.restoreSummernoteCursorPosition(summernoteId);
this.UtilService.insertImageIntoSummernote(summernoteId, fullAssetPath, fileName);
} else if (this.UtilService.isVideo(fileName)) {
this.UtilService.restoreSummernoteCursorPosition(summernoteId);
this.UtilService.insertVideoIntoSummernote(summernoteId, fullAssetPath);
}
}

setReportIdToAuthoringNote(reportId, authoringReportNote) {
this.reportIdToAuthoringNote[reportId] = authoringReportNote;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ <h4>{{ ::'notebookSettings' | translate }}</h4>
<label>
{{ ::'starterText' | translate }}
</label>
<summernote id="{{::reportNote.summernoteId}}"
<summernote id="summernoteNotebook_{{reportNote.reportId}}"
ng-model="authorNotebookController.reportIdToAuthoringNote[reportNote.reportId].summernoteHTML"
ng-change="authorNotebookController.reportStarterTextChanged(reportNote.reportId)"
config="authorNotebookController.reportIdToAuthoringNote[reportNote.reportId].summernoteOptions"
Expand Down Expand Up @@ -250,7 +250,7 @@ <h4>{{ ::'notebookSettings' | translate }}</h4>
<label>
{{ ::'starterText' | translate }}
</label>
<summernote id="{{::reportNote.summernoteId}}"
<summernote id="summernoteNotebook_{{reportNote.reportId}}"
ng-model="authorNotebookController.reportIdToAuthoringNote[reportNote.reportId].summernoteHTML"
ng-change="authorNotebookController.reportStarterTextChanged(reportNote.reportId)"
config="authorNotebookController.reportIdToAuthoringNote[reportNote.reportId].summernoteOptions"
Expand Down
Loading