basic function

This commit is contained in:
Matthew K. Fu JuYuan authored and Christophe Vilayphiou committed 2012-09-17 13:32:52 +08:00
1 parent 9eed9ec7b6
commit 19db9d0037
26 files changed
+420 -185

No files matched your search

@@ -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)
+9
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
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
+4
View File
@@ -0,0 +1,4 @@
class SubRoleTag < ProtoTag
has_and_belongs_to_many :sub_roles
end
+1 -38
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
+7 -3
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
+4 -1
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
+3 -1
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})
+3 -2
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
@@ -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>
@@ -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>
@@ -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>
@@ -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 -%>
@@ -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 %>
@@ -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>
@@ -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>
@@ -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>
@@ -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" %>
@@ -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} %>");
@@ -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" %>
@@ -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} %>");
@@ -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" %>
@@ -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} %>");
@@ -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>
+6 -7
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 -%>