From 706e094c90bbe0c75584ed030997ad60b3fbc213 Mon Sep 17 00:00:00 2001 From: Connor Turland Date: Thu, 8 Mar 2018 17:12:24 -0500 Subject: [PATCH] change metacode set json --- app/controllers/metacode_sets_controller.rb | 3 +- app/helpers/metacodes_helper.rb | 31 +++++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/controllers/metacode_sets_controller.rb b/app/controllers/metacode_sets_controller.rb index 956236b1..bfa77b1c 100644 --- a/app/controllers/metacode_sets_controller.rb +++ b/app/controllers/metacode_sets_controller.rb @@ -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 diff --git a/app/helpers/metacodes_helper.rb b/app/helpers/metacodes_helper.rb index 60da0bf7..6813afd6 100644 --- a/app/helpers/metacodes_helper.rb +++ b/app/helpers/metacodes_helper.rb @@ -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