From 98ce544c9e995e77e72bc762bab3cd64b3750254 Mon Sep 17 00:00:00 2001 From: kiswa Date: Thu, 15 Sep 2016 22:08:09 +0000 Subject: [PATCH] Refactor to update boards on user changes --- .../user-admin/user-admin.component.ts | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/app/settings/user-admin/user-admin.component.ts b/src/app/settings/user-admin/user-admin.component.ts index f5ee6f0..fe9ca38 100644 --- a/src/app/settings/user-admin/user-admin.component.ts +++ b/src/app/settings/user-admin/user-admin.component.ts @@ -58,18 +58,7 @@ export class UserAdmin { settings.getUsers() .subscribe((response: ApiResponse) => { this.users = response.data[1]; - - this.settings.getBoards() - .subscribe((response: ApiResponse) => { - let boards = response.data[1]; - if (boards) { - this.boards = boards; - } - - this.settings.updateBoards(this.boards); - this.updateUserList(); - this.loading = false; - }); + this.getBoards(); }); } @@ -88,11 +77,7 @@ export class UserAdmin { response.alerts.forEach(note => this.notes.add(note)); this.replaceUserList(response); - - if (response.status === 'success') { - this.modal.close(this.MODAL_ID); - this.saving = false; - } + this.closeModal(response.status); }); return; @@ -103,11 +88,7 @@ export class UserAdmin { response.alerts.forEach(note => this.notes.add(note)); this.replaceUser(JSON.parse(response.data[1])); - - if (response.status === 'success') { - this.modal.close(this.MODAL_ID); - this.saving = false; - } + this.closeModal(response.status); }); } @@ -119,10 +100,34 @@ export class UserAdmin { if (response.status === 'success') { this.modal.close(this.MODAL_CONFIRM_ID); + this.getBoards(); } }) } + private closeModal(status: string): void { + if (status === 'success') { + this.modal.close(this.MODAL_ID); + this.saving = false; + + this.getBoards(); + } + } + + private getBoards(): void { + this.settings.getBoards() + .subscribe((response: ApiResponse) => { + let boards = response.data[1]; + if (boards) { + this.boards = boards; + } + + this.settings.updateBoards(this.boards); + this.updateUserList(); + this.loading = false; + }); + } + private replaceUser(newUser: User) { this.users.forEach((user, index) => { if (user.id === newUser.id) {