2017-12-20 05:33:33 -06:00
|
|
|
import store from 'app/core/store';
|
2021-04-21 02:38:00 -05:00
|
|
|
import { filter, isArray, isNumber } from 'lodash';
|
2017-12-20 05:33:33 -06:00
|
|
|
import config from 'app/core/config';
|
2016-02-26 03:09:38 -06:00
|
|
|
|
2017-11-24 09:18:56 -06:00
|
|
|
export class ImpressionSrv {
|
2016-02-26 03:09:38 -06:00
|
|
|
constructor() {}
|
|
|
|
|
2019-04-28 02:58:12 -05:00
|
|
|
addDashboardImpression(dashboardId: number) {
|
|
|
|
const impressionsKey = this.impressionKey();
|
2018-08-30 02:03:11 -05:00
|
|
|
let impressions = [];
|
2016-03-16 05:52:25 -05:00
|
|
|
if (store.exists(impressionsKey)) {
|
|
|
|
impressions = JSON.parse(store.get(impressionsKey));
|
2021-04-21 02:38:00 -05:00
|
|
|
if (!isArray(impressions)) {
|
2016-02-26 03:09:38 -06:00
|
|
|
impressions = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-20 00:59:48 -06:00
|
|
|
impressions = impressions.filter((imp) => {
|
2016-03-05 05:26:21 -06:00
|
|
|
return dashboardId !== imp;
|
2016-02-29 12:51:35 -06:00
|
|
|
});
|
2016-02-26 03:09:38 -06:00
|
|
|
|
2016-03-05 05:26:21 -06:00
|
|
|
impressions.unshift(dashboardId);
|
2016-02-26 03:09:38 -06:00
|
|
|
|
2016-03-05 05:26:21 -06:00
|
|
|
if (impressions.length > 50) {
|
|
|
|
impressions.pop();
|
2016-02-26 03:09:38 -06:00
|
|
|
}
|
2016-03-16 05:52:25 -05:00
|
|
|
store.set(impressionsKey, JSON.stringify(impressions));
|
2016-02-26 03:09:38 -06:00
|
|
|
}
|
|
|
|
|
2016-02-29 07:37:09 -06:00
|
|
|
getDashboardOpened() {
|
2019-04-28 02:58:12 -05:00
|
|
|
let impressions = store.get(this.impressionKey()) || '[]';
|
2016-03-07 04:04:02 -06:00
|
|
|
|
|
|
|
impressions = JSON.parse(impressions);
|
|
|
|
|
2021-04-21 02:38:00 -05:00
|
|
|
impressions = filter(impressions, (el) => {
|
|
|
|
return isNumber(el);
|
2016-03-07 04:04:02 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
return impressions;
|
2016-02-26 03:09:38 -06:00
|
|
|
}
|
2016-03-16 05:52:25 -05:00
|
|
|
|
2019-04-28 02:58:12 -05:00
|
|
|
impressionKey() {
|
2017-12-20 05:33:33 -06:00
|
|
|
return 'dashboard_impressions-' + config.bootData.user.orgId;
|
2016-03-16 05:52:25 -05:00
|
|
|
}
|
2016-02-26 03:09:38 -06:00
|
|
|
}
|
|
|
|
|
2017-11-24 09:18:56 -06:00
|
|
|
const impressionSrv = new ImpressionSrv();
|
|
|
|
export default impressionSrv;
|