openall_time_applet 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/conf/db_schema.rb CHANGED
@@ -7,14 +7,26 @@ Openall_time_applet::DB_SCHEMA = {
7
7
  {"name" => "value", "type" => "text"}
8
8
  ]
9
9
  },
10
+ "Organisation" => {
11
+ "columns" => [
12
+ {"name" => "id", "type" => "int", "autoincr" => true, "primarykey" => true},
13
+ {"name" => "openall_uid", "type" => "int"},
14
+ {"name" => "name", "type" => "varchar"}
15
+ ],
16
+ "indexes" => [
17
+ "openall_uid"
18
+ ]
19
+ },
10
20
  "Task" => {
11
21
  "columns" => [
12
22
  {"name" => "id", "type" => "int", "autoincr" => true, "primarykey" => true},
13
23
  {"name" => "openall_uid", "type" => "int"},
24
+ {"name" => "organisation_id", "type" => "int"},
14
25
  {"name" => "title", "type" => "varchar"}
15
26
  ],
16
27
  "indexes" => [
17
- "openall_uid"
28
+ "openall_uid",
29
+ "organisation_id",
18
30
  ]
19
31
  },
20
32
  "Timelog" => {
@@ -7,6 +7,7 @@
7
7
  <property name="title" translatable="yes">Week status</property>
8
8
  <property name="window_position">center</property>
9
9
  <property name="default_width">440</property>
10
+ <property name="default_height">440</property>
10
11
  <child>
11
12
  <object class="GtkVBox" id="vbox1">
12
13
  <property name="visible">True</property>
@@ -44,7 +45,7 @@
44
45
  </packing>
45
46
  </child>
46
47
  <child>
47
- <object class="GtkLabel" id="label2">
48
+ <object class="GtkLabel" id="labWeek">
48
49
  <property name="visible">True</property>
49
50
  <property name="can_focus">False</property>
50
51
  <property name="label" translatable="yes">Week</property>
@@ -91,11 +92,33 @@
91
92
  </packing>
92
93
  </child>
93
94
  <child>
94
- <object class="GtkHBox" id="boxContent">
95
+ <object class="GtkVBox" id="vbox2">
95
96
  <property name="visible">True</property>
96
97
  <property name="can_focus">False</property>
97
98
  <child>
98
- <placeholder/>
99
+ <object class="GtkHBox" id="boxContent">
100
+ <property name="visible">True</property>
101
+ <property name="can_focus">False</property>
102
+ <child>
103
+ <placeholder/>
104
+ </child>
105
+ </object>
106
+ <packing>
107
+ <property name="expand">False</property>
108
+ <property name="fill">True</property>
109
+ <property name="position">0</property>
110
+ </packing>
111
+ </child>
112
+ <child>
113
+ <object class="GtkLabel" id="label1">
114
+ <property name="visible">True</property>
115
+ <property name="can_focus">False</property>
116
+ </object>
117
+ <packing>
118
+ <property name="expand">True</property>
119
+ <property name="fill">True</property>
120
+ <property name="position">1</property>
121
+ </packing>
99
122
  </child>
100
123
  </object>
101
124
  <packing>
@@ -6,18 +6,24 @@ class Openall_time_applet::Gui::Win_worktime_overview
6
6
  @gui.translate
7
7
  @gui.connect_signals{|h| method(h)}
8
8
 
9
- self.build_week(Knj::Datet.new)
9
+ @date = Knj::Datet.new
10
+ self.build_week
10
11
 
11
12
  @gui["window"].show_all
12
13
  end
13
14
 
14
- def build_week(date)
15
+ def build_week
16
+ date = @date
17
+
15
18
  stats = {
16
19
  :task_total => {},
17
- :days_total => {}
20
+ :days_total => {},
21
+ :week_total => 0
18
22
  }
19
23
 
20
- @args[:oata].ob.list(:Worktime, {"timestamp_month" => date}) do |wt|
24
+ @gui["labWeek"].label = sprintf(_("Week %s"), date.time.strftime("%W"))
25
+
26
+ @args[:oata].ob.list(:Worktime, {"timestamp_week" => date}) do |wt|
21
27
  task = wt.task
22
28
  date = wt.timestamp
23
29
 
@@ -27,13 +33,32 @@ class Openall_time_applet::Gui::Win_worktime_overview
27
33
  stats[:days_total][date.date] = {:secs => 0, :tasks => {}} if !stats[:days_total].key?(date.date)
28
34
  stats[:days_total][date.date][:secs] += wt[:worktime].to_i
29
35
  stats[:days_total][date.date][:tasks][task.id] = task
36
+
37
+ stats[:week_total] += wt[:worktime].to_i
30
38
  end
31
39
 
32
- table = Gtk::Table.new(4, 4)
40
+ table = Gtk::Table.new(5, 5)
41
+ table.row_spacings = 3
42
+ table.column_spacings = 3
33
43
  row = 0
34
44
 
45
+
46
+ #Draw top total-row.
47
+ week_total_title = Gtk::Label.new
48
+ week_total_title.markup = "<b>#{sprintf(_("Week total: %s hours"), Knj::Locales.number_out(stats[:week_total].to_f / 3600.0, 2))}</b>"
49
+ table.attach(week_total_title, 0, 5, row, row + 1)
50
+ row += 1
51
+
52
+
53
+ #Make empty label to make space between total row and days.
54
+ table.attach(Gtk::Label.new(" "), 0, 5, row, row + 1)
55
+ row += 1
56
+
57
+
58
+ #Draw all the days.
35
59
  stats[:days_total].keys.sort.each do |day_no|
36
60
  date = Knj::Datet.in(Time.new(date.year, date.month, day_no))
61
+
37
62
  day_title = Gtk::Label.new
38
63
  day_title.markup = "<b>#{date.out(:time => false)}</b>"
39
64
  day_title.xalign = 0
@@ -43,11 +68,14 @@ class Openall_time_applet::Gui::Win_worktime_overview
43
68
  day_sum.markup = "<b>#{Knj::Locales.number_out(day_sum_float, 2)}</b>"
44
69
  day_sum.xalign = 1
45
70
 
46
- table.attach(day_title, 0, 2, row, row + 1)
47
- table.attach(day_sum, 3, 4, row, row + 1)
71
+ table.attach(day_title, 0, 3, row, row + 1)
72
+ table.attach(day_sum, 4, 5, row, row + 1)
48
73
  row += 1
49
74
 
50
75
  stats[:days_total][day_no][:tasks].each do |task_id, task|
76
+ uid_title = Gtk::Label.new(Knj::Locales.number_out(task[:openall_uid], 0))
77
+ uid_title.xalign = 0
78
+
51
79
  task_title = Gtk::Label.new(task.title)
52
80
  task_title.xalign = 0
53
81
 
@@ -55,22 +83,45 @@ class Openall_time_applet::Gui::Win_worktime_overview
55
83
  task_sum = Gtk::Label.new(Knj::Locales.number_out(task_sum_float, 2))
56
84
  task_sum.xalign = 1
57
85
 
86
+ company_title = Gtk::Label.new(task.organisation_name)
87
+ company_title.xalign = 0
88
+
58
89
  table.attach(Gtk::Label.new(""), 0, 1, row, row + 1)
59
- table.attach(task_title, 1, 2, row, row + 1)
60
- table.attach(Gtk::Label.new("Company"), 2, 3, row, row + 1)
61
- table.attach(task_sum, 3, 4, row, row + 1)
90
+ table.attach(uid_title, 1, 2, row, row + 1)
91
+ table.attach(task_title, 2, 3, row, row + 1)
92
+ table.attach(company_title, 3, 4, row, row + 1)
93
+ table.attach(task_sum, 4, 5, row, row + 1)
62
94
  row += 1
63
95
  end
96
+
97
+ #Make empty label to devide the days with one row.
98
+ table.attach(Gtk::Label.new(" "), 0, 5, row, row + 1)
99
+ row += 1
64
100
  end
65
101
 
102
+ if stats[:days_total].empty?
103
+ table = Gtk::Label.new(_("No worktimes was found that week."))
104
+ end
105
+
106
+ #Remove previous table.
107
+ if @table
108
+ @gui["boxContent"].remove(@table)
109
+ @table.destroy
110
+ end
111
+
112
+ #Attach and set new table.
66
113
  @gui["boxContent"].pack_start(table)
114
+ @gui["window"].show_all
115
+ @table = table
67
116
  end
68
117
 
69
118
  def on_btnNext_clicked
70
- print "Next.\n"
119
+ @date.days + 7
120
+ self.build_week
71
121
  end
72
122
 
73
123
  def on_btnPrevious_clicked
74
- print "Previous.\n"
124
+ @date.days - 7
125
+ self.build_week
75
126
  end
76
127
  end
@@ -1,6 +1,6 @@
1
1
  require "rubygems"
2
2
 
3
- if ENV["HOME"] == "/home/kaspernj"
3
+ if ENV["HOME"] == "/home/kaspernj" and File.exists?("/home/kaspernj/Dev/Ruby/knjrbfw")
4
4
  #For development.
5
5
  require "/home/kaspernj/Dev/Ruby/knjrbfw/lib/knjrbfw"
6
6
  else
@@ -160,6 +160,10 @@ class Openall_time_applet
160
160
  @ob.static(:Worktime, :update_cache, {:oata => self})
161
161
  end
162
162
 
163
+ def update_organisation_cache
164
+ @ob.static(:Organisation, :update_cache, {:oata => self})
165
+ end
166
+
163
167
  #Pushes time-updates to OpenAll.
164
168
  def push_time_updates
165
169
  @ob.static(:Timelog, :push_time_updates, {:oata => self})
@@ -176,16 +180,20 @@ class Openall_time_applet
176
180
 
177
181
  Knj::Thread.new do
178
182
  begin
183
+ sw.label = _("Updating organisation-cache.")
184
+ self.update_organisation_cache
185
+ sw.percent = 0.25
186
+
179
187
  sw.label = _("Updating task-cache.")
180
188
  self.update_task_cache
181
- sw.percent = 0.3
182
-
183
- sw.label = _("Updating worktime-cache.")
184
- self.update_worktime_cache
185
- sw.percent = 0.66
189
+ sw.percent = 0.5
186
190
 
187
191
  sw.label = _("Pushing time-updates.")
188
192
  self.push_time_updates
193
+ sw.percent = 0.75
194
+
195
+ sw.label = _("Updating worktime-cache.")
196
+ self.update_worktime_cache
189
197
  sw.percent = 1
190
198
 
191
199
  sw.label = _("Done")
@@ -0,0 +1,22 @@
1
+ class Openall_time_applet::Models::Organisation < Knj::Datarow
2
+ def self.update_cache(d, args)
3
+ res = nil
4
+ args[:oata].oa_conn do |conn|
5
+ res = conn.request(:getAllOrganisationsForUser)
6
+ end
7
+
8
+ res.each do |org_data|
9
+ org = self.ob.get_by(:Organisation, {"openall_uid" => org_data["uid"]})
10
+ org_data = {
11
+ :openall_uid => org_data["uid"],
12
+ :name => org_data["name"]
13
+ }
14
+
15
+ if org
16
+ org.update(org_data)
17
+ else
18
+ org = self.ob.add(:Organisation, org_data)
19
+ end
20
+ end
21
+ end
22
+ end
data/models/task.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  class Openall_time_applet::Models::Task < Knj::Datarow
2
+ has_one [
3
+ :Organisation
4
+ ]
5
+
2
6
  has_many [
3
7
  [:Timelog, :task_id, :timelogs]
4
8
  ]
@@ -11,15 +15,18 @@ class Openall_time_applet::Models::Task < Knj::Datarow
11
15
 
12
16
  res.each do |task_data|
13
17
  task = self.ob.get_by(:Task, {"openall_uid" => task_data["uid"]})
14
- task_data = {
18
+ data_hash = {
15
19
  :openall_uid => task_data["uid"],
16
20
  :title => task_data["title"]
17
21
  }
18
22
 
23
+ org = self.ob.get_by(:Organisation, {"openall_uid" => task_data["organisation_uid"]})
24
+ data_hash[:organisation_id] = org.id if org
25
+
19
26
  if task
20
- task.update(task_data)
27
+ task.update(data_hash)
21
28
  else
22
- task = self.ob.add(:Task, task_data)
29
+ task = self.ob.add(:Task, data_hash)
23
30
  end
24
31
  end
25
32
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{openall_time_applet}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
@@ -43,6 +43,7 @@ Gem::Specification.new do |s|
43
43
  "lib/openall_time_applet.rb",
44
44
  "locales/da_DK/LC_MESSAGES/default.mo",
45
45
  "locales/da_DK/LC_MESSAGES/default.po",
46
+ "models/organisation.rb",
46
47
  "models/task.rb",
47
48
  "models/timelog.rb",
48
49
  "models/worktime.rb",
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: openall_time_applet
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
@@ -157,6 +157,7 @@ files:
157
157
  - lib/openall_time_applet.rb
158
158
  - locales/da_DK/LC_MESSAGES/default.mo
159
159
  - locales/da_DK/LC_MESSAGES/default.po
160
+ - models/organisation.rb
160
161
  - models/task.rb
161
162
  - models/timelog.rb
162
163
  - models/worktime.rb
@@ -177,7 +178,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
178
  requirements:
178
179
  - - ">="
179
180
  - !ruby/object:Gem::Version
180
- hash: 55925093073077767
181
+ hash: -2304336637192139149
181
182
  segments:
182
183
  - 0
183
184
  version: "0"