| @@ -41,6 +41,13 @@ export class AccountService { | |||||
| this.router.navigate(['/account/login']); | 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) { | register(user: User) { | ||||
| return this.http.post(`${environment.apiUrl}/users/register`, user); | return this.http.post(`${environment.apiUrl}/users/register`, user); | ||||
| } | } | ||||
| @@ -2,22 +2,6 @@ | |||||
| import {User} from '@app/_models'; | import {User} from '@app/_models'; | ||||
| import {AccountService} from '@app/_services'; | 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 {AppHelperService} from "@app/_helpers/app-helper.service"; | ||||
| import {ToggleComponent} from "@app/_components/toggle/toggle.component"; | import {ToggleComponent} from "@app/_components/toggle/toggle.component"; | ||||
| import {TaskListComponent} from "@app/_views/tasks/task-list/task-list.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("toggleTasks", { static: true }) toggleTasks: ToggleComponent = new ToggleComponent(); | ||||
| @ViewChild("taskListComponent", { static: false }) taskListComponent!: TaskListComponent; | @ViewChild("taskListComponent", { static: false }) taskListComponent!: TaskListComponent; | ||||
| @ViewChild(MatPaginator) tasksPaginator: MatPaginator; | |||||
| protected user: User | null; | protected user: User | null; | ||||
| protected postSub: Subscription; | |||||
| protected posts: Array<PostJsonld>; | |||||
| protected usersSub: Subscription; | |||||
| protected users: Array<UserJsonld>; | |||||
| protected userIsAdmin: boolean; | |||||
| protected tasksSub: Subscription; | |||||
| protected tasks: Array<TaskJsonld>; | |||||
| protected tasksDataSource; | |||||
| protected tasksLength: number; | |||||
| protected tasksPageEvent: PageEvent; | |||||
| protected tasksPageSize: number; | |||||
| protected tasksPageIndex: number; | |||||
| protected taskNotesVisibility: Map<string, boolean>; | |||||
| protected modalOptions: NgbModalOptions = { | |||||
| centered: true | |||||
| }; | |||||
| constructor( | constructor( | ||||
| private modalService: NgbModal, | |||||
| private accountService: AccountService, | private accountService: AccountService, | ||||
| private postService: PostService, | |||||
| private userService: UserService, | |||||
| private taskService: TaskService, | |||||
| protected appHelperService: AppHelperService | protected appHelperService: AppHelperService | ||||
| ) { | ) { | ||||
| this.user = this.accountService.userValue; | 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<TaskJsonld>(this.tasks); | |||||
| this.tasksLength = 0; | |||||
| this.tasksPageEvent = new PageEvent(); | |||||
| this.tasksPageSize = 10; | |||||
| this.tasksPageIndex = 0; | |||||
| this.taskNotesVisibility = new Map<string, boolean>(); | |||||
| } | } | ||||
| ngOnInit(): void { | 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() { | 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); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,13 +1,15 @@ | |||||
| <div class="spt-container"> | |||||
| <div class="card"> | |||||
| <div class="card-body row"> | |||||
| <div class="col-4"> | |||||
| <h1>{{ user.firstName }} {{ user.lastName }}</h1> | |||||
| <dl> | |||||
| <dt>Email:</dt> | |||||
| <dd>{{ user.email }}</dd> | |||||
| </dl> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| <app-user | |||||
| [user]="user" | |||||
| ></app-user> | |||||
| <app-toggle #toggleTasks [headline]="('user.my' | translate) + ' ' + ('basic.tasks' | translate)"> | |||||
| <app-task-list #taskListComponent | |||||
| [user]="user"> | |||||
| </app-task-list> | |||||
| </app-toggle> | |||||
| <app-toggle #toggleSales [headline]="('user.my' | translate) + ' ' + ('basic.sales' | translate)"> | |||||
| <app-sale-list #saleListComponent | |||||
| [user]="user"> | |||||
| </app-sale-list> | |||||
| </app-toggle> | |||||
| @@ -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 {User} from "@app/_models"; | ||||
| import {Router} from "@angular/router"; | import {Router} from "@angular/router"; | ||||
| import {AccountService} from "@app/_services"; | import {AccountService} from "@app/_services"; | ||||
| import {Subscription} from "rxjs"; | import {Subscription} from "rxjs"; | ||||
| import {PartnerJsonld, UserJsonld, UserService} from "@app/core/api/v1"; | import {PartnerJsonld, UserJsonld, UserService} from "@app/core/api/v1"; | ||||
| import {AppHelperService} from "@app/_helpers/app-helper.service"; | 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({ | @Component({ | ||||
| selector: 'app-profile', | selector: 'app-profile', | ||||
| templateUrl: './profile.component.html', | templateUrl: './profile.component.html', | ||||
| styleUrl: './profile.component.scss' | 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( | constructor( | ||||
| private router: Router, | |||||
| private accountService: AccountService, | 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() { | 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 { | |||||
| } | } | ||||
| } | } | ||||
| @@ -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 {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 {TranslateService} from "@ngx-translate/core"; | ||||
| import {Router} from "@angular/router"; | import {Router} from "@angular/router"; | ||||
| import {AppHelperService} from "@app/_helpers/app-helper.service"; | import {AppHelperService} from "@app/_helpers/app-helper.service"; | ||||
| @@ -18,6 +18,7 @@ import {AccountService} from "@app/_services"; | |||||
| }) | }) | ||||
| export class SaleListComponent implements OnInit, AfterViewInit { | export class SaleListComponent implements OnInit, AfterViewInit { | ||||
| @Input() public user!: UserJsonld; | |||||
| @ViewChild(MatSort) sort; | @ViewChild(MatSort) sort; | ||||
| @ViewChild("pagingComponent", { static: false }) pagingComponent!: PagingComponent; | @ViewChild("pagingComponent", { static: false }) pagingComponent!: PagingComponent; | ||||
| @@ -56,6 +57,7 @@ export class SaleListComponent implements OnInit, AfterViewInit { | |||||
| this.salesSub = this.saleService.salesGetCollection( | this.salesSub = this.saleService.salesGetCollection( | ||||
| this.pagingComponent.getPageIndex(), | this.pagingComponent.getPageIndex(), | ||||
| this.pagingComponent.getPageSize(), | this.pagingComponent.getPageSize(), | ||||
| this.user !== undefined ? this.user.id : undefined | |||||
| ).subscribe( | ).subscribe( | ||||
| data => { | data => { | ||||
| this.sales = data["hydra:member"]; | this.sales = data["hydra:member"]; | ||||
| @@ -1,6 +1,6 @@ | |||||
| import {AfterViewInit, Component, OnInit} from '@angular/core'; | |||||
| import {AfterViewInit, Component, Input, OnInit} from '@angular/core'; | |||||
| import {Subscription} from "rxjs"; | import {Subscription} from "rxjs"; | ||||
| import {SaleSummaryJsonld, SaleSummaryService} from "@app/core/api/v1"; | |||||
| import {SaleSummaryJsonld, SaleSummaryService, UserJsonld} from "@app/core/api/v1"; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-sale-summary', | selector: 'app-sale-summary', | ||||
| @@ -9,6 +9,8 @@ import {SaleSummaryJsonld, SaleSummaryService} from "@app/core/api/v1"; | |||||
| }) | }) | ||||
| export class SaleSummaryComponent implements OnInit, AfterViewInit { | export class SaleSummaryComponent implements OnInit, AfterViewInit { | ||||
| @Input() public user!: UserJsonld; | |||||
| protected readonly Number = Number; | protected readonly Number = Number; | ||||
| protected salesSummarySub: Subscription; | protected salesSummarySub: Subscription; | ||||
| protected saleSummaries: Array<SaleSummaryJsonld>; | protected saleSummaries: Array<SaleSummaryJsonld>; | ||||
| @@ -0,0 +1,13 @@ | |||||
| <div class="spt-container"> | |||||
| <div class="card"> | |||||
| <div class="card-body row"> | |||||
| <div class="col-4"> | |||||
| <h1>{{ user.firstName }} {{ user.lastName }}</h1> | |||||
| <dl> | |||||
| <dt>Email:</dt> | |||||
| <dd>{{ user.email }}</dd> | |||||
| </dl> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| </div> | |||||
| @@ -0,0 +1,23 @@ | |||||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | |||||
| import { UserComponent } from './user.component'; | |||||
| describe('UserComponent', () => { | |||||
| let component: UserComponent; | |||||
| let fixture: ComponentFixture<UserComponent>; | |||||
| beforeEach(async () => { | |||||
| await TestBed.configureTestingModule({ | |||||
| declarations: [UserComponent] | |||||
| }) | |||||
| .compileComponents(); | |||||
| fixture = TestBed.createComponent(UserComponent); | |||||
| component = fixture.componentInstance; | |||||
| fixture.detectChanges(); | |||||
| }); | |||||
| it('should create', () => { | |||||
| expect(component).toBeTruthy(); | |||||
| }); | |||||
| }); | |||||
| @@ -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; | |||||
| } | |||||
| ); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -59,6 +59,7 @@ import { ProductListComponent } from './_views/products/product-list/product-lis | |||||
| import { DocumentListComponent } from './_views/documents/document-list/document-list.component'; | import { DocumentListComponent } from './_views/documents/document-list/document-list.component'; | ||||
| import { SaleListComponent } from './_views/sales/sale-list/sale-list.component'; | import { SaleListComponent } from './_views/sales/sale-list/sale-list.component'; | ||||
| import { SaleSummaryComponent } from './_views/sales/sale-summary/sale-summary.component'; | import { SaleSummaryComponent } from './_views/sales/sale-summary/sale-summary.component'; | ||||
| import { UserComponent } from './_views/user/user/user.component'; | |||||
| export function apiConfigFactory(): Configuration { | export function apiConfigFactory(): Configuration { | ||||
| const params: ConfigurationParameters = { | const params: ConfigurationParameters = { | ||||
| @@ -139,6 +140,7 @@ export function HttpLoaderFactory(http: HttpClient) { | |||||
| DocumentListComponent, | DocumentListComponent, | ||||
| SaleListComponent, | SaleListComponent, | ||||
| SaleSummaryComponent, | SaleSummaryComponent, | ||||
| UserComponent, | |||||
| ], | ], | ||||
| providers: [ | providers: [ | ||||
| {provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true}, | {provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true}, | ||||