diff --git a/README.md b/README.md index 277a88f..654b058 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ For some queries you may need to use a different index than the global one. In t In the following example, we create a new service called **Equinox** that uses a different Solr index. ``` -app.provider('Equinox', function(Solstice) { +app.service('Equinox', function(Solstice) { return Solstice.withEndpoint('a-diferent-solr-index-url'); }); diff --git a/dist/solstice.js b/dist/solstice.js index b6b7c64..1ac9ab6 100644 --- a/dist/solstice.js +++ b/dist/solstice.js @@ -1,6 +1,6 @@ /** * A simple Solr wrapper for AngularJS apps - * @version v0.0.2 - 2013-11-28 + * @version v0.1 - 2015-07-03 * @link https://github.com/front/solstice * @author Élio Cró * @license MIT License, http://www.opensource.org/licenses/MIT @@ -12,36 +12,65 @@ var solr = ng.module('solstice', []); /* Solr search service */ - solr.provider('Solstice', function () { + function SolsticeProvider() { var defEndpoint = ''; - return { - setEndpoint: function (url) { - defEndpoint = url; - }, - $get: function ($http) { - function Solstice(endpoint) { - this.search = function(options) { - var url = endpoint + '/select/'; - var defaults = { - wt: 'json', - 'json.wrf': 'JSON_CALLBACK' - }; - ng.extend(defaults, options); - return $http.jsonp(url, { - params: defaults - }); - }; - this.withEndpoint = function (url) { - return new Solstice(url); + function $get($http) { + function Solstice(endpoint) { + this.search = function(options) { + var url = endpoint + '/select/'; + var defaults = { + wt: 'json', + 'json.wrf': 'JSON_CALLBACK' }; - } - return new Solstice(defEndpoint); + ng.extend(defaults, options); + return $http.jsonp(url, { + params: defaults + }); + }; + this.withEndpoint = function (url) { + return new Solstice(url); + }; } - }; - }); + return new Solstice(defEndpoint); + } + function setEndpoint(url) { + defEndpoint = url; + } + + return { + $get: [ '$http', $get ], + setEndpoint: setEndpoint + } + } /* Solr search directive */ - solr.directive('solrSearch', function() { + function directive() { + /* Solr search directive controller */ + function controller($scope, $rootScope, Solstice) { + var searchServ = !$scope.indexUrl ? Solstice : + Solstice.withEndpoint($scope.indexUrl); + + var options = { + q: $scope.q || '*:*', + start: $scope.start || 0, + rows: $scope.rows || 10 + }; + if($scope.sort) { + options.sort = $scope.sort; + } + if($scope.fl) { + options.fl = $scope.fl; + } + + searchServ.search(options).then(function (data) { + var res = data.data.response; + var transScope = $scope.$$nextSibling; + transScope.solr = $rootScope.solr || {}; + transScope.solr.results = res.docs; + transScope.solr.count = res.numFound; + }); + } + return { restrict: 'AE', transclude: true, @@ -55,32 +84,12 @@ fl: '@fields', indexUrl: '@' }, - controller: function ($scope, $rootScope, Solstice) { - var searchServ = !$scope.indexUrl ? Solstice : - Solstice.withEndpoint($scope.indexUrl); - - var options = { - q: $scope.q || '*:*', - start: $scope.start || 0, - rows: $scope.rows || 10 - }; - if($scope.sort) { - options.sort = $scope.sort; - } - if($scope.fl) { - options.fl = $scope.fl; - } - - searchServ.search(options) - .then(function (data) { - var res = data.data.response; - var transScope = $scope.$$nextSibling; - transScope.solr = $rootScope.solr || {}; - transScope.solr.results = res.docs; - transScope.solr.count = res.numFound; - }); - } + controller: [ '$scope', '$rootScope', 'Solstice', controller ] }; - }); + } + + solr.provider('Solstice', [ SolsticeProvider ]); + solr.directive('solrSearch', [ directive ]); })(window.angular); + diff --git a/dist/solstice.min.js b/dist/solstice.min.js index 3f37448..1f90405 100644 --- a/dist/solstice.min.js +++ b/dist/solstice.min.js @@ -1,8 +1,8 @@ /** * A simple Solr wrapper for AngularJS apps - * @version v0.0.2 - 2013-11-28 + * @version v0.1 - 2015-07-03 * @link https://github.com/front/solstice * @author Élio Cró * @license MIT License, http://www.opensource.org/licenses/MIT */ -!function(ng){"use strict";var solr=ng.module("solstice",[]);solr.provider("Solstice",function(){var defEndpoint="";return{setEndpoint:function(url){defEndpoint=url},$get:function($http){function Solstice(endpoint){this.search=function(options){var url=endpoint+"/select/",defaults={wt:"json","json.wrf":"JSON_CALLBACK"};return ng.extend(defaults,options),$http.jsonp(url,{params:defaults})},this.withEndpoint=function(url){return new Solstice(url)}}return new Solstice(defEndpoint)}}}),solr.directive("solrSearch",function(){return{restrict:"AE",transclude:!0,replace:!1,template:"
",scope:{q:"@query",start:"@",rows:"@",sort:"@",fl:"@fields",indexUrl:"@"},controller:function($scope,$rootScope,Solstice){var searchServ=$scope.indexUrl?Solstice.withEndpoint($scope.indexUrl):Solstice,options={q:$scope.q||"*:*",start:$scope.start||0,rows:$scope.rows||10};$scope.sort&&(options.sort=$scope.sort),$scope.fl&&(options.fl=$scope.fl),searchServ.search(options).then(function(data){var res=data.data.response,transScope=$scope.$$nextSibling;transScope.solr=$rootScope.solr||{},transScope.solr.results=res.docs,transScope.solr.count=res.numFound})}}})}(window.angular); \ No newline at end of file +!function(ng){"use strict";function SolsticeProvider(){function $get($http){function Solstice(endpoint){this.search=function(options){var url=endpoint+"/select/",defaults={wt:"json","json.wrf":"JSON_CALLBACK"};return ng.extend(defaults,options),$http.jsonp(url,{params:defaults})},this.withEndpoint=function(url){return new Solstice(url)}}return new Solstice(defEndpoint)}function setEndpoint(url){defEndpoint=url}var defEndpoint="";return{$get:["$http",$get],setEndpoint:setEndpoint}}function directive(){function controller($scope,$rootScope,Solstice){var searchServ=$scope.indexUrl?Solstice.withEndpoint($scope.indexUrl):Solstice,options={q:$scope.q||"*:*",start:$scope.start||0,rows:$scope.rows||10};$scope.sort&&(options.sort=$scope.sort),$scope.fl&&(options.fl=$scope.fl),searchServ.search(options).then(function(data){var res=data.data.response,transScope=$scope.$$nextSibling;transScope.solr=$rootScope.solr||{},transScope.solr.results=res.docs,transScope.solr.count=res.numFound})}return{restrict:"AE",transclude:!0,replace:!1,template:"
",scope:{q:"@query",start:"@",rows:"@",sort:"@",fl:"@fields",indexUrl:"@"},controller:["$scope","$rootScope","Solstice",controller]}}var solr=ng.module("solstice",[]);solr.provider("Solstice",[SolsticeProvider]),solr.directive("solrSearch",[directive])}(window.angular); \ No newline at end of file diff --git a/package.json b/package.json index 2c6a7b7..bcef1d5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "solstice", "description": "A simple Solr wrapper for AngularJS apps", - "version": "0.0.2", + "version": "0.1", "author": "Élio Cró ", "homepage": "https://github.com/front/solstice", "repository": { diff --git a/src/solstice.js b/src/solstice.js index fdf3abb..d7e2474 100644 --- a/src/solstice.js +++ b/src/solstice.js @@ -5,36 +5,65 @@ var solr = ng.module('solstice', []); /* Solr search service */ - solr.provider('Solstice', function () { + function SolsticeProvider() { var defEndpoint = ''; - return { - setEndpoint: function (url) { - defEndpoint = url; - }, - $get: function ($http) { - function Solstice(endpoint) { - this.search = function(options) { - var url = endpoint + '/select/'; - var defaults = { - wt: 'json', - 'json.wrf': 'JSON_CALLBACK' - }; - ng.extend(defaults, options); - return $http.jsonp(url, { - params: defaults - }); - }; - this.withEndpoint = function (url) { - return new Solstice(url); + function $get($http) { + function Solstice(endpoint) { + this.search = function(options) { + var url = endpoint + '/select/'; + var defaults = { + wt: 'json', + 'json.wrf': 'JSON_CALLBACK' }; - } - return new Solstice(defEndpoint); + ng.extend(defaults, options); + return $http.jsonp(url, { + params: defaults + }); + }; + this.withEndpoint = function (url) { + return new Solstice(url); + }; } - }; - }); + return new Solstice(defEndpoint); + } + function setEndpoint(url) { + defEndpoint = url; + } + + return { + $get: [ '$http', $get ], + setEndpoint: setEndpoint + } + } /* Solr search directive */ - solr.directive('solrSearch', function() { + function directive() { + /* Solr search directive controller */ + function controller($scope, $rootScope, Solstice) { + var searchServ = !$scope.indexUrl ? Solstice : + Solstice.withEndpoint($scope.indexUrl); + + var options = { + q: $scope.q || '*:*', + start: $scope.start || 0, + rows: $scope.rows || 10 + }; + if($scope.sort) { + options.sort = $scope.sort; + } + if($scope.fl) { + options.fl = $scope.fl; + } + + searchServ.search(options).then(function (data) { + var res = data.data.response; + var transScope = $scope.$$nextSibling; + transScope.solr = $rootScope.solr || {}; + transScope.solr.results = res.docs; + transScope.solr.count = res.numFound; + }); + } + return { restrict: 'AE', transclude: true, @@ -48,32 +77,12 @@ fl: '@fields', indexUrl: '@' }, - controller: function ($scope, $rootScope, Solstice) { - var searchServ = !$scope.indexUrl ? Solstice : - Solstice.withEndpoint($scope.indexUrl); - - var options = { - q: $scope.q || '*:*', - start: $scope.start || 0, - rows: $scope.rows || 10 - }; - if($scope.sort) { - options.sort = $scope.sort; - } - if($scope.fl) { - options.fl = $scope.fl; - } - - searchServ.search(options) - .then(function (data) { - var res = data.data.response; - var transScope = $scope.$$nextSibling; - transScope.solr = $rootScope.solr || {}; - transScope.solr.results = res.docs; - transScope.solr.count = res.numFound; - }); - } + controller: [ '$scope', '$rootScope', 'Solstice', controller ] }; - }); + } + + solr.provider('Solstice', [ SolsticeProvider ]); + solr.directive('solrSearch', [ directive ]); })(window.angular); +