basic function

This commit is contained in:
Matthew K. Fu JuYuan 2012-09-17 12:06:21 +08:00
parent 7f290adfbb
commit 8e014bf59c
26 changed files with 420 additions and 185 deletions

View File

@ -5,20 +5,63 @@ class Admin::UsersNewInterfaceController < ApplicationController
before_filter :set_attribute, :only => [:index, :show, :new, :edit]
def index
@users = User.all.entries
get_tags
get_sub_roles
page_num = params[:page] || 1
@users = []
render case params[:at]
when 'summary'
@users=User.page(page_num).per(12).includes('avatar')
"index_summary"
when 'thumbnail'
@users=User.page(page_num).per(36).includes('avatar')
"index_thumbnail"
else
@users=User.page(page_num).per(10).includes('avatar')
"index"
end
end
def show
@user = User.find(params[:id])
@profile_data = []
@teacher_data = []
@student_data = []
@staff_data = []
@user.attribute_values.each{|att_val|
@profile_data.push({:name => att_val.attribute_field.title,:value =>att_val[I18n.locale]}) if att_val.attribute_field.attribute.key=="profile" rescue false
}
@user.attribute_values.each{|att_val|
@teacher_data.push({:name => att_val.attribute_field.title,:value => eval("att_val.#{att_val.key}")}) if att_val.attribute_field.role.key=="teacher"rescue false
}
@user.attribute_values.each{|att_val|
@student_data.push({:name => att_val.attribute_field.title,:value =>eval("att_val.#{att_val.key}")}) if att_val.attribute_field.role.key=="student"rescue false
}
@user.attribute_values.each{|att_val|
@staff_data.push({:name => att_val.attribute_field.title,:value =>eval("att_val.#{att_val.key}")}) if att_val.attribute_field.role.key=="staff_data"rescue false
}
# binding.pry
# @user.attribute_values.each{|att_val|
# @teacher_data.push({:name => att_val.attribute_field.title,:value =>att_val[I18n.locale]})
# }
# @user.attribute_values.each{|att_val|
# @student_data.push({:name => att_val.attribute_field.title,:value =>att_val[I18n.locale]})
# }
# @user.attribute_values.each{|att_val|
# @staff_data.push({:name => att_val.attribute_field.title,:value =>att_val[I18n.locale]})
# }
# [ {:name=> "1",:value =>"Matt"},{:name=> "2",:value =>"Mark"},{:name=> "3",:value =>"Luke"},{:name=> "4",:value =>"John"} ]
get_info_and_roles
end
@ -74,7 +117,14 @@ class Admin::UsersNewInterfaceController < ApplicationController
end
protected
def get_tags
@sub_role_tags = SubRoleTag.all
end
def get_sub_roles
@sub_roles = SubRole.all
end
def get_info_and_roles
@infos = Info.excludes('disabled' => true)
@roles = Role.excludes('disabled' => true)

View File

