article.service.js
3.95 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
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
(function() {
'use strict';
angular
.module('dialoga')
.factory('ArticleService', ArticleService);
/** @ngInject */
function ArticleService($http, $q, $rootScope, API, UtilService, Slug, $log) {
$log.debug('ArticleService');
var service = {
apiArticles: $rootScope.basePath + '/api/v1/articles/',
getArticleById: getArticleById,
getArticleBySlug: getArticleBySlug,
getCategories: getCategories,
getCategoryBySlug: getCategoryBySlug,
getTopics: getTopics,
getTopicById: getTopicById,
searchTopics: searchTopics,
searchProposals: searchProposals
};
return service;
function _getArticleById (articleId, params, cbSuccess, cbError) {
var url = service.apiArticles + articleId;
var paramsExtended = angular.extend({}, params);
UtilService.get(url, {params: paramsExtended}).then(function(data){
cbSuccess(data);
}).catch(function(error){
cbError(error);
});
}
function getArticleById (articleId, params, cbSuccess, cbError) {
_getArticleById(articleId, params, cbSuccess, cbError);
}
function getArticleBySlug (/*slug, params, cbSuccess, cbError*/) {
throw { name: 'NotImplementedYet', message: 'The service "getArticleBySlug" is not implemented yet.'};
}
function getCategories (articleId, cbSuccess, cbError) {
// Ex.: /api/v1/articles/103358?fields=
var url = service.apiArticles + articleId;
UtilService.get(url, {params: {
'fields[]': ['id', 'categories']
}}).then(function(data){
cbSuccess(data);
}).catch(function(error){
cbError(error);
});
}
function getCategoryBySlug () {
throw { name: 'NotImplementedYet', message: 'The service "getArticleBySlug" is not implemented yet.'};
}
function getTopics (cbSuccess, cbError) {
// Ex.: /api/v1/articles/103358/children?fields=
var url = service.apiArticles + API.articleId.home + '/children';
UtilService.get(url, {params: {
'fields[]': ['id', 'title', 'slug', 'abstract', 'categories', 'setting', 'children_count', 'hits']
}}).then(function(data){
cbSuccess(data);
}).catch(function(error){
cbError(error);
});
}
function getTopicById (topicId, cbSuccess, cbError) {
// Ex.: /api/v1/articles/103358/children/121521?fields=
// var url = service.apiArticles + API.articleId.home + '/children/' + topicId; // dont need to chain
var url = service.apiArticles + topicId;
UtilService.get(url, {params: {
'fields[]': ['id', 'title', 'body', 'slug', 'abstract', 'categories', 'setting', 'children_count', 'hits']
}}).then(function(data){
cbSuccess(data);
}).catch(function(error){
cbError(error);
});
}
function searchTopics (params, cbSuccess, cbError) {
// Ex.: /api/v1/search/article?type=ProposalsDiscussionPlugin::Topic&query=cisternas
var url = '/api/v1/search/article';
var paramsExtended = angular.extend({
'fields[]': ['id', 'title', 'slug', 'abstract', 'categories', 'setting', 'children_count', 'hits'],
'type': 'ProposalsDiscussionPlugin::Topic'
}, params);
UtilService.get(url, {params: paramsExtended}).then(function(data){
cbSuccess(data);
}).catch(function(error){
cbError(error);
});
}
function searchProposals (params, cbSuccess, cbError) {
// Ex.: /api/v1/search/article?type=ProposalsDiscussionPlugin::Proposal&query=cisternas
var url = '/api/v1/search/article';
var paramsExtended = angular.extend({
'fields[]': ['id', 'title', 'slug', 'abstract', 'categories', 'setting', 'children_count', 'hits'],
'type': 'ProposalsDiscussionPlugin::Proposal'
}, params);
UtilService.get(url, {params: paramsExtended}).then(function(data){
cbSuccess(data);
}).catch(function(error){
cbError(error);
});
}
}
})();