wlog 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile +1 -0
- data/README.md +72 -3
- data/Rakefile +31 -0
- data/bin/wlog +12 -6
- data/lib/wlog.rb +0 -1
- data/lib/wlog/commands/commandable.rb +9 -0
- data/lib/wlog/commands/concat_description.rb +21 -0
- data/lib/wlog/commands/innit_db.rb +22 -0
- data/lib/wlog/commands/make_csv.rb +24 -0
- data/lib/wlog/commands/new_entry.rb +16 -0
- data/lib/wlog/commands/replace_pattern.rb +21 -0
- data/lib/wlog/db_registry.rb +19 -31
- data/lib/wlog/domain/ansi_colors.rb +15 -0
- data/lib/wlog/domain/attachment.rb +80 -0
- data/lib/wlog/domain/helpers.rb +42 -0
- data/lib/wlog/domain/issue.rb +100 -0
- data/lib/wlog/domain/key_value.rb +55 -0
- data/lib/wlog/domain/log_entry.rb +100 -0
- data/lib/wlog/domain/sql_modules/attachment_sql.rb +21 -0
- data/lib/wlog/domain/sql_modules/issue_sql.rb +28 -0
- data/lib/wlog/domain/sql_modules/key_value_sql.rb +20 -0
- data/lib/wlog/domain/sql_modules/log_entry_sql.rb +35 -0
- data/lib/wlog/domain/sql_modules/polymorphic_attachments_sql.rb +24 -0
- data/lib/wlog/domain/static_configurations.rb +24 -0
- data/lib/wlog/domain/sys_config.rb +23 -0
- data/lib/wlog/sql/mono/1.sql +50 -0
- data/lib/wlog/sql/seq/.gitkeep +0 -0
- data/lib/wlog/ui/cli_interface.rb +152 -0
- data/lib/wlog/ui/commands/attach_to_issue.rb +0 -0
- data/lib/wlog/ui/commands/attach_to_log_entry.rb +11 -0
- data/lib/wlog/ui/commands/create_issue.rb +18 -0
- data/lib/wlog/ui/commands/ui_command.rb +9 -0
- data/lib/wlog/ui/issue_ui.rb +126 -0
- data/lib/wlog/version.rb +1 -1
- data/spec/key_vale_spec.rb +9 -0
- data/wlog.gemspec +6 -2
- metadata +61 -8
- data/lib/wlog/cli_interface.rb +0 -149
- data/lib/wlog/helpers.rb +0 -28
- data/lib/wlog/log_entry.rb +0 -102
- data/lib/wlog/static_configurations.rb +0 -21
data/lib/wlog/cli_interface.rb
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
require 'wlog/log_entry.rb'
|
2
|
-
|
3
|
-
module Wlog
|
4
|
-
# Author :: Simon Symeonidis
|
5
|
-
class CliInterface
|
6
|
-
|
7
|
-
# Run the interface
|
8
|
-
def run
|
9
|
-
cmd = "default"
|
10
|
-
until cmd == "end" do
|
11
|
-
print "[wlog::] "
|
12
|
-
cmd = $stdin.gets
|
13
|
-
cmd ||= "end"
|
14
|
-
cmd.chomp!
|
15
|
-
|
16
|
-
case cmd
|
17
|
-
when "new"
|
18
|
-
puts "Enter work description:"
|
19
|
-
print " "
|
20
|
-
new_entry_command
|
21
|
-
puts "ok"
|
22
|
-
|
23
|
-
when "show"
|
24
|
-
puts "Showing latest log entries"
|
25
|
-
show_entries_command
|
26
|
-
|
27
|
-
when "outcsv"
|
28
|
-
puts "Exporting to CSV."
|
29
|
-
fh = File.open("out.csv", "w")
|
30
|
-
fh.write(make_csv)
|
31
|
-
fh.close
|
32
|
-
|
33
|
-
when "delete"
|
34
|
-
print "Remove task with id: "
|
35
|
-
delete_entry_command
|
36
|
-
|
37
|
-
when "search"
|
38
|
-
search_term
|
39
|
-
|
40
|
-
when "concat"
|
41
|
-
concat_description
|
42
|
-
|
43
|
-
when "replace"
|
44
|
-
replace_pattern
|
45
|
-
|
46
|
-
when "help"
|
47
|
-
print_help
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# TODO the commands should be factored out
|
53
|
-
def self.list_databases_command
|
54
|
-
puts "Available Worklog databases: "
|
55
|
-
Dir["#{StaticConfigurations::DATA_DIRECTORY}*"].each do |n|
|
56
|
-
print "[%8d bytes]" % File.size(n)
|
57
|
-
print " "
|
58
|
-
print n
|
59
|
-
puts
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
|
65
|
-
# Print the help of the cli app
|
66
|
-
def print_help
|
67
|
-
["new", "Create a new log entry",
|
68
|
-
"outcsv", "Export everything to CSV",
|
69
|
-
"help", "print this dialog",
|
70
|
-
"concat", "Add a string at the end of a previous entry",
|
71
|
-
"end", "Exit the progam",
|
72
|
-
"search", "Search for a string in the log description text",
|
73
|
-
"delete", "Remove the task with a given id"].each_with_index do |el,ix|
|
74
|
-
print " " if 1 == ix % 2
|
75
|
-
puts el
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
# new entry command
|
80
|
-
def new_entry_command
|
81
|
-
description = $stdin.gets.chomp!
|
82
|
-
log_entry = LogEntry.new
|
83
|
-
log_entry.description = description
|
84
|
-
log_entry.insert
|
85
|
-
end
|
86
|
-
|
87
|
-
def show_entries_command
|
88
|
-
print_entries(LogEntry.find_all)
|
89
|
-
end
|
90
|
-
|
91
|
-
def print_entries(entries_arr)
|
92
|
-
date_collections = entries_arr.group_by{|le| le.date.strftime("%Y-%m-%d")}
|
93
|
-
date_collections.each_key do |k|
|
94
|
-
print "\x1b[32;1m#{k}\x1b[0m - "
|
95
|
-
print "\x1b[33;1m#{date_collections[k].first.date.strftime("%A")}\x1b[0m "
|
96
|
-
puts "[\x1b[35;1m#{date_collections[k].count}\x1b[0m]"
|
97
|
-
date_collections[k].each do |le|
|
98
|
-
puts " #{le}"
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def search_term
|
104
|
-
print "Term to search: "
|
105
|
-
term = $stdin.gets.chomp!
|
106
|
-
print_entries(LogEntry.search_descriptions(term))
|
107
|
-
end
|
108
|
-
|
109
|
-
def delete_entry_command
|
110
|
-
LogEntry.delete($stdin.gets.to_i)
|
111
|
-
end
|
112
|
-
|
113
|
-
def make_csv
|
114
|
-
str = String.new
|
115
|
-
LogEntry.find_all.group_by{|el| el.date.strftime("%Y-%m-%d")}.each_pair do |key,value|
|
116
|
-
str.concat("#{value.first.date.strftime("%A")} {key}\n")
|
117
|
-
value.each do |entry|
|
118
|
-
str.concat(",\"#{entry.description}\"")
|
119
|
-
end
|
120
|
-
end
|
121
|
-
str
|
122
|
-
end
|
123
|
-
|
124
|
-
# Concatenate an aggregate description to a previous item
|
125
|
-
def concat_description
|
126
|
-
print "ID of task to concatenate to: "
|
127
|
-
id = $stdin.gets.to_i
|
128
|
-
log_entry = LogEntry.find(id)
|
129
|
-
print "Information to concatenate: "
|
130
|
-
str = $stdin.gets.chomp!
|
131
|
-
log_entry.description.concat(str)
|
132
|
-
log_entry.update
|
133
|
-
end
|
134
|
-
|
135
|
-
# Replace a pattern from a description of a log entry
|
136
|
-
def replace_pattern
|
137
|
-
print "ID of task to perform replace: "
|
138
|
-
id = $stdin.gets.to_i
|
139
|
-
print "replace : "
|
140
|
-
pattern1 = $stdin.gets.chomp!
|
141
|
-
print "with : "
|
142
|
-
pattern2 = $stdin.gets.chomp!
|
143
|
-
|
144
|
-
log_entry = LogEntry.find(id)
|
145
|
-
log_entry.description.gsub!(pattern1,pattern2)
|
146
|
-
log_entry.update
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end # module Wlog
|
data/lib/wlog/helpers.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
module Wlog
|
2
|
-
# @author Simon Symeonidis
|
3
|
-
# @date Wed Jul 10 17:37:24 EDT 2013
|
4
|
-
# This contains a few helper methods that may be used by any part in the
|
5
|
-
# application.
|
6
|
-
class Helpers
|
7
|
-
|
8
|
-
# Break the string to a different line
|
9
|
-
# @param string is the string that we want processed.
|
10
|
-
# @param numchars is the amount of characters max per line.
|
11
|
-
def self.break_string(string,numchars)
|
12
|
-
desc = ""
|
13
|
-
cl = 0
|
14
|
-
string.split.each do |word|
|
15
|
-
if cl + word.length + 1 > numchars
|
16
|
-
cl = 0
|
17
|
-
desc.concat($/)
|
18
|
-
end
|
19
|
-
desc.concat(word).concat(" ")
|
20
|
-
cl += word.length + 1
|
21
|
-
end
|
22
|
-
|
23
|
-
desc.chomp!
|
24
|
-
desc
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
end # module Wlog
|
data/lib/wlog/log_entry.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'wlog/db_registry.rb'
|
2
|
-
require 'wlog/helpers.rb'
|
3
|
-
|
4
|
-
module Wlog
|
5
|
-
# Author :: Simon Symeonidis
|
6
|
-
# Active Record Domain object for a log entry
|
7
|
-
class LogEntry
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@date = Time.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.find(id)
|
14
|
-
row = DbRegistry.instance.execute(@@select,id).first
|
15
|
-
le = LogEntry.new
|
16
|
-
le.id = row[0]
|
17
|
-
le.description = row[1]
|
18
|
-
le.date = Time.at(row[2])
|
19
|
-
le
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.find_all
|
23
|
-
all = Array.new
|
24
|
-
DbRegistry.instance.execute(@@select_all).each do |row|
|
25
|
-
le = LogEntry.new
|
26
|
-
le.id = row[0]
|
27
|
-
le.description = row[1]
|
28
|
-
le.date = Time.at(row[2])
|
29
|
-
all.push le
|
30
|
-
end
|
31
|
-
all
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.delete(id)
|
35
|
-
DbRegistry.instance.execute(@@delete_sql,id)
|
36
|
-
end
|
37
|
-
|
38
|
-
# TODO this shouldn't be here
|
39
|
-
def self.create_table
|
40
|
-
DbRegistry.instance.execute(@@create_sql)
|
41
|
-
end
|
42
|
-
|
43
|
-
# update the entry
|
44
|
-
def update
|
45
|
-
DbRegistry.instance.execute(@@update_sql,@description,@id)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Search by string to find a matching description with 'LIKE'.
|
49
|
-
def self.search_descriptions(term)
|
50
|
-
all = Array.new
|
51
|
-
DbRegistry.instance.execute(@@select_description_like,"%#{term}%").each do |row|
|
52
|
-
le = LogEntry.new
|
53
|
-
le.id = row[0]
|
54
|
-
le.description = row[1]
|
55
|
-
le.date = Time.at(row[2])
|
56
|
-
all.push le
|
57
|
-
end
|
58
|
-
all
|
59
|
-
end
|
60
|
-
|
61
|
-
def insert
|
62
|
-
DbRegistry.instance.execute(@@insert_sql,@description,@date.to_i)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Delete the loaded log entry currently in memory, by passing its id
|
66
|
-
def delete
|
67
|
-
self.delete(self.id)
|
68
|
-
end
|
69
|
-
|
70
|
-
# Print things nicely formmated no more than 80 cars (well, unless you stick
|
71
|
-
# the time in the end which is not counted for).
|
72
|
-
def to_s
|
73
|
-
str = "[#{id}] "
|
74
|
-
tmp = @description + " [#{@date.strftime("%H:%M:%S")}]"
|
75
|
-
desc = Wlog::Helpers.break_string(tmp,80)
|
76
|
-
indent = " " * (id.to_s.split('').count + 5)
|
77
|
-
desc.gsub!(/#{$/}/, "#{$/}#{indent}")
|
78
|
-
str.concat(desc)
|
79
|
-
str
|
80
|
-
end
|
81
|
-
|
82
|
-
# The identity field for the log entry DO
|
83
|
-
attr_accessor :id
|
84
|
-
|
85
|
-
# Text description for the log entry
|
86
|
-
attr_accessor :description
|
87
|
-
|
88
|
-
# Date the entry was created
|
89
|
-
attr_accessor :date
|
90
|
-
|
91
|
-
## SQL ##
|
92
|
-
@@table_name = "log_entries"
|
93
|
-
@@insert_sql = "INSERT INTO #{@@table_name} (description,date) values (?,?);"
|
94
|
-
@@delete_sql = "DELETE FROM #{@@table_name} WHERE id = ? ;"
|
95
|
-
@@select_all = "SELECT * FROM #{@@table_name} ORDER BY date ASC;"
|
96
|
-
@@update_sql = "UPDATE #{@@table_name} SET description=? WHERE id=?;"
|
97
|
-
#@@select_all = "SELECT * FROM #{@@table_name} WHERE date >=#{Time.now.to_i - 604800 - 24 * 60 * 60} ORDER BY date ASC"
|
98
|
-
@@select = "SELECT * FROM #{@@table_name} WHERE id = ? ;"
|
99
|
-
@@select_description_like = "SELECT * FROM #{@@table_name} WHERE description LIKE ?;"
|
100
|
-
|
101
|
-
end
|
102
|
-
end # module Wlog
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Wlog
|
2
|
-
# Author :: Simon Symeonidis
|
3
|
-
# Licenses :: GPL v3.0
|
4
|
-
# Static path data.
|
5
|
-
module StaticConfigurations
|
6
|
-
# The application name
|
7
|
-
APPLICATION_NAME = "wlog"
|
8
|
-
|
9
|
-
# Absolute path to the configuration directory
|
10
|
-
CONFIGURATION_DIRECTORY = "#{ENV['HOME']}/.config/"
|
11
|
-
|
12
|
-
# Absolute path to the application directory
|
13
|
-
APPLICATION_DIRECTORY = "#{CONFIGURATION_DIRECTORY}#{APPLICATION_NAME}/"
|
14
|
-
|
15
|
-
# Absolute path to the data directory
|
16
|
-
DATA_DIRECTORY = "#{APPLICATION_DIRECTORY}data/"
|
17
|
-
|
18
|
-
# Default database name (when unspecified)
|
19
|
-
DEFAULT_DATABASE = "default"
|
20
|
-
end
|
21
|
-
end # module Wlog
|