@ -260,4 +260,13 @@ module ApplicationHelper
wrap_mark = options[:wrap_mark] || "<br />"
str.scan((/.{0,#{line_width}}/)).join(wrap_mark)
end
def show_avatar(user)
if (user.avatar? rescue false)
image_tag(user.avatar.thumb.url)
else
image_tag "person.png"
end
end
end

40
app/models/proto_tag.rb Normal file
View File

@ -0,0 +1,40 @@
class ProtoTag
include Mongoid::Document
include Mongoid::Timestamps
include Impressionist::Impressionable
is_impressionable :counter_cache => { :column_name => :view_count }
field :key
field :view_count, :type => Integer, :default => 0
#field :cloud_amper,:type: Integer,:default=> 0
def self.sorted_for_cloud
tags = {}
self.all.each{ |tag|
tags.merge!({tag => self.get_impressionist(tag)})
}
if !tags.blank?
sorted_tags = tags.sort{|a,b| a[1]<=>b[1]}.reverse
sorted_tags[0][1] = :hot1
offset = (sorted_tags.size - 1) / 3
i = 1
class_i = 2
sorted_tags[1..-1].collect!{ |x|
x[1] = "hot#{class_i}"
i == offset ? i = 1 : i += 1 if class_i < 4
class_i += 1 if i == offset && class_i < 4
}
sorted_tags
else
[]
end
end
protected
def self.get_impressionist(item_tag = self)
item_tag.impressions.where(:created_at.gte=> 14.days.ago,:created_at.lte => Time.now).count
end
end

View File

@ -0,0 +1,4 @@
class SubRoleTag < ProtoTag
has_and_belongs_to_many :sub_roles
end

View File

@ -1,41 +1,4 @@
class Tag
include Mongoid::Document
include Mongoid::Timestamps
include Impressionist::Impressionable
is_impressionable :counter_cache => { :column_name => :view_count }
field :key
field :view_count, :type => Integer, :default => 0
#field :cloud_amper,:type: Integer,:default=> 0
class Tag < ProtoTag
belongs_to :module_app
def self.sorted_for_cloud
tags = {}
self.all.each{ |tag|
tags.merge!({tag => self.get_impressionist(tag)})
}
if !tags.blank?
sorted_tags = tags.sort{|a,b| a[1]<=>b[1]}.reverse
sorted_tags[0][1] = :hot1
offset = (sorted_tags.size - 1) / 3
i = 1
class_i = 2
sorted_tags[1..-1].collect!{ |x|
x[1] = "hot#{class_i}"
i == offset ? i = 1 : i += 1 if class_i < 4
class_i += 1 if i == offset && class_i < 4
}
sorted_tags
else
[]
end
end
protected
def self.get_impressionist(item_tag = self)
item_tag.impressions.where(:created_at.gte=> 14.days.ago,:created_at.lte => Time.now).count
end
end

View File

@ -4,7 +4,7 @@ class AttributeField
include Mongoid::Timestamps
field :key
field :markup
field :markup #[select,text_field,email,date,addr]
field :locale, :type => Boolean, :default => true
field :list_options, :type => Array
field :built_in, :type => Boolean, :default => false
@ -15,10 +15,14 @@ class AttributeField
field :neutral_title
belongs_to :attribute
belongs_to :role
# belongs_to :role
has_many :attribute_values
# validates_uniqueness_of :key
def role
self.attribute.role
end
def title_translations
if locale
return locale_title_translations
@ -29,7 +33,7 @@ class AttributeField
def title_translations=(var)
if locale
self.locale_title = var
self.locale_title_translations = var
end
end

View File

@ -2,9 +2,12 @@ class Status
include Mongoid::Document
include Mongoid::Timestamps
has_and_belongs_to_many :users
belongs_to :role
has_and_belongs_to_many :sub_roles
# has_and_belongs_to_many :sub_roles
field :title, localize: true

View File

@ -2,7 +2,9 @@ class SubRole < Attribute
belongs_to :role
has_and_belongs_to_many :users
has_and_belongs_to_many :statuses, :autosave => true, :dependent => :destroy
#has_and_belongs_to_many :statuses, :autosave => true, :dependent => :destroy
has_and_belongs_to_many :tags, :class_name => "SubRoleTag", :autosave => true
# Get an sub_role from key
def self.get_sub_role_from_key(key)
self.first(:conditions => {:key => key})

View File

@ -14,6 +14,7 @@ class User
# field :cache_dept
# has_one :cache_dept, :class_name => "I18nVariable", :as => :language_value, :autosave => true, :dependent => :destroy
field :cache_dept,type: Hash
field :status_record,type: Hash
has_many :attribute_values, :autosave => true, :dependent => :destroy
has_many :app_auths,as: :privilege_apps,:inverse_of => :privilege_lists
@ -25,9 +26,9 @@ class User
has_many :other_accounts, :autosave => true, :dependent => :destroy
has_many :journals, :autosave => true, :dependent => :destroy
has_many :papers, :autosave => true, :dependent => :destroy
has_and_belongs_to_many :sub_role_tags
belongs_to :role
has_and_belongs_to_many :statuses
has_and_belongs_to_many :roles
has_and_belongs_to_many :sub_roles
accepts_nested_attributes_for :attribute_values, :allow_destroy => true

View File

@ -0,0 +1,16 @@
<div class="quick-edit">
<ul class="nav nav-pills hide">
<li><a href="#"><%= t("admin.new_admin.action.edit")%> </a></li>
<li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle"><%= t("admin.new_admin.action.quick_edit")%><b class="caret"></b></a>
<ul class="dropdown-menu" id="menu1">
<li><a href="#"># TODO:Basic</a></li>
<li><a href="#"># TODO:Picture</a></li>
<li><a href="#"># TODO:Tags</a></li>
<li><a href="#"># TODO:Link</a></li>
<li><a href="#"># TODO:File</a></li>
</ul>
</li>
<li><a href="#"><%= t("admin.new_admin.action.delete")%></a></li>
</ul>
</div>

View File

@ -37,8 +37,9 @@
</div>
<div class="accordion-body collapse" id="collapse-category">
<div class="accordion-inner" data-toggle="buttons-checkbox">
<a href="#" class="btn">Category1</a>
<a href="#" class="btn">Category2</a>
<% @sub_roles.each do |sr|%>
<a href="#" class="btn"><%= sr.title%></a>
<% end -%>
</div>
<div class="filter-clear">
<a href="#" class="btn"><i class="icons-brush-large"></i><%= t("admin.new_admin.table_header.clear_filter")%></a>
@ -46,26 +47,9 @@
</div>
<div class="accordion-body collapse" id="collapse-tags">
<div class="accordion-inner" data-toggle="buttons-checkbox">
<a href="#" class="btn">Tag1</a>
<a href="#" class="btn">Tag2</a>
<a href="#" class="btn">Tag3</a>
<a href="#" class="btn">Tag4</a>
<a href="#" class="btn">Tag5</a>
<a href="#" class="btn">Tag6</a>
<a href="#" class="btn">Tag7</a>
<a href="#" class="btn">Tag8</a>
<a href="#" class="btn">Tag9</a>
<a href="#" class="btn">Tag10</a>
<a href="#" class="btn">Tag11</a>
<a href="#" class="btn">Tag12</a>
<a href="#" class="btn">Tag13</a>
<a href="#" class="btn">Tag14</a>
<a href="#" class="btn">Tag15</a>
<a href="#" class="btn">Tag16</a>
<a href="#" class="btn">Tag17</a>
<a href="#" class="btn">Tag18</a>
<a href="#" class="btn">Tag19</a>
<a href="#" class="btn">Tag20</a>
<% @sub_role_tags.each do |sr_tag|%>
<a href="#" class="btn"><%= sr_tag[I18n.locale] %></a>
<% end -%>
</div>
<div class="filter-clear">
<a href="#" class="btn"><i class="icons-brush-large"></i><%= t("admin.new_admin.table_header.clear_filter")%></a>

View File

@ -1,17 +1,8 @@
<div class="form-actions form-fixed pagination-right">
<div class="form-actions form-fixed pagination-right">
<%= link_to(new_admin_users_new_interface_path,:class=> "btn btn-primary pull-right") do%>
<i class="icon-plus icon-white"></i><%= t("admin.new_admin.action.add")%>
<% end -%>
<div class="paginationFixed">
<div class="pagination">
<ul>
<li><a href="#"><%= t("admin.new_admin.action.prev")%></a></li>
<li class="active"><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#"><%= t("admin.new_admin.action.next")%></a></li>
</ul>
</div>
<div class="paginationFixed" id="user_pagination">
<%= paginate @users, :params => {:inner => false}%>
</div>
</div>

View File

@ -0,0 +1,7 @@
<% content_for :page_specific_css do -%>
<%= stylesheet_link_tag "member" %>
<%= stylesheet_link_tag "item"%>
<% end -%>
<% content_for :page_specific_javascript do -%>
<%#= javascript_include_tag "/static/jquery.cycle.all.latest.js" %>
<% end -%>

View File

@ -0,0 +1,7 @@
<%#= render_sort_bar(true, delete_admin_assets_path(:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil, :sort_options => params[:sort_options]),
['title', 'title','span4', 'admin.title'],
['description', 'description', 'span1-2', 'admin.data'],
['intro', 'intro', 'span1-2', 'admin.file_type'],
['intro', 'intro', 'span1-2', 'admin.file_length'],
['intro', 'intro', 'span1-2', 'admin.description'],
['intro', 'intro', 'span1-2', 'admin.tags']).html_safe %>

View File

@ -2,36 +2,21 @@
<td class="span1"><input type="checkbox"></td>
<td class="span3">
<div class="label-group">
<div class="label-td">
<div class="label-td"><!--
<span class="label label-teacher"># TODO:Teacher</span>
<span class="label label-student"># TODO:Student</span>
<span class="label label-staff"># TODO:Staff</span>
<span class="label label-staff"># TODO:Staff</span> -->
</div>
</div>
</td>
<td class="span1-2">
<%= user_for_listing.name %>
<div class="quick-edit">
<ul class="nav nav-pills hide">
<li><a href="#"><%= t("admin.new_admin.action.edit")%> </a></li>
<li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle"><%= t("admin.new_admin.action.quick_edit")%><b class="caret"></b></a>
<ul class="dropdown-menu" id="menu1">
<li><a href="#"># TODO:Basic</a></li>
<li><a href="#"># TODO:Picture</a></li>
<li><a href="#"># TODO:Tags</a></li>
<li><a href="#"># TODO:Link</a></li>
<li><a href="#"># TODO:File</a></li>
</ul>
</li>
<li><a href="#"><%= t("admin.new_admin.action.delete")%></a></li>
</ul>
</div>
<%= link_to user_for_listing.name,admin_users_new_interface_path(user_for_listing) %>
<%#= render "deled_quick_edit"%>
</td>
<td class="span2"># TODO</td>
<td class="span2"># TODO</td>
<td class="span2"><%= Random.rand(1000)%></td>
<td class="span2"><%= Random.rand(10)%></td>
<td class="span2">
10,597
<%= Random.rand(10000)%>
<p class="gender male"></p>
</td>
</tr>

View File

@ -11,11 +11,11 @@
<p class="gender male"></p>
<div class="user-avatar pull-left">
<p class="reflective"></p>
<%= image_tag(user_for_summary.avatar.thumb.url) %>
<%= show_avatar(user_for_summary) %>
</div>
<div class="user-meta">
<p class="user-name">
<%= user_for_summary.name%>
<%= link_to user_for_summary.name,admin_users_new_interface_path(user_for_summary)%>
</p>
<div class="user-title">
<span>#TODO 教授兼系主任</span><span>#TODO 大學部校友</span>

View File

@ -11,11 +11,11 @@
<p class="gender male"></p>
<div class="user-avatar">
<p class="reflective"></p>
<%= image_tag(user_for_thumbnail.avatar.thumb.url) %>
<%= show_avatar(user_for_thumbnail) %>
</div>
<div class="user-meta">
<p class="user-name">
<%= user_for_thumbnail.name%>
<%= link_to user_for_thumbnail.name,admin_users_new_interface_path(user_for_thumbnail)%>
</p>
</div>
</div>

View File

@ -1,18 +1,20 @@
<%= render :partial => "filter"%>
<table class="table main-list member-list">
<thead>
<tr>
<th class="span1"></th>
<th class="span3"></th>
<th class="span1-2"></th>
<th class="span2"></th>
<th class="span2"></th>
<th class="span2"></th>
</tr>
</thead>
<tbody>
<%= render :partial => "user_for_listing",:collection=> [@users.first]%>
</tbody>
</table>
<%= render :partial => "js_and_css"%>
<%= render :partial=> "index_paginator" %>
<%= render :partial => "filter"%>
<table class="table main-list member-list">
<thead>
<tr>
<th class="span1"></th>
<th class="span3"></th>
<th class="span1-2"></th>
<th class="span2"></th>
<th class="span2"></th>
<th class="span2"></th>
</tr>
</thead>
<tbody id="tbody_users">
<%= render :partial => "user_for_listing",:collection=> @users%>
</tbody>
</table>
<%= render :partial=> "index_paginator" %>

View File

@ -0,0 +1,3 @@
$("#sort_headers").html("<%= j render 'sort_headers' %>");
$("#tbody_users").html("<%= j render :partial => 'user_for_listing', :collection => @users %>");
$("#user_pagination").html("<%= j paginate @users, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil} %>");

View File

@ -1,9 +1,9 @@
<%= render :partial => "filter"%>
<div class="member-abstract">
<ul class="clear">
<% 5.times do %>
<%= render :partial=>"user_for_summary",:collection=> [@users.first]%>
<% end -%>
</ul>
</div>
<%= render :partial=> "index_paginator" %>
<%= render :partial => "js_and_css"%>
<%= render :partial => "filter"%>
<div class="member-abstract">
<ul class="clear" id="summary_block_users">
<%= render :partial=>"user_for_summary",:collection=> @users%>
</ul>
</div>
<%= render :partial=> "index_paginator" %>

View File

@ -0,0 +1,3 @@
$("#sort_headers").html("<%= j render 'sort_headers' %>");
$("#summary_block_users").html("<%= j render :partial => 'user_for_summary', :collection => @users %>");
$("#user_pagination").html("<%= j paginate @users, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil} %>");

View File

@ -1,8 +1,8 @@
<%= render :partial => "filter"%>
<div class="member-large">
<ul class="clear">
<% 5.times do %>
<%= render :partial=>"user_for_thumbnail",:collection=> [@users.first]%>
<% end -%>
</div>
<%= render :partial=> "index_paginator" %>
<%= render :partial => "js_and_css"%>
<%= render :partial => "filter"%>
<div class="member-large">
<ul class="clear" id="thumbnail_block_users">
<%= render :partial=>"user_for_thumbnail",:collection=> @users%>
</div>
<%= render :partial=> "index_paginator" %>

View File

@ -0,0 +1,3 @@
$("#sort_headers").html("<%= j render 'sort_headers' %>");
$("#thumbnail_block_users").html("<%= j render :partial => 'user_for_thumbnail', :collection => @users %>");
$("#user_pagination").html("<%= j paginate @users, :params => {:direction => params[:direction], :sort => params[:sort], :filter => @filter, :new_filter => nil} %>");

View File

@ -1,3 +1,5 @@
<%= render :partial => "js_and_css"%>
<div id="isotope" class="user-data">
<div id="module-nav">
<div class="arrow_next pull-right"><i class="icon-chevron-right"></i></div>
@ -16,7 +18,7 @@
</div>
</div>
<div class="member-plugin">
<% binding.pry%>
<% #binding.pry%>
<%= render :partial=> 'plugin_summary'%>
<%= render :partial=> 'plugin_summary'%>
<%= render :partial=> 'plugin_summary'%>
@ -27,7 +29,7 @@
<p class="gender male"></p>
<div class="user-avatar pull-left">
<p class="reflective"></p>
<img src="images/menber-pic.png">
<%= show_avatar(@user) %>
</div>
<p class="user-name">
<%= @user.name%>
@ -47,11 +49,10 @@
</div>
<div class="viewport">
<div class="overview">
<% test_items = [ {:name=> "1",:value =>"Matt"},{:name=> "2",:value =>"Mark"},{:name=> "3",:value =>"Luke"},{:name=> "4",:value =>"John"} ]%>
<%= render :partial=> "user_role",:locals=>{:role_class=>"basic",:i18n=>"admin.new_admin.users.profile",:items=>test_items} %>
<%= render :partial=> "user_role",:locals=>{:role_class=>"teacher",:i18n=>"admin.new_admin.users.roles.teacher",:items=>test_items} %>
<%= render :partial=> "user_role",:locals=>{:role_class=>"student",:i18n=>"admin.new_admin.users.roles.student",:items=>test_items}%>
<%= render :partial=> "user_role",:locals=>{:role_class=>"staff",:i18n=>"admin.new_admin.users.roles.staff",:items=>test_items} %>
<%= render :partial=> "user_role",:locals=>{:role_class=>"basic",:i18n=>"admin.new_admin.users.profile",:items=>@profile_data} %>
<%= render :partial=> "user_role",:locals=>{:role_class=>"teacher",:i18n=>"admin.new_admin.users.roles.teacher",:items=>@teacher_data} %>
<%= render :partial=> "user_role",:locals=>{:role_class=>"student",:i18n=>"admin.new_admin.users.roles.student",:items=>@student_data}%>
<%= render :partial=> "user_role",:locals=>{:role_class=>"staff",:i18n=>"admin.new_admin.users.roles.staff",:items=>@staff_data} %>
</div>
<div>
</div>

View File

@ -37,14 +37,13 @@
<%# end -%>
<%= content_tag :li, :class => active_for_controllers('users_new_interface') do -%>
<%= link_to content_tag(:i, nil, :class => 'icons-page') + t('admin.new_admin.user'), admin_users_new_interface_index_path %>
<%= link_to content_tag(:i, nil, :class => 'icons-page')+ content_tag(:span, t('admin.new_admin.user')), admin_users_new_interface_index_path %>
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('users_new_interface')) do -%>
<%= content_tag :li, link_to(t('admin.new_admin.side_bar.all_user'), ), :class => active_for_action('users_new_interface', 'index') %>
<%= content_tag :li, link_to("#TODO Role1", ), :class => active_for_action('users_new_interface', 'index') %>
<%= content_tag :li, link_to(t("#TODO Role2"), ), :class => active_for_action('users_new_interface', 'index') %>
<%= content_tag :li, link_to(t('admin.new_admin.side_bar.add_user')) %>
<%= content_tag :li, link_to(t('admin.new_admin.side_bar.user_roles')) %>
<%= content_tag :li, link_to(t('admin.new_admin.side_bar.user_info')) %>
<%= content_tag :li, link_to((t('admin.new_admin.side_bar.all_user') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, admin_users_new_interface_index_path), :class => active_for_action('users_new_interface', 'index') %>
<%= content_tag :li, link_to((t('admin.new_admin.side_bar.add_user') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, ), :class => active_for_action('users_new_interfacexx', 'index') %>
<%= content_tag :li, link_to((t('admin.new_admin.side_bar.user_roles') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, ), :class => active_for_action('users_new_interfacexx', 'index') %>
<%= content_tag :li, link_to((t('admin.new_admin.side_bar.user_info') + content_tag(:i, nil, :class => 'icon-chevron-right')).html_safe, ), :class => active_for_action('users_new_interfacexx', 'index') %>
<% end -%>
<% end -%>

View File

@ -1,6 +1,137 @@
# encoding: utf-8
namespace :build_new_member do
task :sub_role_tags_generate => :environment do
SubRoleTag.destroy_all
role_keys = %w{teacher staff student}
role_keys.each do |role_key|
role = Role.first({conditions:{key: role_key}})
puts "Starting with Role with key: #{role_key}"
role.sub_roles.each do |sr|
puts "Role : #{role_key} => #{sr.title}"
for i in 1..7
sr.tags.build(:en => "Students-#{sr.title_translations['en']}_#{i}" , :zh_tw => "在校學生-#{sr.title_translations['zh_tw']}_#{i}" , :key => "#{role_key}_#{sr.title_translations['en'].parameterize}_#{i}" )
end
sr.save
end
end
end
task :fields_for_teacher => :environment do
sub_role_attribute_fields_template = [
{key: 'status', markup: "text_field", locale: true, list_options: nil, built_in: true, disabled: false, locale_title_translations: {"zh_tw"=>"狀態", "en"=>"Status"}, neutral_title: nil },
{key: 'other_position', markup: "text_field", locale: true, list_options: nil, built_in: true, disabled: false, locale_title_translations: {"zh_tw"=>"其他職位", "en"=>"Other Position"}, neutral_title: nil },
{key: 'research_domain', markup: "text_field", locale: true, list_options: nil, built_in: true, disabled: false, locale_title_translations: {"zh_tw"=>"研究領域", "en"=>"Research Domain"}, neutral_title: nil },
{key: 'teaching_domain', markup: "text_field", locale: true, list_options: nil, built_in: true, disabled: false, locale_title_translations: {"zh_tw"=>"授課領域", "en"=>"Teaching Domain"}, neutral_title: nil }
]
role = Role.first({conditions:{key: 'teacher'}})
role.sub_roles.each{|sb|
sb.attribute_fields.destroy_all
sub_role_attribute_fields_template.each{|att_f|
sb.attribute_fields.build att_f
}
sb.save
}
end
task :fields_for_student => :environment do
sub_role_attribute_fields_template = [
{key: 'status', markup: "text_field", locale: true, list_options: nil, built_in: true, disabled: false, locale_title_translations: {"zh_tw"=>"狀態", "en"=>"Status"}, neutral_title: nil },
{key: 'entrance_year', markup: "text_field", locale: true, list_options: nil, built_in: true, disabled: false, locale_title_translations: {"zh_tw"=>"入學年", "en"=>"Entrance Year"}, neutral_title: nil },
{key: 'graduation_date', markup: "text_field", locale: true, list_options: nil, built_in: true, disabled: false, locale_title_translations: {"zh_tw"=>"屆別", "en"=>"Graduation Date"}, neutral_title: nil },
{key: 'actual_graduation', markup: "text_field", locale: true, list_options: nil, built_in: true, disabled: false, locale_title_translations: {"zh_tw"=>"實際畢業年", "en"=>"Actual Graduation"}, neutral_title: nil }
]
role = Role.first({conditions:{key: 'student'}})
role.sub_roles.each{|sb|
sb.attribute_fields.destroy_all
sub_role_attribute_fields_template.each{|att_f|
sb.attribute_fields.build att_f
}
sb.save
}
end
task :fields_for_staff => :environment do
sub_role_attribute_fields_template = [
{key: 'status', markup: "text_field", locale: true, list_options: nil, built_in: true, disabled: false, locale_title_translations: {"zh_tw"=>"狀態", "en"=>"Status"}, neutral_title: nil },
{key: 'responsibilities', markup: "text_field", locale: true, list_options: nil, built_in: true, disabled: false, locale_title_translations: {"zh_tw"=>"負責業務", "en"=>"Responsibilities"}, neutral_title: nil }
]
role = Role.first({conditions:{key: 'staff'}})
role = Role.create!({key: "staff", built_in: true, disabled: false, title_translations: {"en"=>"Staff", "zh_tw"=>"行政人員"}}) if role.nil?
role.sub_roles.each{|sb|
sb.attribute_fields.destroy_all
sub_role_attribute_fields_template.each{|att_f|
sb.attribute_fields.build att_f
}
sb.save
}
end
task :matt_data => :environment do
b = User.first({conditions:{email: 'matt@rulingcom.com'}})
b.attribute_values.destroy_all
data = [{:key=> 'last_name',:en=>'Fu',:zh_tw=>'傅'},
{:key=> 'first_name',:en=>'Matt',:zh_tw=>'儒淵'},
{:key=> 'nick_name',:en=> 'Matt K.',:zh_tw=> 'Matt K.'},
{:key=> 'addr',:en=>'Earth',:zh_tw=>'302新竹縣竹北市嘉豐南路二段101號'},
{:key=> 'phone',:en=>'035508881',:zh_tw=>'035508881'},
{:key=> 'gender',:en=>'Male',:zh_tw=>'男'},
{:key=> 'birthday',:en=>'1986',:zh_tw=>'1986'},
{:key=> 'email',:en=>'matt@rulingcom.com',:zh_tw=>'matt@rulingcom.com'}]
data_hash = Hash[data.map{|t| [t[:key],t] }]
Info.first.attribute_fields.each do |profile_field|
b.attribute_values.build(data_hash.fetch(profile_field.key).merge({:attribute_field_id=>profile_field.id}))
end
#==================================================================
b.roles = []
b.roles << Role.first({conditions:{key: 'teacher'}})
b.roles << Role.first({conditions:{key: 'student'}})
#==================================================================
b.sub_roles = []
sr_1 = b.roles.first.sub_roles.last
sr_2 = b.roles.last.sub_roles.last
b.sub_roles << sr_1 #use teacher data
b.sub_roles << sr_2 #use student data
#==================================================================
# to get field for fast fill up: sr_2.attribute_fields.map{|t| Hash[t.key,nil]}
{"status"=>"兼職","research_domain"=>"神經網絡","teaching_domain"=>"平行運算"}.each do |key, value|
field = sr_1.attribute_fields.where({key: key}).first
b.attribute_values.build({key=>value}.merge({:key=>field.key,:attribute_field_id=>field.id}))
end
{"status"=>"在學中","entrance_year"=>2010}.each do |key, value|
field = sr_2.attribute_fields.where({key: key}).first
b.attribute_values.build({key=>value}.merge({:key=>field.key,:attribute_field_id=>field.id}))
end
# b.attribute_values.build :key=> 'last_name',:en=>'Fu',:zh_tw=>'傅'
# b.attribute_values.build :key=> 'first_name',:en=>'Matt',:zh_tw=>'儒淵'
# b.attribute_values.build :key=> 'nick_name',:en=> 'Matt K.',:zh_tw=> 'Matt K.'
# b.attribute_values.build :key=> 'addr',:en=>'Earth',:zh_tw=>'302新竹縣竹北市嘉豐南路二段101號'
# b.attribute_values.build :key=> 'phone',:en=>'035508881',:zh_tw=>'035508881'
# b.attribute_values.build :key=> 'gender',:en=>'Male',:zh_tw=>'男'
# b.attribute_values.build :key=> 'birthday',:en=>'1986',:zh_tw=>'1986'
# b.attribute_values.build :key=> 'email',:en=>'matt@rulingcom.com',:zh_tw=>'matt@rulingcom.com'
b.save
end
task :chris_data => :environment do
b = User.first({conditions:{email: 'chris@rulingcom.com'}})
b.attribute_values.destroy_all
b.attribute_values.build :key=> 'last_name',:en=>'Vilayphiou',:zh_tw=>'林'
b.attribute_values.build :key=> 'first_name',:en=>'Christophe',:zh_tw=>'順發'
b.attribute_values.build :key=> 'nick_name',:en=> 'Chris',:zh_tw=> 'Chris'
b.attribute_values.build :key=> 'addr',:en=>'asdsaddasdasd',:zh_tw=>'302新竹縣竹北市嘉豐南路二段101號'
b.attribute_values.build :key=> 'phone',:en=>'035508881',:zh_tw=>'035508881'
b.attribute_values.build :key=> 'gender',:en=>'Male',:zh_tw=>'男'
b.attribute_values.build :key=> 'birthday',:en=>'1990',:zh_tw=>'1990'
b.attribute_values.build :key=> 'email',:en=>'chris@rulingcom.com',:zh_tw=>'chris@rulingcom.com'
b.save
end
task :module_app => :environment do
ModuleApp.create!(:key=>"new_member",
:title=>"new_member",
@ -43,40 +174,67 @@ namespace :build_new_member do
student_role.save
p "==Finished building sub_roles for Students"
staff_role = Role.first({conditions:{key: 'staff'}})
staff_role.sub_roles.destroy_all
staff_sub_roles ={
:general => {"zh_tw"=>"一般", "en"=>"General"}
}
staff_sub_roles.each do |key,title|
staff_role.sub_roles.build :key=>key,:title_translations=>title,:built_in=>true
puts "=SubRole key:#{key}\t Title:#{title}"
end
staff_role.save
p "==Finished building sub_roles for Staff"
staff_role = Role.first({conditions:{key: 'staff'}})
staff_role.sub_roles.destroy_all
staff_sub_roles ={
:general => {"zh_tw"=>"一般", "en"=>"General"}
}
staff_sub_roles.each do |key,title|
staff_role.sub_roles.build :key=>key,:title_translations=>title,:built_in=>true
puts "=SubRole key:#{key}\t Title:#{title}"
end
staff_role.save
p "==Finished building sub_roles for Staff"
end
task :status => :environment do
teacher_role = Role.first({conditions:{key: 'teacher'}})
teacher_role.statuses.destroy_all
teacher_status ={
:fulltime => {"en"=>"Full Time", "zh_tw"=>"全職"},
:adjunct => {"en"=>"Adjunct", "zh_tw"=>"兼職"},
:co_hiring => {"en"=>"Co Hiring", "zh_tw"=>"合聘"},
:distinguished => {"en"=>"Distinguished", "zh_tw"=>"特聘"}
}
teacher_status.each do |key,title|
teacher_role.statuses.build :key=>key,:title_translations=>title
puts "=Status key:#{key}\t Title:#{title}"
end
teacher_role.save
p "==Finished building status for Teachers"
# task :status => :environment do
# teacher_role = Role.first({conditions:{key: 'teacher'}})
# teacher_role.statuses.destroy_all
# teacher_status ={
# :fulltime => {"en"=>"Full Time", "zh_tw"=>"全職"},
# :adjunct => {"en"=>"Adjunct", "zh_tw"=>"兼職"},
# :co_hiring => {"en"=>"Co Hiring", "zh_tw"=>"合聘"},
# :distinguished => {"en"=>"Distinguished", "zh_tw"=>"特聘"}
# }
# teacher_status.each do |key,title|
# teacher_role.statuses.build :key=>key,:title_translations=>title
# puts "=Status key:#{key}\t Title:#{title}"
# end
# teacher_role.save
student_role = Role.first({conditions:{key: 'student'}})
student_status.statuses.destroy_all
student_status ={
:studying => {"en"=>"Studying", "zh_tw"=>"在學"},
:drop_out => {"en"=>"Drop-out", "zh_tw"=>"休學"},
:alumi => {"en"=>"Alumi", "zh_tw"=>"校友"},
:suspended => {"en"=>"Suspended", "zh_tw"=>"未完成"}
}
student_status.each do |key,title|
student_role.statuses.build :key=>key,:title_translations=>title
puts "=Status key:#{key}\t Title:#{title}"
end
student_role.save
# p "==Finished building status for Teachers"
p "==Finished building status for Students"
# student_role = Role.first({conditions:{key: 'student'}})
# student_status.statuses.destroy_all
# student_status ={
# :studying => {"en"=>"Studying", "zh_tw"=>"在學"},
# :drop_out => {"en"=>"Drop-out", "zh_tw"=>"休學"},
# :alumi => {"en"=>"Alumi", "zh_tw"=>"校友"},
# :suspended => {"en"=>"Suspended", "zh_tw"=>"未完成"}
# }
# student_status.each do |key,title|
# student_role.statuses.build :key=>key,:title_translations=>title
# puts "=Status key:#{key}\t Title:#{title}"
# end
# student_role.save
end
# p "==Finished building status for Students"
# end
end