diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-03-26 16:55:08 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-04-03 22:09:33 +0200 |
commit | 64653a9149eca977c16233abb0a472730b94a464 (patch) | |
tree | 7cfd94c7a7cd44374cf88c61f0f7bd926c351615 | |
parent | 877364c24ef9c7954f0e193456bb3f2d39169977 (diff) |
Store reload interval in the Switchboard table.
-rw-r--r-- | app/controllers/switchboard_entries_controller.rb | 13 | ||||
-rw-r--r-- | app/controllers/switchboards_controller.rb | 5 | ||||
-rw-r--r-- | app/models/switchboard.rb | 21 | ||||
-rw-r--r-- | app/models/switchboard_entry.rb | 2 | ||||
-rw-r--r-- | app/serializers/switchboard_entry_serializer.rb | 2 | ||||
-rw-r--r-- | app/serializers/switchboard_serializer.rb | 7 | ||||
-rw-r--r-- | app/views/switchboards/_form_core.html.haml | 3 | ||||
-rw-r--r-- | app/views/switchboards/app.js | 8 | ||||
-rw-r--r-- | app/views/switchboards/show.html.erb | 40 | ||||
-rw-r--r-- | config/locales/views/switchboards/de.yml | 15 | ||||
-rw-r--r-- | config/locales/views/switchboards/en.yml | 15 | ||||
-rw-r--r-- | config/routes.rb | 2 | ||||
-rw-r--r-- | db/migrate/20130326143653_add_reload_timer_to_switchboard.rb | 7 | ||||
-rw-r--r-- | public/js/app.js | 58 | ||||
-rw-r--r-- | public/js/old2-app.js | 64 |
15 files changed, 201 insertions, 61 deletions
diff --git a/app/controllers/switchboard_entries_controller.rb b/app/controllers/switchboard_entries_controller.rb index 32ca9bb..3f82976 100644 --- a/app/controllers/switchboard_entries_controller.rb +++ b/app/controllers/switchboard_entries_controller.rb @@ -3,8 +3,17 @@ class SwitchboardEntriesController < ApplicationController authorize_resource :switchboard_entry, :through => :switchboard, :except => [:sort] def index - @switchboard_entries = @switchboard.switchboard_entries - spread_breadcrumbs + if @switchboard + @switchboard_entries = @switchboard.switchboard_entries + spread_breadcrumbs + else + @switchboard_entries = SwitchboardEntry.where(:id => params[:ids]) + end + + respond_to do |format| + format.html + format.json { render json: @switchboard_entries } + end end def show diff --git a/app/controllers/switchboards_controller.rb b/app/controllers/switchboards_controller.rb index 8ceb96d..d3424ad 100644 --- a/app/controllers/switchboards_controller.rb +++ b/app/controllers/switchboards_controller.rb @@ -31,6 +31,9 @@ class SwitchboardsController < ApplicationController def new @switchboard = @user.switchboards.build + @switchboard.show_avatars = true + @switchboard.entry_width = 2 + @switchboard.reload_interval = 2000 spread_breadcrumbs end @@ -68,7 +71,7 @@ class SwitchboardsController < ApplicationController private def switchboard_params - params.require(:switchboard).permit(:name) + params.require(:switchboard).permit(:name, :reload_interval, :show_avatars, :entry_width) end def spread_breadcrumbs diff --git a/app/models/switchboard.rb b/app/models/switchboard.rb index 74e2767..360de70 100644 --- a/app/models/switchboard.rb +++ b/app/models/switchboard.rb @@ -6,11 +6,32 @@ class Switchboard < ActiveRecord::Base :presence => true, :uniqueness => {:scope => :user_id} + validates :reload_interval, + :numericality => { :only_integer => true, + :greater_than => 250, + :allow_nil => true + } + + validates :entry_width, + :numericality => { :only_integer => true, + :greater_than => 0, + :less_than => 5 + } + belongs_to :user, :touch => true has_many :switchboard_entries, :dependent => :destroy has_many :sip_accounts, :through => :switchboard_entries + before_validation :convert_0_to_nil + def to_s self.name.to_s end + + private + def convert_0_to_nil + if self.reload_interval == 0 + self.reload_interval = nil + end + end end diff --git a/app/models/switchboard_entry.rb b/app/models/switchboard_entry.rb index 76d002f..faeba8c 100644 --- a/app/models/switchboard_entry.rb +++ b/app/models/switchboard_entry.rb @@ -5,6 +5,8 @@ class SwitchboardEntry < ActiveRecord::Base belongs_to :switchboard, :touch => true belongs_to :sip_account, :touch => true + has_many :phone_numbers, :through => :sip_account + validates :switchboard, :presence => true diff --git a/app/serializers/switchboard_entry_serializer.rb b/app/serializers/switchboard_entry_serializer.rb index dace1c5..0b5f4c1 100644 --- a/app/serializers/switchboard_entry_serializer.rb +++ b/app/serializers/switchboard_entry_serializer.rb @@ -1,3 +1,5 @@ class SwitchboardEntrySerializer < ActiveModel::Serializer attributes :id, :name + + has_many :phone_numbers, embed: :ids end diff --git a/app/serializers/switchboard_serializer.rb b/app/serializers/switchboard_serializer.rb index c460add..2912a56 100644 --- a/app/serializers/switchboard_serializer.rb +++ b/app/serializers/switchboard_serializer.rb @@ -1,6 +1,7 @@ class SwitchboardSerializer < ActiveModel::Serializer - embed :ids, :include => true - attributes :id, :name - has_many :switchboard_entries, :key => :switchboard_entry_ids, :root => :switchboardEntrys + + embed :ids + + has_many :switchboard_entries, :key => :switchboard_entrys end diff --git a/app/views/switchboards/_form_core.html.haml b/app/views/switchboards/_form_core.html.haml index 61b5934..59a2442 100644 --- a/app/views/switchboards/_form_core.html.haml +++ b/app/views/switchboards/_form_core.html.haml @@ -1,2 +1,5 @@ .inputs = f.input :name, :label => t('switchboards.form.name.label'), :hint => conditional_hint('switchboards.form.name.hint'), :autofocus => true + = f.input :reload_interval, :label => t('switchboards.form.reload_interval.label'), :hint => conditional_hint('switchboards.form.reload_interval.hint') + = f.input :show_avatars, :label => t('switchboards.form.show_avatars.label'), :hint => conditional_hint('switchboards.form.show_avatars.hint') + = f.input :entry_width, :label => t('switchboards.form.entry_width.label'), :hint => conditional_hint('switchboards.form.entry_width.hint') diff --git a/app/views/switchboards/app.js b/app/views/switchboards/app.js deleted file mode 100644 index a4aa100..0000000 --- a/app/views/switchboards/app.js +++ /dev/null @@ -1,8 +0,0 @@ -window.App = Ember.Application.create({ - rootElement: '#xxxyyy', - - ready: function() { - App.view.appendTo('#xxxyyy'); - } -}); - diff --git a/app/views/switchboards/show.html.erb b/app/views/switchboards/show.html.erb index a4bdae0..87bb551 100644 --- a/app/views/switchboards/show.html.erb +++ b/app/views/switchboards/show.html.erb @@ -2,23 +2,47 @@ <script> var switchboard_id = <%= @switchboard.id %>; + var show_avatars = <%= @switchboard.show_avatars.to_s %>; + var reload_interval = <%= @switchboard.reload_interval.nil? ? 0 : @switchboard.reload_interval %>; </script> <div class='row'> <div class='span12'> - <div id='container'></div> - - <script type="text/x-handlebars"> - <p>{{appName}}</p> - <p>{{title}}</p> + <div id='emberjs-container'></div> + <script type="text/x-handlebars" data-template-name="application"> {{outlet}} </script> <script type="text/x-handlebars" data-template-name="switchboard"> - <h1>{{name}}</h1> - <p>switchboard view marker</p> - <p>Length: {{switchboardEntrys.length}}</p> + <h2>{{name}}</h2> + + {{#if switchboardEntrys.length}} + <ul class="thumbnails"> + {{#each switchboardEntry in switchboardEntrys}} + <li class="span2"> + <div class="thumbnail"> + <a class="thumbnail" href="/tenants/2/users/2"> + <img alt="User-male-16x" class="img-rounded" src="/assets/icons/user-male-16x.png" style="width: 100px;"> + </a> + <p> + <small> + {{switchboardEntry.name}} + <br> + <span class="label"> + 33 + </span> + <br> + <span class="label label-inverse"> + <i class="icon-ban-circle icon-white"></i> + </span> + </small> + </p> + </div> + </li> + {{/each}} + </ul> + {{/if}} </script> </div> diff --git a/config/locales/views/switchboards/de.yml b/config/locales/views/switchboards/de.yml index 97a47b8..e73b100 100644 --- a/config/locales/views/switchboards/de.yml +++ b/config/locales/views/switchboards/de.yml @@ -9,6 +9,9 @@ de: page_title: 'Switchboards' name: 'Name' user_id: 'User' + reload_interval:: 'Reload Interval' + show_avatars: 'Show avatars' + entry_width: 'Entry width' actions: confirm_destroy: 'Sind Sie sicher, dass Sie folgendes löschen möchten: Switchboard' destroy: 'Löschen' @@ -20,6 +23,9 @@ de: page_title: 'Switchboard bearbeiten' name: 'Name' user_id: 'User' + reload_interval:: 'Reload Interval' + show_avatars: 'Show avatars' + entry_width: 'Entry width' actions: confirm_destroy: 'Sind Sie sicher, dass die dieses Element löschen möchten?' destroy: 'Löschen' @@ -42,4 +48,13 @@ de: user_id: label: 'User' hint: '' + reload_interval: + label: 'Reload Interval' + hint: 'Milliseconds. nil = no reload' + show_avatars: + label: 'Show avatars' + hint: '' + entry_width: + label: 'Entry width' + hint: '' submit: 'Absenden'
\ No newline at end of file diff --git a/config/locales/views/switchboards/en.yml b/config/locales/views/switchboards/en.yml index a860763..8489d28 100644 --- a/config/locales/views/switchboards/en.yml +++ b/config/locales/views/switchboards/en.yml @@ -9,6 +9,9 @@ en: page_title: 'Switchboards' name: 'Name' user_id: 'User' + reload_interval:: 'Reload Interval' + show_avatars: 'Show avatars' + entry_width: 'Entry width' actions: confirm_destroy: 'Are you sure you want to delete this Switchboard?' destroy: 'Delete' @@ -20,6 +23,9 @@ en: page_title: 'Show Switchboard' name: 'Name' user_id: 'User' + reload_interval:: 'Reload Interval' + show_avatars: 'Show avatars' + entry_width: 'Entry width' actions: confirm_destroy: 'Are you sure you want to delete this element?' destroy: 'Delete' @@ -42,4 +48,13 @@ en: user_id: label: 'User' hint: '' + reload_interval: + label: 'Reload Interval' + hint: 'Milliseconds. nil = no reload' + show_avatars: + label: 'Show avatars' + hint: '' + entry_width: + label: 'Entry width' + hint: '' submit: 'Submit'
\ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index a4ab062..ce4c028 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,7 +10,7 @@ Gemeinschaft42c::Application.routes.draw do end end - resources :switchboard_entries, :only => [:show] + resources :switchboard_entries, :only => [:show, :index] resources :restore_jobs diff --git a/db/migrate/20130326143653_add_reload_timer_to_switchboard.rb b/db/migrate/20130326143653_add_reload_timer_to_switchboard.rb new file mode 100644 index 0000000..8689c5f --- /dev/null +++ b/db/migrate/20130326143653_add_reload_timer_to_switchboard.rb @@ -0,0 +1,7 @@ +class AddReloadTimerToSwitchboard < ActiveRecord::Migration + def change + add_column :switchboards, :reload_interval, :integer + add_column :switchboards, :show_avatars, :boolean + add_column :switchboards, :entry_width, :integer + end +end diff --git a/public/js/app.js b/public/js/app.js index 97ed43e..87a4ba6 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -1,42 +1,31 @@ App = Ember.Application.create({ LOG_TRANSITIONS: true, - rootElement: '#container' + rootElement: '#emberjs-container', + + // Reload the switchboard every x milliseconds + // if reload_interval != 0 + ready: function() { + if (reload_interval != 0) { + var switchboard = App.Switchboard.find(switchboard_id); + setInterval(function() { + switchboard.reload(); + }, reload_interval); + } + } }); // Router App.Router.map(function() { - this.resource('switchboards', function() { - this.resource('switchboard', { path: ':switchboard_id' }); - }); -}); - -App.ApplicationRoute = Ember.Route.extend({ - setupController: function(controller) { - // `controller` is the instance of ApplicationController - controller.set('title', "Hello world! Switchboard #" + switchboard_id); - } + this.resource('switchboard', { path: '/' }); }); -App.SwitchboardsRoute = Ember.Route.extend({ +App.SwitchboardRoute = Ember.Route.extend({ model: function() { - return App.Switchboard.find(); + return App.Switchboard.find(switchboard_id); } }); -App.IndexRoute = Ember.Route.extend({ - redirect: function() { - this.transitionTo('switchboard', App.Switchboard.find(switchboard_id)); - } -}); - // Controller -App.ApplicationController = Ember.Controller.extend({ - appName: 'My First Example' -}); - -App.SwitchboardsController = Ember.ArrayController.extend({ - // switchboardEntrys: table.get('tab.tabItems') -}) // Models App.Store = DS.Store.extend({ @@ -50,22 +39,15 @@ DS.RESTAdapter.configure("plurals", { App.Switchboard = DS.Model.extend({ switchboardEntrys: DS.hasMany('App.SwitchboardEntry'), name: DS.attr('string'), - didLoad: function() { - console.log('Switchboard model loaded') - } }); - - App.SwitchboardEntry = DS.Model.extend({ switchboard: DS.belongsTo('App.Switchboard'), + switchboard: DS.belongsTo('App.SipAccount'), name: DS.attr('string'), - didLoad: function() { - console.log('SwitchboardEntry model loaded') - } }); -// // Views -// App.SwitchboardView = Ember.View.extend({ -// templateName: 'switchboard' -// });
\ No newline at end of file +App.SipAccount = DS.Model.extend({ + switchboardEntrys: DS.hasMany('App.SwitchboardEntry'), + callerName: DS.attr('string'), +});
\ No newline at end of file diff --git a/public/js/old2-app.js b/public/js/old2-app.js new file mode 100644 index 0000000..4ee9ac9 --- /dev/null +++ b/public/js/old2-app.js @@ -0,0 +1,64 @@ +App = Ember.Application.create({ + LOG_TRANSITIONS: true, + rootElement: '#emberjs-container' +}); + +// Router +App.Router.map(function() { + this.resource('switchboards', function() { + this.resource('switchboard', { path: ':switchboard_id' }); + }); +}); + +App.ApplicationRoute = Ember.Route.extend({ + setupController: function(controller) { + // `controller` is the instance of ApplicationController + controller.set('title', "Hello world! Switchboard #" + switchboard_id); + } +}); + +App.SwitchboardsRoute = Ember.Route.extend({ + model: function() { + return App.Switchboard.find(); + } +}); + +App.IndexRoute = Ember.Route.extend({ + redirect: function() { + this.transitionTo('switchboard', App.Switchboard.find(switchboard_id)); + } +}); + +// Controller +App.ApplicationController = Ember.Controller.extend({ + appName: 'My First Example' +}); + +App.SwitchboardsController = Ember.ArrayController.extend({ + // switchboardEntrys: table.get('tab.tabItems') +}) + +// Models +App.Store = DS.Store.extend({ + revision: 11 +}); + +DS.RESTAdapter.configure("plurals", { + switchboard_entry: "switchboard_entries" +}); + +App.Switchboard = DS.Model.extend({ + switchboardEntrys: DS.hasMany('App.SwitchboardEntry'), + name: DS.attr('string'), + didLoad: function() { + console.log('Switchboard model loaded') + } +}); + +App.SwitchboardEntry = DS.Model.extend({ + switchboard: DS.belongsTo('App.Switchboard'), + name: DS.attr('string'), + didLoad: function() { + console.log('SwitchboardEntry model loaded') + } +}); |