Board edit WIP - Can add to a board now
This commit is contained in:
parent
00c80e4b62
commit
e087aa2a4d
@ -61,12 +61,7 @@ class Boards extends BaseController {
|
||||
$board = new Board($this->container);
|
||||
$board->loadFromJson($request->getBody());
|
||||
|
||||
// All admins are members of every added board
|
||||
$admins = R::findAll('user', ' WHERE security_level = 1 ');
|
||||
foreach($admins as $admin) {
|
||||
$user = new User($this->container, $admin->id);
|
||||
$board->users[] = $user;
|
||||
}
|
||||
$this->includeAdmins($board);
|
||||
|
||||
if (!$board->save()) {
|
||||
$this->logger->addError('Add Board: ', [$board]);
|
||||
@ -96,13 +91,22 @@ class Boards extends BaseController {
|
||||
return $this->jsonResponse($response, $status);
|
||||
}
|
||||
|
||||
$data = json_decode($request->getBody());
|
||||
$board = new Board($this->container, (int)$args['id']);
|
||||
|
||||
if (!$this->checkBoardAccess($board->id, $request)) {
|
||||
return $this->jsonResponse($response, 403);
|
||||
}
|
||||
|
||||
$update = new Board($this->container);
|
||||
if (!property_exists($data, 'id')) {
|
||||
$this->logger->addError('Update Board: ', [$board, $data]);
|
||||
$this->apiJson->addAlert('error', 'Error updating board. ' .
|
||||
'Please check your entries and try again.');
|
||||
|
||||
return $this->jsonResponse($response);
|
||||
}
|
||||
|
||||
$update = new Board($this->container, (int)$args['id']);
|
||||
$update->loadFromJson($request->getBody());
|
||||
|
||||
if ($board->id !== $update->id) {
|
||||
@ -113,6 +117,7 @@ class Boards extends BaseController {
|
||||
return $this->jsonResponse($response);
|
||||
}
|
||||
|
||||
$this->includeAdmins($update);
|
||||
$update->save();
|
||||
|
||||
$actor = new User($this->container, Auth::GetUserId($request));
|
||||
@ -124,6 +129,7 @@ class Boards extends BaseController {
|
||||
$this->apiJson->setSuccess();
|
||||
$this->apiJson->addAlert('success',
|
||||
'Board ' . $update->name . ' updated.');
|
||||
$this->apiJson->addData($this->loadAllBoards($request));
|
||||
|
||||
return $this->jsonResponse($response);
|
||||
}
|
||||
@ -157,10 +163,23 @@ class Boards extends BaseController {
|
||||
$this->apiJson->setSuccess();
|
||||
$this->apiJson->addAlert('success',
|
||||
'Board ' . $before->name . ' removed.');
|
||||
$this->apiJson->addData($this->loadAllBoards($request));
|
||||
|
||||
return $this->jsonResponse($response);
|
||||
}
|
||||
|
||||
private function includeAdmins($board) {
|
||||
$admins = R::findAll('user', ' WHERE security_level = 1 ');
|
||||
|
||||
foreach($admins as $admin) {
|
||||
$user = new User($this->container, $admin->id);
|
||||
|
||||
if (!in_array($user, $board->users)) {
|
||||
$board->users[] = $user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function loadAllBoards($request) {
|
||||
$boards = [];
|
||||
$boardBeans = R::findAll('board');
|
||||
|
@ -105,8 +105,12 @@
|
||||
modal-id="{{ MODAL_CONFIRM_ID }}">
|
||||
<div class="center">Removing a board cannot be undone.<br>Continue?</div>
|
||||
<div class="buttons">
|
||||
<button class="flat" (click)="removeBoard()">Yes</button>
|
||||
<button (click)="modal.close(MODAL_CONFIRM_ID)">No</button>
|
||||
<button class="flat"
|
||||
(click)="removeBoard()"
|
||||
[disabled]="saving">Yes</button>
|
||||
<button
|
||||
(click)="modal.close(MODAL_CONFIRM_ID)"
|
||||
[disabled]="saving">No</button>
|
||||
</div>
|
||||
</tb-modal>
|
||||
|
||||
|
@ -102,6 +102,8 @@ export class BoardAdmin {
|
||||
}
|
||||
|
||||
addEditBoard(): void {
|
||||
let isAdd = this.modalProps.title === 'Add';
|
||||
|
||||
this.saving = true;
|
||||
this.setBoardUsers();
|
||||
|
||||
@ -110,16 +112,21 @@ export class BoardAdmin {
|
||||
return;
|
||||
}
|
||||
|
||||
this.boardService.addBoard(this.modalProps)
|
||||
.subscribe((response: ApiResponse) => {
|
||||
response.alerts.forEach(note => this.notes.add(note));
|
||||
if (isAdd) {
|
||||
this.boardService.addBoard(this.modalProps)
|
||||
.subscribe(this.handleResponse);
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.status === 'success') {
|
||||
this.modal.close(this.MODAL_ID);
|
||||
this.settings.updateBoards(response.data[1]);
|
||||
this.saving = false;
|
||||
}
|
||||
});
|
||||
this.boardService.editBoard(this.modalProps)
|
||||
.subscribe(this.handleResponse);
|
||||
}
|
||||
|
||||
removeBoard() {
|
||||
this.saving = true;
|
||||
|
||||
this.boardService.removeBoard(this.boardToRemove.id)
|
||||
.subscribe(this.handleResponse);
|
||||
}
|
||||
|
||||
private validateBoard(): boolean {
|
||||
@ -138,6 +145,18 @@ export class BoardAdmin {
|
||||
return true;
|
||||
}
|
||||
|
||||
private handleResponse = (response: ApiResponse) => {
|
||||
response.alerts.forEach(note => this.notes.add(note));
|
||||
|
||||
if (response.status === 'success') {
|
||||
this.modal.close(this.MODAL_ID);
|
||||
this.modal.close(this.MODAL_CONFIRM_ID);
|
||||
|
||||
this.settings.updateBoards(response.data[1]);
|
||||
this.saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
private setBoardUsers(): void {
|
||||
this.modalProps.users = [];
|
||||
|
||||
@ -175,6 +194,7 @@ export class BoardAdmin {
|
||||
user.selected = false;
|
||||
});
|
||||
} else {
|
||||
this.modalProps.id = board.id;
|
||||
this.modalProps.boardName = board.name;
|
||||
this.modalProps.columns = board.columns;
|
||||
this.modalProps.categories = board.categories;
|
||||
|
@ -6,7 +6,14 @@ import 'rxjs/add/observable/of';
|
||||
import 'rxjs/add/operator/map';
|
||||
import 'rxjs/add/operator/catch';
|
||||
|
||||
import { ApiResponse, Board, User } from '../../shared/index';
|
||||
import {
|
||||
ApiResponse,
|
||||
Board,
|
||||
Column,
|
||||
Category,
|
||||
IssueTracker,
|
||||
User
|
||||
} from '../../shared/index';
|
||||
import { BoardData } from './board-data.model';
|
||||
|
||||
@Injectable()
|
||||
@ -28,21 +35,67 @@ export class BoardAdminService {
|
||||
});
|
||||
}
|
||||
|
||||
editBoard(board: BoardData): Observable<ApiResponse> {
|
||||
let updateBoard = this.convertForApi(board);
|
||||
|
||||
return this.http.post('api/boards/' + updateBoard.id, updateBoard)
|
||||
.map(res => {
|
||||
let response: ApiResponse = res.json();
|
||||
return response;
|
||||
})
|
||||
.catch((res, caught) => {
|
||||
let response: ApiResponse = res.json();
|
||||
return Observable.of(response);
|
||||
});
|
||||
}
|
||||
|
||||
removeBoard(boardId: number): Observable<ApiResponse> {
|
||||
return this.http.delete('api/boards/' + boardId)
|
||||
.map(res => {
|
||||
let response: ApiResponse = res.json();
|
||||
return response;
|
||||
})
|
||||
.catch((res, caught) => {
|
||||
let response: ApiResponse = res.json();
|
||||
return Observable.of(response);
|
||||
});
|
||||
}
|
||||
|
||||
private convertForApi(board: BoardData): Board {
|
||||
let newBoard = new Board();
|
||||
|
||||
newBoard.id = board.id;
|
||||
newBoard.name = board.boardName;
|
||||
|
||||
board.columns.forEach(column => {
|
||||
newBoard.addColumn(column.name);
|
||||
board.columns.forEach((column, index) => {
|
||||
if (column.id) {
|
||||
let existing = new Column(column.id, column.name, index,
|
||||
board.id, column.tasks);
|
||||
newBoard.columns.push(existing);
|
||||
} else {
|
||||
newBoard.addColumn(column.name);
|
||||
}
|
||||
});
|
||||
|
||||
board.categories.forEach(category => {
|
||||
newBoard.addCategory(category.name, category.defaultColor);
|
||||
if (category.id) {
|
||||
let existing = new Category(category.id, category.name,
|
||||
category.default_task_color,
|
||||
board.id);
|
||||
newBoard.categories.push(existing);
|
||||
} else {
|
||||
newBoard.addCategory(category.name, category.defaultColor);
|
||||
}
|
||||
});
|
||||
|
||||
board.issueTrackers.forEach(tracker => {
|
||||
newBoard.addIssueTracker(tracker.url, tracker.regex);
|
||||
if (tracker.id) {
|
||||
let existing = new IssueTracker(tracker.id, tracker.url,
|
||||
tracker.regex);
|
||||
newBoard.issue_trackers.push(existing);
|
||||
} else {
|
||||
newBoard.addIssueTracker(tracker.url, tracker.regex);
|
||||
}
|
||||
});
|
||||
|
||||
board.users.forEach(user => {
|
||||
|
@ -1,5 +1,6 @@
|
||||
export class BoardData {
|
||||
constructor(public title = '',
|
||||
public id = 0,
|
||||
public boardName = '',
|
||||
public columns = [],
|
||||
public categories = [],
|
||||
@ -16,7 +17,7 @@ export class BoardData {
|
||||
return;
|
||||
}
|
||||
|
||||
this.columns.push({ name: this.newColumnName });
|
||||
this.columns.push({ name: this.newColumnName, tasks: [] });
|
||||
this.newColumnName = '';
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
export * from './top-nav/top-nav.component';
|
||||
export * from './inline-edit/inline-edit.component';
|
||||
export * from './auth/index';
|
||||
export * from './constants';
|
||||
export * from './inline-edit/inline-edit.component';
|
||||
export * from './modal/index';
|
||||
export * from './models/index';
|
||||
export * from './notifications/index';
|
||||
export * from './constants';
|
||||
export * from './modal/index'
|
||||
export * from './top-nav/top-nav.component';
|
||||
|
||||
|
@ -6,23 +6,20 @@ export class Board {
|
||||
constructor(public id: number = 0,
|
||||
public name: string = '',
|
||||
public is_active: boolean = true,
|
||||
public columns = [],
|
||||
public categories = [],
|
||||
public auto_actions = [],
|
||||
public issue_trackers = [],
|
||||
public columns: Array<Column> = [],
|
||||
public categories: Array<Category> = [],
|
||||
public auto_actions = [], // TODO: Add typing
|
||||
public issue_trackers: Array<IssueTracker> = [],
|
||||
public users = []) {
|
||||
}
|
||||
|
||||
addColumn(name: string): void {
|
||||
let column = new Column();
|
||||
column.name = name;
|
||||
column.position = this.columns.length;
|
||||
|
||||
let column = new Column(0, name, this.columns.length);
|
||||
this.columns.push(column);
|
||||
}
|
||||
|
||||
addCategory(name: string, color: string): void {
|
||||
this.categories.push(new Category(0, name, color, 0));
|
||||
this.categories.push(new Category(0, name, color));
|
||||
}
|
||||
|
||||
addIssueTracker(url: string, regex: string): void {
|
||||
|
@ -1,8 +1,9 @@
|
||||
export * from './user.model';
|
||||
export * from './api-response.model';
|
||||
export * from './board.model';
|
||||
export * from './category.model';
|
||||
export * from './column.model';
|
||||
export * from './issue-tracker.model';
|
||||
export * from './api-response.model';
|
||||
export * from './notification.model';
|
||||
export * from './user-options.model';
|
||||
export * from './user.model';
|
||||
|
||||
|
@ -4,3 +4,4 @@ export class IssueTracker {
|
||||
public regex: string = '') {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,12 +171,24 @@ class BoardsTest extends PHPUnit_Framework_TestCase {
|
||||
$this->assertEquals('failure', $response->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group single
|
||||
*/
|
||||
public function testUpdateBoard() {
|
||||
$this->createBoard();
|
||||
|
||||
$board = DataMock::getBoard();
|
||||
$board->is_active = false;
|
||||
|
||||
$column = new stdClass();
|
||||
$column->id = 0;
|
||||
$column->name = 'col2';
|
||||
$column->position = 1;
|
||||
$column->board_id = 0;
|
||||
$column->tasks = [];
|
||||
|
||||
$board->columns[] = $column;
|
||||
|
||||
$args = [];
|
||||
$args['id'] = $board->id;
|
||||
|
||||
@ -189,6 +201,10 @@ class BoardsTest extends PHPUnit_Framework_TestCase {
|
||||
new ResponseMock(), $args);
|
||||
$this->assertEquals('success', $response->status);
|
||||
|
||||
$board = $response->data[1][0];
|
||||
var_dump($board);
|
||||
$this->assertEquals(2, count($board->columns));
|
||||
|
||||
$this->boards = new Boards(new ContainerMock());
|
||||
$request->payload = new stdClass();
|
||||
$request->header = [DataMock::getJwt()];
|
||||
@ -197,6 +213,15 @@ class BoardsTest extends PHPUnit_Framework_TestCase {
|
||||
new ResponseMock(), $args);
|
||||
$this->assertEquals('error', $response->alerts[0]['type']);
|
||||
|
||||
$this->boards = new Boards(new ContainerMock());
|
||||
$board->id = 3;
|
||||
$request->payload = $board;
|
||||
$request->header = [DataMock::getJwt()];
|
||||
|
||||
$response = $this->boards->updateBoard($request,
|
||||
new ResponseMock(), $args);
|
||||
$this->assertEquals('error', $response->alerts[0]['type']);
|
||||
|
||||
$this->boards = new Boards(new ContainerMock());
|
||||
$request->header = null;
|
||||
|
||||
|
@ -229,8 +229,8 @@ class UsersTest extends PHPUnit_Framework_TestCase {
|
||||
|
||||
$user = DataMock::getUser();
|
||||
$user->username = 'newname';
|
||||
$user->default_board_id = 0;
|
||||
$user->boardAccess = [1];
|
||||
$user->default_board_id = 1;
|
||||
$user->boardAccess = [2];
|
||||
|
||||
$args = [];
|
||||
$args['id'] = $user->id;
|
||||
@ -295,6 +295,7 @@ class UsersTest extends PHPUnit_Framework_TestCase {
|
||||
$this->users = new Users(new ContainerMock());
|
||||
|
||||
$user->default_board_id = 1;
|
||||
$user->boardAccess = [0];
|
||||
$request->payload = $user;
|
||||
$request->header = [DataMock::getJwt(2)];
|
||||
|
||||
|
Reference in New Issue
Block a user