<commit_before>'use strict';

/**
 * @ngdoc function
 * @name enlightenApp.factory:Settings
 * @description
 * # Settings
 * A Settings singleton
 */
angular.module('enlightenApp')
	.factory('Settings', function()
	{
		var settings =
		{
			credentials:
			{
				AWS:
				{
					accessKey: "",
					secretKey: "",
					region: "",
					isValid: function()
					{
						return !!(this.accessKey && this.secretKey && this.region);
					},
					reset: function()
					{
						this.accessKey = "";
						this.secretKey = "";
						this.region = "";
					}
				}
			},

			lightroom:
			{
				pathToLrCat: "",
				isValid: function()
				{
					return !!(this.pathToLrCat);
				},
				reset: function()
				{
					this.pathToLrCat = "";
				}
			},

			application:
			{
				backendType: "",
				isValid: function()
				{
					return !!(this.backendType);
				},
				reset: function()
				{
					this.backendType = "";
				}
			}
		}

		var loadAWSCredentials = function()
		{
			settings.credentials["AWS"].accessKey = localStorage.getItem("aws.accessKey");
			settings.credentials["AWS"].secretKey = localStorage.getItem("aws.secretKey");
			settings.credentials["AWS"].region    = localStorage.getItem("aws.region");
		}

		var loadLightroomSettings = function()
		{
			settings.lightroom.pathToLrCat = localStorage.getItem("lr.pathToLrCat");
		}

		var loadApplicationSettings = function()
		{
			settings.application.backendType = localStorage.getItem("app.backendType");
		}

		return {
			hasCredentials: function()
			{
				if (!settings.credentials["AWS"].isValid())
					loadAWSCredentials();

				return settings.credentials["AWS"].isValid();
			},

			getAWSCredentials: function()
			{
				if (!settings.credentials["AWS"].isValid())
					loadAWSCredentials();

				return settings.credentials["AWS"];
			},

			setAWSCredentials: function(awsCredentials)
			{
				localStorage.setItem("aws.accessKey", awsCredentials.accessKey);
				localStorage.setItem("aws.secretKey", awsCredentials.secretKey);
				localStorage.setItem("aws.region", awsCredentials.region);

				settings.credentials["AWS"].reset();
			},

			getLightroomSettings: function()
			{
				if (!settings.lightroom.isValid())
					loadLightroomSettings();

				return settings.lightroom;
			},

			setLightroomSettings: function(lightroomSettings)
			{
				localStorage.setItem("lr.pathToLrCat", lightroomSettings.pathToLrCat);

				settings.lightroom.reset();
			},

			setApplicationSettings: function(applicationSettings)
			{
				localStorage.setItem("app.backendType", applicationSettings.backendType);

				settings.application.reset();
			},

			getApplicationSettings: function()
			{
				if (!settings.application.isValid())
					loadApplicationSettings();

				return settings.application;<commit_msg>Updated Settings class so read from localStorage ins't needed<commit_after>'use strict';

/**
 * @ngdoc function
 * @name enlightenApp.factory:Settings
 * @description
 * # Settings
 * A Settings singleton
 */
angular.module('enlightenApp')
	.factory('Settings', function()
	{
		var settings =
		{
			credentials:
			{
				AWS:
				{
					accessKey: "",
					secretKey: "",
					region: "",
					isValid: function()
					{
						return !!(this.accessKey && this.secretKey && this.region);
					},
					reset: function()
					{
						this.accessKey = "";
						this.secretKey = "";
						this.region = "";
					},
					copyFrom: function(other)
					{
						this.accessKey = other.accessKey;
						this.secretKey = other.secretKey;
						this.region    = other.region;
					}
				}
			},

			lightroom:
			{
				pathToLrCat: "",
				isValid: function()
				{
					return !!(this.pathToLrCat);
				},
				reset: function()
				{
					this.pathToLrCat = "";
				},
				copyFrom: function(other)
				{
					this.pathToLrCat = other.pathToLrCat;
				}
			},

			application:
			{
				backendType: "",
				isValid: function()
				{
					return !!(this.backendType);
				},
				reset: function()
				{
					this.backendType = "";
				},
				copyFrom: function(other)
				{
					this.backendType = other.backendType;
				}
			}
		}

		var loadAWSCredentials = function()
		{
			settings.credentials["AWS"].accessKey = localStorage.getItem("aws.accessKey");
			settings.credentials["AWS"].secretKey = localStorage.getItem("aws.secretKey");
			settings.credentials["AWS"].region    = localStorage.getItem("aws.region");
		}

		var loadLightroomSettings = function()
		{
			settings.lightroom.pathToLrCat = localStorage.getItem("lr.pathToLrCat");
		}

		var loadApplicationSettings = function()
		{
			settings.application.backendType = localStorage.getItem("app.backendType");
		}

		return {
			hasCredentials: function()
			{
				if (!settings.credentials["AWS"].isValid())
					loadAWSCredentials();

				return settings.credentials["AWS"].isValid();
			},

			getAWSCredentials: function()
			{
				if (!settings.credentials["AWS"].isValid())
					loadAWSCredentials();

				return settings.credentials["AWS"];
			},

			setAWSCredentials: function(awsCredentials)
			{
				localStorage.setItem("aws.accessKey", awsCredentials.accessKey);
				localStorage.setItem("aws.secretKey", awsCredentials.secretKey);
				localStorage.setItem("aws.region", awsCredentials.region);

				settings.credentials["AWS"].copyFrom(awsCredentials);
			},

			getLightroomSettings: function()
			{
				if (!settings.lightroom.isValid())
					loadLightroomSettings();

				return settings.lightroom;
			},

			setLightroomSettings: function(lightroomSettings)
			{
				localStorage.setItem("lr.pathToLrCat", lightroomSettings.pathToLrCat);
				settings.lightroom.copyFrom(lightroomSettings);
			},

			getApplicationSettings: function()
			{
				if (!settings.application.isValid())
					loadApplicationSettings();

				return settings.application;
			},

			setApplicationSettings: function(applicationSettings)
			{
				localStorage.setItem("app.backendType", applicationSettings.backendType);
				settings.application.copyFrom(applicationSettings);
{'fraction_non_alphanumeric': 0.14064580559254328, 'fraction_numerical': 0.0, 'mean_word_length': 3.178720445062587, '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': '6322279', 'n_tokens_mistral': 2426, 'n_tokens_neox': 1837, 'n_words': 257}