gprs byebye, location have two language, must have picture, long, lang have limit

This commit is contained in:
Rueshyna 2013-01-15 17:47:00 +08:00 committed by chris
parent 91afad23ba
commit c44b4163e4
78 changed files with 144 additions and 117 deletions

View File

@ -69,8 +69,8 @@
<%= content_tag :li, link_to(t(:tags), panel_calendar_back_end_tags_path), :class => active_for_action('/panel/calendar/back_end/tags', 'index')if (is_manager? rescue nil) %> <%= content_tag :li, link_to(t(:tags), panel_calendar_back_end_tags_path), :class => active_for_action('/panel/calendar/back_end/tags', 'index')if (is_manager? rescue nil) %>
<% end -%> <% end -%>
<% end %> <% end %>
<%= content_tag :li, :class => active_for_controllers('locations') || active_for_app_auth("gprs") do -%> <%= content_tag :li, :class => active_for_controllers('locations') do -%>
<%= link_to content_tag(:i, nil, :class => 'icons-location') + content_tag(:span, t(:location)), panel_gprs_back_end_locations_path %> <%= link_to content_tag(:i, nil, :class => 'icons-location') + content_tag(:span, t(:location)), panel_location_back_end_locations_path %>
<%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('locations') ) do -%> <%= content_tag :ul, :class => ("nav nav-list " + visible_for_controllers('locations') ) do -%>
<% end -%> <% end -%>
<% end %> <% end %>
@ -79,4 +79,4 @@
<% flash.each do |key, msg| %> <% flash.each do |key, msg| %>
<%= content_tag :span, msg, :class => [key, "notice label label-warning"] %> <%= content_tag :span, msg, :class => [key, "notice label label-warning"] %>
<% end %> <% end %>
</div> </div>

View File

@ -1,3 +0,0 @@
= Gprs
This project rocks and uses MIT-LICENSE.

View File

@ -1,2 +0,0 @@
module Panel::Gprs::BackEnd::LocationsHelper
end

View File

@ -1,11 +0,0 @@
class Location
include Mongoid::Document
include Mongoid::Timestamps
mount_uploader :file, GprsUploader
field :name
field :description
field :longitude, type: Float
field :latitude, type: Float
end

View File

@ -1,30 +0,0 @@
<div class="control-group">
<label class="control-label" for="">Name</label>
<div class="controls">
<%= f.text_field :name, :class=>"span4", :placeholder => "Area" %>
</div>
</div>
<div class="control-group">
<label class="control-label" for="">Picture</label>
<div class="controls">
<%= f.file_field :file %>
</div>
</div>
<div class="control-group">
<label class="control-label" for="">Coordinates</label>
<div class="controls">
<%= f.text_field :longitude, :class=>"span2", :placeholder => "Longitude" %>
<%= f.text_field :latitude, :class=>"span2", :placeholder => "Langitude" %>
</div>
</div>
<div class="control-group">
<label class="control-label" for="">Description</label>
<div class="controls">
<%= f.text_area :description, :class=>"span4", :cols=>"30", :row=>"5" %>
</div>
</div>
<div class="control-group">
<div class="controls">
<%= f.submit "Save", :class=>"btn" %>
</div>
</div>

View File

@ -1,4 +0,0 @@
<%= form_for @location, :url=> panel_gprs_back_end_location_path(@location), :html => { :class=>"form-horizontal"} do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<% end %>

View File

@ -1,3 +0,0 @@
<%= form_for @location, :url=> panel_gprs_back_end_locations_path, :html => { :class=>"form-horizontal"} do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<% end %>

View File

@ -1,4 +0,0 @@
require "gprs/engine"
module Gprs
end

View File

@ -1,7 +0,0 @@
require 'test_helper'
class GprsTest < ActiveSupport::TestCase
test "truth" do
assert_kind_of Module, Gprs
end
end

View File

@ -1,4 +0,0 @@
require 'test_helper'
class Panel::Gprs::BackEnd::LocationsHelperTest < ActionView::TestCase
end

View File

