<commit_before>/**
 * Detail controller
 */
(function () {

	'use strict';

	angular
		.module( 'com.missofis.ontheair' )
		.controller( 'DetailCtrl', DetailCtrl );

	DetailCtrl.$inject = [ '$log', 'TMDbTV', '$routeParams', 'OnTheAirFirebaseDatabase', 'OnTheAirUtils', '$scope', '$mdDialog', '$mdToast', '$location', '$rootScope', '_show', '$filter' ];

	/**
	 * Detail controller
	 */
	function DetailCtrl( $log, TMDbTV, $routeParams, OnTheAirFirebaseDatabase, OnTheAirUtils, $scope, $mdDialog, $mdToast, $location, $rootScope, _show, $filter ) {

		var vm = this;

		/*
		----------------------------------------------------------------
		Initiate public scope variables
		----------------------------------------------------------------
		*/
		
		// controller bindables
		vm.show = null;
		vm.appState = null;
		vm.favorited = false;
		vm.videoVisible = false;
		vm.video = null;
		vm.youtubePlayer = null;
		vm.pageLoading = true;

		// controller api
		vm.getShow = _getShow;
		vm.getVideos = _getVideos;
		vm.toggleFavorite = _toggleFavorite;
		vm.toggleVideo = _toggleVideo;

		// initialize controller
		_init();

		/*
		----------------------------------------------------------------
		Private API
		----------------------------------------------------------------
		*/

		// get show
		function _getShow() {			
			vm.show = _show; // resolved as _show at routing state, TMDbTV.get( { id: $routeParams.showId } );
		}

		// get show videos
		function _getVideos() {
			TMDbTV.get( { id: $routeParams.showId, endpoint: 'videos' } )
				.$promise
				.then( function( response ) {					
					vm.video = $filter( 'filter' )( response.results, 'Youtube' )[0];
					vm.pageLoading = false;
				} );
		}

		// toggle favorite
		function _toggleFavorite() {
			if( !vm.appState.user ) {
				$mdDialog
					.show( $mdDialog.confirm( {
						title: 'Uppsiee!',
						textContent: 'You should "login" to favorite content.',
						ok: 'Login',
						cancel: 'no thanks'
					} ) )
					.then( function() {
						$location.path( '/welcome' );
					}, function() {
						$mdToast.showSimple( 'Maybe later?' );
					} );
				return;
			}
			if( vm.favorited ) {
				OnTheAirFirebaseDatabase
					.unfavorite( vm.appState.user.uid, $routeParams.showId )
					.then( function() {
						delete vm.appState.user_favorites[ $routeParams.showId ];
						$scope.$apply( function() {
							vm.favorited = false;
						} );
						$rootScope.$apply();
					} );
			}
			else {
				OnTheAirFirebaseDatabase
					.favorite( vm.appState.user.uid, $routeParams.showId, vm.show.name )
					.then( function() {
						vm.appState.user_favorites[ $routeParams.showId ] = vm.show.name;
						$scope.$apply( function() {
							vm.favorited = true;<commit_msg>Fix first favorite fail bug<commit_after>/**
 * Detail controller
 */
(function () {

	'use strict';

	angular
		.module( 'com.missofis.ontheair' )
		.controller( 'DetailCtrl', DetailCtrl );

	DetailCtrl.$inject = [ '$log', 'TMDbTV', '$routeParams', 'OnTheAirFirebaseDatabase', 'OnTheAirUtils', '$scope', '$mdDialog', '$mdToast', '$location', '$rootScope', '_show', '$filter' ];

	/**
	 * Detail controller
	 */
	function DetailCtrl( $log, TMDbTV, $routeParams, OnTheAirFirebaseDatabase, OnTheAirUtils, $scope, $mdDialog, $mdToast, $location, $rootScope, _show, $filter ) {

		var vm = this;

		/*
		----------------------------------------------------------------
		Initiate public scope variables
		----------------------------------------------------------------
		*/
		
		// controller bindables
		vm.show = null;
		vm.appState = null;
		vm.favorited = false;
		vm.videoVisible = false;
		vm.video = null;
		vm.youtubePlayer = null;
		vm.pageLoading = true;

		// controller api
		vm.getShow = _getShow;
		vm.getVideos = _getVideos;
		vm.toggleFavorite = _toggleFavorite;
		vm.toggleVideo = _toggleVideo;

		// initialize controller
		_init();

		/*
		----------------------------------------------------------------
		Private API
		----------------------------------------------------------------
		*/

		// get show
		function _getShow() {			
			vm.show = _show; // resolved as _show at routing state, TMDbTV.get( { id: $routeParams.showId } );
		}

		// get show videos
		function _getVideos() {
			TMDbTV.get( { id: $routeParams.showId, endpoint: 'videos' } )
				.$promise
				.then( function( response ) {					
					vm.video = $filter( 'filter' )( response.results, 'Youtube' )[0];
					vm.pageLoading = false;
				} );
		}

		// toggle favorite
		function _toggleFavorite() {
			if( !vm.appState.user ) {
				$mdDialog
					.show( $mdDialog.confirm( {
						title: 'Uppsiee!',
						textContent: 'You should "login" to favorite content.',
						ok: 'Login',
						cancel: 'no thanks'
					} ) )
					.then( function() {
						$location.path( '/welcome' );
					}, function() {
						$mdToast.showSimple( 'Maybe later?' );
					} );
				return;
			}
			if( vm.favorited ) {
				OnTheAirFirebaseDatabase
					.unfavorite( vm.appState.user.uid, $routeParams.showId )
					.then( function() {
						delete vm.appState.user_favorites[ $routeParams.showId ];
						$scope.$apply( function() {
							vm.favorited = false;
						} );
						$rootScope.$apply();
					} );
			}
			else {
				OnTheAirFirebaseDatabase
					.favorite( vm.appState.user.uid, $routeParams.showId, vm.show.name )
					.then( function() {
						// todo :: check for another solution (initial app set is false, but service returns null. false set needed for $watchCollection below)
						if( null === vm.appState.user_favorites ) {
							vm.appState.user_favorites = {};
						}
						vm.appState.user_favorites[ $routeParams.showId ] = vm.show.name;
						$scope.$apply( function() {
							vm.favorited = true;
{'fraction_non_alphanumeric': 0.2276536312849162, 'fraction_numerical': 0.00034916201117318437, 'mean_word_length': 2.0232189973614774, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '115059', 'n_tokens_mistral': 2259, 'n_tokens_neox': 1792, 'n_words': 385}