DG MS; added checkboxes for services in the new publisher (currently not working) / user presenter contains services
This commit is contained in:
parent
680e7f6637
commit
74e9cd6ca8
10 changed files with 83 additions and 8 deletions
15
app/presenters/service_presenter.rb
Normal file
15
app/presenters/service_presenter.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
class ServicePresenter < BasePresenter
|
||||||
|
def initialize(service)
|
||||||
|
@service = service
|
||||||
|
end
|
||||||
|
|
||||||
|
def as_json
|
||||||
|
{
|
||||||
|
:provider => @service.provider
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_json(options = {})
|
||||||
|
as_json.to_json(options)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
class UserPresenter
|
class UserPresenter
|
||||||
attr_accessor :user
|
attr_accessor :user
|
||||||
|
|
||||||
def initialize(user)
|
def initialize(user)
|
||||||
self.user = user
|
self.user = user
|
||||||
end
|
end
|
||||||
|
|
@ -10,17 +10,22 @@ class UserPresenter
|
||||||
{ :notifications_count => notifications_count,
|
{ :notifications_count => notifications_count,
|
||||||
:unread_messages_count => unread_messages_count,
|
:unread_messages_count => unread_messages_count,
|
||||||
:admin => admin,
|
:admin => admin,
|
||||||
:aspects => aspects
|
:aspects => aspects,
|
||||||
|
:services => services
|
||||||
}
|
}
|
||||||
).to_json(options)
|
).to_json(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def services
|
||||||
|
ServicePresenter.as_collection(user.services)
|
||||||
|
end
|
||||||
|
|
||||||
def aspects
|
def aspects
|
||||||
AspectPresenter.as_collection(user.aspects)
|
AspectPresenter.as_collection(user.aspects)
|
||||||
end
|
end
|
||||||
|
|
||||||
def notifications_count
|
def notifications_count
|
||||||
@notification_count ||= user.unread_notifications.count
|
@notification_count ||= user.unread_notifications.count
|
||||||
end
|
end
|
||||||
|
|
||||||
def unread_messages_count
|
def unread_messages_count
|
||||||
|
|
@ -30,4 +35,4 @@ class UserPresenter
|
||||||
def admin
|
def admin
|
||||||
user.admin?
|
user.admin?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ app.forms.Post = app.forms.Base.extend({
|
||||||
templateName : "post-form",
|
templateName : "post-form",
|
||||||
|
|
||||||
subviews : {
|
subviews : {
|
||||||
".aspect_selector" : "aspectsDropdown"
|
".aspect_selector" : "aspectsDropdown",
|
||||||
|
".service_selector" : "servicesSelector"
|
||||||
},
|
},
|
||||||
|
|
||||||
formAttrs : {
|
formAttrs : {
|
||||||
|
|
@ -11,6 +12,7 @@ app.forms.Post = app.forms.Base.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
initialize : function(){
|
initialize : function(){
|
||||||
this.aspectsDropdown = new app.views.AspectsDropdown()
|
this.aspectsDropdown = new app.views.AspectsDropdown();
|
||||||
|
this.servicesSelector = new app.views.ServicesSelector();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
<div class='span12'>
|
<div class='span12'>
|
||||||
<form class="new-post well">
|
<form class="new-post well">
|
||||||
<label>text<textarea class="text"/></label>
|
<label>text<textarea class="text"/></label>
|
||||||
|
<div class="service_selector"/>
|
||||||
<div class="aspect_selector"/>
|
<div class="aspect_selector"/>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
{{#each current_user.services}}
|
||||||
|
<input type="checkbox" name="services" class="service" value="{{provider}}" />
|
||||||
|
{{provider}}
|
||||||
|
<br />
|
||||||
|
{{/each}}
|
||||||
|
<br />
|
||||||
|
|
@ -16,7 +16,7 @@ app.views.AspectsDropdown = app.views.Base.extend({
|
||||||
'custom' : setCustom
|
'custom' : setCustom
|
||||||
}
|
}
|
||||||
|
|
||||||
visibilityCallbacks[link.data("visibility") || "all-aspects"].call(this)
|
visibilityCallbacks[link.data("visibility")].call(this)
|
||||||
|
|
||||||
function setPublic (){
|
function setPublic (){
|
||||||
this.setAspectIds("public")
|
this.setAspectIds("public")
|
||||||
|
|
@ -41,4 +41,4 @@ app.views.AspectsDropdown = app.views.Base.extend({
|
||||||
setAspectIds : function(val){
|
setAspectIds : function(val){
|
||||||
this.$("input.aspect_ids").val(val)
|
this.$("input.aspect_ids").val(val)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
5
public/javascripts/app/views/services_selector_view.js
Normal file
5
public/javascripts/app/views/services_selector_view.js
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
app.views.ServicesSelector = app.views.Base.extend({
|
||||||
|
|
||||||
|
templateName : "services-selector"
|
||||||
|
|
||||||
|
});
|
||||||
23
spec/javascripts/app/views/services_selector_view_spec.js
Normal file
23
spec/javascripts/app/views/services_selector_view_spec.js
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
describe("app.views.ServicesSelector", function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
loginAs(factory.user({
|
||||||
|
services : [
|
||||||
|
{ provider : "fakeBook" }
|
||||||
|
]
|
||||||
|
}));
|
||||||
|
|
||||||
|
this.view = new app.views.ServicesSelector();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("rendering", function(){
|
||||||
|
beforeEach(function(){
|
||||||
|
this.view.render();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("displays all services", function(){
|
||||||
|
var checkboxes = $(this.view.el).find('input[type="checkbox"]');
|
||||||
|
|
||||||
|
expect(checkboxes.val()).toBe("fakeBook");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
10
spec/presenters/service_presenter_spec.rb
Normal file
10
spec/presenters/service_presenter_spec.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe ServicePresenter do
|
||||||
|
describe '#as_json' do
|
||||||
|
it 'includes the provider name of the json' do
|
||||||
|
presenter = ServicePresenter.new(stub(:provider => "fakebook"))
|
||||||
|
presenter.as_json[:provider].should == 'fakebook'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -18,4 +18,12 @@ describe UserPresenter do
|
||||||
@presenter.aspects.first[:name].should == aspect.name
|
@presenter.aspects.first[:name].should == aspect.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#services' do
|
||||||
|
it 'provides an array of jsonifed services' do
|
||||||
|
fakebook = stub(:provider => 'fakebook')
|
||||||
|
bob.stub(:services).and_return([fakebook])
|
||||||
|
@presenter.services.should include(:provider => 'fakebook')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
Loading…
Reference in a new issue