Change role structure
Still needs to: change the views and create sub_roles in the dev.rake
This commit is contained in:
parent
e0cdedfa2e
commit
b7ac5478b4
1
Gemfile
1
Gemfile
|
@ -40,6 +40,7 @@ group :test, :development do
|
||||||
gem "rcov"
|
gem "rcov"
|
||||||
gem "delorean"
|
gem "delorean"
|
||||||
gem "watchr"
|
gem "watchr"
|
||||||
|
gem "spork"
|
||||||
# gem "capybara"
|
# gem "capybara"
|
||||||
# gem 'yard'
|
# gem 'yard'
|
||||||
# gem "bluecloth"
|
# gem "bluecloth"
|
||||||
|
|
|
@ -154,6 +154,7 @@ GEM
|
||||||
rack (~> 1.3, >= 1.3.4)
|
rack (~> 1.3, >= 1.3.4)
|
||||||
rack-protection (~> 1.1, >= 1.1.2)
|
rack-protection (~> 1.1, >= 1.1.2)
|
||||||
tilt (~> 1.3, >= 1.3.3)
|
tilt (~> 1.3, >= 1.3.3)
|
||||||
|
spork (0.8.5)
|
||||||
sprockets (2.0.3)
|
sprockets (2.0.3)
|
||||||
hike (~> 1.2)
|
hike (~> 1.2)
|
||||||
rack (~> 1.0)
|
rack (~> 1.0)
|
||||||
|
@ -200,6 +201,7 @@ DEPENDENCIES
|
||||||
sass-rails
|
sass-rails
|
||||||
shoulda-matchers
|
shoulda-matchers
|
||||||
sinatra
|
sinatra
|
||||||
|
spork
|
||||||
sprockets
|
sprockets
|
||||||
therubyracer
|
therubyracer
|
||||||
uglifier
|
uglifier
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
class Admin::InfosController < ApplicationController
|
||||||
|
|
||||||
|
layout "admin"
|
||||||
|
before_filter :authenticate_user!
|
||||||
|
before_filter :is_admin?
|
||||||
|
before_filter :set_attribute, :only => [:index, :show, :new, :edit]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@attributes = Info.all.entries
|
||||||
|
render :template => 'admin/attributes/index'
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
#@attribute = Info.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@attribute = Info.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@attribute = Info.find(params[:id])
|
||||||
|
@i18n_variable = @attribute.i18n_variable
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@attribute = Info.new(params[:info])
|
||||||
|
@attribute.save
|
||||||
|
redirect_to :action => :index
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@attribute = Info.find(params[:id])
|
||||||
|
@attribute.update_attributes(params[:info])
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@attribute = Info.find(params[:id])
|
||||||
|
@attribute.destroy
|
||||||
|
redirect_to :action => :index
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def set_attribute
|
||||||
|
@attribute_type = 'info'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,54 @@
|
||||||
|
class Admin::RolesController < ApplicationController
|
||||||
|
|
||||||
|
layout "admin"
|
||||||
|
before_filter :authenticate_user!
|
||||||
|
before_filter :is_admin?
|
||||||
|
before_filter :set_attribute, :only => [:index, :show, :new, :edit]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@attributes = Role.all.entries
|
||||||
|
render :template => 'admin/attributes/index'
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
#@attribute = Role.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@attribute = Role.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@attribute = Role.find(params[:id])
|
||||||
|
@i18n_variable = @attribute.i18n_variable
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@attribute = Role.new(params[:role])
|
||||||
|
@attribute.save
|
||||||
|
redirect_to :action => :index
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@attribute = Role.find(params[:id])
|
||||||
|
@attribute.update_attributes(params[:role])
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to :action => :index }
|
||||||
|
format.js { render 'admin/attributes/toggle_enable' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@attribute = Role.find(params[:id])
|
||||||
|
@attribute.destroy
|
||||||
|
redirect_to :action => :index
|
||||||
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
def set_attribute
|
||||||
|
@attribute_type = 'role'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -1,58 +0,0 @@
|
||||||
class Admin::UserInfoModelsController < ApplicationController
|
|
||||||
|
|
||||||
layout "admin"
|
|
||||||
before_filter :authenticate_user!
|
|
||||||
before_filter :is_admin?
|
|
||||||
before_filter :set_attribute, :only => [:index, :show, :new, :edit]
|
|
||||||
|
|
||||||
def index
|
|
||||||
@user_attribute_models = UserInfoModel.all.entries
|
|
||||||
render :template => 'admin/user_attribute_models/index'
|
|
||||||
end
|
|
||||||
|
|
||||||
def show
|
|
||||||
#@user_attribute_model = UserInfoModel.find(params[:id])
|
|
||||||
end
|
|
||||||
|
|
||||||
def new
|
|
||||||
@user_attribute_model = UserInfoModel.new
|
|
||||||
render :template => 'admin/user_attribute_models/new'
|
|
||||||
end
|
|
||||||
|
|
||||||
def edit
|
|
||||||
@user_attribute_model = UserInfoModel.find(params[:id])
|
|
||||||
@i18n_variable = @user_attribute_model.i18n_variable
|
|
||||||
render :template => 'admin/user_attribute_models/edit'
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
|
||||||
@user_attribute_model = UserInfoModel.new(params[:user_info_model])
|
|
||||||
@user_attribute_model.save
|
|
||||||
redirect_to :action => :index
|
|
||||||
end
|
|
||||||
|
|
||||||
def update
|
|
||||||
@user_attribute_model = UserInfoModel.find(params[:id])
|
|
||||||
@user_attribute_model.update_attributes(params[:user_info_model])
|
|
||||||
respond_to do |format|
|
|
||||||
format.html { redirect_to :action => :index }
|
|
||||||
format.js { render 'admin/user_attribute_models/toggle_enable' }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy
|
|
||||||
@user_attribute_model = UserInfoModel.find(params[:id])
|
|
||||||
@user_attribute_model.destroy
|
|
||||||
|
|
||||||
@user_attribute_model.destroy_i18n_variables
|
|
||||||
|
|
||||||
redirect_to :action => :index
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def set_attribute
|
|
||||||
@attribute = 'info'
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,59 +0,0 @@
|
||||||
class Admin::UserRoleModelsController < ApplicationController
|
|
||||||
|
|
||||||
layout "admin"
|
|
||||||
before_filter :authenticate_user!
|
|
||||||
before_filter :is_admin?
|
|
||||||
before_filter :set_attribute, :only => [:index, :show, :new, :edit]
|
|
||||||
|
|
||||||
def index
|
|
||||||
@user_attribute_models = UserRoleModel.all.entries
|
|
||||||
render :template => 'admin/user_attribute_models/index'
|
|
||||||
end
|
|
||||||
|
|
||||||
def show
|
|
||||||
#@user_attribute_model = UserRoleModel.find(params[:id])
|
|
||||||
end
|
|
||||||
|
|
||||||
def new
|
|
||||||
@user_attribute_model = UserRoleModel.new
|
|
||||||
render :template => 'admin/user_attribute_models/new'
|
|
||||||
end
|
|
||||||
|
|
||||||
def edit
|
|
||||||
@user_attribute_model = UserRoleModel.find(params[:id])
|
|
||||||
@i18n_variable = @user_attribute_model.i18n_variable
|
|
||||||
render :template => 'admin/user_attribute_models/edit'
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
|
||||||
@user_attribute_model = UserRoleModel.new(params[:user_role_model])
|
|
||||||
@user_attribute_model.save
|
|
||||||
redirect_to :action => :index
|
|
||||||
end
|
|
||||||
|
|
||||||
def update
|
|
||||||
@user_attribute_model = UserRoleModel.find(params[:id])
|
|
||||||
@user_attribute_model.update_attributes(params[:user_role_model])
|
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.html { redirect_to :action => :index }
|
|
||||||
format.js { render 'admin/user_attribute_models/toggle_enable' }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def destroy
|
|
||||||
@user_attribute_model = UserRoleModel.find(params[:id])
|
|
||||||
@user_attribute_model.destroy
|
|
||||||
|
|
||||||
@user_attribute_model.destroy_i18n_variables
|
|
||||||
|
|
||||||
redirect_to :action => :index
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
def set_attribute
|
|
||||||
@attribute = 'role'
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -20,13 +20,13 @@ class Admin::UsersController < ApplicationController
|
||||||
def create
|
def create
|
||||||
@user = User.new(params[:user])
|
@user = User.new(params[:user])
|
||||||
if @user.save
|
if @user.save
|
||||||
@user.user_infos.each do |user_info|
|
@user.user_infos.each do |info|
|
||||||
user_info.save
|
info.save
|
||||||
user_info.attribute_values.each(&:save)
|
info.attribute_values.each(&:save)
|
||||||
end
|
end
|
||||||
@user.user_roles.each do |user_role|
|
@user.roles.each do |role|
|
||||||
user_role.save
|
role.save
|
||||||
user_role.attribute_values.each(&:save)
|
role.attribute_values.each(&:save)
|
||||||
end
|
end
|
||||||
flash[:notice] = t('admin.create_success_user')
|
flash[:notice] = t('admin.create_success_user')
|
||||||
redirect_to :action => :index
|
redirect_to :action => :index
|
||||||
|
@ -77,8 +77,8 @@ class Admin::UsersController < ApplicationController
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def get_info_role_models
|
def get_info_role_models
|
||||||
@user_info_models = UserInfoModel.excludes('disabled' => true)
|
@roles = Info.excludes('disabled' => true)
|
||||||
@user_role_models = UserRoleModel.excludes('disabled' => true)
|
@infos = Role.excludes('disabled' => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,8 @@ class I18nVariable
|
||||||
field :document_class, :type => String
|
field :document_class, :type => String
|
||||||
field :parent_id, :type => BSON::ObjectId, :index => true
|
field :parent_id, :type => BSON::ObjectId, :index => true
|
||||||
|
|
||||||
|
belongs_to :language_value, polymorphic: true
|
||||||
|
|
||||||
def method_missing(field)
|
def method_missing(field)
|
||||||
self[field]
|
self[field]
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
class Attribute
|
||||||
|
|
||||||
|
include Mongoid::Document
|
||||||
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
|
field :key
|
||||||
|
field :built_in, :type => Boolean, :default => false
|
||||||
|
field :disabled, :type => Boolean, :default => false
|
||||||
|
|
||||||
|
embeds_many :attribute_fields
|
||||||
|
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||||
|
accepts_nested_attributes_for :i18n_variable, :allow_destroy => true
|
||||||
|
accepts_nested_attributes_for :attribute_fields, :allow_destroy => true
|
||||||
|
|
||||||
|
def is_built_in?
|
||||||
|
self.built_in
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_disabled?
|
||||||
|
self.disabled
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_enabled_attribute_fields
|
||||||
|
self.attribute_fields.excludes('disabled' => true)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,37 @@
|
||||||
|
class AttributeField
|
||||||
|
|
||||||
|
include Mongoid::Document
|
||||||
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
|
field :key
|
||||||
|
field :markup
|
||||||
|
field :locale, :type => Boolean
|
||||||
|
field :list_options, :type => Array
|
||||||
|
field :built_in, :type => Boolean, :default => false
|
||||||
|
field :disabled, :type => Boolean, :default => false
|
||||||
|
|
||||||
|
embedded_in :attribute
|
||||||
|
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||||
|
has_many :attribute_values
|
||||||
|
validates_uniqueness_of :key
|
||||||
|
accepts_nested_attributes_for :i18n_variable, :allow_destroy => true
|
||||||
|
|
||||||
|
# Convert the string list_options into an array
|
||||||
|
def select_list_options=(var)
|
||||||
|
self.list_options = var.gsub(' ', '').split(',')
|
||||||
|
end
|
||||||
|
|
||||||
|
# Convert the array list_options into a string
|
||||||
|
def select_list_options
|
||||||
|
self.list_options.to_a.join(', ')
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_built_in?
|
||||||
|
self.built_in
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_disabled?
|
||||||
|
self.disabled
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -1,62 +0,0 @@
|
||||||
class AttributeModel
|
|
||||||
|
|
||||||
include Mongoid::Document
|
|
||||||
include Mongoid::Timestamps
|
|
||||||
|
|
||||||
field :key
|
|
||||||
field :i18n_variable_id, :type => BSON::ObjectId, :index => true
|
|
||||||
field :markup
|
|
||||||
field :locale, :type => Boolean
|
|
||||||
field :list_options, :type => Array
|
|
||||||
field :built_in, :type => Boolean, :default => false
|
|
||||||
field :disabled, :type => Boolean, :default => false
|
|
||||||
|
|
||||||
embedded_in :user_attribute_model
|
|
||||||
validates_uniqueness_of :key
|
|
||||||
|
|
||||||
# Destroy the i18n_variable
|
|
||||||
def destroy_i18n_variable
|
|
||||||
self.i18n_variable.destroy rescue nil
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get the i18n_variable
|
|
||||||
def i18n_variable
|
|
||||||
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
|
|
||||||
end
|
|
||||||
|
|
||||||
# Update or create the i18n_variable record
|
|
||||||
def i18n_variable=(attr)
|
|
||||||
if self.i18n_variable_id
|
|
||||||
self.i18n_variable.update_attributes(attr)
|
|
||||||
else
|
|
||||||
# var = I18nVariable.new(attr.merge({:key => self.key, :document_class => self.class, :parent_id => self.user_attribute_model.i18n_variable_id}))
|
|
||||||
var = I18nVariable.new(attr.merge({:key => self.key, :document_class => self.class}))
|
|
||||||
var.save
|
|
||||||
self.i18n_variable_id = var.id
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Convert the string list_options into an array
|
|
||||||
def select_list_options=(var)
|
|
||||||
self.list_options = var.gsub(' ', '').split(',')
|
|
||||||
end
|
|
||||||
|
|
||||||
# Convert the array list_options into a string
|
|
||||||
def select_list_options
|
|
||||||
self.list_options.to_a.join(', ')
|
|
||||||
end
|
|
||||||
|
|
||||||
# Check if the attribute is set to be destroyed
|
|
||||||
def should_destroy?
|
|
||||||
should_destroy.to_i == 1 rescue nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def is_built_in?
|
|
||||||
self.built_in
|
|
||||||
end
|
|
||||||
|
|
||||||
def is_disabled?
|
|
||||||
self.disabled
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -5,6 +5,7 @@ class AttributeValue
|
||||||
|
|
||||||
field :key
|
field :key
|
||||||
|
|
||||||
belongs_to :user_attribute
|
belongs_to :attribute_field
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
class Info < Attribute
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,29 @@
|
||||||
|
class Role
|
||||||
|
|
||||||
|
include Mongoid::Document
|
||||||
|
include Mongoid::Timestamps
|
||||||
|
|
||||||
|
field :key
|
||||||
|
field :built_in, :type => Boolean, :default => false
|
||||||
|
field :disabled, :type => Boolean, :default => false
|
||||||
|
|
||||||
|
embeds_many :sub_roles
|
||||||
|
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||||
|
has_many :users
|
||||||
|
accepts_nested_attributes_for :i18n_variable, :allow_destroy => true
|
||||||
|
accepts_nested_attributes_for :sub_roles, :allow_destroy => true
|
||||||
|
|
||||||
|
def is_built_in?
|
||||||
|
self.built_in
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_disabled?
|
||||||
|
self.disabled
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get an role from key
|
||||||
|
def self.get_role_from_key(key)
|
||||||
|
self.first(:conditions => {:key => key})
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,10 @@
|
||||||
|
class SubRole < Attribute
|
||||||
|
|
||||||
|
has_many :users
|
||||||
|
|
||||||
|
# Get an sub_role from key
|
||||||
|
def self.get_sub_role_from_key(key)
|
||||||
|
self.first(:conditions => {:key => key})
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -10,43 +10,10 @@ class User
|
||||||
field :admin, :type => Boolean, :default => true
|
field :admin, :type => Boolean, :default => true
|
||||||
field :active_role
|
field :active_role
|
||||||
|
|
||||||
has_many :user_attributes
|
has_many :attribute_values, :autosave => true, :dependent => :destroy
|
||||||
has_many :user_roles
|
belongs_to :role
|
||||||
has_many :user_infos
|
belongs_to :sub_role
|
||||||
|
accepts_nested_attributes_for :attribute_values, :allow_destroy => true
|
||||||
# Update or create the user_role records
|
|
||||||
def user_roles=(*attrs)
|
|
||||||
attrs[0].each do |roles|
|
|
||||||
if roles[:id].blank?
|
|
||||||
user_roles.build(roles)
|
|
||||||
else
|
|
||||||
user_role = user_roles.detect {|a| a.id.to_s == roles[:id].to_s }
|
|
||||||
user_role.update_attributes(roles)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Update or create the user_info records
|
|
||||||
def user_infos=(*attrs)
|
|
||||||
attrs[0].each do |infos|
|
|
||||||
if infos[:id].blank?
|
|
||||||
user_infos.build(infos)
|
|
||||||
else
|
|
||||||
user_info = user_infos.detect {|a| a.id.to_s == infos[:id].to_s }
|
|
||||||
user_info.update_attributes(infos)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get an user_info from model key
|
|
||||||
def get_info_from_model_key(key)
|
|
||||||
self.user_infos.detect {|a| a.key.to_s == key.to_s }
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get an user_role from model key
|
|
||||||
def get_role_from_model_key(key)
|
|
||||||
self.user_roles.detect {|a| a.key.to_s == key.to_s }
|
|
||||||
end
|
|
||||||
|
|
||||||
def name
|
def name
|
||||||
infos = self.user_infos.detect {|info| info.key.to_s.eql?('profile') }
|
infos = self.user_infos.detect {|info| info.key.to_s.eql?('profile') }
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
class UserAttribute
|
|
||||||
|
|
||||||
include Mongoid::Document
|
|
||||||
include Mongoid::Timestamps
|
|
||||||
|
|
||||||
field :key
|
|
||||||
has_many :attribute_values
|
|
||||||
|
|
||||||
# Update or create the attribute_value records
|
|
||||||
def attribute_values=(*args)
|
|
||||||
args[0].each do |value|
|
|
||||||
if value[:id].blank?
|
|
||||||
attribute_values.build(value)
|
|
||||||
else
|
|
||||||
attribute_value = attribute_values.detect {|a| a.id.to_s == value[:id].to_s }
|
|
||||||
attribute_value.update_attributes(value)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,74 +0,0 @@
|
||||||
class UserAttributeModel
|
|
||||||
|
|
||||||
include Mongoid::Document
|
|
||||||
include Mongoid::Timestamps
|
|
||||||
|
|
||||||
field :key
|
|
||||||
field :i18n_variable_id, :type => BSON::ObjectId, :index => true
|
|
||||||
field :built_in, :type => Boolean, :default => false
|
|
||||||
field :disabled, :type => Boolean, :default => false
|
|
||||||
|
|
||||||
embeds_many :attribute_models
|
|
||||||
|
|
||||||
after_update :destroy_attrs
|
|
||||||
|
|
||||||
# Update or create the attribute_model records
|
|
||||||
def attribute_models=(*attrs)
|
|
||||||
attrs[0].each do |attributes|
|
|
||||||
if attributes[:id].blank?
|
|
||||||
attribute_models.build(attributes)
|
|
||||||
else
|
|
||||||
attribute_model = attribute_models.detect {|a| a.id.to_s == attributes[:id].to_s }
|
|
||||||
attribute_model.update_attributes(attributes)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Destroy the i18n_variables
|
|
||||||
def destroy_i18n_variables
|
|
||||||
self.i18n_variable.destroy rescue nil
|
|
||||||
self.attribute_models.each do |attr|
|
|
||||||
attr.destroy_i18n_variable
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Update or create the i18n_variable record
|
|
||||||
def i18n_variable=(attr)
|
|
||||||
if self.i18n_variable_id
|
|
||||||
self.i18n_variable.update_attributes(attr) rescue nil
|
|
||||||
else
|
|
||||||
var = I18nVariable.new(attr.merge({:key => self.key, :document_class => self.class}))
|
|
||||||
var.save
|
|
||||||
self.i18n_variable_id = var.id
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get the i18n_variable
|
|
||||||
def i18n_variable
|
|
||||||
@i18n_variable ||= I18nVariable.find(self.i18n_variable_id) rescue nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def is_built_in?
|
|
||||||
self.built_in
|
|
||||||
end
|
|
||||||
|
|
||||||
def is_disabled?
|
|
||||||
self.disabled.blank? ? false : self.disabled
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_enabled_attribute_models
|
|
||||||
self.attribute_models.excludes('disabled' => true)
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
|
||||||
|
|
||||||
# Destroy the i18n_variable for each attribute_models if marked to destroy
|
|
||||||
def destroy_attrs
|
|
||||||
attribute_models.each do |a|
|
|
||||||
if a.should_destroy?
|
|
||||||
a.destroy_i18n_variable
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,5 +0,0 @@
|
||||||
class UserInfo < UserAttribute
|
|
||||||
|
|
||||||
belongs_to :user
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,3 +0,0 @@
|
||||||
class UserInfoModel < UserAttributeModel
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,5 +0,0 @@
|
||||||
class UserRole < UserAttribute
|
|
||||||
|
|
||||||
belongs_to :user
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,8 +0,0 @@
|
||||||
class UserRoleModel < UserAttributeModel
|
|
||||||
|
|
||||||
# Get an user_role_model from key
|
|
||||||
def self.get_role_model_from_key(key)
|
|
||||||
self.first(:conditions => {:key => key})
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
<%= fields_for "user_#{@attribute_type}_model[attribute_models][]", attribute_model, :index => nil do |f| %>
|
||||||
|
<tr class="list_item">
|
||||||
|
<td><%= attribute_model.new_record? ? (f.text_field :key) : attribute_model.key %></td>
|
||||||
|
<td class='select_mulitlingual' style='text-align:center'>
|
||||||
|
<%= check_box_tag "locale[]", value = '', attribute_model.locale.nil? ? true : attribute_model.locale %>
|
||||||
|
<%= hidden_field_tag "user_#{@attribute_type}_model[attribute_models][][locale]", attribute_model.locale.nil? ? true : attribute_model.locale %>
|
||||||
|
</td>
|
||||||
|
<% @site_valid_locales.each do |locale| %>
|
||||||
|
<td><%= text_field_tag "user_#{@attribute_type}_model[attribute_models][][i18n_variable][#{locale}]", (attribute_model.i18n_variable[locale] rescue nil), :style => "width:130px" %></td>
|
||||||
|
<% end %>
|
||||||
|
<td class='select_type'>
|
||||||
|
<%= f.select :markup, LIST[:markups], {}, {:style => "width:90px"} %>
|
||||||
|
<div <%= attribute_model[:markup].eql?('select') ? nil : "style='display:none'"%>>
|
||||||
|
<%= t('admin.options') %>:
|
||||||
|
<%= text_field_tag "user_#{@attribute_type}_model[attribute_models][][select_list_options]", attribute_model.select_list_options, :style => "width:130px" %>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<span class="action">
|
||||||
|
<% if attribute_model.new_record? %>
|
||||||
|
<a href="#" class="delete"><%= t(:delete) %></a>
|
||||||
|
<% else %>
|
||||||
|
<% if attribute_model.is_built_in? %>
|
||||||
|
<a href="#" class="change_built_in switch" id="<%= attribute_model.id %>"></a>
|
||||||
|
<%= hidden_field_tag "user_#{@attribute_type}_model[attribute_models][][disabled]", attribute_model.is_disabled? , :class => 'built_in_state' %>
|
||||||
|
<% else %>
|
||||||
|
<a href="#" class="remove_existing_record delete"><%= t(:delete) %></a>
|
||||||
|
<%= hidden_field_tag "user_#{@attribute_type}_model[attribute_models][][should_destroy]", nil , :class => 'should_destroy' %>
|
||||||
|
<% end %>
|
||||||
|
<%= f.hidden_field :id %>
|
||||||
|
<%= f.hidden_field :key %>
|
||||||
|
<% end %>
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
|
@ -0,0 +1,57 @@
|
||||||
|
<div id="UserRole_block" class="roles_block">
|
||||||
|
<h2><%= t("admin.user_#{@attribute_type}") %></h2>
|
||||||
|
<div class="info_input">
|
||||||
|
<table border="0" cellspacing="0" cellpadding="0">
|
||||||
|
<thead class="list_head">
|
||||||
|
<tr>
|
||||||
|
<td><%= t('admin.key') %></td>
|
||||||
|
<% @site_valid_locales.each do |locale| %>
|
||||||
|
<td style="color:<%= colorize_in_use_locale(locale) %>"><%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %></td>
|
||||||
|
<% end %>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr class="list_item">
|
||||||
|
<td><%= is_new ? (f.text_field :key, {:style => "width:150px"}) : @attribute.key %></td>
|
||||||
|
<% @site_valid_locales.each do |locale| %>
|
||||||
|
<td>
|
||||||
|
<%= text_field_tag "user_#{@attribute_type}_model[i18n_variable][#{locale}]", (@i18n_variable[locale] if @i18n_variable), :style => "width:150px" %>
|
||||||
|
</td>
|
||||||
|
<% end %>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div id="attributes_block" class="roles_block">
|
||||||
|
<h2>Attributes</h2>
|
||||||
|
<div class="info_input">
|
||||||
|
<table id='attributes' border="0" cellspacing="0" cellpadding="0">
|
||||||
|
<thead class="list_head">
|
||||||
|
<tr>
|
||||||
|
<td><%= t('admin.key') %></td>
|
||||||
|
<td><%= t('admin.multilingual') %></td>
|
||||||
|
<% @site_valid_locales.each do |locale| %>
|
||||||
|
<td style="color:<%= colorize_in_use_locale(locale) %>"><%= I18nVariable.first(:conditions => {:key => locale})[I18n.locale] %></td>
|
||||||
|
<% end %>
|
||||||
|
<td><%= t('admin.type')%></td>
|
||||||
|
<td> </td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<td colspan="5"><a href="#" class="add"><%= t(:add) %></a></td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
<tbody>
|
||||||
|
<%= render :partial => 'admin/attributes/attribute_model', :collection => @attribute.attribute_models %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<% content_for :page_specific_javascript do %>
|
||||||
|
<%= javascript_include_tag "attribute_form" %>
|
||||||
|
<% end -%>
|
|
@ -0,0 +1,16 @@
|
||||||
|
<% content_for :secondary do %>
|
||||||
|
<%= render 'admin/users/side_bar' %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div id="porfile">
|
||||||
|
<%= form_for @attribute, :url => eval("admin_user_#{@attribute_type}_model_path(@user_role_model)") do |f| %>
|
||||||
|
<%= f.error_messages %>
|
||||||
|
<%= render :partial => "admin/attributes/form", :locals => { :f => f, :is_new => false } %>
|
||||||
|
<div id="update" class='buttom clear'>
|
||||||
|
<%= link_to t('update'), "#", :onclick=>"$('#edit_user_role_model_#{@attribute.id}').submit()" %>
|
||||||
|
</div>
|
||||||
|
<div id="back" class='buttom clear'>
|
||||||
|
<%= link_back %>
|
||||||
|
</div>
|
||||||
|
<% end -%>
|
||||||
|
</div>
|
|
@ -0,0 +1,34 @@
|
||||||
|
<% content_for :secondary do %>
|
||||||
|
<%= render 'admin/users/side_bar' %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="main_list">
|
||||||
|
<div id="add_new" class="buttom clear">
|
||||||
|
<%= link_to t("admin.new_#{@attribute_type}"), eval("new_admin_#{@attribute_type}_path") %>
|
||||||
|
</div>
|
||||||
|
<ul>
|
||||||
|
<li class="list_head clear">
|
||||||
|
<span class="<%= @attribute_type %>s"><%= t("admin.#{@attribute_type}") %></span>
|
||||||
|
<span class="action"><%= t('admin.action') %></span>
|
||||||
|
</li>
|
||||||
|
<% @attributes.each do |attribute| %>
|
||||||
|
<li id="attribute_<%= attribute.id %>" class="list_item <%= "#{attribute.is_disabled? ? 'disable' : ''}" %> clear">
|
||||||
|
<span class="<%= @attribute_type %>s <%= attribute.i18n_variable[:key].downcase %>"><%= attribute.i18n_variable[I18n.locale] %></span>
|
||||||
|
<span class="action">
|
||||||
|
|
||||||
|
<%= link_to t(:edit), eval("edit_admin_#{@attribute_type}_path(attribute)"), :class => 'edit' %>
|
||||||
|
<% if attribute.is_built_in? %>
|
||||||
|
<%= link_to t(:enable), eval("admin_#{@attribute_type}_path(attribute, :authenticity_token => form_authenticity_token, :#{@attribute_type} => {:disabled => true})"), :remote => true, :method => :put, :id => "disable_#{attribute.id}", :style => "display:#{attribute.is_disabled? ? 'none' : ''}", :class => 'switch' %>
|
||||||
|
<%= link_to t(:disable), eval("admin_#{@attribute_type}_path(attribute, :authenticity_token => form_authenticity_token, :#{@attribute_type} => {:disabled => false})"), :remote => true, :method => :put, :id => "enable_#{attribute.id}", :style => "display:#{attribute.is_disabled? ? '' : 'none'}", :class => 'switch' %>
|
||||||
|
<% else %>
|
||||||
|
<%= link_to t(:delete), eval("admin_#{@attribute_type}_path(attribute)"), :class => 'delete', :confirm => t('sure?'), :method => :delete %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
<div id="add_new" class="buttom clear">
|
||||||
|
<%= link_to t("admin.new_#{@attribute_type}"), eval("new_admin_#{@attribute_type}_path") %>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -0,0 +1,20 @@
|
||||||
|
<% content_for :secondary do %>
|
||||||
|
<%= render 'admin/users/side_bar' %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div id="porfile">
|
||||||
|
<%= form_for @attribute, :url => eval("admin_infos_path") do |f| %>
|
||||||
|
<%= f.error_messages %>
|
||||||
|
<%= render :partial => "admin/infos/form", :locals => { :f => f, :is_new => true } %>
|
||||||
|
<div id="create" class='buttom clear'>
|
||||||
|
<%= link_to t('create'), "#", :onclick=>"$('#new_attribute').submit()" %>
|
||||||
|
</div>
|
||||||
|
<div id="back" class='buttom clear'>
|
||||||
|
<%= link_back %>
|
||||||
|
</div>
|
||||||
|
<% end -%>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
$("#enable_<%= @attribute.id %>").toggle();
|
||||||
|
$("#disable_<%= @attribute.id %>").toggle();
|
||||||
|
$("#attribute_<%= @attribute.id %>").toggleClass('disable');
|
|
@ -0,0 +1,16 @@
|
||||||
|
<% content_for :secondary do %>
|
||||||
|
<%= render 'admin/users/side_bar' %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div id="porfile">
|
||||||
|
<%= form_for @attribute, :url => eval("admin_user_#{@attribute_type}_model_path(@user_role_model)") do |f| %>
|
||||||
|
<%= f.error_messages %>
|
||||||
|
<%= render :partial => "admin/attributes/form", :locals => { :f => f, :is_new => false } %>
|
||||||
|
<div id="update" class='buttom clear'>
|
||||||
|
<%= link_to t('update'), "#", :onclick=>"$('#edit_user_role_model_#{@attribute.id}').submit()" %>
|
||||||
|
</div>
|
||||||
|
<div id="back" class='buttom clear'>
|
||||||
|
<%= link_back %>
|
||||||
|
</div>
|
||||||
|
<% end -%>
|
||||||
|
</div>
|
|
@ -0,0 +1,11 @@
|
||||||
|
<div id="search">
|
||||||
|
<input id="user_search" name="user[username]" size="30" type="text" />
|
||||||
|
</div>
|
||||||
|
<div class="member_setup">
|
||||||
|
<h1><%= t('admin.setup_member') %></h1>
|
||||||
|
<ul class="list">
|
||||||
|
<li class="set_1"><%= link_to content_tag(:span, t('admin.list_users')), admin_users_path %></li>
|
||||||
|
<li class="set_2"><%= link_to content_tag(:span, t('admin.list_roles')), admin_roles_path %></li>
|
||||||
|
<li class="set_3"><%= link_to content_tag(:span, t('admin.list_infos')), admin_infos_path %></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
|
@ -22,6 +22,7 @@ PrototypeR4::Application.routes.draw do
|
||||||
post 'edit_file' => 'designs#edit_file'
|
post 'edit_file' => 'designs#edit_file'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
resources :infos
|
||||||
resources :items
|
resources :items
|
||||||
resources :links do
|
resources :links do
|
||||||
member do
|
member do
|
||||||
|
@ -43,12 +44,11 @@ PrototypeR4::Application.routes.draw do
|
||||||
get 'download'
|
get 'download'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
resources :roles
|
||||||
resources :sites
|
resources :sites
|
||||||
resources :snippets
|
resources :snippets
|
||||||
resources :translations
|
resources :translations
|
||||||
resources :users
|
resources :users
|
||||||
resources :user_info_models
|
|
||||||
resources :user_role_models
|
|
||||||
end
|
end
|
||||||
# end admin
|
# end admin
|
||||||
|
|
||||||
|
|
|
@ -15,13 +15,13 @@ namespace :dev do
|
||||||
|
|
||||||
I18nVariable.create!( :document_class => 'language', :key => 'en', :en => 'English', :zh_tw => '英文' )
|
I18nVariable.create!( :document_class => 'language', :key => 'en', :en => 'English', :zh_tw => '英文' )
|
||||||
I18nVariable.create!( :document_class => 'language', :key => 'zh_tw', :en => 'Chinese', :zh_tw => '中文' )
|
I18nVariable.create!( :document_class => 'language', :key => 'zh_tw', :en => 'Chinese', :zh_tw => '中文' )
|
||||||
var_1 = I18nVariable.create!( :document_class => 'UserRoleModel', :key => 'teacher', :en => 'Teacher', :zh_tw => '老師' )
|
var_1 = I18nVariable.create!( :document_class => 'Role', :key => 'teacher', :en => 'Teacher', :zh_tw => '老師' )
|
||||||
var_2 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'discipline', :en => 'Discipline', :zh_tw => '學科', :parent_id => var_1.id )
|
var_2 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'discipline', :en => 'Discipline', :zh_tw => '學科', :parent_id => var_1.id )
|
||||||
var_3 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'department', :en => 'Department', :zh_tw => '學系', :parent_id => var_1.id )
|
var_3 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'department', :en => 'Department', :zh_tw => '學系', :parent_id => var_1.id )
|
||||||
var_4 = I18nVariable.create!( :document_class => 'UserRoleModel', :key => 'student', :en => 'Student', :zh_tw => '學生' )
|
var_4 = I18nVariable.create!( :document_class => 'Role', :key => 'student', :en => 'Student', :zh_tw => '學生' )
|
||||||
var_5 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'department', :en => 'Department', :zh_tw => '學系', :parent_id => var_4.id )
|
var_5 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'department', :en => 'Department', :zh_tw => '學系', :parent_id => var_4.id )
|
||||||
var_6 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'major', :en => 'Major', :zh_tw => '主修', :parent_id => var_4.id )
|
var_6 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'major', :en => 'Major', :zh_tw => '主修', :parent_id => var_4.id )
|
||||||
var_7 = I18nVariable.create!( :document_class => 'UserInfoModel', :key => 'profile', :en => 'Profile', :zh_tw => '個人檔案' )
|
var_7 = I18nVariable.create!( :document_class => 'Info', :key => 'profile', :en => 'Profile', :zh_tw => '個人檔案' )
|
||||||
var_8 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'last_name', :en => 'Last name', :zh_tw => '姓氏', :parent_id => var_7.id )
|
var_8 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'last_name', :en => 'Last name', :zh_tw => '姓氏', :parent_id => var_7.id )
|
||||||
var_9 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'first_name', :en => 'First name', :zh_tw => '名字', :parent_id => var_7.id )
|
var_9 = I18nVariable.create!( :document_class => 'AttributeModel', :key => 'first_name', :en => 'First name', :zh_tw => '名字', :parent_id => var_7.id )
|
||||||
var_10 = I18nVariable.create!( :document_class => 'Home', :key => 'home', :en => 'Homepage', :zh_tw => '首頁')
|
var_10 = I18nVariable.create!( :document_class => 'Home', :key => 'home', :en => 'Homepage', :zh_tw => '首頁')
|
||||||
|
@ -32,17 +32,17 @@ namespace :dev do
|
||||||
|
|
||||||
|
|
||||||
# TODO: modify for the new model
|
# TODO: modify for the new model
|
||||||
urm_1 = UserRoleModel.new( :key => 'teacher', :i18n_variable_id => var_1.id, :built_in => true )
|
urm_1 = Role.new( :key => 'teacher', :i18n_variable_id => var_1.id, :built_in => true )
|
||||||
urm_1.attribute_models.build( :key => 'discipline', :locale => true, :i18n_variable_id => var_2.id, :markup => 'text_field', :list_options => [], :built_in => true )
|
urm_1.attributes.build( :key => 'discipline', :locale => true, :i18n_variable_id => var_2.id, :markup => 'text_field', :list_options => [], :built_in => true )
|
||||||
urm_1.attribute_models.build( :key => 'department', :locale => true, :i18n_variable_id => var_3.id, :markup => 'text_field', :list_options => [], :built_in => true )
|
urm_1.attributes.build( :key => 'department', :locale => true, :i18n_variable_id => var_3.id, :markup => 'text_field', :list_options => [], :built_in => true )
|
||||||
urm_1.save!
|
urm_1.save!
|
||||||
urm_2 = UserRoleModel.new( :key => 'student', :i18n_variable_id => var_4.id )
|
urm_2 = Role.new( :key => 'student', :i18n_variable_id => var_4.id )
|
||||||
urm_2.attribute_models.build( :key => 'department', :locale => true, :i18n_variable_id => var_5.id, :markup => 'text_field', :list_options => [] )
|
urm_2.attributes.build( :key => 'department', :locale => true, :i18n_variable_id => var_5.id, :markup => 'text_field', :list_options => [] )
|
||||||
urm_2.attribute_models.build( :key => 'major', :locale => true, :i18n_variable_id => var_6.id, :markup => 'text_field', :list_options => [] )
|
urm_2.attributes.build( :key => 'major', :locale => true, :i18n_variable_id => var_6.id, :markup => 'text_field', :list_options => [] )
|
||||||
urm_2.save!
|
urm_2.save!
|
||||||
uim_1 = UserInfoModel.new( :key => 'profile', :i18n_variable_id => var_7.id, :built_in => true )
|
uim_1 = Info.new( :key => 'profile', :i18n_variable_id => var_7.id, :built_in => true )
|
||||||
uim_1.attribute_models.build( :key => 'last_name', :locale => true, :i18n_variable_id => var_8.id, :markup => 'text_field', :list_options => [], :built_in => true )
|
uim_1.attributes.build( :key => 'last_name', :locale => true, :i18n_variable_id => var_8.id, :markup => 'text_field', :list_options => [], :built_in => true )
|
||||||
uim_1.attribute_models.build( :key => 'first_name', :locale => true, :i18n_variable_id => var_9.id, :markup => 'text_field', :list_options => [], :built_in => true )
|
uim_1.attributes.build( :key => 'first_name', :locale => true, :i18n_variable_id => var_9.id, :markup => 'text_field', :list_options => [], :built_in => true )
|
||||||
uim_1.save!
|
uim_1.save!
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,22 +118,18 @@ namespace :dev do
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
user = User.create( :email => 'chris@rulingcom.com', :password => 'password', :password_confirmation => 'password', :admin => true, :active_role => 'teacher' )
|
user = User.create( :email => 'chris@rulingcom.com', :password => 'password', :password_confirmation => 'password', :admin => true, :role_id => urm_1.id )
|
||||||
user_info = UserInfo.create( :user_id => user.id, :key => 'profile' )
|
AttributeValue.create( :user_id => user.id, :key => 'first_name', :en => 'Christophe', :zh_tw => '順發' )
|
||||||
user_role = UserRole.create( :user_id => user.id, :key => 'teacher' )
|
AttributeValue.create( :user_id => user.id, :key => 'last_name', :en => 'Vilayphiou', :zh_tw => '林' )
|
||||||
AttributeValue.create( :user_attribute_id => user_info.id, :key => 'first_name', :en => 'Christophe', :zh_tw => '順發' )
|
AttributeValue.create( :user_id => user.id, :key => 'discipline', :en => 'Computer Architecture', :zh_tw => '計算機系統結構' )
|
||||||
AttributeValue.create( :user_attribute_id => user_info.id, :key => 'last_name', :en => 'Vilayphiou', :zh_tw => '林' )
|
AttributeValue.create( :user_id => user.id, :key => 'department', :en => 'Computer Science', :zh_tw => '計算機科學' )
|
||||||
AttributeValue.create( :user_attribute_id => user_role.id, :key => 'discipline', :en => 'Computer Architecture', :zh_tw => '計算機系統結構' )
|
|
||||||
AttributeValue.create( :user_attribute_id => user_role.id, :key => 'department', :en => 'Computer Science', :zh_tw => '計算機科學' )
|
|
||||||
|
|
||||||
|
|
||||||
user = User.create( :email => 'matt@rulingcom.com', :password => 'password', :password_confirmation => 'password', :admin => true, :active_role => 'student' )
|
user = User.create( :email => 'matt@rulingcom.com', :password => 'password', :password_confirmation => 'password', :admin => true, :role_id => urm_2.id )
|
||||||
user_info = UserInfo.create( :user_id => user.id, :key => 'profile' )
|
AttributeValue.create( :user_id => user.id, :key => 'first_name', :en => 'Matt', :zh_tw => '儒淵' )
|
||||||
user_role = UserRole.create( :user_id => user.id, :key => 'student' )
|
AttributeValue.create( :user_id => user.id, :key => 'last_name', :en => 'Fu', :zh_tw => '傅' )
|
||||||
AttributeValue.create( :user_attribute_id => user_info.id, :key => 'first_name', :en => 'Matt', :zh_tw => '儒淵' )
|
AttributeValue.create( :user_id => user.id, :key => 'major', :en => 'Information management', :zh_tw => '信息化管理' )
|
||||||
AttributeValue.create( :user_attribute_id => user_info.id, :key => 'last_name', :en => 'Fu', :zh_tw => '傅' )
|
AttributeValue.create( :user_id => user.id, :key => 'department', :en => 'Computer Science', :zh_tw => '計算機科學' )
|
||||||
AttributeValue.create( :user_attribute_id => user_role.id, :key => 'major', :en => 'Information management', :zh_tw => '信息化管理' )
|
|
||||||
AttributeValue.create( :user_attribute_id => user_role.id, :key => 'department', :en => 'Computer Science', :zh_tw => '計算機科學' )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe DesignController do
|
|
||||||
|
|
||||||
describe "GET 'index'" do
|
|
||||||
it "should be successful" do
|
|
||||||
get 'index'
|
|
||||||
response.should be_success
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "GET 'new'" do
|
|
||||||
it "should be successful" do
|
|
||||||
get 'new'
|
|
||||||
response.should be_success
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "GET 'update'" do
|
|
||||||
it "should be successful" do
|
|
||||||
get 'update'
|
|
||||||
response.should be_success
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "GET 'edit'" do
|
|
||||||
it "should be successful" do
|
|
||||||
get 'edit'
|
|
||||||
response.should be_success
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "GET 'destroy'" do
|
|
||||||
it "should be successful" do
|
|
||||||
get 'destroy'
|
|
||||||
response.should be_success
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "GET 'create'" do
|
|
||||||
it "should be successful" do
|
|
||||||
get 'create'
|
|
||||||
response.should be_success
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
|
@ -1,15 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
# Specs in this file have access to a helper object that includes
|
|
||||||
# the DesignHelper. For example:
|
|
||||||
#
|
|
||||||
# describe DesignHelper do
|
|
||||||
# describe "string concat" do
|
|
||||||
# it "concats two strings with spaces" do
|
|
||||||
# helper.concat_strings("this","that").should == "this that"
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
describe DesignHelper do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
|
@ -1,5 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe Design do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
|
@ -0,0 +1,109 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Role do
|
||||||
|
before do
|
||||||
|
@role = Role.create(:key => 'teacher',
|
||||||
|
:i18n_variable => {:key => 'teacher', :en => 'Teacher', :zh_tw => 'Teacher in Chinese', :document_class => 'Role'},
|
||||||
|
:sub_roles => [{:key => 'undergrad',
|
||||||
|
:attribute_fields => [{:key => 'department'},
|
||||||
|
{:key => 'room'}]},
|
||||||
|
{:key => 'master',
|
||||||
|
:attribute_fields => [{:key => 'department'}]}])
|
||||||
|
end
|
||||||
|
describe 'New role' do
|
||||||
|
describe '#Role' do
|
||||||
|
it 'should have :built_in false' do
|
||||||
|
@role.built_in.should be false
|
||||||
|
end
|
||||||
|
it 'should have :disabled false' do
|
||||||
|
@role.disabled.should be false
|
||||||
|
end
|
||||||
|
it 'should have a i18n_variable' do
|
||||||
|
@role.i18n_variable.should be_an_instance_of I18nVariable
|
||||||
|
end
|
||||||
|
it 'should create sub_roles' do
|
||||||
|
@role.should have(2).sub_roles
|
||||||
|
end
|
||||||
|
it 'should create attribute_fields' do
|
||||||
|
@role.sub_roles[1].should have(1).attribute_fields
|
||||||
|
end
|
||||||
|
end
|
||||||
|
describe '#SubRole' do
|
||||||
|
it 'should have :built_in false' do
|
||||||
|
@role.sub_roles[0].built_in.should be false
|
||||||
|
end
|
||||||
|
it 'should have :disabled false' do
|
||||||
|
@role.sub_roles[0].disabled.should be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
describe '#AttributeField' do
|
||||||
|
it 'should have :built_in false' do
|
||||||
|
@role.sub_roles[0].attribute_fields[0].built_in.should be false
|
||||||
|
end
|
||||||
|
it 'should have :disabled false' do
|
||||||
|
@role.sub_roles[0].attribute_fields[0].disabled.should be false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
describe 'Edit role' do
|
||||||
|
describe '#Role' do
|
||||||
|
before do
|
||||||
|
@role.update_attributes({:key => 'student', :i18n_variable => {:en => 'Student'},
|
||||||
|
:sub_roles => [{:key => 'new',
|
||||||
|
:attribute_fields => [{:key => 'bob'},
|
||||||
|
{:key => 'great'}]},
|
||||||
|
{:id => @role.sub_roles[0].id},
|
||||||
|
{:id => @role.sub_roles[1].id}]})
|
||||||
|
end
|
||||||
|
it 'should not be the old :key' do
|
||||||
|
@role.key.should_not == 'teacher'
|
||||||
|
end
|
||||||
|
it 'should be the new :key' do
|
||||||
|
@role.key.should == 'student'
|
||||||
|
end
|
||||||
|
it 'should not be the old :i18n_variable[:en]' do
|
||||||
|
@role.i18n_variable[:en].should_not == 'Teacher'
|
||||||
|
end
|
||||||
|
it 'should be the new :i18n_variable[:en]' do
|
||||||
|
@role.i18n_variable[:en].should == 'Student'
|
||||||
|
end
|
||||||
|
it 'should have one more SubRole' do
|
||||||
|
@role.should have(3).sub_roles
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
describe 'Destroy' do
|
||||||
|
describe '#AttributeField' do
|
||||||
|
before do
|
||||||
|
@role.update_attributes(:key => 'teacher',
|
||||||
|
:i18n_variable => {:key => 'teacher', :en => 'Teacher', :zh_tw => 'Teacher in Chinese', :document_class => 'Role'},
|
||||||
|
:sub_roles_attributes => {'0' => {:id => @role.sub_roles[0].id,
|
||||||
|
:key => 'undergrad',
|
||||||
|
:attribute_fields_attributes => {'0' => {:id => @role.sub_roles[0].attribute_fields[0].id,
|
||||||
|
:key => 'department'},
|
||||||
|
'1' => {:id => @role.sub_roles[0].attribute_fields[1].id,
|
||||||
|
:key => 'room', :_destroy => true}}}})
|
||||||
|
end
|
||||||
|
it 'should have only one AttributeField for the first SubRole' do
|
||||||
|
@role.sub_roles[0].should have(1).attribute_fields
|
||||||
|
end
|
||||||
|
end
|
||||||
|
describe '#I18nVariable' do
|
||||||
|
before do
|
||||||
|
@role.update_attributes(:key => 'teacher',
|
||||||
|
:i18n_variable_attributes => {:id => @role.i18n_variable.id, :key => 'teacher', :en => 'Teacher', :zh_tw => 'Teacher in Chinese', :document_class => 'Role', :_destroy => true})
|
||||||
|
end
|
||||||
|
it 'should not have a I18nVariable' do
|
||||||
|
@role.i18n_variable.should_not be_an_instance_of I18nVariable
|
||||||
|
end
|
||||||
|
end
|
||||||
|
describe '#Role' do
|
||||||
|
it 'should destroy the I18nVariable' do
|
||||||
|
id = @role.i18n_variable.id
|
||||||
|
@role.destroy
|
||||||
|
lambda {I18nVariable.find(id)}.should raise_error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -1,4 +0,0 @@
|
||||||
--colour
|
|
||||||
--format progress
|
|
||||||
--loadby mtime
|
|
||||||
--reverse
|
|
|
@ -1,27 +1,58 @@
|
||||||
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
require 'rubygems'
|
||||||
ENV["RAILS_ENV"] ||= 'test'
|
require 'spork'
|
||||||
require File.expand_path("../../config/environment", __FILE__)
|
|
||||||
require 'rspec/rails'
|
|
||||||
|
|
||||||
# Requires supporting ruby files with custom matchers and macros, etc,
|
Spork.prefork do
|
||||||
# in spec/support/ and its subdirectories.
|
# Loading more in this block will cause your tests to run faster. However,
|
||||||
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
# if you change any configuration or code from libraries loaded here, you'll
|
||||||
|
# need to restart spork for it take effect.
|
||||||
|
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
||||||
|
ENV["RAILS_ENV"] ||= 'test'
|
||||||
|
require File.expand_path("../../config/environment", __FILE__)
|
||||||
|
require 'rspec/rails'
|
||||||
|
require 'rspec/autorun'
|
||||||
|
|
||||||
RSpec.configure do |config|
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
||||||
# == Mock Framework
|
# in spec/support/ and its subdirectories.
|
||||||
#
|
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
|
||||||
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
|
||||||
#
|
|
||||||
# config.mock_with :mocha
|
|
||||||
# config.mock_with :flexmock
|
|
||||||
# config.mock_with :rr
|
|
||||||
config.mock_with :rspec
|
|
||||||
|
|
||||||
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
RSpec.configure do |config|
|
||||||
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
# == Mock Framework
|
||||||
|
#
|
||||||
|
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
||||||
|
#
|
||||||
|
# config.mock_with :mocha
|
||||||
|
# config.mock_with :flexmock
|
||||||
|
# config.mock_with :rr
|
||||||
|
config.mock_with :rspec
|
||||||
|
|
||||||
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
||||||
# examples within a transaction, remove the following line or assign false
|
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
||||||
# instead of true.
|
|
||||||
config.use_transactional_fixtures = true
|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
||||||
|
# examples within a transaction, remove the following line or assign false
|
||||||
|
# instead of true.
|
||||||
|
# config.use_transactional_fixtures = true
|
||||||
|
|
||||||
|
# If true, the base class of anonymous controllers will be inferred
|
||||||
|
# automatically. This will be the default behavior in future versions of
|
||||||
|
# rspec-rails.
|
||||||
|
config.infer_base_class_for_anonymous_controllers = false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Spork.each_run do
|
||||||
|
# This code will be run each time you run your specs.
|
||||||
|
load "#{Rails.root}/config/routes.rb"
|
||||||
|
Dir["#{Rails.root}/app/**/*.rb"].each { |f| load f }
|
||||||
|
end
|
||||||
|
|
||||||
|
# --- Instructions ---
|
||||||
|
# - Sort through your spec_helper file. Place as much environment loading
|
||||||
|
# code that you don't normally modify during development in the
|
||||||
|
# Spork.prefork block.
|
||||||
|
# - Place the rest under Spork.each_run block
|
||||||
|
# - Any code that is left outside of the blocks will be ran during preforking
|
||||||
|
# and during each_run!
|
||||||
|
# - These instructions should self-destruct in 10 seconds. If they don't,
|
||||||
|
# feel free to delete them.
|
||||||
|
#
|
|
@ -1,5 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe "design/create.html.erb" do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
|
@ -1,5 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe "design/destroy.html.erb" do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
|
@ -1,5 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe "design/edit.html.erb" do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
|
@ -1,5 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe "design/index.html.erb" do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
|
@ -1,5 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe "design/new.html.erb" do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
|
@ -1,5 +0,0 @@
|
||||||
require 'spec_helper'
|
|
||||||
|
|
||||||
describe "design/update.html.erb" do
|
|
||||||
pending "add some examples to (or delete) #{__FILE__}"
|
|
||||||
end
|
|
Loading…
Reference in New Issue