summaryrefslogtreecommitdiffstats
path: root/webapp/stores/admin_store.jsx
blob: 59c7635755841c1c7c5ab582b64ec52e8177516d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

import AppDispatcher from '../dispatcher/app_dispatcher.jsx';
import EventEmitter from 'events';

import Constants from 'utils/constants.jsx';
const ActionTypes = Constants.ActionTypes;

const LOG_CHANGE_EVENT = 'log_change';
const SERVER_AUDIT_CHANGE_EVENT = 'server_audit_change';
const CONFIG_CHANGE_EVENT = 'config_change';
const ALL_TEAMS_EVENT = 'all_team_change';
const SERVER_COMPLIANCE_REPORT_CHANGE_EVENT = 'server_compliance_reports_change';

class AdminStoreClass extends EventEmitter {
    constructor() {
        super();

        this.logs = null;
        this.audits = null;
        this.config = null;
        this.clusterId = null;
        this.teams = {};
        this.complianceReports = null;
    }

    emitLogChange() {
        this.emit(LOG_CHANGE_EVENT);
    }

    addLogChangeListener(callback) {
        this.on(LOG_CHANGE_EVENT, callback);
    }

    removeLogChangeListener(callback) {
        this.removeListener(LOG_CHANGE_EVENT, callback);
    }

    emitAuditChange() {
        this.emit(SERVER_AUDIT_CHANGE_EVENT);
    }

    addAuditChangeListener(callback) {
        this.on(SERVER_AUDIT_CHANGE_EVENT, callback);
    }

    removeAuditChangeListener(callback) {
        this.removeListener(SERVER_AUDIT_CHANGE_EVENT, callback);
    }

    emitComplianceReportsChange() {
        this.emit(SERVER_COMPLIANCE_REPORT_CHANGE_EVENT);
    }

    addComplianceReportsChangeListener(callback) {
        this.on(SERVER_COMPLIANCE_REPORT_CHANGE_EVENT, callback);
    }

    removeComplianceReportsChangeListener(callback) {
        this.removeListener(SERVER_COMPLIANCE_REPORT_CHANGE_EVENT, callback);
    }

    emitConfigChange() {
        this.emit(CONFIG_CHANGE_EVENT);
    }

    addConfigChangeListener(callback) {
        this.on(CONFIG_CHANGE_EVENT, callback);
    }

    removeConfigChangeListener(callback) {
        this.removeListener(CONFIG_CHANGE_EVENT, callback);
    }

    emitAllTeamsChange() {
        this.emit(ALL_TEAMS_EVENT);
    }

    addAllTeamsChangeListener(callback) {
        this.on(ALL_TEAMS_EVENT, callback);
    }

    removeAllTeamsChangeListener(callback) {
        this.removeListener(ALL_TEAMS_EVENT, callback);
    }

    getClusterId() {
        return this.clusterId;
    }

    saveClusterId(clusterId) {
        this.clusterId = clusterId;
    }

    getLogs() {
        return this.logs;
    }

    saveLogs(logs) {
        this.logs = logs;
    }

    getAudits() {
        return this.audits;
    }

    saveAudits(audits) {
        this.audits = audits;
    }

    getComplianceReports() {
        return this.complianceReports;
    }

    saveComplianceReports(complianceReports) {
        this.complianceReports = complianceReports;
    }

    getConfig() {
        return this.config;
    }

    saveConfig(config) {
        this.config = config;
    }

    getAllTeams() {
        return this.teams;
    }

    saveAllTeams(teams) {
        this.teams = teams;
    }

    getTeam(id) {
        return this.teams[id];
    }
}

var AdminStore = new AdminStoreClass();

AdminStoreClass.dispatchToken = AppDispatcher.register((payload) => {
    var action = payload.action;

    switch (action.type) {
    case ActionTypes.RECEIVED_LOGS:
        AdminStore.saveLogs(action.logs);
        AdminStore.emitLogChange();
        break;
    case ActionTypes.RECEIVED_SERVER_AUDITS:
        AdminStore.saveAudits(action.audits);
        AdminStore.emitAuditChange();
        break;
    case ActionTypes.RECEIVED_SERVER_COMPLIANCE_REPORTS:
        AdminStore.saveComplianceReports(action.complianceReports);
        AdminStore.emitComplianceReportsChange();
        break;
    case ActionTypes.RECEIVED_CONFIG:
        AdminStore.saveConfig(action.config);
        AdminStore.saveClusterId(action.clusterId);
        AdminStore.emitConfigChange();
        break;
    case ActionTypes.RECEIVED_ALL_TEAMS:
        AdminStore.saveAllTeams(action.teams);
        AdminStore.emitAllTeamsChange();
        break;
    default:
    }
});

export default AdminStore;