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

Commit cc4e74a

Browse files
author
Elio Cro
committed
First commit
0 parents  commit cc4e74a

File tree

8 files changed

+250
-0
lines changed

8 files changed

+250
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
node_modules
3+

.jshintrc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"browser": true,
3+
"strict": true,
4+
"indent": 2,
5+
"latedef": true,
6+
"undef": true,
7+
"unused": true,
8+
"camelcase": true,
9+
"curly": true,
10+
"eqeqeq": true,
11+
"newcap": true,
12+
"quotmark": "single"
13+
}

Gruntfile.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use strict';
2+
3+
module.exports = function(grunt) {
4+
5+
// Project configuration.
6+
grunt.initConfig({
7+
pkg: grunt.file.readJSON('package.json'),
8+
meta: {
9+
banner: '/**\n' +
10+
' * <%= pkg.description %>\n' +
11+
' * @version v<%= pkg.version %> - <%= grunt.template.today("yyyy-mm-dd") %>\n' +
12+
' * @link <%= pkg.homepage %>\n' +
13+
' * @author <%= pkg.author %>\n' +
14+
' * @license MIT License, http://www.opensource.org/licenses/MIT\n' +
15+
' */\n'
16+
},
17+
18+
dirs: {
19+
dest: 'dist'
20+
},
21+
concat: {
22+
options: {
23+
banner: '<%= meta.banner %>'
24+
},
25+
dist: {
26+
src: ['src/*.js'],
27+
dest: '<%= dirs.dest %>/<%= pkg.name %>.js'
28+
}
29+
},
30+
uglify: {
31+
options: {
32+
banner: '<%= meta.banner %>',
33+
mangle: false
34+
},
35+
dist: {
36+
src: ['<%= concat.dist.dest %>'],
37+
dest: '<%= dirs.dest %>/<%= pkg.name %>.min.js'
38+
}
39+
},
40+
41+
});
42+
43+
grunt.loadNpmTasks('grunt-contrib-concat');
44+
grunt.loadNpmTasks('grunt-contrib-uglify');
45+
46+
// Build task.
47+
grunt.registerTask('build', ['concat', 'uglify']);
48+
49+
// Default task.
50+
grunt.registerTask('default', ['build']);
51+
};

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Solstice
2+
========
3+
A simple Solr wrapper for AngularJS apps
4+

dist/solstice.js

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* A simple Solr wrapper for AngularJS apps
3+
* @version v0.0.1 - 2013-11-27
4+
* @link https://github.com/front/solstice
5+
* @author Élio Cró <[email protected]>
6+
* @license MIT License, http://www.opensource.org/licenses/MIT
7+
*/
8+
9+
(function (ng) {
10+
'use strict';
11+
12+
var solr = ng.module('solstice', []);
13+
14+
/* Solr search service */
15+
solr.provider('Solstice', function () {
16+
var endpoint = '';
17+
return {
18+
setEndpoint: function (url) {
19+
endpoint = url;
20+
},
21+
$get: function ($http) {
22+
return {
23+
search: function(options) {
24+
var url = endpoint + '/select/';
25+
var defaults = {
26+
wt: 'json',
27+
'json.wrf': 'JSON_CALLBACK'
28+
};
29+
ng.extend(defaults, options);
30+
return $http.jsonp(url, {
31+
params: defaults
32+
});
33+
}
34+
}
35+
}
36+
};
37+
});
38+
39+
/* Solr search directive */
40+
solr.directive('solrSearch', function() {
41+
return {
42+
restrict: 'AE',
43+
transclude: true,
44+
replace: false,
45+
template: '<div ng-transclude></div>',
46+
scope: {
47+
q: '@query',
48+
start: '@start',
49+
rows: '@rows',
50+
sort: '@sort',
51+
fl: '@fields'
52+
},
53+
controller: function ($scope, $rootScope, Solstice) {
54+
var options = {
55+
q: $scope.q || '*:*',
56+
start: $scope.start || 0,
57+
rows: $scope.rows || 10
58+
};
59+
if($scope.sort) {
60+
options.order = $scope.sort;
61+
}
62+
if($scope.fl) {
63+
options.fl = $scope.fl;
64+
}
65+
console.log(options);
66+
67+
Solstice.search(options)
68+
.then(function (data) {
69+
var res = data.data.response;
70+
console.log(res);
71+
var transScope = $scope.$$nextSibling;
72+
transScope.solr = $rootScope.solr || {};
73+
transScope.solr.results = res.docs;
74+
transScope.solr.count = res.numFound;
75+
});
76+
}
77+
};
78+
});
79+
80+
})(window.angular);

dist/solstice.min.js

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "solstice",
3+
"description": "A simple Solr wrapper for AngularJS apps",
4+
"version": "0.0.1",
5+
"author": "Élio Cró <[email protected]>",
6+
"homepage": "https://github.com/front/solstice",
7+
"repository": {
8+
"type": "git",
9+
"url": "git://github.com/front/solstice"
10+
},
11+
"dependencies": {
12+
"grunt-cli": "0.x.x",
13+
"grunt-contrib-concat": "0.3.x",
14+
"grunt-contrib-uglify": "0.2.x"
15+
},
16+
"engine": "node >= 0.10",
17+
"license": "MIT"
18+
}

src/solstice.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
(function (ng) {
3+
'use strict';
4+
5+
var solr = ng.module('solstice', []);
6+
7+
/* Solr search service */
8+
solr.provider('Solstice', function () {
9+
var endpoint = '';
10+
return {
11+
setEndpoint: function (url) {
12+
endpoint = url;
13+
},
14+
$get: function ($http) {
15+
return {
16+
search: function(options) {
17+
var url = endpoint + '/select/';
18+
var defaults = {
19+
wt: 'json',
20+
'json.wrf': 'JSON_CALLBACK'
21+
};
22+
ng.extend(defaults, options);
23+
return $http.jsonp(url, {
24+
params: defaults
25+
});
26+
}
27+
}
28+
}
29+
};
30+
});
31+
32+
/* Solr search directive */
33+
solr.directive('solrSearch', function() {
34+
return {
35+
restrict: 'AE',
36+
transclude: true,
37+
replace: false,
38+
template: '<div ng-transclude></div>',
39+
scope: {
40+
q: '@query',
41+
start: '@start',
42+
rows: '@rows',
43+
sort: '@sort',
44+
fl: '@fields'
45+
},
46+
controller: function ($scope, $rootScope, Solstice) {
47+
var options = {
48+
q: $scope.q || '*:*',
49+
start: $scope.start || 0,
50+
rows: $scope.rows || 10
51+
};
52+
if($scope.sort) {
53+
options.order = $scope.sort;
54+
}
55+
if($scope.fl) {
56+
options.fl = $scope.fl;
57+
}
58+
console.log(options);
59+
60+
Solstice.search(options)
61+
.then(function (data) {
62+
var res = data.data.response;
63+
console.log(res);
64+
var transScope = $scope.$$nextSibling;
65+
transScope.solr = $rootScope.solr || {};
66+
transScope.solr.results = res.docs;
67+
transScope.solr.count = res.numFound;
68+
});
69+
}
70+
};
71+
});
72+
73+
})(window.angular);

0 commit comments

Comments
 (0)