-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
143 lines (124 loc) · 4.26 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
var gw2Items = angular.module('gw2Items', ['ngRoute','angles']);
// configure our routes
gw2Items.config(function($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'partials/home.html',
controller : 'mainController'
})
// route for the weapon page list
.when('/weapons', {
templateUrl : 'partials/weapons.html',
controller : 'weaponController'
})
.when('/weapons/:id', {
templateUrl : 'partials/weapon_detail.html',
controller : 'weaponDetailController'
})
.otherwise({
redirectTo:'/'
});
});
// create the controllers and inject Angular's $scope
gw2Items.controller('mainController', ['$scope','Datasource','$http',function($scope, Datasource, $http) {
Datasource.getGems(function(data) {
$scope.quantity = data.result;
}, $http);
}]);
gw2Items.controller('weaponController', ['$scope', 'Datasource','Currency', '$http',function($scope, Datasource, Currency, $http) {
//initialize page if its null
if($scope.main == null) {
$scope.main = { page: 1 };
}
$scope.loadPage = function() {
Datasource.getWeapons(function(data) {
$scope.weapons = data.weapon_list;
$scope.main.totalPages = data.pages;
$scope.main.page = data.current_page;
$scope.rares = data.rare;
$scope.types = data.type;
$scope.subtypes = data.subtype;
}, $scope.main.page, $http);
$scope.Currency = Currency;
};
//increment page
$scope.nextPage = function() {
if ($scope.main.page < $scope.main.totalPages) {
$scope.main.page++;
$scope.loadPage($scope.main.page);
}
};
//decrement page
$scope.previousPage = function() {
if ($scope.main.page > 1) {
$scope.main.page--;
$scope.loadPage($scope.main.page);
}
};
//initial load
if($scope.weapons == null) {
$scope.loadPage();
}
}]);
gw2Items.controller('weaponDetailController', ['$scope', '$http', 'Datasource','Currency','$routeParams', function($scope, $http, Datasource, Currency, $routeParams) {
$scope.id = $routeParams.id;
$scope.Currency = Currency;
//Grab Chart Data
Datasource.getWeaponCharts(function(data) {
$scope.historyData = data.weapon[0];
$scope.date_list = data.lineChart.date_list.reverse();
$scope.sale_price_list = data.lineChart.sale_price_list.reverse();
$scope.offer_price_list = data.lineChart.offer_price_list.reverse();
$scope.linechart = {
labels: $scope.date_list,
datasets: [
{
label: "Sell Price",
fillColor : "rgba(86,118,247,0.2)",
strokeColor : "rgba(86,118,247,1)",
pointColor : "rgba(86,118,247,1)",
pointStrokeColor : "#fff",
pointHighlightFill : "#fff",
pointHighlightStroke : "rgba(86,118,247,1)",
data: $scope.sale_price_list
},
{
label: "Buy Price",
fillColor : "rgba(51,51,44,0.2)",
strokeColor : "rgba(51,51,44,1)",
pointColor : "rgba(51,51,44,1)",
pointStrokeColor : "#fff",
pointHighlightFill : "#fff",
pointHighlightStroke : "rgba(51,51,44,1)",
data: $scope.offer_price_list
}
]
};
$scope.piechart = [
{
value: $scope.historyData.offer_availability,
color: "#b32e1f",
highlight: "#e84735",
label: "Demand"
},
{
value: $scope.historyData.sale_availability,
color: "#5676f7",
highlight: "#8ca2f7",
label: "Supply"
}
];
}, $scope.id, $http);
//Grab Weapon Details
Datasource.getWeaponDetails(function(data){
$scope.weaponDetail = data;
$scope.attributes = data.weapon.infix_upgrade.attributes;
}, $scope.id, $http);
//Chart Options
$scope.options = {
animation: true,
animationSteps: 60,
responsive: true
};
}]);