mk200789 10 лет назад
Родитель
Сommit
10a45a3c2b

+ 20 - 0
angular/index.html

@@ -5,13 +5,33 @@
 
         <title data-ng-bind="pageTitle + ' | RestAPP'">RestAPP</title>
 
+        <!-- AngularJS -->
         <script src="vendor/angular/angular.js"></script>
         <script src="vendor/angular-ui-router/release/angular-ui-router.min.js"></script>
 
+        <!-- Bootstrap Core CSS -->
+        <link href="vendor/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
+
+        <!-- jQuery -->
+        <script src="vendor/jquery/dist/jquery.min.js"></script>
+
+        <!-- Bootstrap Core JavaScript -->
+        <script src="vendor/bootstrap/dist/js/bootstrap.min.js"></script>
+
+        <!-- Main application file -->
         <script src="scripts/app.js"></script>
+
+        <!-- Controllers --> 
         <script src="scripts/controllers/appController.js"></script>
         <script src="scripts/controllers/restAppController.js"></script>
+        <script src="scripts/controllers/githubUserController.js"></script>
+        <script src="scripts/controllers/githubTopContributionsController.js"></script>
+
+        <!-- Factories -->
         <script src="scripts/factories/restAppFactory.js"></script>
+        <script src="scripts/factories/githubUserFactory.js"></script>
+        <script src="scripts/factories/githubTopContributionsFactory.js"></script>
+
     </head>
 
     <body>

+ 24 - 0
angular/partials/githubTopContributions.partial.html

@@ -0,0 +1,24 @@
+<div class="row text-center">
+	<h1> Github Top Contributed Repositories</h1>
+</div>
+
+<div class="col-lg-12">
+    <div class="table-responsive">
+        <table class="table table-bordered table-hover table-striped tablesorter">
+            <thead>
+                <tr>
+                    <th class="header">Repository Name</th>
+                    <th class="header">Total Commits</th>
+                    <th class="header">Author</th>
+                </tr>
+            </thead>
+            <tbody>
+                <tr data-ng-repeat="data in githubTopContributions.data.committed">
+                        <td>{{ data.repo_name }}</td>
+                        <td>{{ data.total }}</td>
+                        <td>{{ data.author }}</td>
+                </tr>
+            </tbody>
+        </table>
+    </div>
+</div>

+ 34 - 0
angular/partials/githubUser.partial.html

@@ -0,0 +1,34 @@
+<div class="row text-center"> <h1> Github User Data </h1>
+</div>
+
+<div class="col-lg-12">
+    <div class="table-responsive">
+        <table class="table table-bordered table-hover table-striped tablesorter">
+            <thead>
+                <tr>
+                    <th class="header">Public Repos</th>
+                    <th class="header">Public Gists</th>
+                    <th class="header">Name</th>
+                    <th class="header">Blog</th>
+                    <th class="header">Followers</th>
+                    <th class="header">Following</th>
+                    <th class="header">E-mail</th>
+                </tr>
+            </thead>
+            <tbody>
+                <tr data-ng-repeat="data in githubUser.data.userData">
+                        <td>{{ data.public_repos }}</td>
+                        <td>{{ data.public_gists }}</td>
+                        <td>{{ data.name }}</td>
+                        <td>{{ data.blog }}</td>
+                        <td>{{ data.followers }}</td>
+                        <td>{{ data.following }}</td>
+                        <td>{{ data.email }}</td>
+                </tr>
+            </tbody>
+        </table>
+    </div>
+</div>
+
+
+

+ 22 - 3
angular/partials/snippets.partial.html

@@ -1,5 +1,24 @@
-<div data-ng-repeat="data in restData">
-    <div data-ng-repeat="datum in data track by $index">
-        {{ datum }}
+<div class="row text-center">
+	<h1> Code Snippets </h1>
+</div>
+
+<div class="col-lg-12">
+    <div class="table-responsive">
+        <table class="table table-bordered table-hover table-striped tablesorter">
+            <thead>
+                <tr>
+                    <th class="header">Code</th>
+                    <th class="header">ID</th>
+                    <th class="header">Line Numbers</th>
+                </tr>
+            </thead>
+            <tbody>
+                <tr data-ng-repeat="data in restData">
+	                    <td>{{ data.code }}</td>
+	                    <td>{{ data.id }}</td>
+	                    <td>{{ data.linenos }}</td>
+                </tr>
+            </tbody>
+        </table>
     </div>
 </div>

+ 19 - 1
angular/scripts/app.js

@@ -10,7 +10,25 @@ var restApp = angular.module('restApp', [
             templateUrl: 'partials/snippets.partial.html',
             controller: 'restAppController',
             data: {
-                pageTitle: 'Sample API data'
+                pageTitle: 'Sample API Data'
+            }
+        })
+
+        .state('githubUser', {
+            url: '/githubUser',
+            templateUrl: 'partials/githubUser.partial.html',
+            controller: 'githubUserController',
+            data: {
+                pageTitle: 'Github User Data'
+            }
+        })
+
+        .state('githubTopContributions', {
+            url: '/githubTopContributions',
+            templateUrl: 'partials/githubTopContributions.partial.html',
+            controller: 'githubTopContributionsController',
+            data: {
+                pageTitle: 'Top Contributions on Github'
             }
         });
 });

