-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
60 lines (53 loc) · 1.94 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// also include ngRoute for all our routing needs
var trump = angular.module('trump', ['ngRoute', 'ngSanitize']);
// configure our routes
trump.config(function($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'pages/home.html',
controller : 'mainController'
})
});
// create the controller and inject Angular's $scope
trump.controller('mainController', function(TwitterAPI, $scope) {
$scope.twitterHandle = '';
$scope.error = '';
$scope.boxClass = false;
$scope.sentimentTweets = [];
// create a message to display in our view
$scope.checkTweets = function () {
TwitterAPI.embedTweet('nostvlgiv', 121212);
TwitterAPI.getTweets($scope.twitterHandle).then(function(res) {
if(res.data == 0) {
$scope.error = "There is nothing bad in your twitter handle :)";
}
else {
$scope.twitterHandle = '';
$scope.error = '';
$scope.boxClass = true;
angular.forEach(res.data, function(value, key) {
// console.log(value);
TwitterAPI.embedTweet(value.id_str).then(function(res) {
$scope.sentimentTweets.push(res.data);
$('.twitter-tweet').delegate("a", "click", function(){
window.open($(this).attr('href'));
return false;
});
});
});
console.log($scope.sentimentTweets);
}
});
}
});
trump.service('TwitterAPI', function($http) {
var API = 'http://localhost:8080';
var self = this;
self.getTweets = function(username) {
return $http.get(API + '/tweets/' + username);
}
self.embedTweet = function(id) {
return $http.get(API + '/embed/' + id);
}
})