forked from oppia/oppia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix oppia#5426: Lint check to ensure that each Angular file contains …
…exactly one service/directive/etc. inside it. (oppia#6202) * Check js file has only one property * Check js file has only one property * Check js file has only one property * Refactor extensions/ * Resolved conflicts * Fix errors * Fix errors * Fix errors * Lint errors * Lint errors * Fix errors * Fix errors * Fix errors * Fix errors * Fix errors * Fix base test * admin-roles-tab * Removed unneccessary scripts * Change string patterns * Fix lint errors * Fix e2e tests * Address review comments * Addressed comments * Addressed comments * Final reviews * Improve docstring * Improved docstring * addressed review comments * lint checks * Nit * Resolve conflicts * Minor nit * Resolve errors * Fix spaces * Fix spaces * Fix spaces * Fix spaces * Fix spaces
- Loading branch information
Showing
182 changed files
with
1,884 additions
and
1,221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
61 changes: 61 additions & 0 deletions
61
core/templates/dev/head/components/forms/ApplyValidationDirective.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2019 The Oppia Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS-IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @fileoverview Directive for applying validation. | ||
*/ | ||
|
||
/* eslint-disable angular/directive-restrict */ | ||
oppia.directive('applyValidation', ['$filter', function($filter) { | ||
return { | ||
require: 'ngModel', | ||
restrict: 'A', | ||
link: function(scope, elm, attrs, ctrl) { | ||
// Add validators in reverse order. | ||
if (scope.validators()) { | ||
scope.validators().forEach(function(validatorSpec) { | ||
var frontendName = $filter('underscoresToCamelCase')( | ||
validatorSpec.id); | ||
|
||
// Note that there may not be a corresponding frontend filter for | ||
// each backend validator. | ||
try { | ||
$filter(frontendName); | ||
} catch (err) { | ||
return; | ||
} | ||
|
||
var filterArgs = {}; | ||
for (var key in validatorSpec) { | ||
if (key !== 'id') { | ||
filterArgs[$filter('underscoresToCamelCase')(key)] = | ||
angular.copy(validatorSpec[key]); | ||
} | ||
} | ||
|
||
var customValidator = function(viewValue) { | ||
ctrl.$setValidity( | ||
frontendName, $filter(frontendName)(viewValue, | ||
filterArgs)); | ||
return viewValue; | ||
}; | ||
|
||
ctrl.$parsers.unshift(customValidator); | ||
ctrl.$formatters.unshift(customValidator); | ||
}); | ||
} | ||
} | ||
}; | ||
}]); | ||
/* eslint-enable angular/directive-restrict */ |
23 changes: 23 additions & 0 deletions
23
core/templates/dev/head/components/forms/ConvertHtmlToUnicodeFilter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2019 The Oppia Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS-IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @fileoverview Converts HTML to unicode. | ||
*/ | ||
|
||
oppia.filter('convertHtmlToUnicode', [function() { | ||
return function(html) { | ||
return angular.element('<div>' + html + '</div>').text(); | ||
}; | ||
}]); |
26 changes: 26 additions & 0 deletions
26
core/templates/dev/head/components/forms/ConvertUnicodeToHtmlFilter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2019 The Oppia Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS-IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @fileoverview Converts unicode to HTML. | ||
*/ | ||
|
||
oppia.filter('convertUnicodeToHtml', [ | ||
'$sanitize', 'HtmlEscaperService', | ||
function($sanitize, HtmlEscaperService) { | ||
return function(text) { | ||
return $sanitize(HtmlEscaperService.unescapedStrToEscapedStr(text)); | ||
}; | ||
} | ||
]); |
95 changes: 95 additions & 0 deletions
95
core/templates/dev/head/components/forms/ConvertUnicodeWithParamsToHtmlFilter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright 2019 The Oppia Authors. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS-IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/** | ||
* @fileoverview Converts {{name}} substrings to | ||
* <oppia-parameter>name</oppia-parameter> tags and unescapes the | ||
* {, } and \ characters. This is done by reading the given string from | ||
* left to right: if we see a backslash, we use the following character; | ||
* if we see a '{{', this is the start of a parameter; if we see a '}}'; | ||
* this is the end of a parameter. | ||
*/ | ||
|
||
oppia.filter('convertUnicodeWithParamsToHtml', ['$filter', function($filter) { | ||
var assert = function(text) { | ||
if (!text) { | ||
throw 'Invalid unicode-string-with-parameters: ' + text; | ||
} | ||
}; | ||
|
||
return function(text) { | ||
// The parsing here needs to be done with more care because we are replacing | ||
// two-character strings. We can't naively break by {{ because in strings | ||
// like \{{{ the second and third characters will be taken as the opening | ||
// brackets, which is wrong. We can't unescape characters because then the | ||
// { characters that remain will be ambiguous (they may either be the | ||
// openings of parameters or literal '{' characters entered by the user. | ||
// So we build a standard left-to-right parser which examines each | ||
// character of the string in turn, and processes it accordingly. | ||
var textFragments = []; | ||
var currentFragment = ''; | ||
var currentFragmentIsParam = false; | ||
for (var i = 0; i < text.length; i++) { | ||
if (text[i] === '\\') { | ||
assert(!currentFragmentIsParam && text.length > i + 1 && { | ||
'{': true, | ||
'}': true, | ||
'\\': true | ||
}[text[i + 1]]); | ||
currentFragment += text[i + 1]; | ||
i++; | ||
} else if (text[i] === '{') { | ||
assert( | ||
text.length > i + 1 && !currentFragmentIsParam && | ||
text[i + 1] === '{'); | ||
textFragments.push({ | ||
type: 'text', | ||
data: currentFragment | ||
}); | ||
currentFragment = ''; | ||
currentFragmentIsParam = true; | ||
i++; | ||
} else if (text[i] === '}') { | ||
assert( | ||
text.length > i + 1 && currentFragmentIsParam && | ||
text[i + 1] === '}'); | ||
textFragments.push({ | ||
type: 'parameter', | ||
data: currentFragment | ||
}); | ||
currentFragment = ''; | ||
currentFragmentIsParam = false; | ||
i++; | ||
} else { | ||
currentFragment += text[i]; | ||
} | ||
} | ||
|
||
assert(!currentFragmentIsParam); | ||
textFragments.push({ | ||
type: 'text', | ||
data: currentFragment | ||
}); | ||
|
||
var result = ''; | ||
textFragments.forEach(function(fragment) { | ||
result += ( | ||
fragment.type === 'text' ? | ||
$filter('convertUnicodeToHtml')(fragment.data) : | ||
'<oppia-parameter>' + fragment.data + | ||
'</oppia-parameter>'); | ||
}); | ||
return result; | ||
}; | ||
}]); |
Oops, something went wrong.