summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock3
-rw-r--r--app/controllers/switchboard_entries_controller.rb13
-rw-r--r--app/controllers/switchboards_controller.rb13
-rw-r--r--app/serializers/switchboard_entry_serializer.rb3
-rw-r--r--app/serializers/switchboard_serializer.rb6
-rw-r--r--app/views/switchboards/show.html.erb19
-rw-r--r--config/routes.rb2
-rw-r--r--public/js/app.js59
9 files changed, 109 insertions, 10 deletions
diff --git a/Gemfile b/Gemfile
index 0084033..b29d333 100644
--- a/Gemfile
+++ b/Gemfile
@@ -14,6 +14,7 @@ gem 'state_machine'
gem 'acts_as_list'
gem 'dalli' # memcached
gem 'inifile'
+gem 'active_model_serializers' # JSON
# Useful Rails 4 stuff
#
diff --git a/Gemfile.lock b/Gemfile.lock
index 1a120fe..f286709 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -14,6 +14,8 @@ GEM
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.2.1)
+ active_model_serializers (0.7.0)
+ activemodel (>= 3.0)
activemodel (3.2.13)
activesupport (= 3.2.13)
builder (~> 3.0.0)
@@ -213,6 +215,7 @@ PLATFORMS
ruby
DEPENDENCIES
+ active_model_serializers
acts_as_list
backup
bcrypt-ruby
diff --git a/app/controllers/switchboard_entries_controller.rb b/app/controllers/switchboard_entries_controller.rb
index ef6c72e..32ca9bb 100644
--- a/app/controllers/switchboard_entries_controller.rb
+++ b/app/controllers/switchboard_entries_controller.rb
@@ -8,8 +8,17 @@ class SwitchboardEntriesController < ApplicationController
end
def show
- @switchboard_entry = @switchboard.switchboard_entries.find(params[:id])
- spread_breadcrumbs
+ if @switchboard
+ @switchboard_entry = @switchboard.switchboard_entries.find(params[:id])
+ spread_breadcrumbs
+ else
+ @switchboard_entry = SwitchboardEntry.find(params[:id])
+ end
+
+ respond_to do |format|
+ format.html
+ format.json { render json: @switchboard_entry }
+ end
end
def new
diff --git a/app/controllers/switchboards_controller.rb b/app/controllers/switchboards_controller.rb
index c499c69..8ceb96d 100644
--- a/app/controllers/switchboards_controller.rb
+++ b/app/controllers/switchboards_controller.rb
@@ -3,8 +3,16 @@ class SwitchboardsController < ApplicationController
authorize_resource :switchboard, :through => :user
def index
+ if @user.nil?
+ @user = current_user
+ end
@switchboards = @user.switchboards
spread_breadcrumbs
+
+ respond_to do |format|
+ format.html
+ format.json { render json: @switchboards }
+ end
end
def show
@@ -14,6 +22,11 @@ class SwitchboardsController < ApplicationController
@switchboard = @user.switchboards.find(params[:id])
@switchboard_entries = @switchboard.switchboard_entries
spread_breadcrumbs
+
+ respond_to do |format|
+ format.html
+ format.json { render json: @switchboard }
+ end
end
def new
diff --git a/app/serializers/switchboard_entry_serializer.rb b/app/serializers/switchboard_entry_serializer.rb
new file mode 100644
index 0000000..dace1c5
--- /dev/null
+++ b/app/serializers/switchboard_entry_serializer.rb
@@ -0,0 +1,3 @@
+class SwitchboardEntrySerializer < ActiveModel::Serializer
+ attributes :id, :name
+end
diff --git a/app/serializers/switchboard_serializer.rb b/app/serializers/switchboard_serializer.rb
new file mode 100644
index 0000000..c460add
--- /dev/null
+++ b/app/serializers/switchboard_serializer.rb
@@ -0,0 +1,6 @@
+class SwitchboardSerializer < ActiveModel::Serializer
+ embed :ids, :include => true
+
+ attributes :id, :name
+ has_many :switchboard_entries, :key => :switchboard_entry_ids, :root => :switchboardEntrys
+end
diff --git a/app/views/switchboards/show.html.erb b/app/views/switchboards/show.html.erb
index 337d00c..a4bdae0 100644
--- a/app/views/switchboards/show.html.erb
+++ b/app/views/switchboards/show.html.erb
@@ -1,19 +1,26 @@
<% content_for :title, "Switchboard #{@switchboard.name}" %>
+<script>
+ var switchboard_id = <%= @switchboard.id %>;
+</script>
+
<div class='row'>
<div class='span12'>
- <div id='container'>
-
- </div>
+ <div id='container'></div>
<script type="text/x-handlebars">
- <h1>{{appName}}</h1>
+ <p>{{appName}}</p>
+ <p>{{title}}</p>
- <h2>{{title}}</h2>
+ {{outlet}}
</script>
+ <script type="text/x-handlebars" data-template-name="switchboard">
+ <h1>{{name}}</h1>
+ <p>switchboard view marker</p>
+ <p>Length: {{switchboardEntrys.length}}</p>
+ </script>
-
</div>
</div>
diff --git a/config/routes.rb b/config/routes.rb
index 3f0aae4..a4ab062 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -10,6 +10,8 @@ Gemeinschaft42c::Application.routes.draw do
end
end
+ resources :switchboard_entries, :only => [:show]
+
resources :restore_jobs
resources :groups do
diff --git a/public/js/app.js b/public/js/app.js
index 238f29e..97ed43e 100644
--- a/public/js/app.js
+++ b/public/js/app.js
@@ -3,14 +3,69 @@ App = Ember.Application.create({
rootElement: '#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!");
+ 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'
-}); \ No newline at end of file
+});
+
+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')
+ }
+});
+
+// // Views
+// App.SwitchboardView = Ember.View.extend({
+// templateName: 'switchboard'
+// }); \ No newline at end of file