/* * Copyright 2014 Mirantis, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may * not use this file except in compliance with the License. You may obtain * a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. **/ import _ from 'underscore'; import i18n from 'i18n'; import React from 'react'; import utils from 'utils'; import models from 'models'; import {backboneMixin, pollingMixin, unsavedChangesMixin} from 'component_mixins'; import statisticsMixin from 'views/statistics_mixin'; import {ProgressButton, Link} from 'views/controls'; var SupportPage = React.createClass({ mixins: [ backboneMixin('tasks') ], statics: { title: i18n('support_page.title'), navbarActiveElement: 'support', breadcrumbsPath: [['home', '/'], 'support'], fetchData() { var tasks = new models.Tasks(); return Promise.all([app.fuelSettings.fetch({cache: true}), tasks.fetch()]) .then(() => ({tasks, settings: app.fuelSettings})); } }, render() { var elements = [ , , , ]; return (

{i18n('support_page.title')}

{_.reduce(elements, (result, element, index) => { if (index) result.push(
); result.push(element); return result; }, [])}
); } }); var SupportPageElement = React.createClass({ render() { return (

{this.props.title}

{this.props.text}

{this.props.children}
); } }); var DocumentationLink = React.createClass({ render() { var ns = 'support_page.documentation_'; return (

{i18n(ns + 'link')}

); } }); var StatisticsSettings = React.createClass({ mixins: [ statisticsMixin, backboneMixin('settings'), unsavedChangesMixin ], hasChanges() { return _.some(this.props.renderableStatisticsFields, (settingName) => { return this.state.initialSettings.statistics[settingName].value !== this.props.settings.get(utils.makePath('statistics', settingName, 'value')); }); }, isSavingPossible() { return !this.state.actionInProgress && this.hasChanges(); }, saveChanges() { var data = this.getStatisticsSettingsToSave(); this.saveSettings(data) .then(() => this.setState({ initialSettings: data, actionInProgress: false }), (response) => { utils.showErrorDialog({response}); this.setState({actionInProgress: false}); } ); }, applyChanges() { return this.isSavingPossible() ? this.saveChanges() : Promise.resolve(); }, revertChanges() { _.each(this.props.renderableStatisticsFields, (settingName) => { this.props.settings.set( utils.makePath('statistics', settingName, 'value'), this.state.initialSettings.statistics[settingName].value ); }); }, render() { var statistics = this.props.settings.get('statistics'); var sortedSettings = _.chain(_.keys(statistics)) .without('metadata') .sortBy((settingName) => statistics[settingName].weight) .value(); return (
{this.renderIntro()}
{_.map(sortedSettings, (name) => this.renderInput(name))}

{i18n('support_page.save_changes')}

); } }); var DiagnosticSnapshot = React.createClass({ mixins: [ backboneMixin('task'), pollingMixin(2) ], getInitialState() { return {generating: this.isDumpTaskActive()}; }, shouldDataBeFetched() { return this.isDumpTaskActive(); }, fetchData() { return this.props.task.fetch().then(() => { if (!this.isDumpTaskActive()) this.setState({generating: false}); }); }, isDumpTaskActive() { return this.props.task && this.props.task.match({active: true}); }, downloadLogs() { this.setState({generating: true}); (new models.LogsPackage()).save({}, {method: 'PUT'}).then( () => this.props.tasks.fetch(), () => this.props.tasks.fetch() ); }, componentDidUpdate() { this.startPolling(); }, render() { var task = this.props.task; var generating = this.state.generating; return (

{' '} {!generating && task && {task.match({status: 'ready'}) && {i18n('support_page.diagnostic_snapshot')} } {task.match({status: 'error'}) && task.get('message')} }

); } }); var CapacityAudit = React.createClass({ render() { return (

{i18n('support_page.view_capacity_audit')}

); } }); export default SupportPage;