From: Stas Vilchik Date: Wed, 13 Jul 2016 12:11:00 +0000 (+0200) Subject: add profile actions to the main page X-Git-Tag: 6.0-RC1~68 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7f2ca1b740af43da2f3b11c61f47c7913fed66b3;p=sonarqube.git add profile actions to the main page --- diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/components/ProfileActions.js b/server/sonar-web/src/main/js/apps/quality-profiles/components/ProfileActions.js new file mode 100644 index 00000000000..f0a834c0555 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/quality-profiles/components/ProfileActions.js @@ -0,0 +1,152 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import React from 'react'; +import { Link } from 'react-router'; +import RenameProfileView from '../views/RenameProfileView'; +import CopyProfileView from '../views/CopyProfileView'; +import DeleteProfileView from '../views/DeleteProfileView'; +import { translate } from '../../../helpers/l10n'; +import { ProfileType } from '../propTypes'; +import { getRulesUrl } from '../../../helpers/urls'; +import { setDefaultProfile } from '../../../api/quality-profiles'; + +export default class ProfileActions extends React.Component { + static propTypes = { + profile: ProfileType.isRequired, + canAdmin: React.PropTypes.bool.isRequired, + updateProfiles: React.PropTypes.func.isRequired + }; + + static contextTypes = { + router: React.PropTypes.object + }; + + handleRenameClick (e) { + e.preventDefault(); + new RenameProfileView({ + profile: this.props.profile + }).on('done', () => { + this.props.updateProfiles(); + }).render(); + } + + handleCopyClick (e) { + e.preventDefault(); + new CopyProfileView({ + profile: this.props.profile + }).on('done', profile => { + this.props.updateProfiles().then(() => { + this.context.router.push({ + pathname: '/show', + query: { key: profile.key } + }); + }); + }).render(); + } + + handleSetDefaultClick (e) { + e.preventDefault(); + setDefaultProfile(this.props.profile.key) + .then(this.props.updateProfiles); + } + + handleDeleteClick (e) { + e.preventDefault(); + new DeleteProfileView({ + profile: this.props.profile + }).on('done', () => { + this.context.router.replace('/'); + this.props.updateProfiles(); + }).render(); + } + + render () { + const { profile, canAdmin } = this.props; + + const backupUrl = window.baseUrl + + '/api/qualityprofiles/backup?profileKey=' + + encodeURIComponent(profile.key); + + const activateMoreUrl = getRulesUrl({ + qprofile: profile.key, + activation: 'false' + }); + + return ( + + ); + } +} diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileHeader.js b/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileHeader.js index 7f2c10f5abb..51db2e4b8ac 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileHeader.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileHeader.js @@ -20,16 +20,11 @@ import React from 'react'; import { Link, IndexLink } from 'react-router'; import classNames from 'classnames'; -import moment from 'moment'; import ProfileLink from '../components/ProfileLink'; -import RenameProfileView from '../views/RenameProfileView'; -import CopyProfileView from '../views/CopyProfileView'; -import DeleteProfileView from '../views/DeleteProfileView'; +import ProfileActions from '../components/ProfileActions'; import ProfileDate from '../components/ProfileDate'; import { ProfileType } from '../propTypes'; import { translate } from '../../../helpers/l10n'; -import { setDefaultProfile } from '../../../api/quality-profiles'; -import { getRulesUrl } from '../../../helpers/urls'; import { isStagnant } from '../utils'; export default class ProfileHeader extends React.Component { @@ -39,49 +34,6 @@ export default class ProfileHeader extends React.Component { updateProfiles: React.PropTypes.func.isRequired }; - static contextTypes = { - router: React.PropTypes.object - }; - - handleRenameClick (e) { - e.preventDefault(); - new RenameProfileView({ - profile: this.props.profile - }).on('done', () => { - this.props.updateProfiles(); - }).render(); - } - - handleCopyClick (e) { - e.preventDefault(); - new CopyProfileView({ - profile: this.props.profile - }).on('done', profile => { - this.props.updateProfiles().then(() => { - this.context.router.push({ - pathname: '/show', - query: { key: profile.key } - }); - }); - }).render(); - } - - handleSetDefaultClick (e) { - e.preventDefault(); - setDefaultProfile(this.props.profile.key) - .then(this.props.updateProfiles); - } - - handleDeleteClick (e) { - e.preventDefault(); - new DeleteProfileView({ - profile: this.props.profile - }).on('done', () => { - this.context.router.replace('/'); - this.props.updateProfiles(); - }).render(); - } - renderUpdateDate () { const { profile } = this.props; const warning = isStagnant(profile); @@ -98,16 +50,7 @@ export default class ProfileHeader extends React.Component { } render () { - const { profile, canAdmin } = this.props; - - const backupUrl = window.baseUrl + - '/api/qualityprofiles/backup?profileKey=' + - encodeURIComponent(profile.key); - - const activateMoreUrl = getRulesUrl({ - qprofile: this.props.profile.key, - activation: 'false' - }); + const { profile } = this.props; return (
@@ -125,7 +68,7 @@ export default class ProfileHeader extends React.Component {

{profile.name} @@ -141,7 +84,7 @@ export default class ProfileHeader extends React.Component {
  • {translate('changelog')} @@ -154,63 +97,10 @@ export default class ProfileHeader extends React.Component { {' '} - +
  • diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/home/ProfilesList.js b/server/sonar-web/src/main/js/apps/quality-profiles/home/ProfilesList.js index 51f533c1861..ba333be7e12 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/home/ProfilesList.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/home/ProfilesList.js @@ -32,12 +32,18 @@ export default class ProfilesList extends React.Component { static propTypes = { profiles: ProfilesListType, languages: LanguagesListType, - location: RouterPropTypes.location + location: RouterPropTypes.location, + canAdmin: React.PropTypes.bool.isRequired, + updateProfiles: React.PropTypes.func.isRequired }; renderProfiles (profiles) { return profiles.map(profile => ( - + )); } @@ -66,6 +72,9 @@ export default class ProfilesList extends React.Component { {translate('quality_profiles.list.used')} + {this.props.canAdmin && ( +   + )} ); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/home/ProfilesListRow.js b/server/sonar-web/src/main/js/apps/quality-profiles/home/ProfilesListRow.js index cda1762257c..2ff6c99936c 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/home/ProfilesListRow.js +++ b/server/sonar-web/src/main/js/apps/quality-profiles/home/ProfilesListRow.js @@ -21,6 +21,7 @@ import React from 'react'; import shallowCompare from 'react-addons-shallow-compare'; import ProfileLink from '../components/ProfileLink'; import ProfileDate from '../components/ProfileDate'; +import ProfileActions from '../components/ProfileActions'; import { ProfileType } from '../propTypes'; import { translate } from '../../../helpers/l10n'; import { getRulesUrl } from '../../../helpers/urls'; @@ -28,7 +29,9 @@ import { isStagnant } from '../utils'; export default class ProfilesListRow extends React.Component { static propTypes = { - profile: ProfileType.isRequired + profile: ProfileType.isRequired, + canAdmin: React.PropTypes.bool.isRequired, + updateProfiles: React.PropTypes.func.isRequired }; shouldComponentUpdate (nextProps, nextState) { @@ -132,6 +135,19 @@ export default class ProfilesListRow extends React.Component { {this.renderUsageDate()} + {this.props.canAdmin && ( + +
    + + +
    + + )} ); }