wlog 0.0.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/Gemfile +1 -0
  4. data/README.md +72 -3
  5. data/Rakefile +31 -0
  6. data/bin/wlog +12 -6
  7. data/lib/wlog.rb +0 -1
  8. data/lib/wlog/commands/commandable.rb +9 -0
  9. data/lib/wlog/commands/concat_description.rb +21 -0
  10. data/lib/wlog/commands/innit_db.rb +22 -0
  11. data/lib/wlog/commands/make_csv.rb +24 -0
  12. data/lib/wlog/commands/new_entry.rb +16 -0
  13. data/lib/wlog/commands/replace_pattern.rb +21 -0
  14. data/lib/wlog/db_registry.rb +19 -31
  15. data/lib/wlog/domain/ansi_colors.rb +15 -0
  16. data/lib/wlog/domain/attachment.rb +80 -0
  17. data/lib/wlog/domain/helpers.rb +42 -0
  18. data/lib/wlog/domain/issue.rb +100 -0
  19. data/lib/wlog/domain/key_value.rb +55 -0
  20. data/lib/wlog/domain/log_entry.rb +100 -0
  21. data/lib/wlog/domain/sql_modules/attachment_sql.rb +21 -0
  22. data/lib/wlog/domain/sql_modules/issue_sql.rb +28 -0
  23. data/lib/wlog/domain/sql_modules/key_value_sql.rb +20 -0
  24. data/lib/wlog/domain/sql_modules/log_entry_sql.rb +35 -0
  25. data/lib/wlog/domain/sql_modules/polymorphic_attachments_sql.rb +24 -0
  26. data/lib/wlog/domain/static_configurations.rb +24 -0
  27. data/lib/wlog/domain/sys_config.rb +23 -0
  28. data/lib/wlog/sql/mono/1.sql +50 -0
  29. data/lib/wlog/sql/seq/.gitkeep +0 -0
  30. data/lib/wlog/ui/cli_interface.rb +152 -0
  31. data/lib/wlog/ui/commands/attach_to_issue.rb +0 -0
  32. data/lib/wlog/ui/commands/attach_to_log_entry.rb +11 -0
  33. data/lib/wlog/ui/commands/create_issue.rb +18 -0
  34. data/lib/wlog/ui/commands/ui_command.rb +9 -0
  35. data/lib/wlog/ui/issue_ui.rb +126 -0
  36. data/lib/wlog/version.rb +1 -1
  37. data/spec/key_vale_spec.rb +9 -0
  38. data/wlog.gemspec +6 -2
  39. metadata +61 -8
  40. data/lib/wlog/cli_interface.rb +0 -149
  41. data/lib/wlog/helpers.rb +0 -28
  42. data/lib/wlog/log_entry.rb +0 -102
  43. data/lib/wlog/static_configurations.rb +0 -21
