UNPKG

armisa-models

Version:
215 lines (214 loc) 9.82 kB
"use strict"; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _SimpleCodeListViewFactory_urls, _SimpleCodeListViewFactory_apiAxios; Object.defineProperty(exports, "__esModule", { value: true }); exports.SimpleCodeListViewFactory = void 0; const ElementsOfFormFactory_1 = require("../../Page/ElementsOfFormFactory"); class SimpleCodeListViewFactory { get any() { return this; } constructor(mainStateFactory, selfSimpleCode, onlyLastLevel, closeModal) { this.mainStateFactory = mainStateFactory; this.selfSimpleCode = selfSimpleCode; this.onlyLastLevel = onlyLastLevel; this.closeModal = closeModal; _SimpleCodeListViewFactory_urls.set(this, void 0); _SimpleCodeListViewFactory_apiAxios.set(this, void 0); this.forceUpdate = () => { }; this.selectedRowId = null; this.waitForLoad = false; this.currentFilterWaitForLoad = ''; this.rows = []; this.filter = ''; this.code = 0; this.searchParameter = { currentPage: 1, itemsPerPage: 20, totalPages: 0 }; this.selectPreviousRow = () => { for (let index = 0; index < this.rows.length; index++) { const row = this.rows[index]; if (row.id === this.selectedRowId && index > 0) { this.selectThisRow(this.rows[index - 1]); return; } } if (this.rows && this.rows.length > 0) { this.selectThisRow(this.rows[this.rows.length - 1]); } }; this.selectNextRow = () => { for (let index = 0; index < this.rows.length; index++) { const row = this.rows[index]; if (row.id === this.selectedRowId && index < this.rows.length - 1) { this.selectThisRow(this.rows[index + 1]); return; } } if (this.rows && this.rows.length > 0) { this.selectThisRow(this.rows[0]); } }; this.selectedRow = () => { return this.rows.find((i) => i.id > 0 && i.id === this.selectedRowId); }; this.currentRow = () => { return this.rows.find((i) => i.id > 0 && i.id === this.selectedRowId); }; this.setCurrentPage = (page) => { this.searchParameter.currentPage = page; this.searchListView(); }; this.selectThisRow = (row) => { this.selectedRowId = row.id; this.forceUpdate(); }; this._selectCurrentRowByCode = () => { if (this.rows && this.rows.length) { if (this.code === 0) { this.selectedRowId = this.rows[0].id; } else { const findRow = this.rows.find((i) => i.code === this.code); if (findRow) { this.selectedRowId = findRow.id; } } } }; this.exportToExcel = () => { if (__classPrivateFieldGet(this, _SimpleCodeListViewFactory_urls, "f").excel) { this.downloadFile(__classPrivateFieldGet(this, _SimpleCodeListViewFactory_urls, "f").excel, this.searchParameter, this.afterExportToExcelSuccess); } }; this.afterExportToExcelSuccess = (_response) => { //UtilityFile.blobExcel(response.data); }; this.downloadFile = (path, searchParametr, afterSuccess) => { // this.pageData.Eventing.trigger('form.waitLoading'); // const header: AxiosRequestConfig = { responseType: 'arraybuffer', headers: { Authorization: `bearer ${this.mainStateManager.Usering.accessToken}` } }; __classPrivateFieldGet(this, _SimpleCodeListViewFactory_apiAxios, "f") .post(path, searchParametr) .then((response) => { afterSuccess(response); this.forceUpdate(); }) .catch((error) => { console.error(error); this.forceUpdate(); }); }; this.searchListView = () => { this.waitForLoad = true; this.forceUpdate(); const searchParameter = { ...this.searchParameter }; if (this.filter !== '') { searchParameter.filter = this.filter; searchParameter.code = 0; searchParameter.currentPage = 1; } else { searchParameter.code = this.code; searchParameter.filter = ''; } __classPrivateFieldGet(this, _SimpleCodeListViewFactory_apiAxios, "f").get(__classPrivateFieldGet(this, _SimpleCodeListViewFactory_urls, "f").search, { params: searchParameter }) .then((response) => { this.searchParameter = { ...this.searchParameter, totalItems: response.data.searchParameter.totalItems, itemsPerPage: response.data.searchParameter.itemsPerPage, currentPage: response.data.searchParameter.currentPage, totalPages: response.data.searchParameter.totalPages, needTotalCount: response.data.searchParameter.needTotalCount, showAll: response.data.searchParameter.showAll, }; this.rows = response.data.rows; this._selectCurrentRowByCode(); this.waitForLoad = false; this.forceUpdate(); }) .catch((error) => { console.error(error); this.rows = []; this.forceUpdate(); }); }; this.acceptCurrentRow = () => { const currentRow = this.currentRow(); if (currentRow) { this.closeModal(); this.selfSimpleCode.focusToElement(); this.selfSimpleCode.onChangeHandlerCode(currentRow.code.toString()); this.selfSimpleCode.getCodeData(); } }; this.cancelForm = () => { this.closeModal(); this.selfSimpleCode.focusToElement(); }; this.mainStateManager = this.mainStateFactory.mainStateManager; __classPrivateFieldSet(this, _SimpleCodeListViewFactory_urls, selfSimpleCode.urls, "f"); __classPrivateFieldSet(this, _SimpleCodeListViewFactory_apiAxios, selfSimpleCode.apiAxios, "f"); this.elementsOfForm = new ElementsOfFormFactory_1.ElementsOfFormFactory(this.mainStateFactory); this.code = this.selfSimpleCode.code; } selectByPageup() { const selectedRow = this.rows.find((i) => i.id === this.selectedRowId); if (selectedRow) { const selectedRowIndex = this.rows.indexOf(selectedRow); if (selectedRowIndex - 10 < 0) { this.selectThisRow(this.rows[0]); return; } else { this.selectThisRow(this.rows[selectedRowIndex - 10]); return; } } } selectByPagedown() { const selectedRow = this.rows.find((i) => i.id === this.selectedRowId); if (selectedRow) { const selectedRowIndex = this.rows.indexOf(selectedRow); if (selectedRowIndex + 10 <= this.rows.length - 1) { this.selectThisRow(this.rows[selectedRowIndex + 10]); return; } else if (this.rows.length + 1 > selectedRowIndex && this.rows.length - 1 < selectedRowIndex + 10) { this.selectThisRow(this.rows[this.rows.length - 1]); return; } } if (this.rows.length >= 10) { this.selectThisRow(this.rows[10]); return; } else if (this.rows.length > 0 && this.rows.length < 10) { this.selectThisRow(this.rows[this.rows.length]); return; } } selectFirst() { if (this.rows.length > 0) { this.selectThisRow(this.rows[0]); } } selectLast() { if (this.rows.length > 0) { this.selectThisRow(this.rows[this.rows.length - 1]); } } } exports.SimpleCodeListViewFactory = SimpleCodeListViewFactory; _SimpleCodeListViewFactory_urls = new WeakMap(), _SimpleCodeListViewFactory_apiAxios = new WeakMap();