From b5fc471f61c36b97b47ef9204a1ebeda15d6eb1c Mon Sep 17 00:00:00 2001 From: kiswa Date: Sat, 25 Mar 2017 02:03:24 +0000 Subject: [PATCH] Board display work - pull tasks out to own component --- src/api/controllers/Boards.php | 20 ++++++-- src/api/controllers/Tasks.php | 1 + src/api/helpers/BeanLoader.php | 56 ++++++++++++++-------- src/app/app.routes.ts | 4 +- src/app/board/column/column.component.html | 52 ++++---------------- src/app/board/column/column.component.ts | 1 - src/app/board/index.ts | 1 + src/app/board/task/task.component.html | 44 +++++++++++++++++ src/app/board/task/task.component.ts | 34 +++++++++++++ test/api/controllers/BoardsTest.php | 10 ++++ test/api/controllers/TasksTest.php | 8 ++++ 11 files changed, 163 insertions(+), 68 deletions(-) create mode 100644 src/app/board/task/task.component.html create mode 100644 src/app/board/task/task.component.ts diff --git a/src/api/controllers/Boards.php b/src/api/controllers/Boards.php index 93f4663..78c4b42 100644 --- a/src/api/controllers/Boards.php +++ b/src/api/controllers/Boards.php @@ -47,6 +47,7 @@ class Boards extends BaseController { return $this->jsonResponse($response, 403); } + $this->cleanBoard($board); $this->apiJson->setSuccess(); $this->apiJson->addData(R::exportAll($board)); @@ -192,10 +193,7 @@ class Boards extends BaseController { if (count($boardBeans)) { foreach ($boardBeans as $bean) { if (Auth::HasBoardAccess($request, $bean->id)) { - foreach ($bean->sharedUserList as $user) { - $user = $this->cleanUser($user); - } - + $this->cleanBoard($bean); $boards[] = $bean; } } @@ -204,6 +202,20 @@ class Boards extends BaseController { return R::exportAll($boards); } + private function cleanBoard(&$board) { + foreach ($board->sharedUserList as $user) { + $user = $this->cleanUser($user); + } + + foreach ($board->xownColumnList as $column) { + foreach ($column->xownTaskList as $task) { + foreach ($task->sharedUserList as $user) { + $user = $this->cleanUser($user); + } + } + } + } + private function cleanUser($user) { unset($user->password_hash); unset($user->active_token); diff --git a/src/api/controllers/Tasks.php b/src/api/controllers/Tasks.php index 67191fc..b93ddd5 100644 --- a/src/api/controllers/Tasks.php +++ b/src/api/controllers/Tasks.php @@ -66,6 +66,7 @@ class Tasks extends BaseController { $this->apiJson->setSuccess(); $this->apiJson->addAlert('success', 'Task ' . $task->title . ' added.'); + $this->apiJson->addData(R::exportAll($task)); return $this->jsonResponse($response); } diff --git a/src/api/helpers/BeanLoader.php b/src/api/helpers/BeanLoader.php index 466c038..3aedf25 100644 --- a/src/api/helpers/BeanLoader.php +++ b/src/api/helpers/BeanLoader.php @@ -45,20 +45,24 @@ class BeanLoader { $board->name = isset($data->name) ? $data->name : ''; $board->is_active = isset($data->is_active) ? $data->is_active : ''; - if (isset($data->categories)) { - self::updateObjectList('category', 'LoadCategory', - $board->xownCategoryList, $data->categories); - } + try { + if (isset($data->categories)) { + self::updateObjectList('category', 'LoadCategory', + $board->xownCategoryList, $data->categories); + } - if (isset($data->columns)) { - self::updateObjectList('column', 'LoadColumn', - $board->xownColumnList, $data->columns); - } + if (isset($data->issue_trackers)) { + self::updateObjectList('issuetracker', 'LoadIssueTracker', + $board->xownIssueTrackerList, + $data->issue_trackers); + } - if (isset($data->issue_trackers)) { - self::updateObjectList('issuetracker', 'LoadIssueTracker', - $board->xownIssueTrackerList, - $data->issue_trackers); + if (isset($data->columns)) { + self::updateObjectList('column', 'LoadColumn', + $board->xownColumnList, $data->columns); + } + } catch(Exception $ex) { + return false; } // Users do not get deleted when removed from a board @@ -68,7 +72,7 @@ class BeanLoader { foreach ($data->users as $userData) { $user = R::load('user', $userData->id); - if ((int)$user->id > 0) { + if ((int)$user->id) { $board->sharedUserList[] = $user; } } @@ -163,22 +167,36 @@ class BeanLoader { if (isset($data->comments)) { self::updateObjectList('comment', 'LoadComment', - $column->xownCommentList, $data->comments); + $task->xownCommentList, $data->comments); } if (isset($data->attachments)) { self::updateObjectList('attachment', 'LoadAttachment', - $column->xownAttachmentList, $data->attachments); + $task->xownAttachmentList, $data->attachments); } if (isset($data->assignees)) { - self::updateObjectList('user', 'LoadUser', - $column->xownAssigneeList, $data->assignees); + $task->sharedUserList = []; + + foreach ($data->assignees as $assignee) { + $user = R::load('user', $assignee->id); + + if((int) $user->id) { + $task->sharedUserList[] = $user; + } + } } if (isset($data->categories)) { - self::updateObjectList('category', 'LoadCategory', - $column->xownCategoryList, $data->categories); + $task->sharedCategoryList = []; + + foreach ($data->categories as $category) { + $cat = R::load('category', $category->id); + + if ((int)$cat->id) { + $task->sharedCategoryList[] = $cat; + } + } } if (!isset($data->title) || !isset($data->position) || diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index 02a9261..190e42d 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -4,7 +4,8 @@ import { AuthGuard } from './shared/index'; import { Login } from './login/login.component'; import { BoardDisplay, - ColumnDisplay + ColumnDisplay, + TaskDisplay } from './board/index'; import { Settings, @@ -49,6 +50,7 @@ export const ROUTE_COMPONENTS = [ Calendar, Charts, ColumnDisplay, + TaskDisplay, Dashboard, Login, Settings, diff --git a/src/app/board/column/column.component.html b/src/app/board/column/column.component.html index 1e2c503..7964d6c 100644 --- a/src/app/board/column/column.component.html +++ b/src/app/board/column/column.component.html @@ -11,7 +11,7 @@ {{ columnData.name }} - {{ tasks.length }} + {{ columnData.ownTask.length }}
-
-

- - Column Data - 1 -

-
-
{{ columnData | json }}
-
-
- Assigned To: admin - - - - Front End - -
-
-
-

- - Something to Get Done - 3 -

-
-

This is the thing that needs to get done.

-
-
- Assigned To: admin - - - - - -
-
+ + + + + +
diff --git a/src/app/board/column/column.component.ts b/src/app/board/column/column.component.ts index 1d99549..5eae8b0 100644 --- a/src/app/board/column/column.component.ts +++ b/src/app/board/column/column.component.ts @@ -38,7 +38,6 @@ export class ColumnDisplay implements OnInit { private modalProps: Task; @Input('column') columnData: Column; - @Input('show-add-modal') showAddModal: any; constructor(private elRef: ElementRef, private auth: AuthService, diff --git a/src/app/board/index.ts b/src/app/board/index.ts index 325e398..f28152e 100644 --- a/src/app/board/index.ts +++ b/src/app/board/index.ts @@ -1,3 +1,4 @@ export * from './column/column.component'; export * from './board.component'; +export * from './task/task.component'; diff --git a/src/app/board/task/task.component.html b/src/app/board/task/task.component.html new file mode 100644 index 0000000..5e2420e --- /dev/null +++ b/src/app/board/task/task.component.html @@ -0,0 +1,44 @@ +
+

+ + {{ taskData.title }} + + {{ taskData.points }} +

+
+ {{ taskData.description }} +
+ +
+ + Assigned To: + + {{ assignee.username }} + + + Unassigned + + + + + Due: {{ taskData.due_date }} + + + + + {{ category.name }} + + +
+
+ diff --git a/src/app/board/task/task.component.ts b/src/app/board/task/task.component.ts new file mode 100644 index 0000000..7d61e85 --- /dev/null +++ b/src/app/board/task/task.component.ts @@ -0,0 +1,34 @@ +import { Component, Input } from '@angular/core'; + +import { + Task, + UserOptions, + AuthService +} from '../../shared/index'; + +@Component({ + selector: 'tb-task', + templateUrl: 'app/board/task/task.component.html' +}) +export class TaskDisplay { + private userOptions: UserOptions; + + @Input('task') taskData: Task; + + constructor(auth: AuthService) { + auth.userChanged.subscribe(() => { + this.userOptions = auth.userOptions; + }); + } + + // Expects a color in full HEX with leading #, e.g. #ffffe0 + getTextColor(color: string): string { + let r = parseInt(color.substr(1, 2), 16), + g = parseInt(color.substr(3, 2), 16), + b = parseInt(color.substr(5, 2), 16), + yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000; + + return yiq >= 130 ? '#333333' : '#efefef'; + } +} + diff --git a/test/api/controllers/BoardsTest.php b/test/api/controllers/BoardsTest.php index d718126..aa64968 100644 --- a/test/api/controllers/BoardsTest.php +++ b/test/api/controllers/BoardsTest.php @@ -210,6 +210,7 @@ class BoardsTest extends PHPUnit_Framework_TestCase { $board = $this->getBoardData(); $board->id = 3; + unset($board->columns[0]->board_id); unset($board->categories[0]->board_id); unset($board->issue_trackers[0]->board_id); @@ -351,10 +352,19 @@ class BoardsTest extends PHPUnit_Framework_TestCase { private function createBoard() { $board = R::dispense('board'); + $column = R::dispense('column'); + $task = R::dispense('task'); + + $task->sharedUserList[] = R::load('user', 1); + + $column->name = 'test'; + $column->position = 0; + $column->xownTaskList[] = $task; $board->name = 'test'; $board->is_active = true; $board->sharedUserList[] = R::load('user', 1); + $board->xownColumnList[] = $column; R::store($board); } diff --git a/test/api/controllers/TasksTest.php b/test/api/controllers/TasksTest.php index 36d832f..c18f163 100644 --- a/test/api/controllers/TasksTest.php +++ b/test/api/controllers/TasksTest.php @@ -76,6 +76,14 @@ class TasksTest extends PHPUnit_Framework_TestCase { $this->createTask(); $data = $this->getTaskData(); + $assignee = R::load('user', 1); + $data->assignees[] = $assignee; + + $category = R::load('category', 1); + $category->name = 'Front End'; + R::store($category); + $data->categories[] = $category; + $request = new RequestMock(); $request->header = [DataMock::GetJwt()]; $request->payload = $data;