Skip to content

Commit

Permalink
#212 Add Watch toggle component to project page
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylampada committed Dec 30, 2013
1 parent 738f4b8 commit ce49ad0
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
5 changes: 5 additions & 0 deletions djangoproject/core/services/watch_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def is_watching_issue(user, issue_id):
return not watch is None


def is_watching_project(user, project_id):
watch = _findWatchOrNone(user, 'PROJECT', project_id)
return not watch is None


def _findWatchOrNone(user, entity, objid):
watches = Watch.objects.filter(user__id=user.id, entity=entity, objid=objid)
count = len(watches)
Expand Down
4 changes: 3 additions & 1 deletion djangoproject/core/views/project_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.shortcuts import render_to_response, redirect
from django.template import RequestContext
from core.models import Project, ActionLog
from core.services import stats_services, issue_services
from core.services import stats_services, issue_services, watch_services
from core.views import template_folder
from django.contrib.auth.decorators import login_required

Expand All @@ -18,6 +18,7 @@ def view(request, project_id):
issues_kickstarting = json.dumps(issue_services.to_card_dict(issues_kickstarting))
top_sponsors = stats_services.project_top_sponsors(project_id)[0:5]
top_programmers = stats_services.project_top_programmers(project_id)[0:5]
is_watching = request.user.is_authenticated() and watch_services.is_watching_project(request.user, project.id)
return render_to_response('core2/project.html',
{'project': project,
'stats': stats,
Expand All @@ -26,6 +27,7 @@ def view(request, project_id):
'issues_kickstarting': issues_kickstarting,
'top_sponsors': top_sponsors,
'top_programmers': top_programmers,
'is_watching': is_watching,
},
context_instance=RequestContext(request))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<span>
<a ng-show="showWatchLink()" href="{[{watchLink}]}">
<a class="iconized watch" ng-show="showWatchLink()" href="{[{watchLink}]}">
{[{ action() }]}
</a>
<a ng-hide="showWatchLink()" href ng-click="toggle()">
<a class="iconized watch" ng-hide="showWatchLink()" href ng-click="toggle()">
{[{ action() }]}
</a>
<img src="/static/img2/ajax-loader.gif" ng-show="loading">
Expand Down
2 changes: 1 addition & 1 deletion djangoproject/statfiles/static/js/angularutils/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

var mod = angular.module('watch', ['fsapi']);

mod.directive('watchIssue', function() {
mod.directive('watchEntity', function() {
return {
restrict: 'E',
replace: true,
Expand Down
6 changes: 4 additions & 2 deletions djangoproject/templates/core2/issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@

var mod = angular.module('issue', dependencies);
mod.config(
function($interpolateProvider){
function($interpolateProvider, $httpProvider){
$interpolateProvider.startSymbol('{[{').endSymbol('}]}');
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
}
);

Expand Down Expand Up @@ -523,7 +525,7 @@ <h4 class="arial">Paid</h4>
<div class="card-status {{ issue.get_status }}"></div>
<!-- Box Footer -->
<div class="fs-box-footer">
<watch-issue entity="ISSUE" objid="{{ issue.id }}" watching="watching" watch-link="watchLink"></watch-issue>
<watch-entity entity="ISSUE" objid="{{ issue.id }}" watching="watching" watch-link="watchLink"></watch-entity>
</div>
</div>

Expand Down
11 changes: 9 additions & 2 deletions djangoproject/templates/core2/project.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<script src="/static/js/issuecards/issuecards.js"></script>
<script src="/static/js/activitylist/activitylist.js"></script>
<script src="/static/js/fsutil.js"></script>
<script src="/static/js/angularutils/watch.js"></script>
{% if sandbox %}
<script src="/static/js/tags/tag_api_mock.js"></script>
<script src="/static/js/fsapi_mock.js"></script>
Expand All @@ -24,7 +25,7 @@
<script src="/static/bootstrap/js/showdown.js"></script>
<script>

var dependencies = ['issuecards', 'angularutils', 'taglist', 'activitylist'];
var dependencies = ['issuecards', 'angularutils', 'taglist', 'activitylist', 'watch'];

var mod = angular.module('project', dependencies);
mod.config(
Expand All @@ -38,6 +39,11 @@
mod.controller("MyCtrl", function($scope){
$scope.tags = {{ tags|safe }};
$scope.authenticated = {% if user.is_authenticated %}true{% else %}false{% endif %};
$scope.watching = 'True' == '{{ is_watching }}';
$scope.watchLink = '';
if(!$scope.authenticated){
$scope.watchLink = '/core/login?next=/project/{{ project.id }}';
}

var issues_sponsoring = {{ issues_sponsoring|safe }};
for(var i=0; i < issues_sponsoring.length; i++){
Expand Down Expand Up @@ -113,7 +119,8 @@ <h3 class="arial green-text">{{ project.name }}</h3>
<div>
<a class="iconized edit" href="/project/{{ project.id }}/edit">edit project</a>
<div class="hgap-10 inline"><!-- Horizontal Gap 10px --></div>
<a class="iconized watch" href="">watch</a>
{# <a class="iconized watch" href="">watch</a>#}
<watch-entity entity="PROJECT" objid="{{ project.id }}" watching="watching" watch-link="watchLink"></watch-entity>
</div>
</div>
<!-- Project Description: Please limit to characters -->
Expand Down

0 comments on commit ce49ad0

Please sign in to comment.