Skip to content

Commit

Permalink
#212 Select tags for project. Tags are fetched from StackOverflow.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylampada committed Dec 23, 2013
1 parent 8e24893 commit 1ac423f
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 2 deletions.
1 change: 1 addition & 0 deletions djangoproject/sandbox/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def project(request):
u'Coloque 200 ml de água em uma panela, adicione o miojo, deixe\n'
u'ferver por 3 minutos. Adicione o tempero e pronto!',
'get_image3x1': '/static/img2/fs_logo.png',
'get_tags': ['tag1', 'tag2']
}
_stats = {
'issues_open': 2,
Expand Down
23 changes: 23 additions & 0 deletions djangoproject/statfiles/static/js/so/soapi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var mod = angular.module('soapi', []);

mod.factory('SOApi', function($http){
var get_tags = "https://api.stackexchange.com/2.1/tags";


function getTags(s){
return $http({
url: get_tags,
method: "GET",
params: {
order: 'desc',
sort: 'popular',
inname: s,
site: 'stackoverflow'
}
});
}

return {
getTags: getTags
};
})
12 changes: 12 additions & 0 deletions djangoproject/statfiles/static/js/tags/taglist.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div>
<a href="" class="tag" ng-repeat="tag in tags" style="margin-right: 10px;">{[{tag}]}</a>
<div>
<input type="text" ng-model="newtag" ng-keypress="keypress()">
<div ng-show="poptags">
<ul>
<li ng-repeat="poptag in poptags" ng-click="addTag(poptag)">{{ poptag.name }}</li>
</ul>
</div>
<img src="/static/img2/ajax-loader.gif" ng-show="loading">
</div>
</div>
64 changes: 64 additions & 0 deletions djangoproject/statfiles/static/js/tags/taglist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
*
Copyright (C) 2013 FreedomSponsors
The JavaScript code in this page is free software: you can
redistribute it and/or modify it under the terms of the GNU
AFFERO GENERAL PUBLIC LICENSE (GNU AGPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
For more information, refer to
https://github.com/freedomsponsors/www.freedomsponsors.org/blob/master/AGPL_license.txt
*/

var mod = angular.module('taglist', ['soapi' /*'tagsapi'*/]);
mod.directive('taglist', function() {
return {
restrict: 'E',
replace: true,
scope:{
type: "@",
objid: "@"
},
templateUrl: '/static/js/tags/taglist.html',
controller: function ($scope, $timeout, SOApi /*, TagApi, SOApi*/) {
$scope.tags = ["java", "python"];
$scope.poptags = [];

var timer = undefined;

function restartTimer(){
if(timer){
$timeout.cancel(timer);
}
timer = $timeout(getTags, 200);
}

function getTags(){
$scope.loading = true;
SOApi.getTags($scope.newtag).success(function(result){
$scope.loading = false;
$scope.poptags = result.items;
})
}

$scope.keypress = function(){
restartTimer();
};

$scope.addTag = function(t){
$scope.tags.push(t.name);
$scope.poptags = [];
}
}
}
});
28 changes: 26 additions & 2 deletions djangoproject/templates/core2/project.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,31 @@
{% load l10n %}


{% block head %}
<script src="/static/js/angular.min.js"></script>
<script src="/static/js/angularutils/angularutils.js"></script>
<script src="/static/js/so/soapi.js"></script>
<script src="/static/js/tags/taglist.js"></script>
<script src="/static/bootstrap/js/showdown.js"></script>
<script>

var dependencies = ['angularutils', 'taglist'];

var mod = angular.module('project', dependencies);
mod.config(
function($interpolateProvider){
$interpolateProvider.startSymbol('{[{').endSymbol('}]}');
}
);

mod.controller("MyCtrl", function($scope){
});
</script>
{% endblock %}


{% block mainContent%}
<div class="content" align="center">
<div class="content" align="center" ng-app="project" ng-controller="MyCtrl">
<div class="home-content-section" align="left">
<!-- Project Header -->
<div style="height:160px">
Expand Down Expand Up @@ -72,8 +95,9 @@ <h3 class="arial green-text">{{ project.name }}</h3>
<!-- Tags -->
<div class="tag-list">
{% for tag in project.get_tags %}
<a href="" class="tag">{{ tag.name }}</a>
<a href="" class="tag">{{ tag }}</a>
{% endfor %}
<taglist type="Project" objid="{[{ project.id }]}"></taglist>
</div>
</div>
</div>
Expand Down

0 comments on commit 1ac423f

Please sign in to comment.