This commit is contained in:
manson 2014-04-21 10:48:36 +08:00
parent a3f5977b74
commit 7f32588551
33 changed files with 704 additions and 164 deletions

View File

@ -31,6 +31,7 @@ gem "mini_magick", github: 'minimagick/minimagick'
gem 'carrierwave'
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
gem 'mongoid-grid_fs', github: 'ahoward/mongoid-grid_fs'
gem "impressionist"
#built in modules
eval(File.read(File.dirname(__FILE__) + '/built_in_extensions.rb'))

View File

@ -0,0 +1,21 @@
//= require lib/tags
$(function() {
$.pageslide.closeCallback(function(pageslide, item) {
$('.filter-item').removeClass("active");
});
$.pageslide.loadComplete(function(pageslide, item) {
$('.filter-item').removeClass("active");
item.closest('li').addClass('active');
if(item.data('id') == 'new') {
resetForm();
pageslide.find('form').attr('action', '/admin/tags/');
pageslide.find('form').attr('method', 'post');
}
else {
setForm(item.data('form'));
pageslide.find('form').attr('action', '/admin/tags/' + item.data('id'));
pageslide.find('form').attr('method', 'put');
}
});
})

View File

@ -1 +1,6 @@
//= require basic
//= require basic
//= require lib/footable-0.1.js
//= require lib/all-list
//= require lib/jquery.fastLiveFilter.js
//= require lib/checkbox.card.js
//= require lib/jquery.form.js

View File

