From cddcbf3957cd70ddcbddbc3a68f62ec5127b6cfe Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 19 Mar 2013 01:46:49 +0100 Subject: [PATCH] Improved default route for ui controller. --- .../app/controllers/dashboard.js.coffee | 10 +++------ .../app/controllers/default_route.js.coffee | 22 +++++++++++++++++++ .../app/controllers/login.js.coffee | 6 +++++ app/controllers/users_controller.rb | 13 +++++++++++ app/models/setting.rb | 10 +++++---- db/migrate/20130319003833_setting_update.rb | 21 ++++++++++++++++++ db/seeds.rb | 10 +++++++++ 7 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 app/assets/javascripts/app/controllers/default_route.js.coffee create mode 100644 db/migrate/20130319003833_setting_update.rb diff --git a/app/assets/javascripts/app/controllers/dashboard.js.coffee b/app/assets/javascripts/app/controllers/dashboard.js.coffee index d97ee21da..532d9f4f4 100644 --- a/app/assets/javascripts/app/controllers/dashboard.js.coffee +++ b/app/assets/javascripts/app/controllers/dashboard.js.coffee @@ -1,5 +1,3 @@ -$ = jQuery.sub() - class Index extends App.Controller constructor: -> @@ -8,14 +6,13 @@ class Index extends App.Controller # check authentication return if !@authenticate() - # check role if @isRole('Customer') - @navigate '#ticket_view/my_tickets' + @navigate '#' return # set title @title 'Dashboard' - @navupdate '#/' + @navupdate '#dashboard' @plugins = { main: { @@ -91,5 +88,4 @@ class Index extends App.Controller @el.find( '#sortable' ).sortable( dndOptions ) @el.find( '#sortable-sidebar' ).sortable( dndOptions ) -App.Config.set( '', Index, 'Routes' ) -App.Config.set( '/', Index, 'Routes' ) +App.Config.set( 'dashboard', Index, 'Routes' ) diff --git a/app/assets/javascripts/app/controllers/default_route.js.coffee b/app/assets/javascripts/app/controllers/default_route.js.coffee new file mode 100644 index 000000000..808a64c1a --- /dev/null +++ b/app/assets/javascripts/app/controllers/default_route.js.coffee @@ -0,0 +1,22 @@ +class Index extends App.Controller + + constructor: -> + super + + if !@Config.get('system_init_done') + @navigate '#getting_started' + return + + # check role + if @isRole('Customer') + @navigate '#ticket_view/my_tickets' + return + + if @Config.get('default_controller') + @navigate @Config.get('default_controller') + return + + @navigate '#dashboard' + +App.Config.set( '', Index, 'Routes' ) +App.Config.set( '/', Index, 'Routes' ) diff --git a/app/assets/javascripts/app/controllers/login.js.coffee b/app/assets/javascripts/app/controllers/login.js.coffee index b5b841719..7f03f9b76 100644 --- a/app/assets/javascripts/app/controllers/login.js.coffee +++ b/app/assets/javascripts/app/controllers/login.js.coffee @@ -4,6 +4,12 @@ class Index extends App.Controller constructor: -> super + + # navigate to # if sesstion if exists + if @Session.get( 'id' ) + @navigate '#' + return + @title 'Sign in' @render() @navupdate '#login' diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 84401339e..5218a9e35 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -172,6 +172,19 @@ curl http://localhost/api/users.json -v -u #{login}:#{password} -H "Content-Type user.save + # if first user set init done + if count <= 2 + Setting.create_or_update( + :title => 'System Init Done', + :name => 'system_init_done', + :area => 'Core', + :description => 'Defines if application is in init mode.', + :options => {}, + :state => true, + :frontend => true + ) + end + # send inviteation if needed / only if session exists if params[:invite] && current_user diff --git a/app/models/setting.rb b/app/models/setting.rb index 3d737bd5f..08e147f23 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -7,10 +7,12 @@ class Setting < ApplicationModel after_create :delete_cache after_update :delete_cache + @@current = {} + def self.load # check if config is already generated - return Thread.current[:settings_config] if Thread.current[:settings_config] + return @@current[:settings_config] if @@current[:settings_config] # read all config settings config = {} @@ -27,7 +29,7 @@ class Setting < ApplicationModel } # store for class requests - Thread.current[:settings_config] = config + @@current[:settings_config] = config return config end @@ -42,12 +44,12 @@ class Setting < ApplicationModel def self.get(name) self.load - return Thread.current[:settings_config][name] + return @@current[:settings_config][name] end private def delete_cache - Thread.current[:settings_config] = nil + @@current[:settings_config] = nil end def set_initial self.state_initial = self.state diff --git a/db/migrate/20130319003833_setting_update.rb b/db/migrate/20130319003833_setting_update.rb new file mode 100644 index 000000000..a5d6192de --- /dev/null +++ b/db/migrate/20130319003833_setting_update.rb @@ -0,0 +1,21 @@ +require 'user' +require 'setting' +class SettingUpdate < ActiveRecord::Migration + def up + count = User.all.count() + if count <= 2 + Setting.create_or_update( + :title => 'System Init Done', + :name => 'system_init_done', + :area => 'Core', + :description => 'Defines if application is in init mode.', + :options => {}, + :state => true, + :frontend => true + ) + end + end + + def down + end +end diff --git a/db/seeds.rb b/db/seeds.rb index e2fcec6dd..0cb203576 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -995,6 +995,16 @@ Setting.create_if_not_exists( :frontend => true ) +Setting.create_if_not_exists( + :title => 'Default Screen', + :name => 'default_controller', + :area => 'Core', + :description => 'Defines the default controller.', + :options => {}, + :state => '#dashboard', + :frontend => true +) + Setting.create_if_not_exists( :title => 'Import Mode', :name => 'import_mode',