Skip to content

Commit

Permalink
Merge pull request #614 from mayuradesh/newdevelop
Browse files Browse the repository at this point in the history
MOSIP-30508 sonar UI bug
  • Loading branch information
mayuradesh committed Nov 30, 2023
2 parents 6d910a7 + 7e6c813 commit 6dec137
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 155 deletions.
100 changes: 51 additions & 49 deletions src/app/app.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ export default class Utils {
});
}

static getTestcasesForCollection(subscriptions: Subscription[], dataService: DataService, isAdmin: boolean,
static getTestcasesForCollection(subscriptions: Subscription[], dataService: DataService, isAdmin: boolean,
partnerId: string, collectionId: string, resourceBundleJson: any, dialog: MatDialog) {
return new Promise<any[]>((resolve, reject) => {
subscriptions.push(
Expand Down Expand Up @@ -798,15 +798,29 @@ export default class Utils {
});
}

static convertBlobToBase64 = (blob :Blob)=>new Promise ((resolve,reject) =>{
static convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => {
const reader = new FileReader;
reader.onerror = reject;
reader.onload = () =>{
reader.onload = () => {
resolve(reader.result);
};
reader.readAsDataURL(blob);
});

static getReportFromDb(isAdmin: boolean, element: any, request: any, dataService: any) {
return new Promise((resolve, reject) => {
dataService.getReport(isAdmin, element.partnerId, request).subscribe(
(response: any) => {
resolve(response);
},
(errors: any) => {
console.log(errors);
resolve(false);
}
)
});
}

static async getReport(isAndroidAppMode: boolean, isAdmin: boolean, element: any,
dataService: DataService, resourceBundleJson: any, dialog: MatDialog) {
let reportrequest = {
Expand All @@ -822,52 +836,40 @@ export default class Utils {
requesttime: new Date().toISOString(),
request: reportrequest,
};
return new Promise((resolve, reject) => {
dataService
.getReport(isAdmin, element.partnerId, request)
.subscribe(
async (res: any) => {
if (res) {
console.log('isAndroidAppMode' + isAndroidAppMode);
const fileByteArray = res;
var blob = new Blob([fileByteArray], { type: 'application/pdf' });
const base64 = await this.convertBlobToBase64(blob) as string;
const hash = sha256(base64);
console.log(hash.toString());
if (isAndroidAppMode) {
//let fileName = element.projectName + ".pdf";
let fileName = hash + ".pdf";
console.log('ready to download');
await Filesystem.writeFile({
path: fileName,
data: base64,
directory: Directory.Documents
});
Toast.show({
text: 'File has been downloaded to Documents folder: ' + fileName,
}).catch((error) => {
console.log(error);
});
} else {
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = hash;
link.click();
}
} else {
Utils.showErrorMessage(resourceBundleJson,
null,
dialog,
'Unable to download PDF file. Try Again!');
}
resolve(true);
},
(errors) => {
Utils.showErrorMessage(resourceBundleJson, errors, dialog);
resolve(false);
}
);
});
let res: any = await this.getReportFromDb(isAdmin, element, request, dataService);
if (res) {
console.log('isAndroidAppMode' + isAndroidAppMode);
const fileByteArray = res;
var blob = new Blob([fileByteArray], { type: 'application/pdf' });
const base64 = await this.convertBlobToBase64(blob) as string;
const hash = sha256(base64);
console.log(hash.toString());
if (isAndroidAppMode) {
//let fileName = element.projectName + ".pdf";
let fileName = hash + ".pdf";
console.log('ready to download');
await Filesystem.writeFile({
path: fileName,
data: base64,
directory: Directory.Documents
});
Toast.show({
text: 'File has been downloaded to Documents folder: ' + fileName,
}).catch((error) => {
console.log(error);
});
} else {
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = hash;
link.click();
}
} else {
Utils.showErrorMessage(resourceBundleJson,
null,
dialog,
'Unable to download PDF file. Try Again!');
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,15 @@ export class PartnerReportsComponent implements OnInit {
},
});
dialogRef.afterClosed().subscribe(
async (closeBtn: boolean) => {
if (!closeBtn) {
this.dataLoaded = false;
await this.getPartnerReportList();
await this.fetchPartnerReport(element);
this.dataLoaded = true;
}
(closeBtn: boolean) => {
(async () => {
if (!closeBtn) {
this.dataLoaded = false;
await this.getPartnerReportList();
await this.fetchPartnerReport(element);
this.dataLoaded = true;
}
})();
}
);
}
Expand All @@ -216,13 +218,15 @@ export class PartnerReportsComponent implements OnInit {
},
});
dialogRef.afterClosed().subscribe(
async (closeBtn: boolean) => {
if (!closeBtn) {
this.dataLoaded = false;
await this.getPartnerReportList();
await this.fetchPartnerReport(element);
this.dataLoaded = true;
}
(closeBtn: boolean) => {
(async () => {
if (!closeBtn) {
this.dataLoaded = false;
await this.getPartnerReportList();
await this.fetchPartnerReport(element);
this.dataLoaded = true;
}
})();
}
);
}
Expand Down
153 changes: 76 additions & 77 deletions src/app/features/project/view-project/view-project.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,40 +184,34 @@ export class ViewProjectComponent implements OnInit {
}

async getCollections() {
return new Promise((resolve, reject) => {
this.subscriptions.push(
this.dataService
.getCollections(this.projectId, this.projectType)
.subscribe(
async (response: any) => {
const respArr = response[appConstants.RESPONSE]['collections'];
let tableData = [];
for (let item of respArr) {
let disableReportBtn = true;
if (appConstants.COMPLIANCE_COLLECTION == item.collectionType) {
let check = await Utils.isReportAlreadySubmitted(this.projectType, this.projectId, item.collectionId, this.dataService, this.resourceBundleJson, this.dialog);
if (check) {
disableReportBtn = false;
this.isReportAlreadySubmitted = true;
}
}
tableData.push({
...item,
disableReportBtn: disableReportBtn
});
}
this.dataSource = new MatTableDataSource(
tableData
);
resolve(true);
},
(errors) => {
Utils.showErrorMessage(this.resourceBundleJson, errors, this.dialog);
resolve(false);
try {
const response: any = await this.dataService.getCollections(this.projectId, this.projectType).toPromise();
const respArr = response[appConstants.RESPONSE]['collections'];
let tableData = [];
for (let item of respArr) {
let disableReportBtn = true;
if (appConstants.COMPLIANCE_COLLECTION == item.collectionType) {
try {
let check = await Utils.isReportAlreadySubmitted(this.projectType, this.projectId, item.collectionId, this.dataService, this.resourceBundleJson, this.dialog);
if (check) {
disableReportBtn = false;
this.isReportAlreadySubmitted = true;
}
)
);
});
} catch (error) {
console.error('Error checking report submission:', error);
}
}
tableData.push({
...item,
disableReportBtn: disableReportBtn
});
}
this.dataSource = new MatTableDataSource(tableData);
return true;
} catch (errors) {
Utils.showErrorMessage(this.resourceBundleJson, errors, this.dialog);
return false;
}
}

ngOnDestroy(): void {
Expand Down Expand Up @@ -348,53 +342,58 @@ export class ViewProjectComponent implements OnInit {
}
}

downloadEncryptionKey() {
const subs = this.dataService.getEncryptionKey().subscribe(
async (res: any) => {
if (res) {
let obj = res[appConstants.RESPONSE];
if (obj) {
console.log('isAndroidAppMode' + this.isAndroidAppMode);
var blob = new Blob([obj], { type: 'application/json' });
if (this.isAndroidAppMode) {
let fileName = "key.txt";
console.log('ready to download');
const base64 = await Utils.convertBlobToBase64(blob) as string;
await Filesystem.writeFile({
path: fileName,
data: base64,
directory: Directory.Documents
});
Toast.show({
text: 'Encryption key has been downloaded to Documents folder: ' + fileName,
}).catch((error) => {
console.log(error);
});
} else {
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = `key.cer`;
link.click();
}
}
} else {
const err = {
errorCode: 'ENCRYPTION_KEY_001',
message: ''
async downloadEncryptionKey() {
try {
const res: any = await this.dataService.getEncryptionKey().toPromise();

if (res) {
let obj = res[appConstants.RESPONSE];

if (obj) {
console.log('isAndroidAppMode' + this.isAndroidAppMode);

var blob = new Blob([obj], { type: 'application/json' });

if (this.isAndroidAppMode) {
const fileName = "key.txt";
console.log('ready to download');

const base64 = await Utils.convertBlobToBase64(blob) as string;

await Filesystem.writeFile({
path: fileName,
data: base64,
directory: Directory.Documents
});

Toast.show({
text: 'Encryption key has been downloaded to Documents folder: ' + fileName,
}).catch((error) => {
console.log(error);
});
} else {
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = `key.cer`;
link.click();
}
Utils.showErrorMessage(
this.resourceBundleJson,
[err],
this.dialog,
'Unable to get encryption key. Try Again!'
);
}
},
(errors) => {
Utils.showErrorMessage(this.resourceBundleJson, errors, this.dialog);
} else {
const err = {
errorCode: 'ENCRYPTION_KEY_001',
message: ''
};

Utils.showErrorMessage(
this.resourceBundleJson,
[err],
this.dialog,
'Unable to get encryption key. Try Again!'
);
}
);
this.subscriptions.push(subs);
} catch (errors) {
Utils.showErrorMessage(this.resourceBundleJson, errors, this.dialog);
}
}

getDeviceImageUrl() {
Expand Down
6 changes: 3 additions & 3 deletions src/app/features/test-run/test-run/test-run.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ mat-panel-title {
.expanded-details{
width: 700px;
}
testIDHeader{
.testIDHeader{
width: 80px;
}
.testIDCell{
Expand Down Expand Up @@ -204,7 +204,7 @@ mat-panel-title {
.executionStatusCell{
padding-left: 0px;
}
testIDHeader{
.testIDHeader{
width: 80px;
}
.testIDCell{
Expand All @@ -218,7 +218,7 @@ mat-panel-title {
.executionStatusCell{
padding-left: 0px;
}
testIDHeader{
.testIDHeader{
width: 80px;
}
.testIDCell{
Expand Down
Loading

0 comments on commit 6dec137

Please sign in to comment.