@qrvey/utils 1.13.0-7 → 1.13.0-7.performance.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cache-managers/cache-chart-manager.d.ts +34 -0
- package/dist/cache-managers/cache-chart-manager.js +43 -0
- package/dist/cache-managers/cache-manager.d.ts +27 -0
- package/dist/cache-managers/cache-manager.js +39 -0
- package/dist/cache-managers/cache-metric-manager.d.ts +34 -0
- package/dist/cache-managers/cache-metric-manager.js +43 -0
- package/dist/cache-managers/cache-model-manager.d.ts +29 -0
- package/dist/cache-managers/cache-model-manager.js +40 -0
- package/dist/cache-managers/cache-permissions-manager.d.ts +26 -0
- package/dist/cache-managers/cache-permissions-manager.js +39 -0
- package/dist/cache-managers/cache-theme-manager.d.ts +27 -0
- package/dist/cache-managers/cache-theme-manager.js +39 -0
- package/dist/cjs/cache-managers/cache-chart-manager.d.ts +34 -0
- package/dist/cjs/cache-managers/cache-chart-manager.js +50 -0
- package/dist/cjs/cache-managers/cache-manager.d.ts +27 -0
- package/dist/cjs/cache-managers/cache-manager.js +43 -0
- package/dist/cjs/cache-managers/cache-metric-manager.d.ts +34 -0
- package/dist/cjs/cache-managers/cache-metric-manager.js +50 -0
- package/dist/cjs/cache-managers/cache-model-manager.d.ts +29 -0
- package/dist/cjs/cache-managers/cache-model-manager.js +44 -0
- package/dist/cjs/cache-managers/cache-permissions-manager.d.ts +26 -0
- package/dist/cjs/cache-managers/cache-permissions-manager.js +43 -0
- package/dist/cjs/cache-managers/cache-theme-manager.d.ts +27 -0
- package/dist/cjs/cache-managers/cache-theme-manager.js +43 -0
- package/dist/cjs/filters/helpers/common/getFiltersByScopesIds.d.ts +0 -1
- package/dist/cjs/filters/helpers/common/getFiltersByScopesIds.js +3 -3
- package/dist/cjs/filters/helpers/common/getFiltersByVisibility.d.ts +1 -1
- package/dist/cjs/filters/helpers/common/getFiltersByVisibility.js +1 -1
- package/dist/cjs/interfaces/AdminPermissions.interface.d.ts +53 -0
- package/dist/cjs/interfaces/AdminPermissions.interface.js +7 -0
- package/dist/cjs/interfaces/themes/an-style-theme.d.ts +22 -0
- package/dist/cjs/interfaces/themes/an-style-theme.js +2 -0
- package/dist/cjs/interfaces/themes/an-theme.d.ts +15 -0
- package/dist/cjs/interfaces/themes/an-theme.js +2 -0
- package/dist/cjs/services/api/Charts.api.d.ts +2 -7
- package/dist/cjs/services/api/Charts.api.js +22 -0
- package/dist/cjs/services/api/Themes.api.d.ts +3 -0
- package/dist/cjs/services/api/Themes.api.js +13 -0
- package/dist/cjs/services/api/adminPermissions.api.d.ts +2 -0
- package/dist/cjs/services/api/adminPermissions.api.js +20 -0
- package/dist/cjs/services/api/getModel.api.d.ts +1 -1
- package/dist/cjs/services/api/getModel.api.js +1 -2
- package/dist/cjs/services/api/metrics.api.d.ts +4 -0
- package/dist/cjs/services/api/metrics.api.js +19 -0
- package/dist/cjs/services/constants/METRIC_ENDPOINT.d.ts +2 -0
- package/dist/cjs/services/constants/METRIC_ENDPOINT.js +7 -0
- package/dist/cjs/services/constants/THEME_ENDPOINT.d.ts +2 -0
- package/dist/cjs/services/constants/THEME_ENDPOINT.js +7 -0
- package/dist/filters/helpers/common/getFiltersByScopesIds.d.ts +0 -1
- package/dist/filters/helpers/common/getFiltersByScopesIds.js +3 -3
- package/dist/filters/helpers/common/getFiltersByVisibility.d.ts +1 -1
- package/dist/filters/helpers/common/getFiltersByVisibility.js +1 -1
- package/dist/interfaces/AdminPermissions.interface.d.ts +53 -0
- package/dist/interfaces/AdminPermissions.interface.js +4 -0
- package/dist/interfaces/themes/an-style-theme.d.ts +22 -0
- package/dist/interfaces/themes/an-style-theme.js +1 -0
- package/dist/interfaces/themes/an-theme.d.ts +15 -0
- package/dist/interfaces/themes/an-theme.js +1 -0
- package/dist/services/api/Charts.api.d.ts +2 -7
- package/dist/services/api/Charts.api.js +22 -0
- package/dist/services/api/Themes.api.d.ts +3 -0
- package/dist/services/api/Themes.api.js +8 -0
- package/dist/services/api/adminPermissions.api.d.ts +2 -0
- package/dist/services/api/adminPermissions.api.js +16 -0
- package/dist/services/api/getModel.api.d.ts +1 -1
- package/dist/services/api/getModel.api.js +1 -2
- package/dist/services/api/metrics.api.d.ts +4 -0
- package/dist/services/api/metrics.api.js +16 -0
- package/dist/services/constants/METRIC_ENDPOINT.d.ts +2 -0
- package/dist/services/constants/METRIC_ENDPOINT.js +4 -0
- package/dist/services/constants/THEME_ENDPOINT.d.ts +2 -0
- package/dist/services/constants/THEME_ENDPOINT.js +4 -0
- package/package.json +2 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { OnChangeType, QrveyCacheManager } from "./cache-manager";
|
|
2
|
+
export interface IGetChartConfig {
|
|
3
|
+
qv_token?: string;
|
|
4
|
+
api_key?: string;
|
|
5
|
+
app_id?: string;
|
|
6
|
+
user_id?: string;
|
|
7
|
+
domain?: string;
|
|
8
|
+
timezone?: any;
|
|
9
|
+
qrvey_id?: string;
|
|
10
|
+
i18n?: any;
|
|
11
|
+
chart_id?: string;
|
|
12
|
+
lang?: string;
|
|
13
|
+
translated?: boolean;
|
|
14
|
+
headers?: {
|
|
15
|
+
"temporal-tokens"?: boolean;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface IChartStoreState {
|
|
19
|
+
chart: any;
|
|
20
|
+
loading: boolean;
|
|
21
|
+
error: any;
|
|
22
|
+
}
|
|
23
|
+
export declare class ChartCacheManager extends QrveyCacheManager<IChartStoreState, IGetChartConfig> {
|
|
24
|
+
static getInstance(): ChartCacheManager;
|
|
25
|
+
protected getConfigPropertyName(): keyof IGetChartConfig;
|
|
26
|
+
protected getStorePropertyName(): keyof IChartStoreState;
|
|
27
|
+
protected buildStoreId({ chart_id, translated }: IGetChartConfig): string;
|
|
28
|
+
protected createStore(): {
|
|
29
|
+
state: IChartStoreState;
|
|
30
|
+
onChange: OnChangeType;
|
|
31
|
+
};
|
|
32
|
+
protected fetchDataAndUpdateStore(state: IChartStoreState, config: IGetChartConfig): void;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createStore } from "@stencil/store";
|
|
2
|
+
import { QrveyCacheManager } from "./cache-manager";
|
|
3
|
+
import ChartsApi from "../services/api/Charts.api";
|
|
4
|
+
import { isEmpty } from "../general/mix/isEmpty";
|
|
5
|
+
export class ChartCacheManager extends QrveyCacheManager {
|
|
6
|
+
static getInstance() {
|
|
7
|
+
if (!window.chartCacheManager) {
|
|
8
|
+
window.chartCacheManager = new ChartCacheManager();
|
|
9
|
+
}
|
|
10
|
+
return window.chartCacheManager;
|
|
11
|
+
}
|
|
12
|
+
getConfigPropertyName() {
|
|
13
|
+
return "chart_id";
|
|
14
|
+
}
|
|
15
|
+
getStorePropertyName() {
|
|
16
|
+
return "chart";
|
|
17
|
+
}
|
|
18
|
+
buildStoreId({ chart_id, translated }) {
|
|
19
|
+
const translate = isEmpty(translated) ? true : translated;
|
|
20
|
+
return `${chart_id}-${translate ? "translated" : ""}`;
|
|
21
|
+
}
|
|
22
|
+
createStore() {
|
|
23
|
+
return createStore({
|
|
24
|
+
chart: null,
|
|
25
|
+
loading: true,
|
|
26
|
+
error: null,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
fetchDataAndUpdateStore(state, config) {
|
|
30
|
+
const api = new ChartsApi(config);
|
|
31
|
+
api
|
|
32
|
+
.getChart(config)
|
|
33
|
+
.then((chart) => {
|
|
34
|
+
state.chart = chart;
|
|
35
|
+
state.error = null;
|
|
36
|
+
state.loading = false;
|
|
37
|
+
})
|
|
38
|
+
.catch((e) => {
|
|
39
|
+
state.error = e;
|
|
40
|
+
state.loading = false;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type OnChangeType = (property: string | number | symbol, callback: (entity: unknown) => void) => () => void;
|
|
2
|
+
export declare abstract class QrveyCacheManager<TStoreState, TConfig> {
|
|
3
|
+
protected stores: Map<string, {
|
|
4
|
+
state: TStoreState;
|
|
5
|
+
onChange: OnChangeType;
|
|
6
|
+
}>;
|
|
7
|
+
protected abstract getConfigPropertyName(): keyof TConfig;
|
|
8
|
+
protected abstract getStorePropertyName(): keyof TStoreState;
|
|
9
|
+
protected abstract buildStoreId(config: TConfig): string;
|
|
10
|
+
protected abstract fetchDataAndUpdateStore(state: TStoreState, config: TConfig): void;
|
|
11
|
+
protected abstract createStore(): {
|
|
12
|
+
state: TStoreState;
|
|
13
|
+
onChange: OnChangeType;
|
|
14
|
+
};
|
|
15
|
+
protected getStoreFromPromise(config: TConfig, id: string): Promise<{
|
|
16
|
+
state: TStoreState;
|
|
17
|
+
onChange: OnChangeType;
|
|
18
|
+
}>;
|
|
19
|
+
getStore(config: TConfig): {
|
|
20
|
+
state: TStoreState;
|
|
21
|
+
onChange: OnChangeType;
|
|
22
|
+
};
|
|
23
|
+
getMultipleStores(config: TConfig, ids: string[]): Promise<{
|
|
24
|
+
state: TStoreState;
|
|
25
|
+
onChange: OnChangeType;
|
|
26
|
+
}[]>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export class QrveyCacheManager {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.stores = new Map();
|
|
4
|
+
}
|
|
5
|
+
getStoreFromPromise(config, id) {
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
const configProperty = this.getConfigPropertyName();
|
|
8
|
+
const storeProperty = this.getStorePropertyName();
|
|
9
|
+
const extendedConfig = Object.assign(Object.assign({}, config), { [configProperty]: id });
|
|
10
|
+
const store = this.getStore(extendedConfig);
|
|
11
|
+
if (store.state[storeProperty] !== null) {
|
|
12
|
+
resolve(store);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
const unsubscribe = store.onChange(storeProperty, (entity) => {
|
|
16
|
+
if (entity !== null) {
|
|
17
|
+
unsubscribe();
|
|
18
|
+
resolve(store);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
getStore(config) {
|
|
25
|
+
const storeId = this.buildStoreId(config);
|
|
26
|
+
const store = this.stores.get(storeId);
|
|
27
|
+
if (store) {
|
|
28
|
+
return store;
|
|
29
|
+
}
|
|
30
|
+
const { state, onChange } = store !== null && store !== void 0 ? store : this.createStore();
|
|
31
|
+
this.stores.set(storeId, { state, onChange });
|
|
32
|
+
this.fetchDataAndUpdateStore(state, config);
|
|
33
|
+
return { state, onChange };
|
|
34
|
+
}
|
|
35
|
+
getMultipleStores(config, ids) {
|
|
36
|
+
const promises = ids.map((id) => this.getStoreFromPromise(config, id));
|
|
37
|
+
return Promise.all(promises);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { OnChangeType, QrveyCacheManager } from "./cache-manager";
|
|
2
|
+
export interface IGetMetricConfig {
|
|
3
|
+
qv_token?: string;
|
|
4
|
+
api_key?: string;
|
|
5
|
+
app_id?: string;
|
|
6
|
+
user_id?: string;
|
|
7
|
+
domain?: string;
|
|
8
|
+
timezone?: any;
|
|
9
|
+
qrvey_id?: string;
|
|
10
|
+
i18n?: any;
|
|
11
|
+
metric_id?: string;
|
|
12
|
+
lang?: string;
|
|
13
|
+
translated?: boolean;
|
|
14
|
+
headers?: {
|
|
15
|
+
"temporal-tokens"?: boolean;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface IMetricStoreState {
|
|
19
|
+
metric: any;
|
|
20
|
+
loading: boolean;
|
|
21
|
+
error: any;
|
|
22
|
+
}
|
|
23
|
+
export declare class MetricCacheManager extends QrveyCacheManager<IMetricStoreState, IGetMetricConfig> {
|
|
24
|
+
static getInstance(): MetricCacheManager;
|
|
25
|
+
protected getConfigPropertyName(): keyof IGetMetricConfig;
|
|
26
|
+
protected getStorePropertyName(): keyof IMetricStoreState;
|
|
27
|
+
protected buildStoreId({ metric_id, translated }: IGetMetricConfig): string;
|
|
28
|
+
protected createStore(): {
|
|
29
|
+
state: IMetricStoreState;
|
|
30
|
+
onChange: OnChangeType;
|
|
31
|
+
};
|
|
32
|
+
protected fetchDataAndUpdateStore(state: IMetricStoreState, config: IGetMetricConfig): void;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createStore } from "@stencil/store";
|
|
2
|
+
import { QrveyCacheManager } from "./cache-manager";
|
|
3
|
+
import { isEmpty } from "../general/mix/isEmpty";
|
|
4
|
+
import MetricPanelApi from "../services/api/metrics.api";
|
|
5
|
+
export class MetricCacheManager extends QrveyCacheManager {
|
|
6
|
+
static getInstance() {
|
|
7
|
+
if (!window.metricCacheManager) {
|
|
8
|
+
window.metricCacheManager = new MetricCacheManager();
|
|
9
|
+
}
|
|
10
|
+
return window.metricCacheManager;
|
|
11
|
+
}
|
|
12
|
+
getConfigPropertyName() {
|
|
13
|
+
return "metric_id";
|
|
14
|
+
}
|
|
15
|
+
getStorePropertyName() {
|
|
16
|
+
return "metric";
|
|
17
|
+
}
|
|
18
|
+
buildStoreId({ metric_id, translated }) {
|
|
19
|
+
const translate = isEmpty(translated) ? true : translated;
|
|
20
|
+
return `${metric_id}-${translate ? "translated" : ""}`;
|
|
21
|
+
}
|
|
22
|
+
createStore() {
|
|
23
|
+
return createStore({
|
|
24
|
+
metric: null,
|
|
25
|
+
loading: true,
|
|
26
|
+
error: null,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
fetchDataAndUpdateStore(state, config) {
|
|
30
|
+
const api = new MetricPanelApi();
|
|
31
|
+
api
|
|
32
|
+
.getMetricConfig(config)
|
|
33
|
+
.then((metric) => {
|
|
34
|
+
state.metric = metric;
|
|
35
|
+
state.error = null;
|
|
36
|
+
state.loading = false;
|
|
37
|
+
})
|
|
38
|
+
.catch((e) => {
|
|
39
|
+
state.error = e;
|
|
40
|
+
state.loading = false;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { OnChangeType, QrveyCacheManager } from "./cache-manager";
|
|
2
|
+
import { IModel } from "../qrvey";
|
|
3
|
+
interface IGetModelConfig {
|
|
4
|
+
qv_token?: string;
|
|
5
|
+
api_key?: string;
|
|
6
|
+
app_id?: string;
|
|
7
|
+
user_id?: string;
|
|
8
|
+
domain?: string;
|
|
9
|
+
timezone?: any;
|
|
10
|
+
qrvey_id: string;
|
|
11
|
+
i18n?: any;
|
|
12
|
+
}
|
|
13
|
+
interface IModelStoreState {
|
|
14
|
+
model: IModel;
|
|
15
|
+
loading: boolean;
|
|
16
|
+
error: any;
|
|
17
|
+
}
|
|
18
|
+
export declare class ModelCacheManager extends QrveyCacheManager<IModelStoreState, IGetModelConfig> {
|
|
19
|
+
static getInstance(): ModelCacheManager;
|
|
20
|
+
protected getConfigPropertyName(): keyof IGetModelConfig;
|
|
21
|
+
protected getStorePropertyName(): keyof IModelStoreState;
|
|
22
|
+
protected buildStoreId({ qrvey_id }: IGetModelConfig): string;
|
|
23
|
+
protected createStore(): {
|
|
24
|
+
state: IModelStoreState;
|
|
25
|
+
onChange: OnChangeType;
|
|
26
|
+
};
|
|
27
|
+
protected fetchDataAndUpdateStore(state: IModelStoreState, config: IGetModelConfig): void;
|
|
28
|
+
}
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createStore } from "@stencil/store";
|
|
2
|
+
import { QrveyCacheManager } from "./cache-manager";
|
|
3
|
+
import { getModel } from "../services/api/getModel.api";
|
|
4
|
+
export class ModelCacheManager extends QrveyCacheManager {
|
|
5
|
+
static getInstance() {
|
|
6
|
+
if (!window.modelCacheManager) {
|
|
7
|
+
window.modelCacheManager = new ModelCacheManager();
|
|
8
|
+
}
|
|
9
|
+
return window.modelCacheManager;
|
|
10
|
+
}
|
|
11
|
+
getConfigPropertyName() {
|
|
12
|
+
return "qrvey_id";
|
|
13
|
+
}
|
|
14
|
+
getStorePropertyName() {
|
|
15
|
+
return "model";
|
|
16
|
+
}
|
|
17
|
+
buildStoreId({ qrvey_id }) {
|
|
18
|
+
return `${qrvey_id}`;
|
|
19
|
+
}
|
|
20
|
+
createStore() {
|
|
21
|
+
return createStore({
|
|
22
|
+
model: null,
|
|
23
|
+
loading: true,
|
|
24
|
+
error: null,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
fetchDataAndUpdateStore(state, config) {
|
|
28
|
+
const includeInfo = ["bucketsInfo", "formulaInfo", "colorByValueInfo"];
|
|
29
|
+
getModel(config, { includeInfo })
|
|
30
|
+
.then((model) => {
|
|
31
|
+
state.model = model;
|
|
32
|
+
state.error = null;
|
|
33
|
+
state.loading = false;
|
|
34
|
+
})
|
|
35
|
+
.catch((e) => {
|
|
36
|
+
state.error = e;
|
|
37
|
+
state.loading = false;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AdminPermissions } from "../interfaces/AdminPermissions.interface";
|
|
2
|
+
import { OnChangeType, QrveyCacheManager } from "./cache-manager";
|
|
3
|
+
export interface IGetPermissionsConfig {
|
|
4
|
+
qv_token?: string;
|
|
5
|
+
api_key?: string;
|
|
6
|
+
app_id?: string;
|
|
7
|
+
user_id?: string;
|
|
8
|
+
domain?: string;
|
|
9
|
+
}
|
|
10
|
+
interface IPermissionsStoreState {
|
|
11
|
+
permissions: AdminPermissions;
|
|
12
|
+
loading: boolean;
|
|
13
|
+
error: any;
|
|
14
|
+
}
|
|
15
|
+
export declare class PermissionsCacheManager extends QrveyCacheManager<IPermissionsStoreState, IGetPermissionsConfig> {
|
|
16
|
+
static getInstance(): PermissionsCacheManager;
|
|
17
|
+
protected getConfigPropertyName(): keyof IGetPermissionsConfig;
|
|
18
|
+
protected getStorePropertyName(): keyof IPermissionsStoreState;
|
|
19
|
+
protected buildStoreId({ user_id }: IGetPermissionsConfig): string;
|
|
20
|
+
protected createStore(): {
|
|
21
|
+
state: IPermissionsStoreState;
|
|
22
|
+
onChange: OnChangeType;
|
|
23
|
+
};
|
|
24
|
+
protected fetchDataAndUpdateStore(state: IPermissionsStoreState, config: IGetPermissionsConfig): void;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createStore } from "@stencil/store";
|
|
2
|
+
import { QrveyCacheManager } from "./cache-manager";
|
|
3
|
+
import { getAdminPermissions } from "../services/api/adminPermissions.api";
|
|
4
|
+
export class PermissionsCacheManager extends QrveyCacheManager {
|
|
5
|
+
static getInstance() {
|
|
6
|
+
if (!window.permissionsCacheManager) {
|
|
7
|
+
window.permissionsCacheManager = new PermissionsCacheManager();
|
|
8
|
+
}
|
|
9
|
+
return window.permissionsCacheManager;
|
|
10
|
+
}
|
|
11
|
+
getConfigPropertyName() {
|
|
12
|
+
return "user_id";
|
|
13
|
+
}
|
|
14
|
+
getStorePropertyName() {
|
|
15
|
+
return "permissions";
|
|
16
|
+
}
|
|
17
|
+
buildStoreId({ user_id }) {
|
|
18
|
+
return `${user_id}`;
|
|
19
|
+
}
|
|
20
|
+
createStore() {
|
|
21
|
+
return createStore({
|
|
22
|
+
permissions: null,
|
|
23
|
+
loading: true,
|
|
24
|
+
error: null,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
fetchDataAndUpdateStore(state, config) {
|
|
28
|
+
getAdminPermissions(config)
|
|
29
|
+
.then((permissions) => {
|
|
30
|
+
state.permissions = permissions;
|
|
31
|
+
state.error = null;
|
|
32
|
+
state.loading = false;
|
|
33
|
+
})
|
|
34
|
+
.catch((e) => {
|
|
35
|
+
state.error = e;
|
|
36
|
+
state.loading = false;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { OnChangeType, QrveyCacheManager } from "./cache-manager";
|
|
2
|
+
import { AnTheme } from "../interfaces/themes/an-theme";
|
|
3
|
+
export interface IGetThemeConfig {
|
|
4
|
+
qv_token?: string;
|
|
5
|
+
api_key?: string;
|
|
6
|
+
app_id?: string;
|
|
7
|
+
user_id?: string;
|
|
8
|
+
domain?: string;
|
|
9
|
+
theme_id?: string;
|
|
10
|
+
}
|
|
11
|
+
interface IThemeStoreState {
|
|
12
|
+
theme: AnTheme;
|
|
13
|
+
loading: boolean;
|
|
14
|
+
error: any;
|
|
15
|
+
}
|
|
16
|
+
export declare class ThemeCacheManager extends QrveyCacheManager<IThemeStoreState, IGetThemeConfig> {
|
|
17
|
+
static getInstance(): ThemeCacheManager;
|
|
18
|
+
protected getConfigPropertyName(): keyof IGetThemeConfig;
|
|
19
|
+
protected getStorePropertyName(): keyof IThemeStoreState;
|
|
20
|
+
protected buildStoreId({ theme_id, app_id }: IGetThemeConfig): string;
|
|
21
|
+
protected createStore(): {
|
|
22
|
+
state: IThemeStoreState;
|
|
23
|
+
onChange: OnChangeType;
|
|
24
|
+
};
|
|
25
|
+
protected fetchDataAndUpdateStore(state: IThemeStoreState, config: IGetThemeConfig): void;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createStore } from "@stencil/store";
|
|
2
|
+
import { QrveyCacheManager } from "./cache-manager";
|
|
3
|
+
import { getCurrentTheme, getThemeById } from "../services/api/Themes.api";
|
|
4
|
+
export class ThemeCacheManager extends QrveyCacheManager {
|
|
5
|
+
static getInstance() {
|
|
6
|
+
if (!window.themeCacheManager) {
|
|
7
|
+
window.themeCacheManager = new ThemeCacheManager();
|
|
8
|
+
}
|
|
9
|
+
return window.themeCacheManager;
|
|
10
|
+
}
|
|
11
|
+
getConfigPropertyName() {
|
|
12
|
+
return "theme_id";
|
|
13
|
+
}
|
|
14
|
+
getStorePropertyName() {
|
|
15
|
+
return "theme";
|
|
16
|
+
}
|
|
17
|
+
buildStoreId({ theme_id, app_id }) {
|
|
18
|
+
return `${app_id}-${theme_id !== null && theme_id !== void 0 ? theme_id : "current"}`;
|
|
19
|
+
}
|
|
20
|
+
createStore() {
|
|
21
|
+
return createStore({
|
|
22
|
+
theme: null,
|
|
23
|
+
loading: true,
|
|
24
|
+
error: null,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
fetchDataAndUpdateStore(state, config) {
|
|
28
|
+
(config.theme_id ? getThemeById(config) : getCurrentTheme(config))
|
|
29
|
+
.then((theme) => {
|
|
30
|
+
state.theme = theme;
|
|
31
|
+
state.error = null;
|
|
32
|
+
state.loading = false;
|
|
33
|
+
})
|
|
34
|
+
.catch((e) => {
|
|
35
|
+
state.error = e;
|
|
36
|
+
state.loading = false;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { OnChangeType, QrveyCacheManager } from "./cache-manager";
|
|
2
|
+
export interface IGetChartConfig {
|
|
3
|
+
qv_token?: string;
|
|
4
|
+
api_key?: string;
|
|
5
|
+
app_id?: string;
|
|
6
|
+
user_id?: string;
|
|
7
|
+
domain?: string;
|
|
8
|
+
timezone?: any;
|
|
9
|
+
qrvey_id?: string;
|
|
10
|
+
i18n?: any;
|
|
11
|
+
chart_id?: string;
|
|
12
|
+
lang?: string;
|
|
13
|
+
translated?: boolean;
|
|
14
|
+
headers?: {
|
|
15
|
+
"temporal-tokens"?: boolean;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface IChartStoreState {
|
|
19
|
+
chart: any;
|
|
20
|
+
loading: boolean;
|
|
21
|
+
error: any;
|
|
22
|
+
}
|
|
23
|
+
export declare class ChartCacheManager extends QrveyCacheManager<IChartStoreState, IGetChartConfig> {
|
|
24
|
+
static getInstance(): ChartCacheManager;
|
|
25
|
+
protected getConfigPropertyName(): keyof IGetChartConfig;
|
|
26
|
+
protected getStorePropertyName(): keyof IChartStoreState;
|
|
27
|
+
protected buildStoreId({ chart_id, translated }: IGetChartConfig): string;
|
|
28
|
+
protected createStore(): {
|
|
29
|
+
state: IChartStoreState;
|
|
30
|
+
onChange: OnChangeType;
|
|
31
|
+
};
|
|
32
|
+
protected fetchDataAndUpdateStore(state: IChartStoreState, config: IGetChartConfig): void;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ChartCacheManager = void 0;
|
|
7
|
+
const store_1 = require("@stencil/store");
|
|
8
|
+
const cache_manager_1 = require("./cache-manager");
|
|
9
|
+
const Charts_api_1 = __importDefault(require("../services/api/Charts.api"));
|
|
10
|
+
const isEmpty_1 = require("../general/mix/isEmpty");
|
|
11
|
+
class ChartCacheManager extends cache_manager_1.QrveyCacheManager {
|
|
12
|
+
static getInstance() {
|
|
13
|
+
if (!window.chartCacheManager) {
|
|
14
|
+
window.chartCacheManager = new ChartCacheManager();
|
|
15
|
+
}
|
|
16
|
+
return window.chartCacheManager;
|
|
17
|
+
}
|
|
18
|
+
getConfigPropertyName() {
|
|
19
|
+
return "chart_id";
|
|
20
|
+
}
|
|
21
|
+
getStorePropertyName() {
|
|
22
|
+
return "chart";
|
|
23
|
+
}
|
|
24
|
+
buildStoreId({ chart_id, translated }) {
|
|
25
|
+
const translate = (0, isEmpty_1.isEmpty)(translated) ? true : translated;
|
|
26
|
+
return `${chart_id}-${translate ? "translated" : ""}`;
|
|
27
|
+
}
|
|
28
|
+
createStore() {
|
|
29
|
+
return (0, store_1.createStore)({
|
|
30
|
+
chart: null,
|
|
31
|
+
loading: true,
|
|
32
|
+
error: null,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
fetchDataAndUpdateStore(state, config) {
|
|
36
|
+
const api = new Charts_api_1.default(config);
|
|
37
|
+
api
|
|
38
|
+
.getChart(config)
|
|
39
|
+
.then((chart) => {
|
|
40
|
+
state.chart = chart;
|
|
41
|
+
state.error = null;
|
|
42
|
+
state.loading = false;
|
|
43
|
+
})
|
|
44
|
+
.catch((e) => {
|
|
45
|
+
state.error = e;
|
|
46
|
+
state.loading = false;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.ChartCacheManager = ChartCacheManager;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type OnChangeType = (property: string | number | symbol, callback: (entity: unknown) => void) => () => void;
|
|
2
|
+
export declare abstract class QrveyCacheManager<TStoreState, TConfig> {
|
|
3
|
+
protected stores: Map<string, {
|
|
4
|
+
state: TStoreState;
|
|
5
|
+
onChange: OnChangeType;
|
|
6
|
+
}>;
|
|
7
|
+
protected abstract getConfigPropertyName(): keyof TConfig;
|
|
8
|
+
protected abstract getStorePropertyName(): keyof TStoreState;
|
|
9
|
+
protected abstract buildStoreId(config: TConfig): string;
|
|
10
|
+
protected abstract fetchDataAndUpdateStore(state: TStoreState, config: TConfig): void;
|
|
11
|
+
protected abstract createStore(): {
|
|
12
|
+
state: TStoreState;
|
|
13
|
+
onChange: OnChangeType;
|
|
14
|
+
};
|
|
15
|
+
protected getStoreFromPromise(config: TConfig, id: string): Promise<{
|
|
16
|
+
state: TStoreState;
|
|
17
|
+
onChange: OnChangeType;
|
|
18
|
+
}>;
|
|
19
|
+
getStore(config: TConfig): {
|
|
20
|
+
state: TStoreState;
|
|
21
|
+
onChange: OnChangeType;
|
|
22
|
+
};
|
|
23
|
+
getMultipleStores(config: TConfig, ids: string[]): Promise<{
|
|
24
|
+
state: TStoreState;
|
|
25
|
+
onChange: OnChangeType;
|
|
26
|
+
}[]>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QrveyCacheManager = void 0;
|
|
4
|
+
class QrveyCacheManager {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.stores = new Map();
|
|
7
|
+
}
|
|
8
|
+
getStoreFromPromise(config, id) {
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
const configProperty = this.getConfigPropertyName();
|
|
11
|
+
const storeProperty = this.getStorePropertyName();
|
|
12
|
+
const extendedConfig = Object.assign(Object.assign({}, config), { [configProperty]: id });
|
|
13
|
+
const store = this.getStore(extendedConfig);
|
|
14
|
+
if (store.state[storeProperty] !== null) {
|
|
15
|
+
resolve(store);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const unsubscribe = store.onChange(storeProperty, (entity) => {
|
|
19
|
+
if (entity !== null) {
|
|
20
|
+
unsubscribe();
|
|
21
|
+
resolve(store);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
getStore(config) {
|
|
28
|
+
const storeId = this.buildStoreId(config);
|
|
29
|
+
const store = this.stores.get(storeId);
|
|
30
|
+
if (store) {
|
|
31
|
+
return store;
|
|
32
|
+
}
|
|
33
|
+
const { state, onChange } = store !== null && store !== void 0 ? store : this.createStore();
|
|
34
|
+
this.stores.set(storeId, { state, onChange });
|
|
35
|
+
this.fetchDataAndUpdateStore(state, config);
|
|
36
|
+
return { state, onChange };
|
|
37
|
+
}
|
|
38
|
+
getMultipleStores(config, ids) {
|
|
39
|
+
const promises = ids.map((id) => this.getStoreFromPromise(config, id));
|
|
40
|
+
return Promise.all(promises);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.QrveyCacheManager = QrveyCacheManager;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { OnChangeType, QrveyCacheManager } from "./cache-manager";
|
|
2
|
+
export interface IGetMetricConfig {
|
|
3
|
+
qv_token?: string;
|
|
4
|
+
api_key?: string;
|
|
5
|
+
app_id?: string;
|
|
6
|
+
user_id?: string;
|
|
7
|
+
domain?: string;
|
|
8
|
+
timezone?: any;
|
|
9
|
+
qrvey_id?: string;
|
|
10
|
+
i18n?: any;
|
|
11
|
+
metric_id?: string;
|
|
12
|
+
lang?: string;
|
|
13
|
+
translated?: boolean;
|
|
14
|
+
headers?: {
|
|
15
|
+
"temporal-tokens"?: boolean;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface IMetricStoreState {
|
|
19
|
+
metric: any;
|
|
20
|
+
loading: boolean;
|
|
21
|
+
error: any;
|
|
22
|
+
}
|
|
23
|
+
export declare class MetricCacheManager extends QrveyCacheManager<IMetricStoreState, IGetMetricConfig> {
|
|
24
|
+
static getInstance(): MetricCacheManager;
|
|
25
|
+
protected getConfigPropertyName(): keyof IGetMetricConfig;
|
|
26
|
+
protected getStorePropertyName(): keyof IMetricStoreState;
|
|
27
|
+
protected buildStoreId({ metric_id, translated }: IGetMetricConfig): string;
|
|
28
|
+
protected createStore(): {
|
|
29
|
+
state: IMetricStoreState;
|
|
30
|
+
onChange: OnChangeType;
|
|
31
|
+
};
|
|
32
|
+
protected fetchDataAndUpdateStore(state: IMetricStoreState, config: IGetMetricConfig): void;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MetricCacheManager = void 0;
|
|
7
|
+
const store_1 = require("@stencil/store");
|
|
8
|
+
const cache_manager_1 = require("./cache-manager");
|
|
9
|
+
const isEmpty_1 = require("../general/mix/isEmpty");
|
|
10
|
+
const metrics_api_1 = __importDefault(require("../services/api/metrics.api"));
|
|
11
|
+
class MetricCacheManager extends cache_manager_1.QrveyCacheManager {
|
|
12
|
+
static getInstance() {
|
|
13
|
+
if (!window.metricCacheManager) {
|
|
14
|
+
window.metricCacheManager = new MetricCacheManager();
|
|
15
|
+
}
|
|
16
|
+
return window.metricCacheManager;
|
|
17
|
+
}
|
|
18
|
+
getConfigPropertyName() {
|
|
19
|
+
return "metric_id";
|
|
20
|
+
}
|
|
21
|
+
getStorePropertyName() {
|
|
22
|
+
return "metric";
|
|
23
|
+
}
|
|
24
|
+
buildStoreId({ metric_id, translated }) {
|
|
25
|
+
const translate = (0, isEmpty_1.isEmpty)(translated) ? true : translated;
|
|
26
|
+
return `${metric_id}-${translate ? "translated" : ""}`;
|
|
27
|
+
}
|
|
28
|
+
createStore() {
|
|
29
|
+
return (0, store_1.createStore)({
|
|
30
|
+
metric: null,
|
|
31
|
+
loading: true,
|
|
32
|
+
error: null,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
fetchDataAndUpdateStore(state, config) {
|
|
36
|
+
const api = new metrics_api_1.default();
|
|
37
|
+
api
|
|
38
|
+
.getMetricConfig(config)
|
|
39
|
+
.then((metric) => {
|
|
40
|
+
state.metric = metric;
|
|
41
|
+
state.error = null;
|
|
42
|
+
state.loading = false;
|
|
43
|
+
})
|
|
44
|
+
.catch((e) => {
|
|
45
|
+
state.error = e;
|
|
46
|
+
state.loading = false;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.MetricCacheManager = MetricCacheManager;
|