// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react';
import * as Utils from 'utils/utils.jsx';
import AdminSettings from './admin_settings.jsx';
import DropdownSetting from './dropdown_setting.jsx';
import {FormattedMessage, FormattedHTMLMessage} from 'react-intl';
import SettingsGroup from './settings_group.jsx';
import TextSetting from './text_setting.jsx';
import BooleanSetting from './boolean_setting.jsx';
const DRIVER_LOCAL = 'local';
const DRIVER_S3 = 'amazons3';
export default class StorageSettings extends AdminSettings {
constructor(props) {
super(props);
this.getConfigFromState = this.getConfigFromState.bind(this);
this.renderSettings = this.renderSettings.bind(this);
}
getConfigFromState(config) {
config.FileSettings.EnableFileAttachments = this.state.enableFileAttachments;
config.FileSettings.MaxFileSize = this.parseInt(this.state.maxFileSize) * 1024 * 1024;
config.FileSettings.DriverName = this.state.driverName;
config.FileSettings.Directory = this.state.directory;
config.FileSettings.AmazonS3AccessKeyId = this.state.amazonS3AccessKeyId;
config.FileSettings.AmazonS3SecretAccessKey = this.state.amazonS3SecretAccessKey;
config.FileSettings.AmazonS3Bucket = this.state.amazonS3Bucket;
config.FileSettings.AmazonS3Endpoint = this.state.amazonS3Endpoint;
config.FileSettings.AmazonS3SSL = this.state.amazonS3SSL;
return config;
}
getStateFromConfig(config) {
return {
enableFileAttachments: config.FileSettings.EnableFileAttachments,
maxFileSize: config.FileSettings.MaxFileSize / 1024 / 1024,
driverName: config.FileSettings.DriverName,
directory: config.FileSettings.Directory,
amazonS3AccessKeyId: config.FileSettings.AmazonS3AccessKeyId,
amazonS3SecretAccessKey: config.FileSettings.AmazonS3SecretAccessKey,
amazonS3Bucket: config.FileSettings.AmazonS3Bucket,
amazonS3Endpoint: config.FileSettings.AmazonS3Endpoint,
amazonS3SSL: config.FileSettings.AmazonS3SSL
};
}
renderTitle() {
return (
);
}
renderSettings() {
return (
}
helpText={
}
value={this.state.driverName}
onChange={this.handleChange}
/>
}
placeholder={Utils.localizeMessage('admin.image.localExample', 'Ex "./data/"')}
helpText={
}
value={this.state.directory}
onChange={this.handleChange}
disabled={this.state.driverName !== DRIVER_LOCAL}
/>
}
placeholder={Utils.localizeMessage('admin.image.amazonS3IdExample', 'Ex "AKIADTOVBGERKLCBV"')}
helpText={
}
value={this.state.amazonS3AccessKeyId}
onChange={this.handleChange}
disabled={this.state.driverName !== DRIVER_S3}
/>
}
placeholder={Utils.localizeMessage('admin.image.amazonS3SecretExample', 'Ex "jcuS8PuvcpGhpgHhlcpT1Mx42pnqMxQY"')}
helpText={
}
value={this.state.amazonS3SecretAccessKey}
onChange={this.handleChange}
disabled={this.state.driverName !== DRIVER_S3}
/>
}
placeholder={Utils.localizeMessage('admin.image.amazonS3BucketExample', 'Ex "mattermost-media"')}
helpText={
}
value={this.state.amazonS3Bucket}
onChange={this.handleChange}
disabled={this.state.driverName !== DRIVER_S3}
/>
}
placeholder={Utils.localizeMessage('admin.image.amazonS3EndpointExample', 'Ex "s3.amazonaws.com"')}
helpText={
}
value={this.state.amazonS3Endpoint}
onChange={this.handleChange}
disabled={this.state.driverName !== DRIVER_S3}
/>
}
placeholder={Utils.localizeMessage('admin.image.amazonS3SSLExample', 'Ex "true"')}
helpText={
}
value={this.state.amazonS3SSL}
onChange={this.handleChange}
disabled={this.state.driverName !== DRIVER_S3}
/>
}
helpText={
}
value={this.state.enableFileAttachments}
onChange={this.handleChange}
/>
}
placeholder={Utils.localizeMessage('admin.image.maxFileSizeExample', '50')}
helpText={
}
value={this.state.maxFileSize}
onChange={this.handleChange}
disabled={!this.state.enableFileAttachments}
/>
);
}
}