Repository: oppia/oppia

Issue:
Separate inline controllers from $uibModal.open method in new files.
<!--
  - Thanks for taking the time to propose a new feature for the Oppia project.
  - Before filing a new issue, please do a quick search to check that it hasn't
  - already been filed on the [issue tracker](https://github.com/oppia/oppia/issues)._
  -->
**Is your feature request related to a problem? Please describe.**
Some AngularJS files like controllers, directives, and services use $uibModal.open method from Angular UI Bootstrap library:
![image](https://user-images.githubusercontent.com/34922478/80324438-3004f000-8807-11ea-9453-9bb55f7b1235.png)

In almost all files, the controller property from the object passed as parameter is declared as an inline controller, instead of referencing the controller name, e.g.:
![image](https://user-images.githubusercontent.com/34922478/80324479-4743dd80-8807-11ea-8524-f9d60ffb581b.png)

An inline controller makes hard to test the file itself since there isn't any solution for covering it and properly testing it with unit tests. Also, using an inline controller instead of referencing an existed one difficulty the calculation of controllers unit test coverage, since the number of controllers is not precise.

**Describe the solution you'd like**
The first thing to be done is to create a generic modal and replace it or inherit it in all common and similar inline modals that use close or dismiss actions only, then the code will be reused often. (Fixed in #9167).
After that, the main solution is to replace all the inline controllers by separating controllers in its own file, as you can see in the following PRs: #8805, #8799, #8791, #8775 
**Describe alternatives you've considered**
You can follow this example:
![Screenshot from 2020-04-26 21-57-42](https://user-images.githubusercontent.com/34922478/80325183-89bae980-880a-11ea-8c43-564312ce105e.png)
![Screenshot from 2020-04-26 22-08-36](https://user-images.githubusercontent.com/34922478/80325188-8c1d4380-880a-11ea-9f0b-735d4f48e1b2.png)
When inline controller uses variables from the external scope (from the file itself or the function where is being called), resolve property must be used to pass these variables as local in the new controller:
![Screenshot from 2020-04-26 22-09-49](https://user-images.githubusercontent.com/34922478/80325235-ac4d0280-880a-11ea-81b5-bc82351dbd4f.png)

For the **name convention of the file** all the inline controllers must follow the file name of templateUrl property value in `$uibModal.open` method but the extension should be `.controller.t`s instead of `.html`.

**List of files where calls $uibModal.open method**
- [ ] create-activity-button.directive.ts
- [ ] exploration-embed-button.service.ts
- [ ] exploration-creation.service.ts
- [ ] story-creation.service.ts
- [ ] topic-creation.service.ts
- [ ] thumbnail-uploader.directive.ts
- [ ] question-player.directive.ts
- [ ] questions-list.directive.ts
- [ ] skills-mastery-list.directive.ts
- [ ] answer-group-editor.directive.ts
- [ ] state-hints-editor.directive.ts
- [ ] state-interaction-editor.directive.ts
- [ ] state-responses.directive.ts
- [ ] state-solution-editor.directive.ts
- [ ] version-diff-visualization.directive.ts
- [ ] collection-editor-navbar.directive.ts
- [ ] contributions-and-review.directive.ts
- [ ] question-opportunities.directive.ts
- [ ] translation-opportunities.directive.ts
- [ ] delete-account-page.controller.ts
- [ ] exploration-editor-page.controller.ts
- [ ] editor-navigation.directive.ts
- [ ] exploration-graph.directive.ts
- [ ] unresolved-answers-overview.directive.ts
- [ ] feedback-tab.directive.ts
- [ ] history-tab.directive.ts
- [ ] preview-tab.directive.ts
- [ ] exploration-save.service.ts
- [ ] exploration-states.service.ts
- [ ] settings-tab.directive.ts
- [ ] statistics-tab.directive.ts
- [ ] suggestion-modal-for-exploration-editor.service.ts
- [ ] translation-tab.directive.ts
- [ ] audio-translation-bar.directive.ts
- [ ] state-translation-editor.directive.ts
- [ ] learner-local-nav.directive.ts
- [ ] learner-view-info.directive.ts
- [ ] fatigue-detection.service.ts
- [ ] hint-and-solution-modal.service.ts
- [ ] refresher-exploration-confirmation-modal.service.ts
- [ ] suggestion-modal-for-exploration-player.service.ts
- [ ] learner-dashboard-page.controller.ts
- [ ] suggestion-modal-for-learner-dashboard.service.ts
- [ ] preferences-page.controller.ts
- [ ] signup-page.controller.ts
- [ ] skill-concept-card-editor.directive.ts
- [ ] skill-misconceptions-editor.directive.ts
- [ ] skill-prerequisite-skills-editor.directive.ts
- [ ] skill-editor-navbar.directive.ts
- [ ] story-editor-page.controller.ts
- [ ] story-editor.directive.ts
- [ ] story-node-editor.directive.ts
- [ ] story-editor-navbar-breadcrumb.directive.ts
- [ ] story-editor-navbar.directive.ts
- [ ] topic-editor-stories-list.directive.ts
- [ ] topic-editor-tab.directive.ts
- [ ] topic-editor-navbar.directive.ts
- [ ] subtopics-list-tab.directive.ts
- [ ] topics-and-skills-dashboard-page.controller.ts
- [ ] topics-and-skills-dashboard-navbar.directive.ts
- [ ] skills-list.directive.ts
- [ ] topics-list.directive.ts.






Discussion:
Hey, @marianazangrossi I believe this is a pretty huge and comparatively easy task and an eligible good first issue, can you please take a look at this [doc here](https://docs.google.com/document/d/1m4kuLYhDJYTReJHCr-kY866OoHCO4WmBRFTmbU45k-c/edit) and update the issue description accordingly? Let me know if you need some help or clarity. And I believe this falls in the category one(you'll know what's this once you go through the doc).
Hi @Showtim3, I'm a GSoC application for testing directives and controllers project and while I was studying about the codebase I've created this issue. However, it's part of my proposal. Even if I get reject in GSoC, I think it's an important thing to do in the codebase. Is there a problem to keep this issue open until GSoC results? Please let me know what is the best solution. Thanks!
I think you don't need to keep this open until GSoC -- we should just do it anyway, since it's a generally important codebase issue. Maybe let's discuss it when we meet?
Sure. But when we meet, the GSoC deadline will be reached already. If we work on it alright, some part of my proposal will be already done when result be announced (if I get approved).
Update: @marianazangrossi and I chatted about this, and she's going to work on it for the moment. Let's not make it a general starter issue yet -- it's actually a bit more complicated than it looks at first glance, because she's planning to do some consolidation of the existing modals so that we don't have 30 separate modals doing basically the same thing. She'll post back on this thread once the project is in a good state for multiple people to work on simultaneously.

Thanks!
Hi @seanlip and @Showtim3, I've done the consolidation of the similar modals (as you can see in the PR above). Also, I've updated the main comment with new instructions. I was thinking to let people work on the list I've created only after the PR is merged. What do you think?
> I was thinking to let people work on the list I've created only after the PR is merged. What do you think?

I think that sounds totally fine -- thanks, @marianazangrossi! 
**Notes:**
This issue is being fixed by @marianazangrossi, you can checkout the related PR in the thread below

Resolving patch:
diff --git a/scripts/check_frontend_coverage.py b/scripts/check_frontend_coverage.py
--- a/scripts/check_frontend_coverage.py
+++ b/scripts/check_frontend_coverage.py
@@ -36,8 +36,11 @@
     'about-page.module.ts',
     'activity-tiles-infinity-grid.directive.ts',
     'add-answer-group-modal.controller.ts',
+    'add-audio-translation-modal.controller.ts',
     'add-hint-modal.controller.ts',
+    'add-misconception-modal.controller.ts',
     'add-or-update-solution-modal.controller.ts',
+    'add-worked-example-modal.controller.ts',
     'admin-config-tab.directive.ts',
     'admin-dev-mode-activities-tab.directive.ts',
     'admin-jobs-tab.directive.ts',
@@ -53,6 +56,7 @@
     'answer-group-editor.directive.ts',
     'answer-submit-action.directive.ts',
     'App.ts',
+    'assign-skill-to-topic-modal.controller.ts',
     'attribution-guide.directive.ts',
     'audio-bar.directive.ts',
     'audio-file-uploader.directive.ts',
@@ -128,11 +132,15 @@
     'customize-interaction-modal.controller.ts',
     'cyclic-transitions-issue.directive.ts',
     'delete-account-page.component.ts',
+    'delete-misconception-modal.controller.ts',
+    'display-hint-modal.controller.ts',
+    'display-solution-modal.controller.ts',
     'donate-page.component.ts',
     'drag-and-drop-html-string-editor.directive.ts',
     'drag-and-drop-positive-int-editor.directive.ts',
     'drag-and-drop-sort-input-validation.service.ts',
     'early-quit-issue.directive.ts',
+    'edit-profile-picture-modal.controller.ts',
     'edit-thumbnail-modal.controller.ts',
     'editable-collection-backend-api.service.ts',
     'editable-story-backend-api.service.ts',
@@ -157,6 +165,7 @@
     'exploration-objective-editor.directive.ts',
     'exploration-player-page.controller.ts',
     'exploration-player-state.service.ts',
+    'exploration-player-suggestion-modal.controller.ts',
     'exploration-recommendations.service.ts',
     'exploration-save-and-publish-buttons.directive.ts',
     'exploration-save-modal.controller.ts',
@@ -173,6 +182,7 @@
     'feedback-tab.directive.ts',
     'FeedbackThreadSummaryObjectFactory.ts',
     'filepath-editor.directive.ts',
+    'flag-exploration-modal.controller.ts',
     'focus-on.directive.ts',
     'format-timer.filter.ts',
     'fraction-editor.directive.ts',
@@ -199,6 +209,7 @@
     'image-uploader.directive.ts',
     'image-with-regions-editor.directive.ts',
     'improvements-tab.directive.ts',
+    'information-card-modal.controller.ts',
     'input-response-pair.directive.ts',
     'int-editor.directive.ts',
     'item-selection-input-validation.service.ts',
@@ -208,11 +219,13 @@
     'learner-answer-info.service.ts',
     'learner-dashboard-icons.directive.ts',
     'learner-dashboard-page.controller.ts',
+    'learner-dashboard-suggestion-modal.controller.ts',
     'learner-local-nav.directive.ts',
     'learner-view-info.directive.ts',
     'learner-view-rating.service.ts',
     'library-footer.directive.ts',
     'library-page.directive.ts',
+    'license-explanation-modal.controller.ts',
     'list-of-sets-of-html-strings-editor.directive.ts',
     'list-of-tabs-editor.directive.ts',
     'list-of-unicode-string-editor.directive.ts',
@@ -226,6 +239,7 @@
     'math-expression-input-validation.service.ts',
     'math-latex-string-editor.directive.ts',
     'mathjax-bind.directive.ts',
+    'merge-skill-modal.controller.ts',
     'messenger.service.ts',
     'misconception-editor.directive.ts',
     'moderator-unpublish-exploration-modal.controller.ts',
@@ -234,7 +248,9 @@
     'music-notes-input-rules.service.ts',
     'music-phrase-editor.directive.ts',
     'music-phrase-player.service.ts',
+    'new-chapter-title-modal.controller.ts',
     'new-story-title-editor-modal.controller.ts',
+    'new-subtopic-title-modal.controller.ts',
     'nonnegative-int-editor.directive.ts',
     'normalize-whitespace-punctuation-and-case.pipe.ts',
     'normalized-string-editor.directive.ts',
@@ -355,12 +371,16 @@
     'question-suggestion.service.ts',
     'question-update.service.ts',
     'questions-list-select-skill-and-difficulty-modal.controller.ts',
+    'questions-list-select-skill-modal.controller.ts',
     'questions-list.directive.ts',
     'random-selector.directive.ts',
     'rating-display.directive.ts',
     'read-only-collection-backend-api.service.ts',
     'real-editor.directive.ts',
+    'refresher-exploration-confirmation-modal.controller.ts',
     'refresher-exploration-confirmation-modal.service.ts',
+    'registration-session-expired-modal.controller.ts',
+    'remove-activity-from-learner-dashboard-modal.controller.ts',
     'remove-duplicates-in-array.pipe.ts',
     'request-interceptor.service.ts',
     'response-header.directive.ts',
@@ -465,6 +485,7 @@
     'StoryContentsObjectFactory.ts',
     'StoryNodeObjectFactory.ts',
     'student.ts',
+    'subtopic-editor-modal.controller.ts',
     'subtopic-summary-tile.directive.ts',
     'subtopic-viewer-navbar-breadcrumb.directive.ts',
     'subtopic-viewer-page.controller.ts',
@@ -492,6 +513,7 @@
     'topic-editor-navbar.directive.ts',
     'topic-editor-page.controller.ts',
     'topic-editor-routing.service.ts',
+    'topic-editor-save-modal.controller.ts',
     'topic-editor-state.service.ts',
     'topic-editor-stories-list.directive.ts',
     'topic-editor-tab.directive.ts',
@@ -505,12 +527,14 @@
     'topics-and-skills-dashboard-backend-api.service.ts',
     'topics-and-skills-dashboard-navbar-breadcrumb.directive.ts',
     'topics-and-skills-dashboard-navbar.directive.ts',
+    'topics-and-skills-dashboard-page.controller.ts',
     'training-panel.directive.ts',
     'translate-text.service.ts',
     'translation-file-hash-loader.service.ts',
     'translation-modal.controller.ts',
     'translation-opportunities.directive.ts',
     'translation-suggestion-review-modal.controller.ts',
+    'translation-tab-busy-modal.controller.ts',
     'translation-tab.directive.ts',
     'translator-overview.directive.ts',
     'truncate-and-capitalize.filter.ts',


Test patch: