From 8e014bf59c1a3bab67fcc65a9fcf85f1cc1a5714 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Mon, 17 Sep 2012 12:06:21 +0800 Subject: [PATCH 1/3] basic function --- .../admin/users_new_interface_controller.rb | 54 ++++- app/helpers/application_helper.rb | 9 + app/models/proto_tag.rb | 40 ++++ app/models/sub_role_tag.rb | 4 + app/models/tag.rb | 39 +--- app/models/user/attribute_field.rb | 10 +- app/models/user/status.rb | 5 +- app/models/user/sub_role.rb | 4 +- app/models/user/user.rb | 5 +- .../_deled_quick_edit.html.erb | 16 ++ .../users_new_interface/_filter.html.erb | 28 +-- .../_index_paginator.html.erb | 15 +- .../users_new_interface/_js_and_css.html.erb | 7 + .../_sort_headers.html.erb | 7 + .../_user_for_listing.html.erb | 29 +-- .../_user_for_summary.html.erb | 4 +- .../_user_for_thumbnail.html.erb | 4 +- .../admin/users_new_interface/index.html.erb | 36 +-- .../admin/users_new_interface/index.js.erb | 3 + .../index_summary.html.erb | 18 +- .../users_new_interface/index_summary.js.erb | 3 + .../index_thumbnail.html.erb | 16 +- .../index_thumbnail.js.erb | 3 + .../admin/users_new_interface/show.html.erb | 15 +- app/views/layouts/_side_bar.html.erb | 13 +- lib/tasks/build_new_member.rake | 218 +++++++++++++++--- 26 files changed, 420 insertions(+), 185 deletions(-) create mode 100644 app/models/proto_tag.rb create mode 100644 app/models/sub_role_tag.rb create mode 100644 app/views/admin/users_new_interface/_deled_quick_edit.html.erb create mode 100644 app/views/admin/users_new_interface/_js_and_css.html.erb create mode 100644 app/views/admin/users_new_interface/_sort_headers.html.erb create mode 100644 app/views/admin/users_new_interface/index.js.erb create mode 100644 app/views/admin/users_new_interface/index_summary.js.erb create mode 100644 app/views/admin/users_new_interface/index_thumbnail.js.erb diff --git a/app/controllers/admin/users_new_interface_controller.rb b/app/controllers/admin/users_new_interface_controller.rb index 30f8a023..f0aaef73 100644 --- a/app/controllers/admin/users_new_interface_controller.rb +++ b/app/controllers/admin/users_new_interface_controller.rb @@ -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) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fa06948d..7be0e2d7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -260,4 +260,13 @@ module ApplicationHelper wrap_mark = options[:wrap_mark] || "
" 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 diff --git a/app/models/proto_tag.rb b/app/models/proto_tag.rb new file mode 100644 index 00000000..b5724acb --- /dev/null +++ b/app/models/proto_tag.rb @@ -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 diff --git a/app/models/sub_role_tag.rb b/app/models/sub_role_tag.rb new file mode 100644 index 00000000..f2ff6b7b --- /dev/null +++ b/app/models/sub_role_tag.rb @@ -0,0 +1,4 @@ +class SubRoleTag < ProtoTag + has_and_belongs_to_many :sub_roles + +end diff --git a/app/models/tag.rb b/app/models/tag.rb index eb7e1f77..ad63434b 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -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 diff --git a/app/models/user/attribute_field.rb b/app/models/user/attribute_field.rb index dd22b9df..0bda602d 100644 --- a/app/models/user/attribute_field.rb +++ b/app/models/user/attribute_field.rb @@ -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 diff --git a/app/models/user/status.rb b/app/models/user/status.rb index 9022a4f1..f9f19420 100644 --- a/app/models/user/status.rb +++ b/app/models/user/status.rb @@ -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 diff --git a/app/models/user/sub_role.rb b/app/models/user/sub_role.rb index 8ff91b3f..6bd3cf0d 100644 --- a/app/models/user/sub_role.rb +++ b/app/models/user/sub_role.rb @@ -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}) diff --git a/app/models/user/user.rb b/app/models/user/user.rb index f2dcd279..1aa789bf 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -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 diff --git a/app/views/admin/users_new_interface/_deled_quick_edit.html.erb b/app/views/admin/users_new_interface/_deled_quick_edit.html.erb new file mode 100644 index 00000000..a898148b --- /dev/null +++ b/app/views/admin/users_new_interface/_deled_quick_edit.html.erb @@ -0,0 +1,16 @@ +
+ +
\ No newline at end of file diff --git a/app/views/admin/users_new_interface/_filter.html.erb b/app/views/admin/users_new_interface/_filter.html.erb index 92752c8f..3262ea5d 100644 --- a/app/views/admin/users_new_interface/_filter.html.erb +++ b/app/views/admin/users_new_interface/_filter.html.erb @@ -37,8 +37,9 @@
- Category1 - Category2 + <% @sub_roles.each do |sr|%> + <%= sr.title%> + <% end -%>
- Tag1 - Tag2 - Tag3 - Tag4 - Tag5 - Tag6 - Tag7 - Tag8 - Tag9 - Tag10 - Tag11 - Tag12 - Tag13 - Tag14 - Tag15 - Tag16 - Tag17 - Tag18 - Tag19 - Tag20 + <% @sub_role_tags.each do |sr_tag|%> + <%= sr_tag[I18n.locale] %> + <% end -%>
<%= t("admin.new_admin.table_header.clear_filter")%> diff --git a/app/views/admin/users_new_interface/_index_paginator.html.erb b/app/views/admin/users_new_interface/_index_paginator.html.erb index 381ed352..04fff093 100644 --- a/app/views/admin/users_new_interface/_index_paginator.html.erb +++ b/app/views/admin/users_new_interface/_index_paginator.html.erb @@ -1,17 +1,8 @@ -
+
<%= link_to(new_admin_users_new_interface_path,:class=> "btn btn-primary pull-right") do%> <%= t("admin.new_admin.action.add")%> <% end -%> -
- +
+ <%= paginate @users, :params => {:inner => false}%>
diff --git a/app/views/admin/users_new_interface/_js_and_css.html.erb b/app/views/admin/users_new_interface/_js_and_css.html.erb new file mode 100644 index 00000000..d6bb59e0 --- /dev/null +++ b/app/views/admin/users_new_interface/_js_and_css.html.erb @@ -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 -%> \ No newline at end of file diff --git a/app/views/admin/users_new_interface/_sort_headers.html.erb b/app/views/admin/users_new_interface/_sort_headers.html.erb new file mode 100644 index 00000000..9c14a32c --- /dev/null +++ b/app/views/admin/users_new_interface/_sort_headers.html.erb @@ -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 %> diff --git a/app/views/admin/users_new_interface/_user_for_listing.html.erb b/app/views/admin/users_new_interface/_user_for_listing.html.erb index 6d453590..9df1eb10 100644 --- a/app/views/admin/users_new_interface/_user_for_listing.html.erb +++ b/app/views/admin/users_new_interface/_user_for_listing.html.erb @@ -2,36 +2,21 @@
-
+
- <%= user_for_listing.name %> - + <%= link_to user_for_listing.name,admin_users_new_interface_path(user_for_listing) %> + <%#= render "deled_quick_edit"%> - # TODO - # TODO + <%= Random.rand(1000)%> + <%= Random.rand(10)%> - 10,597 + <%= Random.rand(10000)%>

