tawork 0.0.22 → 0.0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/app/controllers/search_controller.rb +21 -21
- data/app/models/attachment.rb +12 -1
- data/app/models/page.rb +4 -2
- data/app/views/wiki/pages/_display.html.haml +1 -1
- data/lib/searcher.rb +26 -6
- data/lib/tawork/version.rb +1 -1
- data/vendor/assets/javascripts/tinymce/mention/plugin.js +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzE1NTgxMWQxYjI4MTJkMGJlYjEwM2U4YTY2ZWQ3OGVkMDE0NWRiNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTcwMzg0NzBkOTQ0NWRkNDNmMDcwM2Q1ZTVhZTlkMGM3ZGRjNmE4YQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MGExNzkxNWY4ODExNTJkNGZmMWVkNDAyM2QxNTkxMTM3NjBlMjk1ZWVmZDc2
|
10
|
+
MDllZTBhY2ZjZTc0OWUyYTY0ZTk4NzVmNmJhMDgwOWUzZjFiMjkzNTMxMjdl
|
11
|
+
NThlMmZlNDU4NTQ2ZjAwODU4YTk5NmQ0NjQ5NTUyYmNiNTU4MDA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NDkzMzZiOWI4NDZkYzdjYzVjMjM0MDNiMzhkMzUxMWVmNzBlYjIxMDdhMTM0
|
14
|
+
NzM5N2FhYTYzOTZlMGM5NDViOGJkMzI4N2JmZmYyYjRhYWFkMmE1OWVlOTFi
|
15
|
+
NDkxY2QyZmVmNzBmNWUwNjNhYWFjMDZiOTI0YTljYWM1ZmZlOGY=
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class SearchController < ApplicationController
|
2
2
|
def index
|
3
3
|
q = params[:term]
|
4
|
-
@searcher = Searcher.search q
|
4
|
+
@searcher = Searcher.search query: q
|
5
5
|
|
6
6
|
render layout: false
|
7
7
|
end
|
@@ -9,44 +9,44 @@ class SearchController < ApplicationController
|
|
9
9
|
def mentions
|
10
10
|
q = params[:query]
|
11
11
|
delimiter = params[:delimiter]
|
12
|
-
search_group = "spaces,pages,projects,bugs,tasks,stories,users,attachments"
|
13
12
|
|
13
|
+
search_group = "pages,attachments"
|
14
14
|
if delimiter == "!"
|
15
15
|
search_group = "attachments"
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
boolean do
|
21
|
-
should { string "title:#{q}*" }
|
22
|
-
should { string "filename:#{q}*" }
|
23
|
-
should { string "name:#{q}*" }
|
24
|
-
should { string "email:#{q}*" }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
18
|
+
q = ["title:#{q}*", "filename:#{q}*", "name:#{q}*", "email:#{q}*"].join(" OR ")
|
19
|
+
@searcher = Searcher.search q: q, search_group: search_group
|
28
20
|
|
29
|
-
|
21
|
+
results = []
|
22
|
+
@searcher.results_with_hits{|result, hit| results << process_result(result, hit) }
|
23
|
+
render json: results
|
30
24
|
end
|
31
25
|
|
32
26
|
protected
|
33
27
|
|
34
28
|
#TODO: dirty. fix.
|
35
|
-
def process_result(result)
|
29
|
+
def process_result(result, hit)
|
36
30
|
json = {}
|
37
|
-
json[:type] = result.
|
38
|
-
if ["space", "page"].include?(
|
31
|
+
json[:type] = result.class.to_s.underscore
|
32
|
+
if ["space", "page"].include?(hit._type)
|
39
33
|
json[:name] = result.title
|
40
34
|
json[:url] = wiki_page_url(result.id)
|
41
|
-
json[:space] = result.
|
42
|
-
|
35
|
+
json[:space] = result.root.title
|
36
|
+
if json[:type] == "space"
|
37
|
+
json[:icon] = "fa-bullseye"
|
38
|
+
else
|
39
|
+
json[:icon] = "fa-file"
|
40
|
+
end
|
41
|
+
elsif ["project", "bug", "task", "story"].include?(hit._type)
|
43
42
|
json[:name] = result.title
|
44
43
|
json[:url] = ticket_url(result.id)
|
45
|
-
json[:project] = result.
|
46
|
-
elsif
|
44
|
+
json[:project] = result.root.title
|
45
|
+
elsif hit._type == "attachment"
|
47
46
|
json[:name] = result.filename
|
48
47
|
json[:url] = attachment_url(result.id)
|
49
|
-
|
48
|
+
json[:icon] = "fa-paperclip"
|
49
|
+
elsif hit._type == "user"
|
50
50
|
json[:name] = result.name
|
51
51
|
json[:email] = result.email
|
52
52
|
end
|
data/app/models/attachment.rb
CHANGED
@@ -6,6 +6,17 @@ class Attachment < ActiveRecord::Base
|
|
6
6
|
belongs_to :attachable, :polymorphic => true
|
7
7
|
validates_presence_of :attachable
|
8
8
|
|
9
|
+
settings do
|
10
|
+
mappings dynamic: 'false' do
|
11
|
+
indexes :id, :index => :not_analyzed
|
12
|
+
indexes :type, :as => :type, :boost => 100
|
13
|
+
indexes :filename, :analyzer => 'snowball', :boost => 100
|
14
|
+
indexes :content_type, :analyzer => 'snowball'
|
15
|
+
indexes :created_at, :type => 'date', :include_in_all => false
|
16
|
+
indexes :updated_at, :type => 'date', :include_in_all => false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
9
20
|
def self.create_from_uploaded_file(file, user, options = {})
|
10
21
|
filename = file.original_filename
|
11
22
|
attachment = Attachment.create( options.merge(
|
@@ -71,7 +82,7 @@ class Attachment < ActiveRecord::Base
|
|
71
82
|
|
72
83
|
def as_indexed_json(options = {})
|
73
84
|
json = self.as_json
|
74
|
-
json[:
|
85
|
+
json[:type] = self.class.to_s.underscore
|
75
86
|
|
76
87
|
json
|
77
88
|
end
|
data/app/models/page.rb
CHANGED
@@ -7,7 +7,7 @@ class Page < ActiveRecord::Base
|
|
7
7
|
settings do
|
8
8
|
mappings dynamic: 'false' do
|
9
9
|
indexes :id, :index => :not_analyzed
|
10
|
-
indexes :
|
10
|
+
indexes :type, :as => :type, :boost => 100
|
11
11
|
indexes :ancestry, :index => :not_analyzed
|
12
12
|
indexes :title, :analyzer => 'snowball', :boost => 100
|
13
13
|
indexes :body, :analyzer => 'snowball'
|
@@ -87,7 +87,9 @@ class Page < ActiveRecord::Base
|
|
87
87
|
|
88
88
|
def as_indexed_json(options = {})
|
89
89
|
json = self.as_json
|
90
|
-
json[:
|
90
|
+
json[:body] = Nokogiri::HTML(self.body || "").text
|
91
|
+
json[:tag] = self.tag_list
|
92
|
+
json[:type] = self.class.to_s.underscore
|
91
93
|
json
|
92
94
|
end
|
93
95
|
|
@@ -118,7 +118,7 @@
|
|
118
118
|
text = item.type + ": " + item.project + " -> " + item.name
|
119
119
|
|
120
120
|
return '<li>' +
|
121
|
-
'<a href="javascript:;"><span>' + text + '</span></a>' +
|
121
|
+
'<a href="javascript:;"><i style="margin: 0 4px;" class="fa ' + (item.icon or "") + '"/><span>' + text + '</span></a>' +
|
122
122
|
'</li>'
|
123
123
|
insert: (item, delimiter) ->
|
124
124
|
$html = $("<span>").text(item.name)
|
data/lib/searcher.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
class Searcher
|
2
2
|
attr_reader :results
|
3
3
|
|
4
|
-
def initialize
|
5
|
-
@
|
4
|
+
def initialize options = {}
|
5
|
+
@options = options
|
6
|
+
|
7
|
+
@query = options[:query]
|
8
|
+
@q = options[:q]
|
9
|
+
|
10
|
+
@search_group = options[:search_group] || "pages,attachments"
|
11
|
+
@type = options[:type]
|
12
|
+
@comparator = options[:comparator] || "AND"
|
6
13
|
end
|
7
14
|
|
8
|
-
def self.search
|
9
|
-
searcher = Searcher.new
|
15
|
+
def self.search options = {}
|
16
|
+
searcher = Searcher.new options
|
10
17
|
searcher.search
|
11
18
|
|
12
19
|
searcher
|
@@ -14,9 +21,18 @@ class Searcher
|
|
14
21
|
|
15
22
|
def search
|
16
23
|
q = @query
|
17
|
-
|
24
|
+
|
25
|
+
if @q
|
26
|
+
q = @q
|
27
|
+
else
|
28
|
+
q = q.split(" ").collect{|x| "_all:" + x + "*"}.join(" #{@comparator} ")
|
29
|
+
end
|
30
|
+
|
31
|
+
if @type
|
32
|
+
q = "(#{q}) AND type:#{@type}"
|
33
|
+
end
|
34
|
+
|
18
35
|
client = Page.__elasticsearch__.client
|
19
|
-
search_group = "pages,attachments"
|
20
36
|
query = client.search index: search_group,
|
21
37
|
size: 30,
|
22
38
|
q: q
|
@@ -38,4 +54,8 @@ class Searcher
|
|
38
54
|
yield grouped_results[hit._type][hit._source.id].first, hit
|
39
55
|
end
|
40
56
|
end
|
57
|
+
|
58
|
+
def search_group
|
59
|
+
@search_group
|
60
|
+
end
|
41
61
|
end
|
data/lib/tawork/version.rb
CHANGED
@@ -194,7 +194,7 @@
|
|
194
194
|
var rtePosition = $(container).offset();
|
195
195
|
var contentAreaPosition = $(this.editor.getContentAreaContainer() || this.editor.bodyElement).position();
|
196
196
|
var nodePosition = $(this.editor.dom.select('span#autocomplete')).position();
|
197
|
-
var top = rtePosition.top + nodePosition.top + $(this.editor.selection.getNode()).innerHeight() - $(this.editor.getDoc()).scrollTop() + 5;
|
197
|
+
var top = rtePosition.top + nodePosition.top + $(this.editor.selection.getNode()).innerHeight(); // - $(this.editor.getDoc()).scrollTop() + 5;
|
198
198
|
var left = rtePosition.left + nodePosition.left;
|
199
199
|
|
200
200
|
this.$dropdown = $(this.renderDropdown())
|