aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/overview/meta.js
blob: 8228db26f3447ee48c2185962618aaaa65926f2e (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
import _ from 'underscore';
import moment from 'moment';
import React from 'react';

import { QualityProfileLink } from './../../components/shared/quality-profile-link';
import { QualityGateLink } from './../../components/shared/quality-gate-link';
import { getEvents } from '../../api/events';
import { EventsList } from './components/events-list';


export default React.createClass({
  componentDidMount() {
    this.requestEvents();
  },

  requestEvents () {
    return getEvents(this.props.component.key).then(events => {
      const nextEvents = events.map(event => {
        return {
          id: event.id,
          date: moment(event.dt).toDate(),
          type: event.c,
          name: event.n,
          text: event.ds
        };
      });
      this.setState({ events: nextEvents });
    });
  },

  isView() {
    return this.props.component.qualifier === 'VW' || this.props.component.qualifier === 'SVW';
  },

  isDeveloper() {
    return this.props.component.qualifier === 'DEV';
  },

  renderEvents() {
    if (this.state && this.state.events) {
      return <EventsList component={this.props.component} events={this.state.events}/>;
    } else {
      return null;
    }
  },

  render() {
    let profiles = (this.props.component.profiles || []).map(profile => {
          return (
              <li key={profile.key}>
                <span className="note spacer-right">({profile.language})</span>
                <QualityProfileLink profile={profile.key}>{profile.name}</QualityProfileLink>
              </li>
          );
        }),
        links = (this.props.component.links || []).map(link => {
          let iconClassName = `spacer-right icon-color-link icon-${link.type}`;
          return (
              <li key={link.type}>
                <i className={iconClassName}/>
                <a href={link.href} target="_blank">{link.name}</a>
              </li>
          );
        });

    let descriptionCard = this.props.component.description ? (
            <div className="overview-meta-card">
              <div className="overview-meta-description">{this.props.component.description}</div>
            </div>
        ) : null,

        linksCard = _.size(this.props.component.links) > 0 ? (
            <div className="overview-meta-card">
              <ul className="overview-meta-list">{links}</ul>
            </div>
        ) : null,

        profilesCard = !this.isView() && !this.isDeveloper() && _.size(this.props.component.profiles) > 0 ? (
            <div className="overview-meta-card">
              <h4 className="overview-meta-header">{window.t('overview.quality_profiles')}</h4>
              <ul className="overview-meta-list">{profiles}</ul>
            </div>
        ) : null,

        gateCard = !this.isView() && !this.isDeveloper() && this.props.component.gate ? (
            <div className="overview-meta-card">
              <h4 className="overview-meta-header">{window.t('overview.quality_gate')}</h4>
              <ul className="overview-meta-list">
                <li>
                  {this.props.component.gate.isDefault ?
                      <span className="note spacer-right">(Default)</span> : null}
                  <QualityGateLink gate={this.props.component.gate.key}>
                    {this.props.component.gate.name}
                  </QualityGateLink>
                </li>
              </ul>
            </div>
        ) : null;

    return (
        <div className="overview-meta">
          {descriptionCard}
          {linksCard}
          {gateCard}
          {profilesCard}
          {this.renderEvents()}
        </div>
    );
  }
});