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

Fix part of #7176: Add types for Customization Args #9463

Merged
merged 8 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,25 @@ import { Injectable } from '@angular/core';
import { AnswerGroup } from
'domain/exploration/AnswerGroupObjectFactory';
import { Hint } from 'domain/exploration/HintObjectFactory';
import { Outcome } from
'domain/exploration/OutcomeObjectFactory';
import {
ICustomizationArgs,
IDragAndDropSortInputCustomizationArgs,
IImageClickInputCustomizationArgs,
IItemSelectionInputCustomizationArgs,
IMultipleChoiceInputCustomizationArgs
} from 'extensions/interactions/customization-args-defs';
import { Interaction } from 'domain/exploration/InteractionObjectFactory';
import { Outcome } from 'domain/exploration/OutcomeObjectFactory';
import { Solution } from 'domain/exploration/SolutionObjectFactory';
import { SolutionValidityService } from
'pages/exploration-editor-page/editor-tab/services/solution-validity.service';
/* eslint-enable max-len */

interface IAnswerChoice {
val: string | number;
label: string;
}

@Injectable({
providedIn: 'root'
})
Expand All @@ -46,10 +59,7 @@ export class StateEditorService {
// is in solution verification. So, once the interaction is set in this
// service, the given solutions would be automatically verified for the set
// interaction.
// TODO(#7165): Replace 'any' with the exact type. This has been kept as
// 'any' because the return type is a interaction domain object which can be
// typed once InteractionObjectFactory is upgraded.
interaction: any = null;
interaction: Interaction = null;
misconceptionsBySkill: {} = {};
explorationIsWhitelisted: boolean = false;
solicitAnswerDetails: boolean = null;
Expand Down Expand Up @@ -135,52 +145,44 @@ export class StateEditorService {
this.interaction.setDefaultOutcome(newOutcome);
}

// TODO(#7176): Replace 'any' with the exact type. This has been kept as
// 'any' because 'newArgs' is a dict with underscore_cased keys which
// give tslint errors against underscore_casing in favor of camelCasing.
setInteractionCustomizationArgs(newArgs: any): void {
setInteractionCustomizationArgs(newArgs: ICustomizationArgs): void {
this.interaction.setCustomizationArgs(newArgs);
}

// TODO(#7165): Replace 'any' with the exact type. This has been kept as
// 'any' because 'solution' is a solution domain object which can be typed
// once SolutionObjectFactory is upgraded.
setInteractionSolution(solution: any): void {
setInteractionSolution(solution: Solution): void {
this.interaction.setSolution(solution);
}

setInteractionHints(hints: Hint[]): void {
this.interaction.setHints(hints);
}

// TODO(#7165): Replace 'any' with the exact type. This has been kept as
// 'any' because the return type is a interaction domain object which can be
// typed once InteractionObjectFactory is upgraded.
getInteraction(): any {
getInteraction(): Interaction {
return cloneDeep(this.interaction);
}

// TODO(#7176): Replace 'any' with the exact type. This has been kept as
// 'any' because 'customizationArgs' is a dict with underscore_cased keys
// which give tslint errors against underscore_casing in favor of camelCasing.
getAnswerChoices(interactionId: string, customizationArgs: any): any {
getAnswerChoices(
interactionId: string, customizationArgs:
brianrodri marked this conversation as resolved.
Show resolved Hide resolved
ICustomizationArgs): IAnswerChoice[] {
if (!interactionId) {
return null;
}
// Special cases for multiple choice input and image click input.
if (interactionId === 'MultipleChoiceInput') {
return customizationArgs.choices.value.map(
function(val, ind) {
return {
val: ind,
label: val
};
}
);
return (<IMultipleChoiceInputCustomizationArgs>customizationArgs)
brianrodri marked this conversation as resolved.
Show resolved Hide resolved
.choices.value.map(
function(val, ind) {
return {
val: ind,
label: val
};
}
);
brianrodri marked this conversation as resolved.
Show resolved Hide resolved
} else if (interactionId === 'ImageClickInput') {
var _answerChoices = [];
var imageWithRegions =
customizationArgs.imageAndRegions.value;
var imageWithRegions = (
<IImageClickInputCustomizationArgs>customizationArgs)
.imageAndRegions.value;
for (
var j = 0; j < imageWithRegions.labeledRegions.length; j++) {
_answerChoices.push({
Expand All @@ -191,12 +193,15 @@ export class StateEditorService {
return _answerChoices;
} else if (interactionId === 'ItemSelectionInput' ||
interactionId === 'DragAndDropSortInput') {
return customizationArgs.choices.value.map(function(val) {
return {
val: val,
label: val
};
});
return (
brianrodri marked this conversation as resolved.
Show resolved Hide resolved
<IDragAndDropSortInputCustomizationArgs |
IItemSelectionInputCustomizationArgs>customizationArgs)
.choices.value.map(function(val) {
return {
val: val,
label: val
};
});
} else {
return null;
}
Expand Down
35 changes: 22 additions & 13 deletions core/templates/domain/classroom/classroom-backend-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,27 @@ import { Injectable } from '@angular/core';

import { ClassroomDomainConstants } from
'domain/classroom/classroom-domain.constants';
import { TopicSummaryObjectFactory } from
'domain/topic/TopicSummaryObjectFactory';
import {
ITopicSummaryBackendDict,
TopicSummary,
TopicSummaryObjectFactory
} from 'domain/topic/TopicSummaryObjectFactory';
import { UrlInterpolationService } from
'domain/utilities/url-interpolation.service';

interface IClassroomTopicSummaryBackendDict {
'topic_summary_dicts': ITopicSummaryBackendDict[];
}

interface IClassroomStatusBackendDict {
'classroom_page_is_shown': boolean;
}

@Injectable({
providedIn: 'root'
})
export class ClassroomBackendApiService {
// TODO(#7176): Replace 'any' with the exact type. This has been kept as
// 'any' because 'subtopicDataBackendDict' is a dict with underscore_cased
// keys which give tslint errors against underscore_casing in favor of
// camelCasing.
topicSummaryObjects: any = null;
topicSummaryObjects: TopicSummary[] = null;
constructor(
private urlInterpolationService: UrlInterpolationService,
private http: HttpClient,
Expand All @@ -44,13 +51,14 @@ export class ClassroomBackendApiService {

_fetchClassroomData(classroomName: string,
successCallback: (value?: Object | PromiseLike<Object>) => void,
errorCallback: (reason?: any) => void): void {
errorCallback: (reason?: string) => void): void {
let classroomDataUrl = this.urlInterpolationService.interpolateUrl(
ClassroomDomainConstants.CLASSROOOM_DATA_URL_TEMPLATE, {
classroom_name: classroomName
});

this.http.get(classroomDataUrl).toPromise().then((data: any) => {
this.http.get<IClassroomTopicSummaryBackendDict>(
classroomDataUrl).toPromise().then(data => {
this.topicSummaryObjects = data.topic_summary_dicts.map(
(summaryDict) => {
return this.topicSummaryObjectFactory.createFromBackendDict(
Expand All @@ -60,7 +68,7 @@ export class ClassroomBackendApiService {
if (successCallback) {
successCallback(this.topicSummaryObjects);
}
}, (error: any) => {
}, (error: string) => {
if (errorCallback) {
errorCallback(error);
}
Expand All @@ -69,14 +77,15 @@ export class ClassroomBackendApiService {

_fetchClassroomPageIsShownStatus(
successCallback: (value?: Object | PromiseLike<Object>) => void,
errorCallback: (reason?: any) => void): void {
errorCallback: (reason?: string) => void): void {
const classroomStatusHandlerUrl = '/classroom_page_status_handler';

this.http.get(classroomStatusHandlerUrl).toPromise().then((data: any) => {
this.http.get<IClassroomStatusBackendDict>(
classroomStatusHandlerUrl).toPromise().then(data => {
if (successCallback) {
successCallback(data.classroom_page_is_shown);
}
}, (error: any) => {
}, (error: string) => {
if (errorCallback) {
errorCallback(error);
}
Expand Down
4 changes: 2 additions & 2 deletions core/templates/domain/topic/TopicSummaryObjectFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { downgradeInjectable } from '@angular/upgrade/static';
import { Injectable } from '@angular/core';

interface ITopicSummaryBackendDict {
export interface ITopicSummaryBackendDict {
'id': string;
'name': string;
'canonical_story_count': number;
Expand All @@ -29,7 +29,7 @@ interface ITopicSummaryBackendDict {
'uncategorized_skill_count': number;
}

class TopicSummary {
export class TopicSummary {
_id: string;
_name: string;
_canonicalStoryCount: number;
Expand Down
39 changes: 27 additions & 12 deletions core/templates/services/compute-graph.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,29 @@
import { downgradeInjectable } from '@angular/upgrade/static';
import { Injectable } from '@angular/core';

import { States } from 'domain/exploration/StatesObjectFactory';

interface IGraphLink {
source: string;
target: string;
}

interface IGraphNodes {
[stateName: string]: string;
}

interface IGraphData {
finalStateIds: string[];
initStateId: string;
links: IGraphLink[];
nodes: IGraphNodes;
}

@Injectable({
providedIn: 'root'
})
export class ComputeGraphService {
// TODO(#7176): Replace 'any' with exact type.As states.getFinalStateNames()
// is being called hence we can't just set the states type to Object
// since it will cause the typescript compilation to fail
_computeGraphData(initStateId: string, states: any): any {
_computeGraphData(initStateId: string, states: States): IGraphData {
let nodes = {};
let links = [];
let finalStateIds = states.getFinalStateNames();
Expand Down Expand Up @@ -60,9 +75,9 @@ export class ComputeGraphService {
nodes: nodes
};
}
// TODO(#7176): Replace 'any' with the exact type.
_computeBfsTraversalOfStates(initStateId: string, states: any,
sourceStateName: string): Array<any> {

_computeBfsTraversalOfStates(
initStateId: string, states: States, sourceStateName: string): string[] {
let stateGraph = this._computeGraphData(initStateId, states);
let stateNamesInBfsOrder = [];
let queue = [];
Expand All @@ -83,13 +98,13 @@ export class ComputeGraphService {
}
return stateNamesInBfsOrder;
}
// TODO(#7176): Replace 'any' with the exact type.
compute(initStateId: string, states: any): Object {

compute(initStateId: string, states: States): IGraphData {
return this._computeGraphData(initStateId, states);
}
// TODO(#7176): Replace 'any' with the exact type.
computeBfsTraversalOfStates(initStateId: string, states: any,
sourceStateName: any): Array<any> {

computeBfsTraversalOfStates(
initStateId: string, states: States, sourceStateName: string): string[] {
return this._computeBfsTraversalOfStates(
initStateId, states, sourceStateName);
}
Expand Down
4 changes: 2 additions & 2 deletions core/templates/services/extension-tag-assembler.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import { HtmlEscaperService } from 'services/html-escaper.service';
export class ExtensionTagAssemblerService {
constructor(private htmlEscaperService: HtmlEscaperService,
private camelCaseToHyphens: CamelCaseToHyphensPipe) {}
// TODO(#7176): Replace 'any' with the exact type.

formatCustomizationArgAttrs(
element: JQuery, customizationArgSpecs: Object): any {
element: JQuery, customizationArgSpecs: Object): JQuery {
brianrodri marked this conversation as resolved.
Show resolved Hide resolved
for (let caSpecName in customizationArgSpecs) {
let caSpecValue = customizationArgSpecs[caSpecName].value;
element.attr(
Expand Down
Loading