Socket
Socket
Sign inDemoInstall

ng-daia

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-daia - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

23

demo/app.js

@@ -15,3 +15,4 @@ var app = angular.module('myApp', ['ngDAIA', 'pascalprecht.translate']);

app.controller('myController', ['$translate', '$scope', function ($translate, $scope) {
app.controller('myController', ['$translate', '$scope', '$http',
function ($translate, $scope, $http) {
$scope.myAPI = "//daia.gbv.de/";

@@ -22,3 +23,21 @@ $scope.myID = "opac-de-ma9:ppn:685460711";

};
// TODO: move into service
function query() {
$http.jsonp( $scope.myAPI, {
params: { id: $scope.myID, format:'json', callback:'JSON_CALLBACK' } }
).success(function(response) {
$scope.daiaResponse = response;
});
}
function triggerQuery(newValue, oldValue) {
if (newValue != oldValue) {
query();
}
}
$scope.$watch("myID",triggerQuery);
$scope.$watch("myAPI",triggerQuery);
query();
}]);

2

ng-daia-templates.js

@@ -20,5 +20,5 @@ angular.module('ngDAIA').run(['$templateCache', function($templateCache) {

$templateCache.put('template/daia-simple.html',
"<span ng-if=\"status == 'openaccess'\" class=\"availability availability-available simple-openaccess\" translate=\"{{status}}\">{{status}}</span> <span ng-if=\"status == 'loan'\" class=\"availability availability-available simple-loan\" translate=\"{{status}}\">{{status}}</span> <span ng-if=\"status == 'presentation'\" class=\"availability availability-presentation simple-presentation\" translate=\"{{status}}\">{{status}}</span> <span ng-if=\"status != 'openaccess' && status != 'loan' && status != 'presentation' && status != 'expected'\" class=\"availability availability-unavailable\" translate=\"{{status}}\">{{status}}</span> <span ng-if=\"expected\" class=\"availability availability-unavailable\" translate=\"EXPECTED_BACK\">expected back:</span> <span ng-if=\"expected\" class=\"availability availability-unavailable\">{{expected}}</span>"
"<span ng-if=\"available\"><span ng-switch=\"service\"><span ng-switch-when=\"openaccess\"><span class=\"availability-available\">frei verfügbar</span> <a ng-if=\"href\" href=\"{{href}}\">aufrufen</a></span> <span ng-switch-when=\"loan\"><span class=\"availability-available\">ausleihbar</span> <a ng-if=\"href\" href=\"{{href}}\">bestellen</a></span> <span ng-switch-when=\"presentation\"><span class=\"availability-available\">vor Ort verfügbar</span> <a ng-if=\"href\" href=\"{{href}}\">bestellen</a></span> <span ng-switch-default=\"\"><span class=\"availability-available\">verfügbar</span> <a ng-if=\"href\" href=\"{{href}}\">bestellen</a></span></span> <span ng-if=\"delay\">(Wartezeit<span ng-if=\"delay != 'unknown'\">etwa {{delay}}</span>)</span> <span ng-if=\"limitation\">| <span class=\"daia-limitation\">{{limitation}}</span></span></span> <span ng-if=\"!available\"><span class=\"availability-unavailable\"><span ng-if=\"expected\">momentan</span> nicht verfügbar</span> <span ng-if=\"expected && expected != 'unknown'\">bis voraussichtlich {{expected}}</span> <span ng-if=\"href\"><a href=\"{{href}}\">vormerken</a></span> <span ng-if=\"queue\">({{queue}} Vormerkungen)</span> <span ng-if=\"limitation\">| <span class=\"daia-limitation\">{{limitation}}</span></span></span>"
);
}]);

@@ -29,3 +29,3 @@ /**

var ngDAIA = angular.module('ngDAIA', []);
ngDAIA.value('version', '0.1.1');
ngDAIA.value('version', '0.1.2');
'use strict';

@@ -41,10 +41,16 @@ /**

* filtered, for instance with {@link ng-daia.filter:daiaSimple daiaSimple}.
*
* The default template [template/daia-response.html](https://github.com/gbv/ng-daia/blob/master/src/templates/daia-response.html)
* makes use of the directives {@link ng-daia.directive:daiaItem daiaItem}
* and {@link ng-daia.directive:daiaAvailability daiaAvailability}. The
* template can be changed with the `template-url` parameter.
* template can be changed with the `template-url` parameter. If parameter
* `daia-filter` is set to `daiaSimple`, the default template
* The default template [template/daia-response.html](https://github.com/gbv/ng-daia/blob/master/src/templates/daia-response.html)
*
*
* ## Scope
*
* The DAIA response is injected into the template's scope as variable `daia`.
* Without `daia-filter`, the DAIA response is injected into the template's
* scope as variable `daia`. With `daia-filter` the filtered response is used
* as scope.
*

@@ -75,3 +81,7 @@ * ## Source code

templateUrl: function (elem, attrs) {
return attrs.templateUrl ? attrs.templateUrl : 'template/daia-response.html';
if (attrs.templateUrl) {
return attrs.templateUrl;
} else {
return attrs.daiaFilter == 'daiaSimple' ? 'template/daia-simple.html' : 'template/daia-response.html';
}
},

@@ -88,3 +98,7 @@ link: function link(scope, element, attr) {

if (scope.filter) {
scope.daia = $filter(scope.filter)(response);
var filtered = $filter(scope.filter)(response);
// FIXME: purge existing variables from scope
angular.forEach(filtered, function (value, key) {
scope[key] = value;
});
} else {

@@ -198,9 +212,4 @@ scope.daia = response;

* default template [template/daia-simple.html](https://github.com/gbv/ng-daia/blob/master/src/templates/daia-simple.html)
* can be changed with the `template-url` parameter. The template's scope
* gets the variables
* can be changed with the `template-url` parameter.
*
* * `daia`: DAIA response, document, or item as passed to the directive
* * `status`: simplified status (set to `none` by default)
* * `expected`, `delay`, `href`, `limitation`: optional additional information
*
* ## Scope

@@ -210,4 +219,4 @@ *

* variable `variable`. The DAIA simple response is provided with its fields
* `status`, `expected`, `delay`, `href`, and `limitation`.
* `service`, `available`, `expected`, `delay`, `href`, `limitation`, and `queue`.
*
* ## Source code

@@ -235,14 +244,12 @@ *

angular.forEach([
'status',
'service',
'available',
'expected',
'delay',
'href',
'limitation'
'limitation',
'queue'
], function (key) {
scope[key] = simple[key];
});
var s = scope.status;
if (s != 'openaccess' && s != 'loan' && s != 'presentation' && s != 'expected') {
scope.status = 'none';
}
});

@@ -288,3 +295,8 @@ }

return function (input, option) {
// extract list of items from input
var services = [
'openaccess',
'loan',
'presentation'
];
// collect list of items
var items = [];

@@ -306,61 +318,72 @@ if (angular.isObject(input)) {

}
var response = {};
angular.forEach(items, function (item) {
if (angular.isArray(item.available)) {
for (var j = 0; j < item.available.length; j++) {
if (item.available[j].service == 'openaccess') {
response.status = 'openaccess';
response.href = item.available[j].href;
return;
}
}
}
});
if (response.status)
return response;
angular.forEach(items, function (item) {
if (angular.isArray(item.available)) {
for (var j = 0; j < item.available.length; j++) {
if (item.available[j].service == 'loan') {
response.status = 'loan';
return response;
}
}
}
});
if (response.status)
return response;
angular.forEach(items, function (item) {
if (angular.isArray(item.available)) {
for (var j = 0; j < item.available.length; j++) {
if (item.available[j].service == 'presentation') {
response.status = 'presentation';
return response;
}
}
}
});
if (response.status)
return response;
angular.forEach(items, function (item) {
angular.forEach(item.unavailable, function (unavailable) {
if (unavailable.service == 'loan' && unavailable.expected) {
var exp = unavailable.expected;
if (response.expected) {
if (exp == 'unknown') {
// default DAIA simple response
var response = {
service: 'none',
available: false
};
// find any item with available openaccess
// otherwise find any item with available loan
// otherwise find any item with available presentation
if (services.some(function (service) {
return items.some(function (item) {
var a = angular.isArray(item.available) ? item.available : [];
return a.some(function (available) {
if (available.service != service) {
return;
} else if (response.expected != 'unknown') {
if (exp > response.expected) {
return;
}
response.available = true;
[
'service',
'href',
'limitation',
'delay'
].forEach(function (key) {
var value = available[key];
if (value || value == 0) {
response[key] = value;
}
});
if (response.limitation) {
response.limitation = response.limitation[0].content;
}
return true;
});
});
})) {
return response;
}
// otherwise find item that is next expected
var expect;
items.forEach(function (item) {
var a = angular.isArray(item.unavailable) ? item.unavailable : [];
a.forEach(function (unavail) {
// any expected openaccess, loan, or presentation
var uexp = unavail.expected;
if (services.indexOf(unavail.service) != -1 && uexp) {
if (!expect || expect == 'unknown' || uexp != 'unknown' && uexp < expect) {
[
'service',
'href',
'limitation',
'expected',
'queue'
].forEach(function (key) {
var value = unavail[key];
if (value || value == 0) {
response[key] = value;
}
});
if (response.limitation) {
response.limitation = response.limitation[0].content;
}
}
response.status = 'expected';
response.expected = exp;
}
});
});
if (!response.status) {
response.status = 'none';
if (expect) {
return response;
}
// otherwise find any additional href or limitation
services.some(function (service) {
});
return response;

@@ -376,4 +399,4 @@ };

$templateCache.put('template/daia-response.html', '<div class="daia-result"><div ng-if="daia.institution.content"><span class="daia-label" translate="INSTITUTION">institution:</span> <a ng-if="daia.institution.href" href="{{daia.institution.href}}">{{daia.institution.content}}</a></div><div ng-if="daia.document[0].href"><span class="daia-label" translate="DOCUMENT">document:</span> <a translate="CATALOG_ENTRY" href="{{daia.document[0].href}}">Catalog entry</a></div><div><span ng-if="!daia.document" translate="NO_RECORDS">no records found</span></div><div ng-if="daia.document" daia-documents="daia.document"><div class="daia-document" ng-repeat="i in daia.document[0].item"><div daia-item="i"></div></div></div></div>');
$templateCache.put('template/daia-simple.html', '<span ng-if="status == \'openaccess\'" class="availability availability-available simple-openaccess" translate="{{status}}">{{status}}</span> <span ng-if="status == \'loan\'" class="availability availability-available simple-loan" translate="{{status}}">{{status}}</span> <span ng-if="status == \'presentation\'" class="availability availability-presentation simple-presentation" translate="{{status}}">{{status}}</span> <span ng-if="status != \'openaccess\' && status != \'loan\' && status != \'presentation\' && status != \'expected\'" class="availability availability-unavailable" translate="{{status}}">{{status}}</span> <span ng-if="expected" class="availability availability-unavailable" translate="EXPECTED_BACK">expected back:</span> <span ng-if="expected" class="availability availability-unavailable">{{expected}}</span>');
$templateCache.put('template/daia-simple.html', '<span ng-if="available"><span ng-switch="service"><span ng-switch-when="openaccess"><span class="availability-available">frei verf\xfcgbar</span> <a ng-if="href" href="{{href}}">aufrufen</a></span> <span ng-switch-when="loan"><span class="availability-available">ausleihbar</span> <a ng-if="href" href="{{href}}">bestellen</a></span> <span ng-switch-when="presentation"><span class="availability-available">vor Ort verf\xfcgbar</span> <a ng-if="href" href="{{href}}">bestellen</a></span> <span ng-switch-default=""><span class="availability-available">verf\xfcgbar</span> <a ng-if="href" href="{{href}}">bestellen</a></span></span> <span ng-if="delay">(Wartezeit<span ng-if="delay != \'unknown\'">etwa {{delay}}</span>)</span> <span ng-if="limitation">| <span class="daia-limitation">{{limitation}}</span></span></span> <span ng-if="!available"><span class="availability-unavailable"><span ng-if="expected">momentan</span> nicht verf\xfcgbar</span> <span ng-if="expected && expected != \'unknown\'">bis voraussichtlich {{expected}}</span> <span ng-if="href"><a href="{{href}}">vormerken</a></span> <span ng-if="queue">({{queue}} Vormerkungen)</span> <span ng-if="limitation">| <span class="daia-limitation">{{limitation}}</span></span></span>');
}
]);

@@ -1,1 +0,1 @@

var ngDAIA=angular.module("ngDAIA",[]);ngDAIA.value("version","0.1.1"),ngDAIA.directive("daiaApi",["$http","$filter",function($http,$filter){return{restrict:"A",scope:{api:"@daiaApi",id:"@daiaId",filter:"@daiaFilter"},templateUrl:function(elem,attrs){return attrs.templateUrl?attrs.templateUrl:"template/daia-response.html"},link:function(scope){scope.daiaRequest=function(){$http.jsonp(scope.api,{params:{id:scope.id,format:"json",callback:"JSON_CALLBACK"}}).success(function(response){scope.daia=scope.filter?$filter(scope.filter)(response):response})},scope.$watch("api",function(){scope.daiaRequest()}),scope.$watch("id",function(){scope.daiaRequest()})}}}]),ngDAIA.directive("daiaAvailability",function(){return{restrict:"A",scope:{item:"=daiaAvailability"},templateUrl:function(elem,attrs){return attrs.templateUrl?attrs.templateUrl:"template/daia-availability.html"},link:function(scope){scope.item.available&&scope.item.available.length&&(scope.available=scope.item.available),scope.item.unavailable&&scope.item.unavailable.length&&(scope.unavailable=scope.item.unavailable)}}}),ngDAIA.directive("daiaItem",function(){return{restrict:"A",scope:{item:"=daiaItem"},templateUrl:function(elem,attrs){return attrs.templateUrl?attrs.templateUrl:"template/daia-item.html"}}}),ngDAIA.directive("daiaSimple",["$filter",function($filter){return{restrict:"A",scope:{daia:"=daiaSimple"},templateUrl:function(elem,attrs){return attrs.templateUrl?attrs.templateUrl:"template/daia-simple.html"},link:function(scope){scope.$watch("daia",function(){var simple=$filter("daiaSimple")(scope.daia);angular.forEach(["status","expected","delay","href","limitation"],function(key){scope[key]=simple[key]});var s=scope.status;"openaccess"!=s&&"loan"!=s&&"presentation"!=s&&"expected"!=s&&(scope.status="none")})}}}]),ngDAIA.filter("daiaSimple",function(){return function(input){var items=[];angular.isObject(input)&&(angular.isArray(input.document)?angular.forEach(input.document,function(document){angular.forEach(document.item,function(item){items.push(item)})}):angular.isArray(input.item)?angular.forEach(input.item,function(item){items.push(item)}):items.push(input));var response={};return angular.forEach(items,function(item){if(angular.isArray(item.available))for(var j=0;j<item.available.length;j++)if("openaccess"==item.available[j].service)return response.status="openaccess",void(response.href=item.available[j].href)}),response.status?response:(angular.forEach(items,function(item){if(angular.isArray(item.available))for(var j=0;j<item.available.length;j++)if("loan"==item.available[j].service)return response.status="loan",response}),response.status?response:(angular.forEach(items,function(item){if(angular.isArray(item.available))for(var j=0;j<item.available.length;j++)if("presentation"==item.available[j].service)return response.status="presentation",response}),response.status?response:(angular.forEach(items,function(item){angular.forEach(item.unavailable,function(unavailable){if("loan"==unavailable.service&&unavailable.expected){var exp=unavailable.expected;if(response.expected){if("unknown"==exp)return;if("unknown"!=response.expected&&exp>response.expected)return}response.status="expected",response.expected=exp}})}),response.status||(response.status="none"),response)))}}),angular.module("ngDAIA").run(["$templateCache",function($templateCache){"use strict";$templateCache.put("template/daia-availability.html",'<ul class="availability" ng-if="available || unavailable"><li ng-if="available" ng-repeat="a in available"><span class="service-label" translate="{{a.service}}">{{a.service}}</span> <span class="availability availability-available" translate="available">available</span> <span class="availability availability-limitation" ng-if="a.limitation">({{a.limitation[0].content}})</span></li><li ng-if="unavailable" ng-repeat="u in unavailable"><span class="service-label" ng-if="u.expected" translate="{{u.service}}">{{u.service}}</span> <span ng-if="u.expected" class="availability availability-expected" translate="expected">expected</span> <span class="service-label" ng-if="!u.expected" translate="{{u.service}}">{{u.service}}</span> <span ng-if="!u.expected" class="availability availability-unavailable" translate="unavailable">unavailable</span></li><div class="returning"><li ng-if="unavailable[0].href && unavailable[0].expected"><div ng-if="unavailable[0].expected" class="returning returning-expected"><span translate="EXPECTED_BACK">expected back:</span> {{unavailable[0].expected}}</div><a href="{{unavailable[0].href}}" translate="RESERVATION">place reservation</a></li></div></ul><div class="access" ng-if="((available[1].service || available[0].service) == \'openaccess\' || unavailable[0].service == \'openaccess\')"><span translate="ACCESS">access via:</span> <a ng-if="available[1].service == \'openaccess\'" href="{{available[1].href}}">{{available[1].href}}</a> <a ng-if="unavailable[0].service == \'openaccess\'" href="{{unavailable[0].href}}">{{available[0].href}}</a></div>'),$templateCache.put("template/daia-item.html",'<div ng-if="item.department"><span class="daia-label" translate="DEPARTMENT">Department:</span> <a ng-if="item.department.href" href="{{item.department.href}}">{{item.department.content}}</a> <span ng-if="!item.department.href">{{item.department.content}}</span></div><div ng-if="item.label"><span class="daia-label" translate="SIGNATURE">Shelf mark:</span> {{item.label}}</div><span ng-if="!item.available && !item.unavailable" class="daia-label" translate="AVAILABILITY">Availability:</span> <span ng-if="!item.available && !item.unavailable" translate="unknown">unknown</span><div daia-availability="item"></div>'),$templateCache.put("template/daia-response.html",'<div class="daia-result"><div ng-if="daia.institution.content"><span class="daia-label" translate="INSTITUTION">institution:</span> <a ng-if="daia.institution.href" href="{{daia.institution.href}}">{{daia.institution.content}}</a></div><div ng-if="daia.document[0].href"><span class="daia-label" translate="DOCUMENT">document:</span> <a translate="CATALOG_ENTRY" href="{{daia.document[0].href}}">Catalog entry</a></div><div><span ng-if="!daia.document" translate="NO_RECORDS">no records found</span></div><div ng-if="daia.document" daia-documents="daia.document"><div class="daia-document" ng-repeat="i in daia.document[0].item"><div daia-item="i"></div></div></div></div>'),$templateCache.put("template/daia-simple.html",'<span ng-if="status == \'openaccess\'" class="availability availability-available simple-openaccess" translate="{{status}}">{{status}}</span> <span ng-if="status == \'loan\'" class="availability availability-available simple-loan" translate="{{status}}">{{status}}</span> <span ng-if="status == \'presentation\'" class="availability availability-presentation simple-presentation" translate="{{status}}">{{status}}</span> <span ng-if="status != \'openaccess\' && status != \'loan\' && status != \'presentation\' && status != \'expected\'" class="availability availability-unavailable" translate="{{status}}">{{status}}</span> <span ng-if="expected" class="availability availability-unavailable" translate="EXPECTED_BACK">expected back:</span> <span ng-if="expected" class="availability availability-unavailable">{{expected}}</span>')}]);
var ngDAIA=angular.module("ngDAIA",[]);ngDAIA.value("version","0.1.2"),ngDAIA.directive("daiaApi",["$http","$filter",function($http,$filter){return{restrict:"A",scope:{api:"@daiaApi",id:"@daiaId",filter:"@daiaFilter"},templateUrl:function(elem,attrs){return attrs.templateUrl?attrs.templateUrl:"daiaSimple"==attrs.daiaFilter?"template/daia-simple.html":"template/daia-response.html"},link:function(scope){scope.daiaRequest=function(){$http.jsonp(scope.api,{params:{id:scope.id,format:"json",callback:"JSON_CALLBACK"}}).success(function(response){if(scope.filter){var filtered=$filter(scope.filter)(response);angular.forEach(filtered,function(value,key){scope[key]=value})}else scope.daia=response})},scope.$watch("api",function(){scope.daiaRequest()}),scope.$watch("id",function(){scope.daiaRequest()})}}}]),ngDAIA.directive("daiaAvailability",function(){return{restrict:"A",scope:{item:"=daiaAvailability"},templateUrl:function(elem,attrs){return attrs.templateUrl?attrs.templateUrl:"template/daia-availability.html"},link:function(scope){scope.item.available&&scope.item.available.length&&(scope.available=scope.item.available),scope.item.unavailable&&scope.item.unavailable.length&&(scope.unavailable=scope.item.unavailable)}}}),ngDAIA.directive("daiaItem",function(){return{restrict:"A",scope:{item:"=daiaItem"},templateUrl:function(elem,attrs){return attrs.templateUrl?attrs.templateUrl:"template/daia-item.html"}}}),ngDAIA.directive("daiaSimple",["$filter",function($filter){return{restrict:"A",scope:{daia:"=daiaSimple"},templateUrl:function(elem,attrs){return attrs.templateUrl?attrs.templateUrl:"template/daia-simple.html"},link:function(scope){scope.$watch("daia",function(){var simple=$filter("daiaSimple")(scope.daia);angular.forEach(["service","available","expected","delay","href","limitation","queue"],function(key){scope[key]=simple[key]})})}}}]),ngDAIA.filter("daiaSimple",function(){return function(input){var services=["openaccess","loan","presentation"],items=[];angular.isObject(input)&&(angular.isArray(input.document)?angular.forEach(input.document,function(document){angular.forEach(document.item,function(item){items.push(item)})}):angular.isArray(input.item)?angular.forEach(input.item,function(item){items.push(item)}):items.push(input));var response={service:"none",available:!1};if(services.some(function(service){return items.some(function(item){var a=angular.isArray(item.available)?item.available:[];return a.some(function(available){return available.service==service?(response.available=!0,["service","href","limitation","delay"].forEach(function(key){var value=available[key];(value||0==value)&&(response[key]=value)}),response.limitation&&(response.limitation=response.limitation[0].content),!0):void 0})})}))return response;var expect;return items.forEach(function(item){var a=angular.isArray(item.unavailable)?item.unavailable:[];a.forEach(function(unavail){var uexp=unavail.expected;-1!=services.indexOf(unavail.service)&&uexp&&(!expect||"unknown"==expect||"unknown"!=uexp&&expect>uexp)&&(["service","href","limitation","expected","queue"].forEach(function(key){var value=unavail[key];(value||0==value)&&(response[key]=value)}),response.limitation&&(response.limitation=response.limitation[0].content))})}),expect?response:(services.some(function(){}),response)}}),angular.module("ngDAIA").run(["$templateCache",function($templateCache){"use strict";$templateCache.put("template/daia-availability.html",'<ul class="availability" ng-if="available || unavailable"><li ng-if="available" ng-repeat="a in available"><span class="service-label" translate="{{a.service}}">{{a.service}}</span> <span class="availability availability-available" translate="available">available</span> <span class="availability availability-limitation" ng-if="a.limitation">({{a.limitation[0].content}})</span></li><li ng-if="unavailable" ng-repeat="u in unavailable"><span class="service-label" ng-if="u.expected" translate="{{u.service}}">{{u.service}}</span> <span ng-if="u.expected" class="availability availability-expected" translate="expected">expected</span> <span class="service-label" ng-if="!u.expected" translate="{{u.service}}">{{u.service}}</span> <span ng-if="!u.expected" class="availability availability-unavailable" translate="unavailable">unavailable</span></li><div class="returning"><li ng-if="unavailable[0].href && unavailable[0].expected"><div ng-if="unavailable[0].expected" class="returning returning-expected"><span translate="EXPECTED_BACK">expected back:</span> {{unavailable[0].expected}}</div><a href="{{unavailable[0].href}}" translate="RESERVATION">place reservation</a></li></div></ul><div class="access" ng-if="((available[1].service || available[0].service) == \'openaccess\' || unavailable[0].service == \'openaccess\')"><span translate="ACCESS">access via:</span> <a ng-if="available[1].service == \'openaccess\'" href="{{available[1].href}}">{{available[1].href}}</a> <a ng-if="unavailable[0].service == \'openaccess\'" href="{{unavailable[0].href}}">{{available[0].href}}</a></div>'),$templateCache.put("template/daia-item.html",'<div ng-if="item.department"><span class="daia-label" translate="DEPARTMENT">Department:</span> <a ng-if="item.department.href" href="{{item.department.href}}">{{item.department.content}}</a> <span ng-if="!item.department.href">{{item.department.content}}</span></div><div ng-if="item.label"><span class="daia-label" translate="SIGNATURE">Shelf mark:</span> {{item.label}}</div><span ng-if="!item.available && !item.unavailable" class="daia-label" translate="AVAILABILITY">Availability:</span> <span ng-if="!item.available && !item.unavailable" translate="unknown">unknown</span><div daia-availability="item"></div>'),$templateCache.put("template/daia-response.html",'<div class="daia-result"><div ng-if="daia.institution.content"><span class="daia-label" translate="INSTITUTION">institution:</span> <a ng-if="daia.institution.href" href="{{daia.institution.href}}">{{daia.institution.content}}</a></div><div ng-if="daia.document[0].href"><span class="daia-label" translate="DOCUMENT">document:</span> <a translate="CATALOG_ENTRY" href="{{daia.document[0].href}}">Catalog entry</a></div><div><span ng-if="!daia.document" translate="NO_RECORDS">no records found</span></div><div ng-if="daia.document" daia-documents="daia.document"><div class="daia-document" ng-repeat="i in daia.document[0].item"><div daia-item="i"></div></div></div></div>'),$templateCache.put("template/daia-simple.html",'<span ng-if="available"><span ng-switch="service"><span ng-switch-when="openaccess"><span class="availability-available">frei verfügbar</span> <a ng-if="href" href="{{href}}">aufrufen</a></span> <span ng-switch-when="loan"><span class="availability-available">ausleihbar</span> <a ng-if="href" href="{{href}}">bestellen</a></span> <span ng-switch-when="presentation"><span class="availability-available">vor Ort verfügbar</span> <a ng-if="href" href="{{href}}">bestellen</a></span> <span ng-switch-default=""><span class="availability-available">verfügbar</span> <a ng-if="href" href="{{href}}">bestellen</a></span></span> <span ng-if="delay">(Wartezeit<span ng-if="delay != \'unknown\'">etwa {{delay}}</span>)</span> <span ng-if="limitation">| <span class="daia-limitation">{{limitation}}</span></span></span> <span ng-if="!available"><span class="availability-unavailable"><span ng-if="expected">momentan</span> nicht verfügbar</span> <span ng-if="expected && expected != \'unknown\'">bis voraussichtlich {{expected}}</span> <span ng-if="href"><a href="{{href}}">vormerken</a></span> <span ng-if="queue">({{queue}} Vormerkungen)</span> <span ng-if="limitation">| <span class="daia-limitation">{{limitation}}</span></span></span>')}]);
{
"name": "ng-daia",
"version": "0.1.1",
"version": "0.1.2",
"author": "Jakob Voß <voss@gbv.de>",
"contributor": ["Moritz Horn <moritz.horn@gmail.com>"],
"description": "AngularJS module to facilitate access to DAIA services",
"keywords": ["angular","angularjs","daia","availability"],
"license": "AGPL",
"homepage": "http://gbv.github.io/ng-daia/",
"repository": {

@@ -12,2 +14,3 @@ "type": "git",

},
"main": "ng-daia.min.js",
"devDependencies": {

@@ -27,3 +30,6 @@ "grunt": "~0.4.2",

"karma-jasmine": "~0.1.5"
},
"scripts": {
"test": "grunt test"
}
}

@@ -5,12 +5,20 @@ # ng-daia [![Build Status](https://travis-ci.org/gbv/ng-daia.png?branch=master)](https://travis-ci.org/gbv/ng-daia)

## Usage and documentation
See <http://gbv.github.io/ng-daia/>.
See <http://gbv.github.io/ng-daia/> for documentation and usage examples.
## Requirements
## Installation
AngularJS >= 1.2
Install **ng-daia** as a dependency in your Node.js project:
npm install ng-daia --safe
Then *require* it in your client-side JavaScript files:
var ng_daia = require('ng-daia');
## Development
*Stop reading here unless you want to modify the source code of ng-daia!*
Requires AngularJS >= 1.2.
Requires OS with POSIX symlinks

@@ -17,0 +25,0 @@

@@ -11,10 +11,16 @@ 'use strict';

* filtered, for instance with {@link ng-daia.filter:daiaSimple daiaSimple}.
*
* The default template [template/daia-response.html](https://github.com/gbv/ng-daia/blob/master/src/templates/daia-response.html)
* makes use of the directives {@link ng-daia.directive:daiaItem daiaItem}
* and {@link ng-daia.directive:daiaAvailability daiaAvailability}. The
* template can be changed with the `template-url` parameter.
* template can be changed with the `template-url` parameter. If parameter
* `daia-filter` is set to `daiaSimple`, the default template
* The default template [template/daia-response.html](https://github.com/gbv/ng-daia/blob/master/src/templates/daia-response.html)
*
*
* ## Scope
*
* The DAIA response is injected into the template's scope as variable `daia`.
* Without `daia-filter`, the DAIA response is injected into the template's
* scope as variable `daia`. With `daia-filter` the filtered response is used
* as scope.
*

@@ -42,4 +48,9 @@ * ## Source code

templateUrl: function(elem, attrs) {
return attrs.templateUrl ?
attrs.templateUrl : 'template/daia-response.html';
if (attrs.templateUrl) {
return attrs.templateUrl;
} else {
return attrs.daiaFilter == 'daiaSimple'
? 'template/daia-simple.html'
: 'template/daia-response.html';
}
},

@@ -49,6 +60,10 @@ link: function link(scope, element, attr) {

$http.jsonp( scope.api, {
params: { id: scope.id, format:'json',callback:'JSON_CALLBACK' } }
params: { id: scope.id, format:'json', callback:'JSON_CALLBACK' } }
).success(function(response) {
if (scope.filter) {
scope.daia = $filter(scope.filter)(response);
var filtered = $filter(scope.filter)(response);
// FIXME: purge existing variables from scope
angular.forEach(filtered,
function(value, key) { scope[key] = value }
);
} else {

@@ -55,0 +70,0 @@ scope.daia = response;

@@ -11,9 +11,4 @@ 'use strict';

* default template [template/daia-simple.html](https://github.com/gbv/ng-daia/blob/master/src/templates/daia-simple.html)
* can be changed with the `template-url` parameter. The template's scope
* gets the variables
* can be changed with the `template-url` parameter.
*
* * `daia`: DAIA response, document, or item as passed to the directive
* * `status`: simplified status (set to `none` by default)
* * `expected`, `delay`, `href`, `limitation`: optional additional information
*
* ## Scope

@@ -23,4 +18,4 @@ *

* variable `variable`. The DAIA simple response is provided with its fields
* `status`, `expected`, `delay`, `href`, and `limitation`.
* `service`, `available`, `expected`, `delay`, `href`, `limitation`, and `queue`.
*
* ## Source code

@@ -48,12 +43,6 @@ *

var simple = $filter('daiaSimple')(scope.daia);
angular.forEach(
['status','expected','delay','href','limitation'],
['service','available','expected','delay','href','limitation','queue'],
function(key) { scope[key] = simple[key]; }
);
var s = scope.status;
if (s!='openaccess' && s!='loan' && s!='presentation' && s!= 'expected') {
scope.status = 'none';
}
});

@@ -60,0 +49,0 @@ }

@@ -34,86 +34,87 @@ 'use strict';

*/
ngDAIA.filter('daiaSimple',function(){
ngDAIA.filter('daiaSimple', function() {
return function(input, option) {
var services = ['openaccess','loan','presentation'];
// extract list of items from input
var items = [];
if (angular.isObject(input)) {
if (angular.isArray(input.document)) {
angular.forEach(input.document,function(document) {
angular.forEach(document.item,function(item) {
items.push(item);
});
});
} else if (angular.isArray(input.item)) {
angular.forEach(input.item,function(item) {
items.push(item);
});
// collect list of items
var items = [];
if (angular.isObject(input)) {
if (angular.isArray(input.document)) {
angular.forEach(input.document,function(document) {
angular.forEach(document.item,function(item) {
items.push(item);
});
});
} else if (angular.isArray(input.item)) {
angular.forEach(input.item,function(item) {
items.push(item);
});
} else {
items.push(input);
}
}
var response = { };
angular.forEach(items,function(item) {
if (angular.isArray(item.available)) {
for(var j=0; j<item.available.length; j++){
if(item.available[j].service == 'openaccess'){
response.status = "openaccess";
response.href = item.available[j].href;
return;
}
}
}
});
if (response.status) return response;
angular.forEach(items,function(item) {
if (angular.isArray(item.available)) {
for(var j=0; j<item.available.length; j++){
if(item.available[j].service == 'loan'){
response.status = "loan";
return response;
}
}
}
});
if (response.status) return response;
angular.forEach(items,function(item) {
if (angular.isArray(item.available)) {
for(var j=0; j<item.available.length; j++){
if(item.available[j].service == 'presentation'){
response.status = "presentation";
return response;
}
}
}
});
if (response.status) return response;
angular.forEach(items,function(item) {
angular.forEach(item.unavailable,function(unavailable) {
if(unavailable.service == 'loan' && unavailable.expected) {
var exp = unavailable.expected;
if (response.expected) {
if (exp == "unknown") {
return;
} else if(response.expected != "unknown") {
if (exp > response.expected) {
return;
}
}
}
response.status = "expected";
response.expected = exp;
}
});
});
if (!response.status) {
response.status = "none";
}
}
return response;
}
// default DAIA simple response
var response = {
service: "none",
available: false
};
// find any item with available openaccess
// otherwise find any item with available loan
// otherwise find any item with available presentation
if ( services.some(function (service) {
return items.some( function (item) {
var a = angular.isArray(item.available) ? item.available : [];
return a.some( function (available) {
if (available.service != service) {
return;
}
response.available = true;
['service','href','limitation','delay'].forEach(function (key) {
var value = available[key];
if ( value || value == 0 ) { response[key] = value; }
});
if (response.limitation) {
response.limitation = response.limitation[0].content;
}
return true;
});
});
})) {
return response;
}
// otherwise find item that is next expected
var expect;
items.forEach( function (item) {
var a = angular.isArray(item.unavailable) ? item.unavailable : [];
a.forEach( function (unavail) {
// any expected openaccess, loan, or presentation
var uexp = unavail.expected;
if (services.indexOf(unavail.service) != -1 && uexp) {
if (!expect || expect == "unknown" ||
(uexp != "unknown" && uexp < expect)) {
['service','href','limitation','expected','queue'].forEach(function (key) {
var value = unavail[key];
if ( value || value == 0 ) { response[key] = value; }
});
if (response.limitation) {
response.limitation = response.limitation[0].content;
}
}
}
});
});
if (expect) {
return response;
}
// otherwise find any additional href or limitation
services.some(function (service) {
// TODO!!!
});
return response;
}
});

@@ -29,2 +29,2 @@ /**

var ngDAIA = angular.module('ngDAIA',[]);
ngDAIA.value('version', '0.1.1');
ngDAIA.value('version', '0.1.2');

@@ -13,8 +13,10 @@ describe('daiaSimple',function() {

it('Should return status none at undefined/null/number/string', function() {
expect(filter(undefined)).toEqual({ status: "none" });
expect(filter(null)).toEqual({ status: "none" });
expect(filter(0)).toEqual({ status: "none" });
expect(filter(42)).toEqual({ status: "none" });
expect(filter("")).toEqual({ status: "none" });
expect(filter("available")).toEqual({ status: "none" });
var simple = { service: "none", available: false };
expect(filter(undefined)).toEqual(simple);
expect(filter(null)).toEqual(simple);
expect(filter(0)).toEqual(simple);
expect(filter(42)).toEqual(simple);
expect(filter("")).toEqual(simple);
expect(filter("available")).toEqual(simple);
});

@@ -25,5 +27,6 @@

expect(filter( loan )).toEqual({ status: "loan" });
expect(filter({ item: [ loan ] })).toEqual({ status: "loan" });
expect(filter({ document: [{ item: [ loan ] }]})).toEqual({ status: "loan" });
var simple = { service: "loan", available: true };
expect(filter( loan )).toEqual(simple);
expect(filter({ item: [ loan ] })).toEqual(simple);
expect(filter({ document: [{ item: [ loan ] }]})).toEqual(simple);
});

@@ -30,0 +33,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc