forked from saurabh/orbit4-5
Personal Plugin with brief intro
This commit is contained in:
parent
09461f7008
commit
49f7d2192d
|
@ -0,0 +1,67 @@
|
|||
class Admin::PersonalPluginIntrosController < OrbitMemberController
|
||||
def index
|
||||
get_types
|
||||
@plugin_intro = @types.where(member_profile_id: params[:member_profile_id]).first rescue nil
|
||||
|
||||
if @plugin_intro.blank?
|
||||
@set_type = @types.new()
|
||||
@url = eval("admin_#{@app_type}s_path(member_profile_id: params[:member_profile_id])")
|
||||
@verb = :post
|
||||
else
|
||||
@set_type = @types.find(@plugin_intro.id)
|
||||
@url = polymorphic_path(["admin", @plugin_intro])
|
||||
@verb = :put
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def create
|
||||
get_types
|
||||
|
||||
@plugin_intro = @types.new(personal_plugin_intro_params)
|
||||
member = MemberProfile.find(personal_plugin_intro_params[:member_profile_id])
|
||||
respond_to do |format|
|
||||
if @plugin_intro.save
|
||||
format.html { redirect_to(admin_member_url(id: member.to_param, show_plugin_profile: @reback_name)) }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
get_types
|
||||
|
||||
@plugin_intro = @types.find(params[:id])
|
||||
member = MemberProfile.find(personal_plugin_intro_params[:member_profile_id])
|
||||
|
||||
respond_to do |format|
|
||||
if @plugin_intro.update_attributes(personal_plugin_intro_params)
|
||||
format.html { redirect_to(admin_member_url(id: member.to_param,show_plugin_profile: @reback_name)) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def personal_plugin_intro_params
|
||||
params.require(:plugin_intro).permit!
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def get_types
|
||||
@types = @app_type.classify.constantize
|
||||
end
|
||||
|
||||
end
|
|
@ -32,20 +32,31 @@ class MembersController < ApplicationController
|
|||
member = MemberProfile.find_by(uid: params[:uid])
|
||||
|
||||
plugins = OrbitApp::Plugin::Registration.all rescue nil
|
||||
plugin_list = plugins.collect do |plugin|
|
||||
plugin_data = plugin.app_name.constantize.where(member_profile_id: member) rescue nil
|
||||
pd = plugin_data.collect do |p|
|
||||
{
|
||||
"data_title" => p.slug_title,
|
||||
"link_to_show" => OrbitHelper.url_to_show(p.to_param) + "?method=personal_plugin&plugin_name=#{plugin.app_name}"
|
||||
}
|
||||
end
|
||||
plugin_list = plugins.collect do |plugin|
|
||||
intro = PersonalPluginIntro.find_by(member_profile_id:member.id, _type: "#{plugin.app_name}Intro")
|
||||
|
||||
{
|
||||
"plugin_data" => pd,
|
||||
"plugin_title" => plugin.app_name.titleize
|
||||
}
|
||||
end
|
||||
if intro.complete_list == true
|
||||
plugin_data = plugin.app_name.constantize.where(member_profile_id: member) rescue nil
|
||||
pd = plugin_data.collect do |p|
|
||||
{
|
||||
"data_title" => p.slug_title,
|
||||
"link_to_show" => OrbitHelper.url_to_show(p.to_param) + "?method=personal_plugin&plugin_name=#{plugin.app_name}"
|
||||
}
|
||||
end
|
||||
{
|
||||
"plugin_data" => pd,
|
||||
"plugin_title" => plugin.app_name.titleize
|
||||
}
|
||||
# end
|
||||
elsif intro.brief_intro == true
|
||||
pd = []
|
||||
pd << { "data_title" => intro.text.html_safe}
|
||||
{
|
||||
"plugin_data" => pd,
|
||||
"plugin_title" => plugin.app_name.titleize
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
if member.avatar.present?
|
||||
image = member.avatar.thumb.url
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
module Admin::PersonalPluginIntrosHelper
|
||||
end
|
|
@ -34,6 +34,8 @@ class MemberProfile
|
|||
has_many :attribute_values
|
||||
accepts_nested_attributes_for :attribute_values, allow_destroy: true
|
||||
|
||||
has_many :personal_plugin_intros
|
||||
|
||||
scope :can_display, ->{where(is_hidden: false).order_by([:is_top,:desc],[:created_at,:desc])}
|
||||
before_save :assign_default_position, :if => :assign_default_position?
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
class PersonalPluginIntro
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :text, type: String, localize: true
|
||||
field :brief_intro, type: Mongoid::Boolean, default: false
|
||||
field :complete_list, type: Mongoid::Boolean, default: true
|
||||
|
||||
belongs_to :member_profile
|
||||
|
||||
def pp_object
|
||||
brief_intro
|
||||
end
|
||||
|
||||
def self.from_id(id)
|
||||
PersonalPluginIntro.find(id) rescue nil
|
||||
end
|
||||
|
||||
def self.is_localized?(field_name)
|
||||
self.fields[field_name.to_s].localized?
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,113 @@
|
|||
<% # encoding: utf-8 %>
|
||||
|
||||
<% content_for :side_bar do %>
|
||||
<%= render :partial => 'layouts/side_bar', :locals => {:link_name => t(:user), :link_url => admin_site_site_info_path(current_site), :icon => 'icons-users', :side_bar_content => 'admin/members/side_bar'} %>
|
||||
<% end %>
|
||||
|
||||
<% content_for :page_specific_css do %>
|
||||
<%= stylesheet_link_tag "lib/main-forms" %>
|
||||
<%= stylesheet_link_tag "lib/fileupload" %>
|
||||
<%= stylesheet_link_tag "lib/main-list" %>
|
||||
<% end %>
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
|
||||
<%= javascript_include_tag "lib/file-type" %>
|
||||
<% end %>
|
||||
|
||||
<%= form_for(:plugin_intro, :url => @url, :method => @verb, html: {class: "form-horizontal main-forms previewable"} ) do |f| %>
|
||||
<fieldset>
|
||||
|
||||
<!-- Input Area -->
|
||||
<div class="input-area">
|
||||
|
||||
<!-- Module Tabs -->
|
||||
<div class="nav-name"><strong><%= I18n.t("module_name.#{@app_type_name}") %></strong></div>
|
||||
<ul class="nav nav-pills module-nav">
|
||||
<li></li>
|
||||
<li class="active">
|
||||
<a href="#basic" data-toggle="tab"><%= t(:basic) %></a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- Module -->
|
||||
<div class="tab-content module-area">
|
||||
|
||||
<!-- Basic Module -->
|
||||
<div class="tab-pane fade in active" id="basic">
|
||||
|
||||
<% if !params[:member_profile_id].blank? %>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t("personal_plugins.author") %></label>
|
||||
<div class="controls">
|
||||
<%= MemberProfile.from_id(params[:member_profile_id]).name rescue ''%>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
<!-- frontend_page -->
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t("personal_plugins.frontend_page") %></label>
|
||||
<div class="controls">
|
||||
<%= f.check_box :brief_intro, :checked => @set_type.brief_intro %> <%= t("personal_plugins.brief_intro") %>
|
||||
<%= f.check_box :complete_list, :checked => @set_type.complete_list %> <%= t("personal_plugins.complete_list") %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Language Tabs -->
|
||||
<div class="nav-name"><strong><%= t(:language) %></strong></div>
|
||||
<ul class="nav nav-pills language-nav">
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
<li class="<%= 'active' if i == 0 %>">
|
||||
<a data-toggle="tab" href=".<%= locale %>"><%= t(locale) %></a>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
||||
<!-- Language -->
|
||||
<div class="tab-content language-area">
|
||||
|
||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||
|
||||
<div class="<%= locale %> tab-pane fade <%= ( i == 0 ) ? "in active" : '' %>">
|
||||
|
||||
<!-- Content -->
|
||||
<div class="control-group input-content">
|
||||
<label class="control-label muted"><%= t(:content) %></label>
|
||||
<div class="controls">
|
||||
<div class="textarea">
|
||||
<%= f.fields_for :text_translations do |f| %>
|
||||
<%= f.cktext_area locale, rows: 5, class: "input-block-level", :value => (@set_type.text_translations[locale] rescue nil) %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<% end %>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Form Actions -->
|
||||
<div class="form-actions">
|
||||
<%= f.hidden_field :member_profile_id, value: params[:member_profile_id] if !params[:member_profile_id].blank? %>
|
||||
<%= f.submit t('submit'), class: 'btn btn-primary' %>
|
||||
<%= link_to t('cancel'), get_go_back, :class=>"btn" %>
|
||||
</div>
|
||||
|
||||
|
||||
</fieldset>
|
||||
<% end %>
|
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class Admin::PersonalPluginIntrosControllerTest < ActionController::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
text: MyString
|
||||
brief_intro: false
|
||||
complete_list: false
|
||||
|
||||
two:
|
||||
text: MyString
|
||||
brief_intro: false
|
||||
complete_list: false
|
|
@ -0,0 +1,4 @@
|
|||
require 'test_helper'
|
||||
|
||||
class Admin::PersonalPluginIntrosHelperTest < ActionView::TestCase
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class PersonalPluginIntroTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
Reference in New Issue