Commit 648f0e6b authored by Leandro Nunes's avatar Leandro Nunes
Browse files

Merge branch 'article_datetime' of gitlab.com:participa/noosfero into article_datetime

parents d168d5b8 a8fd5395
class FavoriteEnterprisesController < MyProfileController
# protect 'manage_favorite_enteprises', :profile
# protect 'manage_favorite_enterprises', :profile
requires_profile_class Person
def index
@favorite_enterprises = profile.favorite_enterprises
end
......@@ -12,7 +12,7 @@ class FavoriteEnterprisesController < MyProfileController
@favorite_enterprise = Enterprise.find(params[:id])
if request.post? && params[:confirmation]
profile.favorite_enterprises << @favorite_enterprise
redirect_to :action => 'index'
redirect_to :action => 'index'
end
end
......
......@@ -8,7 +8,8 @@ class Article < ActiveRecord::Base
:accept_comments, :feed, :published, :source, :source_name,
:highlighted, :notify_comments, :display_hits, :slug,
:external_feed_builder, :display_versions, :external_link,
:image_builder, :show_to_followers
:image_builder, :show_to_followers,
:author
acts_as_having_image
......
......@@ -114,7 +114,7 @@ class Event < Article
end
def duration
((self.end_date || self.start_date) - self.start_date).to_i
(((self.end_date || self.start_date) - self.start_date).to_i/60/60/24)
end
alias_method :article_lead, :lead
......
......@@ -163,4 +163,8 @@ class UploadedFile < Article
true
end
def notifiable?
true
end
end
......@@ -14,7 +14,7 @@ p. Find on top of page the term "Enterprises" and click on it:
h2(#description). Description
# Fill in the search field with what you want to look for and click on "Search" !=/images/doc/enterprises-search-field.en.png(Enterprises search field)!
# Then you will see the search results. To see more results, click on the pages below the search results. !=/images/doc/enterprises-search-results-with-example.en.png(Enteprises search results with example)!
# Then you will see the search results. To see more results, click on the pages below the search results. !=/images/doc/enterprises-search-results-with-example.en.png(Enterprises search results with example)!
# Clicking on one of the search results, you will be redirected to the homepage of choosen enterprise.
h3. More options
......
......@@ -25,7 +25,7 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id)
if tracked_action.user.is_a? Organization
ActionTrackerNotification.connection.execute "insert into action_tracker_notifications(profile_id, action_tracker_id) " +
"select distinct accessor_id, #{tracked_action.id} from role_assignments where resource_id = #{tracked_action.user.id} and resource_type='Profile' " +
if tracked_action.user.is_a? Enterprise then "union select distinct person_id, #{tracked_action.id} from favorite_enteprises_people where enterprise_id = #{tracked_action.user.id}" else "" end
if tracked_action.user.is_a? Enterprise then "union select distinct person_id, #{tracked_action.id} from favorite_enterprise_people where enterprise_id = #{tracked_action.user.id}" else "" end
end
if target.is_a?(Community)
......
......@@ -169,7 +169,7 @@ def test_sequence(plugins, tasks)
failed[plugin] << task
end
end
disable_plugins(plugin)
disable_plugins
end
fail_flag = false
failed.each do |plugin, tasks|
......
......@@ -30,13 +30,13 @@ class EventPlugin::EventBlock < Block
events = user.nil? ? events.public : events.display_filter(user,nil)
if future_only
events = events.where('start_date >= ?', Date.today)
events = events.where('start_date >= ?', DateTime.now.beginning_of_day)
end
if date_distance_limit > 0
events = events.by_range([
Date.today - date_distance_limit,
Date.today + date_distance_limit
DateTime.now.beginning_of_day - date_distance_limit,
DateTime.now.beginning_of_day + date_distance_limit
])
end
......
require File.dirname(__FILE__) + '/../../../../test/test_helper'
# Re-raise errors caught by the controller.
class HomeController
#append_view_path File.join(File.dirname(__FILE__) + '/../../views')
append_view_path File.join(File.dirname(__FILE__) + '/../../views')
def rescue_action(e)
raise e
end
......@@ -15,7 +16,7 @@ class HomeControllerTest < ActionController::TestCase
@env.enable_plugin('EventPlugin')
@p1 = fast_create(Person, :environment_id => @env.id)
@e1a = fast_create(Event, :name=>'Event p1 A', :profile_id=>@p1.id)
@e1a = Event.create!(:name=>'Event p1 A', :profile =>@p1)
box = Box.create!(:owner => @env)
@block = EventPlugin::EventBlock.create!(:box => box)
......@@ -27,6 +28,7 @@ class HomeControllerTest < ActionController::TestCase
should 'see events microdata sturcture' do
get :index
#raise response.body.inspect
assert_select '.event-plugin_event-block ul.events'
assert_select ev
assert_select ev + 'a[itemprop="url"]'
......@@ -41,15 +43,15 @@ class HomeControllerTest < ActionController::TestCase
should 'see event duration' do
@e1a.slug = 'event1a'
@e1a.start_date = Date.today
@e1a.end_date = Date.today + 1.day
@e1a.start_date = DateTime.now
@e1a.end_date = DateTime.now + 1.day
@e1a.save!
get :index
assert_select ev + 'time.duration[itemprop="endDate"]', /1 day/
@e1a.slug = 'event1a'
@e1a.start_date = Date.today
@e1a.end_date = Date.today + 2.day
@e1a.start_date = DateTime.now
@e1a.end_date = DateTime.now + 2.day
@e1a.save!
get :index
assert_select ev + 'time.duration[itemprop="endDate"]', /2 days/
......@@ -60,8 +62,8 @@ class HomeControllerTest < ActionController::TestCase
assert_select ev + 'time.duration[itemprop="endDate"]', false
@e1a.slug = 'event1a'
@e1a.start_date = Date.today
@e1a.end_date = Date.today
@e1a.start_date = DateTime.now
@e1a.end_date = DateTime.now
@e1a.save!
get :index
assert_select ev + 'time.duration[itemprop="endDate"]', false
......
......@@ -2,7 +2,7 @@
<ul class="events">
<% block.events(user).map do |event| %>
<% days_left = ( event.start_date - Date.today ).round %>
<% days_left = ( (event.start_date - DateTime.now)/60/60/24 ).round %>
<li itemscope="itemscope" itemtype="http://data-vocabulary.org/Event" class="event">
<%= render(
:file => 'event_plugin/event_block_item',
......
gem 'jsonify-rails'
class OpenGraphPlugin::MyprofileController < MyProfileController
protect 'edit_profile', :profile
before_filter :set_context
def enterprise_search
scope = environment.enterprises.enabled.public
profile_search scope
end
def community_search
scope = environment.communities.public
profile_search scope
end
def friend_search
scope = profile.friends
profile_search scope
end
def track_config
profile.update_attributes! params[:profile_data]
render partial: 'track_form', locals: {context: context, reload: true}
end
protected
def profile_search scope
@query = params[:query]
@profiles = scope.limit(10).order('name ASC').
where(['name ILIKE ? OR name ILIKE ? OR identifier LIKE ?', "#{@query}%", "% #{@query}%", "#{@query}%"])
render partial: 'profile_search', locals: {profiles: @profiles}
end
def context
:open_graph
end
def set_context
OpenGraphPlugin.context = self.context
end
def default_url_options
# avoid rails' use_relative_controller!
{use_route: '/'}
end
end
class CreateOpenGraphPluginTracks < ActiveRecord::Migration
def up
create_table :open_graph_plugin_tracks do |t|
t.string :type
t.string :context
t.boolean :enabled, default: true
t.integer :tracker_id
t.integer :actor_id
t.string :action
t.string :object_type
t.text :object_data_url
t.integer :object_data_id
t.string :object_data_type
t.timestamps
end
add_index :open_graph_plugin_tracks, [:type]
add_index :open_graph_plugin_tracks, [:context]
add_index :open_graph_plugin_tracks, [:type, :context]
add_index :open_graph_plugin_tracks, [:actor_id]
add_index :open_graph_plugin_tracks, [:action]
add_index :open_graph_plugin_tracks, [:object_type]
add_index :open_graph_plugin_tracks, [:enabled]
add_index :open_graph_plugin_tracks, [:object_data_url]
add_index :open_graph_plugin_tracks, [:object_data_id, :object_data_type], name: 'index_open_graph_plugin_tracks_object_data_id_type'
end
def down
drop_table :open_graph_plugin_tracks
end
end
system "script/noosfero-plugins -q enable metadata"
require_dependency 'article'
class Article
after_update :open_graph_scrape
protected
def open_graph_scrape
activity = OpenGraphPlugin::Activity.where(object_data_id: self.id, object_data_type: self.class.base_class.name).first
activity.scrape if activity
end
handle_asynchronously :open_graph_scrape
end
require_dependency 'profile'
# hate to wrte this, but without Noosfero::Plugin::Settings is loaded instead
require 'open_graph_plugin/settings'
# attr_accessible must be defined on subclasses
Profile.descendants.each do |subclass|
subclass.class_eval do
attr_accessible :open_graph_settings
OpenGraphPlugin::TrackConfig::Types.each do |track, klass|
klass = "OpenGraphPlugin::#{klass}".constantize
attributes = "#{klass.association}_attributes"
profile_ids = "open_graph_#{track}_profiles_ids"
attr_accessible attributes
attr_accessible profile_ids
end
end
end
class Profile
def open_graph_settings attrs = {}
@open_graph_settings ||= OpenGraphPlugin::Settings.new self, attrs
attrs.each{ |a, v| @open_graph_settings.send "#{a}=", v }
@open_graph_settings
end
alias_method :open_graph_settings=, :open_graph_settings
has_many :open_graph_tracks, class_name: 'OpenGraphPlugin::Track', source: :tracker_id, foreign_key: :tracker_id
has_many :open_graph_activities, class_name: 'OpenGraphPlugin::Activity', source: :tracker_id, foreign_key: :tracker_id
has_many :open_graph_track_configs, class_name: 'OpenGraphPlugin::TrackConfig', source: :tracker_id, foreign_key: :tracker_id
OpenGraphPlugin::TrackConfig::Types.each do |track, klass|
klass = "OpenGraphPlugin::#{klass}".constantize
association = klass.association
profile_ids = "open_graph_#{track}_profiles_ids"
has_many association, class_name: klass.name, foreign_key: :tracker_id
accepts_nested_attributes_for association, allow_destroy: true, reject_if: :open_graph_reject_empty_object_type
define_method "#{profile_ids}=" do |ids|
cids = self.send(association).order('created_at ASC').map(&:object_data_id)
nids = if ids.is_a? Array then ids else ids.split ',' end
nids = nids.map(&:to_i)
Profile.where(id: nids-cids).each{ |profile| self.send(association).create! type: klass.name, object_data: profile }
self.send(association).each{ |c| c.destroy unless c.object_data_id.in? nids }
end
end
define_method :open_graph_reject_empty_object_type do |attributes|
exists = attributes[:id].present?
empty = attributes[:object_type].empty?
attributes.merge! _destroy: 1 if exists and empty
return (!exists and empty)
end
end
require_dependency 'profile_activity'
class ProfileActivity
# update happens with grouped ActionTracker
after_save :open_graph_publish
def open_graph_publish
# Scrap not yet supported
if self.activity.is_a? ActionTracker::Record
verb = self.activity.verb.to_sym
return unless object = self.activity.target
return unless stories = OpenGraphPlugin::Stories::TrackerStories[verb]
OpenGraphPlugin::Stories.publish object, stories
end
end
end
require_dependency 'uploaded_file'
class UploadedFile
extend OpenGraphPlugin::AttachStories::ClassMethods
open_graph_attach_stories only: :add_an_image
end
module OpenGraphPlugin
extend Noosfero::Plugin::ParentMethods
def self.plugin_name
I18n.t 'open_graph_plugin.lib.plugin.name'
end
def self.plugin_description
I18n.t 'open_graph_plugin.lib.plugin.description'
end
def self.context
Thread.current[:open_graph_context] || :open_graph
end
def self.context= value
Thread.current[:open_graph_context] = value
end
end
require_dependency 'open_graph_plugin/stories'
# This is used when ActionTracker is not compartible with the way
module OpenGraphPlugin::AttachStories
module ClassMethods
def open_graph_attach_stories options={}
if stories = Array(options[:only])
callbacks = {}
stories.each do |story|
defs = OpenGraphPlugin::Stories::Definitions[story]
Array(defs[:on]).each do |on|
callbacks[on] ||= []
callbacks[on] << story
end
end
else
klass = self.name
callbacks = OpenGraphPlugin::Stories::ModelStories[klass.to_sym]
return if callbacks.blank?
end
callbacks.each do |on, stories|
# subclasses may override this, but the callback is called only once
method = "open_graph_publish_after_#{on}"
self.send "after_#{on}", method
# buggy with rails 3.2
#self.send "after_commit", method, on: on
define_method method do
OpenGraphPlugin::Stories.publish self, stories
end
end
end
end
module InstanceMethods
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment