Refactor and modularize analytics on the client
Этот коммит содержится в:
@@ -11,16 +11,17 @@ import UserStore from '../stores/user_store.jsx';
|
||||
import * as utils from './utils.jsx';
|
||||
|
||||
import Constants from './constants.jsx';
|
||||
var ActionTypes = Constants.ActionTypes;
|
||||
const ActionTypes = Constants.ActionTypes;
|
||||
const StatTypes = Constants.StatTypes;
|
||||
|
||||
// Used to track in progress async calls
|
||||
var callTracker = {};
|
||||
const callTracker = {};
|
||||
|
||||
export function dispatchError(err, method) {
|
||||
AppDispatcher.handleServerAction({
|
||||
type: ActionTypes.RECEIVED_ERROR,
|
||||
err: err,
|
||||
method: method
|
||||
err,
|
||||
method
|
||||
});
|
||||
}
|
||||
|
||||
@@ -848,3 +849,264 @@ export function getFileInfo(filename) {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function getStandardAnalytics(teamId) {
|
||||
const callName = 'getStandardAnaytics' + teamId;
|
||||
|
||||
if (isCallInProgress(callName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
callTracker[callName] = utils.getTimestamp();
|
||||
|
||||
client.getAnalytics(
|
||||
'standard',
|
||||
teamId,
|
||||
(data) => {
|
||||
callTracker[callName] = 0;
|
||||
|
||||
const stats = {};
|
||||
|
||||
for (const index in data) {
|
||||
if (data[index].name === 'channel_open_count') {
|
||||
stats[StatTypes.TOTAL_PUBLIC_CHANNELS] = data[index].value;
|
||||
}
|
||||
|
||||
if (data[index].name === 'channel_private_count') {
|
||||
stats[StatTypes.TOTAL_PRIVATE_GROUPS] = data[index].value;
|
||||
}
|
||||
|
||||
if (data[index].name === 'post_count') {
|
||||
stats[StatTypes.TOTAL_POSTS] = data[index].value;
|
||||
}
|
||||
|
||||
if (data[index].name === 'unique_user_count') {
|
||||
stats[StatTypes.TOTAL_USERS] = data[index].value;
|
||||
}
|
||||
|
||||
if (data[index].name === 'team_count' && teamId == null) {
|
||||
stats[StatTypes.TOTAL_TEAMS] = data[index].value;
|
||||
}
|
||||
}
|
||||
|
||||
AppDispatcher.handleServerAction({
|
||||
type: ActionTypes.RECEIVED_ANALYTICS,
|
||||
teamId,
|
||||
stats
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
callTracker[callName] = 0;
|
||||
|
||||
dispatchError(err, 'getStandardAnalytics');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function getAdvancedAnalytics(teamId) {
|
||||
const callName = 'getAdvancedAnalytics' + teamId;
|
||||
|
||||
if (isCallInProgress(callName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
callTracker[callName] = utils.getTimestamp();
|
||||
|
||||
client.getAnalytics(
|
||||
'extra_counts',
|
||||
teamId,
|
||||
(data) => {
|
||||
callTracker[callName] = 0;
|
||||
|
||||
const stats = {};
|
||||
|
||||
for (const index in data) {
|
||||
if (data[index].name === 'file_post_count') {
|
||||
stats[StatTypes.TOTAL_FILE_POSTS] = data[index].value;
|
||||
}
|
||||
|
||||
if (data[index].name === 'hashtag_post_count') {
|
||||
stats[StatTypes.TOTAL_HASHTAG_POSTS] = data[index].value;
|
||||
}
|
||||
|
||||
if (data[index].name === 'incoming_webhook_count') {
|
||||
stats[StatTypes.TOTAL_IHOOKS] = data[index].value;
|
||||
}
|
||||
|
||||
if (data[index].name === 'outgoing_webhook_count') {
|
||||
stats[StatTypes.TOTAL_OHOOKS] = data[index].value;
|
||||
}
|
||||
|
||||
if (data[index].name === 'command_count') {
|
||||
stats[StatTypes.TOTAL_COMMANDS] = data[index].value;
|
||||
}
|
||||
|
||||
if (data[index].name === 'session_count') {
|
||||
stats[StatTypes.TOTAL_SESSIONS] = data[index].value;
|
||||
}
|
||||
}
|
||||
|
||||
AppDispatcher.handleServerAction({
|
||||
type: ActionTypes.RECEIVED_ANALYTICS,
|
||||
teamId,
|
||||
stats
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
callTracker[callName] = 0;
|
||||
|
||||
dispatchError(err, 'getAdvancedAnalytics');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function getPostsPerDayAnalytics(teamId) {
|
||||
const callName = 'getPostsPerDayAnalytics' + teamId;
|
||||
|
||||
if (isCallInProgress(callName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
callTracker[callName] = utils.getTimestamp();
|
||||
|
||||
client.getAnalytics(
|
||||
'post_counts_day',
|
||||
teamId,
|
||||
(data) => {
|
||||
callTracker[callName] = 0;
|
||||
|
||||
data.reverse();
|
||||
|
||||
const stats = {};
|
||||
stats[StatTypes.POST_PER_DAY] = data;
|
||||
|
||||
AppDispatcher.handleServerAction({
|
||||
type: ActionTypes.RECEIVED_ANALYTICS,
|
||||
teamId,
|
||||
stats
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
callTracker[callName] = 0;
|
||||
|
||||
dispatchError(err, 'getPostsPerDayAnalytics');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function getUsersPerDayAnalytics(teamId) {
|
||||
const callName = 'getUsersPerDayAnalytics' + teamId;
|
||||
|
||||
if (isCallInProgress(callName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
callTracker[callName] = utils.getTimestamp();
|
||||
|
||||
client.getAnalytics(
|
||||
'user_counts_with_posts_day',
|
||||
teamId,
|
||||
(data) => {
|
||||
callTracker[callName] = 0;
|
||||
|
||||
data.reverse();
|
||||
|
||||
const stats = {};
|
||||
stats[StatTypes.USERS_WITH_POSTS_PER_DAY] = data;
|
||||
|
||||
AppDispatcher.handleServerAction({
|
||||
type: ActionTypes.RECEIVED_ANALYTICS,
|
||||
teamId,
|
||||
stats
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
callTracker[callName] = 0;
|
||||
|
||||
dispatchError(err, 'getUsersPerDayAnalytics');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function getRecentAndNewUsersAnalytics(teamId) {
|
||||
const callName = 'getRecentAndNewUsersAnalytics' + teamId;
|
||||
|
||||
if (isCallInProgress(callName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
callTracker[callName] = utils.getTimestamp();
|
||||
|
||||
client.getProfilesForTeam(
|
||||
teamId,
|
||||
(users) => {
|
||||
const stats = {};
|
||||
|
||||
const usersList = [];
|
||||
for (const id in users) {
|
||||
if (users.hasOwnProperty(id)) {
|
||||
usersList.push(users[id]);
|
||||
}
|
||||
}
|
||||
|
||||
usersList.sort((a, b) => {
|
||||
if (a.last_activity_at < b.last_activity_at) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (a.last_activity_at > b.last_activity_at) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
const recentActive = [];
|
||||
for (let i = 0; i < usersList.length; i++) {
|
||||
if (usersList[i].last_activity_at == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
recentActive.push(usersList[i]);
|
||||
if (i >= Constants.STAT_MAX_ACTIVE_USERS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
stats[StatTypes.RECENTLY_ACTIVE_USERS] = recentActive;
|
||||
|
||||
usersList.sort((a, b) => {
|
||||
if (a.create_at < b.create_at) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (a.create_at > b.create_at) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
var newlyCreated = [];
|
||||
for (let i = 0; i < usersList.length; i++) {
|
||||
newlyCreated.push(usersList[i]);
|
||||
if (i >= Constants.STAT_MAX_NEW_USERS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
stats[StatTypes.NEWLY_CREATED_USERS] = newlyCreated;
|
||||
|
||||
AppDispatcher.handleServerAction({
|
||||
type: ActionTypes.RECEIVED_ANALYTICS,
|
||||
teamId,
|
||||
stats
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
callTracker[callName] = 0;
|
||||
|
||||
dispatchError(err, 'getRecentAndNewUsersAnalytics');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user