@@ -0,0 +1,23 @@
1
+ require 'wlog/domain/key_value'
2
+
3
+ module Wlog
4
+ # System preferences helper, that stores last accessed stuff and other fluff.
5
+ # @author Simon Symeonidis
6
+ class SysConfig
7
+ # load the last focused issue
8
+ def self.last_focus
9
+ KeyValue.get('last_focus')
10
+ end
11
+
12
+ # store the last focused issue
13
+ def self.last_focus=(issue)
14
+ KeyValue.put!('last_focus', "#{issue}")
15
+ end
16
+
17
+ private
18
+ class << self
19
+ private :new, :allocate
20
+ end
21
+ end
22
+ end # module Wlog
23
+
@@ -0,0 +1,50 @@
1
+ --$ Migration to turntables. This is the initial configuration of the database
2
+ --$ for this application.
3
+
4
+ -- author: Simon Symeonidis
5
+ --
6
+ -- Please follow plurals like this:
7
+ -- class Issue -> issues;
8
+ -- class Person -> people;
9
+ --
10
+
11
+ -- An issue has many log entries
12
+ CREATE TABLE issues (
13
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
14
+ description TEXT,
15
+ reported_date INTEGER,
16
+ due_date INTEGER,
17
+ status INTEGER
18
+ );
19
+
20
+ -- Where to store the log entries.
21
+ CREATE TABLE log_entries (
22
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
23
+ description TEXT,
24
+ date DATETIME,
25
+ issue_id INTEGER
26
+ );
27
+
28
+ -- We can add attachments to stuff.
29
+ CREATE TABLE attachments (
30
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
31
+ filename TEXT,
32
+ given_name TEXT,
33
+ data BLOB
34
+ );
35
+
36
+ -- Create the key value table
37
+ CREATE TABLE key_values (
38
+ key TEXT,
39
+ value TEXT
40
+ );
41
+
42
+ -- A polymorphic relationship for attachments. So pretty much anything that
43
+ -- wants to have something attached, uses the discriminator in order to
44
+ -- specify itself, as well as its id.
45
+ CREATE TABLE polymorphic_attachments (
46
+ discriminator TEXT,
47
+ discriminator_id INTEGER,
48
+ attachment_id INTEGER
49
+ );
50
+
File without changes
@@ -0,0 +1,152 @@
1
+ require 'turntables'
2
+ require 'wlog/domain/issue'
3
+ require 'wlog/domain/static_configurations'
4
+ require 'wlog/domain/sys_config'
5
+ require 'wlog/domain/attachment'
6
+ require 'wlog/commands/innit_db'
7
+ require 'wlog/ui/commands/create_issue'
8
+ require 'wlog/ui/issue_ui'
9
+
10
+ module Wlog
11
+ # @author Simon Symeonidis
12
+ # Command line interface to the application. The architectural commands are
13
+ # included here, and should be factored out in the future.
14
+ class CliInterface
15
+ include StaticConfigurations
16
+
17
+ # This is the main entry point of the application. Therefore when we init,
18
+ # we want to trigger the table creation stuff.
19
+ def initialize; InnitDb.new.execute end
20
+
21
+ # Run the interface
22
+ def run
23
+ cmd = "default"
24
+ until cmd == "end" do
25
+ print "[wlog] "
26
+ cmd = $stdin.gets || "end"
27
+ cmd.chomp!
28
+
29
+ case cmd
30
+ when /showattach/ then show_attach
31
+ when /outattach/ then output_attach
32
+ when /attach/ then attach
33
+ when /focus/ then focus
34
+ when /new/ then new_issue
35
+ when /show/ then show_issues
36
+ when /outcsv/ then outcsv
37
+ when /delete/ then delete_entry
38
+ when /help/ then print_help
39
+ end
40
+ end
41
+ end
42
+
43
+ # TODO this might need to be factored out elsewhere
44
+ def self.list_databases
45
+ puts "Available Worklog databases: "
46
+ Dir["#{StaticConfigurations::DataDirectory}*"].each do |db|
47
+ puts "[%8d bytes] %s" % [File.size(db), db]
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ # Create a new issue
54
+ def new_issue; CreateIssue.new.execute end
55
+
56
+ # Wriet out the data contained in the database of the attachment
57
+ def output_attach
58
+ print "Which attachment to output? : "
59
+ att_id = $stdin.gets.to_i
60
+ print "Output where (abs dir) : "
61
+ loc = $stdin.gets
62
+ loc.chomp!
63
+ att = Attachment.find(Issue.name, att_id)
64
+
65
+ fh = File.open("#{loc}/#{att.filename}", 'w')
66
+ fh.write(att.data)
67
+ fh.close
68
+ end
69
+
70
+ def show_attach
71
+ print "Which issue : "
72
+ issue_id = $stdin.gets.to_i
73
+ atts = Attachment.find_all_by_discriminator(Issue.name, issue_id)
74
+ atts.each do |att|
75
+ printf "[%d] - %s (alias: %s)\n", att.id, att.filename, att.given_name
76
+ end
77
+ end
78
+
79
+ def attach
80
+ print "Attach to which issue? : "
81
+ issue_id = $stdin.gets.to_i
82
+ print "Absolute file location : "
83
+ loc = $stdin.gets
84
+ loc.chomp!
85
+ print "Alias name for file (optional) :"
86
+ name_alias = $stdin.gets
87
+ name_alias.chomp!
88
+
89
+ unless loc.nil?
90
+ fh = File.open(loc, "r")
91
+ data = fh.read
92
+ fh.close
93
+
94
+ att = Attachment.new(Issue.name, issue_id)
95
+ att.data = data
96
+ att.filename = loc.split('/').last
97
+ att.given_name = name_alias
98
+ att.insert
99
+ puts "Attached file."
100
+ else
101
+ puts "You need to provide a proper path."
102
+ end
103
+ end
104
+
105
+ def focus
106
+ puts "Focus on issue: "
107
+ issue_id = $stdin.gets.to_i
108
+ issue = Issue.find(issue_id)
109
+ SysConfig.last_focus = issue.id if issue
110
+ IssueUi.new(issue).run
111
+ end
112
+
113
+ def outcsv
114
+ puts "Exporting to CSV."
115
+ fh = File.open("out.csv", "w")
116
+ fh.write(make_csv)
117
+ fh.close
118
+ end
119
+
120
+ # Print the help of the cli app
121
+ def print_help
122
+ ["new", "Create a new log entry",
123
+ "outcsv", "Export everything to CSV",
124
+ "help", "print this dialog",
125
+ "end", "Exit the progam",
126
+ "delete", "Remove the issue with a given id"].each_with_index do |el,ix|
127
+ print " " if 1 == ix % 2
128
+ puts el
129
+ end
130
+ end
131
+
132
+ # TODO might need refactoring
133
+ def show_issues
134
+ entries_arr = Issue.find_all
135
+ issue_collections = entries_arr.reverse.group_by{|iss| iss.status_s}
136
+ issue_collections.each_key do |stat|
137
+ print "\x1b[32;1m#{stat}\x1b[0m"
138
+ puts " [\x1b[35;1m#{issue_collections[stat].count}\x1b[0m]"
139
+ issue_collections[stat].each do |iss|
140
+ puts " [#{iss.id}] #{iss.description}"
141
+ end
142
+ end
143
+ end
144
+
145
+ def make_csv
146
+ cmd = MakeCsv.new
147
+ cmd.execute
148
+ cmd.ret
149
+ end
150
+ end
151
+ end # module Wlog
152
+
File without changes
@@ -0,0 +1,11 @@
1
+ require 'wlog/ui/commands/ui_command'
2
+ require 'wlog/domain/attachment'
3
+ module Wlog
4
+ # Attaching a file to a log entry procedural logic
5
+ # @author Simon Symeonidis
6
+ class AttachToLogEntry < UiCommand
7
+ def execute
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,18 @@
1
+ require 'wlog/ui/commands/ui_command'
2
+ require 'wlog/domain/issue'
3
+
4
+ module Wlog
5
+ # Creational logic for issues
6
+ # @author Simon Symeonidis
7
+ class CreateIssue < UiCommand
8
+ def execute
9
+ @ret = Issue.new
10
+ print "Small issue description :"
11
+ desc = $stdin.gets || "None."
12
+ @ret.description = desc.chomp
13
+ @ret.insert
14
+ end
15
+
16
+ attr_accessor :ret
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module Wlog
2
+ # Interface that CLUIs need to follow (purely command pattern)
3
+ # @author
4
+ class UiCommand
5
+ def execute
6
+ throw NotImplementedException
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,126 @@
1
+ require 'wlog/commands/replace_pattern'
2
+ require 'wlog/commands/new_entry'
3
+ require 'wlog/commands/make_csv'
4
+ require 'wlog/commands/innit_db'
5
+ require 'wlog/commands/concat_description'
6
+
7
+ module Wlog
8
+ # The interface when focusing on an issue
9
+ # @author Simon
10
+ class IssueUi
11
+ def initialize(issue)
12
+ @issue = issue
13
+ end
14
+
15
+ # Start up the interface
16
+ def run
17
+ cmd = "default"
18
+ until cmd == "end" do
19
+ print "[issue ##{@issue.id}] "
20
+ cmd = $stdin.gets || ""
21
+ cmd.chomp!
22
+
23
+ case cmd
24
+ when /attach/ then attach
25
+ when /new/ then new_entry
26
+ when /show/ then show_entries
27
+ when /desc/ then describe_issue
28
+ when /delete/ then delete_entry
29
+ when /search/ then search_term
30
+ when /concat/ then concat_description
31
+ when /replace/ then replace_pattern
32
+ when /search/ then search_term
33
+ when /forget/ then cmd = "end"
34
+ when /finish/ then finish.nil? ? nil : cmd = "end"
35
+ when /help/ then print_help
36
+ else puts "Type 'help' for help"
37
+ end
38
+ end
39
+ end
40
+
41
+ # Focusing on the current issue
42
+ attr_accessor :issue
43
+
44
+ private
45
+
46
+ # Print the description of the issue
47
+ def describe_issue; puts @issue end
48
+
49
+ # This needs updating
50
+ def print_help
51
+ ["new", "Create a new log entry",
52
+ "outcsv", "Export everything to CSV",
53
+ "help", "print this dialog",
54
+ "end", "Exit the progam",
55
+ "search", "Search for a string in the log description text",
56
+ "delete", "Remove the task with a given id"].each_with_index do |el,ix|
57
+ print " " if 1 == ix % 2
58
+ puts el
59
+ end
60
+ end
61
+
62
+ # Exit the issue, mark as finished
63
+ def finish
64
+ print "Are you done with this task? [yes/no] : "
65
+ if ret = !!$stdin.gets.match(/^yes/i)
66
+ @issue.mark_finished!
67
+ @issue.update
68
+ end
69
+ ret end
70
+
71
+ # new entry command
72
+ def new_entry
73
+ print "Enter new issue:#{$/} "
74
+ description = $stdin.gets.chomp!
75
+ @issue.mark_working!
76
+ @issue.update
77
+ NewEntry.new(description, @issue.id).execute
78
+ end
79
+
80
+ def delete_entry
81
+ print "Remove task with id: "
82
+ LogEntry.delete($stdin.gets.to_i)
83
+ end
84
+
85
+ # Concatenate an aggregate description to a previous item
86
+ def concat_description
87
+ print "ID of task to concatenate to: "
88
+ id = $stdin.gets.to_i
89
+ print "Information to concatenate: "
90
+ str = $stdin.gets.chomp!
91
+ ConcatDescription.new(id, str).execute
92
+ end
93
+
94
+ # Replace a pattern from a description of a log entry
95
+ def replace_pattern
96
+ print "ID of task to perform replace: "
97
+ id = $stdin.gets.to_i
98
+ print "replace : "
99
+ old_pattern = $stdin.gets.chomp!
100
+ print "with : "
101
+ new_pattern = $stdin.gets.chomp!
102
+ ReplacePattern.new(id, old_pattern, new_pattern).execute
103
+ end
104
+
105
+ def search_term
106
+ print "Term to search: "
107
+ term = $stdin.gets.chomp!
108
+ print_entries(LogEntry.search_descriptions(term))
109
+ end
110
+
111
+ # TODO might need refactoring
112
+ def show_entries
113
+ entries_arr = LogEntry.find_all_by_issue_id @issue.id
114
+ date_collections = entries_arr.group_by{|le| le.date.strftime("%Y-%m-%d")}
115
+ date_collections.each_key do |date_c|
116
+ print "\x1b[32;1m#{date_c}\x1b[0m - "
117
+ print "\x1b[33;1m%9s\x1b[0m " % [date_collections[date_c].first.date.strftime("%A")]
118
+ puts "[\x1b[35;1m#{date_collections[date_c].count}\x1b[0m]"
119
+ date_collections[date_c].each do |le|
120
+ puts " #{le}"
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end # end module
126
+
data/lib/wlog/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wlog
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,9 @@
1
+ require 'wlog/domain/key_value'
2
+
3
+ include Wlog
4
+
5
+ describe KeyValue do
6
+ it "should slam you in the face" do
7
+ # Pass for now. Slap you later.
8
+ end
9
+ end
data/wlog.gemspec CHANGED
@@ -9,16 +9,20 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["psyomn"]
10
10
  spec.email = ["lethaljellybean@gmail.com"]
