<commit_before>// Copyright 2017 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 Controller for the Tutor Card.
 */

require('directives/angular-html-bind.directive.ts');
require(
  'pages/exploration-player-page/layout-directives/audio-bar.component.ts');
require(
  'pages/exploration-player-page/learner-experience/' +
  'input-response-pair.component.ts');

require('domain/utilities/url-interpolation.service.ts');
require('pages/exploration-player-page/services/audio-preloader.service.ts');
require(
  'pages/exploration-player-page/services/' +
  'audio-translation-manager.service.ts');
require(
  'pages/exploration-player-page/services/current-interaction.service.ts');
require('pages/exploration-player-page/services/exploration-engine.service.ts');
require(
  'pages/exploration-player-page/services/exploration-player-state.service.ts');
require(
  'pages/exploration-player-page/services/learner-answer-info.service.ts');
require('pages/exploration-player-page/exploration-player-page.constants.ts');
require('pages/exploration-player-page/services/player-position.service.ts');
require('services/audio-bar-status.service.ts');
require('services/audio-player.service.ts');
require('services/autogenerated-audio-player.service.ts');
require('services/context.service.ts');
require('services/user.service.ts');
require('services/contextual/device-info.service.ts');
require('services/contextual/url.service.ts');
require('services/contextual/window-dimensions.service.ts');

require(
  // eslint-disable-next-line max-len
  'pages/exploration-player-page/layout-directives/content-language-selector.component.ts');
require(
  'pages/exploration-player-page/exploration-player-page.constants.ajs.ts');
require('pages/interaction-specs.constants.ajs.ts');

import { Subscription } from 'rxjs';

angular.module('oppia').animation(
  '.conversation-skin-responses-animate-slide', function() {
    return {
      removeClass: function(element, className, done) {
        if (className !== 'ng-hide') {
          done();
          return;
        }
        element.hide().slideDown(400, <(this: HTMLElement) => void>done);
      },
      addClass: function(element, className, done) {
        if (className !== 'ng-hide') {
          done();
          return;
        }
        element.slideUp(400, <(this: HTMLElement) => void>done);
      }
    };
  });

