Skip to content

Commit

Permalink
Merge pull request #148 from suvarnakale/main
Browse files Browse the repository at this point in the history
#846 - Redirection of certicificate icons to preview - Done
  • Loading branch information
srprasanna authored Oct 27, 2023
2 parents b568a6b + d9b0d53 commit 0525c34
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 42 deletions.
6 changes: 3 additions & 3 deletions src/app/admin/add-template/add-template.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</form> -->

<div class="row d-flex">
<div class="col-12 col-sm-4 card h-card " *ngIf="!fromEdit">
<div class="col-12 col-sm-4 card h-card " *ngIf="!fromEdit && !fromPreview">
<!-- <form [formGroup]="form2" (ngSubmit)="submit()" *ngIf="fields">
<formly-form [model]="model" [fields]="fields" [options]="options" [form]="form2"></formly-form>
</form> -->
Expand Down Expand Up @@ -90,11 +90,11 @@


</div>
<div class=" col-12 col-sm-8 p-sm-0" *ngIf="userHtml" [ngClass]="{'col-sm-12': fromEdit}">
<div class=" col-12 col-sm-8 p-sm-0" *ngIf="userHtml" [ngClass]="{'col-sm-12': fromEdit || fromPreview}">
<div class="card">
<div class="d-flex justify-content-between card-body px-4 py-2">
<div class="heading-2">{{'PREVIEW' | translate}}</div>
<div>
<div *ngIf="fromEdit">
<button class="float-end heading-3 btn bg-color-secondary color-sec fw-bold submit-button" data-toggle="modal" data-target="#deleteDocument" *ngIf="fromEdit"><i
class="fa fa-trash" aria-hidden="true"></i> {{'DELETE_TEMPLATE' | translate}}</button> &nbsp;

Expand Down
85 changes: 49 additions & 36 deletions src/app/admin/add-template/add-template.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export class AddTemplateComponent implements OnInit {
certificateTitle: any;
schemaOsid: any;
vcStep: string;
fromPreview: boolean;
credTemp: any[];
certificateName: any;
constructor(public schemaService: SchemaService,
public toastMsg: ToastMessageService,
private route: ActivatedRoute,
Expand All @@ -72,21 +75,18 @@ export class AddTemplateComponent implements OnInit {
public translate: TranslateService,
public router: Router) { }

ngOnInit(): void {
async ngOnInit() {

this.getDocument();
this.route.queryParams.subscribe(params => {
this.fromEdit = params['fromEdit'] === 'true';
this.certificateIndex = +params['certificateIndex'];

this.fromPreview = params['fromPreview'] === 'true';
this.certificateName = params['certificateName'];
});
if (this.fromEdit) {
this.previewScreen();
}
// this.generalService.getData('/Issuer').subscribe((res) => {
// console.log(res);
// this.issuerOsid = res[0].osid;
// });

this.activeRoute.params.subscribe(params => {
this.params = params;
Expand All @@ -98,16 +98,45 @@ export class AddTemplateComponent implements OnInit {
}
this.schemaService.getEntitySchemaJSON().subscribe((data) => {
let allSteps = data['usecase'][this.usecase]['steps'];
for(let i=0; i<allSteps.length; i++){
if(allSteps[i]['key'] === 'create-vc'){
for (let i = 0; i < allSteps.length; i++) {
if (allSteps[i]['key'] === 'create-vc') {
this.vcStep = i.toString();
}
}
})
});

if (this.fromPreview) {
await this.getCertTemplate();
await this.previewScreen();
}
}

async getCertTemplate() {
this.credTemp = [];

const res = await this.generalService.getData('/Schema').toPromise();
for (let i = 0; i < res.length; i++) {
if (res[i]["name"] === this.entityName) {
const data = JSON.parse(res[i]['schema']);
const certificateTemplate = data["_osConfig"]["certificateTemplates"];

for (const k of Object.keys(certificateTemplate)) {
const CertTitle = k;
const certVal = certificateTemplate[k];
const c = certVal.toString();
const d = c.split("Schema/");

const getHtml = await this.generalService.getText('/Schema/' + d[1]).toPromise();

this.credTemp.push({
"title": CertTitle,
"html": getHtml,
});
}
}
}
}

dataChange() {
window.location.reload();
Expand All @@ -119,37 +148,21 @@ export class AddTemplateComponent implements OnInit {
}

previewScreen() {
// console.log({ doc });
// this.sampleData = doc;


// fetch(doc.schemaUrl)
// .then(response => response.text())
// .then(data => {
// this.schemaContent = data;
// this.userJson = data;
// // Do something with your data
// console.log(this.userJson);
// });

// fetch(doc.certificateUrl)
// .then(response => response.text())
// .then(data => {
// this.certificateContent = data;
// this.userHtml = data;
// this.injectHTML();
// });

// this.isPreview = true;
// localStorage.setItem('isPreview', 'yes');

if (this.fromEdit && this.certificateIndex !== undefined) {
if (this.fromEdit || this.fromPreview && this.certificateIndex !== undefined) {
const credTemp = this.generalService.getCertificateData();
const certificateData = credTemp[this.certificateIndex]['html'];
this.certificateTitle = credTemp[this.certificateIndex]['title'];
if(this.certificateName){
for(let i=0; i < this.credTemp.length; i++){
if(this.credTemp[i].title == this.certificateName){
this.certificateIndex = i;
break;
}
}
}
const certificateData = credTemp ? credTemp[this.certificateIndex]['html'] : this.credTemp[this.certificateIndex]['html'];
this.certificateTitle = credTemp ? credTemp[this.certificateIndex]['title'] : this.credTemp[this.certificateIndex]['title'];
this.userHtml = certificateData;
}
if (!this.fromEdit) {
if (!this.fromEdit && !this.fromPreview) {
this.userHtml = `<html lang="en">
<head>
<style>
Expand Down
4 changes: 2 additions & 2 deletions src/app/admin/configurations/configurations.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ <h3 class="pl-3 h2 text-color">{{'SCHEMA' | translate}}</h3>

<p class="fs-16 fw-bold">{{ item?.name }}</p>
<div class="d-flex align-items-center" *ngFor="let certName of item?.schema?._osConfig?.certificateTemplates | keyvalue">

<img src="{{imgUrl}}" type="button" class="float-left mr-2 img16" alt="" (click)="addVC(item?.name)">
<a id="previewLink" [routerLink]="['/add-template', usecase, item?.name]" [queryParams]="{ fromPreview: true, certificateName: certName.key }"class="ml-1">
<img src="{{imgUrl}}" type="button" class="float-left mr-2 img16" alt="" ></a>
<span class="fs-14 fw-bold" >
{{certName.key}}
</span>
Expand Down
8 changes: 7 additions & 1 deletion src/app/admin/configurations/configurations.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ export class ConfigurationsComponent implements OnInit {
this.router.navigateByUrl('/create/0' + '/' + this.usecase + '/' + this.entityKey);
}
}

previewCertificate(){
const anchorTag = document.getElementById('previewLink');
if (anchorTag) {
anchorTag.click();
}
}
}


0 comments on commit 0525c34

Please sign in to comment.