impression_store.ts 898 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. ///<reference path="../../headers/common.d.ts" />
  2. import store from 'app/core/store';
  3. import _ from 'lodash';
  4. export class ImpressionsStore {
  5. constructor() {}
  6. addDashboardImpression(dashboardId) {
  7. var impressions = [];
  8. if (store.exists("dashboard_impressions")) {
  9. impressions = JSON.parse(store.get("dashboard_impressions"));
  10. if (!_.isArray(impressions)) {
  11. impressions = [];
  12. }
  13. }
  14. impressions = impressions.filter((imp) => {
  15. return dashboardId !== imp;
  16. });
  17. impressions.unshift(dashboardId);
  18. if (impressions.length > 50) {
  19. impressions.pop();
  20. }
  21. store.set("dashboard_impressions", JSON.stringify(impressions));
  22. }
  23. getDashboardOpened() {
  24. var impressions = store.get("dashboard_impressions");
  25. return JSON.parse(impressions || "[]");
  26. }
  27. }
  28. var impressions = new ImpressionsStore();
  29. export {
  30. impressions
  31. };