From 202269bb581c0812e50f166c5e979845e1d0cf9f Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 28 Jul 2014 09:36:05 +0200 Subject: [PATCH] Added config option for browser tracking and browser storage. --- .../_application_controller_generic.js.coffee | 10 ++-- .../app/controllers/_settings/area.js.coffee | 9 ++-- .../app/controllers/settings.js.coffee | 1 + .../app/lib/app_init/track.js.coffee | 5 +- .../app/lib/app_post/store.js.coffee | 5 +- db/migrate/20140728000001_update_setting1.rb | 51 +++++++++++++++++++ db/seeds.rb | 45 ++++++++++++++++ 7 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20140728000001_update_setting1.rb diff --git a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee index 7599929d6..e6a8d492d 100644 --- a/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee +++ b/app/assets/javascripts/app/controllers/_application_controller_generic.js.coffee @@ -311,7 +311,6 @@ class App.ControllerNavSidbar extends App.ControllerContent group.items = _.sortBy( itemsUnsorted, (item) -> return item.prio ) - # set active item selectedItem = undefined for group in @groupsSorted @@ -328,11 +327,6 @@ class App.ControllerNavSidbar extends App.ControllerContent @render(selectedItem) - if selectedItem - new selectedItem.controller( - el: @el.find('.main') - ) - @bind( 'ui:rerender' => @@ -349,6 +343,10 @@ class App.ControllerNavSidbar extends App.ControllerContent @el.find('li').removeClass('active') @el.find('a[href="' + selectedItem.target + '"]').parent().addClass('active') + new selectedItem.controller( + el: @el.find('.main') + ) + class App.GenericHistory extends App.ControllerModal events: 'click [data-type=sortorder]': 'sortorder', diff --git a/app/assets/javascripts/app/controllers/_settings/area.js.coffee b/app/assets/javascripts/app/controllers/_settings/area.js.coffee index 05ecd00e1..703ebfc45 100644 --- a/app/assets/javascripts/app/controllers/_settings/area.js.coffee +++ b/app/assets/javascripts/app/controllers/_settings/area.js.coffee @@ -10,11 +10,11 @@ class App.SettingsArea extends App.Controller render: => settings = App.Setting.all() - + html = $('
') for setting in settings if setting.area is @area - item = new App.SettingsAreaItem( setting: setting ) + item = new App.SettingsAreaItem( setting: setting ) html.append( item.el ) @html html @@ -67,10 +67,12 @@ class App.SettingsAreaItem extends App.Controller state = { value: params } + #App.Config.set((@setting.name, params) else state = { value: directData } + #App.Config.set(@setting.name, directData) @setting['state'] = state ui = @ @@ -83,6 +85,7 @@ class App.SettingsAreaItem extends App.Controller timeout: 1500 } ui.render() + #App.Event.trigger( 'ui:rerender' ) # login check -# App.Auth.loginCheck() + App.Auth.loginCheck() ) diff --git a/app/assets/javascripts/app/controllers/settings.js.coffee b/app/assets/javascripts/app/controllers/settings.js.coffee index ef76d01f3..0150a3e2e 100644 --- a/app/assets/javascripts/app/controllers/settings.js.coffee +++ b/app/assets/javascripts/app/controllers/settings.js.coffee @@ -10,6 +10,7 @@ class System extends App.ControllerTabs # { name: 'Log', 'target': 'log', controller: App.SettingsSystem, params: { area: 'System::Log' } }, { name: 'Storage', 'target': 'storage', controller: App.SettingsArea, params: { area: 'System::Storage' } }, { name: 'Geo Services', 'target': 'geo', controller: App.SettingsArea, params: { area: 'System::Geo' } }, + { name: 'Frontend', 'target': 'ui', controller: App.SettingsArea, params: { area: 'System::UI' } }, ] # render page diff --git a/app/assets/javascripts/app/lib/app_init/track.js.coffee b/app/assets/javascripts/app/lib/app_init/track.js.coffee index 84ecc58de..8a4f6994a 100644 --- a/app/assets/javascripts/app/lib/app_init/track.js.coffee +++ b/app/assets/javascripts/app/lib/app_init/track.js.coffee @@ -89,8 +89,8 @@ class _trackSingleton return ) - log: ( area, level, args ) -> + return if !App.Config.get('ui_send_client_stats') info = time: Math.round( new Date().getTime() / 1000 ) area: area @@ -100,10 +100,11 @@ class _trackSingleton @data.push info send: (async = true) => + return if !App.Config.get('ui_send_client_stats') return if _.isEmpty @data newData = _.clone( @data ) @data = [] - newDataNew = [] + newDataNew = [] for item in newData try itemNew = _.clone( item ) diff --git a/app/assets/javascripts/app/lib/app_post/store.js.coffee b/app/assets/javascripts/app/lib/app_post/store.js.coffee index a45d02fe6..7c3924647 100644 --- a/app/assets/javascripts/app/lib/app_post/store.js.coffee +++ b/app/assets/javascripts/app/lib/app_post/store.js.coffee @@ -46,6 +46,7 @@ class _storeSingleton write: (key, value) -> @store[key] = value return if !@support + return if !App.Config.get('ui_client_storage') try sessionStorage.setItem( key, JSON.stringify( value ) ) catch e @@ -56,6 +57,7 @@ class _storeSingleton # get item get: (key) -> return @store[key] if !@support + return @store[key] if !App.Config.get('ui_client_storage') value = sessionStorage.getItem( key ) return if !value object = JSON.parse( value ) @@ -65,6 +67,7 @@ class _storeSingleton delete: (key) -> delete @store[key] return if !@support + return if !App.Config.get('ui_client_storage') sessionStorage.removeItem( key ) # clear local storage @@ -75,7 +78,7 @@ class _storeSingleton # return list of all keys list: -> list = [] - if !@support + if !@support || !App.Config.get('ui_client_storage') for key of @store list.push key return list diff --git a/db/migrate/20140728000001_update_setting1.rb b/db/migrate/20140728000001_update_setting1.rb new file mode 100644 index 000000000..88eb5991a --- /dev/null +++ b/db/migrate/20140728000001_update_setting1.rb @@ -0,0 +1,51 @@ +class UpdateSetting1 < ActiveRecord::Migration + def up + Setting.create_if_not_exists( + :title => 'Send client stats.', + :name => 'ui_send_client_stats', + :area => 'System::UI', + :description => 'Send client stats to central server.', + :options => { + :form => [ + { + :display => '', + :null => true, + :name => 'ui_send_client_stats', + :tag => 'boolean', + :options => { + true => 'yes', + false => 'no', + }, + }, + ], + }, + :state => true, + :frontend => true + ) + Setting.create_if_not_exists( + :title => 'Client storage.', + :name => 'ui_client_storage', + :area => 'System::UI', + :description => 'Use client storage to cache data to perform speed of application.', + :options => { + :form => [ + { + :display => '', + :null => true, + :name => 'ui_client_storage', + :tag => 'boolean', + :options => { + true => 'yes', + false => 'no', + }, + }, + ], + }, + :state => false, + :frontend => true + ) + end + + def down + end +end \ No newline at end of file diff --git a/db/seeds.rb b/db/seeds.rb index 23775ab31..90a430315 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -178,6 +178,51 @@ Setting.create_if_not_exists( :frontend => false ) +Setting.create_if_not_exists( + :title => 'Send client stats.', + :name => 'ui_send_client_stats', + :area => 'System::UI', + :description => 'Send client stats to central server.', + :options => { + :form => [ + { + :display => '', + :null => true, + :name => 'ui_send_client_stats', + :tag => 'boolean', + :options => { + true => 'yes', + false => 'no', + }, + }, + ], + }, + :state => true, + :frontend => true +) +Setting.create_if_not_exists( + :title => 'Client storage.', + :name => 'ui_client_storage', + :area => 'System::UI', + :description => 'Use client storage to cache data to perform speed of application.', + :options => { + :form => [ + { + :display => '', + :null => true, + :name => 'ui_client_storage', + :tag => 'boolean', + :options => { + true => 'yes', + false => 'no', + }, + }, + ], + }, + :state => false, + :frontend => true +) + Setting.create_if_not_exists( :title => 'New User Accounts', :name => 'user_create_account',