Skip to content

Commit

Permalink
Upgrade more services to Angular 8 - III (oppia#7214)
Browse files Browse the repository at this point in the history
* Untested work on PlaythroughIssueObjectFactory.ts

* Revert "Untested work on PlaythroughIssueObjectFactory.ts"

This reverts commit 13424bf.

* TopicRightsObjectFactory

* Lint fix

* Removed unnecessary constructor statement

* ClassifierObjectFactory

* AnswerClassificationResultObjectFactory

* PredictionResultObjectFactory

* WrittenTranslationObjectFactory

* RuleObjectFactory

* AudioTranslationObjectFactory

* ExplorationDraftObjectFactory

* Fix failing FE in TopicRightsObjectFactory

* Add force bootstrap to all pages

* function() -> () =>

* boilerplate

* FeedbackMessageSummaryObjectFactory

* FeedbackThreadObjectFactory

* FeedbackThreadSummaryObjectFactory

FeedbackThreadSummaryObjectFactory

* Merge ser-up-more

* SuggestionObjectFactory

* AudioFileObjectFactory

* AudioLanguageObjectFactory

* ImageFileObjectFactory

* FileDownloadRequestObjectFactory

* AutogeneratedAudioLanguageObjectFactory

* SkillSummaryObjectFactory

* SkillRightsObjectFactory

* MisconceptionObjectFactory

* LearnerDashboardActivityIdsObjectFactory

LearnerDashboardActivityIdsObjectFactory

* UserInfoObjectFactory

* PageTitleService

* Merge proper

* Merge proper

* UtilsService

* Revert "UtilsService"

This reverts commit dc009f9.

* IdGenerationService Fail FE

* Revert "IdGenerationService Fail FE"

This reverts commit 2406979.

* SchemaUndefinedLastElementService

* AutoplayedVideosService

* EditabilityService

* CodeNormalizerService

* SchemaDefaultValueService

* ImprovementsService

* SuggestionModalService

* CurrentInteractionService

* VoiceoverObjectFactory

* AudioTranslationManagerService

* Fix tests

* Fix tests

* PlayerCorrectnessFeedbackEnabledService

* Update mocking method

* Fix lint

* Fix test

* NumberAttemptsService

* AngularNameService

* SolutionValidityService

* Fix lint

Fix lint

* AdminTaskManagerService

* RatingComputationService

* ContinueRulesService

* AnswerStatsObjectFactory

* More typing

* Audit and newline

* Merge

* Stronger typing

* Fix FE

* Address comments

* Remove newlines, TODO for imports, modify MockOutcome

* Fix matcher case, modify TODO for imports

* Fix FE

* Fix FE

* Stronger typing in RuleObjectFactory

* Fix lint

* Fix e2e

* Fix AJAX errors in Karma

* Fix FE

* Add comment in csrftoken

* Stronger typing

Stronger typing

* Fix FE?

* Fix FE?

* Stronger typing

* Fix FE?

* Fixed e2e but FE?

* Fix FE?

* Fix Karma for good

* Wrap

* Minor nit

* Minor nit

* Address review

* Address review

* Address review

* Address review

* Added comments and types

* Added comments and types

* Narrowed types

* Lint

* Address review

* Address review

* Address review
  • Loading branch information
YashJipkate authored and seanlip committed Jul 25, 2019
1 parent 7976761 commit 88e062c
Show file tree
Hide file tree
Showing 74 changed files with 1,128 additions and 628 deletions.
5 changes: 4 additions & 1 deletion core/templates/dev/head/AppSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@
// TODO(YashJipkate): Remove the following block of unnnecessary imports once
// App.ts is upgraded to Angular 8.
import { RuleObjectFactory } from 'domain/exploration/RuleObjectFactory.ts';
import { VoiceoverObjectFactory } from
'domain/exploration/VoiceoverObjectFactory.ts';
import { WrittenTranslationObjectFactory } from
'domain/exploration/WrittenTranslationObjectFactory.ts';
// ^^^ This block is to be removed.

describe('Constants Generating', function() {
beforeEach(angular.mock.module('oppia'));
beforeEach(angular.mock.module('oppia', function($provide) {
$provide.value('RuleObjectFactory', new RuleObjectFactory());
$provide.value('VoiceoverObjectFactory', new VoiceoverObjectFactory());
$provide.value(
'WrittenTranslationObjectFactory',
new WrittenTranslationObjectFactory());
$provide.value('RuleObjectFactory', new RuleObjectFactory());
}));

var $injector = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ require(
require('components/question-directives/question-player/' +
'question-player.constants.ts');
require('filters/string-utility-filters/normalize-whitespace.filter.ts');
require('services/AutoplayedVideosService.ts');
// ^^^ this block of requires should be removed ^^^

require(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// TODO(YashJipkate): Remove the following block of unnnecessary imports once
// question-player-state.service.ts is upgraded to Angular 8.
import { RuleObjectFactory } from 'domain/exploration/RuleObjectFactory.ts';
import { VoiceoverObjectFactory } from
'domain/exploration/VoiceoverObjectFactory.ts';
import { WrittenTranslationObjectFactory } from
'domain/exploration/WrittenTranslationObjectFactory.ts';
// ^^^ This block is to be removed.
Expand All @@ -37,6 +39,7 @@ describe('Question player state service', function() {
beforeEach(angular.mock.module('oppia'));
beforeEach(angular.mock.module('oppia', function($provide) {
$provide.value('RuleObjectFactory', new RuleObjectFactory());
$provide.value('VoiceoverObjectFactory', new VoiceoverObjectFactory());
$provide.value(
'WrittenTranslationObjectFactory',
new WrittenTranslationObjectFactory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
* @fileoverview Tests that average ratings are being computed correctly.
*/

require('components/ratings/rating-computation/rating-computation.service.ts');
import { RatingComputationService } from
'components/ratings/rating-computation/rating-computation.service.ts';

describe('Rating computation service', function() {
var RatingComputationService;
describe('Rating computation service', () => {
let ratingComputationService: RatingComputationService;

beforeEach(angular.mock.module('oppia'));
beforeEach(angular.mock.inject(function($injector) {
RatingComputationService = $injector.get('RatingComputationService');
}));
beforeEach(() => {
ratingComputationService = new RatingComputationService();
});

it(
'should show an average rating only if there are enough individual ones',
function() {
() => {
// Don't show an average rating if there are too few ratings.
expect(RatingComputationService.computeAverageRating({
expect(ratingComputationService.computeAverageRating({
1: 0,
2: 0,
3: 0,
Expand All @@ -39,7 +39,7 @@ describe('Rating computation service', function() {
})).toBe(undefined);

// Show an average rating once the minimum is reached.
expect(RatingComputationService.computeAverageRating({
expect(ratingComputationService.computeAverageRating({
1: 1,
2: 0,
3: 0,
Expand All @@ -48,7 +48,7 @@ describe('Rating computation service', function() {
})).toBe(1.0);

// Continue showing an average rating if additional ratings are added.
expect(RatingComputationService.computeAverageRating({
expect(ratingComputationService.computeAverageRating({
1: 1,
2: 0,
3: 0,
Expand All @@ -58,8 +58,8 @@ describe('Rating computation service', function() {
}
);

it('should compute average ratings correctly', function() {
expect(RatingComputationService.computeAverageRating({
it('should compute average ratings correctly', () => {
expect(ratingComputationService.computeAverageRating({
1: 6,
2: 3,
3: 8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,49 @@
* @fileoverview Service for computing the average rating.
*/

var oppia = require('AppInit.ts').module;
import { Injectable } from '@angular/core';
import { downgradeInjectable } from '@angular/upgrade/static';

export interface IRatingFrequencies {
[x: string]: number;
}

oppia.factory('RatingComputationService', [function() {
var areRatingsShown = function(ratingFrequencies) {
var MINIMUM_ACCEPTABLE_NUMBER_OF_RATINGS = 1;
@Injectable({
providedIn: 'root'
})
export class RatingComputationService {
static areRatingsShown(ratingFrequencies: IRatingFrequencies): boolean {
let MINIMUM_ACCEPTABLE_NUMBER_OF_RATINGS: number = 1;

var totalNumber = 0;
let totalNumber: number = 0;
for (var value in ratingFrequencies) {
totalNumber += ratingFrequencies[value];
}

return totalNumber >= MINIMUM_ACCEPTABLE_NUMBER_OF_RATINGS;
};
}

computeAverageRating(ratingFrequencies: IRatingFrequencies): number {
if (!RatingComputationService.areRatingsShown(ratingFrequencies)) {
return undefined;
} else {
var totalNumber = 0;
var totalValue = 0.0;
for (var value in ratingFrequencies) {
totalValue += parseInt(value) * ratingFrequencies[value];
totalNumber += ratingFrequencies[value];
}

return {
computeAverageRating: function(ratingFrequencies) {
if (!areRatingsShown(ratingFrequencies)) {
if (totalNumber === 0) {
return undefined;
} else {
var totalNumber = 0;
var totalValue = 0.0;
for (var value in ratingFrequencies) {
totalValue += parseInt(value) * ratingFrequencies[value];
totalNumber += ratingFrequencies[value];
}

if (totalNumber === 0) {
return undefined;
}

return totalValue / totalNumber;
}

return totalValue / totalNumber;
}
};
}]);
}
}

var oppia = require('AppInit.ts').module;

oppia.factory(
'RatingComputationService', downgradeInjectable(RatingComputationService));
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@
* @fileoverview Unit test for the Editor state service.
*/

/* eslint-disable max-len */
import { SolutionValidityService } from
'pages/exploration-editor-page/editor-tab/services/solution-validity.service.ts';
/* eslint-enable max-len */

require(
'components/state-editor/state-editor-properties-services/' +
'state-editor.service.ts');

describe('Editor state service', function() {
beforeEach(angular.mock.module('oppia'));
beforeEach(angular.mock.module('oppia', function($provide) {
$provide.value('SolutionValidityService', new SolutionValidityService());
}));

describe('editor state service', function() {
var ecs = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,30 @@
* particular answer from some particular state.
*/

var oppia = require('AppInit.ts').module;
import * as _ from 'lodash';

import { Injectable } from '@angular/core';
import { downgradeInjectable } from '@angular/upgrade/static';

export interface IAnswerStatsBackendDict {
// TODO(YashJipkate): Replace 'any' with the exact type. This has been kept as
// 'any' since 'answer' is a dict with underscore_cased keys which gives
// tslint errors against underscore_casing in favor of camelCasing.
// https://github.com/oppia/oppia/issues/7176
answer: any;
frequency: number;
}

export class AnswerStats {
// TODO(YashJipkate): Replace 'any' with the exact type. This has been kept as
// 'any' since 'answer' is a dict with underscore_cased keys which gives
// tslint errors against underscore_casing in favor of camelCasing.
// https://github.com/oppia/oppia/issues/7176
answer: any;
answerHtml: string;
frequency: number;
isAddressed: boolean;

oppia.factory('AnswerStatsObjectFactory', [function() {
/**
* @constructor
* @param {*} answer - raw answer object.
Expand All @@ -28,25 +49,32 @@ oppia.factory('AnswerStatsObjectFactory', [function() {
* @param {boolean} isAddressed - whether this answer is addressed by the
* associated state's answer groups.
*/
var AnswerStats = function(answer, answerHtml, frequency, isAddressed) {
constructor(
answer: any, answerHtml: string, frequency: number,
isAddressed: boolean) {
/** @type {*} */
this.answer = angular.copy(answer);
this.answer = _.cloneDeep(answer);
/** @type {string} */
this.answerHtml = answerHtml;
/** @type {number} */
this.frequency = frequency;
/** @type {boolean} */
this.isAddressed = isAddressed;
};
}

/** @returns {answer, frequency: number} */
AnswerStats.prototype.toBackendDict = function() {
toBackendDict(): IAnswerStatsBackendDict {
return {
answer: angular.copy(this.answer),
answer: _.cloneDeep(this.answer),
frequency: this.frequency
};
};
}
}

@Injectable({
providedIn: 'root'
})
export class AnswerStatsObjectFactory {
/**
* Returns a stale instance; specifically, {@link AnswerStats.isAddressed}
* will always be false.
Expand All @@ -56,17 +84,18 @@ oppia.factory('AnswerStatsObjectFactory', [function() {
* @param {{answer, frequency: number}} backendDict
* @returns {AnswerStats}
*/
// TODO(ankita240796): Remove the bracket notation once Angular2 gets in.
/* eslint-disable dot-notation */
AnswerStats['createFromBackendDict'] = function(backendDict) {
/* eslint-enable dot-notation */
createFromBackendDict(
backendDict: IAnswerStatsBackendDict): AnswerStats {
// TODO(brianrodri): Use a proper service which takes the state's
// interaction type into account for generating the answer's HTML.
var answerHtml = (typeof backendDict.answer === 'string') ?
backendDict.answer : angular.toJson(backendDict.answer);
backendDict.answer : JSON.stringify(backendDict.answer);
return new AnswerStats(
backendDict.answer, answerHtml, backendDict.frequency, false);
};
}
}

var oppia = require('AppInit.ts').module;

return AnswerStats;
}]);
oppia.factory(
'AnswerStatsObjectFactory', downgradeInjectable(AnswerStatsObjectFactory));
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@
// TODO(YashJipkate): Remove the following block of unnnecessary imports once
// ExplorationObjectFactory.ts is upgraded to Angular 8.
import { RuleObjectFactory } from 'domain/exploration/RuleObjectFactory.ts';
import { VoiceoverObjectFactory } from
'domain/exploration/VoiceoverObjectFactory.ts';
import { WrittenTranslationObjectFactory } from
'domain/exploration/WrittenTranslationObjectFactory.ts';
// ^^^ This block is to be removed.

require('domain/exploration/ExplorationObjectFactory.ts');
require('domain/exploration/VoiceoverObjectFactory.ts');
require('domain/state/StateObjectFactory.ts');

describe('Exploration object factory', function() {
beforeEach(angular.mock.module('oppia'));
beforeEach(angular.mock.module('oppia', function($provide) {
$provide.value('RuleObjectFactory', new RuleObjectFactory());
$provide.value('VoiceoverObjectFactory', new VoiceoverObjectFactory());
$provide.value(
'WrittenTranslationObjectFactory',
new WrittenTranslationObjectFactory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* @fileoverview Unit tests for RecordedVoiceovers object factory.
*/

import { VoiceoverObjectFactory } from
'domain/exploration/VoiceoverObjectFactory.ts';

require('domain/exploration/RecordedVoiceoversObjectFactory.ts');
require('domain/exploration/VoiceoverObjectFactory.ts');

Expand Down Expand Up @@ -102,6 +105,9 @@ describe('RecordedVoiceovers object factory', function() {
};

beforeEach(angular.mock.module('oppia'));
beforeEach(angular.mock.module('oppia', function($provide) {
$provide.value('VoiceoverObjectFactory', new VoiceoverObjectFactory());
}));

beforeEach(angular.mock.inject(function($injector) {
vof = $injector.get('VoiceoverObjectFactory');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
// TODO(YashJipkate): Remove the following block of unnnecessary imports once
// StatesObjectFactory.ts is upgraded to Angular 8.
import { RuleObjectFactory } from 'domain/exploration/RuleObjectFactory.ts';
import { VoiceoverObjectFactory } from
'domain/exploration/VoiceoverObjectFactory.ts';
import { WrittenTranslationObjectFactory } from
'domain/exploration/WrittenTranslationObjectFactory.ts';
// ^^^ This block is to be removed.
Expand All @@ -31,6 +33,7 @@ describe('States object factory', function() {
beforeEach(angular.mock.module('oppia'));
beforeEach(angular.mock.module('oppia', function($provide) {
$provide.value('RuleObjectFactory', new RuleObjectFactory());
$provide.value('VoiceoverObjectFactory', new VoiceoverObjectFactory());
$provide.value(
'WrittenTranslationObjectFactory',
new WrittenTranslationObjectFactory());
Expand Down
Loading

0 comments on commit 88e062c

Please sign in to comment.