return issueFilterService.findFavoriteFilters(UserSession.get());
}
- public Result toggleFavouriteIssueFilter(Long issueFilterId) {
- Result result = Result.of();
- issueFilterService.toggleFavouriteIssueFilter(issueFilterId, UserSession.get());
- return result;
+ public boolean toggleFavouriteIssueFilter(Long issueFilterId) {
+ return issueFilterService.toggleFavouriteIssueFilter(issueFilterId, UserSession.get());
}
/**
return toIssueFilters(filterDao.selectFavoriteFiltersByUser(getLoggedLogin(userSession)));
}
- public void toggleFavouriteIssueFilter(Long filterId, UserSession userSession) {
+ /**
+ * Return true if favorite is added, false if favorite is removed
+ */
+ public boolean toggleFavouriteIssueFilter(Long filterId, UserSession userSession) {
String user = getLoggedLogin(userSession);
findIssueFilterDto(filterId, user);
IssueFilterFavouriteDto issueFilterFavouriteDto = selectFavouriteFilterForUser(filterId, user);
if (issueFilterFavouriteDto == null) {
addFavouriteIssueFilter(filterId, user);
+ return true;
} else {
deleteFavouriteIssueFilter(issueFilterFavouriteDto);
+ return false;
}
}
class IssuesController < ApplicationController
before_filter :init_options
- before_filter :load_fav_filters, :only => [:index, :search, :filter, :manage, :toggle_fav]
+ before_filter :load_fav_filters, :only => [:index, :search, :filter, :manage, :favourites, :toggle_fav]
PAGE_SIZE = 100
redirect_to :action => 'manage'
end
+ # GET /issues/favourites
+ def favourites
+ verify_ajax_request
+ render :partial => 'issues/filter_favourites'
+ end
+
# POST /issues/toggle_fav/<filter id>
def toggle_fav
verify_ajax_request
require_parameters :id
- Internal.issues.toggleFavouriteIssueFilter(params[:id].to_i)
- render :text => '', :status => 200
+ render :text => Internal.issues.toggleFavouriteIssueFilter(params[:id].to_i), :status => 200
end
# GET /issues/bulk_change_form?[&criteria]
@filter.user = User.find_by_login(params[:owner])
end
- # SONAR-4469
- # If filter become unshared then remove all favorite filters linked to it, expect favorite of filter's owner
- MeasureFilterFavourite.delete_all(['user_id<>? and measure_filter_id=?', @filter.user.id, params[:id]]) if params[:shared]!='true'
if @filter.save
+ # SONAR-4469
+ # If filter become unshared then remove all favorite filters linked to it, expect favorite of filter's owner
+ MeasureFilterFavourite.delete_all(['user_id<>? and measure_filter_id=?', @filter.user.id, params[:id]]) if params[:shared]!='true'
+
render :text => @filter.id.to_s, :status => 200
else
render :partial => 'measures/edit_form', :status => 400
$j(document).ready(function () {
$j(".issue-filter-star").click(function () {
var filterId = $j(this).attr('filter-id');
+ var star = $j(this);
$j.ajax({
type: 'POST',
url: baseUrl + "/issues/toggle_fav",
data: {id: filterId},
success: function (data) {
- window.location = baseUrl + '/issues/manage';
+ if (data == 'true') {
+ star.removeClass('notfav').addClass('fav');
+ star.attr('title', '<%= escape_javascript message('click_to_remove_from_favourites') -%>');
+ } else {
+ star.removeClass('fav').addClass('notfav');
+ star.attr('title', '<%= escape_javascript message('click_to_add_to_favourites') -%>');
+ }
+ $j('#sidebar-favourites').load(baseUrl + '/issues/favourites');
}
});
});
@Test
public void should_toggle_favourite_issue_filter() {
- Result result = service.toggleFavouriteIssueFilter(10L);
- assertThat(result.ok()).isTrue();
+ service.toggleFavouriteIssueFilter(10L);
verify(issueFilterService).toggleFavouriteIssueFilter(eq(10L), any(UserSession.class));
}
when(issueFilterFavouriteDao.selectByFilterId(1L)).thenReturn(Collections.<IssueFilterFavouriteDto> emptyList());
ArgumentCaptor<IssueFilterFavouriteDto> issueFilterFavouriteDtoCaptor = ArgumentCaptor.forClass(IssueFilterFavouriteDto.class);
- service.toggleFavouriteIssueFilter(1L, userSession);
+ boolean result = service.toggleFavouriteIssueFilter(1L, userSession);
+ assertThat(result).isTrue();
verify(issueFilterFavouriteDao).insert(issueFilterFavouriteDtoCaptor.capture());
IssueFilterFavouriteDto issueFilterFavouriteDto = issueFilterFavouriteDtoCaptor.getValue();
when(issueFilterFavouriteDao.selectByFilterId(1L)).thenReturn(Collections.<IssueFilterFavouriteDto> emptyList());
ArgumentCaptor<IssueFilterFavouriteDto> issueFilterFavouriteDtoCaptor = ArgumentCaptor.forClass(IssueFilterFavouriteDto.class);
- service.toggleFavouriteIssueFilter(1L, userSession);
+ boolean result = service.toggleFavouriteIssueFilter(1L, userSession);
+ assertThat(result).isTrue();
verify(issueFilterFavouriteDao).insert(issueFilterFavouriteDtoCaptor.capture());
IssueFilterFavouriteDto issueFilterFavouriteDto = issueFilterFavouriteDtoCaptor.getValue();
// The filter is in the favorite list --> remove favorite
when(issueFilterFavouriteDao.selectByFilterId(1L)).thenReturn(newArrayList(new IssueFilterFavouriteDto().setId(10L).setUserLogin("john").setIssueFilterId(1L)));
- service.toggleFavouriteIssueFilter(1L, userSession);
+ boolean result = service.toggleFavouriteIssueFilter(1L, userSession);
+ assertThat(result).isFalse();
verify(issueFilterFavouriteDao).delete(10L);
}