diff --git a/app/controllers/admin/assets_controller.rb b/app/controllers/admin/assets_controller.rb new file mode 100644 index 00000000..d07d6a43 --- /dev/null +++ b/app/controllers/admin/assets_controller.rb @@ -0,0 +1,51 @@ +class Admin::AssetsController < ApplicationController + + layout "admin" + + def show + @asset = Asset.find(params[:id]) + send_data @asset.data.file.read, :filename => @asset.filename, + :type => @asset.data.content_type, + :disposition => 'inline' # or 'attachment' + end + + def index + @assets = Asset.find(:all) + end + + def edit + @asset = Asset.find(params[:id]) + end + + def new + @asset = Asset.new + end + + def create + @asset = Asset.new(params[:asset]) + if @asset.save + redirect_to admin_assets_url + else + render :action => :new + end + + end + + def update + @asset = Asset.find(params[:id]) + if @asset.update_attributes(params[:asset]) + redirect_to admin_assets_url + else + render :action => :edit + end + + end + + def destroy + @asset = Asset.find(params[:id]) + @asset.destroy + + redirect_to admin_assets_url + end + +end diff --git a/app/models/asset.rb b/app/models/asset.rb new file mode 100644 index 00000000..05ae63e7 --- /dev/null +++ b/app/models/asset.rb @@ -0,0 +1,21 @@ +class Asset + + include MongoMapper::Document + include Grip::HasAttachment + + key :filename, String, :required => true + key :description, String + + has_grid_attachment :data, :required => true + + before_validation :setup_filename + + protected + + def setup_filename + if self.filename.blank? && self.data + self.filename = self.data.file_name + end + end + +end \ No newline at end of file diff --git a/app/models/assets/asset_image.rb b/app/models/assets/asset_image.rb new file mode 100644 index 00000000..1dba508e --- /dev/null +++ b/app/models/assets/asset_image.rb @@ -0,0 +1,3 @@ +class AssetImage < Asset + +end \ No newline at end of file diff --git a/app/models/assets/asset_javascript.rb b/app/models/assets/asset_javascript.rb new file mode 100644 index 00000000..5d14b9f3 --- /dev/null +++ b/app/models/assets/asset_javascript.rb @@ -0,0 +1,3 @@ +class AssetJavascript < Asset + +end \ No newline at end of file diff --git a/app/models/assets/asset_pdf.rb b/app/models/assets/asset_pdf.rb new file mode 100644 index 00000000..457f438d --- /dev/null +++ b/app/models/assets/asset_pdf.rb @@ -0,0 +1,2 @@ +class AssetPdf < Asset +end \ No newline at end of file diff --git a/app/models/assets/asset_stylesheet.rb b/app/models/assets/asset_stylesheet.rb new file mode 100644 index 00000000..f04f37ca --- /dev/null +++ b/app/models/assets/asset_stylesheet.rb @@ -0,0 +1,3 @@ +class AssetStylesheet < Asset + +end \ No newline at end of file diff --git a/app/views/admin/assets/_form.html.erb b/app/views/admin/assets/_form.html.erb new file mode 100644 index 00000000..73f9a316 --- /dev/null +++ b/app/views/admin/assets/_form.html.erb @@ -0,0 +1,16 @@ +<%= f.error_messages %> + +

+<%= f.label :filename, "FileName" %> +<%= f.text_field :filename, :class => 'text' %> +

+ +

+<%= f.label :description, "Description" %> +<%= f.text_field :description, :class => 'text' %> +

+ +

+<%= f.label :data, "Data" %> +<%= f.file_field :data %> +

\ No newline at end of file diff --git a/app/views/admin/assets/edit.html.erb b/app/views/admin/assets/edit.html.erb new file mode 100644 index 00000000..b0a5892c --- /dev/null +++ b/app/views/admin/assets/edit.html.erb @@ -0,0 +1,12 @@ +

Editing assets

+ +<% form_for @asset, :url => admin_asset_path(@asset), :html => { :multipart => true } do |f| %> + <%= f.error_messages %> + + <%= render :partial => "form", :locals => { :f => f } %> +

+ <%= f.submit 'Update' %> +

+<% end %> + +<%= link_to 'Back', admin_assets_path %> \ No newline at end of file diff --git a/app/views/admin/assets/index.html.erb b/app/views/admin/assets/index.html.erb new file mode 100644 index 00000000..abf9d16a --- /dev/null +++ b/app/views/admin/assets/index.html.erb @@ -0,0 +1,29 @@ +

Listing assets

+ + + + + + + + + + + + +<% @assets.each do |asset| %> + + + + + + + + + +<% end %> +
檔案描述格式原上傳檔名檔案大小
<%= link_to asset.filename, admin_asset_path(asset) %><%= asset.description %><%= asset.data.content_type %><%= asset.data.file_name %><%= number_to_human_size(asset.data.file_size) %><%= link_to t(:edit), edit_admin_asset_path(asset) %><%= link_to t(:delete), admin_asset_path(asset), :confirm => 'Are you sure?', :method => :delete %>
+ +
+ +<%= link_to t(:new_asset, :scope => :admin), new_admin_asset_path, :class => 'button positive' %> \ No newline at end of file diff --git a/app/views/admin/assets/new.html.erb b/app/views/admin/assets/new.html.erb new file mode 100644 index 00000000..dc44e2df --- /dev/null +++ b/app/views/admin/assets/new.html.erb @@ -0,0 +1,11 @@ +

