diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2016-02-05 14:56:32 +0100 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2016-02-05 14:56:39 +0100 |
commit | 6a42c875ab63681b99ebea83272cee7bc94f9530 (patch) | |
tree | 261e8ea75acbe42764af129945af91b125db37eb | |
parent | 2e08979e84c395b305c3ae45226a1344dc956c2e (diff) | |
download | sonarqube-6a42c875ab63681b99ebea83272cee7bc94f9530.tar.gz sonarqube-6a42c875ab63681b99ebea83272cee7bc94f9530.zip |
make it possible to manage favorite issue and measure filters on my account page
8 files changed, 186 insertions, 4 deletions
diff --git a/server/sonar-web/src/main/js/api/issue-filters.js b/server/sonar-web/src/main/js/api/issue-filters.js new file mode 100644 index 00000000000..1e8c872dc7d --- /dev/null +++ b/server/sonar-web/src/main/js/api/issue-filters.js @@ -0,0 +1,26 @@ +/* + * 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 { post } from '../helpers/request.js'; + +export function toggleIssueFilter (id) { + const url = window.baseUrl + '/issues/toggle_fav'; + const data = { id }; + return post(url, data); +} diff --git a/server/sonar-web/src/main/js/api/measure-filters.js b/server/sonar-web/src/main/js/api/measure-filters.js new file mode 100644 index 00000000000..67699863d9a --- /dev/null +++ b/server/sonar-web/src/main/js/api/measure-filters.js @@ -0,0 +1,26 @@ +/* + * 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 { post } from '../helpers/request.js'; + +export function toggleMeasureFilter (id) { + const url = window.baseUrl + '/measures/toggle_fav'; + const data = { id }; + return post(url, data); +} diff --git a/server/sonar-web/src/main/js/apps/account/components/FavoriteIssueFilters.js b/server/sonar-web/src/main/js/apps/account/components/FavoriteIssueFilters.js index b607c70b8c8..3eb59fcc076 100644 --- a/server/sonar-web/src/main/js/apps/account/components/FavoriteIssueFilters.js +++ b/server/sonar-web/src/main/js/apps/account/components/FavoriteIssueFilters.js @@ -19,6 +19,7 @@ */ import React from 'react'; +import FavoriteIssueFilter from '../../../components/shared/FavoriteIssueFilter'; import { translate } from '../../../helpers/l10n'; const FavoriteIssueFilters = ({ issueFilters }) => ( @@ -38,7 +39,7 @@ const FavoriteIssueFilters = ({ issueFilters }) => ( {issueFilters.map(f => ( <tr key={f.name}> <td className="thin"> - <i className="icon-favorite"/> + <FavoriteIssueFilter filter={f} favorite={true}/> </td> <td> <a href={`${window.baseUrl}/issues/search#id=${f.id}`}> diff --git a/server/sonar-web/src/main/js/apps/account/components/FavoriteMeasureFilters.js b/server/sonar-web/src/main/js/apps/account/components/FavoriteMeasureFilters.js index 5135dc2890d..c9998d0eaca 100644 --- a/server/sonar-web/src/main/js/apps/account/components/FavoriteMeasureFilters.js +++ b/server/sonar-web/src/main/js/apps/account/components/FavoriteMeasureFilters.js @@ -19,6 +19,7 @@ */ import React from 'react'; +import FavoriteMeasureFilter from '../../../components/shared/FavoriteMeasureFilter'; import { translate } from '../../../helpers/l10n'; const FavoriteMeasureFilters = ({ measureFilters }) => ( @@ -38,7 +39,7 @@ const FavoriteMeasureFilters = ({ measureFilters }) => ( {measureFilters.map(f => ( <tr key={f.name}> <td className="thin"> - <i className="icon-favorite"/> + <FavoriteMeasureFilter filter={f} favorite={true}/> </td> <td> <a href={`${window.baseUrl}/measures/filter/${f.id}`}> diff --git a/server/sonar-web/src/main/js/components/shared/FavoriteIssueFilter.js b/server/sonar-web/src/main/js/components/shared/FavoriteIssueFilter.js new file mode 100644 index 00000000000..aa78a2add0f --- /dev/null +++ b/server/sonar-web/src/main/js/components/shared/FavoriteIssueFilter.js @@ -0,0 +1,65 @@ +/* + * 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 { toggleIssueFilter } from '../../api/issue-filters'; + +export default React.createClass({ + propTypes: { + filter: React.PropTypes.string.isRequired, + favorite: React.PropTypes.bool.isRequired + }, + + getInitialState() { + return { favorite: this.props.favorite }; + }, + + toggleFavorite(e) { + e.preventDefault(); + if (this.state.favorite) { + this.removeFavorite(); + } else { + this.addFavorite(); + } + }, + + addFavorite() { + toggleIssueFilter(this.props.filter.id).then(() => this.setState({ favorite: true })); + }, + + removeFavorite() { + toggleIssueFilter(this.props.filter.id).then(() => this.setState({ favorite: false })); + }, + + renderSVG() { + /* eslint max-len: 0 */ + return ( + <svg width="16" height="16" style={{ fillRule: 'evenodd', clipRule: 'evenodd', strokeLinejoin: 'round', strokeMiterlimit: 1.41421 }}> + <path d="M15.4275,5.77678C15.4275,5.90773 15.3501,6.05059 15.1953,6.20536L11.9542,9.36608L12.7221,13.8304C12.728,13.872 12.731,13.9316 12.731,14.0089C12.731,14.1339 12.6998,14.2396 12.6373,14.3259C12.5748,14.4122 12.484,14.4554 12.3649,14.4554C12.2518,14.4554 12.1328,14.4197 12.0078,14.3482L7.99888,12.2411L3.98995,14.3482C3.85901,14.4197 3.73996,14.4554 3.63281,14.4554C3.50781,14.4554 3.41406,14.4122 3.35156,14.3259C3.28906,14.2396 3.25781,14.1339 3.25781,14.0089C3.25781,13.9732 3.26377,13.9137 3.27567,13.8304L4.04353,9.36608L0.793531,6.20536C0.644719,6.04464 0.570313,5.90178 0.570313,5.77678C0.570313,5.55654 0.736979,5.41964 1.07031,5.36606L5.55245,4.71428L7.56138,0.651781C7.67447,0.407729 7.8203,0.285703 7.99888,0.285703C8.17745,0.285703 8.32328,0.407729 8.43638,0.651781L10.4453,4.71428L14.9274,5.36606C15.2608,5.41964 15.4274,5.55654 15.4274,5.77678L15.4275,5.77678Z" + style={{ fillRule: 'nonzero' }}/> + </svg> + ); + }, + + render() { + const className = this.state.favorite ? 'icon-star icon-star-favorite' : 'icon-star'; + return <a onClick={this.toggleFavorite} className={className} href="#">{this.renderSVG()}</a>; + } +}); diff --git a/server/sonar-web/src/main/js/components/shared/FavoriteMeasureFilter.js b/server/sonar-web/src/main/js/components/shared/FavoriteMeasureFilter.js new file mode 100644 index 00000000000..18cf94ea1d1 --- /dev/null +++ b/server/sonar-web/src/main/js/components/shared/FavoriteMeasureFilter.js @@ -0,0 +1,65 @@ +/* + * 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 { toggleMeasureFilter } from '../../api/measure-filters'; + +export default React.createClass({ + propTypes: { + filter: React.PropTypes.string.isRequired, + favorite: React.PropTypes.bool.isRequired + }, + + getInitialState() { + return { favorite: this.props.favorite }; + }, + + toggleFavorite(e) { + e.preventDefault(); + if (this.state.favorite) { + this.removeFavorite(); + } else { + this.addFavorite(); + } + }, + + addFavorite() { + toggleMeasureFilter(this.props.filter.id).then(() => this.setState({ favorite: true })); + }, + + removeFavorite() { + toggleMeasureFilter(this.props.filter.id).then(() => this.setState({ favorite: false })); + }, + + renderSVG() { + /* eslint max-len: 0 */ + return ( + <svg width="16" height="16" style={{ fillRule: 'evenodd', clipRule: 'evenodd', strokeLinejoin: 'round', strokeMiterlimit: 1.41421 }}> + <path d="M15.4275,5.77678C15.4275,5.90773 15.3501,6.05059 15.1953,6.20536L11.9542,9.36608L12.7221,13.8304C12.728,13.872 12.731,13.9316 12.731,14.0089C12.731,14.1339 12.6998,14.2396 12.6373,14.3259C12.5748,14.4122 12.484,14.4554 12.3649,14.4554C12.2518,14.4554 12.1328,14.4197 12.0078,14.3482L7.99888,12.2411L3.98995,14.3482C3.85901,14.4197 3.73996,14.4554 3.63281,14.4554C3.50781,14.4554 3.41406,14.4122 3.35156,14.3259C3.28906,14.2396 3.25781,14.1339 3.25781,14.0089C3.25781,13.9732 3.26377,13.9137 3.27567,13.8304L4.04353,9.36608L0.793531,6.20536C0.644719,6.04464 0.570313,5.90178 0.570313,5.77678C0.570313,5.55654 0.736979,5.41964 1.07031,5.36606L5.55245,4.71428L7.56138,0.651781C7.67447,0.407729 7.8203,0.285703 7.99888,0.285703C8.17745,0.285703 8.32328,0.407729 8.43638,0.651781L10.4453,4.71428L14.9274,5.36606C15.2608,5.41964 15.4274,5.55654 15.4274,5.77678L15.4275,5.77678Z" + style={{ fillRule: 'nonzero' }}/> + </svg> + ); + }, + + render() { + const className = this.state.favorite ? 'icon-star icon-star-favorite' : 'icon-star'; + return <a onClick={this.toggleFavorite} className={className} href="#">{this.renderSVG()}</a>; + } +}); diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb index 06fff13905f..6570ff3b606 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/issues_controller.rb @@ -126,7 +126,6 @@ class IssuesController < ApplicationController # POST /issues/toggle_fav/<filter id> def toggle_fav - verify_ajax_request require_parameters :id render :text => Internal.issues.toggleFavouriteIssueFilter(params[:id].to_i), :status => 200 end diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb index c5f3c4bdc66..c952c7d838c 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/controllers/measures_controller.rb @@ -210,7 +210,6 @@ class MeasuresController < ApplicationController # POST /measures/toggle_fav/<filter id> def toggle_fav access_denied unless logged_in? - verify_ajax_request require_parameters :id favourites = MeasureFilterFavourite.all(:conditions => ['user_id=? and measure_filter_id=?', current_user.id, params[:id]]) |