/
app.js
99 lines (85 loc) · 2.26 KB
/
app.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
/* globals ANGTREX */
var angtrex = angtrex || {};
angtrex.app = angular.module( 'angtrex', [
'ui.router',
'ngResource'
]
);
/**
* Translations
*/
angtrex.app.service('translationService', function ($scope) {
$scope.translations = ANGTREX.translations;
});
/*
* UI Router States
*/
angtrex.app.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/posts');
$stateProvider
.state('list', {
url: '/posts',
templateUrl: ANGTREX.partials_dir + 'posts.html',
controller: 'ListController'
})
.state('single', {
url: '/posts/:id',
templateUrl: ANGTREX.partials_dir + 'post.html',
controller: 'SingleController'
})
});
/**
* List Controller
*/
angtrex.app.controller( 'ListController', ['$scope', '$rootScope', 'postsFactory', 'translationService', function( $scope, $rootScope, postsFactory, translationService ){
postsFactory.query(function(res){
$scope.posts = res;
console.log( $scope.posts );
});
}]);
/*
* Single post controller
*/
angtrex.app.controller( 'SingleController', ['$scope', '$rootScope', 'postsFactory', '$stateParams', function( $scope, $rootScope, postsFactory, $stateParams, translationService ){
postsFactory.get({ id: $stateParams.id}, function(res){
$scope.post = res;
})
}]);
/**
* Posts Factory
*/
angtrex.app.factory( 'postsFactory', function( $resource ){
return $resource( ANGTREX.api_url + 'wp/v2/posts/:id', {
id: '@id'
},{
'query':{
method: 'GET',
isArray: true,
url: ANGTREX.api_url + 'wp/v2/posts?filter[posts_per_page]=-1',
},
'update':{
method:'POST',
headers: {
'X-WP-Nonce': ANGTREX.nonce
}
},
'post':{
method:'POST',
headers: {
'X-WP-Nonce': ANGTREX.nonce
}
},
'save':{
method:'POST',
headers: {
'X-WP-Nonce': ANGTREX.nonce
}
},
'delete':{
method:'DELETE',
headers: {
'X-WP-Nonce': ANGTREX.nonce
}
}
});
} );