<commit_before>import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import Helmet from 'react-helmet';
//
import * as Basic from '../../../components/basic';
import * as Advanced from '../../../components/advanced';
import * as Utils from '../../../utils';
import { NotificationConfigurationManager, SecurityManager, DataManager, NotificationTemplateManager } from '../../../redux';
import NotificationLevelEnum from '../../../enums/NotificationLevelEnum';

const uiKey = 'notification-configurations-table';
const manager = new NotificationConfigurationManager();
const notificationTemplateManager = new NotificationTemplateManager();

/**
 * Notification configuration
 *
 * @author <NAME>
 */
export default class NotificationConfigurations extends Advanced.AbstractTableContent {

  constructor(props, context) {
    super(props, context);
    this.state = {
      detail: {
        show: false,
        entity: {}
      },
      filterOpened: true
    };
  }

  componentDidMount() {
    this.selectNavigationItems(['notification', 'notification-configurations']);
    this.context.store.dispatch(manager.fetchSupportedNotificationTypes());
  }

  getManager() {
    return manager;
  }

  getUiKey() {
    return uiKey;
  }

  getContentKey() {
    return 'content.notificationConfigurations';
  }

  showDetail(entity, event) {
    if (event) {
      event.preventDefault();
    }
    this.setState({
      detail: {
        show: true,
        entity
      }
    });
  }

  closeDetail(event) {
    if (event) {
      event.preventDefault();
    }
    this.setState({
      detail: {
        show: false,
        entity: {}
      }
    });
  }

  save(entity, event) {
    const formEntity = this.refs.form.getData();
    // transform template id
    const savedEntity = {
      ...formEntity
    };
    //
    super.save(savedEntity, event);
  }

  afterSave(entity, error) {
    if (!error) {
      this.refs.table.getWrappedInstance().reload();
      this.addMessage({ message: this.i18n('save.success', { name: this.getManager().getNiceLabel(entity) }) });
    }
    //
    super.afterSave(entity, error);
  }

