armisa-models
Version:
models of armisa!
218 lines (217 loc) • 8.43 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ViewBargeFactory = void 0;
const ElementsOfFormFactory_1 = require("../Page/ElementsOfFormFactory");
const Columns_1 = require("./Columns");
const LockUnLockFactory_1 = require("./LockUnLockFactory");
class ViewBargeFactory {
get any() {
return this;
}
constructor(mainStateManager, yearId, id, isFindIdInRows, axiosData, hasPagination) {
this.mainStateManager = mainStateManager;
this.yearId = yearId;
this.id = id;
this.isFindIdInRows = isFindIdInRows;
this.axiosData = axiosData;
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.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.forceUpdate();
};
this.refreshList = () => {
this.loadData();
};
this.close = () => {
if (this.elementsOfForm.subPageItem) {
this.elementsOfForm.subPageItem.close();
}
};
this.toggelLockUnlock = (fieldName) => {
this.lockUnLockFactory.toggel(fieldName);
};
this.lock = (fieldName) => {
this.lockUnLockFactory.lock(fieldName);
};
this.unLock = (fieldName) => {
this.lockUnLockFactory.unLock(fieldName);
};
this.elementsOfForm = new ElementsOfFormFactory_1.ElementsOfFormFactory(this);
if (this.axiosData) {
this.controllerPath = this.axiosData.controllerPath || "";
this.actionGetByIdPath = this.axiosData.actionGetByIdPath || 'getById';
this.actionGetByLineIdPath = this.axiosData.actionGetByLineIdPath || 'getByLineId';
this.axiosInstance = this.axiosData.axios(this.controllerPath);
}
this.lockUnLockFactory = new LockUnLockFactory_1.LockUnLockViewBargeFactory(this, this.axiosData, this.id, this.yearId);
}
loadData() {
if (!this.axiosInstance) {
return;
}
this.elementsOfForm.showWaitingFormSpinner();
const actionPath = this.isFindIdInRows ? this.actionGetByLineIdPath : this.actionGetByIdPath;
const yearAction = this.yearId && typeof this.yearId === 'number' ? `/${this.yearId}` : '';
this.axiosInstance.get(`${actionPath}/${this.id}${yearAction}`, this.mainStateManager.tokenInfo.headerOfAxios)
.then(response => {
const data = response.data;
if (data === undefined) {
this.elementsOfForm.showSomeThingWentWrong();
}
if (data.getProp('isSuccess')) {
this.deserializeData(data.data);
}
else {
this.elementsOfForm.closeWaitingFormSpinner();
this.elementsOfForm.showInvalidArgumentMessageBox(data.getProp('messageRoot'));
}
})
.catch(e => {
this.rows = [];
this.elementsOfForm.showErrorMessageBox(e);
this.elementsOfForm.closeWaitingFormSpinner();
});
}
deserializeData(data) {
this.elementsOfForm.deserializedResponse(data);
this.rows = data.getProp('lines');
this.hideAutoHideColumns();
this.lastResponse = { ...data, lines: undefined };
delete this.lastResponse.lines;
if (typeof this.onDeserializedData === 'function') {
this.onDeserializedData(data);
}
this.forceUpdate();
this.elementsOfForm.closeWaitingFormSpinner();
}
hideAutoHideColumns() {
const autoHidColumns = this.columns.filter(i => i.autoHideIfEmpty);
autoHidColumns.forEach(column => {
column.visible = this.rows.some(row => !column.isCellValueEmpty(row));
});
}
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 100;
}
else if (child.type === Columns_1.NumberOfCheckColumn) {
return 50;
}
else if (child.type === Columns_1.DateColumn) {
return 135;
}
else if (child.type === Columns_1.NumberColumn) {
return 100;
}
else if (child.type === Columns_1.AmountColumn) {
return 140;
}
else if (child.type === Columns_1.IdColumn) {
return 100;
}
return 100;
}
}
exports.ViewBargeFactory = ViewBargeFactory;