Improved default route for ui controller.
This commit is contained in:
parent
bcd9395b5f
commit
cddcbf3957
7 changed files with 81 additions and 11 deletions
|
@ -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' )
|
||||
|
|
|
@ -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' )
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
21
db/migrate/20130319003833_setting_update.rb
Normal file
21
db/migrate/20130319003833_setting_update.rb
Normal file
|
@ -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
|
10
db/seeds.rb
10
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',
|
||||
|
|
Loading…
Reference in a new issue