@ -71,14 +71,14 @@ function checkedLength() {
$defaultTags.each(function(i) {
ids.push($defaultTags.eq(i).parent().siblings('.tag_id').val());
});
$('#removeDefaults').attr('rel', "<%= Rails.application.routes.url_helpers.remove_default_admin_module_tags_path %>" + "?module_app_id=" + $('#module_app_id').val() + "&ids=" + ids);
$('#removeDefaults').attr('rel', "<%= Rails.application.routes.url_helpers.remove_default_admin_tags_path %>" + "?module_app_id=" + $('#module_app_id').val() + "&ids=" + ids);
$('#removeDefaults').removeClass('hide');
} else {
var ids = new Array();
$moduleTags.each(function(i) {
ids.push($moduleTags.eq(i).parent().siblings('.tag_id').val());
});
$('#deleteTags').attr('rel', "<%= Rails.application.routes.url_helpers.delete_tags_admin_module_tags_path %>" + "?module_app_id=" + $('#module_app_id').val() + "&ids=" + ids);
$('#deleteTags').attr('rel', "<%= Rails.application.routes.url_helpers.delete_tags_admin_tags_path %>" + "?module_app_id=" + $('#module_app_id').val() + "&ids=" + ids);
$('#deleteTags').removeClass('hide');
if($moduleTags.length > 1) {
$('#mergerTags').removeClass('hide');

View File

@ -0,0 +1,104 @@
class Admin::TagsController < ApplicationController
before_filter :setup_vars
layout "back_end"
def index
@tag = Tag.new
@tags = Tag.where(:is_default=>true)
@module_apps = ModuleApp.where(taggable: true)
end
def new
@tag = Tag.new
render layout: false
end
def edit
@tag = Tag.find(params[:id])
render layout: false
end
def create
@tag = Tag.new(tag_params.merge(is_default: true))
if @tag.save
redirect_to admin_tags_url
else
@tag = Tag.new(tag_params)
flash.now[:error] = t('create.error.tag')
render :action => "new"
end
end
def update
@tag = Tag.find(params[:id])
if @tag.update_attributes(tag_params)
redirect_to action: :index, :status => 303
else
flash.now[:error] = t('update.error.tag')
render :action => "edit"
end
end
def delete_tags
tags = Tag.find(params[:ids].split(',')) rescue nil
if tags
tags.each(&:destroy)
end
redirect_to admin_tags_url
end
def add_to_default
tags = Tag.find(params[:ids].split(',')) rescue nil
if tags
tags.each do |tag|
tag.update_attribute(:is_default, true)
end
end
redirect_to admin_tags_url
end
def merge
tags = Tag.find(params[:ids])
new_tag = Tag.new tag_params
mods = []
tags.each do |tag|
new_tag.is_default = true if tag.is_default
tag.taggings.each do |tagging|
taggable = tagging.taggable
taggable.tags = taggable.tags - [tag] + [new_tag]
taggable.save
end
unless tag.module_app.nil?
tag.module_app.each do |mod|
mods << mod
mod.tags = mod.tags - [tag] + [new_tag]
mod.save
end
end
tag.destroy
end
new_tag.is_default = true if mods.flatten.uniq.size > 1
new_tag.save
redirect_to admin_tags_url
end
def tag_params
params.require(:tag).permit!
end
protected
def setup_vars
@module_app = ModuleApp.where(:key=>"tag").first
end
end

View File

@ -22,13 +22,13 @@ class ApplicationController < ActionController::Base
end
def current_site
@current_site = Site.find_by(site_active: true)
@current_site = Site.first
end
private
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
@current_user ||= User.find(session[:user_id]) if session[:user_id] rescue nil
end
protected
@ -36,8 +36,10 @@ class ApplicationController < ActionController::Base
def authenticate_user
if session[:user_id]
# set current user object to @current_user object variable
@current_user = User.find(session[:user_id])
return true
@current_user = User.find(session[:user_id]) rescue nil
redirect_to new_session_path if @current_user.nil?
return true
else
redirect_to new_session_path
return false

View File

@ -5,7 +5,7 @@ class SessionsController < ApplicationController
end
def create
user = User.find_by(user_name: params[:user_name])
user = User.find_by(user_name: params[:user_name]) rescue nil
if user && user.authenticate(params[:password])
session[:user_id] = user.id
redirect_to admin_dashboards_path, :notice => "Logged in!"

View File

@ -0,0 +1,3 @@
module Admin::TagsHelper
end

View File

@ -1,47 +1,85 @@
module OrbitHelper
def self.set_params(params)
@params = params
end
def self.set_params(params)
@params = params
end
def self.get_params
@params
end
def self.get_params
@params
end
def self.url_to_show(slug)
if @params[:url]
"/#{@site_locale}#{@params[:url]}/#{slug}"
else
page = Page.where(:module => self.current_widget_module).first
"/#{@site_locale}#{page.url}/#{slug}"
end
end
def self.url_to_show(slug)
if @params[:url]
"/#{@site_locale}#{@params[:url]}/#{slug}"
else
page = Page.where(:module => self.current_widget_module).first
"/#{@site_locale}#{page.url}/#{slug}"
end
end
def page_url(url)
"#{request.host_with_port}/#{locale}#{url}"
end
def page_url(url)
"#{request.host_with_port}/#{locale}#{url}"
end
def self.set_site_locale(locale)
@site_locale = locale
end
def self.set_site_locale(locale)
@site_locale = locale
end
def self.get_site_locale
@site_locale
end
def self.get_site_locale
@site_locale
end
def self.current_widget_module
@controller_name
end
def self.current_widget_module
@controller_name
end
def self.set_current_widget_module(name)
@controller_name = name
end
def self.set_current_widget_module(name)
@controller_name = name
end
def get_item_module_infos(page)
if page.parent_page_id.nil?
["Home","icons-house"]
else
module_app = ModuleApp.where(:key => page.module).first
[module_app.title, module_app.get_registration.icon_class]
end
end
# ===============================================================
# Breadcrumbs
# ===============================================================
def back_end_breadcrumb
res = ''
divider = "<span class='divider'>/</span>"
res << "<li><a href='#{admin_dashboards_path}'>#{t(:dashboard_)}</a>#{divider}</li>"
case controller.controller_name
when 'authorizations'
res << "<li><a href='/#{params[:controller]}/#{@module_app.key}'>#{@module_app.title}</a>#{divider}</li>"
case params[:type]
when 'approval'
res << "<li class='active'>#{t(:approval_)}</li>"
when 'category'
res << "<li class='active'>#{t(:category_auth)}</li>"
when nil
res << "<li class='active'>#{t(:module_authorization)}</li>"
else
res << "<li class='active'>#{params[:type].underscore.humanize.capitalize} #{t(:authorization_)}</li>"
end
when 'categories'
res << "<li>#{@module_app.title}#{divider}</li>"
res << "<li class='active'>#{t(:categories)}</li>"
when 'module_tags'
res << "<li>#{@module_app.title}#{divider}</li>"
res << "<li class='active'>#{t(:tags)}</li>"
else
if params[:action].eql?('index')
res << "<li>#{@module_app.title}</li>"
else
res << "<li><a href='/#{params[:controller]}'>#{@module_app.title}</a>#{divider}</li>"
res << "<li class='active'>#{t(params[:action], scope: 'restful_actions')}</li>"
end
end
res.html_safe
end
def get_item_module_infos(page)
if page.parent_page_id.nil?
["Home","icons-house"]
else
module_app = ModuleApp.where(:key => page.module).first
[module_app.title, module_app.get_registration.icon_class]
end
end
end

View File

@ -4,9 +4,17 @@ class ModuleApp
field :title, type: String
field :key, type: String
field :taggable, type: Boolean, default: false
field :categorizable, type: Boolean, default: false
field :sidebar_order,type: Integer,default: 0
has_many :categories, dependent: :destroy, :autosave => true
has_and_belongs_to_many :tags, dependent: :destroy, :autosave => true
def refetch_setting!(reg)
self[:taggable] = reg.is_taggable
self[:categorizable] = reg.is_categorizable
end
def get_registration
OrbitApp::Module::Registration.find_by_key(key)
@ -28,4 +36,16 @@ class ModuleApp
reg = get_registration
reg.nil? ? 'Init is not defined completely' : get_registration.get_label_i18n
end
def taggable
get_registration.is_taggable
end
def taggable_model
get_registration.taggable_model
end
def categorizable
get_registration.is_categorizable
end
end

23
app/models/tag.rb Normal file
View File

@ -0,0 +1,23 @@
class Tag
include Mongoid::Document
include Mongoid::Timestamps
field :name, localize: true
field :is_default, type: Boolean, default: false
has_many :taggings, dependent: :destroy
has_and_belongs_to_many :module_app
def show_names_slash
span_names = []
Site.first.in_use_locales.each do |locale|
span_names << "<span class='tag'>#{self.name_translations[locale]}</span>"
end
span_names.join(" / ").html_safe
end
def get_module_tagging_count(model)
Tagging.where(:tag=>self.id, :taggable_type=>model).count
end
end

7
app/models/tagging.rb Normal file
View File

@ -0,0 +1,7 @@
class Tagging
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :tag
belongs_to :taggable, polymorphic: true
end

View File

@ -0,0 +1,16 @@
<div id="delete_tags" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel"><%= t('tag.delete') %></h3>
</div>
<div class="modal-body tags">
<span class="text-warning text-center"><%= t('tag.warning.delete') %></span>
<hr>
<ul class="tags-groups checkbox-card">
</ul>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><%= t(:close) %></button>
<%= link_to t(:delete_), nil, class: "delete-tags btn btn-danger", method: :post, remote: true %>
</div>
</div>

View File

@ -0,0 +1,9 @@
<%#= flash_messages %>
<%#= f.error_messages %>
<%= f.fields_for :name_translations do |f| %>
<% Site.first.in_use_locales.each do |locale| %>
<%= f.label :locale, "#{t(:name)} #{t(locale)}" %>
<%= f.text_field locale, class: 'input-large', placeholder: "#{t(:name)} #{t(locale)}", value: (@tag.name_translations[locale] rescue nil), id: locale %>
<% end %>
<% end %>

View File

@ -0,0 +1,42 @@
<!-- footer -->
<div class="bottomnav clearfix">
<div class="action pull-right">
<button id="selectAllTags" class="btn"><%= t(:select_all) %></button>
<button id="deselect" class="btn btn-inverse toggable hide"><%= t(:deselect_all) %></button>
<%= link_to t(:delete), '#', id: "deleteTags", class: "btn btn-danger toggable hide", rel: '' %>
<%= link_to t(:merge), '#', id: "mergerTags", class: "btn btn-success toggable hide", rel: merge_admin_tags_path %>
<%= link_to t(:add_to_default), add_to_default_admin_tags_path, id: "addDefault", class: "btn btn-info toggable hide", method: :post, remote: true %>
<%= link_to content_tag(:i, nil, class: "icons-plus") + " " + t(:add), '#', class: "btn btn-primary open-slide", data: {title: t('new.tag'), id: 'new'} %>
</div>
</div>
<!-- footer:end -->
<!-- tags -->
<div class="tags">
<div id="tags-list">
<p class="tag-lead lead muted"><i class="icons-tag"></i> <%= t(:default) %> <span class="badge pull-right"><%= @tags.count %></span></p>
<ul class="tags-groups checkbox-card default-tags">
<%= render partial: "tag", collection: @tags %>
</ul>
<% @module_apps.each do |mod| %>
<%
@mod = mod
tags = mod.tags
%>
<% icon_name = OrbitApp::Module::Registration.find_by_key(mod.key).get_icon_class rescue 'icons-daniel-bruce-2' %>
<p class="tag-lead lead muted"><i class="<%= icon_name %>"></i> <%= mod.title %> <span class="badge pull-right"><%= tags.count %></span></p>
<ul class="tags-groups checkbox-card module-tags">
<%= render partial: "tag", collection: tags, locals: {in_module: true} %>
</ul>
<% end %>
</div>
</div>
<!-- tags:end -->
<!-- merge -->
<%= render 'merge_modal' %>
<!-- merge:end -->
<!-- delete -->
<%= render 'delete_modal' %>
<!-- delete:end -->

View File

@ -0,0 +1,28 @@
<div id="tags-merger" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<%= form_for :tag, url: nil, remote: true do |f| %>
<fieldset>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel"><%= t('tag.merger') %></h3>
</div>
<div class="modal-body tags">
<div class="clearfix">
<%= f.fields_for :name_translations do |f| %>
<% Site.first.in_use_locales.each do |locale| %>
<%= f.label :locale, "#{t(:name)} #{t(locale)}" %>
<%= f.text_field locale, class: 'input-large', placeholder: "#{t(:name)} #{t(locale)}", id: locale %>
<% end %>
<% end %>
</div>
<span class="help-block"><%= t('tag.merge_help') %></span>
<hr>
<ul class="tags-groups checkbox-card">
</ul>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true"><%= t(:cancel) %></button>
<button class="btn btn-primary"><%= t(:submit) %></button>
</div>
</fieldset>
<% end %>
</div>

View File

@ -0,0 +1,21 @@
<li class="filter-item <%= tag.is_default ? 'default' : '' %>">
<% unless defined?(in_module) && tag.is_default %>
<p class="card pull-left">
<input type="checkbox">
</p>
<%= hidden_field_tag "ids[]", tag.id, class: "tag_id" %>
<% end %>
<% if defined?(in_module) && tag.is_default %>
<a>
<span class="amount"><%= tag.get_module_tagging_count @mod.taggable_model %></span>
<%= tag.show_names_slash %>
</a>
<% else %>
<%= link_to '#', class: "open-slide", data: {title: t('editing.tag'), id: tag.id.to_s, form: tag.name_translations} do %>
<span class="amount"><%= tag.taggings.count %></span>
<%= tag.show_names_slash %>
<% end %>
<% end %>
</li>

View File

@ -0,0 +1,35 @@
<% content_for :right_nav do %>
<div class="searchClear pull-right">
<input id="filter-input" class="search-query input-medium" type="text" placeholder="<%= t('search.tags') %>" value="">
</div>
<% end %>
<div id="tags_index">
<%= render 'index' %>
</div>
<!-- pageslide -->
<div id="pageslide">
<div class="page-title clearfix">
<a class="pull-right" href="javascript:$.pageslide.close()">
<i class="icons-arrow-left-2"></i>
</a>
<span></span>
</div>
<div class="view-page">
<div class="nano">
<div class="content">
<%= form_for :tag, url: nil, remote: true do |f| %>
<fieldset>
<%= render :partial => "form", :locals => { :f => f } %>
<div class="form-actions">
<a href="javascript:$.pageslide.close()" class="btn btn-small"><%= t(:cancel) %></a>
<%= f.submit t(:submit), class: 'btn btn-primary btn-small' %>
</div>
</fieldset>
<% end %>
</div>
</div>
</div>
</div>
<!-- pageslide:end -->

View File

@ -0,0 +1,9 @@
$("#delete_tags").modal('hide');
$("#tags-merger").modal('hide');
$("#tags_index").html("<%= j render 'index' %>")
$.pageslide.close();
openSlide();
$('.card').cardCheck({
item: $('.card input[type="checkbox"]'),
});
checkedLength()

View File

@ -0,0 +1 @@
<%= render 'new' %>

View File

@ -5,14 +5,32 @@
<%= render 'shared/meta' %>
<%= render 'shared/google_font' %>
<%= stylesheet_link_tag "back_end", media: "all", "data-turbolinks-track" => true %>
<%= stylesheet_link_tag params[:controller] if Rails.application.assets.find_asset "#{params[:controller]}.css" %>
<%= yield :page_specific_css %>
<%= javascript_include_tag "back_end" %>
<%= render 'shared/ie_html5_fix' %>
<%= javascript_include_tag params[:controller] if Rails.application.assets.find_asset "#{params[:controller]}.js" %>
<%= yield :page_specific_javascript %>
<%= csrf_meta_tags %>
</head>
<body>
<body id="dashboards">
<%= render 'layouts/orbit_bar_backend' %>
<%= render 'layouts/side_bar' %>
<%= yield %>
<section id="main-wrap">
<div class="wrap-inner">
<div id="filter" class="topnav clearfix">
<ul class="breadcrumb text-info pull-left">
<% if @module_app.present?%>
<%= back_end_breadcrumb %>
<%else%>
<%#= site_breadcrumb %>
<%end%>
</ul>
<%= yield :right_nav %>
</div>
<%= yield %>
</div>
</section>
<%= javascript_include_tag "lib/pageslide.js" %>
</body>
</html>

View File

@ -1,51 +1,41 @@
<section id="main-wrap">
<div class="sign-in have-other-sign-in">
<% flash.each do |key, msg| %>
<%= content_tag :p, msg, :class => [key, "alert alert-error in fade"] %>
<% end %>
<div class="form">
<h3 class="login-logo">Log In to Orbit</h3>
<div>
<input name="utf8" type="hidden" value="" />
<input name="authenticity_token" type="hidden" value="" />
</div>
<div class="form-block">
<div class="form-list clearfix">
<form class="content" accept-charset="UTF-8" action="/sessions" method="post">
<%= form_tag sessions_path do %>
<div class="control-group clear">
<label for="user_email">
<i class="icon-user"></i>
</label>
<%= text_field_tag :user_name, params[:user_name], :placeholder => t("users.user_id"), :id=>"user_email" %>
</div>
<div class="control-group clear">
<label for="user_password">
<i class="icon-lock"></i>
</label>
<%= password_field_tag :password, :placeholder => t(:dots), :id=>"user_password" %>
</div>
<br/>
<div class="field">
<%= label_tag :remember_me %>
<%= check_box_tag :remember_me, 1, params[:remember_me] %>
</div>
<%= button_tag(type: 'submit', class: "btn btn-primary") do %>
<%= t(:login) %>
<% end %>
</form>
<section id="main-wrap">
<div class="sign-in have-other-sign-in">
<% flash.each do |key, msg| %>
<%= content_tag :p, msg, :class => [key, "alert alert-error in fade"] %>
<% end %>
<div class="form">
<h3 class="login-logo">Log In to Orbit</h3>
<div>
<input name="utf8" type="hidden" value="" />
<input name="authenticity_token" type="hidden" value="" />
</div>
<div class="form-block">
<div class="form-list clearfix">
<%= form_tag sessions_path, :class => 'content' do %>
<div class="control-group clear">
<label for="user_email">
<i class="icon-user"></i>
</label>
<%= text_field_tag :user_name, params[:user_name], :placeholder => t("users.user_id"), :id=>"user_email" %>
</div>
</div>
<div class="pull-right">
<%= link_to content_tag(:small, t(:forgot_password)) %>
</div>
<br/>
<% end %>
<div class="control-group clear">
<label for="user_password">
<i class="icon-lock"></i>
</label>
<%= password_field_tag :password, nil, :placeholder => t(:dots), :id=>"user_password" %>
</div>
<br/>
<label class="checkbox">
<%= check_box_tag :remember_me %><small><%= label_tag :remember_me %></small>
</label>
<button class="btn btn-primary" name="button" type="submit"><%= t(:login) %></button>
<% end %>
</div>
</div>
</section>
<div class="pull-right">
<%= link_to content_tag(:small, t(:forgot_password)) %>
</div>
<br/>
</div>
</div>
</section>

View File

@ -3,9 +3,26 @@ require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Orbit::Application.initialize!
if Site.count == 0
site = Site.new
site.title = "Orbit"
site.valid_locales = [:en, :zh_tw]
site.in_use_locales = site.valid_locales
site.save
end
if Page.count == 0
home = Page.new
home.name_translations = {:en=>"home",:zh_tw=>"首頁"}
home.url = ""
home.save
end
if User.count==0
user = User.new
user.user_name = "rulingcom"
user.password = "bjo4xjp6"
user.email = "orbit@rulingcom.com"
user.save
end

View File

@ -0,0 +1,6 @@
# Use this hook to configure impressionist parameters
Impressionist.setup do |config|
# Define ORM. Could be :active_record (default), :mongo_mapper or :mongoid
# config.orm = :active_record
config.orm = :mongoid
end

View File

@ -0,0 +1,19 @@
OrbitApp.registration "Tag", type: 'ModuleApp' do
module_label 'module_name.tag'
base_url File.expand_path File.dirname(__FILE__)
side_bar do
head_label_i18n 'module_name.tag', icon_class: "icons-tag"
head_link_path "admin_tags_path"
active_for_controllers ({public: ['admin/tags']})
# available_for [:admin, :manager]
# context_link 'all',
# link_path: "admin_tags_path",
# priority: 1,
# active_for_action: {tags: :index},
# available_for: [:admin, :manager]
end
end

View File

@ -20,16 +20,22 @@
# available at http://guides.rubyonrails.org/i18n.html.
en:
en: English
zh_tw: Chinese
_locale: English
more: "More"
search:
tags: Search Tags
site_: Site
site_info: Site Info
site_map: Site Map
sitemap: Sitemap
site_name: Site Name
site_structure: Structure
submit: Submit
modules: Modules
mobile_settings: Mobile Settings
name: Name
search_engine: Search Engine
templates: Templates
preference: Preferences
@ -44,6 +50,10 @@ en:
password: Password
all: All
add: Add
new:
tag: New tag
editing:
tag: Editing tag
site:
system_preference: System Preference
@ -81,3 +91,6 @@ en:
dots: ●●●●●●
register: Register
registered: Registered
module_name:
tag: Tag

View File

@ -23,7 +23,7 @@ Orbit::Application.routes.draw do
# You can have the root of your site routed with "root"
root 'pages#home'
locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_locales
locales = Site.first.in_use_locales rescue I18n.available_locales
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
resources :users
@ -31,6 +31,15 @@ Orbit::Application.routes.draw do
namespace :admin do
resources :dashboards
resources :items
resources :tags do
collection do
post 'add_to_default'
post 'delete_tags'
post 'merge'
post 'remove_default'
post 'update_included_default'
end
end
resources :sites do
get 'mail_setting'

View File

@ -1,88 +1,113 @@
#This is a core class of Orbit Kernel. This class will register a module and set the properties defined in the module's initializer
#file.
module OrbitApp
module Module
module Registration
module ClassMethods
@@registrations = []
module Module
module Registration
module ClassMethods
@@registrations = []
def new(name,&block)
@@registrations << RegisteredModule.new(name,&block)
end
def new(name,&block)
@@registrations << RegisteredModule.new(name,&block)
end
def find_by_key(key)
@@registrations.each{|t|
return t if t.key.eql?(key)
}
return nil
end
def find_by_key(key)
@@registrations.each{|t|
return t if t.key.eql?(key)
}
return nil
end
def all
return @@registrations
end
end
def all
return @@registrations
end
end
extend ClassMethods
def self.included(other)
other.extend( ClassMethods )
end
extend ClassMethods
def self.included(other)
other.extend( ClassMethods )
end
class RegisteredModule
attr_reader :name,:key,:module_label,:widget_methods
class RegisteredModule
attr_reader :name,:key,:module_label,:widget_methods
def initialize(name,&block)
@name = name
@key = @name.underscore.singularize
@side_bar = nil
@module_label = @name
@widget_methods = []
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
setup_module_app
end
def initialize(name,&block)
@name = name
@key = @name.underscore.singularize
@side_bar = nil
@module_label = @name
@widget_methods = []
@is_taggable = false
@taggable_model = nil
@is_categorizable = false
block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given?
setup_module_app
end
def get_module_app
ModuleApp.find_by(key: @key, title: name) rescue nil
end
def get_module_app
ModuleApp.find_by(key: @key, title: name) rescue nil
end
def setup_module_app
module_app = get_module_app
module_app = ModuleApp.new(:key=>@key,:title=>name) if module_app.nil?
module_app.save(:validate=>false)
end
def setup_module_app
module_app = get_module_app
module_app = ModuleApp.new(:key=>@key,:title=>name) if module_app.nil?
module_app.refetch_setting!(self)
module_app.save(:validate=>false)
end
%w{data_count module_label category base_url version organization author intro update_info}.each do |field|
define_method(field){|var| instance_variable_set( "@" + field, var)}
end
%w{data_count module_label category base_url version organization author intro update_info}.each do |field|
define_method(field){|var| instance_variable_set( "@" + field, var)}
end
def module_label(name = @name)
@module_label = name
end
def module_label(name = @name)
@module_label = name
end
def widget_methods(widgets)
@widget_methods = widgets
end
def widget_methods(widgets)
@widget_methods = widgets
end
def get_widget_methods
@widget_methods
end
def get_widget_methods
@widget_methods
end
def get_icon_class
@side_bar.get_icon_class
end
def get_icon_class
@side_bar.get_icon_class
end
def side_bar(&block) #setter for side_bar from init
@side_bar = SideBarRegistration::SideBar.new(@name,@key,method(:get_module_app), &block)
end
def get_side_bar
@side_bar
end
def side_bar(&block) #setter for side_bar from init
@side_bar = SideBarRegistration::SideBar.new(@name,@key,method(:get_module_app), &block)
end
def get_side_bar
@side_bar
end
def icon_class
@side_bar.get_icon_class
end
def icon_class
@side_bar.get_icon_class
end
end
end
end
def taggable(model)
@is_taggable = true
@taggable_model = model.classify
end
def is_taggable
@is_taggable
end
def taggable_model
@taggable_model
end
def categorizable
@is_categorizable = true
end
def is_categorizable
@is_categorizable
end
end
end
end
end

22
lib/orbit_tag/taggable.rb Normal file
View File

@ -0,0 +1,22 @@
module OrbitTag
module Taggable
def self.included(base)
base.has_many :taggings, as: :taggable, autosave: true, dependent: :destroy
base.accepts_nested_attributes_for :taggings, allow_destroy: true
end
def tags
self.taggings.blank? ? [] : self.taggings.map{|t| t.tag}.compact
end
def tags=(tags)
tags = [tags].flatten.uniq
Tagging.where(:taggable=>self.id).destroy_all
tags.each do |tag|
self.taggings.build(tag: tag)
end
end
end
end

11
test/fixtures/taggings.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

11
test/fixtures/tags.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

7
test/models/tag_test.rb Normal file
View File

@ -0,0 +1,7 @@
require 'test_helper'
class TagTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class TaggingTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end