forked from CodewarsClone/Codewars
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhomeCtrl.js
More file actions
61 lines (48 loc) · 2.14 KB
/
Copy pathhomeCtrl.js
File metadata and controls
61 lines (48 loc) · 2.14 KB
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
61
/***********HOME CONTROLLER***********/
angular.module('app').controller('homeCtrl', function($scope, $state, mainService) {
mainService.checkAuth();
$scope.languageOptions = ["JavaScript", "Ruby", "C++"];
$scope.progressOptions = ["Fundamentals", "Rank Up", "Practice and Repeat", "Beta", "Random"];
//Dummy userKatas for purposes of styling.
$scope.userKatas = [{kyu: 8, id: 1, name: "Kata name", script: "var a = 1", tags: ['FUNDAMENTALS']},{kyu: 8, id: 2, name: "Kata name", script: "var a = 1", tags: ['FUNDAMENTALS']},{kyu: 8, id: 3, name: "Kata name", script: "var a = 1", tags: ['FUNDAMENTALS']}]
$scope.getUser = () => {
mainService.getUser().then(response => {
console.log(response.data);
mainService.user = response.data;
mainService.user.kyu_level = mainService.rankCalculator(mainService.user);
$scope.getUserKatas(mainService.user.id);
$scope.getRandomKata();
})
}
$scope.getRandomKata = () => {
let oldId;
if ($scope.randomKata) {
oldId = $scope.randomKata.id
}
mainService.getRandomKata(mainService.user.kyu_level).then(response => {
if (oldId) {
if (response.data.id === oldId) {
return $scope.getRandomKata(mainService.user.kyu_level);
} else {
return $scope.randomKata = response.data;
}
}
$scope.randomKata = response.data;
})
}
$scope.getUserKatas = (userid) => {
mainService.getUserKatas(userid).then(response => {
$scope.userKatas = response.data;
console.log($scope.userKatas);
})
}
$scope.voteKata = (kataid, vote) => { // the vote is a true or false value
mainService.voteKata(mainService.user.id, kataid, vote).then(response => {
$scope.kataVotes = response.data;
console.log($scope.kataVotes);
})
}
// the random kata is stored on $scope.randomKata.
// If there is a button you can link the button to $scope.getRandomKata
$scope.getUser();
});