UNPKG

armisa-models

Version:
391 lines (390 loc) 16.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GridViewFactory = void 0; const ElementsOfFormFactory_1 = require("../Page/ElementsOfFormFactory"); const Columns_1 = require("./Columns"); const TokenInfo_1 = require("../AmisaAuth/Models/StorageManager/TokenInfo"); class GridViewFactory { get any() { return this; } constructor(mainStateManager, urls, spinnerType, hasPagination, initializeCustomPayLoad) { this.mainStateManager = mainStateManager; this.urls = urls; this.spinnerType = spinnerType; this.hasPagination = hasPagination; this.getTextBoxFactory = (fieldName) => { const selfFactoryName = 'selfFactory' + fieldName; return this.any[selfFactoryName]; }; this.cach = {}; this.forceUpdate = () => { }; this.columns = []; this.columnsReverse = []; this.mergeCaptionColumns = null; this.rows = []; this.deleteRow = (caption, text, main) => { if (this.isValidCurrenRowId) { this.elementsOfForm.showAreYouSureDeleteMessageBox(this.deleteRowFinal, caption, text, main); } else { this.elementsOfForm.showInvalidArgumentMessageBox('هیچ ردیف فعالی به درستی انتخاب نشده است'); } }; this.deleteRowFinal = () => { this.showWaitingSpinner(); const yearId = this.currentRow.getProp('yearId'); if (!(typeof yearId === 'number' && yearId > 0)) { this.elementsOfForm.closeWaitingFormSpinner(); this.elementsOfForm.showInvalidArgumentMessageBox('شناسه سال مالی فعال معتبر نمیباشد'); return; } this.apiAxios.post(this.urls.delete, { ...this.elementsOfForm.searchParameter, idForDelete: this.currentRow.getProp('id'), yearId: yearId }) .then(response => { if (response.data.isSuccess) { this.closeWaitingSpinner(); this.rows = response.data.rows; this.elementsOfForm.pageParameter.totalPages = response.data.searchParameter.totalPages; this.elementsOfForm.pageParameter.currentPage = response.data.searchParameter.currentPage; this.forceUpdate(); } else { this.closeWaitingSpinner(); this.elementsOfForm.showInvalidArgumentMessageBox(response.data.messageRoot); } }) .catch(e => { this.closeWaitingSpinner(); this.elementsOfForm.showErrorMessageBox(e); }); }; this.loadData = () => { this.showWaitingSpinner(); this.apiAxios.post(this.urls.search, this.elementsOfForm.searchParameter) .then(response => { if (response.data.isSuccess) { this.closeWaitingSpinner(); this.rows = response.data.rows; this.hideAutoHideColumns(); this.elementsOfForm.pageParameter.totalPages = response.data.searchParameter.totalPages; this.elementsOfForm.pageParameter.currentPage = response.data.searchParameter.currentPage; this.forceUpdate(); } else { this.closeWaitingSpinner(); this.rows = []; this.elementsOfForm.showInvalidArgumentMessageBox(response.data.messageRoot); } }) .catch(e => { this.closeWaitingSpinner(); this.rows = []; this.elementsOfForm.showErrorMessageBox(e); }); }; this.selectThisRowById = (_rowId) => { throw new Error('Method not implemented.'); }; this.selectThisRowByIndex = (rowIndex) => { return this.currentRowIndex === rowIndex; }; this.showContextMenuForRow = (_rowData, _rowIndex, _arg2, _arg3) => { throw new Error('Method not implemented.'); }; this.hideContextMenuForRow = () => { throw new Error('Method not implemented.'); }; this.currentRowIndex = 0; this.isThisCurrentRow = (rowIndex) => { return this.currentRowIndex === rowIndex; }; this.selectedRowsIds = []; this.isSelectedThisRow = (rowId) => { return this.selectedRowsIds.includes(rowId); }; this.selectThisCell = (rowIndex, _columnIndex) => { this.currentRowIndex = rowIndex; this.elementsOfForm.toolStripFactory.forceUpdateToolStackMenu(); this.forceUpdate(); }; this.refreshList = () => { this.loadData(); }; this.close = () => { if (this.elementsOfForm.subPageItem) { this.elementsOfForm.subPageItem.close(); } else if (this.elementsOfForm.currentModal) { this.elementsOfForm.currentModal.close(); } }; this.nextRow = () => { if (this.currentRowIndex === this.rows.length - 1) { this.currentRowIndex = 0; } else { this.currentRowIndex += 1; } this.forceUpdate(); setTimeout(() => { this.currentRowRef?.current?.scrollIntoView({ behavior: 'auto', inline: 'center', block: 'center', }); }, 90); }; this.previousRow = () => { if (this.currentRowIndex === 0) { this.currentRowIndex = this.rows.length - 1; } else { this.currentRowIndex -= 1; } this.forceUpdate(); setTimeout(() => { this.currentRowRef?.current?.scrollIntoView({ behavior: 'auto', inline: 'center', block: 'center', }); }, 90); }; this.getLockOrginalValue = (row) => { return row['isLockOrginalValueTemp']; }; this.setCachValueOfLockState = (fieldName, newValue) => { const isLockOrginalValueTemp = () => { if (this.currentRow) { return this.getLockOrginalValue(this.currentRow); } return undefined; }; const currentValue = this.currentRow.getProp(fieldName); const cachValueOfLockState = isLockOrginalValueTemp(); if (cachValueOfLockState === undefined && newValue !== currentValue) { this.currentRow['isLockOrginalValueTemp'] = currentValue; } else { if (cachValueOfLockState === newValue) { delete this.currentRow['isLockOrginalValueTemp']; } } this.currentRow.setProp(fieldName, newValue); }; this.toggelLockUnlock = (fieldName) => { const currentValue = this.currentRow.getProp(fieldName); if (currentValue) { this.unLock(fieldName); } else { this.lock(fieldName); } }; this.lock = (fieldName) => { if (!this.urls.lock) { this.elementsOfForm.showInvalidArgumentMessageBox('امکان قفل کردن ردیف ها، موجود نمیباشد'); return; } if (this.isValidCurrenRowId) { const yearId = this.currentRow.getProp('yearId'); if (!(typeof yearId === 'number' && yearId > 0)) { this.elementsOfForm.closeWaitingFormSpinner(); this.elementsOfForm.showInvalidArgumentMessageBox('شناسه سال مالی فعال معتبر نمیباشد'); return; } this.lockUnLock(this.urls.lock, this.currentRowId, yearId, () => { this.setCachValueOfLockState(fieldName, true); }); } else { this.elementsOfForm.showInvalidArgumentMessageBox('هیچ ردیف فعالی به درستی انتخاب نشده است'); } }; this.unLock = (fieldName) => { if (!this.urls.unLock) { this.elementsOfForm.showInvalidArgumentMessageBox('امکان باز کردن قفل ردیف ها، موجود نمیباشد'); return; } if (this.isValidCurrenRowId) { const yearId = this.currentRow.getProp('yearId'); if (!(typeof yearId === 'number' && yearId > 0)) { this.elementsOfForm.closeWaitingFormSpinner(); this.elementsOfForm.showInvalidArgumentMessageBox('شناسه سال مالی فعال معتبر نمیباشد'); return; } this.lockUnLock(this.urls.unLock, this.currentRowId, yearId, () => { this.setCachValueOfLockState(fieldName, false); }); } else { this.elementsOfForm.showInvalidArgumentMessageBox('هیچ ردیف فعالی به درستی انتخاب نشده است'); } }; this.lockUnLock = (path, id, yearId, afterSuccessed) => { this.showWaitingSpinner(); this.apiAxios.post(`${path}/${id}/${yearId}`, {}, this.mainStateManager.tokenInfo.headerOfAxios) .then(response => { if (response.data.isSuccess) { afterSuccessed(); this.closeWaitingSpinner(); this.forceUpdate(); } else { this.closeWaitingSpinner(); this.elementsOfForm.showInvalidArgumentMessageBox(response.data.messageRoot); } }) .catch(e => { this.closeWaitingSpinner(); this.elementsOfForm.showErrorMessageBox(e); }); }; this.elementsOfForm = new ElementsOfFormFactory_1.ElementsOfFormFactory(this, initializeCustomPayLoad); this.apiAxios = (0, TokenInfo_1.useAxios)(this.urls); switch (this.spinnerType) { case 'Form': this.showWaitingSpinner = this.elementsOfForm.showWaitingFormSpinner; this.closeWaitingSpinner = this.elementsOfForm.closeWaitingFormSpinner; break; case 'Table': this.showWaitingSpinner = this.elementsOfForm.showWaitingTableSpinner; this.closeWaitingSpinner = this.elementsOfForm.closeWaitingTableSpinner; break; default: this.showWaitingSpinner = this.elementsOfForm.showFullScreenWaittingSpinner; this.closeWaitingSpinner = this.elementsOfForm.closeFullScreenWaittingSpinner; break; } } hideAutoHideColumns() { const autoHidColumns = this.columns.filter(i => i.autoHideIfEmpty); autoHidColumns.forEach(column => { column.visible = this.rows.some(row => !column.isCellValueEmpty(row)); }); } get isValidCurrenRowId() { if (this.rows && this.rows.length > 0 && typeof this.currentRowIndex === 'number') { const currentRow = this.rows[this.currentRowIndex]; const id = currentRow.getProp('id'); return typeof id === 'number' && id > 0; } return false; } get currentRow() { if (this.rows && this.rows.length > 0 && typeof this.currentRowIndex === 'number') { return this.rows[this.currentRowIndex]; } } get currentRowId() { return this.currentRow.getProp('id'); } get currentRowYearId() { return this.currentRow.getProp('yearId'); } getWidth(child) { const width = child.props.width; const level = child.props.level; if (typeof width === 'number') { return width; } const setting = this.mainStateManager.Setting; if (child.type === Columns_1.AccountColumn) { if (level === 1) { return setting.structureAccountCoding.levelLen1 * 5; } else if (level === 2) { return setting.structureAccountCoding.untilLevelLen2 * 5; } else if (level === 3) { return setting.structureAccountCoding.untilLevelLen3 * 5; } else if (level === 4) { return setting.structureAccountCoding.untilLevelLen4 * 5; } else if (level === 5) { return setting.structureAccountCoding.untilLevelLen5 * 5; } else if (level === 6) { return setting.structureAccountCoding.untilLevelLen6 * 5; } else if (level === 7) { return setting.structureAccountCoding.untilLevelLen7 * 5; } else if (level === 8) { return setting.structureAccountCoding.untilLevelLen8 * 5; } else if (level === 9) { return setting.structureAccountCoding.untilLevelLen9 * 5; } else { return 100; } } else if (child.type === Columns_1.DetailedAccountColumn) { } else if (child.type === Columns_1.CustomerColumn) { } else if (child.type === Columns_1.CostCenterColumn) { } else if (child.type === Columns_1.BankColumn) { } else if (child.type === Columns_1.BranchColumn) { } else if (child.type === Columns_1.CarColumn) { } else if (child.type === Columns_1.CashColumn) { } else if (child.type === Columns_1.DriveColumn) { } else if (child.type === Columns_1.PersonColumn) { } else if (child.type === Columns_1.PurchaseOfficerColumn) { } else if (child.type === Columns_1.SaleManagerColumn) { } else if (child.type === Columns_1.StakeholderColumn) { } else if (child.type === Columns_1.CapitalistColumn) { } else if (child.type === Columns_1.VisitorColumn) { } else if (child.type === Columns_1.StringColumn) { return 120; } else if (child.type === Columns_1.CountColumn) { return 50; } else if (child.type === Columns_1.QTYColumn) { return 70; } else if (child.type === Columns_1.NumberOfCheckColumn) { return 90; } else if (child.type === Columns_1.DateColumn) { return 90; } else if (child.type === Columns_1.NumberColumn) { return 30; } else if (child.type === Columns_1.AmountColumn) { return 90; } else if (child.type === Columns_1.IdColumn) { return 30; } else if (child.type === Columns_1.RowColumn) { return 30; } else if (child.type === Columns_1.IconColumn) { return 20; } else if (child.type === Columns_1.NumberIconColumn) { return 20; } else if (child.type === Columns_1.LockUnLockColumn) { return 20; } return 100; } } exports.GridViewFactory = GridViewFactory;