Skip to content

Commit

Permalink
Merge pull request #137 from suvarnakale/main
Browse files Browse the repository at this point in the history
#784 - VC template -edit and Delete functionality- Done
  • Loading branch information
Pratikshakhandagale authored Oct 10, 2023
2 parents 183d52f + 9c8f9b9 commit 9f4ce87
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 138 deletions.
31 changes: 28 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 ">
<div class="col-12 col-sm-4 card h-card " *ngIf="!fromEdit">
<!-- <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,13 +90,16 @@


</div>
<div class=" col-12 col-sm-8 p-sm-0" *ngIf="userHtml">
<div class=" col-12 col-sm-8 p-sm-0" *ngIf="userHtml" [ngClass]="{'col-sm-12': fromEdit}">
<div class="card">
<div class="d-flex justify-content-between card-body px-4 py-2">
<div class="heading-2">{{'PREVIEW' | translate}}</div>
<div>
<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;

<button (click)="editTemplate()"
class="float-end heading-3 btn bg-color-secondary color-sec fw-bold submit-button"><i
class="float-end heading-3 btn bg-color-secondary color-sec fw-bold submit-button mr-3"><i
class="fa fa-pencil-square-o" aria-hidden="true"></i> {{'EDIT_TEMPLATE' | translate}}</button>
</div>
</div>
Expand All @@ -122,3 +125,25 @@


</div>

<div class="modal right fade" id="deleteDocument" tabindex="-1" role="dialog"
aria-labelledby="deleteDocument">
<div class="modal-dialog" role="document">
<div class="modal-content d-flex">
<div class="modal-header pt-4 border-0">
<h3 class="heading-5">{{'DELETE_TEMPLATE' | translate}}</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span></button>
</div>
<div class="container mt-1 justify-content-center pb-3">
<p class="heading-4 font-700 mb-05 pl-3">{{ 'DELETE_CONFIRM' | translate}}</p>
<div class="mt-2">
<button (click)="deleteTemplate()" data-dismiss="modal" aria-label="Close"
class="btn text-capitalize float-end btn-danger text-white fw-bold p1">{{'DELETE' | translate}}</button>
<button class="close" data-dismiss="modal" aria-label="Close"
class="btn text-capitalize bg-color-primary text-white fw-bold p1 sb-text-primary mr-2 bg-none">{{'CANCEL' | translate}}</button>
</div>
</div>
</div>
</div>
</div>
81 changes: 69 additions & 12 deletions src/app/admin/add-template/add-template.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { GeneralService } from 'src/app/services/general/general.service';
import { ToastMessageService } from 'src/app/services/toast-message/toast-message.service';
import { SchemaService } from '../../services/data/schema.service';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { TranslateService } from '@ngx-translate/core';
import { TranslateService } from '@ngx-translate/core';

@Component({
selector: 'app-add-template',
Expand Down Expand Up @@ -57,6 +57,11 @@ export class AddTemplateComponent implements OnInit {
params: any;
entityName: any;
usecase: any;
fromEdit: boolean = false;
certificateIndex: number;
certificateTitle: any;
schemaOsid: any;
vcStep: string;
constructor(public schemaService: SchemaService,
public toastMsg: ToastMessageService,
private route: ActivatedRoute,
Expand All @@ -70,23 +75,36 @@ export class AddTemplateComponent implements OnInit {
ngOnInit(): void {

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

});
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;
console.log({params});
console.log({ params });

if (this.params.hasOwnProperty('entity')) {
this.entityName = params.entity;
this.usecase = params.usecase.toLowerCase();


}
});
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'){
this.vcStep = i.toString();
}
}
})
});

}

