DB restructure, print page
This commit is contained in:
@@ -5,21 +5,38 @@ export default class extends Controller {
|
||||
logoType: String,
|
||||
employerName: String
|
||||
}
|
||||
static targets = ["preview", "previewContainer", "logoSelect", "logoField", "initialLogoFile"];
|
||||
static targets = ["preview", "previewContainer", "logoSelect", "logoIdField", "logoNameField", "initialLogoFile"];
|
||||
|
||||
async connect() {
|
||||
console.log('in connect');
|
||||
const initValue = this.logoFieldTarget.value
|
||||
this.setPreviewImage()
|
||||
// Remember to revoke the URL when the controller is disconnected if necessary
|
||||
// this.disconnect = () => URL.revokeObjectURL(objectUrl);
|
||||
}
|
||||
|
||||
async setPreviewImage() {
|
||||
const initValue = this.logoIdFieldTarget.value
|
||||
console.log(initValue)
|
||||
console.log(this.logoTypeValue)
|
||||
if (initValue) {
|
||||
const response = await fetch(`/id_card/${this.logoTypeValue}_logos/${initValue}/image`); // Fetch the binary data
|
||||
const logoType = this.logoTypeValue
|
||||
if (logoType == "employer") {
|
||||
const contentDisposition = response.headers.get('Content-Disposition');
|
||||
const filename = contentDisposition.match(/filename="?([^"]+)"?/)[1];
|
||||
this.logoNameFieldTarget.value = filename;
|
||||
}
|
||||
const blob = await response.blob();
|
||||
const objectUrl = URL.createObjectURL(blob);
|
||||
this.previewTarget.src = objectUrl;
|
||||
this.previewContainerTarget.classList.remove("hidden");
|
||||
} else {
|
||||
this.previewContainerTarget.classList.add("hidden");
|
||||
}
|
||||
// Remember to revoke the URL when the controller is disconnected if necessary
|
||||
// this.disconnect = () => URL.revokeObjectURL(objectUrl);
|
||||
}
|
||||
|
||||
setSelectPreview(event) {
|
||||
this.setPreviewImage()
|
||||
}
|
||||
|
||||
uploadLogo(event) {
|
||||
@@ -34,19 +51,25 @@ export default class extends Controller {
|
||||
if (logoType == "network") {
|
||||
console.log("n " + newFileName);
|
||||
newFileName = this.determineNetworkFilename(logoFile)
|
||||
this.addOptionToSelect(newFileName)
|
||||
logoFile = new File([logoFile], newFileName)
|
||||
} else if (logoType == "employer") {
|
||||
newFileName = this.determineEmployerFilename(logoFile)
|
||||
logoFile = new File([logoFile], newFileName)
|
||||
}
|
||||
logoFile = new File([logoFile], newFileName)
|
||||
|
||||
this.uploadLogoToServer(logoFile)
|
||||
.then((result) => {
|
||||
console.log(result);
|
||||
const logoId = result.id
|
||||
this.previewFile(logoFile);
|
||||
this.logoFieldTarget.value = logoId;
|
||||
if (logoType == "network") {
|
||||
this.addOptionToSelect(newFileName, logoId)
|
||||
} else {
|
||||
this.logoNameFieldTarget.value = newFileName;
|
||||
}
|
||||
|
||||
this.logoIdFieldTarget.value = logoId;
|
||||
|
||||
|
||||
})
|
||||
.catch((error) => {
|
||||
// Handle any errors that occurred
|
||||
@@ -93,23 +116,22 @@ export default class extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
addOptionToSelect(name) {
|
||||
addOptionToSelect(name, id) {
|
||||
const blankOptionIndex = 0;
|
||||
const newOption = new Option(name, name, true, true)
|
||||
const newOption = new Option(name, id, true, true)
|
||||
|
||||
if (this.logoFieldTarget.options.length > blankOptionIndex + 1) {
|
||||
this.logoFieldTarget.insertBefore(newOption, this.logoFieldTarget.options[blankOptionIndex + 1]);
|
||||
if (this.logoIdFieldTarget.options.length > blankOptionIndex + 1) {
|
||||
this.logoIdFieldTarget.insertBefore(newOption, this.logoIdFieldTarget.options[blankOptionIndex + 1]);
|
||||
} else {
|
||||
this.logoFieldTarget.appendChild(newOption);
|
||||
this.logoIdFieldTarget.appendChild(newOption);
|
||||
}
|
||||
|
||||
this.logoFieldTarget.value = name;
|
||||
}
|
||||
|
||||
determineNetworkFilename(logoFile) {
|
||||
const fileExtension = logoFile.name.split('.').pop();
|
||||
const primaryNetworkName = prompt("Enter the name for the primary network (Usually 'Cigna' or 'MedCost':");
|
||||
const secondaryNetworkName = prompt("Enter the name for the primary network (ex: Health Partners):");
|
||||
const secondaryNetworkName = prompt("Enter the name for the partner network (ex: Health Partners):");
|
||||
const logoFilename = this.titleizeText(primaryNetworkName).concat(this.titleizeText(secondaryNetworkName)).concat("Logo.").concat(fileExtension).replaceAll(' ', '');
|
||||
|
||||
return logoFilename
|
||||
|
||||
Reference in New Issue
Block a user