diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 265f675..8a0ee2e 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -3,7 +3,6 @@ import {FormBuilder} from '@angular/forms'; import {SelectionModel} from '@angular/cdk/collections'; import {MediaMatcher} from '@angular/cdk/layout'; import {ChangeDetectorRef, Component, OnDestroy} from '@angular/core'; -// import { NavItem } from './nav-item'; import {MatTableDataSource} from '@angular/material/table'; @@ -15,27 +14,27 @@ import {MatTableDataSource} from '@angular/material/table'; export class AppComponent { constructor() - { - - this.connectWallet(); - } - - getWindowEthereumProperty() - { - //@ts-ignore + {this.connectWallet();} + getWindowEthereumProperty(): Ethereum | undefined { return window.ethereum; } + async connectWallet() { if (typeof window != "undefined" && typeof this.getWindowEthereumProperty() != "undefined") { - try { - /* MetaMask is installed */ - const accounts = await this.getWindowEthereumProperty().request({ - method: "eth_requestAccounts", - }); - - } catch (err) { - + const ethereum = this.getWindowEthereumProperty(); + if (ethereum) { + try { + /* MetaMask is installed */ + const accounts = await ethereum.request({ + method: "eth_requestAccounts", + }); + console.log('Connected accounts:', accounts); + } catch (err) { + console.error('Error connecting to MetaMask:', err); + } + } else { + console.error('MetaMask not found'); } } } diff --git a/src/app/auth/authbase.service.ts b/src/app/auth/authbase.service.ts index 04ccaef..84cd3d9 100644 --- a/src/app/auth/authbase.service.ts +++ b/src/app/auth/authbase.service.ts @@ -3,6 +3,7 @@ import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http //import {environment} from '../../environments/environment.dev'; import { environment } from '../../environments/environment'; import { Observable } from 'rxjs'; + @Injectable({ providedIn: 'root' }) diff --git a/src/app/auth/services/invitation.service.ts b/src/app/auth/services/invitation.service.ts index 6e5148d..d26a9c2 100644 --- a/src/app/auth/services/invitation.service.ts +++ b/src/app/auth/services/invitation.service.ts @@ -9,7 +9,6 @@ import { getapiuser_header } from '../../utils/apiuser_clientinfo' }) export class InvitationService { url: String = environment.API_URL; - headersData = getapiuser_header(); constructor(private httpClient: HttpClient) { } public Postuserinvitation(data: any, organizationId?: number, headers?: any): Observable { @@ -17,9 +16,8 @@ export class InvitationService { if (organizationId != null || organizationId != undefined) { addUrl += `?organizationId=${organizationId}`; } - let newheaders = new HttpHeaders(headers); - //@ts-ignore - return this.httpClient.post(addUrl, data, { headers }) + + return this.httpClient.post(addUrl, data) } public getinvitaion(): Observable { diff --git a/src/app/auth/services/organization.service.ts b/src/app/auth/services/organization.service.ts index 8bd73c7..e96be83 100644 --- a/src/app/auth/services/organization.service.ts +++ b/src/app/auth/services/organization.service.ts @@ -35,7 +35,7 @@ export class OrganizationService { return this.httpClient.get(environment.API_URL+ 'Organization/' + orgId); } - public GetApiUserAllOrganization(pagenumber?: number, limit?: number, searchData?: any): Observable { + public GetApiUserAllOrganization(pagenumber?: number, limit?: number, searchData?: any): Observable<{ organizations: OrganizationInformation[] }> { let searchUrl = `${environment.API_URL}Organization/apiuser/all_organization`; if (pagenumber != undefined && limit != undefined) { @@ -48,7 +48,7 @@ export class OrganizationService { searchUrl += `&organizationName=${searchData.organizationName}`; } } - return this.httpClient.get(searchUrl); + return this.httpClient.get<{ organizations: OrganizationInformation[] }>(searchUrl); } public removeUser(userId: number): Observable { diff --git a/src/app/models/Device_type.model.ts b/src/app/models/Device_type.model.ts new file mode 100644 index 0000000..4277370 --- /dev/null +++ b/src/app/models/Device_type.model.ts @@ -0,0 +1,24 @@ +export interface fulecodeType{ + code:string; + name:string; +} +export interface devicecodeType{ + code:string; + name:string; +} + +export interface CountryInfo { + country: string; + alpha2: string; + alpha3: string; + numeric: string; + countryCode: string; + timezones: TimezoneInfo[]; + } + + interface TimezoneInfo { + name: string; + offset: number; + } + + diff --git a/src/app/models/device.model.ts b/src/app/models/device.model.ts index 0c8faa7..ee0b67c 100644 --- a/src/app/models/device.model.ts +++ b/src/app/models/device.model.ts @@ -1,31 +1,38 @@ +export interface Devicelist { + devices: Device[], + currentPage: number, + totalPages: number, + totalCount: number, +} + export interface Device { - id: number; - externalId: string; - developerExternalId?:string; - //status: DeviceStatus; - organizationId: number; - projectName: string; - address?: string; - latitude: string; - longitude: string; - countryCode: string; - fuelCode: string; - deviceTypeCode: string; - capacity: number; - commissioningDate: string; - gridInterconnection: boolean; - offTaker: string; - yieldValue: number; - impactStory?: string; - images?: string[]; - groupId?: number | null; - deviceDescription?: string; - energyStorage?: boolean; - energyStorageCapacity?: number; - SDGBenefits?: string[]; - qualityLabels?: string; - meterReadtype?: string; - createdAt?:Date; - version?:string; - timezone?:string; - } \ No newline at end of file + id: number; + externalId: string; + developerExternalId?: string; + //status: DeviceStatus; + organizationId: number; + projectName: string; + address?: string; + latitude: string; + longitude: string; + countryCode: string; + fuelCode: string; + deviceTypeCode: string; + capacity: number; + commissioningDate: string; + gridInterconnection: boolean; + offTaker: string; + yieldValue: number; + impactStory?: string; + images?: string[]; + groupId?: number | null; + deviceDescription?: string; + energyStorage?: boolean; + energyStorageCapacity?: number; + SDGBenefits?: string[]; + qualityLabels?: string; + meterReadtype?: string; + createdAt?: Date; + version?: string; + timezone?: string; +} \ No newline at end of file diff --git a/src/app/models/index.ts b/src/app/models/index.ts new file mode 100644 index 0000000..4614fb6 --- /dev/null +++ b/src/app/models/index.ts @@ -0,0 +1,6 @@ +export * from './organization.model'; +export * from './blockchain-properties.model'; +export * from './device.model'; +export * from './user.model'; +export * from './yieldvalue.model'; +export * from './Device_type.model' \ No newline at end of file diff --git a/src/app/models/organization.model.ts b/src/app/models/organization.model.ts index dfa5124..dbdb3f8 100644 --- a/src/app/models/organization.model.ts +++ b/src/app/models/organization.model.ts @@ -13,7 +13,8 @@ export interface OrganizationInformation documentIds: string[]; signatoryDocumentIds: string[]; blockchainAccountAddress: string; - blockchainAccountSignedMessage: string; + blockchainAccountSignedMessage: string; + api_user_id:string; } export class IPublicOrganization { id: number; diff --git a/src/app/utils/getTimezone_msg.ts b/src/app/utils/getTimezone_msg.ts index d0d126c..9e7fc54 100644 --- a/src/app/utils/getTimezone_msg.ts +++ b/src/app/utils/getTimezone_msg.ts @@ -1,15 +1,11 @@ export const getValidmsgTimezoneFormat = (msg: string) => { let message = msg; - //"The sent date for reading 2023-01-01T07:44:34.000Z is less than last sent meter read date 2023-01-01T07:45:53.000Z" let r = /\d\d\d\d\-\d\d\-\d\d\T\d\d\:\d\d:\d\d\.\d\d\dZ/g; - //@ts-ignore let dates = message.match(r); - //@ts-ignore if (dates != null || dates != undefined) { dates.forEach(ele => { - //@ts-ignore message = message.replace(ele, new Date(ele).toString()) }) } diff --git a/src/app/view/add-reservation/add-reservation.component.ts b/src/app/view/add-reservation/add-reservation.component.ts index df6c806..22c8c99 100644 --- a/src/app/view/add-reservation/add-reservation.component.ts +++ b/src/app/view/add-reservation/add-reservation.component.ts @@ -14,7 +14,8 @@ import { MatBottomSheet, MatBottomSheetConfig, MatBottomSheetRef } from '@angula import { MeterReadTableComponent } from '../meter-read/meter-read-table/meter-read-table.component' import { Observable, Subscription, debounceTime } from 'rxjs'; import { map, startWith } from 'rxjs/operators'; -import { DeviceDetailsComponent } from '../device/device-details/device-details.component' +import { DeviceDetailsComponent } from '../device/device-details/device-details.component'; +import {OrganizationInformation,Device,fulecodeType,devicecodeType,CountryInfo } from '../../models' @Component({ selector: 'app-add-reservation', templateUrl: './add-reservation.component.html', @@ -28,7 +29,6 @@ export class AddReservationComponent { 'projectName', 'externalId', 'countryCode', - // 'fuelCode', 'commissioningDate', 'status', 'viewread' @@ -39,13 +39,13 @@ export class AddReservationComponent { @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; dataSource: MatTableDataSource; - data: any; + data: Device[]=[]; loginuser: any deviceurl: any; pageSize: number = 20; - countrylist: any; - fuellist: any; - devicetypelist: any; + countrylist: CountryInfo[]=[]; + fuellist: fulecodeType[]=[]; + devicetypelist: devicecodeType[]=[]; fuellistLoaded: boolean = false; devicetypeLoded: boolean = false; countrycodeLoded: boolean = false; @@ -68,9 +68,8 @@ export class AddReservationComponent { showerror: boolean = false; orgname: string; orgId: number; - orglist: any; - filteredOrgList: any[] = []; - // countrycodeLoded: boolean = false; + orglist: OrganizationInformation[] = []; + filteredOrgList: OrganizationInformation[] = []; reservationbollean = { continewwithunavilableonedevice: true, continueWithTCLessDTC: true }; constructor(private authService: AuthbaseService, private reservationService: ReservationService, private router: Router, public dialog: MatDialog, private bottomSheet: MatBottomSheet, @@ -78,7 +77,6 @@ export class AddReservationComponent { private toastrService: ToastrService, private deviceservice: DeviceService, private orgService: OrganizationService) { - // this.loginuser = sessionStorage.getItem('loginuser'); this.loginuser = JSON.parse(sessionStorage.getItem('loginuser')!); this.reservationForm = this.formBuilder.group({ name: [null, Validators.required], @@ -103,7 +101,6 @@ export class AddReservationComponent { SDGBenefits: [], start_date: [null], end_date: [null], - // pagenumber: [this.p] }); this.FilterForm.valueChanges.subscribe(() => { @@ -114,8 +111,10 @@ export class AddReservationComponent { if (this.loginuser.role === 'ApiUser') { this.orgService.GetApiUserAllOrganization().subscribe( (data) => { - //@ts-ignore - this.orglist = data.organizations.filter(org => org.organizationType != "Developer"); + + this.orglist = data.organizations.filter( + (org: OrganizationInformation) => org.organizationType !== 'Developer' + ); // const buyerOrganizations = data.filter(org => org.organizationType === "Buyer"); this.filteredOrgList = this.orglist; } @@ -169,7 +168,7 @@ export class AddReservationComponent { }); } selectOrg(event: any) { - //@ts-ignore + const selectedCountry = this.orglist.find(option => option.name === event.option.value); if (selectedCountry) { this.orgId = selectedCountry.id; @@ -184,7 +183,7 @@ export class AddReservationComponent { ); } - private _filter(value: any): string[] { + private _filter(value: any): CountryInfo[] { const filterValue = value.toLowerCase(); if (!(this.countrylist.filter((option: any) => option.country.toLowerCase().includes(filterValue)).length > 0)) { this.showerror = true; @@ -321,21 +320,21 @@ export class AddReservationComponent { } this.data = data.devices; - //@ts-ignore - this.data.forEach(ele => { - //@ts-ignore + + this.data.forEach((ele:any) => { + ele['fuelname'] = this.fuellist.find((fuelType) => fuelType.code === ele.fuelCode,)?.name; - //@ts-ignore + ele['devicetypename'] = this.devicetypelist.find(devicetype => devicetype.code == ele.deviceTypeCode)?.name; - //@ts-ignore + ele['countryname'] = this.countrylist.find(countrycode => countrycode.alpha3 == ele.countryCode)?.country; }) this.dataSource = new MatTableDataSource(this.data); this.totalRows = data.totalCount this.totalPages = data.totalPages - //this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; - //@ts-ignore + } ) } diff --git a/src/app/view/admin/add-users/add-users.component.ts b/src/app/view/admin/add-users/add-users.component.ts index 2d60c00..7ea7709 100644 --- a/src/app/view/admin/add-users/add-users.component.ts +++ b/src/app/view/admin/add-users/add-users.component.ts @@ -56,19 +56,9 @@ export class AddUsersComponent { confirmPassword: new FormControl(null), }, - // { - // validators: (control) => { - - // if (control.value.password !== control.value.confirmPassword) { - // //@ts-ignore - // control.get("confirmPassword").setErrors({ notSame: true }); - // } - // return null; - // }, - // } + ); - } emaiErrors() { return this.registerForm.get('email')?.hasError('required') ? 'This field is required' : diff --git a/src/app/view/admin/admin-alldevices/admin-alldevices.component.ts b/src/app/view/admin/admin-alldevices/admin-alldevices.component.ts index caf54e2..ce0728e 100644 --- a/src/app/view/admin/admin-alldevices/admin-alldevices.component.ts +++ b/src/app/view/admin/admin-alldevices/admin-alldevices.component.ts @@ -17,6 +17,8 @@ import { map, startWith } from 'rxjs/operators'; import { MatDialog, MatDialogRef } from '@angular/material/dialog'; import { DeviceDetailsComponent } from '../../device/device-details/device-details.component' import { ToastrService } from 'ngx-toastr'; +import {OrganizationInformation,Device,fulecodeType,devicecodeType,CountryInfo } from '../../../models' + @Component({ selector: 'app-admin-alldevices', templateUrl: './admin-alldevices.component.html', @@ -46,9 +48,9 @@ export class AdminAlldevicesComponent { loginuser: any deviceurl: any; pageSize: number = 20; - countrylist: any; - fuellist: any; - devicetypelist: any; + countrylist: CountryInfo[]=[]; + fuellist: fulecodeType[]=[]; + devicetypelist: devicecodeType[]=[]; fuellistLoaded: boolean = false; devicetypeLoded: boolean = false; countrycodeLoded: boolean = false; @@ -68,7 +70,7 @@ export class AdminAlldevicesComponent { showerror: boolean = false; showorgerror: boolean = false; showlist: boolean = false; - orglist: any; + orglist: OrganizationInformation[] = []; showapiuser_devices: boolean = false; apiuserId: string; constructor(private authService: AuthbaseService, private deviceService: DeviceService, private adminService: AdminService, @@ -100,24 +102,28 @@ export class AdminAlldevicesComponent { } this.adminService.GetAllOrganization().subscribe( (data) => { - //@ts-ignore - this.orglist = data.organizations.filter(org => org.organizationType == "Developer" && org.api_user_id ==this.apiuserId); + + // this.orglist = data.organizations.filter(org => org.organizationType == "Developer" && org.api_user_id ==this.apiuserId); + this.orglist = data.organizations.filter( + (org: OrganizationInformation) => org.organizationType !== 'Developer' + ); + }) this.authService.GetMethod('device/fuel-type').subscribe( - (data1) => { + (data1:any) => { this.fuellist = data1; this.fuellistLoaded = true; }); this.authService.GetMethod('device/device-type').subscribe( - (data2) => { + (data2:any) => { this.devicetypelist = data2; this.devicetypeLoded = true; } ); this.authService.GetMethod('countrycode/list').subscribe( - (data3) => { + (data3:any) => { this.countrylist = data3; this.countrycodeLoded = true; @@ -152,7 +158,7 @@ export class AdminAlldevicesComponent { map(value => this._orgfilter(value || '')), ); } - private _orgfilter(value: any): string[] { + private _orgfilter(value: any): OrganizationInformation[] { const filterValue = value.toLowerCase(); if (!(this.orglist.filter((option: any) => option.name.toLowerCase().includes(filterValue)).length > 0)) { @@ -172,7 +178,7 @@ export class AdminAlldevicesComponent { ); } - private _filter(value: any): string[] { + private _filter(value: any): CountryInfo[] { const filterValue = value.toLowerCase(); if (!(this.countrylist.filter((option: any) => option.country.toLowerCase().includes(filterValue)).length > 0)) { @@ -282,10 +288,10 @@ export class AdminAlldevicesComponent { this.deviceService.GetMyDevices(this.deviceurl, this.FilterForm.value, page).subscribe({ next: data => { this.showlist = true - //@ts-ignore + if (data.devices) { this.loading = false; - //@ts-ignore + this.data = data; this.DisplayList() } @@ -303,13 +309,13 @@ export class AdminAlldevicesComponent { DisplayList() { if (this.fuellistLoaded == true && this.devicetypeLoded == true && this.countrycodeLoded === true) { - //@ts-ignore - this.data.devices.forEach(ele => { - //@ts-ignore + + this.data.devices.forEach((ele:any)=> { + ele['fuelname'] = this.fuellist.find((fuelType) => fuelType.code === ele.fuelCode,)?.name; - //@ts-ignore + ele['devicetypename'] = this.devicetypelist.find(devicetype => devicetype.code == ele.deviceTypeCode)?.name; - //@ts-ignore + ele['countryname'] = this.countrylist.find(countrycode => countrycode.alpha3 == ele.countryCode)?.country; }) diff --git a/src/app/view/admin/apiuser/apiuser.component.ts b/src/app/view/admin/apiuser/apiuser.component.ts index 5d7b077..abbf148 100644 --- a/src/app/view/admin/apiuser/apiuser.component.ts +++ b/src/app/view/admin/apiuser/apiuser.component.ts @@ -144,7 +144,6 @@ export class ApiuserComponent { this.showlist = true; this.showorguser=false; this.loading = false - //@ts-ignore this.data = data;//.filter(ele => ele.organizationType === 'Developer'); this.dataSource = new MatTableDataSource(this.data.users); this.totalRows = this.data.totalCount diff --git a/src/app/view/all-users/all-users.component.ts b/src/app/view/all-users/all-users.component.ts index c5f20ed..db3c143 100644 --- a/src/app/view/all-users/all-users.component.ts +++ b/src/app/view/all-users/all-users.component.ts @@ -195,7 +195,6 @@ export class AllUsersComponent { this.showlist = true; this.showorguser = false; this.loading = false - //@ts-ignore this.data = data;//.filter(ele => ele.organizationType === 'Developer'); this.dataSource = new MatTableDataSource(this.data.users); this.totalRows = this.data.totalCount @@ -213,9 +212,8 @@ export class AllUsersComponent { getOrganizationAllUser(page: number, limit: number) { this.orgService.getOrganizationUser(page, limit).subscribe({ next: (data) => { - this.showlist = true - this.loading = false - //@ts-ignore + this.showlist = true; + this.loading = false; this.data = data;//.filter(ele => ele.organizationType === 'Developer'); this.dataSource = new MatTableDataSource(this.data.users); this.totalRows = this.data.totalCount @@ -236,13 +234,12 @@ export class AllUsersComponent { this.adminService.GetAllOrgnaizationUsers(this.orgnaizatioId, page, limit).subscribe({ next: (data) => { this.showorguser = false; - this.showlist = true - this.loading = false - //@ts-ignore + this.showlist = true; + this.loading = false; this.data = data;//.filter(ele => ele.organizationType === 'Developer'); this.dataSource = new MatTableDataSource(this.data.users); - this.totalRows = this.data.totalCount - this.totalPages = this.data.totalPages + this.totalRows = this.data.totalCount; + this.totalPages = this.data.totalPages; }, error: err => { if (err.error.statusCode === 403) { this.toastrService.error('Error:' + err.error.message, 'Unauthorized') diff --git a/src/app/view/apiuser/all-apiuser/all-apiuser.component.ts b/src/app/view/apiuser/all-apiuser/all-apiuser.component.ts index 0d62814..f9f253d 100644 --- a/src/app/view/apiuser/all-apiuser/all-apiuser.component.ts +++ b/src/app/view/apiuser/all-apiuser/all-apiuser.component.ts @@ -148,8 +148,7 @@ export class AllApiuserComponent { this.adminService.GetAllApiUsers(page,limit,this.FilterForm.value).subscribe((data) => { this.showlist = true; this.showorguser=false; - this.loading = false - //@ts-ignore + this.loading = false; this.data = data;//.filter(ele => ele.organizationType === 'Developer'); this.dataSource = new MatTableDataSource(this.data.users); this.totalRows = this.data.totalCount diff --git a/src/app/view/certificate-details/certificate-details.component.ts b/src/app/view/certificate-details/certificate-details.component.ts index 7a6f38c..bf8a42f 100644 --- a/src/app/view/certificate-details/certificate-details.component.ts +++ b/src/app/view/certificate-details/certificate-details.component.ts @@ -158,15 +158,15 @@ export class CertificateDetailsComponent { } showorglist(event: any) { - //this.filteredOrgList=[]; + this.orgService.GetApiUserAllOrganization().subscribe( (data) => { if (event === "Developer") { - //@ts-ignore + this.orglist = data.organizations.filter(org => org.organizationType != "Buyer"); this.applyorgFilter(); } else { - //@ts-ignore + this.orglist = data.organizations.filter(org => org.organizationType != "Developer"); this.applyorgFilter(); } @@ -342,11 +342,10 @@ export class CertificateDetailsComponent { this.loading = false; // display list in the console if (data.certificatelog.length > 0) { - // this.data = data; - //@ts-ignore - this.data = data.certificatelog.filter(ele => ele !== null) - //@ts-ignore - this.data.forEach(ele => { + + this.data = data.certificatelog.filter((ele:any) => ele !== null) + + this.data.forEach((ele:any) => { ele['generationStartTimeinUTC'] = new Date(ele.generationStartTime * 1000).toISOString(); ele['generationEndTimeinUTC'] = new Date(ele.generationEndTime * 1000).toISOString(); @@ -358,9 +357,7 @@ export class CertificateDetailsComponent { if (key !== key.toLowerCase()) { ele.owners[key.toLowerCase()] = ele.owners[key]; delete ele.owners[key]; - // if(ele.owner[key].value=0){ - - // } + } } @@ -368,11 +365,9 @@ export class CertificateDetailsComponent { ele.creationBlockHash ele['energyurl'] = environment.Explorer_URL + '/token/' + this.blockchainProperties.registry + '/instance/' + ele.id + '/token-transfers' } - //@ts-ignore - else if (ele.transactions.find(ele1 => ele1.eventType == "IssuancePersisted")) { + else if (ele.transactions.find((ele1:any) => ele1.eventType == "IssuancePersisted")) { - //@ts-ignore - ele.creationBlockHash = ele.transactions.find(ele1 => ele1.eventType == "IssuancePersisted").transactionHash + ele.creationBlockHash = ele.transactions.find((ele1:any) => ele1.eventType == "IssuancePersisted").transactionHash ele['energyurl'] = environment.Explorer_URL + '/token/' + this.blockchainProperties.registry + '/instance/' + ele.blockchainCertificateId + '/token-transfers' } @@ -403,7 +398,7 @@ export class CertificateDetailsComponent { } getWindowEthereumObject() { - //@ts-ignore + return window.ethereum; } @@ -425,25 +420,34 @@ export class CertificateDetailsComponent { checkMetamaskConnected() { return typeof window !== 'undefined' && typeof this.getWindowEthereumObject() !== 'undefined'; } - - connectWallet() { - //@ts-ignore - if (typeof window !== 'undefined' && typeof window.ethereum! == 'undefined') { - try { - //@ts-ignore - window.ethereum.request({ method: 'eth_requestAccounts' }) - - } - catch (e) { - console.error("some error occures", e); + getWindowEthereumProperty(): Ethereum | undefined { + return window.ethereum; + } + async connectWallet() { + + if (typeof window != "undefined" && typeof this.getWindowEthereumProperty() != "undefined") { + const ethereum = this.getWindowEthereumProperty(); + if (ethereum) { + try { + /* MetaMask is installed */ + const accounts = await ethereum.request({ + method: "eth_requestAccounts", + }); + console.log('Connected accounts:', accounts); + } catch (err) { + console.error('Error connecting to MetaMask:', err); + } + } else { + console.error('MetaMask not found'); } } } + selectAccountAddressFromMetamask() { - //@ts-ignore + if (typeof window !== 'undefined' && typeof window.ethereum !== 'undefined') { - //@ts-ignore + window.ethereum.request({ method: 'eth_requestAccounts' }).then(response => { this.selectedBlockchainAccount = (response && response[0]) ? response[0] : ''; this.selectedBlockchainAccount = this.selectedBlockchainAccount.toLowerCase(); diff --git a/src/app/view/certificate/certificate.component.ts b/src/app/view/certificate/certificate.component.ts index 40f7aaf..ede72af 100644 --- a/src/app/view/certificate/certificate.component.ts +++ b/src/app/view/certificate/certificate.component.ts @@ -16,7 +16,7 @@ import { ethers } from 'ethers'; import { ToastrService } from 'ngx-toastr'; import { issuerABI } from './issuer-abi'; import { registryABI } from './registery-abi'; -import { MeterReadService ,ReservationService,BlockchainDrecService,CertificateService} from '../../auth/services' +import { MeterReadService, ReservationService, BlockchainDrecService, CertificateService } from '../../auth/services' export interface Student { firstName: string; lastName: string; @@ -78,12 +78,12 @@ export class CertificateComponent implements OnDestroy { certifiedp: number = 1 certified_total: number; constructor(private blockchainDRECService: BlockchainDrecService, - private authService: AuthbaseService, - private certificateauthService: CertificateService, + private authService: AuthbaseService, + private certificateauthService: CertificateService, private router: Router, - private activatedRoute: ActivatedRoute, - private toastrService: ToastrService, - private bottomSheet: MatBottomSheet, + private activatedRoute: ActivatedRoute, + private toastrService: ToastrService, + private bottomSheet: MatBottomSheet, private fb: FormBuilder, private reservationService: ReservationService, private readService: MeterReadService, @@ -96,7 +96,7 @@ export class CertificateComponent implements OnDestroy { }); - + } ngOnInit() { this.claimData = this.fb.group({ @@ -109,11 +109,10 @@ export class CertificateComponent implements OnDestroy { }) this.reservationService.GetMethodById(this.group_id).subscribe( (data: any) => { - //@ts-ignore this.group_name = data.name; this.devicesId = data.deviceIds; this.reservationstatus = data.reservationActive; - + } @@ -152,7 +151,6 @@ export class CertificateComponent implements OnDestroy { getnextissuancinfo(historyp: number) { this.reservationService.GetnextissuanceCycleinfo(this.group_uid, historyp).subscribe( (data: any) => { - //@ts-ignore this.history_nextissuanclist = data.historynextissuansinfo.AllDeviceshistnextissuansinfo; this.historynextissuance_total = data.historynextissuansinfo.totalPages; @@ -180,7 +178,7 @@ export class CertificateComponent implements OnDestroy { if (typeof this.devicesId === 'string') { this.readService.Getlastread(this.devicesId).subscribe({ next: data => { - this.alldevicesread.push(data) + this.alldevicesread.push(data) }, error: err => { //Error callback console.error('error caught in component', err) @@ -193,7 +191,7 @@ export class CertificateComponent implements OnDestroy { this.devicesId.forEach((elemant: any) => { this.readService.Getlastread(elemant).subscribe({ next: data => { - this.alldevicesread.push(data) + this.alldevicesread.push(data) }, error: err => { //Error callback console.error('error caught in component', err) @@ -300,19 +298,14 @@ export class CertificateComponent implements OnDestroy { } // CertificateClaimed:boolean=false; DisplayList(p: number) { - - this.certificateauthService.getcertifiedlogByGooupUid( this.group_uid , p).subscribe({ - next: (data: any) => { + + this.certificateauthService.getcertifiedlogByGooupUid(this.group_uid, p).subscribe({ + next: (data: any) => { this.loading = false; - // display list in the console + this.data = data.certificatelog.filter((ele: any) => ele !== null) + this.totalPages = data.totalPages; - // this.data = data; - //@ts-ignore - this.data = data.certificatelog.filter(ele => ele !== null) - this.totalPages = data.totalPages - ; - //@ts-ignore - this.data.forEach(ele => { + this.data.forEach((ele: any) => { ele['generationStartTimeinUTC'] = new Date(ele.generationStartTime * 1000).toISOString(); ele['generationEndTimeinUTC'] = new Date(ele.generationEndTime * 1000).toISOString(); @@ -331,17 +324,14 @@ export class CertificateComponent implements OnDestroy { ele.creationBlockHash ele['energyurl'] = environment.Explorer_URL + '/token/' + this.blockchainProperties.registry + '/instance/' + ele.id + '/token-transfers' } - //@ts-ignore - else if (ele.transactions.find(ele1 => ele1.eventType == "IssuancePersisted")) { - - //@ts-ignore - ele.creationBlockHash = ele.transactions.find(ele1 => ele1.eventType == "IssuancePersisted").transactionHash + else if (ele.transactions.find((ele1: any) => ele1.eventType == "IssuancePersisted")) { + ele.creationBlockHash = ele.transactions.find((ele1: any) => ele1.eventType == "IssuancePersisted").transactionHash ele['energyurl'] = environment.Explorer_URL + '/token/' + this.blockchainProperties.registry + '/instance/' + ele.blockchainCertificateId + '/token-transfers' } }) - },error:err=>{ + }, error: err => { if (err.error.statusCode === 403) { this.toastrService.error('Error:' + err.error.message, 'Unauthorized') } else { @@ -349,7 +339,7 @@ export class CertificateComponent implements OnDestroy { } } } - + ) } @@ -367,7 +357,6 @@ export class CertificateComponent implements OnDestroy { } } getWindowEthereumObject() { - //@ts-ignore return window.ethereum; } @@ -389,25 +378,34 @@ export class CertificateComponent implements OnDestroy { checkMetamaskConnected() { return typeof window !== 'undefined' && typeof this.getWindowEthereumObject() !== 'undefined'; } - - connectWallet() { - //@ts-ignore - if (typeof window !== 'undefined' && typeof window.ethereum! == 'undefined') { - try { - //@ts-ignore - window.ethereum.request({ method: 'eth_requestAccounts' }) - - } - catch (e) { - console.error("some error occures", e); + getWindowEthereumProperty(): Ethereum | undefined { + return window.ethereum; + } + async connectWallet() { + + if (typeof window != "undefined" && typeof this.getWindowEthereumProperty() != "undefined") { + const ethereum = this.getWindowEthereumProperty(); + if (ethereum) { + try { + /* MetaMask is installed */ + const accounts = await ethereum.request({ + method: "eth_requestAccounts", + }); + console.log('Connected accounts:', accounts); + } catch (err) { + console.error('Error connecting to MetaMask:', err); + } + } else { + console.error('MetaMask not found'); } } } + selectAccountAddressFromMetamask() { - //@ts-ignore + if (typeof window !== 'undefined' && typeof window.ethereum !== 'undefined') { - //@ts-ignore + window.ethereum.request({ method: 'eth_requestAccounts' }).then(response => { this.selectedBlockchainAccount = (response && response[0]) ? response[0] : ''; this.selectedBlockchainAccount = this.selectedBlockchainAccount.toLowerCase(); @@ -459,29 +457,40 @@ export class CertificateComponent implements OnDestroy { } claimUsingEtherJS() { - //@ts-ignore - const provider = new ethers.providers.Web3Provider(window.ethereum); - //@ts-ignore - //const daiContract = new ethers.Contract("0x4dae00fa86aC7548f92a0293A676Ad07b65c264F", registryABI, provider); - - const daiContract = new ethers.Contract(this.blockchainProperties.registry, registryABI, provider); - const signer = provider.getSigner(); - const daiWithSigner = daiContract.connect(signer); - - let claimData = { - beneficiary: 'Beneficiary: ' + this.claimData.value.beneficiary, - location: 'Location: ' + this.claimData.value.location, - countryCode: 'Country Code: ' + this.claimData.value.countryCode, - periodStartDate: 'Period Start Date: ' + new Date(this.selectedCertificateForClaim.generationStartTime * 1000).toISOString(), - periodEndDate: 'Period End Date: ' + new Date(this.selectedCertificateForClaim.generationEndTime * 1000).toISOString(), - purpose: 'Purpose: ' + this.claimData.value.purpose - } - daiWithSigner.functions['safeTransferAndClaimFrom'](this.selectedBlockchainAccount, this.selectedBlockchainAccount, this.selectedCertificateForClaim.id, this.formattedClaimAmount, this.encodeClaimData(claimData), this.encodeClaimData(claimData)); + if (window.ethereum) { + try { + const provider = new ethers.providers.Web3Provider(window.ethereum); + + const daiContract = new ethers.Contract(this.blockchainProperties.registry, registryABI, provider); + const signer = provider.getSigner(); + const daiWithSigner = daiContract.connect(signer); + + let claimData = { + beneficiary: 'Beneficiary: ' + this.claimData.value.beneficiary, + location: 'Location: ' + this.claimData.value.location, + countryCode: 'Country Code: ' + this.claimData.value.countryCode, + periodStartDate: 'Period Start Date: ' + new Date(this.selectedCertificateForClaim.generationStartTime * 1000).toISOString(), + periodEndDate: 'Period End Date: ' + new Date(this.selectedCertificateForClaim.generationEndTime * 1000).toISOString(), + purpose: 'Purpose: ' + this.claimData.value.purpose + } + daiWithSigner.functions['safeTransferAndClaimFrom'](this.selectedBlockchainAccount, this.selectedBlockchainAccount, this.selectedCertificateForClaim.id, this.formattedClaimAmount, this.encodeClaimData(claimData), this.encodeClaimData(claimData)); - setTimeout(() => { - this.toastrService.info(`Please check metamask for success or failure of claim of this certificate`); - this.closeTemplateSheetMenu(); - }, 1000); + setTimeout(() => { + this.toastrService.info(`Please check metamask for success or failure of claim of this certificate`); + this.closeTemplateSheetMenu(); + }, 1000); + + } + catch (error) { + console.error('Error during the claim process:', error); + this.toastrService.error('An error occurred during the claim process. Please try again.'); + } finally { + this.closeTemplateSheetMenu(); + } + } else { + console.error('window.ethereum is not available'); + this.toastrService.error('Ethereum provider is not available. Please install MetaMask.'); + } } diff --git a/src/app/view/certified-devices-developer/certified-devices-developer.component.ts b/src/app/view/certified-devices-developer/certified-devices-developer.component.ts index eed49bf..a0355b7 100644 --- a/src/app/view/certified-devices-developer/certified-devices-developer.component.ts +++ b/src/app/view/certified-devices-developer/certified-devices-developer.component.ts @@ -323,14 +323,9 @@ export class CertifiedDevicesDeveloperComponent { this.loading = false; // display list in the console - - // this.data = data; - if (data.certificatelog.length > 0) { - //@ts-ignore - this.data = data.certificatelog.filter(ele => ele !== null) - //@ts-ignore - this.data.forEach(ele => { + this.data = data.certificatelog.filter((ele:any) => ele !== null) + this.data.forEach((ele:any) => { ele['generationStartTimeinUTC'] = new Date(ele.generationStartTime * 1000).toISOString(); ele['generationEndTimeinUTC'] = new Date(ele.generationEndTime * 1000).toISOString(); @@ -342,24 +337,8 @@ export class CertifiedDevicesDeveloperComponent { if (key !== key.toLowerCase()) { ele.owners[key.toLowerCase()] = ele.owners[key]; delete ele.owners[key]; - // if(ele.owner[key].value=0){ - - // } } } - - // if (ele.creationBlockHash != "") { - // ele.creationBlockHash - // ele['energyurl'] = environment.Explorer_URL + '/token/' + this.blockchainProperties.registry + '/instance/' + ele.id + '/token-transfers' - // } - // //@ts-ignore - // else if (ele.transactions.find(ele1 => ele1.eventType == "IssuancePersisted")) { - - // //@ts-ignore - // ele.creationBlockHash = ele.transactions.find(ele1 => ele1.eventType == "IssuancePersisted").transactionHash - - // ele['energyurl'] = environment.Explorer_URL + '/token/' + this.blockchainProperties.registry + '/instance/' + ele.blockchainCertificateId + '/token-transfers' - // } }) this.dataSource = new MatTableDataSource(this.data); @@ -380,7 +359,6 @@ export class CertifiedDevicesDeveloperComponent { } getWindowEthereumObject() { - //@ts-ignore return window.ethereum; } @@ -402,25 +380,32 @@ export class CertifiedDevicesDeveloperComponent { checkMetamaskConnected() { return typeof window !== 'undefined' && typeof this.getWindowEthereumObject() !== 'undefined'; } - - connectWallet() { - //@ts-ignore - if (typeof window !== 'undefined' && typeof window.ethereum! == 'undefined') { - try { - //@ts-ignore - window.ethereum.request({ method: 'eth_requestAccounts' }) - - } - catch (e) { - console.error("some error occures", e); + getWindowEthereumProperty(): Ethereum | undefined { + return window.ethereum; + } + async connectWallet() { + + if (typeof window != "undefined" && typeof this.getWindowEthereumProperty() != "undefined") { + const ethereum = this.getWindowEthereumProperty(); + if (ethereum) { + try { + /* MetaMask is installed */ + const accounts = await ethereum.request({ + method: "eth_requestAccounts", + }); + console.log('Connected accounts:', accounts); + } catch (err) { + console.error('Error connecting to MetaMask:', err); + } + } else { + console.error('MetaMask not found'); } } } + selectAccountAddressFromMetamask() { - //@ts-ignore if (typeof window !== 'undefined' && typeof window.ethereum !== 'undefined') { - //@ts-ignore window.ethereum.request({ method: 'eth_requestAccounts' }).then(response => { this.selectedBlockchainAccount = (response && response[0]) ? response[0] : ''; this.selectedBlockchainAccount = this.selectedBlockchainAccount.toLowerCase(); diff --git a/src/app/view/device/add-bulk-device/add-bulk-device.component.ts b/src/app/view/device/add-bulk-device/add-bulk-device.component.ts index 1c74e63..da7985e 100644 --- a/src/app/view/device/add-bulk-device/add-bulk-device.component.ts +++ b/src/app/view/device/add-bulk-device/add-bulk-device.component.ts @@ -7,9 +7,10 @@ import { MatTableDataSource, MatTable } from '@angular/material/table'; import { animate, state, style, transition, trigger } from '@angular/animations'; import { MatSort } from '@angular/material/sort'; import { MatPaginator } from '@angular/material/paginator'; - import { DeviceService, AdminService, OrganizationService } from '../../../auth/services' import { Router, ActivatedRoute } from '@angular/router'; +import {OrganizationInformation,Device,fulecodeType,devicecodeType,CountryInfo } from '../../../models' + @Component({ selector: 'app-add-bulk-device', templateUrl: './add-bulk-device.component.html', @@ -53,27 +54,25 @@ export class AddBulkDeviceComponent implements OnInit { dataSource1: MatTableDataSource; data: any; orglist: any; - filteredOrgList: any[] = []; + filteredOrgList: OrganizationInformation[] = []; //public color: ThemePalette = 'primary'; orgname: string; orgId: number; loginuser: any; + ngOnInit(): void { if (this.loginuser.role === 'Admin') { this.adminService.GetAllOrganization().subscribe( (data) => { - //@ts-ignore - this.orglist = data.organizations.filter(org => org.organizationType != "Buyer"); - + this.orglist = data.organizations.filter( + (org: OrganizationInformation) => org.organizationType !== 'Buyer' + ); this.filteredOrgList = this.orglist; }) } else if (this.loginuser.role === 'ApiUser') { this.orgService.GetApiUserAllOrganization().subscribe( (data) => { - //@ts-ignore this.orglist = data.organizations.filter(org => org.organizationType != "Buyer"); - - // const buyerOrganizations = data.filter(org => org.organizationType === "Buyer"); this.filteredOrgList = this.orglist; } ); @@ -83,13 +82,12 @@ export class AddBulkDeviceComponent implements OnInit { } filterOrgList() { - this.filteredOrgList = this.orglist.filter((org: any) => { + this.filteredOrgList = this.orglist.filter((org: OrganizationInformation) => { return org.name.toLowerCase().includes(this.orgname.toLowerCase()); }); } selectOrg(event: any) { - //@ts-ignore - const selectedCountry = this.orglist.find(option => option.name === event.option.value); + const selectedCountry = this.orglist.find((option:any) => option.name === event.option.value); if (selectedCountry) { this.orgId = selectedCountry.id; } diff --git a/src/app/view/device/add-devices/add-devices.component.ts b/src/app/view/device/add-devices/add-devices.component.ts index b911ea3..6ad2b21 100644 --- a/src/app/view/device/add-devices/add-devices.component.ts +++ b/src/app/view/device/add-devices/add-devices.component.ts @@ -6,6 +6,8 @@ import { Router } from '@angular/router'; import { ToastrService } from 'ngx-toastr'; import { Observable, Subscription } from 'rxjs'; import { startWith, map } from 'rxjs/operators'; +import {OrganizationInformation,Device,fulecodeType,devicecodeType,CountryInfo } from '../../../models' + //import * as moment from 'moment'; @Component({ selector: 'app-add-devices', @@ -15,9 +17,9 @@ import { startWith, map } from 'rxjs/operators'; export class AddDevicesComponent { loginuser: any; myform: FormGroup; - countrylist: any; - fuellist: any; - devicetypelist: any; + countrylist: CountryInfo[]=[]; + fuellist: fulecodeType[]=[]; + devicetypelist: devicecodeType[]=[]; hide = true; addmoredetals: any[] = []; shownomore: any[] = []; @@ -31,17 +33,15 @@ export class AddDevicesComponent { public showSeconds = false; public touchUi = false; public enableMeridian = false; - orglist: any; - // public minDate: moment.Moment; - //public maxDate: moment.Moment; + orglist: OrganizationInformation[]=[]; + public stepHour = 1; public stepMinute = 1; public stepSecond = 1; numberregex: RegExp = /^[0-9]+(\.[0-9]*)?$/ filteredCountryList: Observable[] = []; subscription: Subscription; - filteredOrgList: any[] = []; - //public color: ThemePalette = 'primary'; + filteredOrgList: OrganizationInformation[] = []; orgname: string; orgId: number; offtaker = ['School', 'Education', 'Health Facility', 'Residential', 'Commercial', 'Industrial', 'Public Sector', 'Agriculture', 'Utility', 'Off-Grid Community'] @@ -67,8 +67,6 @@ export class AddDevicesComponent { setTimeout(() => { this.setupCountryAutocomplete(0); - //this.filteredOrgList = this.orglist; - // Call it with the appropriate index }, 1500); } ngOnDestroy() { @@ -82,11 +80,10 @@ export class AddDevicesComponent { if (this.loginuser.role === 'Admin') { this.adminService.GetAllOrganization().subscribe( (data) => { - //@ts-ignore - this.orglist = data.organizations.filter(org => org.organizationType != "Buyer"); - - // const buyerOrganizations = data.filter(org => org.organizationType === "Buyer"); - this.filteredOrgList = this.orglist; + this.orglist = data.organizations.filter( + (org: OrganizationInformation) => org.organizationType !== 'Buyer' + ); + this.filteredOrgList = this.orglist; // Once data is loaded, call any other functions that depend on it this.date = new Date(); @@ -95,9 +92,9 @@ export class AddDevicesComponent { } else if (this.loginuser.role === 'ApiUser') { this.orgService.GetApiUserAllOrganization().subscribe( (data) => { - //@ts-ignore - this.orglist = data.organizations.filter(org => org.organizationType != "Buyer"); - + this.orglist = data.organizations.filter( + (org: OrganizationInformation) => org.organizationType !== 'Buyer' + ); // const buyerOrganizations = data.filter(org => org.organizationType === "Buyer"); this.filteredOrgList = this.orglist; } @@ -120,7 +117,6 @@ export class AddDevicesComponent { }); } selectOrg(event: any) { - //@ts-ignore const selectedCountry = this.orglist.find(option => option.name === event.option.value); if (selectedCountry) { this.orgId = selectedCountry.id; @@ -175,7 +171,7 @@ export class AddDevicesComponent { DisplayList() { this.authService.GetMethod('countrycode/list').subscribe( - (data) => { + (data:any) => { // display list in the console this.countrylist = data; @@ -196,9 +192,7 @@ export class AddDevicesComponent { DisplayfuelList() { this.authService.GetMethod('device/fuel-type').subscribe( - (data) => { - // display list in the console - + (data:any) => { this.fuellist = data; } @@ -207,26 +201,13 @@ export class AddDevicesComponent { DisplaytypeList() { this.authService.GetMethod('device/device-type').subscribe( - (data) => { - // display list in the console - + (data:any) => { this.devicetypelist = data; } ) } - // selectCountry(event: any,i:number) { - // const toppings: any = this.myform.get('devices') as FormArray - // this.subscription = this.filteredCountryList[i].subscribe(options => { - // const selectedCountry = options.find(option => option.country === event.option.value); - // if (selectedCountry) { - // // toppings.value[i].countryCode.setValue(selectedCountry.alpha3); - // toppings.at(i).get('countryCode').setValue(selectedCountry.alpha3); - // //this.deviceForms.controls.map(control => control['countryCode']).setValue(selectedCountry.alpha3); - // } - // }); - // } onSDGBRemoved(topping: string, i: number) { const toppings: any = this.myform.get('devices') as FormArray const sdgb = toppings[i].SDGBenefits.value as string[]; @@ -273,16 +254,14 @@ export class AddDevicesComponent { map(value => this._filter(value || '', index)) ); } - private _filter(value: string, i: number): any[] { + private _filter(value: string, i: number): CountryInfo[] { const filterValue = value.toLowerCase(); const toppings: any = this.myform.get('devices') as FormArray; - if (!(this.countrylist.filter((option: any) => option.country.toLowerCase().includes(filterValue)).length > 0)) { + if (!(this.countrylist.filter((option: CountryInfo) => option.country.toLowerCase().includes(filterValue)).length > 0)) { this.showerror[i] = true; - // toppings.at(i).get('countryCode').setValue(null); } else { this.showerror[i] = false; } - //@ts-ignore return this.countrylist.filter(code => code.country.toLowerCase().includes(filterValue)); } @@ -313,11 +292,7 @@ export class AddDevicesComponent { getCountryCodeControl(index: number): FormControl { return this.deviceForms.at(index).get('countryCodename') as FormControl; } - // private _filter(value: string): any[] { - // const filterValue = value.toLowerCase(); - // //@ts-ignore - // return this.countrylist.filter(code => code.country.toLowerCase().includes(filterValue)); - // } + onSubmit() { const formArray = this.myform.get('devices') as FormArray; @@ -326,19 +301,12 @@ export class AddDevicesComponent { if (this.orgname != null) { element['organizationId'] = this.orgId; } - //@ts-ignore - const selectedCountry = this.countrylist.find(option => option.country === element.countryCodename); - element['countryCode'] = selectedCountry.alpha3; + + const selectedCountry = this.countrylist.find((option:CountryInfo) => option.country === element.countryCodename); + element['countryCode'] = selectedCountry?.alpha3; this.deviceService.Postdevices(element).subscribe({ next: data => { - - // const formGroup = formArray.at(index); - // this.deviceForms.reset(); this.toastrService.success('Added Successfully !!', 'Device! ' + element.externalId); - // formGroup.reset(); - // while (formArray.length > 1) { - // formArray.removeAt(1); - // } const index = deviceArray.indexOf(element); deviceArray.splice(index, 1); diff --git a/src/app/view/device/alldevices/alldevices.component.ts b/src/app/view/device/alldevices/alldevices.component.ts index e002142..f8a9f8f 100644 --- a/src/app/view/device/alldevices/alldevices.component.ts +++ b/src/app/view/device/alldevices/alldevices.component.ts @@ -18,6 +18,8 @@ import { MatDialog, MatDialogRef, MatDialogModule, MAT_DIALOG_DATA } from '@angu import { MatButtonModule } from '@angular/material/button'; import { DeviceDetailsComponent } from '../device-details/device-details.component' import { ToastrService } from 'ngx-toastr'; +import {OrganizationInformation,Device,fulecodeType,devicecodeType,CountryInfo } from '../../../models' + @Component({ selector: 'app-alldevices', templateUrl: './alldevices.component.html', @@ -45,9 +47,9 @@ export class AlldevicesComponent { loginuser: any deviceurl: any; pageSize: number = 20; - countrylist: any; - fuellist: any; - devicetypelist: any; + countrylist: CountryInfo[]=[]; + fuellist: fulecodeType[]=[]; + devicetypelist: devicecodeType[]=[]; fuellistLoaded: boolean = false; devicetypeLoded: boolean = false; countrycodeLoded: boolean = false; @@ -96,27 +98,27 @@ export class AlldevicesComponent { this.FilterForm.addControl('organizationId', this.formBuilder.control('')); this.orgService.GetApiUserAllOrganization().subscribe( (data) => { - //@ts-ignore + this.orglist = data.organizations.filter(org => org.organizationType != "Buyer"); } ); } this.authService.GetMethod('device/fuel-type').subscribe( - (data1) => { + (data1:any) => { this.fuellist = data1; this.fuellistLoaded = true; }); this.authService.GetMethod('device/device-type').subscribe( - (data2) => { + (data2:any) => { this.devicetypelist = data2; this.devicetypeLoded = true; } ); this.authService.GetMethod('countrycode/list').subscribe( - (data3) => { + (data3:any) => { this.countrylist = data3; this.countrycodeLoded = true; @@ -177,14 +179,11 @@ export class AlldevicesComponent { ); } - private _filter(value: any): string[] { + private _filter(value: any): CountryInfo[] { const filterValue = value.toLowerCase(); if (!(this.countrylist.filter((option: any) => option.country.toLowerCase().includes(filterValue)).length > 0)) { this.showerror = true; - // const updatedFormValues = this.FilterForm.value; - // const isAllValuesNull = Object.values(this.FilterForm.value).some((value) => !!value); - // this.isAnyFieldFilled = false; } else { this.showerror = false; } @@ -278,10 +277,10 @@ export class AlldevicesComponent { this.deviceService.GetMyDevices(this.deviceurl, this.FilterForm.value, page).subscribe({ next: data => { this.showlist = true - //@ts-ignore + if (data.devices) { this.loading = false; - //@ts-ignore + this.data = data; this.DisplayList() } @@ -303,13 +302,13 @@ export class AlldevicesComponent { DisplayList() { if (this.fuellistLoaded == true && this.devicetypeLoded == true && this.countrycodeLoded === true) { - //@ts-ignore - this.data.devices.forEach(ele => { - //@ts-ignore + + this.data.devices.forEach((ele:any) => { + ele['fuelname'] = this.fuellist.find((fuelType) => fuelType.code === ele.fuelCode,)?.name; - //@ts-ignore + ele['devicetypename'] = this.devicetypelist.find(devicetype => devicetype.code == ele.deviceTypeCode)?.name; - //@ts-ignore + ele['countryname'] = this.countrylist.find(countrycode => countrycode.alpha3 == ele.countryCode)?.country; }) diff --git a/src/app/view/device/device-details/device-details.component.ts b/src/app/view/device/device-details/device-details.component.ts index 5f2c7ea..56f0971 100644 --- a/src/app/view/device/device-details/device-details.component.ts +++ b/src/app/view/device/device-details/device-details.component.ts @@ -4,16 +4,8 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { DeviceService } from '../../../auth/services/device.service' import { AuthbaseService } from '../../../auth/authbase.service'; import { Observable } from 'rxjs'; -import { Device } from '../../../models/device.model' +import { Device,CountryInfo,fulecodeType,devicecodeType } from '../../../models'; -// export interface Device { -// netId: number -// registry: string -// issuer: string -// rpcNode: string -// rpcNodeFallback: string -// privateIssuer: string -// } @Component({ selector: 'app-device-details', templateUrl: './device-details.component.html', @@ -24,9 +16,9 @@ export class DeviceDetailsComponent { form: FormGroup; id: number; device_details: any = {}; - fuellist: any; - devicetypelist: any - countrylist: any + countrylist: CountryInfo[]=[]; + fuellist: fulecodeType[]=[]; + devicetypelist: devicecodeType[]=[]; loading: boolean = true; value = 0; viewoptionfrom: string; @@ -41,16 +33,16 @@ export class DeviceDetailsComponent { this.id = data.deviceid; this.authService.GetMethod('device/fuel-type').subscribe( - (data1) => { + (data1:any) => { this.fuellist = data1; - // this.fuellistLoaded = true; + }); this.authService.GetMethod('device/device-type').subscribe( - (data2) => { + (data2:any) => { this.devicetypelist = data2; - // this.devicetypeLoded = true; + } ); @@ -58,10 +50,10 @@ export class DeviceDetailsComponent { name: any; ngOnInit(): void { this.authService.GetMethod('countrycode/list').subscribe( - (data3) => { + (data3:any) => { this.countrylist = data3; - // this.countrycodeLoded = true; + } ) setTimeout(() => { @@ -76,11 +68,11 @@ export class DeviceDetailsComponent { this.loading = false; this.device_details = data; this.name = this.device_details.externalId - //@ts-ignore + this.device_details['fuelname'] = this.fuellist.find((fuelType) => fuelType.code === this.device_details.fuelCode)?.name; - //@ts-ignore + this.device_details['devicetypename'] = this.devicetypelist.find(devicetype => devicetype.code == this.device_details.deviceTypeCode)?.name; - //@ts-ignore + this.device_details['countryname'] = this.countrylist.find(countrycode => countrycode.alpha3 == this.device_details.countryCode)?.country; } }, error: err => { diff --git a/src/app/view/device/edit-device/edit-device.component.ts b/src/app/view/device/edit-device/edit-device.component.ts index bd30ff3..d820a81 100644 --- a/src/app/view/device/edit-device/edit-device.component.ts +++ b/src/app/view/device/edit-device/edit-device.component.ts @@ -6,6 +6,8 @@ import { Router, ActivatedRoute } from '@angular/router'; import { ToastrService } from 'ngx-toastr'; import { Observable, Subscription } from 'rxjs'; import { map, startWith } from 'rxjs/operators'; +import { Device,CountryInfo,fulecodeType,devicecodeType } from '../../../models'; + @Component({ selector: 'app-edit-device', templateUrl: './edit-device.component.html', @@ -14,9 +16,9 @@ import { map, startWith } from 'rxjs/operators'; export class EditDeviceComponent implements OnInit { updatedeviceform: FormGroup; - countrylist: any; - fuellist: any; - devicetypelist: any; + countrylist: CountryInfo[]=[]; + fuellist: fulecodeType[]=[]; + devicetypelist: devicecodeType[]=[]; numberregex: RegExp = /[0-9]+(\.[0-9]*){0,1}/; maxDate = new Date(); public date: any; @@ -115,16 +117,14 @@ export class EditDeviceComponent implements OnInit { }, 1000); } - private _filter(value: string): any[] { + private _filter(value: string): CountryInfo[] { const filterValue = value.toLowerCase(); if (!(this.countrylist.filter((option: any) => option.country.toLowerCase().includes(filterValue)).length > 0)) { this.showerror = true; - // toppings.at(i).get('countryCode').setValue(null); } else { this.showerror = false; } - //@ts-ignore return this.countrylist.filter(code => code.country.toLowerCase().includes(filterValue)); } getCountryCodeControl(): FormControl { @@ -142,7 +142,7 @@ export class EditDeviceComponent implements OnInit { DisplayList() { this.authService.GetMethod('countrycode/list').subscribe( - (data1) => { + (data1:any) => { this.countrylist = data1; } ) @@ -157,9 +157,7 @@ export class EditDeviceComponent implements OnInit { DisplayfuelList() { this.authService.GetMethod('device/fuel-type').subscribe( - (data3) => { - // display list in the console - + (data3:any) => { this.fuellist = data3; } @@ -168,9 +166,7 @@ export class EditDeviceComponent implements OnInit { DisplaytypeList() { this.authService.GetMethod('device/device-type').subscribe( - (data4) => { - // display list in the console - + (data4:any) => { this.devicetypelist = data4; } @@ -214,15 +210,13 @@ export class EditDeviceComponent implements OnInit { this.address = data.address; this.latitude = data.latitude; this.longitude = data.longitude; - //@ts-ignore this.countryCode = this.countrylist.find(countrycode => countrycode.alpha3 == data.countryCode)?.country; this.fuelCode = data.fuelCode; this.deviceTypeCode = data.deviceTypeCode; this.capacity = data.capacity; data.SDGBenefits.forEach( (sdgbname: string, index: number) => { - //@ts-ignore - let foundEle = this.sdgblist.find(ele => ele.value.toLowerCase() === sdgbname.toString().toLowerCase()); + let foundEle = this.sdgblist.find((ele:any) => ele.value.toLowerCase() === sdgbname.toString().toLowerCase()); data.SDGBenefits[index] = foundEle.name }); @@ -249,12 +243,10 @@ export class EditDeviceComponent implements OnInit { if (this.updatedeviceform.value.externalId === null) { this.updatedeviceform.removeControl('externalId'); } - //@ts-ignore - const selectedCountry = this.countrylist.find(option => option.country === this.updatedeviceform.value.countryCode); - this.updatedeviceform.value['countryCode'] = selectedCountry.alpha3; + const selectedCountry: CountryInfo|undefined= this.countrylist.find(option => option.country === this.updatedeviceform.value.countryCode); + this.updatedeviceform.value['countryCode'] = selectedCountry?.alpha3; this.deviceService.Patchdevices(this.externalid, this.updatedeviceform.value).subscribe({ next: (data: any) => { - // this.deviceForms.reset(); this.toastrService.success('Updated Successfully !!', 'Device! ' + data.externalId); this.router.navigate(['device/AllList']); }, diff --git a/src/app/view/login/login.component.ts b/src/app/view/login/login.component.ts index e17059d..6ef8a14 100644 --- a/src/app/view/login/login.component.ts +++ b/src/app/view/login/login.component.ts @@ -66,12 +66,9 @@ export class LoginComponent implements OnInit { this.inviteservice.getinvitationByemail().subscribe({ next: data => { const invitationId = data.id - //@ts-ignore - let loginuser = JSON.parse(sessionStorage.getItem('loginuser')); - + let loginuser = JSON.parse(sessionStorage.getItem('loginuser') as any); // Update the role property of the loginuser object with the new value loginuser.role = data.role; - // Save the updated loginuser object back to sessionStorage sessionStorage.setItem('loginuser', JSON.stringify(loginuser)); this.inviteservice.acceptinvitaion(invitationId, { diff --git a/src/app/view/meter-read/addread/addread.component.ts b/src/app/view/meter-read/addread/addread.component.ts index 99f53d8..2219b04 100644 --- a/src/app/view/meter-read/addread/addread.component.ts +++ b/src/app/view/meter-read/addread/addread.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, importProvidersFrom } from '@angular/core'; import { FormGroup, FormBuilder, FormArray, Validators, FormControl } from '@angular/forms'; import { MeterReadService, DeviceService, AdminService, OrganizationService } from '../../../auth/services'; import { AuthbaseService } from '../../../auth/authbase.service' @@ -9,6 +9,7 @@ import { map, startWith } from 'rxjs/operators'; import * as moment from 'moment'; import * as momentTimeZone from 'moment-timezone'; import { getValidmsgTimezoneFormat } from '../../../utils/getTimezone_msg' +import { CountryInfo, OrganizationInformation } from '../../../models' @Component({ selector: 'app-addread', templateUrl: './addread.component.html', @@ -40,9 +41,9 @@ export class AddreadComponent implements OnInit { selectedResult: any; filteredOptions: Observable; filteredexternalIdOptions: Observable; - orglist: any; + orglist: OrganizationInformation[] = []; loginuser: any; - filteredOrgList: any[] = []; + filteredOrgList: OrganizationInformation[] = []; //public color: ThemePalette = 'primary'; orgname: string; orgId: number; @@ -70,21 +71,19 @@ export class AddreadComponent implements OnInit { if (this.loginuser.role === 'Admin') { this.adminService.GetAllOrganization().subscribe( (data) => { - //@ts-ignore - this.orglist = data.organizations.filter(org => org.organizationType != "Buyer"); + this.orglist = data.organizations.filter( + (org: OrganizationInformation) => org.organizationType !== 'Buyer' + ); + this.filteredOrgList = this.orglist; }) } else if (this.loginuser.role === 'ApiUser') { this.orgService.GetApiUserAllOrganization().subscribe( (data) => { - //@ts-ignore - this.orglist = data.organizations.filter(org => org.organizationType != "Buyer"); - // const buyerOrganizations = data.filter(org => org.organizationType === "Buyer"); + this.orglist = data.organizations.filter((org: OrganizationInformation) => org.organizationType != "Buyer"); this.filteredOrgList = this.orglist; - // Once data is loaded, call any other functions that depend on it - // this.date = new Date(); } ); } @@ -104,15 +103,23 @@ export class AddreadComponent implements OnInit { endtimestamp: [null, Validators.required], value: [null, Validators.required], }, { - validators: (control) => { - - if (control.value.starttimestamp > control.value.endtimestamp) { - //@ts-ignore - control.get("endtimestamp").setErrors({ notSame: true }); + validators: (control: FormGroup) => { + const startTimestampControl = control.get('starttimestamp'); + const endTimestampControl = control.get('endtimestamp'); + + if (startTimestampControl && endTimestampControl) { + const startTimestamp = startTimestampControl.value; + const endTimestamp = endTimestampControl.value; + + if (startTimestamp > endTimestamp) { + endTimestampControl.setErrors({ notSame: true }); + } else { + endTimestampControl.setErrors(null); + } } return null; }, - }) + }); this.addreads.push(read); // this.DisplayList(); //this.TimeZoneList(); @@ -144,7 +151,6 @@ export class AddreadComponent implements OnInit { } selectOrg(event: any) { this.showexternaiIdform = true; - //@ts-ignore const selectedCountry = this.orglist.find(option => option.name === event.option.value); if (selectedCountry) { this.orgId = selectedCountry.id; @@ -198,14 +204,13 @@ export class AddreadComponent implements OnInit { _externalIdfilter(value: string): string[] { const filterValue = value.toLowerCase(); - if ((!(this.devicelist.filter((option: any) => option.externalId.toLowerCase().includes(filterValue)).length > 0) && filterValue != '')) { + if ((!(this.devicelist.filter((option: any) => option.externalId.toLowerCase().includes(filterValue)).length > 0) && filterValue != '')) { this.showerror = true; this.showerrorexternalid = true; } else { this.showerror = false; this.showerrorexternalid = false; } - // this.endmaxdate = new Date(); return this.devicelist.filter((option: any) => option.externalId.toLowerCase().includes(filterValue)) } @@ -275,8 +280,7 @@ export class AddreadComponent implements OnInit { this.historyAge = new Date(this.devicecreateddate); this.historyAge.setFullYear(this.historyAge.getFullYear() - 3); - //@ts-ignore - this.timezonedata = this.countrylist.find(countrycode => countrycode.alpha3 == result.countryCode)?.timezones; + this.timezonedata = this.countrylist.find((countrycode:CountryInfo) => countrycode.alpha3 == result.countryCode)?.timezones; this.readForm.controls['timezone'].setValue(null); this.filteredOptions = this.readForm.controls['timezone'].valueChanges.pipe( @@ -343,44 +347,7 @@ export class AddreadComponent implements OnInit { } ) } - // TimeZoneList() { - // this.authService.GetMethod('meter-reads/time-zones').subscribe( - // (data) => { - // // display list in the console - // this.timezonedata = data; - // } - // ) - // } - // ExternaIdonChangeEvent(event: any) { - // this.addreads.reset(); - // this.readForm.controls['type'].setValue(null) - // this.devicecreateddate = event.createdAt; - // this.commissioningDate = event.commissioningDate; - - // this.historyAge = new Date(this.devicecreateddate); - // this.historyAge.setFullYear(this.historyAge.getFullYear() - 3); - // //@ts-ignore - // this.timezonedata = this.countrylist.find(countrycode => countrycode.alpha3 == event.countryCode)?.timezones; - - // this.readForm.controls['timezone'].setValue(null); - // this.filteredOptions = this.readForm.controls['timezone'].valueChanges.pipe( - // startWith(''), - // map(value => this._filter(value || '')), - // ); - - // this.readService.Getlastread(event.externalId).subscribe({ - // next: data => { - - // this.lastreaddate = data.enddate; - // this.lastreadvalue = data.value; - // }, - // error: err => { //Error callback - // console.error('error caught in component', err) - // } - // }) - - // } onChangeEvent(event: any) { if (event === 'Delta' || event === 'Aggregate') { this.endmaxdate = new Date(); @@ -482,8 +449,8 @@ export class AddreadComponent implements OnInit { }, error: (err: { error: { message: string | undefined; }; }) => { //Error callback console.error('error caught in component', err) - //@ts-ignore - let message = getValidmsgTimezoneFormat(err.error.message); + + let message = getValidmsgTimezoneFormat(err.error.message?? 'Someting Wrong'); this.toastrService.error(message, 'error!'); } @@ -502,8 +469,8 @@ export class AddreadComponent implements OnInit { }, error: (err: { error: { message: string | undefined; }; }) => { //Error callback console.error('error caught in component', err) - //@ts-ignore - let message = getValidmsgTimezoneFormat(err.error.message); + + let message = getValidmsgTimezoneFormat(err.error.message?? 'Something Wrong!!'); this.toastrService.error(message, 'error!'); } diff --git a/src/app/view/meter-read/all-metereads/all-metereads.component.ts b/src/app/view/meter-read/all-metereads/all-metereads.component.ts index bbc8d87..9b9ee67 100644 --- a/src/app/view/meter-read/all-metereads/all-metereads.component.ts +++ b/src/app/view/meter-read/all-metereads/all-metereads.component.ts @@ -8,6 +8,7 @@ import { MatBottomSheetRef, MAT_BOTTOM_SHEET_DATA } from '@angular/material/bott import { MeterReadTableComponent } from '../meter-read-table/meter-read-table.component' import { Observable, of } from 'rxjs'; import { map, startWith } from 'rxjs/operators'; +import { OrganizationInformation ,Device} from '../../../models' @Component({ selector: 'app-all-metereads', templateUrl: './all-metereads.component.html', @@ -44,11 +45,11 @@ export class AllMetereadsComponent implements OnInit { autocompleteResults: any[] = []; // searchControl: FormControl = new FormControl(); filteredResults: Observable; - filteredOrgList: any[] = []; + filteredOrgList: OrganizationInformation[] = []; //public color: ThemePalette = 'primary'; orgname: any; orgId: any; - orglist: any; + orglist: OrganizationInformation[]=[]; showerrorexternalid: boolean = false; showerror: boolean; filteredexternalIdOptions: Observable; @@ -70,15 +71,15 @@ export class AllMetereadsComponent implements OnInit { if (this.loginuser.role === 'Admin') { this.adminService.GetAllOrganization().subscribe( (data) => { - //@ts-ignore - this.orglist = data.organizations.filter(org => org.organizationType == "Developer" && org.api_user_id ==this.apiuserId); + + this.orglist = data.organizations.filter((org:OrganizationInformation) => org.organizationType == "Developer" && org.api_user_id ==this.apiuserId); this.filteredOrgList = this.orglist; }) } else if (this.loginuser.role === 'ApiUser') { this.orgService.GetApiUserAllOrganization().subscribe( (data) => { - //@ts-ignore - this.orglist = data.organizations.filter(org => org.organizationType != "Buyer"); + + this.orglist = data.organizations.filter((org:OrganizationInformation) => org.organizationType != "Buyer"); // const buyerOrganizations = data.filter(org => org.organizationType === "Buyer"); this.filteredOrgList = this.orglist; @@ -112,16 +113,13 @@ export class AllMetereadsComponent implements OnInit { }, 2000); } filterOrgList() { - this.filteredOrgList = this.orglist.filter((org: any) => { + this.filteredOrgList = this.orglist.filter((org: OrganizationInformation) => { return org.name.toLowerCase().includes(this.orgname.toLowerCase()); - - }); } selectOrg(event: any) { - //@ts-ignore const selectedCountry = this.orglist.find(option => option.name === event.option.value); if (selectedCountry) { this.filteredexternalIdOptions = of([]); @@ -179,24 +177,21 @@ export class AllMetereadsComponent implements OnInit { } } - _externalIdfilter(value: string): string[] { - + _externalIdfilter(value: string | Device): Device[] { let filterValue:any; if(typeof value ==='string'){ filterValue = value.toLowerCase(); }else{ - //@ts-ignore filterValue = value.externalId.toLowerCase(); } - if ((!(this.devicelist.filter((option: any) => option.externalId.toLowerCase().includes(filterValue)).length > 0) && filterValue != '')) { + if ((!(this.devicelist.filter((option: Device) => option.externalId.toLowerCase().includes(filterValue)).length > 0) && filterValue != '')) { this.showerror = true; this.showerrorexternalid = true; } else { this.showerror = false; this.showerrorexternalid = false; } - // this.endmaxdate = new Date(); - return this.devicelist.filter((option: any) => option.externalId.toLowerCase().includes(filterValue)) + return this.devicelist.filter((option: Device) => option.externalId.toLowerCase().includes(filterValue)) } @@ -210,9 +205,7 @@ export class AllMetereadsComponent implements OnInit { this.showerror = false; this.showerrorexternalid = false; } - // this.endmaxdate = new Date(); return this.devicelist.filter((option: any) => option.developerExternalId.toLowerCase().includes(filterValue)) - } search(): void { const input = this.FilterForm.controls['externalId'].value; diff --git a/src/app/view/myreservation/myreservation.component.ts b/src/app/view/myreservation/myreservation.component.ts index f53264b..066e177 100644 --- a/src/app/view/myreservation/myreservation.component.ts +++ b/src/app/view/myreservation/myreservation.component.ts @@ -2,7 +2,7 @@ import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; import { SelectionModel } from '@angular/cdk/collections'; import { MediaMatcher } from '@angular/cdk/layout'; -import { Component, OnInit, ViewChild, ViewChildren, QueryList, ChangeDetectorRef, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; +import { Component, OnInit, ViewChild, ViewChildren, QueryList, ChangeDetectorRef, CUSTOM_ELEMENTS_SCHEMA, importProvidersFrom } from '@angular/core'; // import { NavItem } from './nav-item'; import { MatTableDataSource, MatTable } from '@angular/material/table'; import { animate, state, style, transition, trigger } from '@angular/animations'; @@ -15,6 +15,7 @@ import { Observable, Subscription, take, debounceTime } from 'rxjs'; import { map, startWith } from 'rxjs/operators'; import { ToastrService } from 'ngx-toastr'; import { AnyCatcher } from 'rxjs/internal/AnyCatcher'; +import {fulecodeType,devicecodeType,CountryInfo} from '../../models' @Component({ selector: 'app-myreservation', @@ -118,8 +119,6 @@ export class MyreservationComponent implements OnInit { this.FilterForm.addControl('organizationId', this.formBuilder.control('')); this.orgService.GetApiUserAllOrganization().subscribe( (data) => { - - //@ts-ignore this.orglist = data.organizations.filter(org => org.organizationType != "Developer"); if (this.orglist.length > 0) { this.applyorgFilter(); @@ -311,8 +310,8 @@ export class MyreservationComponent implements OnInit { this.showdevicesinfo = false; this.data = data.groupedData; - //@ts-ignore - this.data.forEach(ele => { + + this.data.forEach((ele:any) => { if (ele.deviceIds != null) { ele['numberOfdevices'] = ele.deviceIds.length; @@ -335,7 +334,6 @@ export class MyreservationComponent implements OnInit { } else { if (this.FilterForm.value.reservationActive === "All") { this.FilterForm.removeControl('reservationActive'); - //this.FilterForm.controls['reservationActive'].setValue(null); } if (!(this.FilterForm.value.reservationStartDate != null && this.FilterForm.value.reservationEndDate === null)) { @@ -344,8 +342,7 @@ export class MyreservationComponent implements OnInit { this.showdevicesinfo = false; this.data = data.groupedData; - //@ts-ignore - this.data.forEach(ele => { + this.data.forEach((ele:any) => { if (ele.deviceIds != null) { ele['numberOfdevices'] = ele.deviceIds.length; @@ -378,27 +375,17 @@ export class MyreservationComponent implements OnInit { } DisplayDeviceList(row: any) { - //this.FilterForm.reset(); this.showdevicesinfo = true; - this.group_info = row; - // this.reservationsstatus=row.reservationActivethis, - - // this.reservationstart= "start from "+row.reservationStartDate+ " To "+row. reservationEndDate - this.DevicesList = []; - //@ts-ignore - row.deviceIds.forEach(ele => { + this.DevicesList = []; + row.deviceIds.forEach((ele:any) => { this.authService.GetMethod('device/' + ele).subscribe( (data) => { this.data = data; - // this.data.forEach(ele => { - //@ts-ignore - this.data['fuelname'] = this.fuellist.find((fuelType) => fuelType.code === this.data.fuelCode)?.name; - //@ts-ignore - this.data['devicetypename'] = this.devicetypelist.find(devicetype => devicetype.code == this.data.deviceTypeCode)?.name; - //@ts-ignore - this.data['countryname'] = this.countrylist.find(countrycode => countrycode.alpha3 == this.data.countryCode)?.country; + this.data['fuelname'] = this.fuellist.find((fuelType:fulecodeType) => fuelType.code === this.data.fuelCode)?.name; + this.data['devicetypename'] = this.devicetypelist.find((devicetype:devicecodeType) => devicetype.code == this.data.deviceTypeCode)?.name; + this.data['countryname'] = this.countrylist.find((countrycode:CountryInfo) => countrycode.alpha3 == this.data.countryCode)?.country; // }) this.DevicesList.push(data) this.dataSource1 = new MatTableDataSource(this.DevicesList); diff --git a/src/app/view/organization/admin-organization/admin-organization.component.ts b/src/app/view/organization/admin-organization/admin-organization.component.ts index 63eaacf..c5a69c3 100644 --- a/src/app/view/organization/admin-organization/admin-organization.component.ts +++ b/src/app/view/organization/admin-organization/admin-organization.component.ts @@ -2,7 +2,6 @@ import { FormBuilder, FormGroup, FormControl } from '@angular/forms'; import { SelectionModel } from '@angular/cdk/collections'; import { MediaMatcher } from '@angular/cdk/layout'; import { Component, OnInit, ViewChild, ViewChildren, QueryList, ChangeDetectorRef } from '@angular/core'; -// import { NavItem } from './nav-item'; import { MatTableDataSource, MatTable } from '@angular/material/table'; import { animate, state, style, transition, trigger } from '@angular/animations'; import { MatSort } from '@angular/material/sort'; @@ -13,7 +12,7 @@ import { Router, ActivatedRoute } from '@angular/router'; import { Observable, Subscription, debounceTime } from 'rxjs'; import { map, startWith } from 'rxjs/operators'; import { MatDialog, MatDialogRef } from '@angular/material/dialog'; -// import { DeviceDetailsComponent } from '../device-details/device-details.component' +import {OrganizationInformation,fulecodeType,devicecodeType,CountryInfo} from '../../../models' @Component({ selector: 'app-admin-organization', templateUrl: './admin-organization.component.html', @@ -24,7 +23,6 @@ export class AdminOrganizationComponent { dataFromDialog: any; displayedColumns = [ 'name', - // 'orgemail', 'type', 'status', 'no of users', @@ -37,10 +35,10 @@ export class AdminOrganizationComponent { loginuser: any deviceurl: any; pageSize: number = 20; - countrylist: any; - fuellist: any; - orglist: any; - devicetypelist: any; + countrylist: CountryInfo[]=[]; + fuellist: fulecodeType[]=[]; + orglist: OrganizationInformation[]=[]; + devicetypelist: devicecodeType[]=[]; fuellistLoaded: boolean = false; devicetypeLoded: boolean = false; countrycodeLoded: boolean = false; @@ -78,8 +76,7 @@ export class AdminOrganizationComponent { if (this.loginuser.role === 'Admin') { this.adminService.GetAllOrganization().subscribe( (data) => { - //@ts-ignore - this.orglist =data.organizations.filter(org => org.organizationType != "ApiUser"); + this.orglist =data.organizations.filter((org:OrganizationInformation) => org.organizationType != "ApiUser"); this.orglistload = true; }); @@ -92,7 +89,6 @@ export class AdminOrganizationComponent { }); } - setTimeout(() => { this.loading = false; if (this.loginuser.role === 'Admin') { @@ -101,7 +97,6 @@ export class AdminOrganizationComponent { else if (this.loginuser.role === 'ApiUser') { this.getApiuserAllOrganization(this.p); } - if (this.orglistload) { this.applyorgFilter(); } @@ -122,25 +117,19 @@ export class AdminOrganizationComponent { ); } - private _filter(value: any): string[] { + private _filter(value: any): OrganizationInformation[] { const filterValue = value.toLowerCase(); - if (!(this.orglist.filter((option: any) => option.name.toLowerCase().includes(filterValue)).length > 0)) { + if (!(this.orglist.filter((option: OrganizationInformation) => option.name.toLowerCase().includes(filterValue)).length > 0)) { this.showerror = true; - // const updatedFormValues = this.FilterForm.value; - // const isAllValuesNull = Object.values(this.FilterForm.value).some((value) => !!value); - // this.isAnyFieldFilled = false; } else { this.showerror = false; } - return this.orglist.filter((option: any) => option.name.toLowerCase().indexOf(filterValue.toLowerCase()) === 0); - + return this.orglist.filter((option: OrganizationInformation) => option.name.toLowerCase().indexOf(filterValue.toLowerCase()) === 0); } - selectOrg(event: any) { - + selectOrg(event: any) { this.subscription = this.filteredOptions.subscribe(options => { - const selectedorg = options.find(option => option.name === event.option.value); if (selectedorg) { this.FilterForm.controls['organizationName'].setValue(selectedorg.name); @@ -150,28 +139,20 @@ export class AdminOrganizationComponent { reset() { this.FilterForm.reset(); this.p = 1 - // this.FilterForm.controls['organizationName'].setValue(null); this.loading = true; - // this.applyorgFilter(); this.getAllOrganization(this.p); } getAllOrganization(page: number) { - //this.FilterForm.controls['pagenumber'].setValue(page); const limit = 20; this.adminService.GetAllOrganization(page, limit, this.FilterForm.value).subscribe( (data) => { this.showlist = true this.loading = false; - //@ts-ignore - this.data = data;//.filter(ele => ele.organizationType === 'Developer'); - - //@ts-ignore - this.dataSource = new MatTableDataSource(this.data.organizations.filter(org => org.organizationType != "ApiUser")); + this.data = data; + this.dataSource = new MatTableDataSource(this.data.organizations.filter((org:OrganizationInformation) => org.organizationType != "ApiUser")); this.totalRows = this.data.totalCount - this.totalPages = this.data.totalPages - // this.dataSource.paginator = this.paginator; this.dataSource.sort = this.sort; }, error => { this.data = []; @@ -180,21 +161,15 @@ export class AdminOrganizationComponent { ) } getApiuserAllOrganization(page: number) { - //this.FilterForm.controls['pagenumber'].setValue(page); const limit = 20; this.orgService.GetApiUserAllOrganization(page, limit, this.FilterForm.value).subscribe( (data) => { - this.showlist = true this.loading = false; - //@ts-ignore - this.data = data;//.filter(ele => ele.organizationType === 'Developer'); - + this.data = data; this.dataSource = new MatTableDataSource(this.data.organizations); this.totalRows = this.data.totalCount - this.totalPages = this.data.totalPages - // this.dataSource.paginator = this.paginator; this.dataSource.sort = this.sort; }, error => { this.data = []; diff --git a/src/app/view/organization/user-invitation/user-invitation.component.ts b/src/app/view/organization/user-invitation/user-invitation.component.ts index 95eaee0..6da95ee 100644 --- a/src/app/view/organization/user-invitation/user-invitation.component.ts +++ b/src/app/view/organization/user-invitation/user-invitation.component.ts @@ -7,6 +7,8 @@ import { MatSort } from '@angular/material/sort'; import { MatPaginator, PageEvent } from '@angular/material/paginator'; import { MatTableDataSource, MatTable } from '@angular/material/table'; import { MatTabGroup } from '@angular/material/tabs'; +import {OrganizationInformation,fulecodeType,devicecodeType,CountryInfo} from '../../../models' + @Component({ selector: 'app-user-invitation', templateUrl: './user-invitation.component.html', @@ -30,7 +32,6 @@ export class UserInvitationComponent { loading: boolean = false; emailregex: RegExp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ orgtype: any[] = [ - // { value: 'OrganizationAdmin', viewValue: 'Developer' }, { value: 'DeviceOwner', viewValue: 'DeviceOwner' }, { value: 'User', viewValue: 'User' } ]; @@ -41,11 +42,10 @@ export class UserInvitationComponent { { value: 'User', viewValue: 'User' } ]; loginuser: any; - filteredOrgList: any[] = []; - //public color: ThemePalette = 'primary'; + filteredOrgList: OrganizationInformation[] = []; orgname: string; orgId: number; - orglist: any; + orglist: OrganizationInformation[]=[]; constructor(private fb: FormBuilder, private adminService: AdminService, private router: Router, @@ -63,14 +63,8 @@ export class UserInvitationComponent { if (this.loginuser.role === 'ApiUser') { this.orgService.GetApiUserAllOrganization().subscribe( (data) => { - //@ts-ignore - this.orglist = data.organizations.filter(org => org.organizationType != "Buyer"); - - // const buyerOrganizations = data.filter(org => org.organizationType === "Buyer"); - this.filteredOrgList = this.orglist; - // Once data is loaded, call any other functions that depend on it - - + this.orglist = data.organizations.filter((org:OrganizationInformation) => org.organizationType != "Buyer"); + this.filteredOrgList = this.orglist; } ); } @@ -91,12 +85,11 @@ export class UserInvitationComponent { } filterOrgList() { - this.filteredOrgList = this.orglist.filter((org: any) => { + this.filteredOrgList = this.orglist.filter((org: OrganizationInformation) => { return org.name.toLowerCase().includes(this.orgname.toLowerCase()); }); } selectOrg(event: any) { - //@ts-ignore const selectedCountry = this.orglist.find(option => option.name === event.option.value); if (selectedCountry) { this.orgId = selectedCountry.id; @@ -135,9 +128,7 @@ export class UserInvitationComponent { } getorginviteuserlist() { - this.orgService.getOrganizationInformation().subscribe((data) => { - - //@ts-ignore + this.orgService.getOrganizationInformation().subscribe((data:any) => { this.orginviteuser = data.invitations this.dataSource1 = new MatTableDataSource(this.orginviteuser); diff --git a/src/app/view/permission/add-userpermission/add-userpermission.component.ts b/src/app/view/permission/add-userpermission/add-userpermission.component.ts index bb0abe3..7ea0251 100644 --- a/src/app/view/permission/add-userpermission/add-userpermission.component.ts +++ b/src/app/view/permission/add-userpermission/add-userpermission.component.ts @@ -78,22 +78,20 @@ export class UserpermissionComponent { }) - //@ts-ignore this.dataSource1 = new MatTableDataSource([]); this.aclpermissionServcie.getAcl_moduleList().subscribe({ next: (data) => { const permissionFormArray = this.UserPermissionForm.get('permissions') as FormArray; - //@ts-ignore - data.forEach(permission => { + data.forEach((permission:any) => { permission.selectedPermissions = []; // Initialize with empty strings permissionFormArray.push(this.createPermissionFormGroup(permission)); }); - //@ts-ignore - this.dataSource1.data = this.UserPermissionForm.get('permissions').value; + + this.dataSource1.data = this.UserPermissionForm.get('permissions')?.value ?? [];; }, error: (err) => { - // Handle the error + this.toastrService.error(err.error.message??'Permission Not found') }, }); } @@ -112,10 +110,9 @@ export class UserpermissionComponent { this.aclpermissionServcie.getUserAcl_modulePermissionList().subscribe({ next: data => { this.userdatalist = data - //@ts-ignore - this.userdatalist = data.filter(permission => permission.entityType != "User"); - //@ts-ignore - this.userdatalist.forEach(ele => { + + this.userdatalist = data.filter((permission:any) => permission.entityType != "User"); + this.userdatalist.forEach((ele:any) => { if (ele.entityType === 'Role') { ele['user_role'] = this.rolelist.find((rolename: any) => rolename.id === ele.entityId,)?.name; diff --git a/src/app/view/permission/api-user-permission/api-user-permission.component.ts b/src/app/view/permission/api-user-permission/api-user-permission.component.ts index 3599fe8..a4a1b42 100644 --- a/src/app/view/permission/api-user-permission/api-user-permission.component.ts +++ b/src/app/view/permission/api-user-permission/api-user-permission.component.ts @@ -105,19 +105,10 @@ export class ApiUserPermissionComponent { }) } - // setTimeout(() => { - // // if (this.countrycodeLoded) { - // this.applyorgFilter(); - // // } - // this.loading = false; - // //this.getAllUserspermission(this.p); - // }, 2000) - } async getapiUser(){ this.userId = this.loginuser.id; this.showuserdetails = true; - // let headers:any = await getapiuser_header(); this.userService.userProfile().subscribe({ next: data1 => { this.showclientform = false; @@ -151,13 +142,9 @@ export class ApiUserPermissionComponent { } private _filter(value: any): string[] { - const filterValue = value.toLowerCase(); if (!(this.apiuserlist.filter((option: any) => option.firstName.toLowerCase().includes(filterValue)).length > 0)) { this.showerror = true; - // const updatedFormValues = this.FilterForm.value; - // const isAllValuesNull = Object.values(this.FilterForm.value).some((value) => !!value); - // this.isAnyFieldFilled = false; } else { this.showerror = false; } @@ -165,24 +152,14 @@ export class ApiUserPermissionComponent { } selectOrg(event: any) { - // this.subscription = this.filteredOptions.subscribe(options => { - // const selectedorg = options.find(option => option.id === event.option.value); - // if (selectedorg) { this.fromselectid = true; - // this.FilterForm.controls['user_id'].setValue(selectedorg.id); - // this.FilterForm.controls['organizationName'].setValue(selectedorg.firstName); - // } - // }); } reset() { this.FilterForm.reset(); this.FilterForm.controls['organizationName'].setValue(null); this.FilterForm.controls['user_id'].setValue(null); - // this.loading = true; - // this.applyorgFilter(); this.showlist = false; - // this.getAllUserspermission(this.p); } submit() { @@ -202,29 +179,18 @@ export class ApiUserPermissionComponent { const limit = 20; this.loading = true if (this.loginuser.role === "Admin") { - this.userpermissionService.getUserpermission(this.FilterForm.value).subscribe((data) => { - this.loading = false if (data.length > 0) { this.showorg = true; - this.showlist = true - - //@ts-ignore - this.data = data;//.filter(ele => ele.organizationType === 'Developer'); - + this.data = data; this.dataSource = new MatTableDataSource(this.data); - this.totalRows = this.data.totalCount - + this.totalRows = this.data.totalCount this.totalPages = this.data.totalPages } - }) - - - } else if (this.loginuser.role === "ApiUser") { - + } else if (this.loginuser.role === "ApiUser") { const data = { user_id: this.userId } @@ -232,21 +198,13 @@ export class ApiUserPermissionComponent { this.loading = false if (data.length > 0) { - //this.showorg = true; - - this.showlist = true - - //@ts-ignore - this.data = data;//.filter(ele => ele.organizationType === 'Developer'); - + this.showlist = true; + this.data = data; this.dataSource = new MatTableDataSource(this.data); - this.totalRows = this.data.totalCount - + this.totalRows = this.data.totalCount this.totalPages = this.data.totalPages } - }) - } } @@ -260,15 +218,12 @@ export class ApiUserPermissionComponent { }); confirmDialog.afterClosed().subscribe(result => { if (result === true) { - // this.employeeList = this.employeeList.filter(item => item.employeeId !== employeeObj.employeeId); - //this.deleteDevice(device.id) this.getuserinfo(); } }); } UpdatePermission(row:number){ - const dialogRef = this.dialog.open(EditPermissionComponent, { data: { upatefor: 'User ', diff --git a/src/app/view/permission/apiuser-permission-form/apiuser-permission-form.component.ts b/src/app/view/permission/apiuser-permission-form/apiuser-permission-form.component.ts index 8c0c238..ef290c4 100644 --- a/src/app/view/permission/apiuser-permission-form/apiuser-permission-form.component.ts +++ b/src/app/view/permission/apiuser-permission-form/apiuser-permission-form.component.ts @@ -28,23 +28,18 @@ export class ApiuserPermissionFormComponent { this.form = this.fb.group({ - // client_id:[null, Validators.required], - // client_secret:[null, Validators.required], permissions: this.fb.array([]), }); - //@ts-ignore this.dataSource = new MatTableDataSource([]); this.aclpermissionServcie.getAcl_moduleList().subscribe({ next: (data) => { const permissionFormArray = this.form.get('permissions') as FormArray; - //@ts-ignore - data.forEach(permission => { + data.forEach((permission:any) => { permission.selectedPermissions = []; // Initialize with empty strings permissionFormArray.push(this.createPermissionFormGroup(permission)); }); - //@ts-ignore - this.dataSource.data = this.form.get('permissions').value; + this.dataSource.data = this.form.get('permissions')?.value ?? []; }, error: (err) => { // Handle the error @@ -148,20 +143,5 @@ export class ApiuserPermissionFormComponent { row.selectedPermissions = []; // Clear selected permissions for the deselected row } } - - // getSelectedPermissions(module: any): string { - // return module.permissions - // //@ts-ignore - // .filter((_, i) => module.selectedPermissions[i]) - // .join(', '); - // } - - // getPermissionControls(permissions: string[]): { [key: string]: any } { - // const permissionControls = {}; - // permissions.forEach(permission => { - // //@ts-ignore - // permissionControls[permission] = false; - // }); - // return permissionControls; - // } + } diff --git a/src/app/view/redemption-report/redemption-report.component.ts b/src/app/view/redemption-report/redemption-report.component.ts index 541e673..09b21df 100644 --- a/src/app/view/redemption-report/redemption-report.component.ts +++ b/src/app/view/redemption-report/redemption-report.component.ts @@ -6,6 +6,7 @@ import { MatPaginator } from '@angular/material/paginator'; import { ReservationService } from '../../auth//services/reservation.service'; import { Router } from '@angular/router'; import { AuthbaseService } from '../../auth/authbase.service'; +import {fulecodeType,devicecodeType,CountryInfo}from '../../models' @Component({ selector: 'app-redemption-report', templateUrl: './redemption-report.component.html', @@ -20,25 +21,19 @@ export class RedemptionReportComponent implements OnInit { 'compliance', 'country', 'fuelCode', - // 'commissioningDateRange', "beneficiary", "beneficiary_address", "claimCoiuntryCode", 'capacityRange', "purpose", 'offTakers', - // 'sectors', - // 'standardCompliance', - // 'installations' - ]; pageSize: number = 20; @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; dataSource: MatTableDataSource; - - countrylist: any; - fuellist: any; + countrylist:CountryInfo[]=[]; + fuellist: fulecodeType[]=[]; offtaker = ['School','Education','Health Facility', 'Residential', 'Commercial', 'Industrial', 'Public Sector', 'Agriculture','Utility','Off-Grid Community'] @@ -53,7 +48,7 @@ export class RedemptionReportComponent implements OnInit { DisplayfuelList() { this.authService.GetMethod('device/fuel-type').subscribe( - (data) => { + (data:any) => { this.fuellist = data; } @@ -62,7 +57,7 @@ export class RedemptionReportComponent implements OnInit { DisplaycountryList() { this.authService.GetMethod('countrycode/list').subscribe( - (data) => { + (data:any) => { this.countrylist = data; @@ -74,45 +69,29 @@ export class RedemptionReportComponent implements OnInit { (data) => { this.data = data; - //@ts-ignore - this.data.forEach(ele => { + this.data.forEach((ele:any) => { if (ele.fuelCode != '') { let fuelname: any = []; - //@ts-ignore - let f = ele.fuelCode.filter((str) => str !== ' '); - //@ts-ignore - f.map((aele) => - //@ts-ignore + let f = ele.fuelCode.filter((str:any) => str !== ' '); + f.map((aele:any) => fuelname.push(this.fuellist.find((fuelType) => fuelType.code === aele.trim())?.name) ) ele['fuelname'] = [...new Set(fuelname)].toString(); - - // fuelname.filter((item,index) => fuelname.indexOf(item) === index);; - } else { ele['fuelname'] = ''; } - // @ts-ignore - ele.country.filter((str) => str !== ''); + ele.country.filter((str:any) => str !== ''); if (ele.country != '') { - - // @ts-ignore - ele['countryname'] = [... new Set(ele.country.map((bele) => (this.countrylist.find(countrycode => countrycode.alpha3 === bele.trim())?.country)))].toString(); + ele['countryname'] = [... new Set(ele.country.map((bele:any) => (this.countrylist.find((countrycode:CountryInfo) => countrycode.alpha3 === bele.trim())?.country)))].toString(); } else { ele['countryname'] = ''; } + ele['claimCoiuntryCode'] = this.countrylist.find((countrycode:CountryInfo) => countrycode.alpha3 === ele.claimCoiuntryCode)?.country; - //@ts-ignore - ele['claimCoiuntryCode'] = this.countrylist.find(countrycode => countrycode.alpha3 === ele.claimCoiuntryCode)?.country; - //@ts-ignore - // ele.offTakers.filter((str) => str !== ' '); - //@ts-ignore - let o = ele.offTakers.filter((str) => str !== ' '); - //@ts-ignore - ele['offTakername'] = [...new Set(o.map((e) => e.trim()))].toString() - //[... new Set(ele.offTakers)].toString(); + let o = ele.offTakers.filter((str:any) => str !== ' '); + ele['offTakername'] = [...new Set(o.map((e:any) => e.trim()))].toString() }) diff --git a/src/app/view/register/register.component.ts b/src/app/view/register/register.component.ts index 9d1308e..d3d5ec4 100644 --- a/src/app/view/register/register.component.ts +++ b/src/app/view/register/register.component.ts @@ -57,16 +57,15 @@ export class RegisterComponent implements OnInit { }, { validators: (control) => { - - if (control.value.password !== control.value.confirmPassword) { - //@ts-ignore - control.get("confirmPassword").setErrors({ notSame: true }); + const password = control.get("password")?.value; + const confirmPassword = control.get("confirmPassword")?.value; + + if (password !== null && confirmPassword !== null && password !== confirmPassword) { + control.get("confirmPassword")?.setErrors({ notSame: true }); } return null; - }, - } - ); - + }, + }); } emaiErrors() { diff --git a/src/app/view/reset-password/reset-password.component.ts b/src/app/view/reset-password/reset-password.component.ts index a572d7f..bf737c1 100644 --- a/src/app/view/reset-password/reset-password.component.ts +++ b/src/app/view/reset-password/reset-password.component.ts @@ -18,13 +18,14 @@ export class ResetPasswordComponent { }, { validators: (control) => { - - if (control.value.newPassword != control.value.confirmPassword) { - //@ts-ignore - control.get("confirmPassword").setErrors({ notSame: true }); + const newPassword = control.get("newPassword")?.value; + const confirmPassword = control.get("confirmPassword")?.value; + + if (newPassword !== null && confirmPassword !== null && newPassword !== confirmPassword) { + control.get("confirmPassword")?.setErrors({ notSame: true }); } return null; - }, + }, } ); hide = true; diff --git a/src/app/view/user-profile/user-profile.component.ts b/src/app/view/user-profile/user-profile.component.ts index bbd3bc4..06e732d 100644 --- a/src/app/view/user-profile/user-profile.component.ts +++ b/src/app/view/user-profile/user-profile.component.ts @@ -47,7 +47,7 @@ export class UserProfileComponent { this.email = this.userinfo.email // this.status = this, this.userinfo.status }); - + } ngOnInit() { this.updateForm = this.fb.group({ @@ -64,10 +64,11 @@ export class UserProfileComponent { }, { validators: (control) => { + const newPassword = control.get("newPassword")?.value; + const confirmPassword = control.get("confirmPassword")?.value; - if (control.value.newPassword !== control.value.confirmPassword) { - //@ts-ignore - control.get("confirmPassword").setErrors({ notSame: true }); + if (newPassword !== null && confirmPassword !== null && newPassword !== confirmPassword) { + control.get("confirmPassword")?.setErrors({ notSame: true }); } return null; }, @@ -108,19 +109,19 @@ export class UserProfileComponent { onUpdate() { this.userService.updatProfile(this.updateForm.value). - subscribe({ - next: data => { - this.toastrService.success("User Updated", "Successful") - //this.dialogRef.close(); + subscribe({ + next: data => { + this.toastrService.success("User Updated", "Successful") + //this.dialogRef.close(); - }, error: err => { - this.updateForm.reset(); + }, error: err => { + this.updateForm.reset(); - this.updateForm.patchValue(this.userinfo); + this.updateForm.patchValue(this.userinfo); - this.toastrService.error(err.error.message, "Error") - } - }) + this.toastrService.error(err.error.message, "Error") + } + }) } onResetPasswordUpdate() { diff --git a/src/app/view/yieldconfiguration/all-country-yieldvalue/all-country-yieldvalue.component.ts b/src/app/view/yieldconfiguration/all-country-yieldvalue/all-country-yieldvalue.component.ts index 1c4ae97..f81b29e 100644 --- a/src/app/view/yieldconfiguration/all-country-yieldvalue/all-country-yieldvalue.component.ts +++ b/src/app/view/yieldconfiguration/all-country-yieldvalue/all-country-yieldvalue.component.ts @@ -53,43 +53,17 @@ export class AllCountryYieldvalueComponent { ) setTimeout(() => { - // if (this.countrycodeLoded) { - // this.applycountryFilter(); - // } this.loading = false; this.getCountryyieldListData(); }, 1000) } - // applycountryFilter() { - // this.FilterForm.controls['countryname']; - // this.filteredOptions = this.FilterForm.controls['countryname'].valueChanges.pipe( - // startWith(''), - // map(value => this._filter(value || '')), - // ); - // } - // private _filter(value: any): string[] { - - // const filterValue = value.toLowerCase(); - // if (!(this.countrylist.filter((option: any) => option.country.toLowerCase().includes(filterValue)).length > 0)) { - // this.showerror = true; - - // } else { - // this.showerror = false; - // } - // return this.countrylist.filter((option: any) => option.country.toLowerCase().indexOf(filterValue.toLowerCase()) === 0); - - // } getCountryyieldListData() { - //this.FilterForm.controls['pagenumber'].setValue(page); this.yieldService.getyieldList().subscribe( - (data) => { - - //@ts-ignore + (data:any) => { this.data=data; this.dataSource = new MatTableDataSource(this.data); - this.totalRows = this.data.length - // this.totalPages = this.data.totalPages + this.totalRows = this.data.length; this.dataSource.paginator = this.paginator; this.dataSource.sort = this.sort; } diff --git a/src/global.d.ts b/src/global.d.ts new file mode 100644 index 0000000..1d2cb61 --- /dev/null +++ b/src/global.d.ts @@ -0,0 +1,10 @@ +interface Ethereum { + isMetaMask?: boolean; + request: (args: { method: string, params?: any[] }) => Promise; + on?: (eventName: string, callback: (...args: any[]) => void) => void; + // Add other properties and methods as needed +} + +interface Window { + ethereum?: Ethereum; +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index b2004ba..72f46d7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,6 +27,10 @@ "dom" ] }, + "include": [ + "src", + "global.d.ts" + ], "angularCompilerOptions": { "enableI18nLegacyMessageIdFormat": false, "strictInjectionParameters": true,