|
| 1 | +// Copyright 2025 The Nomulus Authors. All Rights Reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +import { Component, effect } from '@angular/core'; |
| 16 | +import { UserDataService } from '../shared/services/userData.service'; |
| 17 | +import { BackendService } from '../shared/services/backend.service'; |
| 18 | +import { RegistrarService } from '../registrar/registrar.service'; |
| 19 | +import { HistoryService } from './history.service'; |
| 20 | +import { MatSnackBar } from '@angular/material/snack-bar'; |
| 21 | +import { |
| 22 | + GlobalLoader, |
| 23 | + GlobalLoaderService, |
| 24 | +} from '../shared/services/globalLoader.service'; |
| 25 | +import { HttpErrorResponse } from '@angular/common/http'; |
| 26 | +import { RESTRICTED_ELEMENTS } from '../shared/directives/userLevelVisiblity.directive'; |
| 27 | + |
| 28 | +@Component({ |
| 29 | + selector: 'app-history', |
| 30 | + templateUrl: './history.component.html', |
| 31 | + styleUrls: ['./history.component.scss'], |
| 32 | + providers: [HistoryService], |
| 33 | + standalone: false, |
| 34 | +}) |
| 35 | +export class HistoryComponent implements GlobalLoader { |
| 36 | + public static PATH = 'history'; |
| 37 | + |
| 38 | + consoleUserEmail: string = ''; |
| 39 | + isLoading: boolean = false; |
| 40 | + |
| 41 | + constructor( |
| 42 | + private backendService: BackendService, |
| 43 | + private registrarService: RegistrarService, |
| 44 | + protected historyService: HistoryService, |
| 45 | + protected globalLoader: GlobalLoaderService, |
| 46 | + protected userDataService: UserDataService, |
| 47 | + private _snackBar: MatSnackBar |
| 48 | + ) { |
| 49 | + effect(() => { |
| 50 | + if (registrarService.registrarId()) { |
| 51 | + this.loadHistory(); |
| 52 | + } |
| 53 | + }); |
| 54 | + } |
| 55 | + |
| 56 | + getElementIdForUserLog() { |
| 57 | + return RESTRICTED_ELEMENTS.ACTIVITY_PER_USER; |
| 58 | + } |
| 59 | + |
| 60 | + loadingTimeout() { |
| 61 | + this._snackBar.open('Timeout loading records history'); |
| 62 | + } |
| 63 | + |
| 64 | + loadHistory() { |
| 65 | + this.globalLoader.startGlobalLoader(this); |
| 66 | + this.isLoading = true; |
| 67 | + this.historyService |
| 68 | + .getHistoryLog(this.registrarService.registrarId(), this.consoleUserEmail) |
| 69 | + .subscribe({ |
| 70 | + error: (err: HttpErrorResponse) => { |
| 71 | + this._snackBar.open(err.error || err.message); |
| 72 | + this.isLoading = false; |
| 73 | + }, |
| 74 | + next: () => { |
| 75 | + this.globalLoader.stopGlobalLoader(this); |
| 76 | + this.isLoading = false; |
| 77 | + }, |
| 78 | + }); |
| 79 | + } |
| 80 | +} |
0 commit comments