angular-smart-search 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/app/assets/javascripts/angular-smart-search.js +219 -0
- data/lib/angular-smart-search.rb +4 -0
- data/lib/angular-smart-search/version.rb +3 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 98c570f756f33bc7318eddd400bf9ca156fa8699
|
4
|
+
data.tar.gz: c091854d1356759f86c45ae54d1c44665ba730d7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8b5b605c23e57e67143d53b8426bcbb85685760c7777b9ba86e5f74356df8dc572322a69ddb20a0c90ff4baca34466feb3b918ceed0c064c56e576cfa895c5e6
|
7
|
+
data.tar.gz: eea4b5b51d135db8e1216200a74ee49e50a8b58b230fdf8c5027b47ebbc87889febf59845b539e7ccfa911488c15f6c54c0fa8ec1b9a0c4d14d5ffe05041b49d
|
@@ -0,0 +1,219 @@
|
|
1
|
+
// author: Samuel Mueller
|
2
|
+
// version: 0.0.1
|
3
|
+
// license: MIT
|
4
|
+
// homepage: http://github.com/ssmm/angular-smart-search
|
5
|
+
(function() {
|
6
|
+
var padding, template;
|
7
|
+
|
8
|
+
padding = 30;
|
9
|
+
|
10
|
+
angular.module("angular-smart-search", []);
|
11
|
+
|
12
|
+
angular.module("angular-smart-search").directive("smartSearch", [
|
13
|
+
"$http", "searchQueryFactory", function($http, searchQueryFactory) {
|
14
|
+
var QueryState;
|
15
|
+
|
16
|
+
QueryState = function() {
|
17
|
+
this.state = 'initial';
|
18
|
+
this.query = void 0;
|
19
|
+
this.is = function(state) {
|
20
|
+
return this.state === state;
|
21
|
+
};
|
22
|
+
this.setTo = function(state) {
|
23
|
+
return this.state = state;
|
24
|
+
};
|
25
|
+
};
|
26
|
+
return {
|
27
|
+
restrict: "A",
|
28
|
+
scope: true,
|
29
|
+
replace: true,
|
30
|
+
template: template,
|
31
|
+
compile: function(element, attributes, transclude) {
|
32
|
+
var id_field;
|
33
|
+
|
34
|
+
id_field = angular.element("<input ng-model='result.id' type='text' style='width: 30px; text-align: center; display: none;' disabled='disabled'>");
|
35
|
+
id_field.attr("id", attributes.id);
|
36
|
+
id_field.attr("name", attributes.name);
|
37
|
+
element.append(id_field);
|
38
|
+
return {
|
39
|
+
post: function($scope, $element, $attributes) {
|
40
|
+
var allowedFormats, input, outerQueryTimeout, overlay, queryState, service;
|
41
|
+
|
42
|
+
allowedFormats = $attributes.formats.split(" ");
|
43
|
+
service = $attributes.service;
|
44
|
+
input = $element.find("[queryfield]");
|
45
|
+
overlay = $element.children("[overlay]");
|
46
|
+
$scope.show = function() {
|
47
|
+
var position;
|
48
|
+
|
49
|
+
position = input.position();
|
50
|
+
overlay.css("top", position.top - padding);
|
51
|
+
overlay.css("left", position.left - padding);
|
52
|
+
return overlay.show("fade");
|
53
|
+
};
|
54
|
+
$scope.hide = function() {
|
55
|
+
return overlay.hide("fade");
|
56
|
+
};
|
57
|
+
$scope.search = function(query) {
|
58
|
+
return $http.get("" + service + ".json?fulltext=" + query).success(function(data) {
|
59
|
+
$scope.quickQuery = "";
|
60
|
+
return $scope.resultList = data;
|
61
|
+
}).error(function() {});
|
62
|
+
};
|
63
|
+
$scope.pick = function(item) {
|
64
|
+
queryState.setTo("successful");
|
65
|
+
$scope.result = item;
|
66
|
+
return $scope.hide();
|
67
|
+
};
|
68
|
+
$scope.hover = function(item) {
|
69
|
+
return $scope.currentItem = item;
|
70
|
+
};
|
71
|
+
outerQueryTimeout = null;
|
72
|
+
queryState = new QueryState();
|
73
|
+
$scope.queryState = queryState;
|
74
|
+
return $scope.outerQueryChanged = function(query) {
|
75
|
+
window.clearTimeout(outerQueryTimeout);
|
76
|
+
query = searchQueryFactory(query, allowedFormats);
|
77
|
+
if (query) {
|
78
|
+
queryState.setTo("changed");
|
79
|
+
queryState.query = query;
|
80
|
+
return outerQueryTimeout = window.setTimeout(function() {
|
81
|
+
queryState.setTo("pending");
|
82
|
+
$http.get("" + service + ".json?" + query.format.name + "=" + query.query).success(function(data) {
|
83
|
+
if (data[0] && data[0].id) {
|
84
|
+
queryState.setTo("successful");
|
85
|
+
return $scope.result = data[0];
|
86
|
+
} else {
|
87
|
+
return queryState.setTo("unsuccessful");
|
88
|
+
}
|
89
|
+
}).error(function() {
|
90
|
+
return queryState.setTo("error");
|
91
|
+
});
|
92
|
+
return $scope.$apply();
|
93
|
+
}, 1200);
|
94
|
+
} else {
|
95
|
+
return queryState.setTo("invalid-format");
|
96
|
+
}
|
97
|
+
};
|
98
|
+
}
|
99
|
+
};
|
100
|
+
}
|
101
|
+
};
|
102
|
+
}
|
103
|
+
]);
|
104
|
+
|
105
|
+
template = '\
|
106
|
+
<div>\
|
107
|
+
<!-- input section you see initially -->\
|
108
|
+
<div class="input-prepend input-append">\
|
109
|
+
<!-- gray display section -->\
|
110
|
+
<span class="add-on" style="min-width: 200px;">\
|
111
|
+
<!-- result if found -->\
|
112
|
+
<span ng-show="queryState.is(\'successful\')">\
|
113
|
+
<i class="ubs-icon-small-suitability"></i>\
|
114
|
+
{{result.displayText}}\
|
115
|
+
</span>\
|
116
|
+
<!-- query states -->\
|
117
|
+
<span ng-show="queryState.is(\'changed\')">\
|
118
|
+
<em>{{queryState.query.format.name}} detected</em>\
|
119
|
+
</span>\
|
120
|
+
<span ng-show="queryState.is(\'pending\')">\
|
121
|
+
<em>searching...</em>\
|
122
|
+
</span>\
|
123
|
+
<span ng-show="queryState.is(\'unsuccessful\')">\
|
124
|
+
<em>Not found</em>\
|
125
|
+
</span>\
|
126
|
+
<span ng-show="queryState.is(\'invalid-format\')">\
|
127
|
+
<em>Invalid format</em>\
|
128
|
+
</span>\
|
129
|
+
<span ng-show="queryState.is(\'error\')">\
|
130
|
+
<em>Error</em>\
|
131
|
+
</span>\
|
132
|
+
</span>\
|
133
|
+
<!-- quick query field -->\
|
134
|
+
<input ng-change="outerQueryChanged(quickQuery)" ng-model="quickQuery" queryfield="" style="width: 100px;" type="text">\
|
135
|
+
<!-- button that triggers detail search overlay -->\
|
136
|
+
<button class="btn btn-ubs-dark" ng-click="show()">\
|
137
|
+
<i class="ubs-icon-small-search ubs-icon-small-white"></i>\
|
138
|
+
</button>\
|
139
|
+
</div>\
|
140
|
+
<!-- detail search overlay, initially hidden -->\
|
141
|
+
<div class="uw-overlay shadow" ng-mouseleave="hide()" overlay="">\
|
142
|
+
<div class="row-fluid">\
|
143
|
+
<div class="span12">\
|
144
|
+
<div class="input-append">\
|
145
|
+
<input detail-queryfield="" ng-model="detailQuery" type="text">\
|
146
|
+
<button class="btn btn-ubs-dark" ng-click="search(detailQuery)">\
|
147
|
+
<i class="ubs-icon-small-search ubs-icon-small-white"></i>\
|
148
|
+
</button>\
|
149
|
+
</div>\
|
150
|
+
</div>\
|
151
|
+
</div>\
|
152
|
+
<div class="horizontal-space"></div>\
|
153
|
+
<div class="row-fluid">\
|
154
|
+
<div class="span12">\
|
155
|
+
<table at-table="" class="table table-bordered table-hover" fill-last-page="" pagination="wildPagination">\
|
156
|
+
<thead></thead>\
|
157
|
+
<tbody>\
|
158
|
+
<tr ng-mouseover="hover(item)">\
|
159
|
+
<td at-implicit="" attribute="id" class="sortable 50px"></td>\
|
160
|
+
<td at-implicit="" attribute="displayText" class="sortable 280px" title="Result"></td>\
|
161
|
+
<td class="50px" title="-">\
|
162
|
+
<button class="btn btn-mini btn-ubs-blue" ng-click="pick(item)">pick</button>\
|
163
|
+
</td>\
|
164
|
+
</tr>\
|
165
|
+
</tbody>\
|
166
|
+
</table>\
|
167
|
+
<at-pagination instance="wildPagination" items-per-page="3" list="resultList"></at-pagination>\
|
168
|
+
</div>\
|
169
|
+
</div>\
|
170
|
+
</div>\
|
171
|
+
</div>\
|
172
|
+
';
|
173
|
+
|
174
|
+
angular.module("angular-smart-search").provider("searchQueryFactory", [
|
175
|
+
function() {
|
176
|
+
var Query, detectFormat, formats;
|
177
|
+
|
178
|
+
Query = function(query, format) {
|
179
|
+
this.format = format;
|
180
|
+
this.query = query;
|
181
|
+
};
|
182
|
+
formats = {};
|
183
|
+
detectFormat = function(query, allowedFormats) {
|
184
|
+
var name, _i, _len;
|
185
|
+
|
186
|
+
for (_i = 0, _len = allowedFormats.length; _i < _len; _i++) {
|
187
|
+
name = allowedFormats[_i];
|
188
|
+
if (formats[name].pattern.exec(query)) {
|
189
|
+
return formats[name];
|
190
|
+
}
|
191
|
+
}
|
192
|
+
};
|
193
|
+
this.registerFormats = function(formats) {
|
194
|
+
var format, _i, _len, _results;
|
195
|
+
|
196
|
+
_results = [];
|
197
|
+
for (_i = 0, _len = formats.length; _i < _len; _i++) {
|
198
|
+
format = formats[_i];
|
199
|
+
_results.push(this.registerFormat(format));
|
200
|
+
}
|
201
|
+
return _results;
|
202
|
+
};
|
203
|
+
this.registerFormat = function(format) {
|
204
|
+
return formats[format.name] = format;
|
205
|
+
};
|
206
|
+
return this.$get = function() {
|
207
|
+
return function(query, allowedFormats) {
|
208
|
+
var format;
|
209
|
+
|
210
|
+
format = detectFormat(query, allowedFormats);
|
211
|
+
if (format) {
|
212
|
+
return new Query(query, format);
|
213
|
+
}
|
214
|
+
};
|
215
|
+
};
|
216
|
+
}
|
217
|
+
]);
|
218
|
+
|
219
|
+
}).call(this);
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: angular-smart-search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Samuel Mueller
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: angular smart search
|
42
|
+
email:
|
43
|
+
- mueller.samu@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/angular-smart-search/version.rb
|
49
|
+
- lib/angular-smart-search.rb
|
50
|
+
- app/assets/javascripts/angular-smart-search.js
|
51
|
+
homepage: https://github.com/ssmm/angular-smart-search
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.0.3
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: angular smart search
|
75
|
+
test_files: []
|
76
|
+
has_rdoc:
|