used and recent
This commit is contained in:
parent
77d353464b
commit
f39b31519d
2 changed files with 48 additions and 0 deletions
|
@ -64,6 +64,28 @@ class User < ApplicationRecord
|
|||
json['rtype'] = 'mapper'
|
||||
json
|
||||
end
|
||||
|
||||
def recentMetacodes
|
||||
array = []
|
||||
self.topics.sort{|a,b| b.created_at <=> a.created_at }.each do |t|
|
||||
if array.length < 5 and array.index(t.metacode_id) == nil
|
||||
array.push(t.metacode_id)
|
||||
end
|
||||
end
|
||||
array
|
||||
end
|
||||
|
||||
def mostUsedMetacodes
|
||||
self.topics.to_a.reduce({}) { |memo, topic|
|
||||
if memo[topic.metacode_id] == nil
|
||||
memo[topic.metacode_id] = 1
|
||||
else
|
||||
memo[topic.metacode_id] = memo[topic.metacode_id] + 1
|
||||
end
|
||||
|
||||
memo
|
||||
}.to_a.sort{ |a, b| b[1] <=> a[1] }.map{|i| i[0]}.slice(0, 5)
|
||||
end
|
||||
|
||||
# generate a random 8 letter/digit code that they can use to invite people
|
||||
def generate_code
|
||||
|
|
|
@ -5,6 +5,32 @@
|
|||
|
||||
<div id="metacodeOptions">
|
||||
<ul>
|
||||
<li>
|
||||
<span>Most Used</span>
|
||||
<div class="expandMetacodeSet"></div>
|
||||
<ul>
|
||||
<% set.metacodes.sort { |a, b| a.name <=> b.name }.each do |m| %>
|
||||
<li data-id="<%= m.id.to_s %>">
|
||||
<img width="24" height="24" src="<%= asset_path m.icon %>" alt="<%= m.name %>" />
|
||||
<div class="mSelectName"><%= m.name %></div>
|
||||
<div class="clearfloat"></div>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
<span>Recently Used</span>
|
||||
<div class="expandMetacodeSet"></div>
|
||||
<ul>
|
||||
<% set.metacodes.sort { |a, b| a.name <=> b.name }.each do |m| %>
|
||||
<li data-id="<%= m.id.to_s %>">
|
||||
<img width="24" height="24" src="<%= asset_path m.icon %>" alt="<%= m.name %>" />
|
||||
<div class="mSelectName"><%= m.name %></div>
|
||||
<div class="clearfloat"></div>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</li>
|
||||
<% MetacodeSet.order("name").all.each do |set| %>
|
||||
<li>
|
||||
<span><%= set.name %></span>
|
||||
|
|
Loading…
Add table
Reference in a new issue