invenio-search-js
Advanced tools
Comparing version 1.2.2 to 1.3.0
@@ -23,2 +23,2 @@ /* | ||
*/ | ||
function invenioSearchConfiguration(e){e.html5Mode({enabled:!0,requireBase:!1,rewriteLinks:!1})}function invenioSearchCtrl(e,n,r){function i(){return n.get()}function a(){function n(){v.invenioSearchLoading=!1,e.$broadcast("invenio.search.finished")}function i(n){e.$broadcast("invenio.search.success",n)}function a(n){e.$broadcast("invenio.search.error",n)}e.$broadcast("invenio.search.requested"),v.invenioSearchLoading=!0,v.invenioSearchError={},v.invenioSearchErrorsResults={},r.search(v.invenioSearchCurrentArgs,v.invenioSearchHiddenParams).then(i,a).finally(n)}function t(e){for(var n=(e.split("?")[1]||"").split("&"),r={},i=0;i<n.length;i+=1){var a=(n[i]||"").split("="),t=decodeURIComponent(a[0]||"");t&&(r[t]=decodeURIComponent(a[1]||""))}return r}function o(e,n){v.invenioSearchErrorResults=n.data,v.invenioSearchError=e}function c(e,n){if(v.invenioSearchResults=n.data,v.invenioSearchErrorResults={},n.data.links){var r=t(n.data.links.self);r.page&&(r.page=parseInt(r.page)),r.size&&(r.size=parseInt(r.size)),delete r.q,angular.equals(v.invenioSearchCurrentArgs,r)||(v.invenioSearchSortArgs=r)}}function s(r,i){v.invenioSearchCurrentArgs=angular.merge({},v.invenioSearchCurrentArgs,i),v.invenioSearchArgs=angular.merge({},v.invenioSearchCurrentArgs.params),v.disableUrlHandler||(n.set(v.invenioSearchArgs),n.replace()),v.userQuery=v.invenioSearchArgs.q,v.invenioSearchInitialized=!0,v.invenioDoSearch(),e.$broadcast("invenio.search.initialiazed")}function l(e,r,i){void 0!==i&&!0===i?v.invenioSearchCurrentArgs.params=angular.copy(r):(v.invenioSearchCurrentArgs.params.page===r.page&&(r.page=1),angular.forEach(r,function(e,n){v.invenioSearchCurrentArgs.params[n]=e})),v.invenioSearchArgs=angular.copy(v.invenioSearchCurrentArgs.params),v.disableUrlHandler||n.set(v.invenioSearchCurrentArgs.params),v.userQuery=v.invenioSearchArgs.q,v.invenioDoSearch()}function h(r,i,a){if(!v.disableUrlHandler){var t=n.get();angular.equals(t,v.invenioSearchCurrentArgs.params)||e.$broadcast("invenio.search.request",t,!0)}}function u(n,r){var i=angular.copy(v.invenioSearchCurrentArgs.params);angular.forEach(r,function(e,n){i[n]=angular.copy(r[n])}),angular.equals(v.invenioSearchCurrentArgs.params,i)||e.$broadcast("invenio.search.request",i)}function d(n,r){angular.equals(n,v.invenioSearchCurrentArgs.params)||e.$broadcast("invenio.search.request",n)}var v=this;v.invenioSearchResults={},v.invenioSearchErrorResults={},v.invenioSearchLoading=!0,v.invenioSearchError={},v.invenioSearchInitialized=!1,v.invenioSearchArgs={},v.invenioSearchSortArgs={},v.invenioSearchCurrentArgs={method:"GET",params:{page:1,size:20}},v.invenioSearchGetUrlArgs=i,v.invenioDoSearch=a,v.parseURLQueryString=t,e.$on("invenio.search.initialization",s),e.$on("invenio.search.request",l),e.$on("invenio.search.success",c),e.$on("invenio.search.error",o),e.$on("invenio.search.params.change",u),e.$on("$locationChangeStart",h),e.$watch("vm.invenioSearchArgs",d,!0)}function invenioSearch(){function e(e,n,r,i){var a={url:r.searchEndpoint,method:r.searchMethod||"GET",headers:JSON.parse(r.searchHeaders||"{}")},t={params:JSON.parse(r.searchExtraParams||"{}")},o={params:i.invenioSearchGetUrlArgs()};i.disableUrlHandler=!!r.disableUrlHandler,i.invenioSearchHiddenParams=JSON.parse(r.searchHiddenParams||"{}");var c=angular.merge({},a,t,o);e.$broadcast("invenio.search.initialization",c)}return{restrict:"AE",scope:!1,controller:"invenioSearchCtrl",controllerAs:"vm",link:e}}function invenioSearchBar(){function e(e,n,r,i){function a(){i.invenioSearchArgs.q=i.userQuery}e.placeholder=r.placeholder,e.updateQuery=a}function n(e,n){return n.template}return{restrict:"AE",require:"^invenioSearch",scope:!1,templateUrl:n,link:e}}function invenioSearchCount(){function e(e,n){return n.template}return{restrict:"AE",scope:!1,require:"^invenioSearch",templateUrl:e}}function invenioSearchError(){function e(e,n,r,i){e.errorMessage=r.message}function n(e,n){return n.template}return{restrict:"AE",scope:!1,require:"^invenioSearch",templateUrl:n,link:e}}function invenioSearchFacets(){function e(e,n,r,i){function a(n,r){e.handler[n]=void 0===e.handler[n]?[]:e.handler[n],"string"==typeof e.handler[n]&&(e.handler[n]=[e.handler[n]]);var i=e.handler[n].indexOf(r);-1===i?e.handler[n].push(r):"string"==typeof e.handler[n]?e.handler[n]=[]:e.handler[n].splice(i,1);var a={};a[n]=angular.copy(e.handler[n]),e.$broadcast("invenio.search.params.change",a)}function t(n){return"string"==typeof e.handler[n]?[e.handler[n]]:e.handler[n]}function o(n){if(n){var r=e.aggOrder||Object.keys(n);e.orderedAggs=r.map(function(e){return{key:e,value:n[e]}})}}e.handler=angular.copy(i.invenioSearchCurrentArgs.params),r.order&&(e.aggOrder=r.order.split(",")),o(i.invenioSearchResults.aggregations),e.$on("invenio.search.finished",function(n){e.handler=angular.copy(i.invenioSearchCurrentArgs.params)}),e.$watch("vm.invenioSearchResults.aggregations",o),e.handleClick=a,e.getValues=t}function n(e,n){return n.template}return{restrict:"AE",scope:!1,require:"^invenioSearch",templateUrl:n,link:e}}function invenioSearchLoading(){function e(e,n,r,i){e.loadingMessage=r.message}function n(e,n){return n.template}return{restrict:"AE",require:"^invenioSearch",templateUrl:n,link:e}}function invenioSearchPagination(){function e(e,n,r,i){function a(n,r){for(var i=(c(),n);i<=r;i++){var a=function(e){return{value:e,title:"Go to page "+e}}(i);e.paginatePages.push(a)}}function t(){e.paginatePages=[];var n,r,i=e.adjacentSize,t=o(),s=c(),l=2*i;t<=l+2?(n=1,a(n,t)):s-i<=2?(n=1,r=1+l,a(n,r)):s<t-(i+2)?(n=s-i,r=s+i,a(n,r)):(n=t-l,r=t,a(n,r))}function o(){var e;try{e=i.invenioSearchResults.hits.total}catch(n){e=0}return Math.ceil(e/i.invenioSearchArgs.size)}function c(){return parseInt(i.invenioSearchArgs.page)||1}function s(){var e=c();return e<o()&&(e+=1),e}function l(){var e=c();o();return e>1&&(e-=1),e}function h(e){return e===c()?"active":""}function u(){return c()<o()?"":"disabled"}function d(){return c()>1?"":"disabled"}function v(){return 1!==c()?"":"disabled"}function g(){return c()!==o()?"":"disabled"}function p(e){e>o()?i.invenioSearchArgs.page=o():i.invenioSearchArgs.page=e<1?1:e}e.paginatePages=[],e.adjacentSize=r.adjacentSize||4,e.showGoToFirstLast=r.showGoToFirstLast||!1,e.$watch("vm.invenioSearchArgs.page",function(e,n){e!==n&&t()}),e.$watch("vm.invenioSearchResults",function(e,n){t()}),e.paginationHelper={changePage:p,current:c,getFirstClass:v,getLastClass:g,getNextClass:u,getPageClass:h,getPrevClass:d,next:s,pages:t,previous:l,total:o}}function n(e,n){return n.template}return{restrict:"AE",scope:!1,require:"^invenioSearch",templateUrl:n,link:e}}function invenioSearchRange(e,n){function r(r,i,a,t){function o(e,n){if(!isNaN(e)&&!isNaN(n)){var i={},a={from:e,to:n},t=a.from+"--"+a.to;i[s.name]=t,r.$broadcast("invenio.search.params.change",i)}}function c(){if(h&&(s.width=l()||u),t.invenioSearchResults.aggregations){var n=t.invenioSearchResults.aggregations[s.name].buckets;if(n.length>0){if(t.invenioSearchArgs[s.name]&&t.invenioSearchArgs[s.name].length>0){var r=t.invenioSearchArgs[s.name].split("--"),i=+r[0],a=2===r.length?+r[1]:i;isNaN(i)||isNaN(a)||(s.selectionRange={min:i,max:a})}e(s.histogramId,s.selectionId,n,s,o)}}}var s={height:70,name:"years",histogramId:"#hist",selectionId:"#select",margins:{left:10,right:10,top:10,bottom:0},barColor:"#2c3e50",selectColor:"#3498db",lineColor:"#ccc",circleColor:"white",padding:2},l=function(){return d3.select(s.histogramId).node().getBoundingClientRect().width};angular.merge(s,angular.fromJson(a.options));var h=!s.width;if(h)var u=l();r.$on("invenio.search.finished",c),h&&angular.element(n).bind("resize",c)}function i(e,n){return n.template}return{restrict:"AE",require:"^invenioSearch",templateUrl:i,link:r}}function invenioSearchResults(){function e(e,n,r,i){e.recordTemplate=r.recordTemplate}function n(e,n){return n.template}return{restrict:"AE",scope:!1,require:"^invenioSearch",templateUrl:n,link:e}}function invenioSearchSelectBox(){function e(e,n,r,i){function a(n){var r=i.invenioSearchArgs[e.data.sortKey]||i.invenioSearchSortArgs[e.data.sortKey]||e.data.defaultSortBy||"";return"-"===r.charAt(0)&&(r=r.slice(1,r.length)),"-"===n.charAt(0)&&(n=n.slice(1,n.length)),r===n}function t(){i.invenioSearchArgs[e.data.sortKey]=e.data.selectedOption}function o(n,r){if(n){var i=null;i="-"===n.charAt(0)?n.slice(1,n.length):n,i.length&&(e.data.selectedOption=i)}}e.data={availableOptions:JSON.parse(r.availableOptions||"{}"),selectedOption:i.invenioSearchArgs[r.sortKey]||null,sortKey:r.sortKey||"sort",defaultSortBy:r.defaultSortBy},null===e.data.selectedOption&&(e.data.selectedOption=e.data.availableOptions.options[0].value),e.isSelected=a,e.handleFieldChange=t,e.$watchCollection("vm.invenioSearchSortArgs."+e.data.sortKey,o),e.$watchCollection("vm.invenioSearchArgs."+e.data.sortKey,o)}function n(e,n){return n.template}return{restrict:"AE",require:"^invenioSearch",templateUrl:n,link:e}}function invenioSearchSortOrder(){function e(e,n,r,i){function a(n,r){var a={};a[n]=r||null,i.invenioSearchArgs=angular.merge(i.invenioSearchArgs,a),e.whichOrder="-"!==(r||"").charAt(0)?"asc":"desc"}function t(){var n=i.invenioSearchArgs[e.sortKey]||i.invenioSearchCurrentArgs[e.sortKey]||this.data.selectedOption||"";"-"===n.charAt(0)&&(n=n.slice(1,n.length)),"asc"===e.whichOrder?a(e.sortKey,n):"desc"===e.whichOrder&&a(e.sortKey,"-"+n)}function o(n,r){n&&(e.whichOrder="-"!==n.charAt(0)?"asc":"desc")}e.sortKey=r.sortKey,e.handleOrderChange=t,e.whichOrder="asc",e.$watchCollection("vm.invenioSearchSortArgs."+e.sortKey,o),e.$watchCollection("vm.invenioSearchArgs."+e.sortKey,o)}function n(e,n){return n.template}return{restrict:"AE",require:"^invenioSearch",templateUrl:n,link:e}}function invenioSearchRangeFactory(){function e(e,r,t,l,v){o=angular.merge(l,o),n&&n.remove(),n=d3.select(e).append("svg").attr({width:o.width,height:o.height});var g=n.append("g").style("pointer-events","all"),p=d3.select("body").append("div").attr("class","range_tooltip").style({position:"absolute","text-align":"center",width:"40px",height:"18px",padding:"2px",font:"12px sans-serif",background:"lightblue",border:"0px","border-radius":"8px","pointer-events":"none",opacity:0});h(t);var S=d3.extent(t,function(e){return e.key});S[0]=S[0]-.1*t.length,S[1]=S[1]+.1*t.length,i=d3.scale.linear().domain(S).range([o.margins.left,o.width-o.margins.left-o.margins.right]);var f=Math.min(10,(o.width-o.margins.left-o.margins.right-t.length*o.padding)/(s-c));f=Math.max(1,f);var m=d3.max(t,function(e){return e.doc_count});a=d3.scale.linear().domain([0,m]).range([0,o.height-o.margins.bottom]);var y=g.selectAll(".bar").data(t).enter().append("g").attr("class","bar");y.append("rect").attr("height",function(e){return a(e.doc_count)}).attr("width",f).attr("x",function(e){return i(e.key)-f/2}).attr("y",function(e){return a.range()[1]-a(e.doc_count)}).style("fill",function(e){return e.selected?o.selectColor:o.barColor}),y.on("mouseenter",function(e){d3.select(this).style("cursor","pointer"),d3.select(this).style("opacity",.8),d3.select(this).select("rect").style("fill",d3.rgb(e.selected?o.selectColor:o.barColor).brighter()),p.transition().duration(200).style("opacity",.9),p.html(e.doc_count).style("left",d3.event.pageX+"px").style("top",d3.event.pageY-28+"px")}).on("mouseout",function(e){d3.select(this).style("cursor","default"),d3.select(this).style("opacity",1),d3.select(this).select("rect").style("fill",e.selected?o.selectColor:o.barColor),p.transition().duration(500).style("opacity",0)}).on("click",function(e){p.transition().style("opacity",0),u([e.key,e.key]),d3.select(".resize.e").style("display","inline")}),d(e,r,v)}var n,r,i,a,t,o,c,s,l=[],h=function(e){e.forEach(function(e){e.key=+e.key_as_string,o.showBarOnEmpty&&0===e.doc_count&&(e.doc_count=.01),o.selectionRange?e.selected=e.key>=o.selectionRange.min&&e.key<=o.selectionRange.max:e.selected=!0});var n=e.map(function(e){return e.key});c=Math.min.apply(void 0,n),s=Math.max.apply(void 0,n)},u=function(e){e=angular.copy(e),e[0]===e[1]&&(e[1]+=1e-5),t.extent(e),t(d3.select(".brush").transition()),t.event(d3.select(".brush").transition())},d=function(e,n,a){r&&r.remove(),r=d3.select(n).append("svg").attr({width:o.width,height:35}).style("fill",o.selectColor).style("overflow","visible"),r.append("line").attr({x1:0,x2:o.width,y1:5.5,y2:5.5}).style({stroke:o.lineColor,"stroke-width":3});var h=function(){var e=t.extent().map(Math.round);e.some(isNaN)&&(e=[c,s]),d3.select(".brush-range.min").text(e[0]),d3.select(".brush-range.max").text(e[1]),l=[],d3.selectAll("g.bar").select("rect").style("fill",function(n){return n.selected=n.key>=e[0]&&n.key<=e[1],n.selected&&l.push(n.key),n.selected?o.selectColor:o.barColor})},u=[c,s];if(o.selectionRange){var d=parseInt(i.domain()[0]),v=parseInt(i.domain()[1]);u=[o.selectionRange.min<d||o.selectionRange.min>v?d:o.selectionRange.min,o.selectionRange.max>v||o.selectionRange.max<d?v:o.selectionRange.max]}t=d3.svg.brush().x(i).extent(u).on("brush",h).on("brushend",function(){var e;0===l.length?e=[c,s]:(e=t.extent().map(Math.round),e[0]=Math.max(e[0],c),e[1]=Math.min(e[1],s)),a.apply(void 0,e)}),r.append("g").attr("class","brush").call(t).selectAll("rect").attr("y",4).attr("height",3);var g=r.selectAll(".resize").append("g");g.append("circle").attr("r",5).attr("cx",0).attr("cy",6).style({"stroke-width":2,stroke:o.selectColor,fill:o.circleColor}),g.append("text").attr("text-anchor","middle").style("transform","rotate(-45deg) translateX(-15px)").text(function(e,n){return parseInt(t.extent()[0===n?1:0])}).attr("class",function(e,n){return"brush-range "+(0===n?"max":"min")}).attr("y",31),parseInt(u[0])===parseInt(u[1])&&d3.select(".resize.e").style("display","inline")};return e}function invenioSearchAPI(e,n,r){function i(i,a){function t(e){c.resolve(e)}function o(e){c.reject(e)}var c=n.defer(),s=angular.copy(i);return s.params=angular.merge(s.params,a||{}),s.paramSerializer=function(e){var n=[];return angular.forEach(e,function(e,n){if(angular.isArray(e)){var i=this;e.filter(function(e){i.push(r.encodeURIComponent(n)+"="+r.encodeURIComponent(e))})}else this.push(r.encodeURIComponent(n)+"="+r.encodeURIComponent(e))},n),n.join("&")},e(s).then(t,o),c.promise}return{search:i}}function invenioSearchHandler(e){function n(){return e.search()}function r(n){e.search(n)}function i(){e.replace()}return{get:n,replace:i,set:r}}invenioSearchConfiguration.$inject=["$locationProvider"],angular.module("invenioSearch.configuration",[]).config(invenioSearchConfiguration),angular.module("invenioSearch.services",[]),angular.module("invenioSearch.factories",[]),angular.module("invenioSearch.controllers",[]),angular.module("invenioSearch.directives",[]),angular.module("invenioSearch",["invenioSearch.configuration","invenioSearch.services","invenioSearch.factories","invenioSearch.controllers","invenioSearch.directives"]),invenioSearchCtrl.$inject=["$scope","invenioSearchHandler","invenioSearchAPI"],angular.module("invenioSearch.controllers").controller("invenioSearchCtrl",invenioSearchCtrl),angular.module("invenioSearch.directives").directive("invenioSearch",invenioSearch),angular.module("invenioSearch.directives").directive("invenioSearchBar",invenioSearchBar),angular.module("invenioSearch.directives").directive("invenioSearchCount",invenioSearchCount),angular.module("invenioSearch.directives").directive("invenioSearchError",invenioSearchError),angular.module("invenioSearch.directives").directive("invenioSearchFacets",invenioSearchFacets),angular.module("invenioSearch.directives").directive("invenioSearchLoading",invenioSearchLoading),angular.module("invenioSearch.directives").directive("invenioSearchPagination",invenioSearchPagination),invenioSearchRange.$inject=["invenioSearchRangeFactory","$window"],angular.module("invenioSearch.directives").directive("invenioSearchRange",invenioSearchRange),angular.module("invenioSearch.directives").directive("invenioSearchResults",invenioSearchResults),angular.module("invenioSearch.directives").directive("invenioSearchSelectBox",invenioSearchSelectBox),angular.module("invenioSearch.directives").directive("invenioSearchSortOrder",invenioSearchSortOrder),angular.module("invenioSearch.factories").factory("invenioSearchRangeFactory",invenioSearchRangeFactory),invenioSearchAPI.$inject=["$http","$q","$window"],angular.module("invenioSearch.services").service("invenioSearchAPI",invenioSearchAPI),invenioSearchHandler.$inject=["$location"],angular.module("invenioSearch.services").service("invenioSearchHandler",invenioSearchHandler); | ||
function invenioSearchConfiguration(e){e.html5Mode({enabled:!0,requireBase:!1,rewriteLinks:!1})}function invenioSearchCtrl(e,n,r){function i(){return n.get()}function a(){function n(){v.invenioSearchLoading=!1,e.$broadcast("invenio.search.finished")}function i(n){e.$broadcast("invenio.search.success",n)}function a(n){e.$broadcast("invenio.search.error",n)}e.$broadcast("invenio.search.requested"),v.invenioSearchLoading=!0,v.invenioSearchError={},v.invenioSearchErrorsResults={},r.search(v.invenioSearchCurrentArgs,v.invenioSearchHiddenParams).then(i,a).finally(n)}function t(e){for(var n=(e.split("?")[1]||"").split("&"),r={},i=0;i<n.length;i+=1){var a=(n[i]||"").split("="),t=decodeURIComponent(a[0]||"");t&&(r[t]=decodeURIComponent(a[1]||""))}return r}function o(e,n){v.invenioSearchErrorResults=n.data,v.invenioSearchError=e}function c(e,n){if(v.invenioSearchResults=n.data,v.invenioSearchErrorResults={},n.data.links){var r=t(n.data.links.self);r.page&&(r.page=parseInt(r.page)),r.size&&(r.size=parseInt(r.size)),delete r.q,angular.equals(v.invenioSearchCurrentArgs,r)||(v.invenioSearchSortArgs=r)}}function s(r,i){v.invenioSearchCurrentArgs=angular.merge({},v.invenioSearchCurrentArgs,i),v.invenioSearchArgs=angular.merge({},v.invenioSearchCurrentArgs.params),v.disableUrlHandler||(n.set(v.invenioSearchArgs),n.replace()),v.userQuery=v.invenioSearchArgs.q,v.invenioSearchInitialized=!0,v.invenioDoSearch(),e.$broadcast("invenio.search.initialiazed")}function l(e,r,i){void 0!==i&&!0===i?v.invenioSearchCurrentArgs.params=angular.copy(r):(v.invenioSearchCurrentArgs.params.page===r.page&&(r.page=1),angular.forEach(r,function(e,n){v.invenioSearchCurrentArgs.params[n]=e})),v.invenioSearchArgs=angular.copy(v.invenioSearchCurrentArgs.params),v.disableUrlHandler||n.set(v.invenioSearchCurrentArgs.params),v.userQuery=v.invenioSearchArgs.q,v.invenioDoSearch()}function h(r,i,a){if(!v.disableUrlHandler){var t=n.get();angular.equals(t,v.invenioSearchCurrentArgs.params)||e.$broadcast("invenio.search.request",t,!0)}}function u(n,r){var i=angular.copy(v.invenioSearchCurrentArgs.params);angular.forEach(r,function(e,n){i[n]=angular.copy(r[n])}),angular.equals(v.invenioSearchCurrentArgs.params,i)||e.$broadcast("invenio.search.request",i)}function d(n,r){angular.equals(n,v.invenioSearchCurrentArgs.params)||e.$broadcast("invenio.search.request",n)}var v=this;v.invenioSearchResults={},v.invenioSearchErrorResults={},v.invenioSearchLoading=!0,v.invenioSearchError={},v.invenioSearchInitialized=!1,v.invenioSearchArgs={},v.invenioSearchSortArgs={},v.invenioSearchCurrentArgs={method:"GET",params:{page:1,size:20}},v.invenioSearchGetUrlArgs=i,v.invenioDoSearch=a,v.parseURLQueryString=t,e.$on("invenio.search.initialization",s),e.$on("invenio.search.request",l),e.$on("invenio.search.success",c),e.$on("invenio.search.error",o),e.$on("invenio.search.params.change",u),e.$on("$locationChangeStart",h),e.$watch("vm.invenioSearchArgs",d,!0)}function invenioSearch(){function e(e,n,r,i){var a={url:r.searchEndpoint,method:r.searchMethod||"GET",headers:JSON.parse(r.searchHeaders||"{}")},t={params:JSON.parse(r.searchExtraParams||"{}")},o={params:i.invenioSearchGetUrlArgs()};i.disableUrlHandler=!!r.disableUrlHandler,i.invenioSearchHiddenParams=JSON.parse(r.searchHiddenParams||"{}");var c=angular.merge({},a,t,o);e.$broadcast("invenio.search.initialization",c)}return{restrict:"AE",scope:!1,controller:"invenioSearchCtrl",controllerAs:"vm",link:e}}function invenioSearchBar(){function e(e,n,r,i){function a(){i.invenioSearchArgs.q=i.userQuery}e.placeholder=r.placeholder,e.updateQuery=a}function n(e,n){return n.template}return{restrict:"AE",require:"^invenioSearch",scope:!1,templateUrl:n,link:e}}function invenioSearchCount(){function e(e,n){return n.template}return{restrict:"AE",scope:!1,require:"^invenioSearch",templateUrl:e}}function invenioSearchError(){function e(e,n,r,i){e.errorMessage=r.message}function n(e,n){return n.template}return{restrict:"AE",scope:!1,require:"^invenioSearch",templateUrl:n,link:e}}function invenioSearchFacets(){function e(e,n,r,i){function a(n,r){e.handler[n]=void 0===e.handler[n]?[]:e.handler[n],"string"==typeof e.handler[n]&&(e.handler[n]=[e.handler[n]]);var i=e.handler[n].indexOf(r);-1===i?e.handler[n].push(r):"string"==typeof e.handler[n]?e.handler[n]=[]:e.handler[n].splice(i,1);var a={};a[n]=angular.copy(e.handler[n]),e.$broadcast("invenio.search.params.change",a)}function t(n){return"string"==typeof e.handler[n]?[e.handler[n]]:e.handler[n]}function o(n){if(n){var r=e.aggOrder||Object.keys(n);e.orderedAggs=r.map(function(e){return{key:e,value:n[e]}})}}e.handler=angular.copy(i.invenioSearchCurrentArgs.params),r.order&&(e.aggOrder=r.order.split(",")),o(i.invenioSearchResults.aggregations),e.$on("invenio.search.finished",function(n){e.handler=angular.copy(i.invenioSearchCurrentArgs.params)}),e.$watch("vm.invenioSearchResults.aggregations",o),e.handleClick=a,e.getValues=t}function n(e,n){return n.template}return{restrict:"AE",scope:!1,require:"^invenioSearch",templateUrl:n,link:e}}function invenioSearchLoading(){function e(e,n,r,i){e.loadingMessage=r.message}function n(e,n){return n.template}return{restrict:"AE",require:"^invenioSearch",templateUrl:n,link:e}}function invenioSearchPagination(){function e(e,n,r,i){function a(n,r){for(var i=(c(),n);i<=r;i++){var a=function(e){return{value:e,title:"Go to page "+e}}(i);e.paginatePages.push(a)}}function t(){e.paginatePages=[];var n,r,i=e.adjacentSize,t=o(),s=c(),l=2*i;t<=l+2?(n=1,a(n,t)):s-i<=2?(n=1,r=1+l,a(n,r)):s<t-(i+2)?(n=s-i,r=s+i,a(n,r)):(n=t-l,r=t,a(n,r))}function o(){var e;try{e=i.invenioSearchResults.hits.total}catch(n){e=0}return Math.ceil(e/i.invenioSearchArgs.size)}function c(){return parseInt(i.invenioSearchArgs.page)||1}function s(){var e=c();return e<o()&&(e+=1),e}function l(){var e=c();o();return e>1&&(e-=1),e}function h(e){return e===c()?"active":""}function u(){return c()<o()?"":"disabled"}function d(){return c()>1?"":"disabled"}function v(){return 1!==c()?"":"disabled"}function g(){return c()!==o()?"":"disabled"}function p(e){e>o()?i.invenioSearchArgs.page=o():i.invenioSearchArgs.page=e<1?1:e}e.paginatePages=[],e.adjacentSize=r.adjacentSize||4,e.showGoToFirstLast=r.showGoToFirstLast||!1,e.$watch("vm.invenioSearchArgs.page",function(e,n){e!==n&&t()}),e.$watch("vm.invenioSearchResults",function(e,n){t()}),e.paginationHelper={changePage:p,current:c,getFirstClass:v,getLastClass:g,getNextClass:u,getPageClass:h,getPrevClass:d,next:s,pages:t,previous:l,total:o}}function n(e,n){return n.template}return{restrict:"AE",scope:!1,require:"^invenioSearch",templateUrl:n,link:e}}function invenioSearchRange(e,n){function r(r,i,a,t){function o(e,n){if(!isNaN(e)&&!isNaN(n)){var i={},a={from:e,to:n},t=a.from+"--"+a.to;i[l.name]=t,r.$broadcast("invenio.search.params.change",i)}}function c(){var e={};delete l.selectionRange,e[l.name]=[],r.$broadcast("invenio.search.params.change",e)}function s(){if(u&&(l.width=h()||d),t.invenioSearchResults.aggregations){var n=t.invenioSearchResults.aggregations[l.name].buckets;if(n.length>0){if(t.invenioSearchArgs[l.name]&&t.invenioSearchArgs[l.name].length>0){var r=t.invenioSearchArgs[l.name].split("--"),i=+r[0],a=2===r.length?+r[1]:i;isNaN(i)||isNaN(a)||(l.selectionRange={min:i,max:a})}e(l.histogramId,l.selectionId,n,l,o)}}}var l={height:70,name:"years",histogramId:"#hist",selectionId:"#select",margins:{left:10,right:10,top:10,bottom:0},barColor:"#2c3e50",selectColor:"#3498db",lineColor:"#ccc",circleColor:"white",padding:2},h=function(){return d3.select(l.histogramId).node().getBoundingClientRect().width};angular.merge(l,angular.fromJson(a.options));var u=!l.width;if(u)var d=h();r.$on("invenio.search.finished",s),u&&angular.element(n).bind("resize",s),r.resetRangeSelection=c}function i(e,n){return n.template}return{restrict:"AE",require:"^invenioSearch",templateUrl:i,link:r}}function invenioSearchResults(){function e(e,n,r,i){e.recordTemplate=r.recordTemplate}function n(e,n){return n.template}return{restrict:"AE",scope:!1,require:"^invenioSearch",templateUrl:n,link:e}}function invenioSearchSelectBox(){function e(e,n,r,i){function a(n){var r=i.invenioSearchArgs[e.data.sortKey]||i.invenioSearchSortArgs[e.data.sortKey]||e.data.defaultSortBy||"";return"-"===r.charAt(0)&&(r=r.slice(1,r.length)),"-"===n.charAt(0)&&(n=n.slice(1,n.length)),r===n}function t(){i.invenioSearchArgs[e.data.sortKey]=e.data.selectedOption}function o(n,r){if(n){var i=null;i="-"===n.charAt(0)?n.slice(1,n.length):n,i.length&&(e.data.selectedOption=i)}}e.data={availableOptions:JSON.parse(r.availableOptions||"{}"),selectedOption:i.invenioSearchArgs[r.sortKey]||null,sortKey:r.sortKey||"sort",defaultSortBy:r.defaultSortBy},null===e.data.selectedOption&&(e.data.selectedOption=e.data.availableOptions.options[0].value),e.isSelected=a,e.handleFieldChange=t,e.$watchCollection("vm.invenioSearchSortArgs."+e.data.sortKey,o),e.$watchCollection("vm.invenioSearchArgs."+e.data.sortKey,o)}function n(e,n){return n.template}return{restrict:"AE",require:"^invenioSearch",templateUrl:n,link:e}}function invenioSearchSortOrder(){function e(e,n,r,i){function a(n,r){var a={};a[n]=r||null,i.invenioSearchArgs=angular.merge(i.invenioSearchArgs,a),e.whichOrder="-"!==(r||"").charAt(0)?"asc":"desc"}function t(){var n=i.invenioSearchArgs[e.sortKey]||i.invenioSearchCurrentArgs[e.sortKey]||this.data.selectedOption||"";"-"===n.charAt(0)&&(n=n.slice(1,n.length)),"asc"===e.whichOrder?a(e.sortKey,n):"desc"===e.whichOrder&&a(e.sortKey,"-"+n)}function o(n,r){n&&(e.whichOrder="-"!==n.charAt(0)?"asc":"desc")}e.sortKey=r.sortKey,e.handleOrderChange=t,e.whichOrder="asc",e.$watchCollection("vm.invenioSearchSortArgs."+e.sortKey,o),e.$watchCollection("vm.invenioSearchArgs."+e.sortKey,o)}function n(e,n){return n.template}return{restrict:"AE",require:"^invenioSearch",templateUrl:n,link:e}}function invenioSearchRangeFactory(){function e(e,r,t,l,v){o=angular.merge(l,o),n&&n.remove(),n=d3.select(e).append("svg").attr({width:o.width,height:o.height});var g=n.append("g").style("pointer-events","all"),p=d3.select("body").append("div").attr("class","range_tooltip").style({position:"absolute","text-align":"center",width:"40px",height:"18px",padding:"2px",font:"12px sans-serif",background:"lightblue",border:"0px","border-radius":"8px","pointer-events":"none",opacity:0});h(t);var S=d3.extent(t,function(e){return e.key});S[0]=S[0]-.1*t.length,S[1]=S[1]+.1*t.length,i=d3.scale.linear().domain(S).range([o.margins.left,o.width-o.margins.left-o.margins.right]);var f=Math.min(10,(o.width-o.margins.left-o.margins.right-t.length*o.padding)/(s-c));f=Math.max(1,f);var m=d3.max(t,function(e){return e.doc_count});a=d3.scale.linear().domain([0,m]).range([0,o.height-o.margins.bottom]);var y=g.selectAll(".bar").data(t).enter().append("g").attr("class","bar");y.append("rect").attr("height",function(e){return a(e.doc_count)}).attr("width",f).attr("x",function(e){return i(e.key)-f/2}).attr("y",function(e){return a.range()[1]-a(e.doc_count)}).style("fill",function(e){return e.selected?o.selectColor:o.barColor}),y.on("mouseenter",function(e){d3.select(this).style("cursor","pointer"),d3.select(this).style("opacity",.8),d3.select(this).select("rect").style("fill",d3.rgb(e.selected?o.selectColor:o.barColor).brighter()),p.transition().duration(200).style("opacity",.9),p.html(e.doc_count).style("left",d3.event.pageX+"px").style("top",d3.event.pageY-28+"px")}).on("mouseout",function(e){d3.select(this).style("cursor","default"),d3.select(this).style("opacity",1),d3.select(this).select("rect").style("fill",e.selected?o.selectColor:o.barColor),p.transition().duration(500).style("opacity",0)}).on("click",function(e){p.transition().style("opacity",0),u([e.key,e.key]),d3.select(".resize.e").style("display","inline")}),d(e,r,v)}var n,r,i,a,t,o,c,s,l=[],h=function(e){e.forEach(function(e){e.key=+e.key_as_string,o.showBarOnEmpty&&0===e.doc_count&&(e.doc_count=.01),o.selectionRange?e.selected=e.key>=o.selectionRange.min&&e.key<=o.selectionRange.max:e.selected=!0});var n=e.map(function(e){return e.key});c=Math.min.apply(void 0,n),s=Math.max.apply(void 0,n)},u=function(e){e=angular.copy(e),e[0]===e[1]&&(e[1]+=1e-5),t.extent(e),t(d3.select(".brush").transition()),t.event(d3.select(".brush").transition())},d=function(e,n,a){r&&r.remove(),r=d3.select(n).append("svg").attr({width:o.width,height:35}).style("fill",o.selectColor).style("overflow","visible"),r.append("line").attr({x1:0,x2:o.width,y1:5.5,y2:5.5}).style({stroke:o.lineColor,"stroke-width":3});var h=function(){var e=t.extent().map(Math.round);e.some(isNaN)&&(e=[c,s]),d3.select(".brush-range.min").text(e[0]),d3.select(".brush-range.max").text(e[1]),l=[],d3.selectAll("g.bar").select("rect").style("fill",function(n){return n.selected=n.key>=e[0]&&n.key<=e[1],n.selected&&l.push(n.key),n.selected?o.selectColor:o.barColor})},u=[c,s];if(o.selectionRange){var d=parseInt(i.domain()[0]),v=parseInt(i.domain()[1]);u=[o.selectionRange.min<d||o.selectionRange.min>v?d:o.selectionRange.min,o.selectionRange.max>v||o.selectionRange.max<d?v:o.selectionRange.max]}t=d3.svg.brush().x(i).extent(u).on("brush",h).on("brushend",function(){var e;0===l.length?e=[c,s]:(e=t.extent().map(Math.round),e[0]=Math.max(e[0],c),e[1]=Math.min(e[1],s)),a.apply(void 0,e)}),r.append("g").attr("class","brush").call(t).selectAll("rect").attr("y",4).attr("height",3);var g=r.selectAll(".resize").append("g");g.append("circle").attr("r",5).attr("cx",0).attr("cy",6).style({"stroke-width":2,stroke:o.selectColor,fill:o.circleColor}),g.append("text").attr("text-anchor","middle").style("transform","rotate(-45deg) translateX(-15px)").text(function(e,n){return parseInt(t.extent()[0===n?1:0])}).attr("class",function(e,n){return"brush-range "+(0===n?"max":"min")}).attr("y",31),parseInt(u[0])===parseInt(u[1])&&d3.select(".resize.e").style("display","inline")};return e}function invenioSearchAPI(e,n,r){function i(i,a){function t(e){c.resolve(e)}function o(e){c.reject(e)}var c=n.defer(),s=angular.copy(i);return s.params=angular.merge(s.params,a||{}),s.paramSerializer=function(e){var n=[];return angular.forEach(e,function(e,n){if(angular.isArray(e)){var i=this;e.filter(function(e){i.push(r.encodeURIComponent(n)+"="+r.encodeURIComponent(e))})}else this.push(r.encodeURIComponent(n)+"="+r.encodeURIComponent(e))},n),n.join("&")},e(s).then(t,o),c.promise}return{search:i}}function invenioSearchHandler(e){function n(){return e.search()}function r(n){e.search(n)}function i(){e.replace()}return{get:n,replace:i,set:r}}invenioSearchConfiguration.$inject=["$locationProvider"],angular.module("invenioSearch.configuration",[]).config(invenioSearchConfiguration),angular.module("invenioSearch.services",[]),angular.module("invenioSearch.factories",[]),angular.module("invenioSearch.controllers",[]),angular.module("invenioSearch.directives",[]),angular.module("invenioSearch",["invenioSearch.configuration","invenioSearch.services","invenioSearch.factories","invenioSearch.controllers","invenioSearch.directives"]),invenioSearchCtrl.$inject=["$scope","invenioSearchHandler","invenioSearchAPI"],angular.module("invenioSearch.controllers").controller("invenioSearchCtrl",invenioSearchCtrl),angular.module("invenioSearch.directives").directive("invenioSearch",invenioSearch),angular.module("invenioSearch.directives").directive("invenioSearchBar",invenioSearchBar),angular.module("invenioSearch.directives").directive("invenioSearchCount",invenioSearchCount),angular.module("invenioSearch.directives").directive("invenioSearchError",invenioSearchError),angular.module("invenioSearch.directives").directive("invenioSearchFacets",invenioSearchFacets),angular.module("invenioSearch.directives").directive("invenioSearchLoading",invenioSearchLoading),angular.module("invenioSearch.directives").directive("invenioSearchPagination",invenioSearchPagination),invenioSearchRange.$inject=["invenioSearchRangeFactory","$window"],angular.module("invenioSearch.directives").directive("invenioSearchRange",invenioSearchRange),angular.module("invenioSearch.directives").directive("invenioSearchResults",invenioSearchResults),angular.module("invenioSearch.directives").directive("invenioSearchSelectBox",invenioSearchSelectBox),angular.module("invenioSearch.directives").directive("invenioSearchSortOrder",invenioSearchSortOrder),angular.module("invenioSearch.factories").factory("invenioSearchRangeFactory",invenioSearchRangeFactory),invenioSearchAPI.$inject=["$http","$q","$window"],angular.module("invenioSearch.services").service("invenioSearchAPI",invenioSearchAPI),invenioSearchHandler.$inject=["$location"],angular.module("invenioSearch.services").service("invenioSearchHandler",invenioSearchHandler); |
{ | ||
"name": "invenio-search-js", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "Javascript search components for Invenio-Search", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -154,2 +154,3 @@ /* | ||
} | ||
scope.resetRangeSelection = resetUserSelection; | ||
} | ||
@@ -156,0 +157,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
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
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
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
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
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
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
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
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
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
898518
6687