11
11
  spec.description = %q{Track tasks and time on the command line.}
12
- spec.summary = %q{A light ruby script to help track tasks and time}
12
+ spec.summary = "A light ruby script to help track tasks and time"\
13
+ "#{$/}#{$/}"\
14
+ "commit: #{`git log -n1 | head -1 | awk '{print $2}'`}"
13
15
  spec.homepage = "http://github.com/psyomn/wlog"
14
16
  spec.license = "GPL v3.0"
15
17
 
16
18
  spec.files = `git ls-files`.split($/)
17
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.test_files = spec.files.grep(%r{^(spec|features)/})
19
21
  spec.require_paths = ["lib"]
20
22
 
21
23
  spec.add_development_dependency "bundler", "~> 1.3"
22
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
23
26
  spec.add_runtime_dependency "sqlite3", ">= 1.3.7"
27
+ spec.add_runtime_dependency "turntables", ">= 1.0.3"
24
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wlog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - psyomn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-13 00:00:00.000000000 Z
11
+ date: 2013-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: sqlite3
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - '>='
53
67
  - !ruby/object:Gem::Version
54
68
  version: 1.3.7
69
+ - !ruby/object:Gem::Dependency
70
+ name: turntables
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.0.3
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.0.3
55
83
  description: Track tasks and time on the command line.
