Skip to content

Commit

Permalink
download optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
terance-edmonds committed Nov 2, 2023
1 parent 2bc67fa commit 7fabc69
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
7 changes: 5 additions & 2 deletions src/app/credentials/credentials.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
<div class="card">
<div *ngFor="let vc of currentVCs; let i = index" class="vc">
<label class="vc-label">
<input type="checkbox" class="checkbox" [checked]="selectedVCs[i]"
<input
type="checkbox"
class="checkbox"
[checked]="selectedVCs[i]"
(change)="selectedVCs[vc.index] = !selectedVCs[vc.index]" />
<span class="name">{{ getName(vc) || 'VC ' + vc.index }}</span>
</label>
Expand All @@ -18,4 +21,4 @@
</div>
</div>
</div>
</div>
</div>
9 changes: 1 addition & 8 deletions src/app/credentials/credentials.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@ export class CredentialsComponent {
const vc_data = this.currentVCs.find((item: any) => item.index == index);
let title = utils.getObjectValue(vc_data.vc, 'title') || 'Verifiable credential';

var element = document.createElement('a');
var sJson = JSON.stringify(vc_data.vc, null, 4);
element.setAttribute('href', 'data:text/json;charset=UTF-8,' + encodeURIComponent(sJson));
element.setAttribute('download', `${title}.json`);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
utils.downloadJson(vc_data.vc, title);
}

removeVC(index: string | number) {
Expand Down
5 changes: 4 additions & 1 deletion src/app/presentations/presentations.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@
</div>
</div>

<app-presentation *ngIf="selectedVP != null" [data]="selectedVP" (onBack)="onSelectVP(null)"></app-presentation>
<app-presentation
*ngIf="selectedVP != null"
[data]="selectedVP"
(onBack)="onSelectVP(null)"></app-presentation>
9 changes: 1 addition & 8 deletions src/app/presentations/presentations.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,7 @@ export class PresentationsComponent implements OnInit {
const vp_data = this.currentVPs.find((item: any) => item.index == index);
let title = vp_data.title || 'Verifiable presentation';

var element = document.createElement('a');
var sJson = JSON.stringify(vp_data.vp, null, 4);
element.setAttribute('href', 'data:text/json;charset=UTF-8,' + encodeURIComponent(sJson));
element.setAttribute('download', `${title}.json`);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
utils.downloadJson(vp_data.vp, title);
}

removeVP(index: string | number) {
Expand Down
10 changes: 10 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,15 @@ export default {
} catch (error) {
return false;
}
},
downloadJson: (json: object, title: string) => {
var element = document.createElement('a');
var sJson = JSON.stringify(json, null, 4);
element.setAttribute('href', 'data:text/json;charset=UTF-8,' + encodeURIComponent(sJson));
element.setAttribute('download', `${title}.json`);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
};

0 comments on commit 7fabc69

Please sign in to comment.