-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GUI based on Glimmer for Windows users
- Loading branch information
Showing
4 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
lib = File.expand_path('lib', __dir__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'buchungsstreber/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'buchungsstreber-gui' | ||
spec.version = Buchungsstreber::VERSION | ||
spec.licenses = ['MIT'] | ||
spec.authors = ['jbuch'] | ||
spec.email = ['[email protected]'] | ||
|
||
spec.summary = %q{Enables timely timekeeping} | ||
spec.description = "Enriches buchungsstreber with GUI." | ||
spec.homepage = 'https://buchungsstreber.synyx.de' | ||
|
||
spec.metadata['allowed_push_host'] = 'https://nexus.synyx.de/content/repositories/gems/' | ||
|
||
spec.metadata['homepage_uri'] = spec.homepage | ||
spec.metadata['source_code_uri'] = 'https://gitlab.synyx.de/synyx/buchungsstreber' | ||
spec.metadata['changelog_uri'] = 'https://gitlab.synyx.de/synyx/buchungsstreber/CHANGELOG.md' | ||
spec.files = [] | ||
|
||
spec.add_dependency 'buchungsstreber', Buchungsstreber::VERSION | ||
spec.add_dependency 'glimmer-dsl-libui', '~> 1.4.0' | ||
spec.add_dependency 'concurrent-ruby', '~> 1.1.9' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
require 'concurrent-ruby' | ||
require 'glimmer-dsl-libui' | ||
|
||
require_relative '../../buchungsstreber/watcher' | ||
|
||
module Buchungsstreber | ||
module GUI | ||
class App | ||
include Glimmer | ||
|
||
def initialize(buchungsstreber, startdate = nil, options = {}) | ||
@buchungsstreber = buchungsstreber | ||
@date = startdate | ||
@options = options | ||
@data = Concurrent::Array.new | ||
@day = "" | ||
end | ||
|
||
def start | ||
refresh_data | ||
|
||
@window = window('Buchungsstreber', 800, 400) { | ||
margined true | ||
vertical_box { | ||
label("Buchungsstreber") { | ||
stretchy false | ||
text @day | ||
} | ||
table { | ||
text_column | ||
text_column | ||
text_column | ||
text_column | ||
text_column | ||
text_column | ||
|
||
cell_rows @data | ||
} | ||
horizontal_box { | ||
stretchy false | ||
button(_('Buchen')) { | ||
stretchy true | ||
on_clicked do | ||
buchen | ||
end | ||
} | ||
button(_('Generate')) { | ||
stretchy true | ||
on_clicked do | ||
generate | ||
refresh_data | ||
end | ||
} | ||
} | ||
} | ||
} | ||
|
||
Thread.start do | ||
Watcher.watch(@buchungsstreber.timesheet_file) do |_| | ||
refresh_data | ||
end | ||
end | ||
|
||
@window.show | ||
rescue Interrupt | ||
exit | ||
end | ||
|
||
private | ||
|
||
def refresh_data | ||
stats = @buchungsstreber.entries(@date) | ||
|
||
hours = stats[:entries].map { |x| x[:time] }.sum | ||
@day.replace "%s %sh / %sh\n" % [@date, hours, stats[:work_hours][@date]] | ||
|
||
entries = Aggregator.aggregate(stats[:entries]) | ||
data = entries.map do |e| | ||
err = e[:errors].map { |x| "<#{x.gsub(/:.*/m, '')}> " }.join('') | ||
[ | ||
'', | ||
e[:date], | ||
e[:time], | ||
e[:redmine], | ||
(err || e[:title])[0..50], | ||
e[:text], | ||
] | ||
end | ||
@data.replace data | ||
end | ||
|
||
def generate | ||
entries = @buchungsstreber.generate(@date) | ||
entries.each do |e| | ||
@buchungsstreber.resolve(e) | ||
e[:redmine] = nil if @buchungsstreber.redmines.default?(e[:redmine]) | ||
end | ||
|
||
parser = @buchungsstreber.timesheet_parser | ||
parser.add(entries) | ||
end | ||
|
||
def buchen(date = nil) | ||
redmines = @buchungsstreber.redmines | ||
entries = @entries[:entries].select { |e| date.nil? || date == e[:date] } | ||
entries = Aggregator.aggregate(entries) | ||
|
||
entries.each_with_index do |entry, i| | ||
redmine = redmines.get(entry[:redmine]) | ||
status = Validator.status!(entry, redmine) | ||
|
||
if status.grep(/(time|activity)_different/).any? | ||
success = false | ||
entry[:errors] << _('-> DIFF') + " #{$1}" | ||
elsif status.include?(:existing) | ||
success = true | ||
else | ||
success = redmine.add_time entry | ||
end | ||
@data[i][0] = success ? _('o') : _('x') | ||
end | ||
end | ||
end | ||
end | ||
end |