  render() {
    const { _showLoading, _supportedNotificationTypesLoading, _supportedNotificationTypes } = this.props;
    const { detail, filterOpened } = this.state;
    return (
      <div>
        <Helmet title={this.i18n('title')} />
        <Basic.Confirm ref="confirm-delete" level="danger"/>

        <Basic.ContentHeader>
          <span dangerouslySetInnerHTML={{ __html: this.i18n('header') }}/>
        </Basic.ContentHeader>

        <Basic.Panel className="last">
          <Advanced.Table
            ref="table"
            uiKey={uiKey}
            filterOpened={filterOpened}
            _searchParameters={ this.getSearchParameters() }
            manager={this.getManager()}
            showRowSelection={SecurityManager.hasAnyAuthority(['NOTIFICATIONCONFIGURATION_UPDATE'])}
            actions={
              SecurityManager.hasAnyAuthority(['NOTIFICATIONCONFIGURATION_DELETE'])
              ?
              [{ value: 'delete', niceLabel: this.i18n('action.delete.action'), action: this.onDelete.bind(this), disabled: false }]
              :
              null
            }
            buttons={
              [
                <Basic.Button
                  level="success"
                  key="add_button"
                  className="btn-xs"
                  onClick={this.showDetail.bind(this, { level: NotificationLevelEnum.findKeyBySymbol(NotificationLevelEnum.SUCCESS) })}
                  rendered={SecurityManager.hasAnyAuthority(['NOTIFICATIONCONFIGURATION_CREATE'])}>
                  <Basic.Icon type="fa" icon="plus"/>
                  {' '}
                  {this.i18n('button.add')}
                </Basic.Button>
              ]
            }
            filter={
              <Filter
                ref="filterForm"
                onSubmit={ this.useFilter.bind(this) }
                onCancel={ this.cancelFilter.bind(this) }
                supportedNotificationTypes={_supportedNotificationTypes}/>
            }
            >
            <Advanced.Column
              property=""
              header=""
              className="detail-button"
              cell={
                ({ rowIndex, data }) => {
                  return (
                    <Advanced.DetailButton
                      title={this.i18n('button.detail')}
                      onClick={this.showDetail.bind(this, data[rowIndex])}/>
                  );
                }
              }/>
            <Advanced.Column property="topic" width="200px" header={this.i18n('entity.NotificationConfiguration.topic')} sort face="text" />
            <Advanced.Column property="level" width="75px" header={this.i18n('entity.NotificationConfiguration.level')} sort face="enum" enumClass={NotificationLevelEnum} />
            <Advanced.Column property="notificationType" width="75px" header={this.i18n('entity.NotificationConfiguration.notificationType')} sort face="text" />
            <Advanced.Column property="template" header={this.i18n('entity.NotificationConfiguration.template')} sort
              cell={
                ({ rowIndex, data }) => {
                  const templId = data[rowIndex].template;
                  return (
                    <Advanced.NotificationTemplateInfo entityIdentifier={templId} face="link" />
                  );
                }
                }
              />
          </Advanced.Table>
        </Basic.Panel>

        <Basic.Modal
          bsSize="large"
          show={detail.show}
          onHide={this.closeDetail.bind(this)}
          backdrop="static"
          keyboard={!_showLoading}
          showLoading={_supportedNotificationTypesLoading}>

          <form onSubmit={this.save.bind(this, {})}>
            <Basic.Modal.Header closeButton={!_showLoading} text={this.i18n('create.header')} rendered={Utils.Entity.isNew(detail.entity)}/>
            <Basic.Modal.Header closeButton={!_showLoading} text={this.i18n('edit.header', { name: detail.entity.topic })} rendered={!Utils.Entity.isNew(detail.entity)}/>
            <Basic.Modal.Body>
              <Basic.AbstractForm data={detail.entity} showLoading={_showLoading}>
                <Basic.TextField
                  ref="topic"
                  label={this.i18n('entity.NotificationConfiguration.topic')}
                  required/>
                <Basic.EnumSelectBox
                  ref="level"
                  enum={NotificationLevelEnum}
                  useSymbol={false}
                  label={this.i18n('entity.NotificationConfiguration.level')}/>
                <Basic.EnumSelectBox
                  ref="notificationType"
                  label={this.i18n('entity.NotificationConfiguration.notificationType')}
                  options={!_supportedNotificationTypes ? null : _supportedNotificationTypes.map(type => { return { value: type, niceLabel: type }; })}
                  required/>
                <Basic.SelectBox
                  ref="template"
                  label={this.i18n('entity.NotificationConfiguration.template')}
                  manager={notificationTemplateManager}/>
                <Basic.TextArea
                  ref="description"
                  label={this.i18n('entity.NotificationConfiguration.description')}/>
              </Basic.AbstractForm>
            </Basic.Modal.Body>

            <Basic.Modal.Footer>
              <Basic.Button
                level="link"<commit_msg>#785 filter<commit_after>import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import Helmet from 'react-helmet';
//
import * as Basic from '../../../components/basic';
import * as Advanced from '../../../components/advanced';
import * as Utils from '../../../utils';
import { NotificationConfigurationManager, SecurityManager, DataManager, NotificationTemplateManager } from '../../../redux';
import NotificationLevelEnum from '../../../enums/NotificationLevelEnum';

const uiKey = 'notification-configurations-table';
const manager = new NotificationConfigurationManager();
const notificationTemplateManager = new NotificationTemplateManager();

/**
 * Notification configuration
 *
 * @author <NAME>
 */
export default class NotificationConfigurations extends Advanced.AbstractTableContent {

  constructor(props, context) {
    super(props, context);
    this.state = {
      detail: {
        show: false,
        entity: {}
      },
      filterOpened: true
    };
  }

  componentDidMount() {
    this.selectNavigationItems(['notification', 'notification-configurations']);
    this.context.store.dispatch(manager.fetchSupportedNotificationTypes());
  }

  getManager() {
    return manager;
  }

  getUiKey() {
    return uiKey;
  }

  getContentKey() {
    return 'content.notificationConfigurations';
  }

  showDetail(entity, event) {
    if (event) {
      event.preventDefault();
    }
    this.setState({
      detail: {
        show: true,
        entity
      }
    });
  }

  closeDetail(event) {
    if (event) {
      event.preventDefault();
    }
    this.setState({
      detail: {
        show: false,
        entity: {}
      }
    });
  }

  save(entity, event) {
    const formEntity = this.refs.form.getData();
    // transform template id
    const savedEntity = {
      ...formEntity
    };
    //
    super.save(savedEntity, event);
  }

  afterSave(entity, error) {
    if (!error) {
      this.refs.table.getWrappedInstance().reload();
      this.addMessage({ message: this.i18n('save.success', { name: this.getManager().getNiceLabel(entity) }) });
    }
    //
    super.afterSave(entity, error);
  }

  render() {
    const { _showLoading, _supportedNotificationTypesLoading, _supportedNotificationTypes } = this.props;
    const { detail, filterOpened } = this.state;

    return (
      <div>
        <Helmet title={this.i18n('title')} />
        <Basic.Confirm ref="confirm-delete" level="danger"/>

        <Basic.ContentHeader>
          <span dangerouslySetInnerHTML={{ __html: this.i18n('header') }}/>
        </Basic.ContentHeader>

        <Basic.Panel className="last">
          <Advanced.Table
            ref="table"
            uiKey={uiKey}
            filterOpened={filterOpened}
            _searchParameters={ this.getSearchParameters() }
            manager={this.getManager()}
            showRowSelection={SecurityManager.hasAnyAuthority(['NOTIFICATIONCONFIGURATION_UPDATE'])}
            actions={
              SecurityManager.hasAnyAuthority(['NOTIFICATIONCONFIGURATION_DELETE'])
              ?
              [{ value: 'delete', niceLabel: this.i18n('action.delete.action'), action: this.onDelete.bind(this), disabled: false }]
              :
              null
            }
            buttons={
              [
                <Basic.Button
                  level="success"
                  key="add_button"
                  className="btn-xs"
                  onClick={this.showDetail.bind(this, { level: NotificationLevelEnum.findKeyBySymbol(NotificationLevelEnum.SUCCESS) })}
                  rendered={SecurityManager.hasAnyAuthority(['NOTIFICATIONCONFIGURATION_CREATE'])}>
                  <Basic.Icon type="fa" icon="plus"/>
                  {' '}
                  {this.i18n('button.add')}
                </Basic.Button>
              ]
            }
            filter={
              <Filter
                ref="filterForm"
                onSubmit={ this.useFilter.bind(this) }
                onCancel={ this.cancelFilter.bind(this) }
                supportedNotificationTypes={_supportedNotificationTypes}/>
            }
            >
            <Advanced.Column
              property=""
              header=""
              className="detail-button"
              cell={
                ({ rowIndex, data }) => {
                  return (
                    <Advanced.DetailButton
                      title={this.i18n('button.detail')}
                      onClick={this.showDetail.bind(this, data[rowIndex])}/>
                  );
                }
              }/>
            <Advanced.Column property="topic" width="200px" header={this.i18n('entity.NotificationConfiguration.topic')} sort face="text" />
            <Advanced.Column property="level" width="75px" header={this.i18n('entity.NotificationConfiguration.level')} sort face="enum" enumClass={NotificationLevelEnum} />
            <Advanced.Column property="notificationType" width="75px" header={this.i18n('entity.NotificationConfiguration.notificationType')} sort face="text" />
            <Advanced.Column property="template" header={this.i18n('entity.NotificationConfiguration.template')} sort
              cell={
                ({ rowIndex, data }) => {
                  const templId = data[rowIndex].template;
                  return (
                    <Advanced.NotificationTemplateInfo entityIdentifier={templId} face="link" />
                  );
                }
                }
              />
          </Advanced.Table>
        </Basic.Panel>

        <Basic.Modal
          bsSize="large"
          show={detail.show}
          onHide={this.closeDetail.bind(this)}
          backdrop="static"
          keyboard={!_showLoading}
          showLoading={_supportedNotificationTypesLoading}>

          <form onSubmit={this.save.bind(this, {})}>
            <Basic.Modal.Header closeButton={!_showLoading} text={this.i18n('create.header')} rendered={Utils.Entity.isNew(detail.entity)}/>
            <Basic.Modal.Header closeButton={!_showLoading} text={this.i18n('edit.header', { name: detail.entity.topic })} rendered={!Utils.Entity.isNew(detail.entity)}/>
            <Basic.Modal.Body>
              <Basic.AbstractForm ref="form" data={detail.entity} showLoading={_showLoading}>
                <Basic.TextField
                  ref="topic"
                  label={this.i18n('entity.NotificationConfiguration.topic')}
                  required/>
                <Basic.EnumSelectBox
                  ref="level"
                  enum={NotificationLevelEnum}
                  useSymbol={false}
                  label={this.i18n('entity.NotificationConfiguration.level')}/>
                <Basic.EnumSelectBox
                  ref="notificationType"
                  label={this.i18n('entity.NotificationConfiguration.notificationType')}
                  options={!_supportedNotificationTypes ? null : _supportedNotificationTypes.map(type => { return { value: type, niceLabel: type }; })}
                  required/>
                <Basic.SelectBox
                  ref="template"
                  label={this.i18n('entity.NotificationConfiguration.template')}
                  manager={notificationTemplateManager}/>
                <Basic.TextArea
                  ref="description"
                  label={this.i18n('entity.NotificationConfiguration.description')}/>
              </Basic.AbstractForm>
            </Basic.Modal.Body>

            <Basic.Modal.Footer>
              <Basic.Button
                level="link"
{'fraction_non_alphanumeric': 0.12840879004500927, 'fraction_numerical': 0.005626158326714323, 'mean_word_length': 2.0013905442987685, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3408801', 'n_tokens_mistral': 3940, 'n_tokens_neox': 3754, 'n_words': 595}