New Asset

+ +<% form_for :asset, :url => admin_assets_path, :html => { :multipart => true } do |f| %> + <%= f.error_messages %> + + <%= render :partial => "form", :locals => { :f => f } %> + +

+ <%= f.submit 'Create' %> +

+<% end %> \ No newline at end of file diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 72c883bd..20e7674f 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -22,6 +22,7 @@
  • <%= link_to t(:home, :scope => :admin), root_path %>
  • <%= link_to t(:item, :scope => :admin), admin_items_path %>
  • <%= link_to t(:layout, :scope => :admin), admin_layouts_path %>
  • +
  • <%= link_to t(:asset, :scope => :admin), admin_assets_path %>
  • <%= link_to t(:announcement, :scope => :admin), panel_announcements_path( :entry_name => 'news' ) %>
  • diff --git a/config/environment.rb b/config/environment.rb index d25990b7..7a5234fa 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -22,7 +22,8 @@ Rails::Initializer.run do |config| config.gem "liquid" config.gem "mongo_mapper" - + config.gem 'grip' + # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named # config.plugins = [ :exception_notification, :ssl_requirement, :all ] diff --git a/config/locales/rails.yml b/config/locales/rails.yml new file mode 100644 index 00000000..058a48e8 --- /dev/null +++ b/config/locales/rails.yml @@ -0,0 +1,132 @@ +# Chinese (Taiwan) translations for Ruby on Rails +# by tsechingho (http://github.com/tsechingho) + +:zh_tw: + date: + formats: + default: "%Y-%m-%d" + short: "%b%d日" + long: "%Y年%b%d日" + day_names: [星期日, 星期一, 星期二, 星期三, 星期四, 星期五, 星期六] + abbr_day_names: [日, 一, 二, 三, 四, 五, 六] + month_names: [~, 一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月] + abbr_month_names: [~, 1月, 2月, 3月, 4月, 5月, 6月, 7月, 8月, 9月, 10月, 11月, 12月] + order: [ :year, :month, :day ] + + time: + formats: + default: "%Y年%b%d日 %A %H:%M:%S %Z" + short: "%b%d日 %H:%M" + long: "%Y年%b%d日 %H:%M" + am: "上午" + pm: "下午" + + datetime: + distance_in_words: + half_a_minute: "半分鐘" + less_than_x_seconds: + one: "不到一秒" + other: "不到 {{count}} 秒" + x_seconds: + one: "一秒" + other: "{{count}} 秒" + less_than_x_minutes: + one: "不到一分鐘" + other: "不到 {{count}} 分鐘" + x_minutes: + one: "一分鐘" + other: "{{count}} 分鐘" + about_x_hours: + one: "大約一小時" + other: "大約 {{count}} 小時" + x_days: + one: "一天" + other: "{{count}} 天" + about_x_months: + one: "大約一個月" + other: "大約 {{count}} 個月" + x_months: + one: "一個月" + other: "{{count}} 個月" + about_x_years: + one: "大約一年" + other: "大約 {{count}} 年" + over_x_years: + one: "一年多" + other: "{{count}} 年多" + prompts: + year: "年" + month: "月" + day: "日" + hour: "時" + minute: "分" + second: "秒" + + number: + format: + separator: "." + delimiter: "," + precision: 3 + currency: + format: + format: "%u %n" + unit: "NT$" + separator: "." + delimiter: "," + precision: 2 + percentage: + format: + delimiter: "" + precision: + format: + delimiter: "" + human: + format: + delimiter: "" + precision: 1 + storage_units: + format: "%n %u" + units: + byte: + one: "Byte" + other: "Bytes" + kb: "KB" + mb: "MB" + gb: "GB" + tb: "TB" + + support: + array: + words_connector: ", " + two_words_connector: " 和 " + last_word_connector: ", 和 " + + activerecord: + errors: + template: + header: + one: "有 1 個錯誤發生使得「{{model}}」無法被儲存。" + other: "有 {{count}} 個錯誤發生使得「{{model}}」無法被儲存。" + body: "下面欄位有問題:" + messages: + inclusion: "沒有包含在列表中" + exclusion: "是被保留的" + invalid: "是無效的" + confirmation: "不符合確認值" + accepted: "必須是可被接受的" + empty: "不能留空" + blank: "不能是空白字元" + too_long: "過長(最長是 {{count}} 個字)" + too_short: "過短(最短是 {{count}} 個字)" + wrong_length: "字數錯誤(必須是 {{count}} 個字)" + taken: "已經被使用" + not_a_number: "不是數字" + greater_than: "必須大於 {{count}}" + greater_than_or_equal_to: "必須大於或等於 {{count}}" + equal_to: "必須等於 {{count}}" + less_than: "必須小於 {{count}}" + less_than_or_equal_to: "必須小於或等於 {{count}}" + odd: "必須是奇數" + even: "必須是偶數" + + diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 6403ffc6..a86547e3 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -13,4 +13,6 @@ zh_tw: new_link: 新增連結 new_snippet: 新增片段 new_layout: 新增樣板 - announcement: 公告管理 \ No newline at end of file + announcement: 公告管理 + asset: 資產管理 + new_asset: 新增資產 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 049217b7..20cdf488 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,7 @@ ActionController::Routing::Routes.draw do |map| admin.resources :components admin.resources :layouts admin.resources :snippets + admin.resources :assets end map.namespace :panel do |panel|