\ No newline at end of file diff --git a/app/views/admin/users_new_interface/_user_for_summary.html.erb b/app/views/admin/users_new_interface/_user_for_summary.html.erb index 27127142..17848797 100644 --- a/app/views/admin/users_new_interface/_user_for_summary.html.erb +++ b/app/views/admin/users_new_interface/_user_for_summary.html.erb @@ -11,11 +11,11 @@

- <%= image_tag(user_for_summary.avatar.thumb.url) %> + <%= show_avatar(user_for_summary) %>

- <%= user_for_summary.name%> + <%= link_to user_for_summary.name,admin_users_new_interface_path(user_for_summary)%>

#TODO 教授兼系主任#TODO 大學部校友 diff --git a/app/views/admin/users_new_interface/_user_for_thumbnail.html.erb b/app/views/admin/users_new_interface/_user_for_thumbnail.html.erb index ac320227..38b9aae5 100644 --- a/app/views/admin/users_new_interface/_user_for_thumbnail.html.erb +++ b/app/views/admin/users_new_interface/_user_for_thumbnail.html.erb @@ -11,11 +11,11 @@

- <%= image_tag(user_for_thumbnail.avatar.thumb.url) %> + <%= show_avatar(user_for_thumbnail) %>

- <%= user_for_thumbnail.name%> + <%= link_to user_for_thumbnail.name,admin_users_new_interface_path(user_for_thumbnail)%>

