Optimize data handling by embedding EnvelopeResponse in Razor Page, eliminating additional requests

This commit is contained in:
Developer 02 2024-04-08 17:05:01 +02:00
parent 1584fd6f1c
commit 6941a3db8d
3 changed files with 19 additions and 24 deletions

View File

@ -83,7 +83,7 @@ namespace EnvelopeGenerator.Web.Controllers
var envelope = await _envelopeService.ReadByUuidAsync(uuid: decodedId.EnvelopeUuid, signature: decodedId.ReceiverSignature, withAll:true); var envelope = await _envelopeService.ReadByUuidAsync(uuid: decodedId.EnvelopeUuid, signature: decodedId.ReceiverSignature, withAll:true);
database.Services.actionService.EnterCorrectAccessCode(response.Envelope, response.Receiver); //for history database.Services.actionService.EnterCorrectAccessCode(response.Envelope, response.Receiver); //for history
ViewData["EnvelopeKey"] = envelopeReceiverId; ViewData["EnvelopeKey"] = envelopeReceiverId;
ViewData["EnveResponse"] = response; ViewData["EnvelopeResponse"] = response;
return View("ShowEnvelope", envelope); return View("ShowEnvelope", envelope);
} }
else else

View File

@ -44,6 +44,7 @@
</div> </div>
</div> </div>
} }
<script> <script>
const collapseNav = () => { const collapseNav = () => {
document.addEventListener('click', function (event) { document.addEventListener('click', function (event) {
@ -57,8 +58,20 @@
}); });
} }
@{
var envelopeResponse = ViewData["EnvelopeResponse"];
var settings = new Newtonsoft.Json.JsonSerializerSettings
{
ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver()
};
var envelopeResponseJson = Newtonsoft.Json.JsonConvert.SerializeObject(envelopeResponse, settings);
}
var envelopeResponse = @Html.Raw(envelopeResponseJson);
console.log(envelopeResponse);
document.addEventListener("DOMContentLoaded", async () => { document.addEventListener("DOMContentLoaded", async () => {
const app = new App("#app", "@ViewData["EnvelopeKey"]"); const app = new App("#app", "@ViewData["EnvelopeKey"]", envelopeResponse);
await app.init(); await app.init();
}) })
</script> </script>

View File

@ -10,7 +10,7 @@ const ActionType = {
} }
class App { class App {
constructor(container, envelopeKey) { constructor(container, envelopeKey, envelopeResponse) {
this.container = container this.container = container
this.envelopeKey = envelopeKey this.envelopeKey = envelopeKey
@ -22,33 +22,15 @@ class App {
this.currentDocument = null this.currentDocument = null
this.currentReceiver = null this.currentReceiver = null
this.signatureCount = 0 this.signatureCount = 0
this.envelopeResponse = envelopeResponse;
} }
// This function will be called from the ShowEnvelope.razor page // This function will be called from the ShowEnvelope.razor page
// and will trigger loading of the Editor Interface // and will trigger loading of the Editor Interface
async init() { async init() {
// Load the envelope from the database // Load the envelope from the database
console.debug('Loading envelope from database..') this.currentDocument = this.envelopeResponse.envelope.documents[0]
const envelopeResponse = await this.Network.getEnvelope(this.envelopeKey) this.currentReceiver = this.envelopeResponse.receiver
if (envelopeResponse.fatal) {
return Swal.fire({
title: 'Fehler',
text: 'Umschlag konnte nicht geladen werden!',
icon: 'error',
})
}
if (envelopeResponse.error) {
return Swal.fire({
title: 'Warnung',
text: 'Umschlag ist nicht mehr verfügbar.',
icon: 'warning',
})
}
this.currentDocument = envelopeResponse.data.envelope.documents[0]
this.currentReceiver = envelopeResponse.data.receiver
// Load the document from the filestore // Load the document from the filestore
console.debug('Loading document from filestore') console.debug('Loading document from filestore')