Skip to content

Commit

Permalink
Fix oppia#5069: Remove $parent from codebase. (oppia#7110)
Browse files Browse the repository at this point in the history
* remove $parent.localvalue

* Fix e2e

* Fix FE

* Fix e2e

* Removed .displayedCollectionCategory

* Removed .displayedCollectionTags

* Removed .newCategory

* Removed ..tmpStateName

* Removed .emailBody

* Removed ..customizationArgs

* Fix backend tests

* Added the lint check

* Revert package-lock

* Revert package-lock.json

* Restored permission for hook
  • Loading branch information
YashJipkate authored and vojtechjelinek committed Jul 9, 2019
1 parent 189d211 commit 3316974
Show file tree
Hide file tree
Showing 31 changed files with 312 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Testing apply-validation directive', function() {
scope = $rootScope.$new();
element = '<form name="testForm">' +
'<input name="inputValue" type="number" ng-model="localValue" ' +
'apply-validation>' +
'apply-validation validators="validators()">' +
'</form>';
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ oppia.directive('applyValidation', ['$filter', function($filter) {
return {
require: 'ngModel',
restrict: 'A',
scope: {},
bindToController: {
validators: '&'
},
controllerAs: '$ctrl',
controller: [function() {}],
link: function(scope: ICustomScope, elm, attrs, ctrl) {
// Add validators in reverse order.
if (scope.validators()) {
scope.validators().forEach(function(validatorSpec) {
if (scope.$ctrl.validators()) {
scope.$ctrl.validators().forEach(function(validatorSpec) {
var frontendName = $filter('underscoresToCamelCase')(
validatorSpec.id);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="input-group">
<span ng-if="!expressionMode">
<input type="checkbox" ng-model="$parent.localValue" ng-disabled="isDisabled()"
focus-on="<[labelForFocusTarget()]>">
<input type="checkbox" ng-model="$ctrl.localValue" ng-disabled="$ctrl.isDisabled()"
focus-on="<[$ctrl.labelForFocusTarget()]>">
</span>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ oppia.directive('schemaBasedBoolEditor', [
'UrlInterpolationService',
function(UrlInterpolationService) {
return {
scope: {
restrict: 'E',
scope: {},
bindToController: {
localValue: '=',
isDisabled: '&',
labelForFocusTarget: '&'
},
templateUrl: UrlInterpolationService.getDirectiveTemplateUrl(
'/components/forms/' +
'schema-based-editors/schema-based-bool-editor.directive.html'),
restrict: 'E'
controllerAs: '$ctrl',
controller: [function() {}]
};
}]);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<select class="form-control" ng-model="$parent.$parent.localValue"
ng-options="choice as choice for choice in choices()" required
ng-disabled="isDisabled()">
<select class="form-control" ng-model="$ctrl.localValue"
ng-options="choice as choice for choice in $ctrl.choices()" required
ng-disabled="$ctrl.isDisabled()">
</select>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ oppia.directive('schemaBasedChoicesEditor', [
NestedDirectivesRecursionTimeoutPreventionService,
UrlInterpolationService) {
return {
scope: {
restrict: 'E',
scope: {},
bindToController: {
localValue: '=',
// The choices for the object's value.
choices: '&',
Expand All @@ -40,11 +42,12 @@ oppia.directive('schemaBasedChoicesEditor', [
templateUrl: UrlInterpolationService.getDirectiveTemplateUrl(
'/components/forms/schema-based-editors/' +
'schema-based-choices-editor.directive.html'),
restrict: 'E',
controllerAs: '$ctrl',
compile: NestedDirectivesRecursionTimeoutPreventionService.compile,
controller: ['$scope', function($scope) {
$scope.getReadonlySchema = function() {
var readonlySchema = angular.copy($scope.schema());
var ctrl = this;
ctrl.getReadonlySchema = function() {
var readonlySchema = angular.copy(ctrl.schema());
delete readonlySchema.choices;
return readonlySchema;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<object-editor obj-type="<[objType]>" value="$parent.$parent.localValue" always-editable="true">
<object-editor obj-type="<[$ctrl.objType]>" value="$ctrl.localValue" always-editable="true">
</object-editor>
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ oppia.directive('schemaBasedCustomEditor', [
NestedDirectivesRecursionTimeoutPreventionService,
UrlInterpolationService) {
return {
scope: {
restrict: 'E',
scope: {},
bindToController: {
localValue: '=',
// The class of the object being edited.
objType: '='
},
templateUrl: UrlInterpolationService.getDirectiveTemplateUrl(
'/components/forms/schema-based-editors/' +
'schema-based-custom-editor.directive.html'),
restrict: 'E',
compile: NestedDirectivesRecursionTimeoutPreventionService.compile
controllerAs: '$ctrl',
compile: NestedDirectivesRecursionTimeoutPreventionService.compile,
controller: [function() {}]
};
}
]);
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
<schema-based-choices-editor ng-if="schema().choices" local-value="$parent.localValue"
schema="schema()" choices="schema().choices"
is-disabled="isDisabled()">
<schema-based-choices-editor ng-if="$ctrl.schema().choices" local-value="$ctrl.localValue"
schema="$ctrl.schema()" choices="$ctrl.schema().choices"
is-disabled="$ctrl.isDisabled()">
</schema-based-choices-editor>

<schema-based-bool-editor ng-if="schema().type === 'bool' && !schema().choices"
local-value="$parent.localValue" is-disabled="isDisabled()"
label-for-focus-target="labelForFocusTarget()">
<schema-based-bool-editor ng-if="$ctrl.schema().type === 'bool' && !$ctrl.schema().choices"
local-value="$ctrl.localValue" is-disabled="$ctrl.isDisabled()"
label-for-focus-target="$ctrl.labelForFocusTarget()">
</schema-based-bool-editor>

<schema-based-int-editor ng-if="schema().type === 'int' && !schema().choices"
local-value="$parent.localValue" is-disabled="isDisabled()"
validators="schema().validators"
label-for-focus-target="labelForFocusTarget()"
on-input-blur="onInputBlur"
on-input-focus="onInputFocus">
<schema-based-int-editor ng-if="$ctrl.schema().type === 'int' && !$ctrl.schema().choices"
local-value="$ctrl.localValue" is-disabled="$ctrl.isDisabled()"
validators="$ctrl.schema().validators"
label-for-focus-target="$ctrl.labelForFocusTarget()"
on-input-blur="$ctrl.onInputBlur"
on-input-focus="$ctrl.onInputFocus">
</schema-based-int-editor>

<schema-based-float-editor ng-if="schema().type === 'float' && !schema().choices"
local-value="$parent.localValue" is-disabled="isDisabled()"
validators="schema().validators"
label-for-focus-target="labelForFocusTarget()"
on-input-blur="onInputBlur"
on-input-focus="onInputFocus">
<schema-based-float-editor ng-if="$ctrl.schema().type === 'float' && !$ctrl.schema().choices"
local-value="$ctrl.localValue" is-disabled="$ctrl.isDisabled()"
validators="$ctrl.schema().validators"
label-for-focus-target="$ctrl.labelForFocusTarget()"
on-input-blur="$ctrl.onInputBlur"
on-input-focus="$ctrl.onInputFocus">
</schema-based-float-editor>

<schema-based-unicode-editor ng-if="schema().type === 'unicode' && !schema().choices"
local-value="$parent.localValue" is-disabled="isDisabled()"
validators="schema().validators" ui-config="schema().ui_config"
label-for-focus-target="labelForFocusTarget()"
on-input-blur="onInputBlur"
on-input-focus="onInputFocus">
<schema-based-unicode-editor ng-if="$ctrl.schema().type === 'unicode' && !$ctrl.schema().choices"
local-value="$ctrl.localValue" is-disabled="$ctrl.isDisabled()"
validators="$ctrl.schema().validators" ui-config="$ctrl.schema().ui_config"
label-for-focus-target="$ctrl.labelForFocusTarget()"
on-input-blur="$ctrl.onInputBlur"
on-input-focus="$ctrl.onInputFocus">
</schema-based-unicode-editor>

<schema-based-html-editor ng-if="schema().type === 'html' && !schema().choices"
local-value="$parent.localValue" is-disabled="isDisabled()"
label-for-focus-target="labelForFocusTarget()"
ui-config="schema().ui_config">
<schema-based-html-editor ng-if="$ctrl.schema().type === 'html' && !$ctrl.schema().choices"
local-value="$ctrl.localValue" is-disabled="$ctrl.isDisabled()"
label-for-focus-target="$ctrl.labelForFocusTarget()"
ui-config="$ctrl.schema().ui_config">
</schema-based-html-editor>

<schema-based-list-editor ng-if="schema().type === 'list' && !schema().choices"
local-value="$parent.localValue" is-disabled="isDisabled()"
item-schema="schema().items" len="schema().len"
ui-config="schema().ui_config" validators="schema().validators"
label-for-focus-target="labelForFocusTarget()">
<schema-based-list-editor ng-if="$ctrl.schema().type === 'list' && !$ctrl.schema().choices"
local-value="$ctrl.localValue" is-disabled="$ctrl.isDisabled()"
item-schema="$ctrl.schema().items" len="$ctrl.schema().len"
ui-config="$ctrl.schema().ui_config" validators="$ctrl.schema().validators"
label-for-focus-target="$ctrl.labelForFocusTarget()">
</schema-based-list-editor>

<schema-based-dict-editor ng-if="schema().type === 'dict' && !schema().choices"
local-value="$parent.localValue" is-disabled="isDisabled()"
property-schemas="schema().properties"
label-for-focus-target="labelForFocusTarget()">
<schema-based-dict-editor ng-if="$ctrl.schema().type === 'dict' && !$ctrl.schema().choices"
local-value="$ctrl.localValue" is-disabled="$ctrl.isDisabled()"
property-schemas="$ctrl.schema().properties"
label-for-focus-target="$ctrl.labelForFocusTarget()">
</schema-based-dict-editor>

<schema-based-custom-editor ng-if="schema().type === 'custom' && !schema().choices"
obj-type="schema().obj_type" local-value="$parent.localValue"
is-disabled="isDisabled()">
<schema-based-custom-editor ng-if="$ctrl.schema().type === 'custom' && !$ctrl.schema().choices"
obj-type="$ctrl.schema().obj_type" local-value="$ctrl.localValue"
is-disabled="$ctrl.isDisabled()">
</schema-based-custom-editor>
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ var oppia = require('AppInit.ts').module;
oppia.directive('schemaBasedEditor', [
'UrlInterpolationService', function(UrlInterpolationService) {
return {
scope: {
restrict: 'E',
scope: {},
bindToController: {
schema: '&',
isDisabled: '&',
localValue: '=',
Expand All @@ -61,6 +63,7 @@ oppia.directive('schemaBasedEditor', [
templateUrl: UrlInterpolationService.getDirectiveTemplateUrl(
'/components/forms/schema-based-editors/' +
'schema-based-editor.directive.html'),
restrict: 'E'
controllerAs: '$ctrl',
controller: [function() {}]
};
}]);
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<span ng-model="localValue" ui-validate="'validate($value)'">
<span ng-form="floatForm">
<span ng-model="$ctrl.localValue" ui-validate="'$ctrl.validate($value)'">
<span ng-form="$ctrl.floatForm">
<span ng-if="!expressionMode">
<input type="number" step="any" ng-model="$parent.localValue" class="form-control protractor-test-float-form-input"
name="floatValue" ng-attr-placeholder="<['I18N_FORMS_TYPE_NUMBER' | translate]>" ng-disabled="isDisabled()"
require-is-float apply-validation="validators()"
focus-on="<[labelForFocusTarget()]>" ng-keypress="onKeypress($event)"
ng-blur="onBlur()" ng-focus="onFocus()" style="display: inline;">
<input type="number" step="any" ng-model="$ctrl.localValue" class="form-control protractor-test-float-form-input"
name="floatValue" ng-attr-placeholder="<['I18N_FORMS_TYPE_NUMBER' | translate]>" ng-disabled="$ctrl.isDisabled()"
require-is-float apply-validation validators="$ctrl.validators()"
focus-on="<[$ctrl.labelForFocusTarget()]>" ng-keypress="$ctrl.onKeypress($event)"
ng-blur="$ctrl.onBlur()" ng-focus="$ctrl.onFocus()" style="display: inline;">

<span ng-if="hasLoaded && !isUserCurrentlyTyping && hasFocusedAtLeastOnce"
<span ng-if="$ctrl.hasLoaded && !$ctrl.isUserCurrentlyTyping && $ctrl.hasFocusedAtLeastOnce"
style="font-size: 0.85em; position: absolute;"
tabindex="-1" focus-on="<[labelForErrorFocusTarget]>">
<span ng-if="floatForm.floatValue.$error.isFloat && floatForm.floatValue.$viewValue" class="oppia-form-error" aria-live="assertive" translate="I18N_FORMS_TYPE_NUMBER_INVALID_DECIMAL"></span>
<span ng-if="!floatForm.floatValue.$error.isFloat && floatForm.floatValue.$error.isAtLeast"
tabindex="-1" focus-on="<[$ctrl.labelForErrorFocusTarget]>">
<span ng-if="$ctrl.floatForm.floatValue.$error.isFloat && $ctrl.floatForm.floatValue.$viewValue" class="oppia-form-error" aria-live="assertive" translate="I18N_FORMS_TYPE_NUMBER_INVALID_DECIMAL"></span>
<span ng-if="!$ctrl.floatForm.floatValue.$error.isFloat && $ctrl.floatForm.floatValue.$error.isAtLeast"
class="oppia-form-error" aria-live="assertive" translate="I18N_FORMS_TYPE_NUMBER_AT_LEAST" translate-values="{minValue: <[minValue]>}">
</span>
<span ng-if="!floatForm.floatValue.$error.isFloat && floatForm.floatValue.$error.isAtMost"
<span ng-if="!$ctrl.floatForm.floatValue.$error.isFloat && $ctrl.floatForm.floatValue.$error.isAtMost"
class="oppia-form-error" aria-live="assertive" translate="I18N_FORMS_TYPE_NUMBER_AT_MOST" translate-values="{maxValue: <[maxValue]>}">
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ var oppia = require('AppInit.ts').module;
oppia.directive('schemaBasedFloatEditor', [
'UrlInterpolationService', function(UrlInterpolationService) {
return {
scope: {
restrict: 'E',
scope: {},
bindToController: {
localValue: '=',
isDisabled: '&',
validators: '&',
Expand All @@ -36,74 +38,75 @@ oppia.directive('schemaBasedFloatEditor', [
templateUrl: UrlInterpolationService.getDirectiveTemplateUrl(
'/components/forms/schema-based-editors/' +
'schema-based-float-editor.directive.html'),
restrict: 'E',
controllerAs: '$ctrl',
controller: [
'$scope', '$filter', '$timeout', 'FocusManagerService',
function($scope, $filter, $timeout, FocusManagerService) {
$scope.hasLoaded = false;
$scope.isUserCurrentlyTyping = false;
$scope.hasFocusedAtLeastOnce = false;
var ctrl = this;
ctrl.hasLoaded = false;
ctrl.isUserCurrentlyTyping = false;
ctrl.hasFocusedAtLeastOnce = false;

$scope.labelForErrorFocusTarget =
ctrl.labelForErrorFocusTarget =
FocusManagerService.generateFocusLabel();

$scope.validate = function(localValue) {
ctrl.validate = function(localValue) {
return $filter('isFloat')(localValue) !== undefined;
};

$scope.onFocus = function() {
$scope.hasFocusedAtLeastOnce = true;
if ($scope.onInputFocus) {
$scope.onInputFocus();
ctrl.onFocus = function() {
ctrl.hasFocusedAtLeastOnce = true;
if (ctrl.onInputFocus) {
ctrl.onInputFocus();
}
};

$scope.onBlur = function() {
$scope.isUserCurrentlyTyping = false;
if ($scope.onInputBlur) {
$scope.onInputBlur();
ctrl.onBlur = function() {
ctrl.isUserCurrentlyTyping = false;
if (ctrl.onInputBlur) {
ctrl.onInputBlur();
}
};

// TODO(sll): Move these to ng-messages when we move to Angular 1.3.
$scope.getMinValue = function() {
for (var i = 0; i < $scope.validators().length; i++) {
if ($scope.validators()[i].id === 'is_at_least') {
return $scope.validators()[i].min_value;
ctrl.getMinValue = function() {
for (var i = 0; i < ctrl.validators().length; i++) {
if (ctrl.validators()[i].id === 'is_at_least') {
return ctrl.validators()[i].min_value;
}
}
};

$scope.getMaxValue = function() {
for (var i = 0; i < $scope.validators().length; i++) {
if ($scope.validators()[i].id === 'is_at_most') {
return $scope.validators()[i].max_value;
ctrl.getMaxValue = function() {
for (var i = 0; i < ctrl.validators().length; i++) {
if (ctrl.validators()[i].id === 'is_at_most') {
return ctrl.validators()[i].max_value;
}
}
};

$scope.onKeypress = function(evt) {
ctrl.onKeypress = function(evt) {
if (evt.keyCode === 13) {
if (
Object.keys($scope.floatForm.floatValue.$error).length !== 0) {
$scope.isUserCurrentlyTyping = false;
FocusManagerService.setFocus($scope.labelForErrorFocusTarget);
Object.keys(ctrl.floatForm.floatValue.$error).length !== 0) {
ctrl.isUserCurrentlyTyping = false;
FocusManagerService.setFocus(ctrl.labelForErrorFocusTarget);
} else {
$scope.$emit('submittedSchemaBasedFloatForm');
}
} else {
$scope.isUserCurrentlyTyping = true;
ctrl.isUserCurrentlyTyping = true;
}
};

if ($scope.localValue === undefined) {
$scope.localValue = 0.0;
if (ctrl.localValue === undefined) {
ctrl.localValue = 0.0;
}

// This prevents the red 'invalid input' warning message from flashing
// at the outset.
$timeout(function() {
$scope.hasLoaded = true;
ctrl.hasLoaded = true;
});
}
]
Expand Down
Loading

0 comments on commit 3316974

Please sign in to comment.