@ -1,6 +1,6 @@
source "http://rubygems.org" source "http://rubygems.org"
# Declare your gem's dependencies in gprs.gemspec. # Declare your gem's dependencies in location.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and # Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group. # development dependencies will be added by default to the :development group.
gemspec gemspec

View File

@ -0,0 +1,3 @@
= Location
This project rocks and uses MIT-LICENSE.

View File

@ -14,7 +14,7 @@ end
RDoc::Task.new(:rdoc) do |rdoc| RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc' rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Gprs' rdoc.title = 'Location'
rdoc.options << '--line-numbers' rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc') rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb') rdoc.rdoc_files.include('lib/**/*.rb')

View File

@ -1,13 +1,11 @@
class Panel::Gprs::BackEnd::LocationsController < OrbitBackendController class Panel::Location::BackEnd::LocationsController < OrbitBackendController
include AdminHelper
#before_filter :clean_values, :only => [:create, :update] before_filter :force_order_for_visitor,:only => [:index, :new, :edit, :create, :update, :delete]
before_filter :force_order_for_visitor,:only => [:index, :new, :edit, :delete]
before_filter :force_order_for_user,:except => [:get_locations,:index] before_filter :force_order_for_user,:except => [:get_locations,:index]
#before_filter :for_app_sub_manager,:except => [:index, :new, :edit, :delete, :get_locations]
def index def index
@locations = Location.all @location_infos = LocationInfo.all
respond_to do |format| respond_to do |format|
format.html # new.html.erb format.html # new.html.erb
format.json { render json: @locations } format.json { render json: @locations }
@ -15,7 +13,7 @@ class Panel::Gprs::BackEnd::LocationsController < OrbitBackendController
end end
def new def new
@location = Location.new @location_info = LocationInfo.new
respond_to do |format| respond_to do |format|
format.html # new.html.erb format.html # new.html.erb
@ -24,11 +22,11 @@ class Panel::Gprs::BackEnd::LocationsController < OrbitBackendController
end end
def edit def edit
@location = Location.find(params[:id]) @location_info = LocationInfo.find(params[:id])
end end
def show def show
@location = Location.find(params[:id]) @location_info = LocationInfo.find(params[:id])
respond_to do |format| respond_to do |format|
format.html format.html
format.json { render json: @location } format.json { render json: @location }
@ -36,29 +34,34 @@ class Panel::Gprs::BackEnd::LocationsController < OrbitBackendController
end end
def create def create
@location = Location.new(params[:location]) @location_info = LocationInfo.new(params[:location_info])
@location.save! if @location_info.save
redirect_to panel_gprs_back_end_locations_url flash[:success] = "Success!!"
redirect_to panel_location_back_end_locations_url
else
error_msg = @location_info.errors.full_messages
render 'new'
end
end end
def update def update
@location = Location.find(params[:id]) @location_info = LocationInfo.find(params[:id])
@location.update_attributes(params[:location]) @location_info.update_attributes(params[:location_info])
redirect_to panel_gprs_back_end_locations_url redirect_to panel_location_back_end_locations_url
end end
def destroy def destroy
@location = Location.find(params[:id]) @location_info = LocationInfo.find(params[:id])
@location.destroy @location_info.destroy
redirect_to panel_gprs_back_end_locations_url redirect_to panel_location_back_end_locations_url
end end
def get_locations def get_locations
locations = Location.all location_infos = LocationInfo.all
@data = Array.new @data = Array.new
locations.each do |location| location_infos.each do |location|
picurl = location.file.blank? ? '' : "http://#{request.host_with_port + location.file.url}" picurl = location.file.blank? ? '' : "http://#{request.host_with_port + location.file.url}"
thumburl = location.file.blank? ? '' : "http://#{request.host_with_port + location.file.thumb.url}" thumburl = location.file.blank? ? '' : "http://#{request.host_with_port + location.file.thumb.url}"
@data << { name: location.name, @data << { name: location.name,
@ -69,9 +72,6 @@ class Panel::Gprs::BackEnd::LocationsController < OrbitBackendController
description: location.description } description: location.description }
end end
#print readable json
render :json => JSON.pretty_generate({location: @data}) render :json => JSON.pretty_generate({location: @data})
#render :json => {location: @data}.to_json
end end
end end

