Sha256: ee59dd122b66de7f037a544358fe61eeac11243458e2ca00c7994320eaddb15f

Contents?: true

Size: 1.24 KB

Versions: 21

Compression:

Stored size: 1.24 KB

Contents

class Openall_time_applet::Models::Worktime < Knj::Datarow
  has_one [
    :Task
  ]
  
  def self.update_cache(d, args)
    res = nil
    args[:oata].oa_conn do |conn|
      res = conn.request(:getLatestWorktimes)
    end
    
    #Update all worktimes.
    found = []
    res.each do |wt_d|
      found << wt_d["uid"]
      task = self.ob.get_by(:Task, {"openall_uid" => wt_d["task_uid"]})
      
      if !task
        $stderr.puts sprintf(_("Task with UID '%s' was not found."), wt_d["task_uid"]) + " - " + sprintf(_("Skipping worktime with UID %s"), wt_d["uid"])
        next
      end
      
      save_hash = {
        :openall_uid => wt_d["uid"],
        :task_id => task.id,
        :timestamp => Datet.in(wt_d["timestamp"]),
        :worktime => Knj::Strings.human_time_str_to_secs(wt_d["worktime"]),
        :transporttime => Knj::Strings.human_time_str_to_secs(wt_d["transporttime"]),
        :comment => wt_d["comment"]
      }
      
      wt = self.ob.get_by(:Worktime, {"openall_uid" => wt_d["uid"]})
      if wt
        wt.update(save_hash)
      else
        wt = self.ob.add(:Worktime, save_hash)
      end
    end
    
    #Delete the ones not given.
    list = self.ob.list(:Worktime, {"openall_uid_not" => found})
    self.ob.deletes(list)
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
openall_time_applet-0.0.45 models/worktime.rb
openall_time_applet-0.0.44 models/worktime.rb
openall_time_applet-0.0.43 models/worktime.rb
openall_time_applet-0.0.42 models/worktime.rb
openall_time_applet-0.0.41 models/worktime.rb
openall_time_applet-0.0.40 models/worktime.rb
openall_time_applet-0.0.38 models/worktime.rb
openall_time_applet-0.0.37 models/worktime.rb
openall_time_applet-0.0.36 models/worktime.rb
openall_time_applet-0.0.35 models/worktime.rb
openall_time_applet-0.0.34 models/worktime.rb
openall_time_applet-0.0.33 models/worktime.rb
openall_time_applet-0.0.32 models/worktime.rb
openall_time_applet-0.0.31 models/worktime.rb
openall_time_applet-0.0.30 models/worktime.rb
openall_time_applet-0.0.29 models/worktime.rb
openall_time_applet-0.0.28 models/worktime.rb
openall_time_applet-0.0.27 models/worktime.rb
openall_time_applet-0.0.26 models/worktime.rb
openall_time_applet-0.0.25 models/worktime.rb