diff options
Diffstat (limited to 'lib/stif')
| -rw-r--r-- | lib/stif/dashboard.rb | 4 | ||||
| -rw-r--r-- | lib/stif/netex_file.rb | 28 | ||||
| -rw-r--r-- | lib/stif/permission_translator.rb | 1 | ||||
| -rw-r--r-- | lib/stif/reflex_synchronization.rb | 21 |
4 files changed, 32 insertions, 22 deletions
diff --git a/lib/stif/dashboard.rb b/lib/stif/dashboard.rb index 46c635091..f558b79fb 100644 --- a/lib/stif/dashboard.rb +++ b/lib/stif/dashboard.rb @@ -1,7 +1,7 @@ module Stif class Dashboard < ::Dashboard def workbench - @workbench ||= current_organisation.workbenches.find_by(name: "Gestion de l'offre") + @workbench ||= current_organisation.workbenches.default end def workgroup @@ -13,7 +13,7 @@ module Stif end def calendars - @calendars ||= Calendar.where('(organisation_id = ? OR shared = ?) AND workgroup_id = ?', current_organisation.id, true, workgroup.id) + workbench.calendars end end end diff --git a/lib/stif/netex_file.rb b/lib/stif/netex_file.rb index db0801bbe..1e78ca04a 100644 --- a/lib/stif/netex_file.rb +++ b/lib/stif/netex_file.rb @@ -47,6 +47,23 @@ module STIF base_name = File.basename(file_name) STIF::NetexFile::LINE_FILE_FORMAT.match(base_name).try(:[], 'line_object_id') end + + def parse_calendars calendars + # <netex:ValidBetween> + # <netex:FromDate>2017-03-01</netex:FromDate> + # <netex:ToDate>2017-03-31</netex:ToDate> + # </netex:ValidBetween> + xml = Nokogiri::XML(calendars) + from_date = nil + to_date = nil + xml.xpath("//netex:ValidBetween", "netex" => NetexFile::XML_NAME_SPACE).each do |valid_between| + from_date = valid_between.xpath("netex:FromDate").try :text + to_date = valid_between.xpath("netex:ToDate").try :text + end + from_date = from_date && Date.parse(from_date) + to_date = to_date && Date.parse(to_date) + Range.new from_date, to_date + end end attr_accessor :name @@ -56,16 +73,7 @@ module STIF end def parse_calendars(calendars) - # <netex:ValidBetween> - # <netex:FromDate>2017-03-01</netex:FromDate> - # <netex:ToDate>2017-03-31</netex:ToDate> - # </netex:ValidBetween> - xml = Nokogiri::XML(calendars) - xml.xpath("//netex:ValidBetween", "netex" => NetexFile::XML_NAME_SPACE).each do |valid_between| - from_date = valid_between.xpath("netex:FromDate").try :text - to_date = valid_between.xpath("netex:ToDate").try :text - periods << Range.new(Date.parse(from_date), Date.parse(to_date)) - end + periods << self.class.parse_calendars(calendars) end def add_offer_file(line_object_id) diff --git a/lib/stif/permission_translator.rb b/lib/stif/permission_translator.rb index 9e0feb9b8..09a7c610c 100644 --- a/lib/stif/permission_translator.rb +++ b/lib/stif/permission_translator.rb @@ -21,6 +21,7 @@ module Stif calendars footnotes imports + exports merges journey_patterns referentials diff --git a/lib/stif/reflex_synchronization.rb b/lib/stif/reflex_synchronization.rb index 7570e4c49..508d28b40 100644 --- a/lib/stif/reflex_synchronization.rb +++ b/lib/stif/reflex_synchronization.rb @@ -151,24 +151,25 @@ module Stif def create_or_update_stop_area entry stop = Chouette::StopArea.find_or_create_by(objectid: entry['id'], stop_area_referential: self.defaut_referential ) - stop.kind = :commercial - stop.deleted_at = nil { - :comment => 'Description', - :name => 'Name', - :area_type => 'TypeOfPlaceRef', - :object_version => 'version', - :zip_code => 'PostalRegion', - :city_name => 'Town', - :stif_type => 'OBJECT_STATUS' + comment: 'Description', + name: 'Name', + area_type: 'TypeOfPlaceRef', + object_version: 'version', + zip_code: 'PostalRegion', + city_name: 'Town', + stif_type: 'OBJECT_STATUS', }.each do |k, v| stop[k] = entry[v] end - # TODO: use stop.update_attributes instead of the above if entry['gml:pos'] stop['longitude'] = entry['gml:pos'][:lng] stop['latitude'] = entry['gml:pos'][:lat] end + stop.kind = :commercial + stop.deleted_at = nil + stop.confirmed_at = Time.now if stop.new_record? + if stop.changed? stop.created_at = entry[:created] stop.import_xml = entry[:xml] |
