<commit_before>define [
	"base"
], (App) ->
	App.factory "queuedHttp", ["$http", "$q", ($http, $q) ->
		pendingRequests = []
		inflight = false

		processPendingRequests = () ->
			return if inflight
			doRequest = pendingRequests.shift()
			if doRequest?
				inflight = true
				doRequest()
					.success () ->
						inflight = false
						processPendingRequests()
					.error () ->
						inflight = false
						processPendingRequests()

		queuedHttp = (args...) ->
			deferred = $q.defer()
			promise = deferred.promise

			# Adhere to the $http promise conventions
			promise.success = (callback) ->
				promise.then(callback)
				return promise

			promise.error = (callback) ->
				promise.catch(callback)
				return promise

			doRequest = () ->
				$http(args...)
					.success (successArgs...) ->
						deferred.resolve(successArgs...)
					.error (errorArgs...) ->
						deferred.reject(errorArgs...)

			pendingRequests.push doRequest
			processPendingRequests()

			return promise

		queuedHttp.post = (url, data) ->
			queuedHttp({method: "POST", url: url, data: data})

		return queuedHttp

	]

	App.controller "ProjectPageController", ($scope, $modal, $q, $window, queuedHttp, event_tracking) ->
		$scope.projects = window.data.projects
		$scope.tags = window.data.tags
		$scope.allSelected = false
		$scope.selectedProjects = []
		$scope.filter = "all"
		$scope.predicate = "lastUpdated"
		$scope.reverse = true

		recalculateProjectListHeight = () ->
			topOffset = $(".project-list-card").offset().top
			bottomOffset = $("footer").outerHeight() + 25
			sideBarHeight = $("aside").height() - 56
			# When footer is visible and page doesn't need to scroll we just make it
			# span between header and footer
			height = $window.innerHeight - topOffset - bottomOffset
			
			# When page is small enough that this pushes the project list smaller than
			# the side bar, then the window going to have to scroll to take into account the
			# footer. So we now start to track to the bottom of the window, with a 25px padding
			# since the footer is hidden below the fold. Don't ever get bigger than the sidebar
			# though since that's what triggered this happening in the first place.
			if height < sideBarHeight
				height = Math.min(sideBarHeight, $window.innerHeight - topOffset - 25)
			$scope.projectListHeight = height
			
		recalculateProjectListHeight()
		angular.element($window).bind "resize", () ->
			recalculateProjectListHeight()
			$scope.$apply()
			
		# Allow tags to be accessed on projects as well
		projectsById = {}
		for project in $scope.projects
			projectsById[project.id] = project

		for tag in $scope.tags
			for project_id in tag.project_ids or []
				project = projectsById[project_id]
				if project?
					project.tags ||= []
					project.tags.push tag

		$scope.changePredicate = (newPredicate)->
			if $scope.predicate == newPredicate
				$scope.reverse = !$scope.reverse
			$scope.predicate = newPredicate

		$scope.getSortIconClass = (column)->
			if column == $scope.predicate and $scope.reverse
				return "fa-caret-down"
			else if column == $scope.predicate and !$scope.reverse
				return "fa-caret-up"
			else
				return ""

		$scope.searchProjects = ->
			event_tracking.send 'project-list-page-interaction', 'project-search', 'keydown'<commit_msg>Resize project list correctly on page load<commit_after>define [
	"base"
], (App) ->
	App.factory "queuedHttp", ["$http", "$q", ($http, $q) ->
		pendingRequests = []
		inflight = false

		processPendingRequests = () ->
			return if inflight
			doRequest = pendingRequests.shift()
			if doRequest?
				inflight = true
				doRequest()
					.success () ->
						inflight = false
						processPendingRequests()
					.error () ->
						inflight = false
						processPendingRequests()

		queuedHttp = (args...) ->
			deferred = $q.defer()
			promise = deferred.promise

			# Adhere to the $http promise conventions
			promise.success = (callback) ->
				promise.then(callback)
				return promise

			promise.error = (callback) ->
				promise.catch(callback)
				return promise

			doRequest = () ->
				$http(args...)
					.success (successArgs...) ->
						deferred.resolve(successArgs...)
					.error (errorArgs...) ->
						deferred.reject(errorArgs...)

			pendingRequests.push doRequest
			processPendingRequests()

			return promise

		queuedHttp.post = (url, data) ->
			queuedHttp({method: "POST", url: url, data: data})

		return queuedHttp

	]

	App.controller "ProjectPageController", ($scope, $modal, $q, $window, queuedHttp, event_tracking, $timeout) ->
		$scope.projects = window.data.projects
		$scope.tags = window.data.tags
		$scope.allSelected = false
		$scope.selectedProjects = []
		$scope.filter = "all"
		$scope.predicate = "lastUpdated"
		$scope.reverse = true

		recalculateProjectListHeight = () ->
			topOffset = $(".project-list-card").offset().top
			bottomOffset = $("footer").outerHeight() + 25
			sideBarHeight = $("aside").height() - 56
			# When footer is visible and page doesn't need to scroll we just make it
			# span between header and footer
			height = $window.innerHeight - topOffset - bottomOffset
			
			# When page is small enough that this pushes the project list smaller than
			# the side bar, then the window going to have to scroll to take into account the
			# footer. So we now start to track to the bottom of the window, with a 25px padding
			# since the footer is hidden below the fold. Don't ever get bigger than the sidebar
			# though since that's what triggered this happening in the first place.
			if height < sideBarHeight
				height = Math.min(sideBarHeight, $window.innerHeight - topOffset - 25)
			$scope.projectListHeight = height
		
		$timeout () ->
			recalculateProjectListHeight()
		, 0
		angular.element($window).bind "resize", () ->
			recalculateProjectListHeight()
			$scope.$apply()
			
		# Allow tags to be accessed on projects as well
		projectsById = {}
		for project in $scope.projects
			projectsById[project.id] = project

		for tag in $scope.tags
			for project_id in tag.project_ids or []
				project = projectsById[project_id]
				if project?
					project.tags ||= []
					project.tags.push tag

		$scope.changePredicate = (newPredicate)->
			if $scope.predicate == newPredicate
				$scope.reverse = !$scope.reverse
			$scope.predicate = newPredicate

		$scope.getSortIconClass = (column)->
			if column == $scope.predicate and $scope.reverse
				return "fa-caret-down"
			else if column == $scope.predicate and !$scope.reverse
				return "fa-caret-up"
			else
				return ""

		$scope.searchProjects = ->
			event_tracking.send 'project-list-page-interaction', 'project-search', 'keydown'
{'fraction_non_alphanumeric': 0.11997600479904019, 'fraction_numerical': 0.002549490101979604, 'mean_word_length': 3.1785714285714284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, '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': '6810427', 'n_tokens_mistral': 2427, 'n_tokens_neox': 1969, 'n_words': 572}