+ 10 - 0
angular/scripts/controllers/githubTopContributionsController.js

@@ -0,0 +1,10 @@
+'use strict';
+
+restApp.controller('githubTopContributionsController', function($scope, githubTopContributionsFactory) {
+    $scope.githubTopContributions = {};
+    
+    $scope.githubTopContributions = githubTopContributionsFactory.get().success(function(data) {
+    	$scope.githubTopContributions = data;
+    	console.log(data);
+    });
+});

+ 10 - 0
angular/scripts/controllers/githubUserController.js

@@ -0,0 +1,10 @@
+'use strict';
+
+restApp.controller('githubUserController', function($scope, githubUserFactory) {
+    $scope.githubUser = {};
+    
+    $scope.githubUser = githubUserFactory.get().success(function(data) {
+    	$scope.githubUser = data;
+    	console.log(data);
+    });
+});

+ 12 - 0
angular/scripts/factories/githubTopContributionsFactory.js

@@ -0,0 +1,12 @@
+'use strict';
+
+restApp.factory('githubTopContributionsFactory', function($http) {
+    return {
+        get: function() {
+            return $http({
+                url: 'http://127.0.0.1:8000/hackathon/githubTopRepositories/',
+                method: 'GET',
+            });
+        }
+    };
+});

+ 12 - 0
angular/scripts/factories/githubUserFactory.js

@@ -0,0 +1,12 @@
+'use strict';
+
+restApp.factory('githubUserFactory', function($http) {
+    return {
+        get: function() {
+            return $http({
+                url: 'http://127.0.0.1:8000/hackathon/githubUser/',
+                method: 'GET',
+            });
+        }
+    };
+});

+ 1 - 1
hackathon_starter/hackathon/templates/hackathon/api_examples.html

@@ -4,7 +4,7 @@
 
 
 	<div class="row text-center">
-	    <div class="col-sm-4"><a href="http://127.0.0.1:8000/hackathon/github/">Github Example</a></div>
+	    <div class="col-sm-4"><a href="http://127.0.0.1:8000/hackathon/githubResume/">Github Example</a></div>
 	    <div class="col-sm-4"><a href="http://127.0.0.1:8000/hackathon/steam/">Steam Example</a></div>
 	    <div class="col-sm-4"><a href={{tumblr_url}}>Tumblr Example</a></div>
 		<div class="col-sm-4"><a href="http://127.0.0.1:8000/hackathon/linkedin/">LinkedIn Example</a></div>

+ 5 - 3
hackathon_starter/hackathon/urls.py

@@ -9,10 +9,12 @@ urlpatterns = patterns('',
     url(r'^logout/$', views.user_logout, name='logout'),
     url(r'^api/$', views.api_examples, name='api'),
     url(r'^steam/$', views.steam, name='steam'),
-    url(r'^github/$', views.github, name='github'),
+    url(r'^githubResume/$', views.githubResume, name='githubResume'),
+    url(r'^githubUser/$', views.githubUser, name='githubUser'),
+    url(r'^githubTopRepositories/$', views.githubTopRepositories, name='githubTopRepositories'),
     url(r'^tumblr/$', views.tumblr, name='tumblr'),
     url(r'^linkedin/$', views.linkedin, name='linkedin'),
     url(r'^snippets/$', views.snippet_list, name='snippets'),
-    url(r'^twilio/$', views.twilio, name="twilio"),
-    url(r'^instagram/$', views.instagram, name="instagram"),
+    url(r'^twilio/$', views.twilio, name='twilio'),
+    url(r'^instagram/$', views.instagram, name='instagram'),
 )

+ 106 - 48
hackathon_starter/hackathon/views.py

@@ -36,10 +36,18 @@ def index(request):
     context = {'hello': 'world'}
     return render(request, 'hackathon/index.html', context)
 
+##################
+#   Twilio API   #
+##################
+
 def twilio(request):
     sendSMS('Meow', '+13473282978', '+13473781813')
     return render(request, 'hackathon/twilio.html')
 
+##################
+#  API Examples  #
+##################
+
 def api_examples(request):
     instagram_url =getInstagram.get_authorize_url()
     if not getTumblr.accessed:
@@ -49,52 +57,9 @@ def api_examples(request):
     context = {'title': 'API Examples Page', 'tumblr_url': obtain_oauth_verifier, 'instagram_url':instagram_url}
     return render(request, 'hackathon/api_examples.html', context)
 