angular.module('oppia').directive('tutorCard', [
  'UrlInterpolationService', function(UrlInterpolationService) {
    return {
      restrict: 'E',
      scope: {
        isLearnAgainButton: '&',
        onDismiss: '&',
        getDisplayedCard: '&displayedCard',
        startCardChangeAnimation: '=',
        isAvatarImageShown: '&avatarImageIsShown'
      },
      template: require('./tutor-card.directive.html'),
      controller: [
        '$anchorScroll', '$location', '$rootScope', '$scope',
        'AudioBarStatusService', 'AudioPlayerService', 'AudioPreloaderService',
        'AudioTranslationManagerService', 'AutogeneratedAudioPlayerService',
        'ContextService', 'CurrentInteractionService', 'DeviceInfoService',
        'ExplorationPlayerStateService', 'LearnerAnswerInfoService',
        'PlayerPositionService', 'UrlService', 'UserService',
        'WindowDimensionsService', 'AUDIO_HIGHLIGHT_CSS_CLASS',
        'COMPONENT_NAME_CONTENT', 'CONTENT_FOCUS_LABEL_PREFIX',
        'DEFAULT_PROFILE_IMAGE_PATH', 'OPPIA_AVATAR_LINK_URL',
        'TWO_CARD_THRESHOLD_PX',
        function(
            $anchorScroll, $location, $rootScope, $scope,
            AudioBarStatusService, AudioPlayerService, AudioPreloaderService,
            AudioTranslationManagerService, AutogeneratedAudioPlayerService,
            ContextService, CurrentInteractionService, DeviceInfoService,
            ExplorationPlayerStateService, LearnerAnswerInfoService,
            PlayerPositionService, UrlService, UserService,
            WindowDimensionsService, AUDIO_HIGHLIGHT_CSS_CLASS,
            COMPONENT_NAME_CONTENT, CONTENT_FOCUS_LABEL_PREFIX,
            DEFAULT_PROFILE_IMAGE_PATH, OPPIA_AVATAR_LINK_URL,
            TWO_CARD_THRESHOLD_PX) {
          var ctrl = this;
          ctrl.directiveSubscriptions = new Subscription();
          var updateDisplayedCard = function() {
            $scope.arePreviousResponsesShown = false;
            $scope.lastAnswer = null;
            $scope.conceptCardIsBeingShown = Boolean(
              !$scope.getDisplayedCard().getInteraction());
            $scope.interactionIsActive =
              !$scope.getDisplayedCard().isCompleted();
            ctrl.directiveSubscriptions.add(
              PlayerPositionService.onNewCardAvailable.subscribe(
                (data) => $scope.interactionIsActive = false
              )
            );
            CurrentInteractionService.registerPresubmitHook(function() {
              $scope.waitingForOppiaFeedback = true;
            });
            if (!$scope.interactionIsActive) {
              $scope.lastAnswer = $scope.getDisplayedCard().getLastAnswer();
            }
            if (!$scope.conceptCardIsBeingShown) {
              $scope.interactionInstructions = (
                $scope.getDisplayedCard().getInteractionInstructions());
              $scope.contentAudioTranslations = (
                $scope.getDisplayedCard().getVoiceovers());
              AudioTranslationManagerService
                .clearSecondaryAudioTranslations();
              AudioTranslationManagerService.setContentAudioTranslations(
                angular.copy($scope.contentAudioTranslations),
                $scope.getDisplayedCard().getContentHtml(),
                COMPONENT_NAME_CONTENT);
              AudioPlayerService.stop();
              AudioPreloaderService.clearMostRecentlyRequestedAudioFilename();
              AutogeneratedAudioPlayerService.cancel();
            }
          };

          $scope.isInteractionInline = function() {
            if ($scope.conceptCardIsBeingShown) {
              return true;
            }
            return $scope.getDisplayedCard().isInteractionInline();
          };

          $scope.getContentAudioHighlightClass = function() {
            if (AudioTranslationManagerService
              .getCurrentComponentName() ===
              COMPONENT_NAME_CONTENT &&
              (AudioPlayerService.isPlaying() ||
              AutogeneratedAudioPlayerService.isPlaying())) {
              return AUDIO_HIGHLIGHT_CSS_CLASS;
            }<commit_msg>Clear currently played audio track when the card changes (#13430)<commit_after>// Copyright 2017 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 Controller for the Tutor Card.
 */

require('directives/angular-html-bind.directive.ts');
require(
  'pages/exploration-player-page/layout-directives/audio-bar.component.ts');
require(
  'pages/exploration-player-page/learner-experience/' +
  'input-response-pair.component.ts');

require('domain/utilities/url-interpolation.service.ts');
require('pages/exploration-player-page/services/audio-preloader.service.ts');
require(
  'pages/exploration-player-page/services/' +
  'audio-translation-manager.service.ts');
require(
  'pages/exploration-player-page/services/current-interaction.service.ts');
require('pages/exploration-player-page/services/exploration-engine.service.ts');
require(
  'pages/exploration-player-page/services/exploration-player-state.service.ts');
require(
  'pages/exploration-player-page/services/learner-answer-info.service.ts');
require('pages/exploration-player-page/exploration-player-page.constants.ts');
require('pages/exploration-player-page/services/player-position.service.ts');
require('services/audio-bar-status.service.ts');
require('services/audio-player.service.ts');
require('services/autogenerated-audio-player.service.ts');
require('services/context.service.ts');
require('services/user.service.ts');
require('services/contextual/device-info.service.ts');
require('services/contextual/url.service.ts');
require('services/contextual/window-dimensions.service.ts');

require(
  // eslint-disable-next-line max-len
  'pages/exploration-player-page/layout-directives/content-language-selector.component.ts');
require(
  'pages/exploration-player-page/exploration-player-page.constants.ajs.ts');
require('pages/interaction-specs.constants.ajs.ts');

import { Subscription } from 'rxjs';

angular.module('oppia').animation(
  '.conversation-skin-responses-animate-slide', function() {
    return {
      removeClass: function(element, className, done) {
        if (className !== 'ng-hide') {
          done();
          return;
        }
        element.hide().slideDown(400, <(this: HTMLElement) => void>done);
      },
      addClass: function(element, className, done) {
        if (className !== 'ng-hide') {
          done();
          return;
        }
        element.slideUp(400, <(this: HTMLElement) => void>done);
      }
    };
  });

angular.module('oppia').directive('tutorCard', [
  'UrlInterpolationService', function(UrlInterpolationService) {
    return {
      restrict: 'E',
      scope: {
        isLearnAgainButton: '&',
        onDismiss: '&',
        getDisplayedCard: '&displayedCard',
        startCardChangeAnimation: '=',
        isAvatarImageShown: '&avatarImageIsShown'
      },
      template: require('./tutor-card.directive.html'),
      controller: [
        '$anchorScroll', '$location', '$rootScope', '$scope',
        'AudioBarStatusService', 'AudioPlayerService', 'AudioPreloaderService',
        'AudioTranslationManagerService', 'AutogeneratedAudioPlayerService',
        'ContextService', 'CurrentInteractionService', 'DeviceInfoService',
        'ExplorationPlayerStateService', 'LearnerAnswerInfoService',
        'PlayerPositionService', 'UrlService', 'UserService',
        'WindowDimensionsService', 'AUDIO_HIGHLIGHT_CSS_CLASS',
        'COMPONENT_NAME_CONTENT', 'CONTENT_FOCUS_LABEL_PREFIX',
        'DEFAULT_PROFILE_IMAGE_PATH', 'OPPIA_AVATAR_LINK_URL',
        'TWO_CARD_THRESHOLD_PX',
        function(
            $anchorScroll, $location, $rootScope, $scope,
            AudioBarStatusService, AudioPlayerService, AudioPreloaderService,
            AudioTranslationManagerService, AutogeneratedAudioPlayerService,
            ContextService, CurrentInteractionService, DeviceInfoService,
            ExplorationPlayerStateService, LearnerAnswerInfoService,
            PlayerPositionService, UrlService, UserService,
            WindowDimensionsService, AUDIO_HIGHLIGHT_CSS_CLASS,
            COMPONENT_NAME_CONTENT, CONTENT_FOCUS_LABEL_PREFIX,
            DEFAULT_PROFILE_IMAGE_PATH, OPPIA_AVATAR_LINK_URL,
            TWO_CARD_THRESHOLD_PX) {
          var ctrl = this;
          ctrl.directiveSubscriptions = new Subscription();
          var updateDisplayedCard = function() {
            $scope.arePreviousResponsesShown = false;
            $scope.lastAnswer = null;
            $scope.conceptCardIsBeingShown = Boolean(
              !$scope.getDisplayedCard().getInteraction());
            $scope.interactionIsActive =
              !$scope.getDisplayedCard().isCompleted();
            ctrl.directiveSubscriptions.add(
              PlayerPositionService.onNewCardAvailable.subscribe(
                (data) => $scope.interactionIsActive = false
              )
            );
            CurrentInteractionService.registerPresubmitHook(function() {
              $scope.waitingForOppiaFeedback = true;
            });
            if (!$scope.interactionIsActive) {
              $scope.lastAnswer = $scope.getDisplayedCard().getLastAnswer();
            }
            if (!$scope.conceptCardIsBeingShown) {
              $scope.interactionInstructions = (
                $scope.getDisplayedCard().getInteractionInstructions());
              $scope.contentAudioTranslations = (
                $scope.getDisplayedCard().getVoiceovers());
              AudioTranslationManagerService
                .clearSecondaryAudioTranslations();
              AudioTranslationManagerService.setContentAudioTranslations(
                angular.copy($scope.contentAudioTranslations),
                $scope.getDisplayedCard().getContentHtml(),
                COMPONENT_NAME_CONTENT);
              AudioPlayerService.clear();
              AudioPreloaderService.clearMostRecentlyRequestedAudioFilename();
              AutogeneratedAudioPlayerService.cancel();
            }
          };

          $scope.isInteractionInline = function() {
            if ($scope.conceptCardIsBeingShown) {
              return true;
            }
            return $scope.getDisplayedCard().isInteractionInline();
          };

          $scope.getContentAudioHighlightClass = function() {
            if (AudioTranslationManagerService
              .getCurrentComponentName() ===
              COMPONENT_NAME_CONTENT &&
              (AudioPlayerService.isPlaying() ||
              AutogeneratedAudioPlayerService.isPlaying())) {
              return AUDIO_HIGHLIGHT_CSS_CLASS;
            }
{'fraction_non_alphanumeric': 0.11705969832164861, 'fraction_numerical': 0.0023369449755683024, 'mean_word_length': 3.053386911595867, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '987065', 'n_tokens_mistral': 3885, 'n_tokens_neox': 3814, 'n_words': 589}