sandi metz function simplification
This commit is contained in:
parent
7ec7f9f892
commit
fa017a8559
5 changed files with 30 additions and 38 deletions
|
@ -50,8 +50,7 @@ class SynapsesController < ApplicationController
|
||||||
|
|
||||||
# DELETE synapses/:id
|
# DELETE synapses/:id
|
||||||
def destroy
|
def destroy
|
||||||
@current = current_user
|
@synapse = Synapse.find(params[:id]).authorize_to_delete(current_user)
|
||||||
@synapse = Synapse.find(params[:id]).authorize_to_delete(@current)
|
|
||||||
@synapse.delete if @synapse
|
@synapse.delete if @synapse
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
class UsersController < ApplicationController
|
class UsersController < ApplicationController
|
||||||
|
|
||||||
before_filter :require_user, only: [:edit, :update, :updatemetacodes]
|
before_filter :require_user, only: [:edit, :update, :updatemetacodes]
|
||||||
|
|
||||||
respond_to :html, :json
|
respond_to :html, :json
|
||||||
|
@ -14,7 +13,6 @@ class UsersController < ApplicationController
|
||||||
# GET /users/:id/edit
|
# GET /users/:id/edit
|
||||||
def edit
|
def edit
|
||||||
@user = current_user
|
@user = current_user
|
||||||
|
|
||||||
respond_with(@user)
|
respond_with(@user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,9 @@
|
||||||
module UsersHelper
|
module UsersHelper
|
||||||
|
# build custom json autocomplete for typeahead
|
||||||
## this one is for building our custom JSON autocomplete format for typeahead
|
|
||||||
def autocomplete_user_array_json(users)
|
def autocomplete_user_array_json(users)
|
||||||
temp = []
|
json_users = []
|
||||||
users.each do |u|
|
users.each do |user|
|
||||||
user = {}
|
json_users.push user.as_json_for_autocomplete
|
||||||
user['id'] = u.id
|
|
||||||
user['label'] = u.name
|
|
||||||
user['value'] = u.name
|
|
||||||
user['profile'] = u.image.url(:sixtyfour)
|
|
||||||
user['mapCount'] = u.maps.count
|
|
||||||
user['generation'] = u.generation
|
|
||||||
user['created_at'] = u.created_at.strftime("%m/%d/%Y")
|
|
||||||
user['rtype'] = "mapper"
|
|
||||||
|
|
||||||
temp.push user
|
|
||||||
end
|
end
|
||||||
return temp
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,6 +40,7 @@ class User < ActiveRecord::Base
|
||||||
# Validate the attached image is image/jpg, image/png, etc
|
# Validate the attached image is image/jpg, image/png, etc
|
||||||
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
|
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
|
||||||
|
|
||||||
|
# override default as_json
|
||||||
def as_json(options={})
|
def as_json(options={})
|
||||||
{ :id => self.id,
|
{ :id => self.id,
|
||||||
:name => self.name,
|
:name => self.name,
|
||||||
|
@ -47,27 +48,36 @@ class User < ActiveRecord::Base
|
||||||
:admin => self.admin
|
:admin => self.admin
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def as_json_for_autocomplete
|
||||||
|
user = {}
|
||||||
|
user['id'] = u.id
|
||||||
|
user['label'] = u.name
|
||||||
|
user['value'] = u.name
|
||||||
|
user['profile'] = u.image.url(:sixtyfour)
|
||||||
|
user['mapCount'] = u.maps.count
|
||||||
|
user['generation'] = u.generation
|
||||||
|
user['created_at'] = u.created_at.strftime("%m/%d/%Y")
|
||||||
|
user['rtype'] = "mapper"
|
||||||
|
end
|
||||||
|
|
||||||
|
#generate a random 8 letter/digit code that they can use to invite people
|
||||||
def generate_code
|
def generate_code
|
||||||
#generate a random 8 letter/digit code that they can use to invite people
|
|
||||||
self.code = rand(36**8).to_s(36)
|
self.code = rand(36**8).to_s(36)
|
||||||
|
|
||||||
$codes.push(self.code)
|
$codes.push(self.code)
|
||||||
|
|
||||||
self.generation = self.get_generation
|
self.generation = self.get_generation
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_generation
|
def get_generation
|
||||||
if self.joinedwithcode == self.code
|
calculate_generation() if generation.nil?
|
||||||
# if your joinedwithcode equals your code you must be GEN 0
|
generation
|
||||||
gen = 0
|
end
|
||||||
elsif self.generation
|
|
||||||
# if your generation has already been calculated then just return that value
|
def calculate_generation
|
||||||
gen = self.generation
|
if code == joinedwithcode
|
||||||
|
update(generation: 0)
|
||||||
else
|
else
|
||||||
# if your generation hasn't been calculated, base it off the
|
update(generation: User.find_by_code(joinedwithcode) + 1
|
||||||
# generation of the person whose code you joined with + 1
|
|
||||||
gen = User.find_by_code(self.joinedwithcode).get_generation + 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -75,13 +85,12 @@ class User < ActiveRecord::Base
|
||||||
# make sure we always return a UserPreference instance
|
# make sure we always return a UserPreference instance
|
||||||
if read_attribute(:settings).nil?
|
if read_attribute(:settings).nil?
|
||||||
write_attribute :settings, UserPreference.new
|
write_attribute :settings, UserPreference.new
|
||||||
read_attribute :settings
|
|
||||||
else
|
|
||||||
read_attribute :settings
|
|
||||||
end
|
end
|
||||||
|
read_attribute :settings
|
||||||
end
|
end
|
||||||
|
|
||||||
def settings=(val)
|
def settings=(val)
|
||||||
write_attribute :settings, val
|
write_attribute :settings, val
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,8 +2,7 @@ class MetacodeAssetPathUpdate < ActiveRecord::Migration
|
||||||
def change
|
def change
|
||||||
Metacode.all.each do |metacode|
|
Metacode.all.each do |metacode|
|
||||||
if metacode.icon.start_with?("/assets/icons/")
|
if metacode.icon.start_with?("/assets/icons/")
|
||||||
metacode.icon = metacode.icon.gsub(/^\/assets\/icons/, "https://s3.amazonaws.com/metamaps-assets/metacodes")
|
metacode.update(icon: metacode.icon.gsub(/^\/assets\/icons/, "https://s3.amazonaws.com/metamaps-assets/metacodes"))
|
||||||
metacode.save
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue