wordjelly-auth 1.2.5 → 1.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/auth/auth_modals_and_navbar.js +1 -0
- data/app/controllers/auth/concerns/token_concern.rb +9 -10
- data/app/controllers/auth/search_controller.rb +25 -23
- data/app/models/auth/concerns/chief_model_concern.rb +4 -15
- data/app/models/auth/concerns/es_concern.rb +137 -0
- data/app/models/auth/concerns/image_load_concern.rb +21 -0
- data/app/models/auth/concerns/search/autocompleted_concern.rb +139 -0
- data/app/models/auth/concerns/shopping/bar_code_concern.rb +29 -0
- data/app/models/auth/concerns/shopping/cart_concern.rb +20 -6
- data/app/models/auth/concerns/shopping/cart_item_concern.rb +54 -82
- data/app/models/auth/concerns/shopping/personality_concern.rb +75 -55
- data/app/models/auth/concerns/shopping/place_concern.rb +1 -3
- data/app/models/auth/concerns/shopping/product_concern.rb +71 -174
- data/app/models/auth/concerns/user_concern.rb +7 -66
- data/app/models/auth/shopping/bar_code.rb +71 -0
- data/app/models/auth/shopping/personality.rb +9 -0
- data/app/models/auth/work/bullet.rb +3 -1
- data/app/models/auth/work/communication.rb +3 -1
- data/app/models/auth/work/instruction.rb +2 -1
- data/app/models/auth/work/link.rb +3 -1
- data/app/views/auth/search/_search_bar.html.erb +12 -7
- data/app/views/auth/search/_search_result.html.erb +21 -7
- data/app/views/auth/search/authenticated_user_search.js.erb +8 -15
- data/app/views/auth/search/authenticated_user_search.json +1 -1
- data/app/views/layouts/auth/application.html.erb +1 -1
- data/app/views/layouts/auth/navbar/_navbar.html.erb +5 -5
- data/config/initializers/omniauth.rb +0 -3
- data/lib/assets/javascripts/bar_code.js +97 -0
- data/lib/assets/javascripts/search.js +32 -12
- data/lib/assets/javascripts/spinner.js +5 -3
- data/lib/auth/engine.rb +40 -0
- data/lib/auth/rails/routes.rb +2 -0
- data/lib/auth/search/main.rb +28 -13
- data/lib/auth/version.rb +1 -1
- data/lib/wordjelly-auth.rb +2 -1
- data/spec/dummy/app/assets/time_hashes.json +1 -1
- data/spec/dummy/app/models/shopping/cart.rb +1 -1
- data/spec/dummy/app/models/shopping/cart_item.rb +11 -1
- data/spec/dummy/app/models/shopping/personality.rb +1 -0
- data/spec/dummy/app/models/shopping/place.rb +1 -0
- data/spec/dummy/app/models/shopping/product.rb +8 -10
- data/spec/dummy/app/models/user.rb +8 -17
- data/spec/dummy/config/initializers/preinitializer.rb +0 -1
- data/spec/factories/client_factory.rb +2 -0
- data/spec/requests/search/search_request_spec.rb +50 -50
- data/spec/support/sign_in_support.rb +40 -0
- metadata +35 -3
- data/app/views/auth/search/_search_results.html.erb +0 -4
@@ -1,6 +1,8 @@
|
|
1
1
|
class Auth::Work::Bullet
|
2
2
|
include Mongoid::Document
|
3
|
-
include
|
3
|
+
include Mongoid::Timestamps
|
4
|
+
include Auth::Concerns::ImageLoadConcern
|
5
|
+
|
4
6
|
embedded_in :instruction, :class_name => "Auth::Work::Instruction"
|
5
7
|
field :title, type: String
|
6
8
|
field :description, type: String
|
@@ -1,7 +1,8 @@
|
|
1
1
|
class Auth::Work::Instruction
|
2
2
|
include Mongoid::Document
|
3
|
-
include
|
3
|
+
include Mongoid::Timestamps
|
4
4
|
include Auth::Concerns::Work::CommunicationFieldsConcern
|
5
|
+
include Auth::Concerns::ImageLoadConcern
|
5
6
|
|
6
7
|
attr_accessor :product_id
|
7
8
|
attr_accessor :cart_item_id
|
@@ -1,5 +1,7 @@
|
|
1
1
|
class Auth::Work::Link
|
2
|
-
include
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Timestamps
|
4
|
+
include Auth::Concerns::ImageLoadConcern
|
3
5
|
embedded_in :instruction, :class_name => "Auth::Work::Instruction"
|
4
6
|
field :url, type: String
|
5
7
|
field :url_text, type: String
|
@@ -1,8 +1,13 @@
|
|
1
|
-
<
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
</
|
1
|
+
<div class="row" style="margin-bottom:1.4rem;">
|
2
|
+
<ul class="collection with-header" id="search_collection">
|
3
|
+
<li class="collection-header" id="search_title">
|
4
|
+
<h4>
|
5
|
+
<div class="input-field">
|
6
|
+
<input id="search" type="search" placeholder="Search" required>
|
7
|
+
<i class="material-icons">close</i>
|
8
|
+
</div>
|
9
|
+
</h4>
|
10
|
+
</li>
|
11
|
+
</ul>
|
12
|
+
</div>
|
8
13
|
|
@@ -1,7 +1,21 @@
|
|
1
|
-
<
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
<li class="collection-item search_result teal-text">
|
2
|
+
<%= link_to result.primary_link.html_safe do %>
|
3
|
+
<h5><%= result.tags.join(" ") %></h5>
|
4
|
+
<% end %>
|
5
|
+
<h6 class="grey-text"><%= result.autocomplete_description %></h6>
|
6
|
+
<% result.secondary_links.keys.each do |sl| %>
|
7
|
+
<% if result.secondary_links[sl][:partial] %>
|
8
|
+
<% locals = {} %>
|
9
|
+
<% other_locals = result.secondary_links[sl] || {} %>
|
10
|
+
<% locals = locals.merge(other_locals) %>
|
11
|
+
<% if result.secondary_links[sl][:instance_name_in_locals] %>
|
12
|
+
<% locals = locals.merge(result.secondary_links[sl][:instance_name_in_locals].to_sym => result) %>
|
13
|
+
<% end %>
|
14
|
+
<%= render :partial => result.secondary_links[sl][:partial], locals: locals %>
|
15
|
+
<% else %>
|
16
|
+
<%= link_to result.secondary_links[sl][:url].html_safe, :data => result.secondary_links[sl][:data] || {} do %>
|
17
|
+
<span class="m-20-right"><%= sl %></span>
|
18
|
+
<% end %>
|
19
|
+
<% end %>
|
20
|
+
<% end %>
|
21
|
+
</li>
|
@@ -1,19 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
search_path = Auth::OmniAuth::Path.model_to_path(result.class) + "/_search_result.html.erb"
|
4
|
-
if lookup_context.find_all(search_path).any?
|
5
|
-
puts "found in lookup context."
|
6
|
-
_partial = search_path
|
7
|
-
end
|
8
|
-
_partial = _partial.gsub(/\/_search/,"/search")
|
9
|
-
puts "partial is: #{_partial}"
|
10
|
-
%>
|
1
|
+
$(".search_result").remove();
|
2
|
+
<% @search_results.each do |result| %>
|
11
3
|
|
12
|
-
|
13
|
-
|
4
|
+
<% if result %>
|
5
|
+
|
6
|
+
$("#search_collection").append("<%= escape_javascript(render :partial => 'auth/search/search_result', locals: {result: result}) %>");
|
7
|
+
<% end %>
|
14
8
|
|
15
|
-
<%
|
9
|
+
<% end %>
|
16
10
|
|
17
|
-
|
11
|
+
highlight();
|
18
12
|
|
19
|
-
%>
|
@@ -8,13 +8,10 @@
|
|
8
8
|
<%= content_for(:navbar_left) %>
|
9
9
|
<% else %>
|
10
10
|
<a href="/" class="brand-logo"><%= Auth.configuration.brand_name %></a>
|
11
|
-
|
11
|
+
|
12
12
|
<% end %>
|
13
13
|
</div>
|
14
|
-
|
15
|
-
<%= render :partial => 'auth/search/search_bar.html.erb' %>
|
16
|
-
</div>
|
17
|
-
|
14
|
+
|
18
15
|
<a href="#" data-target="mobile-demo" class="sidenav-trigger"><i class="material-icons">menu</i></a>
|
19
16
|
<ul class="right hide-on-med-and-down">
|
20
17
|
<% if content_for?(:navbar_right) %>
|
@@ -41,6 +38,9 @@
|
|
41
38
|
<% else %>
|
42
39
|
<div id="proxy_user"></div>
|
43
40
|
<% end %>
|
41
|
+
<div class="progress" id="progress" style="margin-top:5px !important; visibility:hidden;">
|
42
|
+
<div class="indeterminate" style="width: 100%"></div>
|
43
|
+
</div>
|
44
44
|
</div>
|
45
45
|
|
46
46
|
|
@@ -412,10 +412,7 @@ module SimpleTokenAuthentication
|
|
412
412
|
|
413
413
|
## CHANGE THE AUTHENTICATION TOKEN WHENEVER THE USER IS SAVED. IT DOESNT MATTER IF THERE IS AN EXISTING AUTHENTICATION TOKEN OR NOT.
|
414
414
|
def ensure_authentication_token
|
415
|
-
#if authentication_token.blank?
|
416
|
-
#puts "------------------CAME TO ENSURE AUTHENTICATION TOKEN--------------------"
|
417
415
|
regenerate_token
|
418
|
-
#end
|
419
416
|
end
|
420
417
|
end
|
421
418
|
|
@@ -0,0 +1,97 @@
|
|
1
|
+
var _scannerIsRunning = false;
|
2
|
+
|
3
|
+
function startScanner() {
|
4
|
+
Quagga.init({
|
5
|
+
inputStream: {
|
6
|
+
name: "Live",
|
7
|
+
type: "LiveStream",
|
8
|
+
target: document.querySelector('#scanner-container'),
|
9
|
+
constraints: {
|
10
|
+
width: 480,
|
11
|
+
height: 320,
|
12
|
+
facingMode: "environment"
|
13
|
+
},
|
14
|
+
},
|
15
|
+
decoder: {
|
16
|
+
readers: [
|
17
|
+
"code_128_reader",
|
18
|
+
"ean_reader",
|
19
|
+
"ean_8_reader",
|
20
|
+
"code_39_reader",
|
21
|
+
"code_39_vin_reader",
|
22
|
+
"codabar_reader",
|
23
|
+
"upc_reader",
|
24
|
+
"upc_e_reader",
|
25
|
+
"i2of5_reader"
|
26
|
+
],
|
27
|
+
debug: {
|
28
|
+
showCanvas: true,
|
29
|
+
showPatches: true,
|
30
|
+
showFoundPatches: true,
|
31
|
+
showSkeleton: true,
|
32
|
+
showLabels: true,
|
33
|
+
showPatchLabels: true,
|
34
|
+
showRemainingPatchLabels: true,
|
35
|
+
boxFromPatches: {
|
36
|
+
showTransformed: true,
|
37
|
+
showTransformedBox: true,
|
38
|
+
showBB: true
|
39
|
+
}
|
40
|
+
}
|
41
|
+
},
|
42
|
+
|
43
|
+
}, function (err) {
|
44
|
+
if (err) {
|
45
|
+
console.log(err);
|
46
|
+
return
|
47
|
+
}
|
48
|
+
|
49
|
+
console.log("Initialization finished. Ready to start");
|
50
|
+
Quagga.start();
|
51
|
+
|
52
|
+
// Set flag to is running
|
53
|
+
_scannerIsRunning = true;
|
54
|
+
});
|
55
|
+
|
56
|
+
Quagga.onProcessed(function (result) {
|
57
|
+
var drawingCtx = Quagga.canvas.ctx.overlay,
|
58
|
+
drawingCanvas = Quagga.canvas.dom.overlay;
|
59
|
+
|
60
|
+
if (result) {
|
61
|
+
if (result.boxes) {
|
62
|
+
drawingCtx.clearRect(0, 0, parseInt(drawingCanvas.getAttribute("width")), parseInt(drawingCanvas.getAttribute("height")));
|
63
|
+
result.boxes.filter(function (box) {
|
64
|
+
return box !== result.box;
|
65
|
+
}).forEach(function (box) {
|
66
|
+
Quagga.ImageDebug.drawPath(box, { x: 0, y: 1 }, drawingCtx, { color: "green", lineWidth: 2 });
|
67
|
+
});
|
68
|
+
}
|
69
|
+
|
70
|
+
if (result.box) {
|
71
|
+
Quagga.ImageDebug.drawPath(result.box, { x: 0, y: 1 }, drawingCtx, { color: "#00F", lineWidth: 2 });
|
72
|
+
}
|
73
|
+
|
74
|
+
if (result.codeResult && result.codeResult.code) {
|
75
|
+
Quagga.ImageDebug.drawPath(result.line, { x: 'x', y: 'y' }, drawingCtx, { color: 'red', lineWidth: 3 });
|
76
|
+
}
|
77
|
+
}
|
78
|
+
});
|
79
|
+
|
80
|
+
Quagga.onDetected(function (result) {
|
81
|
+
console.log("Barcode detected and processed : [" + result.codeResult.code + "]", result);
|
82
|
+
});
|
83
|
+
}
|
84
|
+
|
85
|
+
// Start/stop scanner
|
86
|
+
document.getElementById("btn").addEventListener("click", function () {
|
87
|
+
if (_scannerIsRunning) {
|
88
|
+
Quagga.stop();
|
89
|
+
} else {
|
90
|
+
if(typeof Quagga === 'undefined'){
|
91
|
+
console.log("Please add the Quagga js library to use the barcode api");
|
92
|
+
}
|
93
|
+
else{
|
94
|
+
startScanner();
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}, false);
|
@@ -6,7 +6,7 @@ function navbar_search(query_string){
|
|
6
6
|
{query_string: query_string}
|
7
7
|
},
|
8
8
|
beforeSend: function(){
|
9
|
-
clear_search_results();
|
9
|
+
//clear_search_results();
|
10
10
|
},
|
11
11
|
success : function( data ) {},
|
12
12
|
dataType : "script"
|
@@ -15,20 +15,40 @@ function navbar_search(query_string){
|
|
15
15
|
|
16
16
|
|
17
17
|
$(document).on('keyup', '#search',function(event){
|
18
|
-
|
19
|
-
|
18
|
+
navbar_search($(this).val());
|
19
|
+
});
|
20
|
+
|
21
|
+
/* Clear the search result if focus out from the title. */
|
22
|
+
$(document).on('click','body',function(event){
|
23
|
+
if(event.target.id === 'search'){
|
24
|
+
|
25
|
+
}
|
26
|
+
else if(event.target.id === 'search_title'){
|
27
|
+
|
20
28
|
}
|
21
29
|
else{
|
22
|
-
|
30
|
+
$(".search_result").remove();
|
23
31
|
}
|
24
32
|
});
|
25
33
|
|
26
|
-
|
27
|
-
|
34
|
+
/* Highlight Autocomplete Matching Text */
|
35
|
+
var highlight = function() {
|
36
|
+
|
37
|
+
var strings = $("#search").val().split(/\s+/);
|
38
|
+
|
39
|
+
$.each(strings,function(index,string){
|
40
|
+
|
41
|
+
$(".search_result").each(function () {
|
42
|
+
|
43
|
+
var matchStart = $(this).html().toLowerCase().indexOf("" + string.toLowerCase() + "");
|
44
|
+
|
45
|
+
var matchEnd = matchStart + string.length - 1;
|
46
|
+
|
47
|
+
var beforeMatch = $(this).html().slice(0, matchStart);
|
48
|
+
var matchText = $(this).html().slice(matchStart, matchEnd + 1);
|
49
|
+
var afterMatch = $(this).html().slice(matchEnd + 1);
|
50
|
+
$(this).html(beforeMatch + "<span class='yellow'>" + matchText + "</span>" + afterMatch);
|
51
|
+
});
|
52
|
+
});
|
53
|
+
|
28
54
|
}
|
29
|
-
|
30
|
-
/***
|
31
|
-
when search is empty, clear the search results.
|
32
|
-
when new search key is pressed, clear the older search results.
|
33
|
-
when focus is not on the search bar, then clear the search results.
|
34
|
-
****/
|
@@ -1,16 +1,18 @@
|
|
1
1
|
$(document).bind("ajaxSend", function(){
|
2
2
|
$(".modal:visible").find(".error_notification").hide();
|
3
|
-
$("#
|
3
|
+
$("#progress").css('visibility','visible');
|
4
4
|
}).bind("ajaxStop", function(){
|
5
|
-
|
5
|
+
|
6
6
|
}).bind("ajaxComplete",function(event,request,settings){
|
7
|
+
// do this with a small timeout.
|
8
|
+
setTimeout(function(){ $("#progress").css('visibility','hidden'); }, 500);
|
7
9
|
|
8
10
|
//$("body").append("<div id='dog'>dogged</div>");
|
9
11
|
}).bind("ajaxError",function(event,request,settings){
|
10
12
|
//console.log(event);
|
11
13
|
//console.log(request);
|
12
14
|
//console.log(settings);
|
13
|
-
$("#
|
15
|
+
setTimeout(function(){ $("#progress").css('visibility','hidden'); }, 500);
|
14
16
|
var request_url = settings.url;
|
15
17
|
var request_method = settings.type;
|
16
18
|
var status = request.status;
|
data/lib/auth/engine.rb
CHANGED
@@ -18,6 +18,7 @@ module Auth
|
|
18
18
|
g.test_framework :rspec
|
19
19
|
end
|
20
20
|
|
21
|
+
|
21
22
|
|
22
23
|
end
|
23
24
|
|
@@ -238,6 +239,28 @@ module Auth
|
|
238
239
|
attr_accessor :two_factor_otp_transactional_sms_template_sender_id
|
239
240
|
attr_accessor :two_factor_otp_transactional_sms_template_name
|
240
241
|
|
242
|
+
|
243
|
+
###############################################################
|
244
|
+
##
|
245
|
+
##
|
246
|
+
## HASHIDS SALT.
|
247
|
+
## THIS IS USED IN PERSONALITY AND PLACE.
|
248
|
+
##
|
249
|
+
###############################################################
|
250
|
+
|
251
|
+
attr_accessor :hashids_salt
|
252
|
+
attr_accessor :hashids_alphabet
|
253
|
+
|
254
|
+
|
255
|
+
###############################################################
|
256
|
+
##
|
257
|
+
##
|
258
|
+
## FOR BARCODE.
|
259
|
+
##
|
260
|
+
##
|
261
|
+
###############################################################
|
262
|
+
attr_accessor :enable_barcode_api
|
263
|
+
|
241
264
|
def initialize
|
242
265
|
|
243
266
|
|
@@ -500,6 +523,23 @@ module Auth
|
|
500
523
|
@two_factor_otp_transactional_sms_template_name = "test2"
|
501
524
|
@two_factor_otp_transactional_sms_template_sender_id = "PATHOF"
|
502
525
|
|
526
|
+
|
527
|
+
########################################################
|
528
|
+
##
|
529
|
+
##
|
530
|
+
########################################################
|
531
|
+
@hashids_salt = "i am a salt"
|
532
|
+
@hashids_alphabet = "abcdefghijklmnopqrstuvwxyz123456789"
|
533
|
+
|
534
|
+
|
535
|
+
########################################################
|
536
|
+
##
|
537
|
+
## barcode : api enabled by default.
|
538
|
+
##
|
539
|
+
########################################################
|
540
|
+
@enable_barcode_api = true
|
541
|
+
|
542
|
+
|
503
543
|
end
|
504
544
|
end
|
505
545
|
|
data/lib/auth/rails/routes.rb
CHANGED
@@ -61,6 +61,8 @@ module ActionDispatch::Routing
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
resources :bar_codes, :controller => "auth/shopping/bar_codes"
|
65
|
+
|
64
66
|
## this controller may need to be changed, actually will have to be changed for every single thing.
|
65
67
|
resources :assemblies, :controller => Auth.configuration.assembly_controller
|
66
68
|
|
data/lib/auth/search/main.rb
CHANGED
@@ -6,9 +6,14 @@ module Auth
|
|
6
6
|
## the query_string is left blank, and you should merge this in through any def that wants to perform an ngram query.
|
7
7
|
## param[Symbol] search_on_field : the field on which we are going to do the n_Gram query. Most of the times this should default to _all_fields
|
8
8
|
## @return[Hash]
|
9
|
-
def self.es_six_base_ngram_query(search_on_field)
|
9
|
+
def self.es_six_base_ngram_query(search_on_field,highlight_fields=nil)
|
10
10
|
|
11
|
-
search_on_field ||= :
|
11
|
+
search_on_field ||= :tags
|
12
|
+
highlight_fields ||= {
|
13
|
+
fields: {
|
14
|
+
model_fields: {}
|
15
|
+
}
|
16
|
+
}
|
12
17
|
|
13
18
|
qc = {
|
14
19
|
body: {
|
@@ -25,7 +30,8 @@ module Auth
|
|
25
30
|
}
|
26
31
|
}
|
27
32
|
}
|
28
|
-
}
|
33
|
+
},
|
34
|
+
highlight: highlight_fields
|
29
35
|
}
|
30
36
|
}
|
31
37
|
|
@@ -51,7 +57,7 @@ module Auth
|
|
51
57
|
## @return[Hash] : returns a query clause(hash)
|
52
58
|
def self.es_six_finalize_search_query_clause(args)
|
53
59
|
|
54
|
-
search_on_field = args[:search_field] || :
|
60
|
+
search_on_field = args[:search_field] || :tags
|
55
61
|
|
56
62
|
args = args.deep_symbolize_keys
|
57
63
|
|
@@ -59,12 +65,13 @@ module Auth
|
|
59
65
|
|
60
66
|
query = es_six_base_ngram_query(search_on_field)
|
61
67
|
|
62
|
-
query[:size] = args[:size] ||
|
68
|
+
query[:size] = args[:size] || 5
|
63
69
|
|
64
70
|
query[:body][:query][:bool][:must][:match][search_on_field][:query] = args[:query_string]
|
65
71
|
|
66
|
-
|
72
|
+
|
67
73
|
if args[:resource_id]
|
74
|
+
## if a resource id is provided, show all public records + those records which have this resource id as the owner.
|
68
75
|
query[:body][:query][:bool][:filter] = {
|
69
76
|
|
70
77
|
bool: {
|
@@ -95,12 +102,21 @@ module Auth
|
|
95
102
|
|
96
103
|
}
|
97
104
|
else
|
98
|
-
## if
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
105
|
+
## if its not provided, and there is no admin in the args, then only show the public records.
|
106
|
+
unless args[:resource_is_admin]
|
107
|
+
query[:body][:query][:bool][:filter] = {
|
108
|
+
bool:
|
109
|
+
{
|
110
|
+
must: [
|
111
|
+
{
|
112
|
+
term: {
|
113
|
+
public: "yes"
|
114
|
+
}
|
115
|
+
}
|
116
|
+
]
|
117
|
+
}
|
118
|
+
}
|
119
|
+
end
|
104
120
|
end
|
105
121
|
|
106
122
|
query
|
@@ -112,7 +128,6 @@ module Auth
|
|
112
128
|
## @return[Array] response: an array of mongoid search result objects.
|
113
129
|
def self.search(args)
|
114
130
|
query = es_six_finalize_search_query_clause(args)
|
115
|
-
puts "query finalized as:"
|
116
131
|
puts JSON.pretty_generate(query)
|
117
132
|
Mongoid::Elasticsearch.search(query,{:wrapper => :load}).results
|
118
133
|
end
|