Skip to content

Commit

Permalink
Fix part of #10083: Removes events 'topicsAndSkillsDashboardReinitial…
Browse files Browse the repository at this point in the history
…ized' and 'undoRedoChangeApplied' (#10342)

* Initial commit

* Debugging done

* Mid 2

* Consolidated logs

* Removed redundant events

* Finish undoredochangeapplied

* Consolidated testing logs

* Debugging

* Rollback undoredo

* rollback pt 2

* Removed logs

* Mid test debugging

* Prem fixed tests

* Fixed tests with 100% coverage

* Minor fixes

* Initial commit

* Finally debugged

* Full coverage achieved

* Removed editor page constants

* Minor fixes

* Debugged

* Nit
  • Loading branch information
sainanee committed Aug 16, 2020
1 parent 2d4e576 commit b8734a4
Show file tree
Hide file tree
Showing 27 changed files with 283 additions and 186 deletions.
Expand Up @@ -18,6 +18,8 @@

require('domain/utilities/url-interpolation.service.ts');
require('domain/skill/skill-creation-backend-api.service.ts');
require('domain/topics_and_skills_dashboard/' +
'topics-and-skills-dashboard-backend-api.service.ts');
require('services/alerts.service.ts');
require('services/image-local-storage.service.ts');

Expand All @@ -29,14 +31,14 @@ require(
'pages/topics-and-skills-dashboard-page/' +
'create-new-skill-modal.controller.ts');
angular.module('oppia').factory('SkillCreationService', [
'$rootScope', '$timeout', '$uibModal', '$window', 'AlertsService',
'$timeout', '$uibModal', '$window', 'AlertsService',
'ImageLocalStorageService', 'SkillCreationBackendApiService',
'UrlInterpolationService', 'EVENT_TOPICS_AND_SKILLS_DASHBOARD_REINITIALIZED',
'TopicsAndSkillsDashboardBackendApiService', 'UrlInterpolationService',
'SKILL_DESCRIPTION_STATUS_VALUES',
function(
$rootScope, $timeout, $uibModal, $window, AlertsService,
$timeout, $uibModal, $window, AlertsService,
ImageLocalStorageService, SkillCreationBackendApiService,
UrlInterpolationService, EVENT_TOPICS_AND_SKILLS_DASHBOARD_REINITIALIZED,
TopicsAndSkillsDashboardBackendApiService, UrlInterpolationService,
SKILL_DESCRIPTION_STATUS_VALUES) {
var CREATE_NEW_SKILL_URL_TEMPLATE = (
'/skill_editor/<skill_id>');
Expand Down Expand Up @@ -94,8 +96,8 @@ angular.module('oppia').factory('SkillCreationService', [
result.description, rubrics, result.explanation,
topicIds || [], imagesData).then(function(response) {
$timeout(function() {
$rootScope.$broadcast(
EVENT_TOPICS_AND_SKILLS_DASHBOARD_REINITIALIZED, true);
TopicsAndSkillsDashboardBackendApiService.
onTopicsAndSkillsDashboardReinitialized.emit(true);
skillCreationInProgress = false;
ImageLocalStorageService.flushStoredImagesData();
newTab.location.href = UrlInterpolationService.interpolateUrl(
Expand Down
Expand Up @@ -26,6 +26,8 @@ require('domain/topics_and_skills_dashboard/' +
require('domain/utilities/url-interpolation.service.ts');
require('domain/topic/topic-creation-backend-api.service.ts');
require('pages/topic-editor-page/services/topic-editor-state.service.ts');
require('domain/topics_and_skills_dashboard/' +
'topics-and-skills-dashboard-backend-api.service.ts');
require(
'pages/topics-and-skills-dashboard-page/' +
'create-new-topic-modal.controller.ts');
Expand All @@ -35,15 +37,13 @@ require('services/image-local-storage.service.ts');
require('services/image-upload-helper.service.ts');

angular.module('oppia').factory('TopicCreationService', [
'$rootScope', '$uibModal', '$window', 'AlertsService', 'ContextService',
'$uibModal', '$window', 'AlertsService', 'ContextService',
'ImageLocalStorageService', 'TopicCreationBackendApiService',
'UrlInterpolationService',
'EVENT_TOPICS_AND_SKILLS_DASHBOARD_REINITIALIZED',
'TopicsAndSkillsDashboardBackendApiService', 'UrlInterpolationService',
function(
$rootScope, $uibModal, $window, AlertsService, ContextService,
$uibModal, $window, AlertsService, ContextService,
ImageLocalStorageService, TopicCreationBackendApiService,
UrlInterpolationService,
EVENT_TOPICS_AND_SKILLS_DASHBOARD_REINITIALIZED) {
TopicsAndSkillsDashboardBackendApiService, UrlInterpolationService) {
var TOPIC_EDITOR_URL_TEMPLATE = '/topic_editor/<topic_id>';
var topicCreationInProgress = false;

Expand Down Expand Up @@ -78,8 +78,8 @@ angular.module('oppia').factory('TopicCreationService', [
TopicCreationBackendApiService.createTopic(
newlyCreatedTopic, imagesData, bgColor).then(
function(response) {
$rootScope.$broadcast(
EVENT_TOPICS_AND_SKILLS_DASHBOARD_REINITIALIZED);
TopicsAndSkillsDashboardBackendApiService.
onTopicsAndSkillsDashboardReinitialized.emit();
topicCreationInProgress = false;
ImageLocalStorageService.flushStoredImagesData();
ContextService.resetImageSaveDestination();
Expand Down
26 changes: 0 additions & 26 deletions core/templates/domain/editor/editor-domain.constants.ajs.ts

This file was deleted.

22 changes: 0 additions & 22 deletions core/templates/domain/editor/editor-domain.constants.ts

This file was deleted.

38 changes: 23 additions & 15 deletions core/templates/domain/editor/undo_redo/base-undo-redo.service.ts
Expand Up @@ -17,39 +17,40 @@
* Changes may be undone, redone, or replaced.
*/

require('domain/editor/editor-domain.constants.ajs.ts');
import { EventEmitter } from '@angular/core';

/**
* Stores a stack of changes to a domain object. Please note that only one
* instance of this service exists at a time, so multiple undo/redo stacks are
* not currently supported.
*/
angular.module('oppia').factory('BaseUndoRedoService', [
'$rootScope', 'EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED',
function($rootScope, EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED) {
function() {
var BaseUndoRedoService = {};

this._appliedChanges = [];
this._undoneChanges = [];
var _undoRedoChangeEventEmitter = new EventEmitter();

var _dispatchMutation = function() {
$rootScope.$broadcast(EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED);
var _dispatchMutation = () => {
_undoRedoChangeEventEmitter.emit();
};
var _applyChange = function(changeObject, domainObject) {
var _applyChange = (changeObject, domainObject) => {
changeObject.applyChange(domainObject);
_dispatchMutation();
};
var _reverseChange = function(changeObject, domainObject) {
var _reverseChange = (changeObject, domainObject) => {
changeObject.reverseChange(domainObject);
_dispatchMutation();
};

// TODO(ankita240796): Remove the bracket notation once Angular2 gets in.
/* eslint-disable dot-notation */
BaseUndoRedoService['init'] = function() {
/* eslint-enable dot-notation */
/* eslint-enable dot-notation */
this._appliedChanges = [];
this._undoneChanges = [];
_undoRedoChangeEventEmitter = new EventEmitter();
};

/**
Expand All @@ -76,7 +77,7 @@ angular.module('oppia').factory('BaseUndoRedoService', [
// TODO(ankita240796): Remove the bracket notation once Angular2 gets in.
/* eslint-disable dot-notation */
BaseUndoRedoService['undoChange'] = function(domainObject) {
/* eslint-enable dot-notation */
/* eslint-enable dot-notation */
if (this._appliedChanges.length !== 0) {
var change = this._appliedChanges.pop();
this._undoneChanges.push(change);
Expand All @@ -94,7 +95,7 @@ angular.module('oppia').factory('BaseUndoRedoService', [
// TODO(ankita240796): Remove the bracket notation once Angular2 gets in.
/* eslint-disable dot-notation */
BaseUndoRedoService['redoChange'] = function(domainObject) {
/* eslint-enable dot-notation */
/* eslint-enable dot-notation */
if (this._undoneChanges.length !== 0) {
var change = this._undoneChanges.pop();
this._appliedChanges.push(change);
Expand All @@ -112,7 +113,7 @@ angular.module('oppia').factory('BaseUndoRedoService', [
// TODO(ankita240796): Remove the bracket notation once Angular2 gets in.
/* eslint-disable dot-notation */
BaseUndoRedoService['getChangeList'] = function() {
/* eslint-enable dot-notation */
/* eslint-enable dot-notation */
// TODO(bhenning): Consider integrating something like Immutable.js to
// avoid the slice here and ensure the returned object is truly an
// immutable copy.
Expand All @@ -127,7 +128,7 @@ angular.module('oppia').factory('BaseUndoRedoService', [
// TODO(ankita240796): Remove the bracket notation once Angular2 gets in.
/* eslint-disable dot-notation */
BaseUndoRedoService['getCommittableChangeList'] = function() {
/* eslint-enable dot-notation */
/* eslint-enable dot-notation */
var committableChangeList = [];
for (var i = 0; i < this._appliedChanges.length; i++) {
committableChangeList[i] =
Expand All @@ -139,7 +140,7 @@ angular.module('oppia').factory('BaseUndoRedoService', [
// TODO(ankita240796): Remove the bracket notation once Angular2 gets in.
/* eslint-disable dot-notation */
BaseUndoRedoService['setChangeList'] = function(changeList) {
/* eslint-enable dot-notation */
/* eslint-enable dot-notation */
this._appliedChanges = angular.copy(changeList);
};

Expand All @@ -150,7 +151,7 @@ angular.module('oppia').factory('BaseUndoRedoService', [
// TODO(ankita240796): Remove the bracket notation once Angular2 gets in.
/* eslint-disable dot-notation */
BaseUndoRedoService['getChangeCount'] = function() {
/* eslint-enable dot-notation */
/* eslint-enable dot-notation */
return this._appliedChanges.length;
};

Expand All @@ -172,12 +173,19 @@ angular.module('oppia').factory('BaseUndoRedoService', [
// TODO(ankita240796): Remove the bracket notation once Angular2 gets in.
/* eslint-disable dot-notation */
BaseUndoRedoService['clearChanges'] = function() {
/* eslint-enable dot-notation */
/* eslint-enable dot-notation */
this._appliedChanges = [];
this._undoneChanges = [];
this._undoRedoChangeAppliedEventEmitter = new EventEmitter();
_dispatchMutation();
};

/* eslint-disable dot-notation */
BaseUndoRedoService['onUndoRedoChangeApplied'] = function() {
/* eslint-enable dot-notation */
return _undoRedoChangeEventEmitter;
};

return BaseUndoRedoService;
}
]);
Expand Up @@ -19,7 +19,7 @@

import { downgradeInjectable } from '@angular/upgrade/static';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { EventEmitter, Injectable } from '@angular/core';

import {
AssignedSkill,
Expand Down Expand Up @@ -121,6 +121,9 @@ export class TopicsAndSkillsDashboardBackendApiService {
private topicSummaryObjectFactory: TopicSummaryObjectFactory,
private urlInterpolationService: UrlInterpolationService) {}

private _topicsAndSkillsDashboardReinitializedEventEmitter =
new EventEmitter();

fetchDashboardData(): Promise<TopicsAndSkillDashboardData> {
return this.http.get<TopicsAndSkillsDashboardDataBackendDict>(
'/topics_and_skills_dashboard/data').toPromise().then(response => {
Expand Down Expand Up @@ -213,6 +216,10 @@ export class TopicsAndSkillsDashboardBackendApiService {
throw new Error(errorResponse.error.error);
});
}

get onTopicsAndSkillsDashboardReinitialized() {
return this._topicsAndSkillsDashboardReinitializedEventEmitter;
}
}
angular.module('oppia').factory(
'TopicsAndSkillsDashboardBackendApiService',
Expand Down
Expand Up @@ -44,8 +44,6 @@ import { CollectionDomainConstants } from
'domain/collection/collection-domain.constants';
import { CollectionEditorPageConstants } from
'pages/collection-editor-page/collection-editor-page.constants';
import { EditorDomainConstants } from
'domain/editor/editor-domain.constants';
import { InteractionsExtensionsConstants } from
'interactions/interactions-extension.constants';
import { ObjectsDomainConstants } from
Expand Down Expand Up @@ -89,7 +87,6 @@ import { CollectionStatisticsTabComponent } from
providers: [
AppConstants,
CollectionDomainConstants,
EditorDomainConstants,
InteractionsExtensionsConstants,
ObjectsDomainConstants,
ServicesConstants,
Expand Down
Expand Up @@ -58,14 +58,12 @@ angular.module('oppia').directive('collectionEditorNavbar', [
'CollectionValidationService',
'CollectionRightsBackendApiService',
'EditableCollectionBackendApiService', 'UrlService',
'EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED',
function(
$scope, $rootScope, $uibModal, AlertsService, RouterService,
UndoRedoService, CollectionEditorStateService,
CollectionValidationService,
CollectionRightsBackendApiService,
EditableCollectionBackendApiService, UrlService,
EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED) {
EditableCollectionBackendApiService, UrlService) {
var ctrl = this;
ctrl.directiveSubscriptions = new Subscription();
var _validateCollection = function() {
Expand Down Expand Up @@ -215,8 +213,11 @@ angular.module('oppia').directive('collectionEditorNavbar', [
() => _validateCollection()
)
);
$scope.$on(
EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED, _validateCollection);
ctrl.directiveSubscriptions.add(
UndoRedoService.onUndoRedoChangeApplied().subscribe(
() => _validateCollection()
)
);
ctrl.collectionId = UrlService.getCollectionIdFromEditorUrl();
ctrl.collection = CollectionEditorStateService.getCollection();
ctrl.collectionRights = (
Expand Down
Expand Up @@ -48,8 +48,6 @@ import { ClassifiersExtensionConstants } from
'classifiers/classifiers-extension.constants';
import { CollectionSummaryTileConstants } from
'components/summary-tile/collection-summary-tile.constants';
import { EditorDomainConstants } from
'domain/editor/editor-domain.constants';
import { InteractionsExtensionsConstants } from
'interactions/interactions-extension.constants';
import { ObjectsDomainConstants } from
Expand Down Expand Up @@ -83,7 +81,6 @@ import { ExplorationEditorPageConstants } from
ClassifiersExtensionConstants,
CollectionSummaryTileConstants,
InteractionsExtensionsConstants,
EditorDomainConstants,
ObjectsDomainConstants,
QuestionDomainConstants,
ServicesConstants,
Expand Down
Expand Up @@ -42,8 +42,6 @@ import { OppiaAngularRootComponent } from
'components/oppia-angular-root.component';

import { AppConstants } from 'app.constants';
import { EditorDomainConstants } from
'domain/editor/editor-domain.constants';
import { InteractionsExtensionsConstants } from
'interactions/interactions-extension.constants';
import { ObjectsDomainConstants } from
Expand Down Expand Up @@ -72,7 +70,6 @@ import { SkillEditorPageConstants } from
providers: [
AppConstants,
InteractionsExtensionsConstants,
EditorDomainConstants,
ObjectsDomainConstants,
QuestionDomainConstants,
QuestionsListConstants,
Expand Down
Expand Up @@ -44,12 +44,10 @@ angular.module('oppia').directive('storyEditorNavbar', [
'$scope', '$rootScope', '$uibModal', 'AlertsService',
'EditableStoryBackendApiService', 'UndoRedoService',
'StoryEditorStateService', 'StoryEditorNavigationService', 'UrlService',
'EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED',
function(
$scope, $rootScope, $uibModal, AlertsService,
EditableStoryBackendApiService, UndoRedoService,
StoryEditorStateService, StoryEditorNavigationService, UrlService,
EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED) {
StoryEditorStateService, StoryEditorNavigationService, UrlService) {
var ctrl = this;
var EDITOR = 'Editor';
var PREVIEW = 'Preview';
Expand Down Expand Up @@ -213,8 +211,11 @@ angular.module('oppia').directive('storyEditorNavbar', [
$scope.isSaveInProgress = StoryEditorStateService.isSavingStory;
$scope.validationIssues = [];
$scope.prepublishValidationIssues = [];
$scope.$on(
EVENT_UNDO_REDO_SERVICE_CHANGE_APPLIED, _validateStory);
ctrl.directiveSubscriptions.add(
UndoRedoService.onUndoRedoChangeApplied().subscribe(
() => _validateStory()
)
);
};

ctrl.$onDestroy = function() {
Expand Down

0 comments on commit b8734a4

Please sign in to comment.