-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: added new attribute "valueName" for setting value "apingResu…
…lts"
- Loading branch information
1 parent
71e6c7c
commit 6e6ee62
Showing
6 changed files
with
69 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "apiNG", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"homepage": "https://github.com/JohnnyTheTank/apiNG", | ||
"authors": [ | ||
"Jonathan Hornung <[email protected]>" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/** | ||
@name: aping | ||
@version: 1.0.3 (23-01-2016) | ||
@version: 1.0.4 (23-01-2016) | ||
@author: Jonathan Hornung <[email protected]> | ||
@url: https://github.com/JohnnyTheTank/apiNG | ||
@license: MIT | ||
|
@@ -18,7 +18,8 @@ angular.module('jtt_aping') | |
}); | ||
|
||
}]) | ||
.directive('aping', ['apingDefaultSettings', 'apingUtilityHelper', '$templateRequest', '$compile', function (apingDefaultSettings, apingUtilityHelper, $templateRequest, $compile) { | ||
.value("apingResults", {}) | ||
.directive('aping', ['apingResults', 'apingDefaultSettings', 'apingUtilityHelper', '$templateRequest', '$compile', function (apingResults, apingDefaultSettings, apingUtilityHelper, $templateRequest, $compile) { | ||
return { | ||
restrict: 'E', | ||
replace: 'false', | ||
|
@@ -31,7 +32,8 @@ angular.module('jtt_aping') | |
orderReverse: '@', | ||
templateUrl: '@', | ||
payloadJson: '@', | ||
removeDoubles: '@' | ||
removeDoubles: '@', | ||
valueName: '@' | ||
}, | ||
link: function (scope, element, attrs) { | ||
$templateRequest(scope.templateUrl || apingDefaultSettings.templateUrl).then(function (html) { | ||
|
@@ -56,6 +58,14 @@ angular.module('jtt_aping') | |
var orderReverse; | ||
var orderBy; | ||
var removeDoubles; | ||
var valueName; | ||
|
||
|
||
if (angular.isDefined($scope.valueName)) { | ||
valueName = $scope.valueName; | ||
} else { | ||
valueName = undefined; | ||
} | ||
|
||
if (angular.isDefined($scope.items)) { | ||
items = $scope.items; | ||
|
@@ -120,7 +130,8 @@ angular.module('jtt_aping') | |
maxItems: maxItems, | ||
orderBy: orderBy, | ||
orderReverse: orderReverse, | ||
removeDoubles: removeDoubles | ||
removeDoubles: removeDoubles, | ||
valueName: valueName | ||
}; | ||
}; | ||
|
||
|
@@ -158,6 +169,11 @@ angular.module('jtt_aping') | |
if (appSettings.maxItems > -1 && $scope.results.length > appSettings.maxItems) { | ||
$scope.results = $scope.results.splice(0, appSettings.maxItems); | ||
} | ||
|
||
if(angular.isDefined(appSettings.valueName)) { | ||
apingResults[appSettings.valueName] = $scope.results; | ||
} | ||
|
||
$scope.$broadcast('apiNG.resultMerged'); | ||
}; | ||
this.apply = function () { | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,53 @@ | ||
describe('A apingDefaultSettings Service', function(){ | ||
describe('A apingDefaultSettings Service', function () { | ||
|
||
var $compile; | ||
var $rootScope; | ||
var $q; | ||
|
||
// Mocks & Stubs | ||
var templateRequestMock = function(){ | ||
return $q.when('<template>Test</template>') | ||
var templateRequestMock = function () { | ||
return $q.when('<div><pre>{{results | json}}</pre></div>') | ||
}; | ||
|
||
beforeEach(module('jtt_aping', function($provide){ | ||
beforeEach(module('jtt_aping', function ($provide) { | ||
// Mock apingDefaultSettings with what ever you want | ||
// Do the same for other services if needed | ||
$provide.value('apingDefaultSettings',{}); | ||
$provide.value('$templateRequest',templateRequestMock) | ||
$provide.value('apingDefaultSettings', { | ||
apingApiKeys: {} | ||
}); | ||
$provide.value('$templateRequest', templateRequestMock) | ||
})); | ||
|
||
beforeEach(inject(function(_$compile_, _$rootScope_, _$q_){ | ||
beforeEach(inject(function (_$compile_, _$rootScope_, _$q_) { | ||
$compile = _$compile_; | ||
$rootScope = _$rootScope_; | ||
$q = _$q_; | ||
})); | ||
|
||
|
||
it('should init scope.results with an empty array', function(){ | ||
it('should init scope.results with an empty array', function () { | ||
var html = '<aping></aping>'; | ||
|
||
var element = $compile(html)($rootScope); | ||
|
||
|
||
// TODO: Try to Debug the element and look "inside" | ||
expect(element.isolateScope().results).toEqual([]); | ||
}); | ||
|
||
|
||
it('should get an json file and merge it into results', function () { | ||
|
||
var jsonloaderRequest = "{'path':'https://github.com/JohnnyTheTank/apiNG/blob/master/package.json'}"; | ||
|
||
var html = '<aping aping-jsonloader="['+jsonloaderRequest+']"></aping>'; | ||
|
||
var element = $compile(html)($rootScope); | ||
|
||
waitFor(function () { | ||
expect(element.isolateScope().results.length === 1); | ||
}, "Results array length should be one", 5000); | ||
|
||
}); | ||
|
||
|
||
}); |