Source: fedramp.models/settings.factory.js

  1. (function () {
  2. 'use strict';
  3. angular
  4. .module('fedramp.services')
  5. .factory('Settings', SettingsFactory);
  6. SettingsFactory.$inject = ['helperService'];
  7. function SettingsFactory (helperService) {
  8. return Settings;
  9. /**
  10. * Application settings for the FedRAMP dashboard.
  11. * @constructor
  12. * @memberof Models
  13. */
  14. function Settings (options) {
  15. // Scope `this` to self
  16. var self = this;
  17. var mapping = {
  18. 'Created_At': 'lastRefresh',
  19. 'Produced_By' : 'producedBy'
  20. };
  21. /**
  22. * The last refresh date
  23. * @member {string}
  24. * @memberof Models.Settings
  25. */
  26. self.lastRefresh = null;
  27. /**
  28. * Initialize the Settings object.
  29. *
  30. * @param {object} options
  31. * A dictionary of options to configure the Settings object.
  32. *
  33. * @returns
  34. * The Settings object
  35. */
  36. self.init = function (options) {
  37. if (options) {
  38. for (var x in options) {
  39. if (!options.hasOwnProperty(x)) {
  40. continue;
  41. }
  42. var key = mapping[x];
  43. if(key){
  44. self[key] = options[x];
  45. }
  46. }
  47. }
  48. return self;
  49. };
  50. /**
  51. * Refreshes the date to current date
  52. * @public
  53. * @memberof Models.Settings
  54. *
  55. * @returns
  56. * The last refresh date
  57. */
  58. self.refresh = function () {
  59. self.lastRefresh = helperService.toDate(new Date().toString());
  60. return self.lastRefresh;
  61. };
  62. /**
  63. * Clears last refresh
  64. * @public
  65. * @memberof Models.Settings
  66. */
  67. self.clearRefresh = function () {
  68. self.lastRefresh = null;
  69. };
  70. /**
  71. * Determine if the data requires a refresh.
  72. * @public
  73. * @memberof Models.Settings
  74. *
  75. * @returns
  76. * A boolean value
  77. */
  78. self.needsRefresh = function () {
  79. return self.lastRefresh !== helperService.toDate(new Date().toString());
  80. };
  81. /**
  82. * Hard-coded hash used since only a single instance will be stored
  83. * @public
  84. * @memberof Models.Settings
  85. *
  86. * @returns
  87. * hash for settings
  88. */
  89. self.hash = function(){
  90. return "fedramp";
  91. };
  92. return self.init(options);
  93. }
  94. }
  95. })();