impression_store.ts 1017 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. impressions = JSON.parse(impressions);
  26. impressions = _.filter(impressions, el => {
  27. return _.isNumber(el);
  28. });
  29. return impressions;
  30. }
  31. }
  32. var impressions = new ImpressionsStore();
  33. export {
  34. impressions
  35. };