<commit_before>angular.module('dashboard.directives.ModelFieldPointsOfInterest', [
		'dashboard.Dashboard.Model.Edit.SaveDialog',
		"dashboard.Config",
		"dashboard.services.Location",
		"ui.bootstrap",
		"dashboard.services.GeneralModel",
		"ui.select"
	])
	
	.directive('modelFieldPointsOfInterestView', function($compile) {
		return {
			restrict: 'E',
			template: '<b>{{ options.model }}</b>: {{ data[options.key] }}',
			scope: {
				options: '=options',
				data: '=ngModel',
				required: 'ngRequired',
				disabled: 'disabled'
			},
			link: function(scope, element, attrs) {
			}
		};
	})

  .directive('modelFieldPointsOfInterestEdit', function($compile, $cookies, $timeout, $modal, $http, $q, $window, Config, GeneralModelService, LocationService) {
		//  load google maps javascript asynchronously
		function loadScript() {
			var deferred = $q.defer();
			if(angular.element('#google_maps').length ) {
				deferred.resolve();
				return deferred.promise;
			}
		 	var googleMapsApiJS = document.createElement('script');
			googleMapsApiJS.onload = function() {
					deferred.resolve();
			};
			googleMapsApiJS.id = 'google_maps';
			googleMapsApiJS.type = 'text/javascript';
			googleMapsApiJS.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,places';
			document.getElementsByTagName('head')[0].appendChild(googleMapsApiJS);
			return deferred.promise;
		}

		function getTemplate() {
			var repeatExpression = 'item in displayedSearchResults track by item.id';
			var template = ' \
        <div class="loading" ng-if="isMapLoading"><img src="http://www.nasa.gov/multimedia/videogallery/ajax-loader.gif" width="20" height="20" />Search results are loading...</div> \
        <div ng-show="isLoaded"> \
        <accordion close-others="oneAtATime"> \
        <accordion-group id="accordion-group-1" heading="Pharmacy Search" is-open="true"> \
        <input id="zipCode" class="field form-control" placeholder="Zip Code" ng-model="data.zipCode">\
        <input id="searchInput" class="field form-control" placeholder="Search Location" ng-model="request[\'query\']">\
         <select id="radius" ng-options="value as value for value in display.options" ng-required="" class="field form-control ng-pristine ng-valid ng-valid-required" ng-disabled=""> \
           <option value="" disabled selected class="">Radius</option> \
           <option value="1" label="1 Mile">1 Mile</option> \
           <option value="2" label="2 Miles">2 Miles</option> \
           <option value="3" label="3 Miles">3 Miles</option> \
           <option value="5" label="5 Miles">5 Miles</option> \
           <option value="10" label="10 Miles">10 Miles</option> \
           <option value="20" label="20 Miles">20 Miles</option> \
        	 <option value="30" label="30 Miles">30 Miles</option> \
         </select> \
        <button class="btn" ng-click="doSearch()" ng-model="request.query">Search</button>\
        </accordion-group>\
        </accordion> \
        <div class="map-canvas"id="map_canvas"></div> \
        <ul class="selected-location" ng-model="displayedSearchResults" > \
          <li ng-repeat="'+repeatExpression+'"> \
            <div class="location-title">{{ item.name }}</div> \
              <span>{{item.formatted_address}}</span> \
            <div class="col-sm checkbox-container">\
              <input type="checkbox" ng-attr-id="{{item.id}}" ng-model="item.checked" ng-click="updateSelection($index, displayedSearchResults)" class="field"> \
              <label class="checkbox-label" ng-attr-for="{{item.id}}" ></label> \
            </div> \
          </li> \
        </ul>';
			return template;
		}

		return {
			restrict: 'E',
			require: "ngModel",
			scope: {
				key: '=key',
				property: '=property',
				options: '=options',
				data: '=ngModel',
				modelData: '=modelData',
				disabled: '=disabled'
			},
			link: function(scope, element, attrs) {

				var map;
				var milesToMeters = 1609.34;           // Conversion to miles to meters
				var miles = 3;
				var geocoder;
				var radius = miles*milesToMeters;
				var bounds;

				scope.circle = {};                     // displayed cicle boundary
				scope.markers = [];                    // Stored markers
				scope.boundaries = [];                 // Stored google boundary circles
				scope.searchResults = [];              // All data recieved from query
				scope.displayedMarkers = [];           // Markers that match query
				scope.displayedSearchResults = [];     // Data for location list
				scope.isMapLoading = true;
				scope.isLoaded = false;
				scope.placeType = scope.property.display.options.placeType; //Default query value
				scope.data = {};

				loadScript().then(function () {
					bounds = new google.maps.LatLngBounds(); // Set initial bounds for markers
					geocoder = new google.maps.Geocoder();

					scope.request = {
						radius: radius,
						query: scope.placeType,
						types: scope.placeType
					};

					element.html(getTemplate()).show();
					$compile(element.contents())(scope);
					//Currently calls LocationService to get user's current location
					LocationService.currentLocation().then(function (position) {
						var pointLocation = {
							lat: position.latitude,
							lng: position.longitude
						};
						scope.request.location = pointLocation;
						initMap(scope.request.location);
					});
				}, function () {
					console.error("Error loading Google Maps")
				});

				function initMap() {
					scope.isMapLoading = false;
					scope.isLoaded = true;
					map = new google.maps.Map(document.getElementById('map_canvas'), {
						center: scope.request.location,<commit_msg>Added check to see if data passed into ModelFieldPointsOfInterest is a JSON string<commit_after>angular.module('dashboard.directives.ModelFieldPointsOfInterest', [
		'dashboard.Dashboard.Model.Edit.SaveDialog',
		"dashboard.Config",
		"dashboard.services.Location",
		"ui.bootstrap",
		"dashboard.services.GeneralModel",
		"ui.select"
	])
	
	.directive('modelFieldPointsOfInterestView', function($compile) {
		return {
			restrict: 'E',
			template: '<b>{{ options.model }}</b>: {{ data[options.key] }}',
			scope: {
				options: '=options',
				data: '=ngModel',
				required: 'ngRequired',
				disabled: 'disabled'
			},
			link: function(scope, element, attrs) {
			}
		};
	})

  .directive('modelFieldPointsOfInterestEdit', function($compile, $cookies, $timeout, $modal, $http, $q, $window, Config, GeneralModelService, LocationService) {
		//  load google maps javascript asynchronously
		function loadScript() {
			var deferred = $q.defer();
			if(angular.element('#google_maps').length ) {
				deferred.resolve();
				return deferred.promise;
			}
		 	var googleMapsApiJS = document.createElement('script');
			googleMapsApiJS.onload = function() {
					deferred.resolve();
			};
			googleMapsApiJS.id = 'google_maps';
			googleMapsApiJS.type = 'text/javascript';
			googleMapsApiJS.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,places';
			document.getElementsByTagName('head')[0].appendChild(googleMapsApiJS);
			return deferred.promise;
		}

		function getTemplate() {
			var repeatExpression = 'item in displayedSearchResults track by item.id';
			var template = ' \
        <div class="loading" ng-if="isMapLoading"><img src="http://www.nasa.gov/multimedia/videogallery/ajax-loader.gif" width="20" height="20" />Search results are loading...</div> \
        <div ng-show="isLoaded"> \
        <accordion close-others="oneAtATime"> \
        <accordion-group id="accordion-group-1" heading="Pharmacy Search" is-open="true"> \
        <input id="zipCode" class="field form-control" placeholder="Zip Code" ng-model="data.zipCode">\
        <input id="searchInput" class="field form-control" placeholder="Search Location" ng-model="request[\'query\']">\
         <select id="radius" ng-options="value as value for value in display.options" ng-required="" class="field form-control ng-pristine ng-valid ng-valid-required" ng-disabled=""> \
           <option value="" disabled selected class="">Radius</option> \
           <option value="1" label="1 Mile">1 Mile</option> \
           <option value="2" label="2 Miles">2 Miles</option> \
           <option value="3" label="3 Miles">3 Miles</option> \
           <option value="5" label="5 Miles">5 Miles</option> \
           <option value="10" label="10 Miles">10 Miles</option> \
           <option value="20" label="20 Miles">20 Miles</option> \
        	 <option value="30" label="30 Miles">30 Miles</option> \
         </select> \
        <button class="btn" ng-click="doSearch()" ng-model="request.query">Search</button>\
        </accordion-group>\
        </accordion> \
        <div class="map-canvas"id="map_canvas"></div> \
        <ul class="selected-location" ng-model="displayedSearchResults" > \
          <li ng-repeat="'+repeatExpression+'"> \
            <div class="location-title">{{ item.name }}</div> \
              <span>{{item.formatted_address}}</span> \
            <div class="col-sm checkbox-container">\
              <input type="checkbox" ng-attr-id="{{item.id}}" ng-model="item.checked" ng-click="updateSelection($index, displayedSearchResults)" class="field"> \
              <label class="checkbox-label" ng-attr-for="{{item.id}}" ></label> \
            </div> \
          </li> \
        </ul>';
			return template;
		}

		return {
			restrict: 'E',
			require: "ngModel",
			scope: {
				key: '=key',
				property: '=property',
				options: '=options',
				data: '=ngModel',
				modelData: '=modelData',
				disabled: '=disabled'
			},
			link: function(scope, element, attrs) {

				var map;
				var milesToMeters = 1609.34;           // Conversion to miles to meters
				var miles = 3;
				var geocoder;
				var radius = miles*milesToMeters;
				var bounds;

				scope.circle = {};                     // displayed cicle boundary
				scope.markers = [];                    // Stored markers
				scope.boundaries = [];                 // Stored google boundary circles
				scope.searchResults = [];              // All data recieved from query
				scope.displayedMarkers = [];           // Markers that match query
				scope.displayedSearchResults = [];     // Data for location list
				scope.isMapLoading = true;
				scope.isLoaded = false;
				scope.placeType = scope.property.display.options.placeType; //Default query value
				if (!scope.data) scope.data = {};

				//Check if scope.data is JSON string and try to parse it to load the data
				if (scope.data && typeof scope.data === 'string') {
					try {
						scope.data = JSON.parse(scope.data);
					} catch (e) {
						console.error(e);
						scope.data = {};
					}
				}

				loadScript().then(function () {
					bounds = new google.maps.LatLngBounds(); // Set initial bounds for markers
					geocoder = new google.maps.Geocoder();

					scope.request = {
						radius: radius,
						query: scope.placeType,
						types: scope.placeType
					};

					element.html(getTemplate()).show();
					$compile(element.contents())(scope);
					//Currently calls LocationService to get user's current location
					LocationService.currentLocation().then(function (position) {
						var pointLocation = {
							lat: position.latitude,
							lng: position.longitude
						};
						scope.request.location = pointLocation;
						initMap();
					});
				}, function () {
					console.error("Error loading Google Maps")
				});

				function initMap() {
					scope.isMapLoading = false;
					scope.isLoaded = true;
					map = new google.maps.Map(document.getElementById('map_canvas'), {
						center: scope.request.location,
{'fraction_non_alphanumeric': 0.1539516543802503, 'fraction_numerical': 0.007543288187896451, 'mean_word_length': 2.894192256341789, 'pattern_counts': {'":': 0, '<': 97, '<?xml version=': 0, '>': 97, 'https://': 2, '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': '5835064', 'n_tokens_mistral': 4095, 'n_tokens_neox': 3416, 'n_words': 730}