Skip to content

Commit d4c79b5

Browse files
committed
impr: Implemented "getNativeData" functionality (close #4)
1 parent 8600027 commit d4c79b5

File tree

7 files changed

+53
-23
lines changed

7 files changed

+53
-23
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"authors": [
55
"Jonathan Hornung <jonathan.hornung@gmail.com>"
66
],
7-
"version": "0.1.1",
7+
"version": "0.1.2",
88
"description": "github plugin for apiNG",
99
"main": "dist/apiNG-plugin-github.min.js",
1010
"moduleType": [],

demo/aping-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ apingApp.config(['$provide', function ($provide) {
1212
orderBy : "updated_timestamp",
1313
orderReverse : "true",
1414
model: "repo",
15+
getNativeData: false
1516
});
1617

1718
}]);

demo/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
<script src="../src/aping-github-helper.js"></script>
1616
</head>
1717
<body ng-app="app">
18+
<!--
1819
<h1>Activity by User</h1>
1920
<aping
2021
model="activity"
2122
items="40"
2223
aping-github="[{'user':'passy'}]">
2324
</aping>
2425
<hr>
26+
-->
2527
<h1>Repos by User</h1>
2628
<aping model="repo" items="40" aping-github="[{'user':'JohnnyTheTank'}]"></aping>
2729
<hr>

dist/aping-plugin-github.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aping-plugin-github",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "github plugin for apiNG",
55
"main": "Gruntfile.js",
66
"scripts": {

src/aping-github-directive.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,70 @@ var jjtApingGithub = angular.module("jtt_aping_github", ['jtt_github'])
2020

2121
requests.forEach(function (request) {
2222

23-
var githubSearchObject = {
23+
//create helperObject for helper function call
24+
var helperObject = {
25+
model: appSettings.model,
26+
};
27+
if(typeof appSettings.getNativeData !== "undefined") {
28+
helperObject.getNativeData = appSettings.getNativeData;
29+
} else {
30+
helperObject.getNativeData = false;
31+
}
32+
33+
//create requestObject for api request call
34+
var requestObject = {
2435
access_token: apingUtilityHelper.getApiCredentials(apingGithubHelper.getThisPlattformString(), "access_token"),
2536
per_page: request.items || appSettings.items,
2637
};
2738

2839
if(request.user) {
2940

30-
githubSearchObject.user = request.user;
41+
requestObject.user = request.user;
3142

3243
switch(appSettings.model) {
3344
case "repo":
3445

3546
if(request.repo) {
36-
githubSearchObject.repo = request.repo;
47+
requestObject.repo = request.repo;
3748

38-
githubFactory.getRepoByUserAndName(githubSearchObject).success(function(_data){
39-
apingController.concatToResults(apingGithubHelper.getObjectByJsonData(_data, appSettings.model));
49+
githubFactory.getRepoByUserAndName(requestObject).success(function(_data){
50+
apingController.concatToResults(apingGithubHelper.getObjectByJsonData(_data, helperObject));
4051
}).error(function (_data) {
4152
//on error
4253
});
4354
} else {
44-
githubFactory.getReposByUser(githubSearchObject).success(function(_data){
45-
apingController.concatToResults(apingGithubHelper.getObjectByJsonData(_data, appSettings.model));
55+
githubFactory.getReposByUser(requestObject).success(function(_data){
56+
apingController.concatToResults(apingGithubHelper.getObjectByJsonData(_data, helperObject));
4657
}).error(function (_data) {
4758
//on error
4859
});
4960
}
5061
break;
5162

5263
case "activity":
53-
githubFactory.getEventsByUser(githubSearchObject).success(function(_data){
54-
apingController.concatToResults(apingGithubHelper.getObjectByJsonData(_data, appSettings.model));
64+
githubFactory.getEventsByUser(requestObject).success(function(_data){
65+
apingController.concatToResults(apingGithubHelper.getObjectByJsonData(_data, helperObject));
5566
}).error(function (_data) {
5667
//on error
5768
});
5869
break;
5970
}
6071
} else if(request.search) {
6172

62-
githubSearchObject.q = request.search;
73+
requestObject.q = request.search;
6374

6475
if(typeof request.sort !== "undefined") {
65-
githubSearchObject.sort = request.sort;
76+
requestObject.sort = request.sort;
6677
}
6778
if(typeof request.order !== "undefined") {
68-
githubSearchObject.order = request.order;
79+
requestObject.order = request.order;
6980
}
7081

7182
switch(appSettings.model) {
7283
case "repo":
7384

74-
githubFactory.getReposByName(githubSearchObject).success(function(_data){
75-
apingController.concatToResults(apingGithubHelper.getObjectByJsonData(_data, appSettings.model));
85+
githubFactory.getReposByName(requestObject).success(function(_data){
86+
apingController.concatToResults(apingGithubHelper.getObjectByJsonData(_data, helperObject));
7687
}).error(function (_data) {
7788
//on error
7889
});

src/aping-github-helper.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jjtApingGithub.service('apingGithubHelper', ['apingModels', 'apingTimeHelper', '
1515
return "https://github.com/";
1616
};
1717

18-
this.getObjectByJsonData = function (_data, _model) {
18+
this.getObjectByJsonData = function (_data, _helperObject) {
1919
var requestResults = [];
2020
if (_data) {
2121

@@ -24,7 +24,12 @@ jjtApingGithub.service('apingGithubHelper', ['apingModels', 'apingTimeHelper', '
2424
if(_data.constructor === Array) {
2525

2626
angular.forEach(_data, function (value, key) {
27-
var tempResult = _this.getItemByJsonData(value, _model);
27+
var tempResult;
28+
if(_helperObject.getNativeData === true || _helperObject.getNativeData === "true") {
29+
tempResult = value;
30+
} else {
31+
tempResult = _this.getItemByJsonData(value, _helperObject.model);
32+
}
2833
if(tempResult) {
2934
requestResults.push(tempResult);
3035
}
@@ -35,13 +40,23 @@ jjtApingGithub.service('apingGithubHelper', ['apingModels', 'apingTimeHelper', '
3540

3641
if(_data.items) {
3742
angular.forEach(_data.items, function (value, key) {
38-
var tempResult = _this.getItemByJsonData(value, _model);
43+
var tempResult;
44+
if(_helperObject.getNativeData === true || _helperObject.getNativeData === "true") {
45+
tempResult = value;
46+
} else {
47+
tempResult = _this.getItemByJsonData(value, _helperObject.model);
48+
}
3949
if(tempResult) {
4050
requestResults.push(tempResult);
4151
}
4252
});
4353
} else {
44-
var tempResult = _this.getItemByJsonData(_data, _model);
54+
var tempResult;
55+
if(_helperObject.getNativeData === true || _helperObject.getNativeData === "true") {
56+
tempResult = _data;
57+
} else {
58+
tempResult = _this.getItemByJsonData(_data, _helperObject.model);
59+
}
4560
if(tempResult) {
4661
requestResults.push(tempResult);
4762
}
@@ -59,10 +74,11 @@ jjtApingGithub.service('apingGithubHelper', ['apingModels', 'apingTimeHelper', '
5974
case "repo":
6075
returnObject = this.getRepoItemByJsonData(_item);
6176
break;
62-
77+
/*
6378
case "activity":
6479
returnObject = this.getActivityItemByJsonData(_item);
6580
break;
81+
*/
6682

6783
default:
6884
return false;

0 commit comments

Comments
 (0)