Budget Download

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

<template>

<c-download-excel lwc:if={isInitialized} is-logfile={isLogFile} excel-


setupdata={excelSetupObject} onshowspinner={showSpinner}
onclosespinner={onDownloadProcessingCompleted}></c-download-excel>
<lightning-spinner lwc:if={isLoading} alternative-text="Loading"
size="medium"></lightning-spinner>
</template>

????????????????????

import { LightningElement, track, wire, api } from 'lwc';


import {ShowToastEvent} from 'lightning/platformShowToastEvent';
import {createEvent} from 'c/toastNotification';
import {getErrorMesage} from 'c/errorGenerator';

import getBudgetExcelFieldSetsData from


'@salesforce/apex/BudgetExcelDownload_Ctrl.getBudgetExcelFieldSetsData';
import DOWNLOAD_BUDGET_ERROR_MSG from
'@salesforce/label/c.DOWNLOAD_BUDGET_ERROR_MSG';
import FINANCIAL_ERROR from '@salesforce/label/c.FINANCIAL_ERROR';

export default class BudgetDownload extends LightningElement {

@api recordId;
@track excelSetupObject;
@track isInitialized = false;
@track isLogFile = false;
@track isLoading = false;

label = {
DOWNLOAD_BUDGET_ERROR_MSG,
FINANCIAL_ERROR
}

@api
invoke() {
this.showSpinner();
getBudgetExcelFieldSetsData({recordId : this.recordId}).then(response => {
if (response.isFinancialAccessible) {
if (response.hasErrorInSetup) {
this.showErrorToast(response.errorMessage, '', 'dismissible');
this.hideSpinner();
}
else {
this.excelSetupObject = response;
this.isInitialized = true;
}
}
else {
this.showErrorToast(this.label.FINANCIAL_ERROR, '', 'dismissible');
this.hideSpinner();
}
})
.catch(error => {
this.showErrorToast(this.label.DOWNLOAD_BUDGET_ERROR_MSG,
getErrorMesage(error), 'dismissible');
this.hideSpinner();
});
}

/**
* Spinner
*/
showSpinner() {
this.isLoading = true;
}

hideSpinner() {
this.isLoading = false;
}

onDownloadProcessingCompleted() {
this.resetDownload();
this.hideSpinner();
}

showErrorToast(header, error, mode) {


this.dispatchEvent(new ShowToastEvent(createEvent(header, error, 'error',
mode)));
}

resetDownload() {
this.isInitialized = false;
this.isLogFile = false;
}
}

???????????????????????????????????

<?xml version="1.0" encoding="UTF-8"?>


<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>56.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Budget Download</masterLabel>
<targets>
<target>lightning__RecordAction</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__RecordAction">
<actionType>Action</actionType>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>
????????????????//////

budgetDownload

????????????????????????????

import { createElement } from 'lwc';


import BudgetDownload from 'c/budgetDownload';

describe('c-budget-download', () => {
afterEach(() => {
// The jsdom instance is shared across test cases in a single file so reset
the DOM
while (document.body.firstChild) {
document.body.removeChild(document.body.firstChild);
}
});

it('TODO: test case generated by CLI command, please fill in test logic', () =>
{
// Arrange
const element = createElement('c-budget-download', {
is: BudgetDownload
});

// Act
document.body.appendChild(element);

// Assert
// const div = element.shadowRoot.querySelector('div');
expect(1).toBe(1);
});
});

You might also like