-def register(request):
-    registered = False
-    if request.method == 'POST':
-        user_form = UserForm(data=request.POST)
-        if user_form.is_valid():
-            user = user_form.save()
-            user.set_password(user.password)
-            user.save()
-            registered = True
-        else:
-            print user_form.errors
-    else:
-        user_form = UserForm()
-
-    
-    return render(request,
-            'hackathon/register.html',
-            {'user_form': user_form, 'registered': registered} )
-
-def user_login(request):
-
-    
-    if request.method == 'POST':
-        username = request.POST.get('username')
-        password = request.POST.get('password')
-
-
-        user = authenticate(username=username, password=password)
-
-
-        if user:
-            if user.is_active:
-                login(request, user)
-                return HttpResponseRedirect('/hackathon/')
-            else:
-                return HttpResponse("Your Django Hackathon account is disabled.")
-        else:
-            print "Invalid login details: {0}, {1}".format(username, password)
-            return HttpResponse("Invalid login details supplied.")
-
-    else:
-        return render(request, 'hackathon/login.html', {})
-
-def user_logout(request):
-    logout(request)
-    return HttpResponseRedirect('/hackathon/')
+#################
+#   STEAM API   #
+#################
 
 def steam(request):
     #Should link to test of Steam API example.
@@ -104,7 +69,32 @@ def steam(request):
     game = gamesPulling(steamID, key)
     return render(request,'hackathon/steam.html', {"game": game })
 
-def github(request):
+
+#################
+#   GITHUB API  #
+#################
+
+
+def githubUser(request):
+    '''Returns JSON response about a specific Github User'''
+
+    parsedData = {}
+    parsedData['userData'] = getUserData(settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
+    return JsonResponse({ 'data': parsedData })
+
+def githubTopRepositories(request):
+    '''Returns JSON response of a User's Top Committed repositories'''
+
+    parsedData = {}
+    repositories = getUserRepositories(settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
+    list = getTopContributedRepositories(repositories, settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
+    filtered = filterCommits(list)
+    parsedData['committed'] = filtered
+    return JsonResponse({ 'data': parsedData })
+
+def githubResume(request):
+    '''A sample application which pulls various Github data to form a Resume of sorts'''
+    
     allData = {}
     userData = getUserData(settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
     repositories = getUserRepositories(settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
@@ -117,9 +107,13 @@ def github(request):
     allData['filteredData'] = filtered
     allData['filteredStargazers'] = filteredStargazers
     allData['forkedRepos'] = forkedRepos
-
     return render(request, 'hackathon/github.html', { 'data': allData })
 
+
+#################
+#   TUMBLR API  #
+#################
+
 def tumblr(request):
     ''' Tumblr api calls '''
     #retrieve verifier via url link
@@ -139,6 +133,11 @@ def tumblr(request):
     context = {'title': "What's up Starbucks?", 'blogData': blog, 'blogTag': tagged_blog, 'blogontag': blogontag, 'userinfo': userinfo, 'total_blog':total_blog}
     return render(request, 'hackathon/tumblr.html', context)
 
+
+####################
+#   INSTAGRAM API  #
+####################
+
 def instagram(request):
     search_tag = 'kitten'
     code = request.GET['code']
@@ -148,11 +147,20 @@ def instagram(request):
     context = {'title': 'Instagram', 'tagged_media': tagged_media, 'search_tag': search_tag}
     return render(request, 'hackathon/instagram.html', context)
 
+##################
+#  LINKED IN API #
+##################
+
 def linkedin(request):
     userinfo = getUserInfo()
     context = {'title': 'linkedin Example','userdata': userinfo}
     return render(request, 'hackathon/linkedin.html', context)
 
+
+#########################
+# Snippet RESTful Model #
+#########################
+
 class JSONResponse(HttpResponse):
     """
     An HttpResponse that renders its content into JSON.
@@ -172,3 +180,53 @@ def snippet_list(request):
         serializer = SnippetSerializer(snippets, many=True)
         return JSONResponse(serializer.data)
 
+
+######################
+# Registration Views #
+######################
+
+def register(request):
+    registered = False
+    if request.method == 'POST':
+        user_form = UserForm(data=request.POST)
+        if user_form.is_valid():
+            user = user_form.save()
+            user.set_password(user.password)
+            user.save()
+            registered = True
+        else:
+            print user_form.errors
+    else:
+        user_form = UserForm()
+
+    
+    return render(request,
+            'hackathon/register.html',
+            {'user_form': user_form, 'registered': registered} )
+
+def user_login(request):
+    if request.method == 'POST':
+        username = request.POST.get('username')
+        password = request.POST.get('password')
+
+
+        user = authenticate(username=username, password=password)
+
+
+        if user:
+            if user.is_active:
+                login(request, user)
+                return HttpResponseRedirect('/hackathon/')
+            else:
+                return HttpResponse("Your Django Hackathon account is disabled.")
+        else:
+            print "Invalid login details: {0}, {1}".format(username, password)
+            return HttpResponse("Invalid login details supplied.")
+
+    else:
+        return render(request, 'hackathon/login.html', {})
+
+def user_logout(request):
+    logout(request)
+    return HttpResponseRedirect('/hackathon/')
+