From 5d6279a9eada26711e4223ebee148eb55a2a5a94 Mon Sep 17 00:00:00 2001 From: Fu Matthew Date: Thu, 3 Jan 2013 10:58:52 +0800 Subject: [PATCH] fix calendar broken --- app/controllers/application_controller.rb | 3 ++- app/controllers/orbit_backend_controller.rb | 1 + app/errors/module_app_error.rb | 3 +++ .../error_handlers/module_app_error_handler.rb | 16 ++++++++++++++++ lib/tasks/migrate.rake | 12 ++++++++++++ vendor/built_in_modules/calendar/calendar.json | 14 ++++++++++++++ 6 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 app/errors/module_app_error.rb create mode 100644 lib/orbit_app/error_handlers/module_app_error_handler.rb create mode 100644 vendor/built_in_modules/calendar/calendar.json diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cddb5833..8bb94384 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,8 +2,9 @@ class ApplicationController < ActionController::Base protect_from_forgery include ParserFrontEnd, ParserBackEnd, ApplicationHelper - include OrbitApp::ErrorHandlers::ObjectAuthErrorHandler + include OrbitApp::ErrorHandlers rescue_from ObjectAuthError, :with => :render_object_auth_error + rescue_from ModuleAppError, :with => :render_module_app_error layout :layout_by_resource diff --git a/app/controllers/orbit_backend_controller.rb b/app/controllers/orbit_backend_controller.rb index 530415ba..557070f4 100644 --- a/app/controllers/orbit_backend_controller.rb +++ b/app/controllers/orbit_backend_controller.rb @@ -13,6 +13,7 @@ class OrbitBackendController < ApplicationController def setup_vars @app_title ||= controller_path.split('/')[1].singularize @module_app ||= ModuleApp.first(conditions: {:key => @app_title} ) + raise ModuleAppError, 'Can not find ModuleApp' if @module_app.nil? end private diff --git a/app/errors/module_app_error.rb b/app/errors/module_app_error.rb new file mode 100644 index 00000000..ee52369a --- /dev/null +++ b/app/errors/module_app_error.rb @@ -0,0 +1,3 @@ +class ModuleAppError < StandardError + +end \ No newline at end of file diff --git a/lib/orbit_app/error_handlers/module_app_error_handler.rb b/lib/orbit_app/error_handlers/module_app_error_handler.rb new file mode 100644 index 00000000..74001d02 --- /dev/null +++ b/lib/orbit_app/error_handlers/module_app_error_handler.rb @@ -0,0 +1,16 @@ +module OrbitApp + module ErrorHandlers + module ModuleAppErrorHandler + + + def render_module_app_error(exception = nil) + default_message = 'ModuleAppErrorHandler' + meaasge = '' + if exception + meaasge = default_message + exception.message + end + render :text=>meaasge + end + end + end +end diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index aa866e5f..74d1f53a 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -338,4 +338,16 @@ namespace :migrate do @module_app.save end + task :reinstall_calendar => :environment do + old_calendar = ModuleApp.where(key: "calendar") + old_calendar.destroy_all unless old_calendar.empty? + ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/calendar/calendar.json").read).save + end + + task :reinstall_gallery => :environment do + old_gallery = ModuleApp.where(key: "gallery") + old_gallery.destroy_all unless old_gallery.empty? + ModuleApp.new.from_json(File.open("#{Rails.root}/vendor/built_in_modules/gallery/gallery.json").read).save + end + end diff --git a/vendor/built_in_modules/calendar/calendar.json b/vendor/built_in_modules/calendar/calendar.json new file mode 100644 index 00000000..db61bc9f --- /dev/null +++ b/vendor/built_in_modules/calendar/calendar.json @@ -0,0 +1,14 @@ +{ + "title": "calendar", + "version": "0.1", + "organization": "Rulingcom", + "author": "Visual dep", + "intro": "A simple and amazing calendar", + "update_info": "Some info", + "create_date": "11-08-2012", + "app_pages": ["calendar"], + "widgets": [], + "category": [], + "widget_fields":[], + "enable_frontend": true +} \ No newline at end of file