lib/timeline_source.rb in muruca_widgets-0.2.4 vs lib/timeline_source.rb in muruca_widgets-0.2.6

- old
+ new

@@ -156,34 +156,68 @@ # We may accept an array of possible predicates indicating the dates # we try to find out the one in use in this particular source here start_predicate = date_predicate_from_array(original_start_predicate, src) end_predicate = date_predicate_from_array(original_end_predicate, src) + # we expect to have a TaliaCore::SemanticCollectionWrapper for the dates + # if it's not the case, we create an array with the single value + if src[start_predicate].is_a? TaliaCore::SemanticCollectionWrapper + start_dates = src[start_predicate] + else + start_dates = [src[start_predicate]] + end + + if src[end_predicate].is_a? TaliaCore::SemanticCollectionWrapper + end_dates = src[end_predicate] + else + end_dates = [src[end_predicate]] + end + + # Ignore all sources that do not have a timestamp - next if((stamp = src[start_predicate].first).blank?) + next if((stamp = start_dates.first).blank?) new_event = {} # Fill the start and end date fields dates = process_timestamp(stamp) # Overwrite the second date if we have a predefined "end" field - dates[1] = process_timestamp(src[end_predicate].first).first if(end_predicate) and !src[end_predicate].empty? + dates[1] = process_timestamp(end_dates.first).first unless end_dates.empty? new_event[:start], new_event[:end] = dates.collect { |d| to_iso8601(d) } update_first_last_year(dates) # Fill the title/description fields - new_event[:title] = src[@options[:title_property]].first || src[N::RDFS.label].first || N::URI.new(src.uri).to_name_s - new_event[:description] = src[@options[:description_property]].first || new_event[:title] + + if (titles = src[@options[:title_property]]).is_a? TaliaCore::SemanticCollectionWrapper and !titles.empty? + title = titles.first + else + title = titles unless titles.nil? + title = src[N::RDFS.label].first if title.nil? + title = N::URI.new(src.uri).to_name_s if title.nil? + end + +# src[@options[:title_property]].first || src[N::RDFS.label].first || N::URI.new(src.uri).to_name_s + + if (descriptions = src[@options[:description_property]]).is_a? TaliaCore::SemanticCollectionWrapper and !descriptions.empty? + description = descriptions.first + else + description = descriptions unless descriptions.nil? + description = title if description.nil? + end + + + new_event[:title] = title + new_event[:description] = description # new_event['image'] = '' # The link field may either be filled from a property, or with a link to the element itself (default) new_event[:link] = if(@options[:link_property]) src[@options[:link_property]].first || '' else - if((uri = src.to_uri).local?) - '/' << uri.local_name - else - uri.to_s - end +# if((uri = src.to_uri).local?) +# '/' << uri.local_name +# else + src.to_uri.to_s +# end end # We have a duration event if we have a non-nil end date new_event[:duration_event] = true unless(new_event[:end]) # new_event[:icon] = 'red_circle.png' # Colors as defined in the options \ No newline at end of file