From 8dac8273f73ac8f111949bb65c811fdd5c666157 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 20 May 2015 14:17:00 +0800 Subject: [PATCH] group mods.. --- .../stylesheets/lib/group/_group-index.scss | 11 +++++- app/controllers/admin/groups_controller.rb | 20 +++++++++++ app/models/group.rb | 2 +- app/views/admin/groups/_group.html.erb | 11 +++--- app/views/admin/groups/_post.html.erb | 11 +++--- app/views/admin/groups/categories.html.erb | 33 ++++++++++++------ app/views/admin/groups/index.html.erb | 18 +++++++++- app/views/admin/groups/newpost.html.erb | 34 +++++++++++++------ app/views/admin/groups/show.html.erb | 16 +++++++++ app/views/admin/groups/showpost.html.erb | 22 +++++++++++- config/routes.rb | 2 ++ 11 files changed, 145 insertions(+), 35 deletions(-) diff --git a/app/assets/stylesheets/lib/group/_group-index.scss b/app/assets/stylesheets/lib/group/_group-index.scss index f01a773..aa7346b 100644 --- a/app/assets/stylesheets/lib/group/_group-index.scss +++ b/app/assets/stylesheets/lib/group/_group-index.scss @@ -59,7 +59,16 @@ font-size: 25px; position: absolute; top: 50%; - left: 50%; + left: 45%; + transform: translate(-50%, -50%); + margin: auto; + } + .trash { + color: $red; + font-size: 25px; + position: absolute; + top: 49%; + left: 60%; transform: translate(-50%, -50%); margin: auto; } diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 3bec795..ba8fd13 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -25,6 +25,12 @@ class Admin::GroupsController < OrbitGroupController redirect_to admin_group_path(@group) end + def deletepost + gp = GroupPost.find(params[:id]) + gp.destroy + render :json => {"success" => true}.to_json + end + def showpost render_401 and return if !user_can_read? if (current_user.id.to_s != @post.author.to_s) && (!@post.read_by.include?(current_user.id.to_s)) @@ -53,6 +59,14 @@ class Admin::GroupsController < OrbitGroupController render :partial => "group_categories" end + def update_category + gc = GroupCategory.find(params[:category_id]) + gc.update_attributes(category_params) + gc.save + @categories = GroupCategory.all + render :partial => "group_categories" + end + def upload_photo photo = GroupPostImage.new(post_image_params) photo.save @@ -81,6 +95,12 @@ class Admin::GroupsController < OrbitGroupController redirect_to admin_groups_path end + def destroy + group = Group.find(params[:id]) + group.destroy + render :json => {"success" => true}.to_json + end + def new @group = Group.new @categories = GroupCategory.all.collect{|gc| [gc.title,gc.id]} diff --git a/app/models/group.rb b/app/models/group.rb index dbe344f..c699203 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -13,7 +13,7 @@ class Group belongs_to :group_category has_and_belongs_to_many :users - has_many :group_posts + has_many :group_posts, :dependent => :destroy scope :closed, ->{ where(privacy: "closed") } scope :open, ->{ where(privacy: "open") } diff --git a/app/views/admin/groups/_group.html.erb b/app/views/admin/groups/_group.html.erb index 798cf66..90f93c0 100644 --- a/app/views/admin/groups/_group.html.erb +++ b/app/views/admin/groups/_group.html.erb @@ -6,13 +6,16 @@ current_user_is_group_member = true end %> -
  • +
  • ">

    -
    - <%= link_to(content_tag(:i, nil, :class => 'icon-edit'),"#",:class=>"edit" ) if current_user_is_group_admin %> -
    + <% if current_user_is_group_admin %> +
    + <%= link_to(content_tag(:i, nil, :class => 'icon-edit'),"#",:class=>"edit" ) %> + <%= link_to(content_tag(:i, nil, :class => 'icon-trash'),"/admin/groups/#{group.id.to_s}",:class=>"trash delete-group-button" ) %> +
    + <% end %> <%= image_tag(group.image) %>
    diff --git a/app/views/admin/groups/_post.html.erb b/app/views/admin/groups/_post.html.erb index ec9da9f..0c58b76 100644 --- a/app/views/admin/groups/_post.html.erb +++ b/app/views/admin/groups/_post.html.erb @@ -1,15 +1,14 @@ -
    +
    -
    - Edit this post -
    diff --git a/app/views/admin/groups/categories.html.erb b/app/views/admin/groups/categories.html.erb index 41f9f21..c424448 100644 --- a/app/views/admin/groups/categories.html.erb +++ b/app/views/admin/groups/categories.html.erb @@ -20,7 +20,7 @@
  • -
    +
    <%= render :partial => "group_categories" %>
    @@ -60,17 +60,17 @@