Expand Down Expand Up @@ -125,7 +143,14 @@ export class AddTemplateComponent implements OnInit {
// this.isPreview = true;
// localStorage.setItem('isPreview', 'yes');

this.userHtml = `<html lang="en">
if (this.fromEdit && this.certificateIndex !== undefined) {
const credTemp = this.generalService.getCertificateData();
const certificateData = credTemp[this.certificateIndex]['html'];
this.certificateTitle = credTemp[this.certificateIndex]['title'];
this.userHtml = certificateData;
}
if (!this.fromEdit) {
this.userHtml = `<html lang="en">
<head>
<style>
.line {
Expand Down Expand Up @@ -170,12 +195,16 @@ export class AddTemplateComponent implements OnInit {
</body>
</html>
`
this.injectHTML();
}
this.injectHTML();
}

editTemplate() {
localStorage.setItem('sampleData', JSON.stringify(this.userHtml));
this.router.navigate(['/edit-template/' + this.usecase + '/' +this.entityName], { state: { item: this.userHtml } });
localStorage.setItem('sampleData', JSON.stringify(this.userHtml));
if (this.certificateTitle) {
localStorage.setItem('certificateTitle', this.certificateTitle);
}
this.router.navigate(['/edit-template/' + this.usecase + '/' + this.entityName], { state: { item: this.userHtml } });
}


Expand All @@ -184,9 +213,9 @@ export class AddTemplateComponent implements OnInit {
"filters": {}
}

this.documentTypeList = [{"osUpdatedAt":"2022-05-24T10:24:21.515Z","osCreatedAt":"2022-05-24T10:24:21.515Z","osUpdatedBy":"anonymous","name":"Proof of skill","osCreatedBy":"anonymous","samples":[{"osUpdatedAt":"2022-05-24T10:24:21.515Z","osCreatedAt":"2022-05-24T10:24:21.515Z","osUpdatedBy":"anonymous","osCreatedBy":"anonymous","certificateUrl":"https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/SkillCertificate.html","osid":"1-cf863d16-c827-446b-93bf-8ce98cb92ece","schemaUrl":"https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/SkillCertificate.json"}],"osid":"1-69ff3505-99b5-4271-9996-7c0e31624bb9","osOwner":["anonymous"]},{"osUpdatedAt":"2022-05-24T10:06:42.920Z","osCreatedAt":"2022-05-24T10:06:42.920Z","osUpdatedBy":"anonymous","name":"Proof of Work","osCreatedBy":"anonymous","samples":[{"osUpdatedAt":"2022-05-24T10:06:42.920Z","osCreatedAt":"2022-05-24T10:06:42.920Z","osUpdatedBy":"anonymous","osCreatedBy":"anonymous","certificateUrl":"https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/TrainingCertificate.html","osid":"1-93537196-1a5f-4fd2-bbc9-8934b451b2e6","schemaUrl":"https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/TrainingCertificate.json","thumbnailUrl":"https://i.ibb.co/7n2pjt6/A4-Template-5.png"}],"osid":"1-0f708c3f-1430-47ea-a107-55bb22c7a225","osOwner":["anonymous"]}];
this.selectedDecType = [{"osUpdatedAt":"2022-05-24T10:24:21.515Z","osCreatedAt":"2022-05-24T10:24:21.515Z","osUpdatedBy":"anonymous","name":"Proof of skill","osCreatedBy":"anonymous","samples":[{"osUpdatedAt":"2022-05-24T10:24:21.515Z","osCreatedAt":"2022-05-24T10:24:21.515Z","osUpdatedBy":"anonymous","osCreatedBy":"anonymous","certificateUrl":"https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/SkillCertificate.html","osid":"1-cf863d16-c827-446b-93bf-8ce98cb92ece","schemaUrl":"https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/SkillCertificate.json"}],"osid":"1-69ff3505-99b5-4271-9996-7c0e31624bb9","osOwner":["anonymous"]},{"osUpdatedAt":"2022-05-24T10:06:42.920Z","osCreatedAt":"2022-05-24T10:06:42.920Z","osUpdatedBy":"anonymous","name":"Proof of Work","osCreatedBy":"anonymous","samples":[{"osUpdatedAt":"2022-05-24T10:06:42.920Z","osCreatedAt":"2022-05-24T10:06:42.920Z","osUpdatedBy":"anonymous","osCreatedBy":"anonymous","certificateUrl":"https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/TrainingCertificate.html","osid":"1-93537196-1a5f-4fd2-bbc9-8934b451b2e6","schemaUrl":"https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/TrainingCertificate.json","thumbnailUrl":"https://i.ibb.co/7n2pjt6/A4-Template-5.png"}],"osid":"1-0f708c3f-1430-47ea-a107-55bb22c7a225","osOwner":["anonymous"]}];
this.documentTypeList = [{ "osUpdatedAt": "2022-05-24T10:24:21.515Z", "osCreatedAt": "2022-05-24T10:24:21.515Z", "osUpdatedBy": "anonymous", "name": "Proof of skill", "osCreatedBy": "anonymous", "samples": [{ "osUpdatedAt": "2022-05-24T10:24:21.515Z", "osCreatedAt": "2022-05-24T10:24:21.515Z", "osUpdatedBy": "anonymous", "osCreatedBy": "anonymous", "certificateUrl": "https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/SkillCertificate.html", "osid": "1-cf863d16-c827-446b-93bf-8ce98cb92ece", "schemaUrl": "https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/SkillCertificate.json" }], "osid": "1-69ff3505-99b5-4271-9996-7c0e31624bb9", "osOwner": ["anonymous"] }, { "osUpdatedAt": "2022-05-24T10:06:42.920Z", "osCreatedAt": "2022-05-24T10:06:42.920Z", "osUpdatedBy": "anonymous", "name": "Proof of Work", "osCreatedBy": "anonymous", "samples": [{ "osUpdatedAt": "2022-05-24T10:06:42.920Z", "osCreatedAt": "2022-05-24T10:06:42.920Z", "osUpdatedBy": "anonymous", "osCreatedBy": "anonymous", "certificateUrl": "https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/TrainingCertificate.html", "osid": "1-93537196-1a5f-4fd2-bbc9-8934b451b2e6", "schemaUrl": "https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/TrainingCertificate.json", "thumbnailUrl": "https://i.ibb.co/7n2pjt6/A4-Template-5.png" }], "osid": "1-0f708c3f-1430-47ea-a107-55bb22c7a225", "osOwner": ["anonymous"] }];
this.selectedDecType = [{ "osUpdatedAt": "2022-05-24T10:24:21.515Z", "osCreatedAt": "2022-05-24T10:24:21.515Z", "osUpdatedBy": "anonymous", "name": "Proof of skill", "osCreatedBy": "anonymous", "samples": [{ "osUpdatedAt": "2022-05-24T10:24:21.515Z", "osCreatedAt": "2022-05-24T10:24:21.515Z", "osUpdatedBy": "anonymous", "osCreatedBy": "anonymous", "certificateUrl": "https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/SkillCertificate.html", "osid": "1-cf863d16-c827-446b-93bf-8ce98cb92ece", "schemaUrl": "https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/SkillCertificate.json" }], "osid": "1-69ff3505-99b5-4271-9996-7c0e31624bb9", "osOwner": ["anonymous"] }, { "osUpdatedAt": "2022-05-24T10:06:42.920Z", "osCreatedAt": "2022-05-24T10:06:42.920Z", "osUpdatedBy": "anonymous", "name": "Proof of Work", "osCreatedBy": "anonymous", "samples": [{ "osUpdatedAt": "2022-05-24T10:06:42.920Z", "osCreatedAt": "2022-05-24T10:06:42.920Z", "osUpdatedBy": "anonymous", "osCreatedBy": "anonymous", "certificateUrl": "https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/TrainingCertificate.html", "osid": "1-93537196-1a5f-4fd2-bbc9-8934b451b2e6", "schemaUrl": "https://raw.githubusercontent.com/Sunbird-RC/demo-certificate-issuance/main/samples/TrainingCertificate.json", "thumbnailUrl": "https://i.ibb.co/7n2pjt6/A4-Template-5.png" }], "osid": "1-0f708c3f-1430-47ea-a107-55bb22c7a225", "osOwner": ["anonymous"] }];

}

onChange(index) {
Expand Down Expand Up @@ -219,5 +248,33 @@ export class AddTemplateComponent implements OnInit {
}, 500)
}

deleteTemplate() {
this.generalService.getData('/Schema').subscribe((res) => {
for (let i = 0; i < res.length; i++) {
if (res[i]["name"] == this.entityName) {
this.schemaOsid = res[i].osid;
let data = JSON.parse(res[i]['schema']);
var certificateTemplates = data._osConfig['certificateTemplates'];
var templateKeys = Object.keys(certificateTemplates);
if (this.certificateIndex >= 0 && this.certificateIndex < templateKeys.length) {
var templateName = templateKeys[this.certificateIndex];
var certificateTemplateData = certificateTemplates[templateName];
}
if (certificateTemplates.hasOwnProperty(templateName)) {
delete certificateTemplates[templateName];
}

let payload = {
"schema": JSON.stringify(data)
};

this.generalService.putData('/Schema/', this.schemaOsid, payload).subscribe((res) => {
this.router.navigate(['/create/' + this.vcStep + '/' + this.usecase + '/' + this.entityName]);
});

}
}
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
<div class="wrap">
<iframe id="iframe{{i}}" class="iframe-container embed-responsive-item iframeCert"></iframe>
</div>
<div class="l12 fw-bold">{{item?.title}}</div>
<div class="l12 fw-bold">{{item?.title}}
<a id="editLink" [routerLink]="['/add-template', usecase, entityName]" [queryParams]="{ fromEdit: true, certificateIndex: i }"class="ml-1">
<i class="fa fa-pencil-square-o" aria-hidden="true"></i>
</a>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ export class CreateVcTemplateComponent implements OnInit, OnChanges {
// Put the content in the iframe
iframedoc.open();
iframedoc.writeln(this.credTemp[i].html);

iframedoc.close();
this.generalService.setCertificateData(this.credTemp);
} else {
alert('Cannot inject dynamic contents into iframe.');
}
Expand All @@ -195,6 +195,11 @@ export class CreateVcTemplateComponent implements OnInit, OnChanges {
this.location.replaceState('/add-template/' + this.usecase + '/' + this.entityName);
}


editCertificate(){
const anchorTag = document.getElementById('editLink');
if (anchorTag) {
anchorTag.click();
}
}

}
Loading

0 comments on commit 9f4ce87

Please sign in to comment.