View File

@ -0,0 +1,2 @@
module Panel::Location::BackEnd::LocationsHelper
end

View File

@ -0,0 +1,19 @@
class LocationInfo
include Mongoid::Document
include Mongoid::Timestamps
mount_uploader :file, LocationsUploader
field :name, localize: true
field :description, localize: true
field :longitude, type: Float
field :latitude, type: Float
validates :file, presence: true
validates :longitude,
numericality: { less_than_or_equal_to: 180.0, greater_than_or_equal_to: -180.0 },
unless: Proc.new{self.longitude.blank?}
validates :latitude,
numericality: { less_than_or_equal_to: 90.0, greater_than_or_equal_to: -90.0 },
unless: Proc.new{self.latitude.blank?}
end

View File

@ -1,4 +1,4 @@
class GprsUploader < CarrierWave::Uploader::Base class LocationsUploader < CarrierWave::Uploader::Base
# Include RMagick or ImageScience support: # Include RMagick or ImageScience support:
# include CarrierWave::RMagick # include CarrierWave::RMagick
@ -12,7 +12,7 @@ class GprsUploader < CarrierWave::Uploader::Base
# Override the directory where uploaded files will be stored. # Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted: # This is a sensible default for uploaders that are meant to be mounted:
def store_dir def store_dir
"gprs/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" "location/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end end
# Provide a default URL as a default if there hasn't been a file uploaded: # Provide a default URL as a default if there hasn't been a file uploaded:

View File

@ -0,0 +1,38 @@
<% @location_info.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
<div class="control-group">
<label class="control-label" for=""><%= t "name" %></label>
<div class="controls">
<%= f.fields_for :name_translations do |f| %>
<%= f.text_field locale, :class=>'span4', :value => (@location_info.name_translations[locale.to_s] rescue nil) %>
<% end %>
</div>
</div>
<div class="control-group">
<label class="control-label" for=""><%= t 'picture' %></label>
<div class="controls">
<%= @location_info.file? ? ( link_to t(:view), @location_info.file.url, {:class => 'for_preview btn', :target => '_blank', :title => t(:view)}) : '' %>
<%= f.file_field :file %>
</div>
</div>
<div class="control-group">
<label class="control-label" for=""><%= t 'coordinates' %></label>
<div class="controls">
<%= f.text_field :longitude, :class=>"span2", :placeholder => "Longitude" %>
<%= f.text_field :latitude, :class=>"span2", :placeholder => "Langitude" %>
</div>
</div>
<div class="control-group">
<label class="control-label" for=""><%= t 'description' %></label>
<div class="controls">
<%= f.fields_for :description_translations do |f| %>
<%= f.text_area locale, :class=>'span4', :cols=>"30", :row=>"5", :value => (@location_info.description_translations[locale.to_s] rescue nil) %>
<% end %>
</div>
</div>
<div class="control-group">
<div class="controls">
<%= f.submit t("submit"), :class=>"btn" %>
</div>
</div>

View File

@ -0,0 +1,4 @@
<%= form_for @location_info, :url=> panel_location_back_end_location_path(@location_info), :html => { :class=>"form-horizontal"} do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<% end %>

View File

@ -13,22 +13,21 @@
</tr> </tr>
</thead> </thead>
<tbody id="tbody_locations" class="sort-holder"> <tbody id="tbody_locations" class="sort-holder">
<% @locations.each do |location| %> <% @location_infos.each do |location| %>
<tr class="with_action"> <tr class="with_action">
<td><%= image_tag(location.file, alt: location.file, size: "50x50" ) if !location.file.blank? %></td> <td><%= image_tag(location.file, alt: location.file, size: "50x50" ) if !location.file.blank? %></td>
<td><%= location.name%></td> <td><%= location.name %></td>
<td><%= location.longitude%></td> <td><%= location.longitude%></td>
<td><%= location.latitude%></td> <td><%= location.latitude%></td>
<td><%= location.description%></td> <td><%= location.description %></td>
<%if is_manager? %> <%if is_manager? %>
<td><%= link_to 'Edit', edit_panel_gprs_back_end_location_path(location) %></td> <td><%= link_to 'Edit', edit_panel_location_back_end_location_path(location) %></td>
<td><%= link_to 'Destroy', panel_gprs_back_end_location_path(location), method: :delete , :confirm => t(:sure?) %></td> <td><%= link_to 'Destroy', panel_location_back_end_location_path(location), method: :delete , :confirm => t(:sure?) %></td>
<%end%> <%end%>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<%if is_manager? %> <%if is_manager? %>
<td><%= link_to 'New', new_panel_gprs_back_end_location_path %></td> <td><%= link_to 'New', new_panel_location_back_end_location_path %></td>
<% end %> <% end %>

