change metacode set json
This commit is contained in:
parent
3348ea7b54
commit
706e094c90
2 changed files with 19 additions and 15 deletions
|
@ -1,6 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class MetacodeSetsController < ApplicationController
|
class MetacodeSetsController < ApplicationController
|
||||||
|
include MetacodesHelper
|
||||||
before_action :require_admin
|
before_action :require_admin
|
||||||
|
|
||||||
# GET /metacode_sets
|
# GET /metacode_sets
|
||||||
|
@ -10,7 +11,7 @@ class MetacodeSetsController < ApplicationController
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
format.json { render json: @metacode_sets }
|
format.json { render json: metacode_sets_json }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -52,27 +52,30 @@ module MetacodesHelper
|
||||||
|
|
||||||
def metacode_sets_json
|
def metacode_sets_json
|
||||||
metacode_sets = []
|
metacode_sets = []
|
||||||
|
if current_user
|
||||||
metacode_sets << {
|
metacode_sets << {
|
||||||
name: 'Recently Used',
|
name: 'Recently Used',
|
||||||
metacodes: user_recent_metacodes
|
description: 'Your recently used metacodes',
|
||||||
.map { |m| { id: m.id, icon_path: asset_path(m.icon), name: m.name } }
|
metacodes: user_recent_metacodes.map { |m| m.id }
|
||||||
}
|
}
|
||||||
metacode_sets << {
|
metacode_sets << {
|
||||||
name: 'Most Used',
|
name: 'Most Used',
|
||||||
metacodes: user_most_used_metacodes
|
description: 'Your most used metacodes',
|
||||||
.map { |m| { id: m.id, icon_path: asset_path(m.icon), name: m.name } }
|
metacodes: user_most_used_metacodes.map { |m| m.id }
|
||||||
}
|
}
|
||||||
|
end
|
||||||
metacode_sets += MetacodeSet.order('name').all.map do |set|
|
metacode_sets += MetacodeSet.order('name').all.map do |set|
|
||||||
{
|
{
|
||||||
|
id: set.id,
|
||||||
name: set.name,
|
name: set.name,
|
||||||
metacodes: set.metacodes.order('name')
|
desc: set.desc,
|
||||||
.map { |m| { id: m.id, icon_path: asset_path(m.icon), name: m.name } }
|
metacodes: set.metacodes.order('name').map { |m| m.id }
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
metacode_sets << {
|
metacode_sets << {
|
||||||
name: 'All',
|
name: 'All',
|
||||||
metacodes: Metacode.order('name').all
|
desc: 'A list of all the metacodes',
|
||||||
.map { |m| { id: m.id, icon_path: asset_path(m.icon), name: m.name } }
|
metacodes: Metacode.order('name').all.map { |m| m.id }
|
||||||
}
|
}
|
||||||
metacode_sets.to_json
|
metacode_sets.to_json
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue