Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

Enhancement/strict di #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down
113 changes: 61 additions & 52 deletions dist/solstice.js
Original file line number Diff line number Diff line change
@@ -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ó <[email protected]>
* @license MIT License, http://www.opensource.org/licenses/MIT
Expand All @@ -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,
Expand All @@ -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);

4 changes: 2 additions & 2 deletions dist/solstice.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "solstice",
"description": "A simple Solr wrapper for AngularJS apps",
"version": "0.0.2",
"version": "0.1",
"author": "Élio Cró <[email protected]>",
"homepage": "https://github.com/front/solstice",
"repository": {
Expand Down
111 changes: 60 additions & 51 deletions src/solstice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);