From 42cfe5ac916e24cfac895bb4cba52bc45810d7ab Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 11 Sep 2012 10:52:27 +0800 Subject: [PATCH 1/4] first version for new member html --- app/controllers/application_controller.rb | 2 +- app/controllers/pages_controller.rb | 3 +- app/models/user/user.rb | 1 + .../users_new_interface/_filter.html.erb | 94 ++++++++++++ .../_index_paginator.html.erb | 17 +++ .../_user_for_listing.html.erb | 37 +++++ .../_user_for_summary.html.erb | 30 ++++ .../_user_for_thumbnail.html.erb | 22 +++ .../admin/users_new_interface/index.html.erb | 18 +++ .../index_summary.html.erb | 9 ++ .../index_thumbnail.html.erb | 8 ++ .../admin/users_new_interface/show.html.erb | 135 ++++++++++++++++++ app/views/layouts/_side_bar.html.erb | 28 +++- config/locales/zh_tw.yml | 32 ++++- config/routes.rb | 1 + 15 files changed, 426 insertions(+), 11 deletions(-) create mode 100644 app/views/admin/users_new_interface/_filter.html.erb create mode 100644 app/views/admin/users_new_interface/_index_paginator.html.erb create mode 100644 app/views/admin/users_new_interface/_user_for_listing.html.erb create mode 100644 app/views/admin/users_new_interface/_user_for_summary.html.erb create mode 100644 app/views/admin/users_new_interface/_user_for_thumbnail.html.erb create mode 100644 app/views/admin/users_new_interface/index.html.erb create mode 100644 app/views/admin/users_new_interface/index_summary.html.erb create mode 100644 app/views/admin/users_new_interface/index_thumbnail.html.erb create mode 100644 app/views/admin/users_new_interface/show.html.erb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 74274eeb..16b2c493 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,7 @@ class ApplicationController < ActionController::Base protect_from_forgery - include ParserFrontEnd, ParserBackEnd + include ParserFrontEnd, ParserBackEnd,ApplicationHelper layout :layout_by_resource diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index bfc4f403..e8de7132 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -17,7 +17,8 @@ class PagesController < ApplicationController def show #begin @item = Item.first(:conditions => {:path => params[:page_name]}) - if @item && @item.is_published #&& (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s)) + #binding.pry + if @item && @item.is_published && (@item.enabled_for.nil? ? true : @item.enabled_for.include?(I18n.locale.to_s)) impressionist(@item) case @item.class.to_s when 'Page' diff --git a/app/models/user/user.rb b/app/models/user/user.rb index 3df40a3b..ce809ab8 100644 --- a/app/models/user/user.rb +++ b/app/models/user/user.rb @@ -27,6 +27,7 @@ class User has_many :papers, :autosave => true, :dependent => :destroy belongs_to :role + 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/_filter.html.erb b/app/views/admin/users_new_interface/_filter.html.erb new file mode 100644 index 00000000..92752c8f --- /dev/null +++ b/app/views/admin/users_new_interface/_filter.html.erb @@ -0,0 +1,94 @@ + \ No newline at end of file diff --git a/app/views/admin/users_new_interface/_index_paginator.html.erb b/app/views/admin/users_new_interface/_index_paginator.html.erb new file mode 100644 index 00000000..381ed352 --- /dev/null +++ b/app/views/admin/users_new_interface/_index_paginator.html.erb @@ -0,0 +1,17 @@ +
+ <%= link_to(new_admin_users_new_interface_path,:class=> "btn btn-primary pull-right") do%> + <%= t("admin.new_admin.action.add")%> + <% end -%> + +
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 new file mode 100644 index 00000000..6d453590 --- /dev/null +++ b/app/views/admin/users_new_interface/_user_for_listing.html.erb @@ -0,0 +1,37 @@ + + + +
+
+ # TODO:Teacher + # TODO:Student + # TODO:Staff +
+
+ + + <%= user_for_listing.name %> +
+ +
+ + # TODO + # TODO + + 10,597 +

