Initial commit
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
export function canCreateDatasets (state) {
|
||||
if (!state.remaining_byte_quota || state.remaining_byte_quota <= 0 || isOutOfDatasetsQuota(state)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return hasCreateDatasetsFeature(state);
|
||||
}
|
||||
|
||||
export function hasCreateDatasetsFeature (state) {
|
||||
return isBuilder(state);
|
||||
}
|
||||
|
||||
export function isBuilder (state) {
|
||||
return !isViewer(state);
|
||||
}
|
||||
|
||||
export function isViewer (state) {
|
||||
return state.viewer === true;
|
||||
}
|
||||
|
||||
export function hasEngine (state) {
|
||||
return state.actions.engine_enabled === true;
|
||||
}
|
||||
|
||||
export function isNotificationVisible (state) {
|
||||
return state.notification && state.showNotification;
|
||||
}
|
||||
|
||||
export function userNotification (state) {
|
||||
return state.notification ? state.notification : null;
|
||||
}
|
||||
|
||||
export function getPublicMapsCount (state) {
|
||||
return (state.link_privacy_map_count + state.password_privacy_map_count + state.public_privacy_map_count) || 0;
|
||||
}
|
||||
|
||||
export function getPublicMapsQuota (state) {
|
||||
return state.public_map_quota;
|
||||
}
|
||||
|
||||
export function isOutOfPublicMapsQuota (state) {
|
||||
return getPublicMapsQuota(state) && getPublicMapsCount(state) >= getPublicMapsQuota(state);
|
||||
}
|
||||
|
||||
export function getDatasetsCount (state) {
|
||||
return state.table_count;
|
||||
}
|
||||
|
||||
export function getDatasetsQuota (state) {
|
||||
return state.table_quota;
|
||||
}
|
||||
|
||||
export function isOutOfDatasetsQuota (state) {
|
||||
return getDatasetsQuota(state) && getDatasetsCount(state) >= getDatasetsQuota(state);
|
||||
}
|
||||
|
||||
export function isOrganizationUser (state) {
|
||||
return Boolean(state.organization);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import CartoNode from 'carto-node';
|
||||
import getCARTOData from 'new-dashboard/store/utils/getCARTOData';
|
||||
|
||||
import * as getters from './getters';
|
||||
|
||||
const client = new CartoNode.AuthenticatedClient();
|
||||
|
||||
// Data coming from Static Page Loading,
|
||||
// which requests user and config data from
|
||||
// /me API endpoint.
|
||||
const CARTOData = getCARTOData();
|
||||
|
||||
const user = {
|
||||
namespaced: true,
|
||||
state: {
|
||||
...CARTOData.user_data,
|
||||
organizationNotifications: CARTOData.organization_notifications || [],
|
||||
showNotification: true
|
||||
},
|
||||
getters: {
|
||||
canCreateDatasets: getters.canCreateDatasets,
|
||||
isViewer: getters.isViewer,
|
||||
hasEngine: getters.hasEngine,
|
||||
userNotification: getters.userNotification,
|
||||
isNotificationVisible: getters.isNotificationVisible,
|
||||
publicMapsCount: getters.getPublicMapsCount,
|
||||
publicMapsQuota: getters.getPublicMapsQuota,
|
||||
isOutOfPublicMapsQuota: getters.isOutOfPublicMapsQuota,
|
||||
datasetsCount: getters.getDatasetsCount,
|
||||
datasetsQuota: getters.getDatasetsQuota,
|
||||
isOutOfDatasetsQuota: getters.isOutOfDatasetsQuota,
|
||||
isOrganizationUser: getters.isOrganizationUser
|
||||
},
|
||||
mutations: {
|
||||
setUserData (state, userData) {
|
||||
Object.assign(state, userData);
|
||||
},
|
||||
setOrganizationNotifications (state, organizationNotifications) {
|
||||
state.organizationNotifications = organizationNotifications;
|
||||
},
|
||||
setShowNotification (state, showNotification) {
|
||||
state.showNotification = showNotification;
|
||||
},
|
||||
updateTableCount (state, newTableCount) {
|
||||
state.table_count = newTableCount;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
updateData (context) {
|
||||
client.getConfig(function (err, _, data) {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
context.commit('setUserData', data.user_data);
|
||||
});
|
||||
},
|
||||
resetOrganizationNotifications (context) {
|
||||
context.commit('setOrganizationNotifications', []);
|
||||
},
|
||||
hideUserNotification (context) {
|
||||
context.commit('setShowNotification', false);
|
||||
},
|
||||
updateTableCount (context, newTableCount) {
|
||||
context.commit('updateTableCount', newTableCount);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default user;
|
||||
Reference in New Issue
Block a user