change metacode set json

This commit is contained in:
Connor Turland 2018-03-08 17:12:24 -05:00
parent 3348ea7b54
commit 706e094c90
2 changed files with 19 additions and 15 deletions

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true
class MetacodeSetsController < ApplicationController
include MetacodesHelper
before_action :require_admin
# GET /metacode_sets
@ -10,7 +11,7 @@ class MetacodeSetsController < ApplicationController
respond_to do |format|
format.html # index.html.erb
format.json { render json: @metacode_sets }
format.json { render json: metacode_sets_json }
end
end

View file

@ -52,27 +52,30 @@ module MetacodesHelper
def metacode_sets_json
metacode_sets = []
metacode_sets << {
name: 'Recently Used',
metacodes: user_recent_metacodes
.map { |m| { id: m.id, icon_path: asset_path(m.icon), name: m.name } }
}
metacode_sets << {
name: 'Most Used',
metacodes: user_most_used_metacodes
.map { |m| { id: m.id, icon_path: asset_path(m.icon), name: m.name } }
}
if current_user
metacode_sets << {
name: 'Recently Used',
description: 'Your recently used metacodes',
metacodes: user_recent_metacodes.map { |m| m.id }
}
metacode_sets << {
name: 'Most Used',
description: 'Your most used metacodes',
metacodes: user_most_used_metacodes.map { |m| m.id }
}
end
metacode_sets += MetacodeSet.order('name').all.map do |set|
{
id: set.id,
name: set.name,
metacodes: set.metacodes.order('name')
.map { |m| { id: m.id, icon_path: asset_path(m.icon), name: m.name } }
desc: set.desc,
metacodes: set.metacodes.order('name').map { |m| m.id }
}
end
metacode_sets << {
name: 'All',
metacodes: Metacode.order('name').all
.map { |m| { id: m.id, icon_path: asset_path(m.icon), name: m.name } }
desc: 'A list of all the metacodes',
metacodes: Metacode.order('name').all.map { |m| m.id }
}
metacode_sets.to_json
end