Added ConfigStore that is populated from the server
Этот коммит содержится в:
@@ -5,7 +5,9 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
l4g "code.google.com/p/log4go"
|
l4g "code.google.com/p/log4go"
|
||||||
|
"encoding/json"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/mattermost/platform/model"
|
||||||
"github.com/mattermost/platform/utils"
|
"github.com/mattermost/platform/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -15,9 +17,23 @@ func InitConfig(r *mux.Router) {
|
|||||||
l4g.Debug("Initializing config api routes")
|
l4g.Debug("Initializing config api routes")
|
||||||
|
|
||||||
sr := r.PathPrefix("/config").Subrouter()
|
sr := r.PathPrefix("/config").Subrouter()
|
||||||
|
sr.Handle("/get_all", ApiAppHandler(getConfig)).Methods("GET")
|
||||||
sr.Handle("/get/bypass_email", ApiAppHandler(getBypassEmail)).Methods("GET")
|
sr.Handle("/get/bypass_email", ApiAppHandler(getBypassEmail)).Methods("GET")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
settings := make(map[string]string)
|
||||||
|
|
||||||
|
settings["ByPassEmail"] = strconv.FormatBool(utils.Cfg.EmailSettings.ByPassEmail)
|
||||||
|
|
||||||
|
if bytes, err := json.Marshal(settings); err != nil {
|
||||||
|
c.Err = model.NewAppError("getConfig", "Unable to marshall configuration data", err.Error())
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
w.Write(bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getBypassEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
func getBypassEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write([]byte(strconv.FormatBool(utils.Cfg.EmailSettings.ByPassEmail)))
|
w.Write([]byte(strconv.FormatBool(utils.Cfg.EmailSettings.ByPassEmail)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
|
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
|
||||||
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
|
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
|
||||||
var Navbar = require('../components/navbar.jsx');
|
var Navbar = require('../components/navbar.jsx');
|
||||||
var Sidebar = require('../components/sidebar.jsx');
|
var Sidebar = require('../components/sidebar.jsx');
|
||||||
@@ -36,11 +35,13 @@ var AccessHistoryModal = require('../components/access_history_modal.jsx');
|
|||||||
var ActivityLogModal = require('../components/activity_log_modal.jsx');
|
var ActivityLogModal = require('../components/activity_log_modal.jsx');
|
||||||
var RemovedFromChannelModal = require('../components/removed_from_channel_modal.jsx')
|
var RemovedFromChannelModal = require('../components/removed_from_channel_modal.jsx')
|
||||||
|
|
||||||
|
var AsyncClient = require('../utils/async_client.jsx');
|
||||||
|
|
||||||
var Constants = require('../utils/constants.jsx');
|
var Constants = require('../utils/constants.jsx');
|
||||||
var ActionTypes = Constants.ActionTypes;
|
var ActionTypes = Constants.ActionTypes;
|
||||||
|
|
||||||
global.window.setup_channel_page = function(team_name, team_type, team_id, channel_name, channel_id) {
|
global.window.setup_channel_page = function(team_name, team_type, team_id, channel_name, channel_id) {
|
||||||
|
AsyncClient.getConfig();
|
||||||
|
|
||||||
AppDispatcher.handleViewAction({
|
AppDispatcher.handleViewAction({
|
||||||
type: ActionTypes.CLICK_CHANNEL,
|
type: ActionTypes.CLICK_CHANNEL,
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
|
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
|
||||||
// See License.txt for license information.
|
// See License.txt for license information.
|
||||||
|
|
||||||
var SignupTeam =require('../components/signup_team.jsx');
|
var SignupTeam = require('../components/signup_team.jsx');
|
||||||
|
|
||||||
|
var AsyncClient = require('../utils/async_client.jsx');
|
||||||
|
|
||||||
global.window.setup_signup_team_page = function() {
|
global.window.setup_signup_team_page = function() {
|
||||||
|
AsyncClient.getConfig();
|
||||||
|
|
||||||
React.render(
|
React.render(
|
||||||
<SignupTeam />,
|
<SignupTeam />,
|
||||||
document.getElementById('signup-team')
|
document.getElementById('signup-team')
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
56
web/react/stores/config_store.jsx
Обычный файл
56
web/react/stores/config_store.jsx
Обычный файл
@@ -0,0 +1,56 @@
|
|||||||
|
// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
|
||||||
|
var EventEmitter = require('events').EventEmitter;
|
||||||
|
var assign = require('object-assign');
|
||||||
|
|
||||||
|
var BrowserStore = require('../stores/browser_store.jsx');
|
||||||
|
|
||||||
|
var Constants = require('../utils/constants.jsx');
|
||||||
|
var ActionTypes = Constants.ActionTypes;
|
||||||
|
|
||||||
|
var CHANGE_EVENT = 'change';
|
||||||
|
|
||||||
|
var ConfigStore = assign({}, EventEmitter.prototype, {
|
||||||
|
emitChange: function emitChange() {
|
||||||
|
this.emit(CHANGE_EVENT);
|
||||||
|
},
|
||||||
|
addChangeListener: function addChangeListener(callback) {
|
||||||
|
this.on(CHANGE_EVENT, callback);
|
||||||
|
},
|
||||||
|
removeChangeListener: function removeChangeListener(callback) {
|
||||||
|
this.removeListener(CHANGE_EVENT, callback);
|
||||||
|
},
|
||||||
|
getSetting: function getSetting(key, defaultValue) {
|
||||||
|
return BrowserStore.getItem('config_' + key, defaultValue);
|
||||||
|
},
|
||||||
|
getSettingAsBoolean: function getSettingAsNumber(key, defaultValue) {
|
||||||
|
var value = ConfigStore.getSetting(key, defaultValue);
|
||||||
|
|
||||||
|
if (typeof value !== 'string') {
|
||||||
|
return !!value;
|
||||||
|
} else {
|
||||||
|
return value === 'true';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
updateStoredSettings: function updateStoredSettings(settings) {
|
||||||
|
for (var key in settings) {
|
||||||
|
BrowserStore.setItem('config_' + key, settings[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ConfigStore.dispatchToken = AppDispatcher.register(function registry(payload) {
|
||||||
|
var action = payload.action;
|
||||||
|
|
||||||
|
switch (action.type) {
|
||||||
|
case ActionTypes.RECIEVED_CONFIG:
|
||||||
|
ConfigStore.updateStoredSettings(action.settings);
|
||||||
|
ConfigStore.emitChange();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = ConfigStore;
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
var client = require('./client.jsx');
|
var client = require('./client.jsx');
|
||||||
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
|
var AppDispatcher = require('../dispatcher/app_dispatcher.jsx');
|
||||||
var ChannelStore = require('../stores/channel_store.jsx');
|
var ChannelStore = require('../stores/channel_store.jsx');
|
||||||
|
var ConfigStore = require('../stores/config_store.jsx');
|
||||||
var PostStore = require('../stores/post_store.jsx');
|
var PostStore = require('../stores/post_store.jsx');
|
||||||
var UserStore = require('../stores/user_store.jsx');
|
var UserStore = require('../stores/user_store.jsx');
|
||||||
var utils = require('./utils.jsx');
|
var utils = require('./utils.jsx');
|
||||||
@@ -383,3 +384,28 @@ module.exports.getMyTeam = function() {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getConfig() {
|
||||||
|
if (isCallInProgress('getConfig')) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
callTracker['getConfig'] = utils.getTimestamp();
|
||||||
|
client.getConfig(
|
||||||
|
function(data, textStatus, xhr) {
|
||||||
|
callTracker['getConfig'] = 0;
|
||||||
|
|
||||||
|
if (data && xhr.status !== 304) {
|
||||||
|
AppDispatcher.handleServerAction({
|
||||||
|
type: ActionTypes.RECIEVED_CONFIG,
|
||||||
|
settings: data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function(err) {
|
||||||
|
callTracker['getConfig'] = 0;
|
||||||
|
dispatchError(err, 'getConfig');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
module.exports.getConfig = getConfig;
|
||||||
|
|||||||
@@ -850,6 +850,21 @@ module.exports.updateValetFeature = function(data, success, error) {
|
|||||||
module.exports.track('api', 'api_teams_update_valet_feature');
|
module.exports.track('api', 'api_teams_update_valet_feature');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getConfig(success, error) {
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/v1/config/get_all',
|
||||||
|
dataType: 'json',
|
||||||
|
type: 'GET',
|
||||||
|
ifModified: true,
|
||||||
|
success: success,
|
||||||
|
error: function(xhr, status, err) {
|
||||||
|
var e = handleError('getConfig', xhr, status, err);
|
||||||
|
error(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
module.exports.getConfig = getConfig;
|
||||||
|
|
||||||
module.exports.isEmailEnabledSynchronous = function() {
|
module.exports.isEmailEnabledSynchronous = function() {
|
||||||
var enabled = false;
|
var enabled = false;
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ module.exports = {
|
|||||||
|
|
||||||
CLICK_TEAM: null,
|
CLICK_TEAM: null,
|
||||||
RECIEVED_TEAM: null,
|
RECIEVED_TEAM: null,
|
||||||
|
|
||||||
|
RECIEVED_CONFIG: null
|
||||||
}),
|
}),
|
||||||
|
|
||||||
PayloadSources: keyMirror({
|
PayloadSources: keyMirror({
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user