add ability to keep metacode focus

This commit is contained in:
Connor Turland 2017-02-05 06:28:10 +00:00
parent 00ecb0f6bb
commit 3ae4072b5d
6 changed files with 36 additions and 7 deletions

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
class UsersController < ApplicationController
before_action :require_user, only: [:edit, :update, :updatemetacodes]
before_action :require_user, only: [:edit, :update, :updatemetacodes, :update_metacode_focus]
respond_to :html, :json
@ -92,6 +92,16 @@ class UsersController < ApplicationController
end
end
# PUT /user/update_metacode_focus
def update_metacode_focus
@user = current_user
@user.settings.metacode_focus = params[:value]
@user.save
respond_to do |format|
format.json { render json: { success: "success" }}
end
end
private
def user_params

View file

@ -22,7 +22,24 @@ module ApplicationHelper
else
Metacode.where(id: @m).to_a
end
@metacodes.sort! { |m1, m2| m2.name.downcase <=> m1.name.downcase }.rotate!(-1)
focus_code = user_metacode()
if focus_code != nil && @metacodes.index{|m| m.id == focus_code.id} == nil
@metacodes.push(focus_code)
end
@metacodes
.sort! { |m1, m2| m2.name.downcase <=> m1.name.downcase }
if focus_code != nil
@metacodes.rotate!(@metacodes.index{|m| m.id == focus_code.id})
else
@metacodes.rotate!(-1)
end
end
def user_metacode
current_user.settings.metacode_focus ? Metacode.find(current_user.settings.metacode_focus.to_i) : nil
end
def user_most_used_metacodes

View file

@ -8,10 +8,6 @@ class Mapping < ApplicationRecord
belongs_to :user
belongs_to :updated_by, class_name: 'User'
validates :xloc, presence: true,
unless: proc { |m| m.mappable_type == 'Synapse' }
validates :yloc, presence: true,
unless: proc { |m| m.mappable_type == 'Synapse' }
validates :map, presence: true
validates :mappable, presence: true

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
class UserPreference
attr_accessor :metacodes
attr_accessor :metacodes, :metacode_focus
def initialize
array = []
@ -15,5 +15,6 @@ class UserPreference
end
end
@metacodes = array
@metacode_focus = array[0]
end
end

View file

@ -28,6 +28,10 @@ class UserPolicy < ApplicationPolicy
update?
end
def update_metacode_focus?
update?
end
# API action
def current?
user == record

View file

@ -105,6 +105,7 @@ Metamaps::Application.routes.draw do
end
end
post 'user/updatemetacodes', to: 'users#updatemetacodes', as: :updatemetacodes
post 'user/update_metacode_focus', to: 'users#update_metacode_focus'
namespace :api, path: '/api', default: { format: :json } do
namespace :v2, path: '/v2' do