Skip to content
This repository has been archived by the owner on Feb 13, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:toggl/toggldesktop
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrekV committed Mar 20, 2018
2 parents 85ff9d3 + 1c0d4fa commit 542590a
Show file tree
Hide file tree
Showing 26 changed files with 1,588 additions and 249 deletions.
66 changes: 46 additions & 20 deletions src/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ error Context::save(const bool push_changes) {

UIElements UIElements::Reset() {
UIElements render;
render.first_load = true;
render.display_time_entries = true;
render.display_time_entry_autocomplete = true;
render.display_mini_timer_autocomplete = true;
Expand Down Expand Up @@ -494,10 +495,6 @@ void Context::updateUI(const UIElements &what) {

view::TimeEntry editor_time_entry_view;

std::vector<view::Autocomplete> time_entry_autocompletes;
std::vector<view::Autocomplete> minitimer_autocompletes;
std::vector<view::Autocomplete> project_autocompletes;

bool use_proxy(false);
bool record_timeline(false);
Poco::Int64 unsynced_item_count(0);
Expand All @@ -518,10 +515,6 @@ void Context::updateUI(const UIElements &what) {
{
Poco::Mutex::ScopedLock lock(user_m_);

if (what.display_project_autocomplete && user_) {
user_->related.ProjectAutocompleteItems(&project_autocompletes);
}

if (what.display_time_entry_editor && user_) {
TimeEntry *editor_time_entry =
user_->related.TimeEntryByGUID(what.time_entry_editor_guid);
Expand Down Expand Up @@ -585,15 +578,6 @@ void Context::updateUI(const UIElements &what) {
}
}

if (what.display_time_entry_autocomplete && user_) {
user_->related.TimeEntryAutocompleteItems(
&time_entry_autocompletes);
}

if (what.display_mini_timer_autocomplete && user_) {
user_->related.MinitimerAutocompleteItems(&minitimer_autocompletes);
}

if (what.display_workspace_select && user_) {
std::vector<Workspace *> workspaces;
user_->related.WorkspaceList(&workspaces);
Expand Down Expand Up @@ -872,11 +856,27 @@ void Context::updateUI(const UIElements &what) {
}

if (what.display_time_entry_autocomplete) {
UI()->DisplayTimeEntryAutocomplete(&time_entry_autocompletes);
if (what.first_load) {
std::vector<view::Autocomplete> time_entry_autocompletes;
user_->related.TimeEntryAutocompleteItems(&time_entry_autocompletes);
UI()->DisplayTimeEntryAutocomplete(&time_entry_autocompletes);
} else {
Poco::Util::TimerTask::Ptr teTask =
new Poco::Util::TimerTaskAdapter<Context>(*this, &Context::onTimeEntryAutocompletes);
timer_.schedule(teTask, Poco::Timestamp());
}
}

if (what.display_mini_timer_autocomplete) {
UI()->DisplayMinitimerAutocomplete(&minitimer_autocompletes);
if (what.first_load) {
std::vector<view::Autocomplete> minitimer_autocompletes;
user_->related.MinitimerAutocompleteItems(&minitimer_autocompletes);
UI()->DisplayMinitimerAutocomplete(&minitimer_autocompletes);
} else {
Poco::Util::TimerTask::Ptr mtTask =
new Poco::Util::TimerTaskAdapter<Context>(*this, &Context::onMiniTimerAutocompletes);
timer_.schedule(mtTask, Poco::Timestamp());
}
}

if (what.display_workspace_select) {
Expand Down Expand Up @@ -922,7 +922,15 @@ void Context::updateUI(const UIElements &what) {
// Apply autocomplete as last element,
// as its depending on selects on Windows
if (what.display_project_autocomplete) {
UI()->DisplayProjectAutocomplete(&project_autocompletes);
if (what.first_load) {
std::vector<view::Autocomplete> project_autocompletes;
user_->related.ProjectAutocompleteItems(&project_autocompletes);
UI()->DisplayProjectAutocomplete(&project_autocompletes);
} else {
Poco::Util::TimerTask::Ptr prTask =
new Poco::Util::TimerTaskAdapter<Context>(*this, &Context::onProjectAutocompletes);
timer_.schedule(prTask, Poco::Timestamp());
}
}

if (what.display_unsynced_items) {
Expand Down Expand Up @@ -1079,6 +1087,24 @@ void Context::onSync(Poco::Util::TimerTask& task) { // NOLINT
displayError(save(false));
}

void Context::onTimeEntryAutocompletes(Poco::Util::TimerTask& task) { // NOLINT
std::vector<view::Autocomplete> time_entry_autocompletes;
user_->related.TimeEntryAutocompleteItems(&time_entry_autocompletes);
UI()->DisplayTimeEntryAutocomplete(&time_entry_autocompletes);
}

void Context::onMiniTimerAutocompletes(Poco::Util::TimerTask& task) { // NOLINT
std::vector<view::Autocomplete> minitimer_autocompletes;
user_->related.MinitimerAutocompleteItems(&minitimer_autocompletes);
UI()->DisplayMinitimerAutocomplete(&minitimer_autocompletes);
}

void Context::onProjectAutocompletes(Poco::Util::TimerTask& task) { // NOLINT
std::vector<view::Autocomplete> project_autocompletes;
user_->related.ProjectAutocompleteItems(&project_autocompletes);
UI()->DisplayProjectAutocomplete(&project_autocompletes);
}

void Context::setOnline(const std::string reason) {
std::stringstream ss;
ss << "setOnline, reason:" << reason;
Expand Down
8 changes: 7 additions & 1 deletion src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class WindowChangeRecorder;
class UIElements {
public:
UIElements()
: display_time_entries(false)
: first_load(false)
, display_time_entries(false)
, display_time_entry_autocomplete(false)
, display_mini_timer_autocomplete(false)
, display_project_autocomplete(false)
Expand All @@ -61,6 +62,7 @@ class UIElements {
const std::string editor_guid,
const std::vector<ModelChange> &changes);

bool first_load;
bool display_time_entries;
bool display_time_entry_autocomplete;
bool display_mini_timer_autocomplete;
Expand Down Expand Up @@ -472,6 +474,10 @@ class Context : public TimelineDatasource {
void onWake(Poco::Util::TimerTask& task); // NOLINT
void onLoadMore(Poco::Util::TimerTask& task); // NOLINT

void onTimeEntryAutocompletes(Poco::Util::TimerTask& task); // NOLINT
void onMiniTimerAutocompletes(Poco::Util::TimerTask& task); // NOLINT
void onProjectAutocompletes(Poco::Util::TimerTask& task); // NOLINT

void startPeriodicUpdateCheck();
void executeUpdateCheck();

Expand Down
16 changes: 4 additions & 12 deletions src/related_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ void RelatedData::taskAutocompleteItems(
it != Tasks.end(); it++) {
Task *t = *it;

if (t == NULL) {
continue;
}

if (t->IsMarkedAsDeletedOnServer()) {
continue;
}
Expand Down Expand Up @@ -406,8 +410,6 @@ void RelatedData::MinitimerAutocompleteItems(
timeEntryAutocompleteItems(&unique_names, result);
taskAutocompleteItems(&unique_names, nullptr, result);
projectAutocompleteItems(&unique_names, nullptr, result);

std::sort(result->begin(), result->end(), CompareAutocompleteItems);
}

void RelatedData::ProjectAutocompleteItems(
Expand All @@ -418,9 +420,6 @@ void RelatedData::ProjectAutocompleteItems(
workspaceAutocompleteItems(&unique_names, &ws_names, result);
projectAutocompleteItems(&unique_names, &ws_names, result);
taskAutocompleteItems(&unique_names, &ws_names, result);

std::sort(result->begin(), result->end(),
CompareStructuredAutocompleteItems);
}

void RelatedData::workspaceAutocompleteItems(
Expand Down Expand Up @@ -451,13 +450,6 @@ void RelatedData::workspaceAutocompleteItems(

std::string ws_name = Poco::UTF8::toUpper(ws->Name());
(*ws_names)[ws->ID()] = ws_name;

view::Autocomplete autocomplete_item;
autocomplete_item.Text = ws_name;
autocomplete_item.WorkspaceName = ws_name;
autocomplete_item.WorkspaceID = ws->ID();
autocomplete_item.Type = kAutocompleteItemWorkspace;
list->push_back(autocomplete_item);
}
}

Expand Down
13 changes: 10 additions & 3 deletions src/time_entry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,23 @@ bool TimeEntry::billableIsAPremiumFeature(const error err) const {
}

void TimeEntry::DiscardAt(const Poco::UInt64 at) {
if (!IsTracking()) {
logger().error("Cannot discard time entry that is not tracking");
return;
}

if (!at) {
logger().error("Cannot discard time entry without a timestamp");
return;
}

Poco::Int64 duration = at + DurationInSeconds();
if (duration < 0) {
duration = -1 * duration;
if (at < Start()) {
logger().error("Cannot discard time entry with start time bigger than current moment");
return;
}

Poco::Int64 duration = at - Start();

if (duration < 0) {
logger().error("Discarding with this time entry would result in negative duration"); // NOLINT
return;
Expand Down
20 changes: 20 additions & 0 deletions src/ui/osx/TogglDesktop/AutoComplete/AutoCompleteInput.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// AutoCompleteInput.m
// TogglDesktop
//
// Created by Indrek Vändrik on 19/02/2018.
// Copyright © 2018 Alari. All rights reserved.
//

#import "AutoCompleteInput.h"

@implementation AutoCompleteInput

- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];

// Drawing code here.
}

@end
20 changes: 20 additions & 0 deletions src/ui/osx/TogglDesktop/AutoComplete/AutoCompleteTableCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// AutoCompleteTableCell.m
// TogglDesktop
//
// Created by Indrek Vändrik on 19/02/2018.
// Copyright © 2018 Alari. All rights reserved.
//

#import "AutoCompleteTableCell.h"

@implementation AutoCompleteTableCell

- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];

// Drawing code here.
}

@end
15 changes: 10 additions & 5 deletions src/ui/osx/TogglDesktop/TimeEntryEditViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
#import "NSTextFieldClickable.h"
#import "NSResize.h"
#import "MkColorWellCustom.h"
#import "AutoCompleteInput.h"
#import "AutoCompleteItem.h"

@interface TimeEntryEditViewController : NSViewController <NSComboBoxDataSource> {
@interface TimeEntryEditViewController : NSViewController <NSComboBoxDataSource, NSTextFieldDelegate, NSTableViewDelegate> {
}
@property (strong) IBOutlet MKColorWellCustom *colorPicker;
@property IBOutlet NSCustomComboBox *descriptionCombobox;
@property IBOutlet NSCustomComboBox *projectSelect;
@property IBOutlet NSTextField *durationTextField;
@property IBOutlet NSTextField *startTime;
@property IBOutlet NSTextField *endTime;
Expand Down Expand Up @@ -49,9 +49,11 @@
@property (strong) IBOutlet NSButton *addClientButton;
@property (strong) IBOutlet NSTextField *clientNameTextField;
@property (strong) IBOutlet NSButton *saveNewClientButton;
- (IBAction)descriptionComboboxChanged:(id)sender;
@property (strong) IBOutlet AutoCompleteInput *descriptionAutoCompleteInput;
- (IBAction)descriptionAutoCompleteChanged:(id)sender;
@property (strong) IBOutlet AutoCompleteInput *projectAutoCompleteInput;
- (IBAction)projectAutoCompleteChanged:(id)sender;
- (IBAction)durationTextFieldChanged:(id)sender;
- (IBAction)projectSelectChanged:(id)sender;
- (IBAction)startTimeChanged:(id)sender;
- (IBAction)endTimeChanged:(id)sender;
- (IBAction)dateChanged:(id)sender;
Expand All @@ -67,4 +69,7 @@
- (void)setDragHandle:(BOOL)onLeft;
- (void)setInsertionPointColor;
- (void)closeEdit;
- (BOOL)autcompleteFocused;
- (void)updateWithSelectedDescription:(AutocompleteItem *)autocomplete withKey:(NSString *)key;
- (void)updateWithSelectedProject:(AutocompleteItem *)autocomplete withKey:(NSString *)key;
@end
Loading

0 comments on commit 542590a

Please sign in to comment.