Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DR-804:convert code base to type script #68

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

import {FormBuilder} from '@angular/forms';

Check failure on line 2 in src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'FormBuilder' is defined but never used

Check failure on line 2 in src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'FormBuilder' is defined but never used
import {SelectionModel} from '@angular/cdk/collections';

Check failure on line 3 in src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'SelectionModel' is defined but never used

Check failure on line 3 in src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'SelectionModel' is defined but never used
import {MediaMatcher} from '@angular/cdk/layout';

Check failure on line 4 in src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'MediaMatcher' is defined but never used

Check failure on line 4 in src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'MediaMatcher' is defined but never used
import {ChangeDetectorRef, Component, OnDestroy} from '@angular/core';

Check failure on line 5 in src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'ChangeDetectorRef' is defined but never used

Check failure on line 5 in src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'OnDestroy' is defined but never used

Check failure on line 5 in src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'ChangeDetectorRef' is defined but never used

Check failure on line 5 in src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'OnDestroy' is defined but never used
// import { NavItem } from './nav-item';
import {MatTableDataSource} from '@angular/material/table';

Check failure on line 6 in src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'MatTableDataSource' is defined but never used

Check failure on line 6 in src/app/app.component.ts

View workflow job for this annotation

GitHub Actions / lint-eslint

'MatTableDataSource' is defined but never used


@Component({
Expand All @@ -15,27 +14,27 @@
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');
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/app/auth/authbase.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
})
Expand Down
6 changes: 2 additions & 4 deletions src/app/auth/services/invitation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,15 @@ 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<any> {
let addUrl = `${this.url}invitation`;
if (organizationId != null || organizationId != undefined) {
addUrl += `?organizationId=${organizationId}`;
}
let newheaders = new HttpHeaders(headers);
//@ts-ignore
return this.httpClient.post<any>(addUrl, data, { headers })

return this.httpClient.post<any>(addUrl, data)

}
public getinvitaion(): Observable<any> {
Expand Down
4 changes: 2 additions & 2 deletions src/app/auth/services/organization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class OrganizationService {

return this.httpClient.get<any>(environment.API_URL+ 'Organization/' + orgId);
}
public GetApiUserAllOrganization(pagenumber?: number, limit?: number, searchData?: any): Observable<any> {
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) {
Expand All @@ -48,7 +48,7 @@ export class OrganizationService {
searchUrl += `&organizationName=${searchData.organizationName}`;
}
}
return this.httpClient.get<any>(searchUrl);
return this.httpClient.get<{ organizations: OrganizationInformation[] }>(searchUrl);
}
public removeUser(userId: number): Observable<any> {

Expand Down
24 changes: 24 additions & 0 deletions src/app/models/Device_type.model.ts
Original file line number Diff line number Diff line change
@@ -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;
}


67 changes: 37 additions & 30 deletions src/app/models/device.model.ts
Original file line number Diff line number Diff line change
@@ -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;
}
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;
}
6 changes: 6 additions & 0 deletions src/app/models/index.ts
Original file line number Diff line number Diff line change
@@ -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'
3 changes: 2 additions & 1 deletion src/app/models/organization.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions src/app/utils/getTimezone_msg.ts
Original file line number Diff line number Diff line change
@@ -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())
})
}
Expand Down
43 changes: 21 additions & 22 deletions src/app/view/add-reservation/add-reservation.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -28,7 +29,6 @@ export class AddReservationComponent {
'projectName',
'externalId',
'countryCode',
// 'fuelCode',
'commissioningDate',
'status',
'viewread'
Expand All @@ -39,13 +39,13 @@ export class AddReservationComponent {
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
dataSource: MatTableDataSource<any>;
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;
Expand All @@ -68,17 +68,15 @@ 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,
private formBuilder: FormBuilder,
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],
Expand All @@ -103,7 +101,6 @@ export class AddReservationComponent {
SDGBenefits: [],
start_date: [null],
end_date: [null],
// pagenumber: [this.p]
});

this.FilterForm.valueChanges.subscribe(() => {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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

}
)
}
Expand Down
12 changes: 1 addition & 11 deletions src/app/view/admin/add-users/add-users.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' :
Expand Down
Loading
Loading