diff --git a/app/views/admin/users_new_interface/index.html.erb b/app/views/admin/users_new_interface/index.html.erb index 2e58ab72..d07a7668 100644 --- a/app/views/admin/users_new_interface/index.html.erb +++ b/app/views/admin/users_new_interface/index.html.erb @@ -1,18 +1,20 @@ - <%= render :partial => "filter"%> - - - - - - - - - - - - - <%= render :partial => "user_for_listing",:collection=> [@users.first]%> - -
+<%= render :partial => "js_and_css"%> - <%= render :partial=> "index_paginator" %> +<%= render :partial => "filter"%> + + + + + + + + + + + + + <%= render :partial => "user_for_listing",:collection=> @users%> + +
+ +<%= render :partial=> "index_paginator" %> diff --git a/app/views/admin/users_new_interface/index.js.erb b/app/views/admin/users_new_interface/index.js.erb new file mode 100644 index 00000000..6c7ec7fc --- /dev/null +++ b/app/views/admin/users_new_interface/index.js.erb @@ -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} %>"); \ No newline at end of file diff --git a/app/views/admin/users_new_interface/index_summary.html.erb b/app/views/admin/users_new_interface/index_summary.html.erb index ac568bfe..993dece6 100644 --- a/app/views/admin/users_new_interface/index_summary.html.erb +++ b/app/views/admin/users_new_interface/index_summary.html.erb @@ -1,9 +1,9 @@ - <%= render :partial => "filter"%> -
-
    - <% 5.times do %> - <%= render :partial=>"user_for_summary",:collection=> [@users.first]%> - <% end -%> -
-
- <%= render :partial=> "index_paginator" %> \ No newline at end of file +<%= render :partial => "js_and_css"%> + +<%= render :partial => "filter"%> +
+
    + <%= render :partial=>"user_for_summary",:collection=> @users%> +
+
+<%= render :partial=> "index_paginator" %> \ No newline at end of file diff --git a/app/views/admin/users_new_interface/index_summary.js.erb b/app/views/admin/users_new_interface/index_summary.js.erb new file mode 100644 index 00000000..109a7596 --- /dev/null +++ b/app/views/admin/users_new_interface/index_summary.js.erb @@ -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} %>"); \ No newline at end of file diff --git a/app/views/admin/users_new_interface/index_thumbnail.html.erb b/app/views/admin/users_new_interface/index_thumbnail.html.erb index 35eb6a18..7402f6c3 100644 --- a/app/views/admin/users_new_interface/index_thumbnail.html.erb +++ b/app/views/admin/users_new_interface/index_thumbnail.html.erb @@ -1,8 +1,8 @@ - <%= render :partial => "filter"%> -
-
    - <% 5.times do %> - <%= render :partial=>"user_for_thumbnail",:collection=> [@users.first]%> - <% end -%> -
- <%= render :partial=> "index_paginator" %> \ No newline at end of file +<%= render :partial => "js_and_css"%> + +<%= render :partial => "filter"%> +
+
    + <%= render :partial=>"user_for_thumbnail",:collection=> @users%> +
+<%= render :partial=> "index_paginator" %> \ No newline at end of file diff --git a/app/views/admin/users_new_interface/index_thumbnail.js.erb b/app/views/admin/users_new_interface/index_thumbnail.js.erb new file mode 100644 index 00000000..234663ef --- /dev/null +++ b/app/views/admin/users_new_interface/index_thumbnail.js.erb @@ -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} %>"); \ No newline at end of file diff --git a/app/views/admin/users_new_interface/show.html.erb b/app/views/admin/users_new_interface/show.html.erb index a1f5fdee..c70a1d98 100644 --- a/app/views/admin/users_new_interface/show.html.erb +++ b/app/views/admin/users_new_interface/show.html.erb @@ -1,3 +1,5 @@ +<%= render :partial => "js_and_css"%> +
@@ -16,7 +18,7 @@
- <% binding.pry%> + <% #binding.pry%> <%= render :partial=> 'plugin_summary'%> <%= render :partial=> 'plugin_summary'%> <%= render :partial=> 'plugin_summary'%> @@ -27,7 +29,7 @@

- + <%= show_avatar(@user) %>

<%= @user.name%> @@ -47,11 +49,10 @@

- <% 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} %>
diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index 964547c7..e62596d5 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -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 -%> diff --git a/lib/tasks/build_new_member.rake b/lib/tasks/build_new_member.rake index 390a0030..c7953057 100644 --- a/lib/tasks/build_new_member.rake +++ b/lib/tasks/build_new_member.rake @@ -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 From 4c7906898eeaaa3aca2afe6454a8abe0b9bb9425 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Mon, 17 Sep 2012 14:12:01 +0800 Subject: [PATCH 2/3] add member link to orbit menu --- app/views/layouts/_orbit_bar.html.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/views/layouts/_orbit_bar.html.erb b/app/views/layouts/_orbit_bar.html.erb index 59a3bf6c..c3decff8 100644 --- a/app/views/layouts/_orbit_bar.html.erb +++ b/app/views/layouts/_orbit_bar.html.erb @@ -6,6 +6,8 @@ Orbit