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

Commit

Permalink
Fixed adding new project to the end of the list (lib), closes #2492
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrekV committed Jun 14, 2018
1 parent 541b091 commit 1141b6e
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/user.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Project *User::CreateProject(
const std::string project_color,
const bool billable) {

bool projectAdded = false;
Project *p = new Project();
p->SetWID(workspace_id);
p->SetName(project_name);
Expand All @@ -62,12 +63,6 @@ Project *User::CreateProject(
p->SetColorCode(project_color);
}

// if no projects present just add
if (related.Projects.size() == 0) {
related.Projects.push_back(p);
return p;
}

// We should push the project to correct alphabetical position
// (since we try to avoid sorting the large list)
for (std::vector<Project *>::iterator it =
Expand All @@ -76,26 +71,28 @@ Project *User::CreateProject(
Project *pr = *it;
if (Poco::UTF8::icompare(p->Name(), pr->Name()) < 0) {
related.Projects.insert(it,p);
projectAdded = true;
break;
}
}

// if projects vector is empty or project should be added to the end
if (!projectAdded) {
related.Projects.push_back(p);
}

return p;
}

Client *User::CreateClient(
const Poco::UInt64 workspace_id,
const std::string client_name) {
bool clientAdded = false;
Client *c = new Client();
c->SetWID(workspace_id);
c->SetName(client_name);
c->SetUID(ID());

// if no clients present just add
if (related.Clients.size() == 0) {
related.Clients.push_back(c);
return c;
}

// We should push the project to correct alphabetical position
// (since we try to avoid sorting the large list)
for (std::vector<Client *>::iterator it =
Expand All @@ -104,9 +101,16 @@ Client *User::CreateClient(
Client *cl = *it;
if (Poco::UTF8::icompare(c->Name(), cl->Name()) < 0) {
related.Clients.insert(it,c);
clientAdded = true;
break;
}
}

// if clients vector is empty or client should be added to the end
if (!clientAdded) {
related.Clients.push_back(c);
}

return c;
}

Expand Down

0 comments on commit 1141b6e

Please sign in to comment.