2018-10-25 00:45:22 -05:00
|
|
|
import { ThunkAction } from 'redux-thunk';
|
2018-10-26 07:15:37 -05:00
|
|
|
import { DashboardAcl, Organization, OrganizationPreferences, StoreState } from 'app/types';
|
2018-10-25 00:45:22 -05:00
|
|
|
import { getBackendSrv } from '../../../core/services/backend_srv';
|
|
|
|
|
2018-10-26 07:15:37 -05:00
|
|
|
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, any>;
|
|
|
|
|
2018-10-25 00:45:22 -05:00
|
|
|
export enum ActionTypes {
|
2018-10-26 07:15:37 -05:00
|
|
|
LoadOrganization = 'LOAD_ORGANISATION',
|
2018-10-25 00:45:22 -05:00
|
|
|
LoadPreferences = 'LOAD_PREFERENCES',
|
2018-10-25 09:56:49 -05:00
|
|
|
LoadStarredDashboards = 'LOAD_STARRED_DASHBOARDS',
|
2018-10-26 07:15:37 -05:00
|
|
|
SetOrganizationName = 'SET_ORGANIZATION_NAME',
|
|
|
|
SetOrganizationTheme = 'SET_ORGANIZATION_THEME',
|
|
|
|
SetOrganizationHomeDashboard = 'SET_ORGANIZATION_HOME_DASHBOARD',
|
|
|
|
SetOrganizationTimezone = 'SET_ORGANIZATION_TIMEZONE',
|
2018-10-25 00:45:22 -05:00
|
|
|
}
|
|
|
|
|
2018-10-25 09:56:49 -05:00
|
|
|
interface LoadOrganizationAction {
|
2018-10-26 07:15:37 -05:00
|
|
|
type: ActionTypes.LoadOrganization;
|
2018-10-25 09:56:49 -05:00
|
|
|
payload: Organization;
|
2018-10-25 00:45:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
interface LoadPreferencesAction {
|
|
|
|
type: ActionTypes.LoadPreferences;
|
2018-10-26 07:15:37 -05:00
|
|
|
payload: OrganizationPreferences;
|
2018-10-25 00:45:22 -05:00
|
|
|
}
|
|
|
|
|
2018-10-25 09:56:49 -05:00
|
|
|
interface LoadStarredDashboardsAction {
|
|
|
|
type: ActionTypes.LoadStarredDashboards;
|
|
|
|
payload: DashboardAcl[];
|
|
|
|
}
|
|
|
|
|
2018-10-26 07:15:37 -05:00
|
|
|
interface SetOrganizationNameAction {
|
|
|
|
type: ActionTypes.SetOrganizationName;
|
|
|
|
payload: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface SetOrganizationThemeAction {
|
|
|
|
type: ActionTypes.SetOrganizationTheme;
|
|
|
|
payload: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface SetOrganizationHomeDashboardAction {
|
|
|
|
type: ActionTypes.SetOrganizationHomeDashboard;
|
|
|
|
payload: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface SetOrganizationTimezoneAction {
|
|
|
|
type: ActionTypes.SetOrganizationTimezone;
|
|
|
|
payload: string;
|
|
|
|
}
|
|
|
|
|
2018-10-25 09:56:49 -05:00
|
|
|
const organisationLoaded = (organisation: Organization) => ({
|
2018-10-26 07:15:37 -05:00
|
|
|
type: ActionTypes.LoadOrganization,
|
2018-10-25 00:45:22 -05:00
|
|
|
payload: organisation,
|
|
|
|
});
|
|
|
|
|
2018-10-26 07:15:37 -05:00
|
|
|
const preferencesLoaded = (preferences: OrganizationPreferences) => ({
|
2018-10-25 00:45:22 -05:00
|
|
|
type: ActionTypes.LoadPreferences,
|
|
|
|
payload: preferences,
|
|
|
|
});
|
|
|
|
|
2018-10-25 09:56:49 -05:00
|
|
|
const starredDashboardsLoaded = (dashboards: DashboardAcl[]) => ({
|
|
|
|
type: ActionTypes.LoadStarredDashboards,
|
|
|
|
payload: dashboards,
|
|
|
|
});
|
|
|
|
|
2018-10-26 07:15:37 -05:00
|
|
|
export const setOrganizationName = (orgName: string) => ({
|
|
|
|
type: ActionTypes.SetOrganizationName,
|
|
|
|
payload: orgName,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const setOrganizationTheme = (theme: string) => ({
|
|
|
|
type: ActionTypes.SetOrganizationTheme,
|
|
|
|
payload: theme,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const setOrganizationHomeDashboard = (id: number) => ({
|
|
|
|
type: ActionTypes.SetOrganizationHomeDashboard,
|
|
|
|
payload: id,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const setOrganizationTimezone = (timezone: string) => ({
|
|
|
|
type: ActionTypes.SetOrganizationTimezone,
|
|
|
|
payload: timezone,
|
|
|
|
});
|
|
|
|
|
|
|
|
export type Action =
|
|
|
|
| LoadOrganizationAction
|
|
|
|
| LoadPreferencesAction
|
|
|
|
| LoadStarredDashboardsAction
|
|
|
|
| SetOrganizationNameAction
|
|
|
|
| SetOrganizationThemeAction
|
|
|
|
| SetOrganizationHomeDashboardAction
|
|
|
|
| SetOrganizationTimezoneAction;
|
2018-10-25 00:45:22 -05:00
|
|
|
|
2018-10-25 09:56:49 -05:00
|
|
|
export function loadOrganization(): ThunkResult<void> {
|
2018-10-25 00:45:22 -05:00
|
|
|
return async dispatch => {
|
2018-10-26 07:15:37 -05:00
|
|
|
const organisationResponse = await loadOrg();
|
2018-10-25 00:45:22 -05:00
|
|
|
dispatch(organisationLoaded(organisationResponse));
|
2018-10-25 09:56:49 -05:00
|
|
|
|
|
|
|
return organisationResponse;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function loadOrganizationPreferences(): ThunkResult<void> {
|
|
|
|
return async dispatch => {
|
2018-10-26 07:15:37 -05:00
|
|
|
const preferencesResponse = await loadPreferences();
|
2018-10-25 00:45:22 -05:00
|
|
|
dispatch(preferencesLoaded(preferencesResponse));
|
2018-10-25 09:56:49 -05:00
|
|
|
|
|
|
|
const starredDashboards = await getBackendSrv().search({ starred: true });
|
|
|
|
dispatch(starredDashboardsLoaded(starredDashboards));
|
2018-10-25 00:45:22 -05:00
|
|
|
};
|
|
|
|
}
|
2018-10-26 07:15:37 -05:00
|
|
|
|
|
|
|
export async function loadOrg() {
|
|
|
|
return await await getBackendSrv().get('/api/org');
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function loadPreferences() {
|
|
|
|
return await getBackendSrv().get('/api/org/preferences');
|
|
|
|
}
|