From fb8c8d45266277a86d96a82b231098917f448e50 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 18 Mar 2015 15:41:24 +0800 Subject: [PATCH 1/3] fixed omniauth --- config/initializers/omniauth.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index 72cbdda..c3325c3 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -1,15 +1,16 @@ OmniAuth.config.logger = Rails.logger +site = Site.first rescue nil +if !site.nil? + client_id = site.google_client_id + client_secret = site.google_client_secret -site = Site.first -client_id = site.google_client_id -client_secret = site.google_client_secret - -if !client_id.nil? && !client_secret.nil? - Rails.application.config.middleware.use OmniAuth::Builder do - provider :google_oauth2, client_id, client_secret,{ access_type: "offline", approval_prompt: "" } + if !client_id.nil? && !client_secret.nil? + Rails.application.config.middleware.use OmniAuth::Builder do + provider :google_oauth2, client_id, client_secret,{ access_type: "offline", approval_prompt: "" } + end + else + site.google_oauth_enabled = false + site.save end -else - site.google_oauth_enabled = false - site.save end \ No newline at end of file From 2432a587d518c29a50777621d38226331cb93d0c Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 18 Mar 2015 17:59:36 +0800 Subject: [PATCH 2/3] css mods for archive --- app/assets/stylesheets/lib/main-forms.css | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/assets/stylesheets/lib/main-forms.css b/app/assets/stylesheets/lib/main-forms.css index 680e95f..dbff9fb 100644 --- a/app/assets/stylesheets/lib/main-forms.css +++ b/app/assets/stylesheets/lib/main-forms.css @@ -539,6 +539,14 @@ #sideset blockquote { margin-bottom: 30px; } +.downloaded_times{ + display: inline-block; + font-size: 14px; + height: 30px; + line-height: 30px; + padding-left: 10px; + vertical-align: top; +} /* Responsive */ @media (min-width: 768px) and (max-width: 979px) { From f52919e4b65fdb843adc02824792f9dff34ba991 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 19 Mar 2015 14:24:40 +0800 Subject: [PATCH 3/3] group added --- app/controllers/admin/groups_controller.rb | 47 +++++ app/models/group.rb | 16 ++ app/models/group_category.rb | 8 + app/models/member_profile.rb | 7 + app/models/user.rb | 1 + .../admin/groups/_create_group_form.html.erb | 164 ++++++++++++++++++ app/views/admin/groups/_group.html.erb | 31 ++++ .../admin/groups/_group_categories.html.erb | 5 + app/views/admin/groups/categories.html.erb | 84 ++++++++- app/views/admin/groups/index.html.erb | 18 +- app/views/admin/groups/new.html.erb | 5 + app/views/admin/members/_side_bar.html.erb | 1 + app/views/orbit_bar/index.html.erb | 2 +- config/routes.rb | 1 + 14 files changed, 387 insertions(+), 3 deletions(-) create mode 100644 app/models/group.rb create mode 100644 app/models/group_category.rb create mode 100644 app/views/admin/groups/_create_group_form.html.erb create mode 100644 app/views/admin/groups/_group.html.erb create mode 100644 app/views/admin/groups/_group_categories.html.erb create mode 100644 app/views/admin/groups/new.html.erb diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index e838d5e..b35a517 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -1,9 +1,56 @@ class Admin::GroupsController < OrbitMemberController def index + @groups = Group.all end def categories + @categories = GroupCategory.all + end + + def create_category + gc = GroupCategory.new(category_params) + gc.save + @categories = GroupCategory.all + render :partial => "group_categories" + end + + def create + group = Group.new(group_params) + group.save + redirect_to admin_groups_path + end + + def new + @group = Group.new + @categories = GroupCategory.all.collect{|gc| [gc.title,gc.id]} + @members = [] + MemberProfile.all.each do |mp| + user = mp.user rescue nil + if !user.nil? && user.id.to_s != current_user.id.to_s && user.user_name != "rulingcom" + avatar = (mp.avatar.thumb.url == "thumb_person.png" ? "/assets/thumb_person.png" : mp.avatar.thumb.url rescue "/assets/thumb_person.png") + @members << { + "id" => user.id.to_s, + "user_name" => (user.user_name rescue ""), + "avatar" => avatar, + "name" => (mp.name_translations rescue {"en" => "","zh_tw" => ""}) + } + end + end + end + + private + + def category_params + params.require(:category).permit! + end + + def group_params + p = params.require(:group).permit! + p["user_ids"] << current_user.id.to_s + p["admins"] = [] + p["admins"] << current_user.id.to_s + p end end \ No newline at end of file diff --git a/app/models/group.rb b/app/models/group.rb new file mode 100644 index 0000000..a8ef047 --- /dev/null +++ b/app/models/group.rb @@ -0,0 +1,16 @@ +class Group + include Mongoid::Document + include Mongoid::Timestamps + include Slug + + field :title, as: :slug_title, type: String, localize: true + field :description, localize: true + field :admins, type: Array, default: [] + field :privacy, default: "closed" + mount_uploader :image, ImageUploader + + belongs_to :group_category + has_and_belongs_to_many :users + + +end \ No newline at end of file diff --git a/app/models/group_category.rb b/app/models/group_category.rb new file mode 100644 index 0000000..5a3e7a5 --- /dev/null +++ b/app/models/group_category.rb @@ -0,0 +1,8 @@ +class GroupCategory + include Mongoid::Document + include Mongoid::Timestamps + + field :title, localize: true + + has_many :groups +end \ No newline at end of file diff --git a/app/models/member_profile.rb b/app/models/member_profile.rb index 1e3680b..324f19b 100644 --- a/app/models/member_profile.rb +++ b/app/models/member_profile.rb @@ -52,6 +52,13 @@ class MemberProfile end end + def name_translations + { + "en" => "#{self.first_name_translations["en"]} #{self.last_name_translations["zh_tw"]}", + "zh_tw" => "#{self.last_name_translations["zh_tw"]} #{self.first_name_translations["zh_tw"]}" + } + end + def disable_role=(var) var[:id].each do |id,val| if (val=="true") diff --git a/app/models/user.rb b/app/models/user.rb index f11c615..fc44c65 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -20,6 +20,7 @@ class User belongs_to :workgroup has_many :authorizations belongs_to :member_profile + has_and_belongs_to_many :groups has_one :facebook, :autosave => true, :dependent => :destroy has_one :google, :autosave => true, :dependent => :destroy # has_one :desktop, :dependent => :destroy diff --git a/app/views/admin/groups/_create_group_form.html.erb b/app/views/admin/groups/_create_group_form.html.erb new file mode 100644 index 0000000..a649d73 --- /dev/null +++ b/app/views/admin/groups/_create_group_form.html.erb @@ -0,0 +1,164 @@ +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/fileupload" %> + <%= stylesheet_link_tag "lib/main-list" %> + <%= stylesheet_link_tag "select2/select2" %> + +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/bootstrap-fileupload" %> + <%= javascript_include_tag "lib/file-type" %> + <%= javascript_include_tag "lib/module-area" %> + <%= javascript_include_tag "select2/select2.min" %> +<% end %> + +
+ + + + +
+ + +
+ + +
+ +
+ <%= f.select :group_category_id, @categories %> +
+
+ +
+ +
+
+
+ <% if @group.image.file %> + <%= image_tag @group.image %> + <% else %> + + <% end %> +
+
+ + <%= t(:select_image) %> + <%= t(:change) %> + <%= f.file_field :image %> + + <%= t(:cancel) %> +
+ +
+
+
+
+ +
+ +
+ Open + Closed +
+
+
+ +
+ +
+
+ +
+
+ + + + + +
+ + <% @site_in_use_locales.each_with_index do |locale, i| %> + +
"> + + +
+ +
+ <%= f.fields_for :title_translations do |f| %> + <%= f.text_field locale, class: "input-block-level", placeholder: t(:title), value: (@group.title_translations[locale] rescue nil) %> + <% end %> +
+
+ + +
+ +
+
+ <%= f.fields_for :description_translations do |f| %> + <%= f.text_area locale, rows: 2, class: "input-block-level", value: (@group.description_translations[locale] rescue nil) %> + <% end %> +
+
+
+
+ <% end %> +
+
+ + +
+ <%= f.submit t('submit'), class: 'btn btn-primary' %> + <%= link_to t('cancel'), admin_groups_path, :class=>"btn" %> +
+ + + + diff --git a/app/views/admin/groups/_group.html.erb b/app/views/admin/groups/_group.html.erb new file mode 100644 index 0000000..b9c37b6 --- /dev/null +++ b/app/views/admin/groups/_group.html.erb @@ -0,0 +1,31 @@ +<% current_user_is_group_admin = group.admins.include?(current_user.id.to_s) ? true : false %> +
  • +
    + +

    ">

    +
    + <%= link_to(content_tag(:i, nil, :class => 'icon-edit'),"#",:class=>"edit" ) if current_user_is_group_admin %> +
    + <%= image_tag(group.image) %> +
    +
    +

    <%= link_to group.title, "#" %>

    + <% + author = "" + group.admins.each_with_index do |admin,i| + user = User.find(admin) rescue nil + if !user.nil? + author = author + (user.member_profile.name == "" ? user.user_name : user.member_profile.name rescue "") + author = author + ", " if i != group.admins.count - 1 + end + end + %> +
    Admin : <%= author %>
    +
    +
      +
    • + <%= group.description %> +
    • +
    +
    +
  • \ No newline at end of file diff --git a/app/views/admin/groups/_group_categories.html.erb b/app/views/admin/groups/_group_categories.html.erb new file mode 100644 index 0000000..b9d103d --- /dev/null +++ b/app/views/admin/groups/_group_categories.html.erb @@ -0,0 +1,5 @@ +<% @categories.each do |cat| %> +
    + <%= cat.title_translations["en"] %> / <%= cat.title_translations["zh_tw"] %> +
    +<% end %> \ No newline at end of file diff --git a/app/views/admin/groups/categories.html.erb b/app/views/admin/groups/categories.html.erb index 1eab51a..ce368ad 100644 --- a/app/views/admin/groups/categories.html.erb +++ b/app/views/admin/groups/categories.html.erb @@ -1 +1,83 @@ -this is category. \ No newline at end of file +
    + <%= render :partial => "group_categories" %> +
    ++ + + + \ No newline at end of file diff --git a/app/views/admin/groups/index.html.erb b/app/views/admin/groups/index.html.erb index ebc19ee..b14c207 100644 --- a/app/views/admin/groups/index.html.erb +++ b/app/views/admin/groups/index.html.erb @@ -1 +1,17 @@ -this is my group page \ No newline at end of file +<% content_for :page_specific_css do -%> + + <%= stylesheet_link_tag "lib/wrap-nav" %> + <%= stylesheet_link_tag "lib/main-list" %> + <%= stylesheet_link_tag "lib/filter" %> + <%= stylesheet_link_tag "lib/member" %> + +<% end -%> +<% content_for :page_specific_javascript do -%> + <%= javascript_include_tag "lib/jquery.lite.image.resize.js" %> + <%= javascript_include_tag "lib/member/list-view.js" %> +<% end -%> +
    +
      + <%= render :partial=>"group",:collection=> @groups %> +
    +
    \ No newline at end of file diff --git a/app/views/admin/groups/new.html.erb b/app/views/admin/groups/new.html.erb new file mode 100644 index 0000000..6f87f09 --- /dev/null +++ b/app/views/admin/groups/new.html.erb @@ -0,0 +1,5 @@ +<%= form_for @group, :url => admin_groups_path, :html => { :multipart => true , :class=>"form-horizontal main-forms"} do |f| %> +
    + <%= render :partial => "create_group_form", locals: {f: f} %> +
    +<% end %> \ No newline at end of file diff --git a/app/views/admin/members/_side_bar.html.erb b/app/views/admin/members/_side_bar.html.erb index 32a197b..a45cf1e 100644 --- a/app/views/admin/members/_side_bar.html.erb +++ b/app/views/admin/members/_side_bar.html.erb @@ -52,6 +52,7 @@ <%= content_tag :ul, :class => ("nav nav-list ") do -%> <%= content_tag :li, link_to((content_tag(:span, "My Groups")), admin_groups_path), :class => active_for_action('groups', 'index') %> <%= content_tag :li, link_to((content_tag(:span, "Categories")), admin_groups_categories_path), :class => active_for_action('groups','categories') %> + <%= content_tag :li, link_to((content_tag(:span, "Create New Group")), new_admin_group_path), :class => active_for_action('groups','new') %> <% end -%> diff --git a/app/views/orbit_bar/index.html.erb b/app/views/orbit_bar/index.html.erb index 4337bfb..e22cca3 100644 --- a/app/views/orbit_bar/index.html.erb +++ b/app/views/orbit_bar/index.html.erb @@ -61,7 +61,7 @@
  • - + <%= t(:member_) %>
  • diff --git a/config/routes.rb b/config/routes.rb index 11b6b5a..48cbcff 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -122,6 +122,7 @@ Orbit::Application.routes.draw do # GROUPS START HERE get "groups/categories" => 'groups#categories' + post "groups/create_category" => 'groups#create_category' resources :groups do