56
84
  email:
57
85
  - lethaljellybean@gmail.com
@@ -66,12 +94,36 @@ files:
66
94
  - Rakefile
67
95
  - bin/wlog
68
96
  - lib/wlog.rb
69
- - lib/wlog/cli_interface.rb
97
+ - lib/wlog/commands/commandable.rb
98
+ - lib/wlog/commands/concat_description.rb
99
+ - lib/wlog/commands/innit_db.rb
100
+ - lib/wlog/commands/make_csv.rb
101
+ - lib/wlog/commands/new_entry.rb
102
+ - lib/wlog/commands/replace_pattern.rb
70
103
  - lib/wlog/db_registry.rb
71
- - lib/wlog/helpers.rb
72
- - lib/wlog/log_entry.rb
73
- - lib/wlog/static_configurations.rb
104
+ - lib/wlog/domain/ansi_colors.rb
105
+ - lib/wlog/domain/attachment.rb
106
+ - lib/wlog/domain/helpers.rb
107
+ - lib/wlog/domain/issue.rb
108
+ - lib/wlog/domain/key_value.rb
109
+ - lib/wlog/domain/log_entry.rb
110
+ - lib/wlog/domain/sql_modules/attachment_sql.rb
111
+ - lib/wlog/domain/sql_modules/issue_sql.rb
112
+ - lib/wlog/domain/sql_modules/key_value_sql.rb
113
+ - lib/wlog/domain/sql_modules/log_entry_sql.rb
114
+ - lib/wlog/domain/sql_modules/polymorphic_attachments_sql.rb
115
+ - lib/wlog/domain/static_configurations.rb
116
+ - lib/wlog/domain/sys_config.rb
117
+ - lib/wlog/sql/mono/1.sql
118
+ - lib/wlog/sql/seq/.gitkeep
119
+ - lib/wlog/ui/cli_interface.rb
120
+ - lib/wlog/ui/commands/attach_to_issue.rb
121
+ - lib/wlog/ui/commands/attach_to_log_entry.rb
122
+ - lib/wlog/ui/commands/create_issue.rb
123
+ - lib/wlog/ui/commands/ui_command.rb
124
+ - lib/wlog/ui/issue_ui.rb
74
125
  - lib/wlog/version.rb
126
+ - spec/key_vale_spec.rb
75
127
  - wlog.gemspec
76
128
  homepage: http://github.com/psyomn/wlog
77
129
  licenses:
@@ -96,6 +148,7 @@ rubyforge_project:
96
148
  rubygems_version: 2.0.3
97
149
  signing_key:
98
150
  specification_version: 4
99
- summary: A light ruby script to help track tasks and time
100
- test_files: []
151
+ summary: 'A light ruby script to help track tasks and time commit: 5fd33ab8e4f380c95af2527b13c274310a76ce4a'
152
+ test_files:
153
+ - spec/key_vale_spec.rb
101
154
  has_rdoc: