diff --git a/matsen-tool/src/app/_services/account.service.ts b/matsen-tool/src/app/_services/account.service.ts index 5af2a36..d85ec56 100644 --- a/matsen-tool/src/app/_services/account.service.ts +++ b/matsen-tool/src/app/_services/account.service.ts @@ -41,6 +41,13 @@ export class AccountService { this.router.navigate(['/account/login']); } + isUserAdmin(): boolean { + if (this.userValue && this.userValue?.roles) { + return this.userValue?.roles?.includes('ROLE_ADMIN'); + } + return false; + } + register(user: User) { return this.http.post(`${environment.apiUrl}/users/register`, user); } diff --git a/matsen-tool/src/app/_views/home/home.component.ts b/matsen-tool/src/app/_views/home/home.component.ts index 0873990..e16b3fd 100644 --- a/matsen-tool/src/app/_views/home/home.component.ts +++ b/matsen-tool/src/app/_views/home/home.component.ts @@ -2,22 +2,6 @@ import {User} from '@app/_models'; import {AccountService} from '@app/_services'; -import {Subscription} from "rxjs"; -import { - PostJsonld, - PostService, - TaskJsonld, - TaskNoteJsonld, - TaskService, - UserJsonld, - UserService -} from "@app/core/api/v1"; -import {MatPaginator, MatPaginatorIntl, PageEvent} from "@angular/material/paginator"; -import {NgbModal, NgbModalOptions} from "@ng-bootstrap/ng-bootstrap"; -import {MatTableDataSource} from "@angular/material/table"; -import {NewTaskComponent} from "@app/_views/tasks/new-task/new-task.component"; -import {ModalStatus} from "@app/_helpers/modal.states"; -import {NewTaskNoteComponent} from "@app/_views/tasks/new-task-note/new-task-note.component"; import {AppHelperService} from "@app/_helpers/app-helper.service"; import {ToggleComponent} from "@app/_components/toggle/toggle.component"; import {TaskListComponent} from "@app/_views/tasks/task-list/task-list.component"; @@ -31,162 +15,18 @@ export class HomeComponent implements OnInit, AfterViewInit { @ViewChild("toggleTasks", { static: true }) toggleTasks: ToggleComponent = new ToggleComponent(); @ViewChild("taskListComponent", { static: false }) taskListComponent!: TaskListComponent; - @ViewChild(MatPaginator) tasksPaginator: MatPaginator; - protected user: User | null; - protected postSub: Subscription; - protected posts: Array; - - protected usersSub: Subscription; - protected users: Array; - - protected userIsAdmin: boolean; - - protected tasksSub: Subscription; - protected tasks: Array; - protected tasksDataSource; - protected tasksLength: number; - protected tasksPageEvent: PageEvent; - protected tasksPageSize: number; - protected tasksPageIndex: number; - - protected taskNotesVisibility: Map; - - protected modalOptions: NgbModalOptions = { - centered: true - }; constructor( - private modalService: NgbModal, private accountService: AccountService, - private postService: PostService, - private userService: UserService, - private taskService: TaskService, protected appHelperService: AppHelperService ) { this.user = this.accountService.userValue; - // this.accountService.user.subscribe(x => this.user = x); - this.postSub = new Subscription(); - this.posts = []; - - this.usersSub = new Subscription(); - this.users = []; - - this.userIsAdmin = false; - - this.tasksSub = new Subscription(); - this.tasks = []; - this.tasksPaginator = new MatPaginator(new MatPaginatorIntl(), ChangeDetectorRef.prototype); - this.tasksDataSource = new MatTableDataSource(this.tasks); - this.tasksLength = 0; - this.tasksPageEvent = new PageEvent(); - this.tasksPageSize = 10; - this.tasksPageIndex = 0; - this.taskNotesVisibility = new Map(); } ngOnInit(): void { - if (this.user) { - this.userIsAdmin = this.user.roles ? this.user.roles.includes('ROLE_ADMIN') : false; - } - this.postSub = this.postService.postsGetCollection().subscribe( - data => { - this.posts = data["hydra:member"]; - } - ); - - this.usersSub = this.userService.usersGetCollection().subscribe( - data => { - this.users = data["hydra:member"]; - } - ); - this.getTasksData(); } ngAfterViewInit() { - this.tasksDataSource.paginator = this.tasksPaginator; - } - - getTasksData() { - this.tasksSub = this.taskService.tasksGetCollection( - this.tasksPageIndex + 1, - this.tasksPageSize, - this.user?.id - ).subscribe( - data => { - this.tasks = data["hydra:member"]; - this.tasksLength = Number(data["hydra:totalItems"]); - this.tasks.forEach(task => { - if (task.id) { - this.taskNotesVisibility.set(task.id, false); - } - }); - } - ); - } - - tasksHandlePageEvent(e: PageEvent) { - this.tasksPageEvent = e; - this.tasksLength = e.length; - this.tasksPageIndex = e.pageIndex.valueOf(); - this.tasksPageSize = e.pageSize.valueOf(); - this.getTasksData(); - } - - openModalNewTask() { - const modalRefTask = this.modalService.open(NewTaskComponent, this.appHelperService.getModalOptions()); - let task: TaskJsonld = {} as TaskJsonld; - task.partner = null; - task.completed = false; - modalRefTask.componentInstance.task = task; - modalRefTask.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefTask.dismiss(); - this.getTasksData(); - } - }); - } - - openModalNewTaskNote(task: TaskJsonld) { - const modalRefTaskNote = this.modalService.open(NewTaskNoteComponent, this.appHelperService.getModalOptions()); - let taskNote: TaskNoteJsonld = {} as TaskNoteJsonld; - taskNote.task = task.id ?? null; - modalRefTaskNote.componentInstance.taskNote = taskNote; - modalRefTaskNote.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefTaskNote.dismiss(); - this.getTasksData(); - } - }); - } - - openModalEditTask(task: TaskJsonld) { - const modalRefTaskEdit = this.modalService.open(NewTaskComponent, this.appHelperService.getModalOptions()); - modalRefTaskEdit.componentInstance.task = task; - modalRefTaskEdit.componentInstance.dueAtValue = this.appHelperService.convertDate(task.dueAt); - modalRefTaskEdit.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefTaskEdit.dismiss(); - this.getTasksData(); - } - }); - } - - openModalEditTaskNote(taskNote: TaskNoteJsonld) { - const modalRefTaskNote = this.modalService.open(NewTaskNoteComponent, this.appHelperService.getModalOptions()); - modalRefTaskNote.componentInstance.taskNote = taskNote; - modalRefTaskNote.componentInstance.submit.subscribe((modalStatus: ModalStatus) => { - if (modalStatus === ModalStatus.Submitted) { - modalRefTaskNote.dismiss(); - this.getTasksData(); - } - }); - } - - showTaskNotes(task: TaskJsonld) { - if (task.id) { - const currentVisibility = this.taskNotesVisibility.get(task.id); - this.taskNotesVisibility.set(task.id, !currentVisibility); - } } } diff --git a/matsen-tool/src/app/_views/profile/profile.component.html b/matsen-tool/src/app/_views/profile/profile.component.html index 464c21f..a0b6085 100644 --- a/matsen-tool/src/app/_views/profile/profile.component.html +++ b/matsen-tool/src/app/_views/profile/profile.component.html @@ -1,13 +1,15 @@ -
-
-
-
-

{{ user.firstName }} {{ user.lastName }}

-
-
Email:
-
{{ user.email }}
-
-
-
-
-
\ No newline at end of file + + + + + + + + + + + \ No newline at end of file diff --git a/matsen-tool/src/app/_views/profile/profile.component.ts b/matsen-tool/src/app/_views/profile/profile.component.ts index 1fd2e5e..1a820b7 100644 --- a/matsen-tool/src/app/_views/profile/profile.component.ts +++ b/matsen-tool/src/app/_views/profile/profile.component.ts @@ -1,46 +1,46 @@ -import {AfterViewInit, Component, OnInit} from '@angular/core'; +import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core'; import {User} from "@app/_models"; import {Router} from "@angular/router"; import {AccountService} from "@app/_services"; import {Subscription} from "rxjs"; import {PartnerJsonld, UserJsonld, UserService} from "@app/core/api/v1"; import {AppHelperService} from "@app/_helpers/app-helper.service"; +import {PagingComponent} from "@app/_components/paging/paging.component"; +import {UserComponent} from "@app/_views/user/user/user.component"; +import {ToggleComponent} from "@app/_components/toggle/toggle.component"; +import {TaskListComponent} from "@app/_views/tasks/task-list/task-list.component"; +import {SaleListComponent} from "@app/_views/sales/sale-list/sale-list.component"; @Component({ selector: 'app-profile', templateUrl: './profile.component.html', styleUrl: './profile.component.scss' }) -export class ProfileComponent implements OnInit { +export class ProfileComponent implements OnInit, AfterViewInit { - protected userSub: Subscription; - protected user: UserJsonld; + @ViewChild("userComponent", { static: false }) userComponent!: UserComponent; + @ViewChild("toggleTasks", { static: true }) toggleTasks: ToggleComponent = new ToggleComponent(); + @ViewChild("taskListComponent", { static: false }) taskListComponent!: TaskListComponent; + @ViewChild("toggleSales", { static: true }) toggleSales: ToggleComponent = new ToggleComponent(); + @ViewChild("saleListComponent", { static: false }) saleListComponent!: SaleListComponent; + + protected user!: UserJsonld; constructor( - private router: Router, private accountService: AccountService, - private userService: UserService, - protected appHelperService: AppHelperService ) { - this.userSub = new Subscription(); - this.user = {} as UserJsonld; + if (this.accountService.userValue?.userResource) { + this.user = this.accountService.userValue?.userResource; + } + } ngOnInit() { - this.getUserData(); } - getUserData() { - const user = this.accountService.userValue; - if (user?.id !== null && user?.id !== undefined) { - this.userSub = this.userService.usersIdGet( - this.appHelperService.extractId(user.id) - ).subscribe( - data => { - this.user = data; - } - ); - } + ngAfterViewInit(): void { } + + } diff --git a/matsen-tool/src/app/_views/sales/sale-list/sale-list.component.ts b/matsen-tool/src/app/_views/sales/sale-list/sale-list.component.ts index cd25750..130632e 100644 --- a/matsen-tool/src/app/_views/sales/sale-list/sale-list.component.ts +++ b/matsen-tool/src/app/_views/sales/sale-list/sale-list.component.ts @@ -1,6 +1,6 @@ -import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core'; +import {AfterViewInit, Component, Input, OnInit, ViewChild} from '@angular/core'; import {Subscription} from "rxjs"; -import {SaleJsonld, SaleService, SaleSummaryJsonld} from "@app/core/api/v1"; +import {SaleJsonld, SaleService, SaleSummaryJsonld, UserJsonld} from "@app/core/api/v1"; import {TranslateService} from "@ngx-translate/core"; import {Router} from "@angular/router"; import {AppHelperService} from "@app/_helpers/app-helper.service"; @@ -18,6 +18,7 @@ import {AccountService} from "@app/_services"; }) export class SaleListComponent implements OnInit, AfterViewInit { + @Input() public user!: UserJsonld; @ViewChild(MatSort) sort; @ViewChild("pagingComponent", { static: false }) pagingComponent!: PagingComponent; @@ -56,6 +57,7 @@ export class SaleListComponent implements OnInit, AfterViewInit { this.salesSub = this.saleService.salesGetCollection( this.pagingComponent.getPageIndex(), this.pagingComponent.getPageSize(), + this.user !== undefined ? this.user.id : undefined ).subscribe( data => { this.sales = data["hydra:member"]; diff --git a/matsen-tool/src/app/_views/sales/sale-summary/sale-summary.component.ts b/matsen-tool/src/app/_views/sales/sale-summary/sale-summary.component.ts index 9fd0429..33d8bb0 100644 --- a/matsen-tool/src/app/_views/sales/sale-summary/sale-summary.component.ts +++ b/matsen-tool/src/app/_views/sales/sale-summary/sale-summary.component.ts @@ -1,6 +1,6 @@ -import {AfterViewInit, Component, OnInit} from '@angular/core'; +import {AfterViewInit, Component, Input, OnInit} from '@angular/core'; import {Subscription} from "rxjs"; -import {SaleSummaryJsonld, SaleSummaryService} from "@app/core/api/v1"; +import {SaleSummaryJsonld, SaleSummaryService, UserJsonld} from "@app/core/api/v1"; @Component({ selector: 'app-sale-summary', @@ -9,6 +9,8 @@ import {SaleSummaryJsonld, SaleSummaryService} from "@app/core/api/v1"; }) export class SaleSummaryComponent implements OnInit, AfterViewInit { + @Input() public user!: UserJsonld; + protected readonly Number = Number; protected salesSummarySub: Subscription; protected saleSummaries: Array; diff --git a/matsen-tool/src/app/_views/user/user/user.component.html b/matsen-tool/src/app/_views/user/user/user.component.html new file mode 100644 index 0000000..f9f09c5 --- /dev/null +++ b/matsen-tool/src/app/_views/user/user/user.component.html @@ -0,0 +1,13 @@ +
+
+
+
+

{{ user.firstName }} {{ user.lastName }}

+
+
Email:
+
{{ user.email }}
+
+
+
+
+
diff --git a/matsen-tool/src/app/_views/user/user/user.component.scss b/matsen-tool/src/app/_views/user/user/user.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/matsen-tool/src/app/_views/user/user/user.component.spec.ts b/matsen-tool/src/app/_views/user/user/user.component.spec.ts new file mode 100644 index 0000000..7d16b25 --- /dev/null +++ b/matsen-tool/src/app/_views/user/user/user.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { UserComponent } from './user.component'; + +describe('UserComponent', () => { + let component: UserComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [UserComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(UserComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/matsen-tool/src/app/_views/user/user/user.component.ts b/matsen-tool/src/app/_views/user/user/user.component.ts new file mode 100644 index 0000000..c5b7f66 --- /dev/null +++ b/matsen-tool/src/app/_views/user/user/user.component.ts @@ -0,0 +1,46 @@ +import {AfterViewInit, Component, Input, OnInit} from '@angular/core'; +import {Subscription} from "rxjs"; +import {UserJsonld, UserService} from "@app/core/api/v1"; +import {AccountService} from "@app/_services"; +import {AppHelperService} from "@app/_helpers/app-helper.service"; + +@Component({ + selector: 'app-user', + templateUrl: './user.component.html', + styleUrl: './user.component.scss' +}) +export class UserComponent implements OnInit, AfterViewInit { + + @Input() public user!: UserJsonld; + protected userSub: Subscription; + + constructor( + private accountService: AccountService, + private userService: UserService, + protected appHelperService: AppHelperService + ) { + this.userSub = new Subscription(); + } + + ngOnInit() { + + } + + ngAfterViewInit(): void { + this.getData(); + } + + getData() { + const user = this.accountService.userValue; + if (user?.id !== null && user?.id !== undefined) { + this.userSub = this.userService.usersIdGet( + this.appHelperService.extractId(user.id) + ).subscribe( + data => { + this.user = data; + } + ); + } + } + +} diff --git a/matsen-tool/src/app/app.module.ts b/matsen-tool/src/app/app.module.ts index f413807..cca619f 100644 --- a/matsen-tool/src/app/app.module.ts +++ b/matsen-tool/src/app/app.module.ts @@ -59,6 +59,7 @@ import { ProductListComponent } from './_views/products/product-list/product-lis import { DocumentListComponent } from './_views/documents/document-list/document-list.component'; import { SaleListComponent } from './_views/sales/sale-list/sale-list.component'; import { SaleSummaryComponent } from './_views/sales/sale-summary/sale-summary.component'; +import { UserComponent } from './_views/user/user/user.component'; export function apiConfigFactory(): Configuration { const params: ConfigurationParameters = { @@ -139,6 +140,7 @@ export function HttpLoaderFactory(http: HttpClient) { DocumentListComponent, SaleListComponent, SaleSummaryComponent, + UserComponent, ], providers: [ {provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true},