View File

@ -0,0 +1,3 @@
<%= form_for @location_info, :url=> panel_location_back_end_locations_path, :html => { :class=>"form-horizontal"} do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<% end %>

View File

@ -1,6 +1,6 @@
Rails.application.routes.draw do Rails.application.routes.draw do
namespace :panel do namespace :panel do
namespace :gprs do namespace :location do
namespace :back_end do namespace :back_end do
match "locations/get_locations" => "locations#get_locations" match "locations/get_locations" => "locations#get_locations"

View File

@ -0,0 +1,4 @@
require "location/engine"
module Location
end

View File

@ -1,4 +1,4 @@
module Gprs module Location
class Engine < Rails::Engine class Engine < Rails::Engine
end end
end end

View File

@ -1,3 +1,3 @@
module Gprs module Location
VERSION = "0.0.1" VERSION = "0.0.1"
end end

View File

@ -1,4 +1,4 @@
# desc "Explaining what the task does" # desc "Explaining what the task does"
# task :gprs do # task :location do
# # Task goes here # # Task goes here
# end # end

View File

@ -1,17 +1,17 @@
$:.push File.expand_path("../lib", __FILE__) $:.push File.expand_path("../lib", __FILE__)
# Maintain your gem's version: # Maintain your gem's version:
require "gprs/version" require "location/version"
# Describe your gem and declare its dependencies: # Describe your gem and declare its dependencies:
Gem::Specification.new do |s| Gem::Specification.new do |s|
s.name = "gprs" s.name = "location"
s.version = Gprs::VERSION s.version = Location::VERSION
s.authors = ["TODO: Your name"] s.authors = ["TODO: Your name"]
s.email = ["TODO: Your email"] s.email = ["TODO: Your email"]
s.homepage = "TODO" s.homepage = "TODO"
s.summary = "TODO: Summary of Gprs." s.summary = "TODO: Summary of Location."
s.description = "TODO: Description of Gprs." s.description = "TODO: Description of Location."
s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"] s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"] s.test_files = Dir["test/**/*"]

View File

@ -0,0 +1,12 @@
{
"title": "location",
"version": "0.1",
"organization": "Rulingcom",
"author": "RD dep",
"intro": "A simple blog……",
"update_info": "Some info",
"create_date": "11-11-2011",
"widgets": [],
"category": [],
"enable_frontend": false
}

View File

@ -3,7 +3,7 @@ require File.expand_path('../boot', __FILE__)
require 'rails/all' require 'rails/all'
Bundler.require Bundler.require
require "gprs" require "location"
module Dummy module Dummy
class Application < Rails::Application class Application < Rails::Application

View File

@ -1,6 +1,6 @@
require 'test_helper' require 'test_helper'
class Panel::Gprs::BackEnd::LocationsControllerTest < ActionController::TestCase class Panel::Location::BackEnd::LocationsControllerTest < ActionController::TestCase
test "should get index" do test "should get index" do
get :index get :index
assert_response :success assert_response :success

View File

@ -0,0 +1,7 @@
require 'test_helper'
class LocationTest < ActiveSupport::TestCase
test "truth" do
assert_kind_of Module, Location
end
end

View File

@ -0,0 +1,4 @@
require 'test_helper'
class Panel::Location::BackEnd::LocationsHelperTest < ActionView::TestCase
end