+ + \ 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 new file mode 100644 index 00000000..27127142 --- /dev/null +++ b/app/views/admin/users_new_interface/_user_for_summary.html.erb @@ -0,0 +1,30 @@ +
  • + + + + + + + +
    +
    +

    +
    +

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

    + <%= user_for_summary.name%> +

    +
    + #TODO 教授兼系主任#TODO 大學部校友 +
    +
      +
    • #TODO 258Publications
    • +
    • #TODO 16Courses
    • +
    • #TODO 10,578Followers
    • +
    +
    +
    +
  • \ No newline at end of file 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 new file mode 100644 index 00000000..ac320227 --- /dev/null +++ b/app/views/admin/users_new_interface/_user_for_thumbnail.html.erb @@ -0,0 +1,22 @@ +
  • + + + + + + + +
    +
    +

    +
    +

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

    + <%= user_for_thumbnail.name%> +

    +
    +
    +
  • \ No newline at end of file diff --git a/app/views/admin/users_new_interface/index.html.erb b/app/views/admin/users_new_interface/index.html.erb new file mode 100644 index 00000000..2e58ab72 --- /dev/null +++ b/app/views/admin/users_new_interface/index.html.erb @@ -0,0 +1,18 @@ + <%= render :partial => "filter"%> + + + + + + + + + + + + + <%= render :partial => "user_for_listing",:collection=> [@users.first]%> + +
    + + <%= render :partial=> "index_paginator" %> diff --git a/app/views/admin/users_new_interface/index_summary.html.erb b/app/views/admin/users_new_interface/index_summary.html.erb new file mode 100644 index 00000000..ac568bfe --- /dev/null +++ b/app/views/admin/users_new_interface/index_summary.html.erb @@ -0,0 +1,9 @@ + <%= render :partial => "filter"%> +
    + +
    + <%= render :partial=> "index_paginator" %> \ 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 new file mode 100644 index 00000000..35eb6a18 --- /dev/null +++ b/app/views/admin/users_new_interface/index_thumbnail.html.erb @@ -0,0 +1,8 @@ + <%= render :partial => "filter"%> +
    +
    + <%= render :partial=> "index_paginator" %> \ 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 new file mode 100644 index 00000000..d6a83048 --- /dev/null +++ b/app/views/admin/users_new_interface/show.html.erb @@ -0,0 +1,135 @@ +
    +
    +

    + <%= image_tag(@user.avatar.url) %> +
    + +
    +
    + + +
    \ No newline at end of file diff --git a/app/views/layouts/_side_bar.html.erb b/app/views/layouts/_side_bar.html.erb index f98984a3..68b4bb02 100644 --- a/app/views/layouts/_side_bar.html.erb +++ b/app/views/layouts/_side_bar.html.erb @@ -36,6 +36,22 @@ <%#= link_to content_tag(:i, nil, :class => 'icons-member') + t('admin.member'), admin_users_path %> <%# 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 %> + <%= 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')) %> + <% end -%> + +<% end -%> + + + + <%= content_tag :li, :class => active_for_controllers('page_contexts') || active_for_app_auth('page_content') || active_for_ob_auths_object("PageContext") do -%> <%= link_to content_tag(:i, nil, :class => 'icons-page') + t('admin.page'), panel_page_content_back_end_page_contexts_path %> <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('page_contexts')) do -%> @@ -56,6 +72,7 @@ <% end -%> <% end %> + <%= content_tag :li, :class => active_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys') || active_for_app_auth('web_resource') || active_for_ob_auths_object("WebLinkCategory") do -%> <%= link_to content_tag(:i, nil, :class => 'icons-link') + t('admin.link'), panel_web_resource_back_end_web_links_path %> <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('web_links', '/panel/web_resource/back_end/tags', 'web_link_categorys')) do -%> @@ -66,16 +83,15 @@ <%= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: "web_resource"}))), :class => active_for_app_auth('web_resource') if (is_admin? rescue nil) %> <% end -%> <% end -%> - -<%= content_tag :li, :class => active_for_controllers('orbit_galleries','/panel/gallery/back_end/tags') || active_for_app_auth("orbit_gallery") do -%> - <%= link_to content_tag(:i, nil, :class => 'icons-picture') + t('admin.orbit_gallery'), panel_gallery_back_end_orbit_gallery_path %> +<%= content_tag :li, :class => active_for_controllers('orbit_galleries','/panel/gallery/back_end/tags') || active_for_app_auth("gallery") do -%> + <%#= link_to content_tag(:i, nil, :class => 'icons-picture') + t('admin.orbit_gallery'), panel_gallery_back_end_orbit_gallery_path %> <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('orbit_galleries') ) do -%> <%#= content_tag :li, link_to(t('admin.ad.all_banners'), admin_ad_banners_path), :class => active_for_action('ad_banners', 'index') %> <%#= content_tag :li, link_to(t('admin.ad.new_banner'), new_admin_ad_banner_path), :class => active_for_action('ad_banners', 'new') %> <%#= content_tag :li, link_to(t('admin.ad.new_image'), new_ad_image_admin_ad_banners_path), :class => active_for_action('ad_images', 'new') %> - <%= content_tag :li, link_to(t('gallery.categories'), panel_gallery_back_end_categorylist_path), :class => active_for_action('/panel/gallery/back_end/categorylist','categorylist') %> - <%= content_tag :li, link_to(t('gallery.tags'), panel_gallery_back_end_tags_path), :class => active_for_action('/panel/gallery/back_end/tags', 'index') %> - <%= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: "orbit_gallery"}))), :class => active_for_app_auth('orbit_gallery') if (is_admin? rescue nil) %> + <%#= content_tag :li, link_to(t('gallery.categories'), panel_gallery_back_end_categorylist_path), :class => active_for_action('/panel/gallery/back_end/categorylist','categorylist') %> + <%#= content_tag :li, link_to(t('gallery.tags'), panel_gallery_back_end_tags_path), :class => active_for_action('/panel/gallery/back_end/tags', 'index') %> + <%= content_tag :li, link_to(t('admin.module.authorization'),admin_module_app_manager_auth_proc_path(ModuleApp.first(conditions: {title: "gallery"}))), :class => active_for_app_auth('orbit_gallery') if (is_admin? rescue nil) %> <% end -%> <% end %> <%#= content_tag :li, :class => active_for_controllers('assets', '/admin/asset_tags', 'asset_categories') do -%> diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index d8483ece..81f974f5 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -210,9 +210,35 @@ zh_tw: no_home_page: 您沒有首頁 no_layout: 您沒有佈局 name: 名稱 - nccu: 政大客制 - nccu_c: - nccu_ldap_uid: NCCU LDAP 帳號 + new_admin: + side_bar: + all_user: 所有使用者 + add_user: 新增使用者 + user_roles: 角色 + user_info: 使用者資訊 + user: 會員 + action: + add: 新增 + edit: 編輯 + delete: 刪除 + quick_edit: 快速編輯 + next: 下一頁 + prev: 上一頁 + attributes: + roles: 角色 + name: 名稱 + publications: 出版數 + courses: 開課數 + followers: 被關注數 + show_mode: + index: 清單 + summary: 摘要 + thumbnail: 縮圖 + table_header: + status: 狀態 + category: 分類 + tags: 標籤 + clear_filter: 重置 new_asset: 新增資產 new_component: 新增元件 new_design: 新設計 diff --git a/config/routes.rb b/config/routes.rb index 64e2648a..0293f3b2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -127,6 +127,7 @@ Orbit::Application.routes.draw do resources :tags resources :translations resources :users + resources :users_new_interface end # end admin From 01a8a9b5b614dcdb55d06fad75dd43c3c93a9bb7 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Tue, 11 Sep 2012 10:53:05 +0800 Subject: [PATCH 2/4] users new interface controller --- .../admin/users_new_interface_controller.rb | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 app/controllers/admin/users_new_interface_controller.rb diff --git a/app/controllers/admin/users_new_interface_controller.rb b/app/controllers/admin/users_new_interface_controller.rb new file mode 100644 index 00000000..30f8a023 --- /dev/null +++ b/app/controllers/admin/users_new_interface_controller.rb @@ -0,0 +1,87 @@ +class Admin::UsersNewInterfaceController < ApplicationController + + layout "new_admin" + before_filter :authenticate_user! + before_filter :set_attribute, :only => [:index, :show, :new, :edit] + + def index + @users = User.all.entries + + render case params[:at] + when 'summary' + "index_summary" + when 'thumbnail' + "index_thumbnail" + else + "index" + end + end + + def show + @user = User.find(params[:id]) + get_info_and_roles + end + + def new + @user = User.new + get_info_and_roles + end + + def create + puts params.to_yaml + @user = User.new(params[:user]) + if @user.save + flash[:notice] = t('admin.create_success_user') + redirect_to :action => :index + else + render :action => :new + end + end + + def edit + @user = User.find(params[:id]) + get_info_and_roles + end + + def update + @user = User.find(params[:id]) + + # Update changes to the avatar + @user.remove_avatar! if params[:file] + @user.avatar = params[:file] if params[:file] + + if @user.id.to_s.eql?(session['warden.user.user.key'][1].to_s) && @user.admin != params[:user][:admin].to_i.to_b + flash.now[:error] = t('admin.cant_revoke_self_admin') + end + if !flash[:error] && @user.update_attributes(params[:user]) + flash[:notice] = t('admin.update_success_user') + redirect_to :action => :index + else + get_info_and_roles + render :action => :edit + end + end + + def destroy + if params[:id].eql?(session['warden.user.user.key'][1].to_s) + flash[:error] = t('admin.cant_delete_self') + else + @user = User.find(params[:id]) + @user.destroy + end + + redirect_to :action => :index + end + + protected + + def get_info_and_roles + @infos = Info.excludes('disabled' => true) + @roles = Role.excludes('disabled' => true) + end + + def set_attribute + @class = 'users' + end + +end From 9bfd1d2b0c9b6de8368c457420109483981d1da0 Mon Sep 17 00:00:00 2001 From: "Matthew K. Fu JuYuan" Date: Thu, 13 Sep 2012 18:39:27 +0800 Subject: [PATCH 3/4] break down Ray's HTML --- Gemfile | 7 +- app/models/user/attribute_field.rb | 38 +++- app/models/user/role.rb | 2 + app/models/user/status.rb | 11 ++ app/models/user/sub_role.rb | 2 +- .../attributes/_attribute_field.html.erb | 5 +- .../_plugin_summary.html.erb | 46 +++++ .../users_new_interface/_user_role.html.erb | 16 ++ .../admin/users_new_interface/show.html.erb | 175 +++++------------- config/locales/zh_tw.yml | 7 + lib/tasks/build_new_member.rake | 82 ++++++++ 11 files changed, 260 insertions(+), 131 deletions(-) create mode 100644 app/models/user/status.rb create mode 100644 app/views/admin/users_new_interface/_plugin_summary.html.erb create mode 100644 app/views/admin/users_new_interface/_user_role.html.erb create mode 100644 lib/tasks/build_new_member.rake diff --git a/Gemfile b/Gemfile index 906fa408..e83da25d 100644 --- a/Gemfile +++ b/Gemfile @@ -31,7 +31,7 @@ gem 'resque' # background jobs gem 'resque-scheduler' # job scheduling gem 'resque-restriction' #gem 'rb-readline' -gem 'ruby-debug19' +# gem 'ruby-debug19' gem 'rubyzip' gem 'sunspot_mongo' @@ -68,6 +68,11 @@ end group :test, :development do + gem 'pry' + gem 'pry-remote' + gem 'pry-stack_explorer' + gem 'pry-debugger' + gem "sunspot-rails-tester" gem 'spork' gem 'database_cleaner' #Strategies for cleaning databases. Can be used to ensure a clean state for testing. diff --git a/app/models/user/attribute_field.rb b/app/models/user/attribute_field.rb index 2a227d27..dd22b9df 100644 --- a/app/models/user/attribute_field.rb +++ b/app/models/user/attribute_field.rb @@ -9,13 +9,47 @@ class AttributeField field :list_options, :type => Array field :built_in, :type => Boolean, :default => false field :disabled, :type => Boolean, :default => false - field :title, localize: true - + #field :title, localize: true + + field :locale_title, localize: true + field :neutral_title + belongs_to :attribute + belongs_to :role has_many :attribute_values # validates_uniqueness_of :key + def title_translations + if locale + return locale_title_translations + else + return Hash[VALID_LOCALES.map{|d| [d,neutral_title]}] + end + end + + def title_translations=(var) + if locale + self.locale_title = var + end + end + + def title + if locale + return self.locale_title + else + return self.neutral_title + end + end + def title=(var) + binding.pry + if locale + self.locale_title = var + else + self.neutral_title = var + end + end + # Convert the string list_options into an array def select_list_options=(var) self.list_options = var.gsub(' ', '').split(',') diff --git a/app/models/user/role.rb b/app/models/user/role.rb index bbcedfc7..438e2dab 100644 --- a/app/models/user/role.rb +++ b/app/models/user/role.rb @@ -10,6 +10,8 @@ class Role has_many :sub_roles, :autosave => true, :dependent => :destroy has_many :users + has_many :statuses, :autosave => true, :dependent => :destroy + has_many :attribute_fields, :autosave => true, :dependent => :destroy accepts_nested_attributes_for :sub_roles, :allow_destroy => true def is_built_in? diff --git a/app/models/user/status.rb b/app/models/user/status.rb new file mode 100644 index 00000000..9022a4f1 --- /dev/null +++ b/app/models/user/status.rb @@ -0,0 +1,11 @@ +class Status + + include Mongoid::Document + include Mongoid::Timestamps + + belongs_to :role + has_and_belongs_to_many :sub_roles + + field :title, localize: true + +end \ No newline at end of file diff --git a/app/models/user/sub_role.rb b/app/models/user/sub_role.rb index cdefb5f5..8ff91b3f 100644 --- a/app/models/user/sub_role.rb +++ b/app/models/user/sub_role.rb @@ -2,7 +2,7 @@ class SubRole < Attribute belongs_to :role has_and_belongs_to_many :users - + has_and_belongs_to_many :statuses, :autosave => true, :dependent => :destroy # Get an sub_role from key def self.get_sub_role_from_key(key) self.first(:conditions => {:key => key}) diff --git a/app/views/admin/attributes/_attribute_field.html.erb b/app/views/admin/attributes/_attribute_field.html.erb index b2e94344..7fd85285 100644 --- a/app/views/admin/attributes/_attribute_field.html.erb +++ b/app/views/admin/attributes/_attribute_field.html.erb @@ -9,10 +9,13 @@ <% end %> <% end %> + <%= f.select :markup, LIST[:markups], {}, {:style => "width:90px"} %>
    > <%= t('admin.options') %>: - <%= f.select "select_list_options", attribute_field.select_list_options, :style => "width:130px" %> + <%= f.select "select_list_options", {'1'=>"A",'2'=>"B",'3'=>"C"}, :style => "width:130px" %> + <%#= collection_select(:select_list_options, method, collection, value_method, text_method, options = {}, html_options = {}) %> +
    diff --git a/app/views/admin/users_new_interface/_plugin_summary.html.erb b/app/views/admin/users_new_interface/_plugin_summary.html.erb new file mode 100644 index 00000000..09871ad8 --- /dev/null +++ b/app/views/admin/users_new_interface/_plugin_summary.html.erb @@ -0,0 +1,46 @@ +
    +

    Module Name

    +
    + + + + + + + +
    模組數量
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + +
    University2,304
    Master783
    Doctor45
    Staff62
    +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/admin/users_new_interface/_user_role.html.erb b/app/views/admin/users_new_interface/_user_role.html.erb new file mode 100644 index 00000000..05ef4bb1 --- /dev/null +++ b/app/views/admin/users_new_interface/_user_role.html.erb @@ -0,0 +1,16 @@ +
    +
    +
    + <%= t(i18n)%> +
    + + + <% items.each do |item| %> + + + + + <% end -%> + +
    <%= item[:name] %><%= item[:value] %>
    +
    diff --git a/app/views/admin/users_new_interface/show.html.erb b/app/views/admin/users_new_interface/show.html.erb index d6a83048..a1f5fdee 100644 --- a/app/views/admin/users_new_interface/show.html.erb +++ b/app/views/admin/users_new_interface/show.html.erb @@ -1,135 +1,58 @@ -