@nettyapps/ntybase 21.1.36 → 21.1.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4644,6 +4644,189 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImpor
|
|
|
4644
4644
|
args: [{ selector: 'ntybase-netty-apps-base', imports: [], template: `` }]
|
|
4645
4645
|
}], ctorParameters: () => [], propDecorators: { isFilterExpanded: [{ type: i0.Input, args: [{ isSignal: true, alias: "isFilterExpanded", required: false }] }, { type: i0.Output, args: ["isFilterExpandedChange"] }], filteredRecords: [{ type: i0.Output, args: ["filteredRecords"] }], filterSelectionChanged: [{ type: i0.Output, args: ["filterSelectionChanged"] }], refresh: [{ type: i0.Input, args: [{ isSignal: true, alias: "refresh", required: false }] }], fileName: [{ type: i0.Input, args: [{ isSignal: true, alias: "fileName", required: false }] }] } });
|
|
4646
4646
|
|
|
4647
|
+
class ParseLog {
|
|
4648
|
+
rowIndex = 0; // Excel line no (1-based)
|
|
4649
|
+
message = ""; // Error or info message (fallback)
|
|
4650
|
+
level = "INFO";
|
|
4651
|
+
messageKey; // i18n translation key
|
|
4652
|
+
messageParams; // parameters for translation
|
|
4653
|
+
init() {
|
|
4654
|
+
this.rowIndex = 0;
|
|
4655
|
+
this.message = "";
|
|
4656
|
+
this.level = "INFO";
|
|
4657
|
+
this.messageKey = undefined;
|
|
4658
|
+
this.messageParams = undefined;
|
|
4659
|
+
}
|
|
4660
|
+
compare(other) { return this; }
|
|
4661
|
+
getPK() { return this.rowIndex; }
|
|
4662
|
+
setPK(pk) { this.rowIndex = pk; }
|
|
4663
|
+
}
|
|
4664
|
+
|
|
4665
|
+
class ExcelParserError extends Error {
|
|
4666
|
+
key;
|
|
4667
|
+
params;
|
|
4668
|
+
constructor(key, params) {
|
|
4669
|
+
super(key);
|
|
4670
|
+
this.key = key;
|
|
4671
|
+
this.params = params;
|
|
4672
|
+
this.name = 'ExcelParserError';
|
|
4673
|
+
}
|
|
4674
|
+
}
|
|
4675
|
+
class ExcelParser {
|
|
4676
|
+
mappings;
|
|
4677
|
+
constructor(mappings) {
|
|
4678
|
+
this.mappings = mappings;
|
|
4679
|
+
}
|
|
4680
|
+
async parse(file, options) {
|
|
4681
|
+
// PERFORMANS: XLSX library only loads at parse time!
|
|
4682
|
+
const XLSX = await import('xlsx');
|
|
4683
|
+
const sheetIndex = options?.sheetIndex ?? 0;
|
|
4684
|
+
const headerRowIndex = options?.headerRowIndex ?? 0; // 0-based
|
|
4685
|
+
return new Promise((resolve, reject) => {
|
|
4686
|
+
const reader = new FileReader();
|
|
4687
|
+
reader.onload = (e) => {
|
|
4688
|
+
try {
|
|
4689
|
+
const data = new Uint8Array(e.target?.result);
|
|
4690
|
+
const workbook = XLSX.read(data, { type: 'array' });
|
|
4691
|
+
if (!workbook.SheetNames[sheetIndex]) {
|
|
4692
|
+
throw new ExcelParserError('@EXCEL_PARSER.sheetNotFound', { index: sheetIndex });
|
|
4693
|
+
}
|
|
4694
|
+
const sheetName = workbook.SheetNames[sheetIndex];
|
|
4695
|
+
const sheet = workbook.Sheets[sheetName];
|
|
4696
|
+
const rows = XLSX.utils.sheet_to_json(sheet, { header: 1 });
|
|
4697
|
+
const logs = [];
|
|
4698
|
+
const result = [];
|
|
4699
|
+
// Skip headerline
|
|
4700
|
+
const dataRows = rows.slice(headerRowIndex + 1);
|
|
4701
|
+
dataRows.forEach((row, i) => {
|
|
4702
|
+
// Skip empty lines
|
|
4703
|
+
if (!row || row.length === 0)
|
|
4704
|
+
return;
|
|
4705
|
+
const obj = {};
|
|
4706
|
+
let hasError = false;
|
|
4707
|
+
const actualRowIndex = headerRowIndex + i + 2; // Excel line no (1-based)
|
|
4708
|
+
this.mappings.forEach(m => {
|
|
4709
|
+
let rawValue = row[m.index];
|
|
4710
|
+
if ((rawValue === undefined || rawValue === null || rawValue === '') && m.defaultValue !== undefined) {
|
|
4711
|
+
rawValue = m.defaultValue;
|
|
4712
|
+
logs.push(Object.assign(new ParseLog(), {
|
|
4713
|
+
rowIndex: actualRowIndex,
|
|
4714
|
+
message: `Boş alan için default değer atandı: ${String(m.prop)}`,
|
|
4715
|
+
level: 'INFO',
|
|
4716
|
+
messageKey: '@EXCEL_PARSER.defaultValueSet',
|
|
4717
|
+
messageParams: { prop: String(m.prop) }
|
|
4718
|
+
}));
|
|
4719
|
+
}
|
|
4720
|
+
if (m.required && (rawValue === undefined || rawValue === null || rawValue === '')) {
|
|
4721
|
+
logs.push(Object.assign(new ParseLog(), {
|
|
4722
|
+
rowIndex: actualRowIndex,
|
|
4723
|
+
message: `Zorunlu alan boş: ${String(m.prop)}`,
|
|
4724
|
+
level: 'ERROR',
|
|
4725
|
+
messageKey: '@EXCEL_PARSER.requiredFieldMissing',
|
|
4726
|
+
messageParams: { prop: String(m.prop) }
|
|
4727
|
+
}));
|
|
4728
|
+
hasError = true;
|
|
4729
|
+
}
|
|
4730
|
+
try {
|
|
4731
|
+
obj[m.prop] = m.converter ? m.converter(rawValue) : rawValue;
|
|
4732
|
+
}
|
|
4733
|
+
catch (err) {
|
|
4734
|
+
logs.push(Object.assign(new ParseLog(), {
|
|
4735
|
+
rowIndex: actualRowIndex,
|
|
4736
|
+
message: `Tip dönüşüm hatası: ${String(m.prop)} -> ${rawValue}`,
|
|
4737
|
+
level: 'ERROR',
|
|
4738
|
+
messageKey: '@EXCEL_PARSER.conversionError',
|
|
4739
|
+
messageParams: { prop: String(m.prop), value: rawValue }
|
|
4740
|
+
}));
|
|
4741
|
+
hasError = true;
|
|
4742
|
+
}
|
|
4743
|
+
});
|
|
4744
|
+
if (!hasError) {
|
|
4745
|
+
result.push(obj);
|
|
4746
|
+
}
|
|
4747
|
+
else {
|
|
4748
|
+
logs.push(Object.assign(new ParseLog(), {
|
|
4749
|
+
rowIndex: actualRowIndex,
|
|
4750
|
+
message: `Satır atlandı`,
|
|
4751
|
+
level: 'WARN',
|
|
4752
|
+
messageKey: '@EXCEL_PARSER.rowSkipped'
|
|
4753
|
+
}));
|
|
4754
|
+
}
|
|
4755
|
+
});
|
|
4756
|
+
resolve({ data: result, logs });
|
|
4757
|
+
}
|
|
4758
|
+
catch (error) {
|
|
4759
|
+
reject(error);
|
|
4760
|
+
}
|
|
4761
|
+
};
|
|
4762
|
+
reader.onerror = () => reject(reader.error);
|
|
4763
|
+
reader.readAsArrayBuffer(file);
|
|
4764
|
+
});
|
|
4765
|
+
}
|
|
4766
|
+
async generateSampleExcel(options) {
|
|
4767
|
+
const sampleCount = options?.sampleCount ?? 5;
|
|
4768
|
+
const fileName = (options?.fileName ?? 'sample-import.xlsx').endsWith('.xlsx')
|
|
4769
|
+
? (options?.fileName ?? 'sample-import.xlsx')
|
|
4770
|
+
: `${options?.fileName}.xlsx`;
|
|
4771
|
+
const sheetName = (options?.sheetName ?? 'Sample').substring(0, 15);
|
|
4772
|
+
const XLSX = await import('xlsx');
|
|
4773
|
+
// Header row: property names according to column order
|
|
4774
|
+
const headers = this.mappings.map(m => m.headerName || String(m.prop));
|
|
4775
|
+
const rows = [];
|
|
4776
|
+
for (let i = 1; i <= sampleCount; i++) {
|
|
4777
|
+
const row = this.mappings.map(m => {
|
|
4778
|
+
if (m.sampleValue !== undefined) {
|
|
4779
|
+
// Use sampleValue if it exists
|
|
4780
|
+
return typeof m.sampleValue === 'function'
|
|
4781
|
+
? m.sampleValue(i) // if it's a function, generate value based on index
|
|
4782
|
+
: m.sampleValue; // if it's a constant value, use it directly
|
|
4783
|
+
}
|
|
4784
|
+
});
|
|
4785
|
+
rows.push(row);
|
|
4786
|
+
}
|
|
4787
|
+
const worksheet = XLSX.utils.aoa_to_sheet([headers, ...rows]);
|
|
4788
|
+
const workbook = XLSX.utils.book_new();
|
|
4789
|
+
XLSX.utils.book_append_sheet(workbook, worksheet, sheetName);
|
|
4790
|
+
XLSX.writeFile(workbook, fileName);
|
|
4791
|
+
}
|
|
4792
|
+
}
|
|
4793
|
+
|
|
4794
|
+
// converters.ts
|
|
4795
|
+
// Sayı dönüştürücü (hem . hem , destekler)
|
|
4796
|
+
const toNumber = (v) => {
|
|
4797
|
+
if (v == null || v === '')
|
|
4798
|
+
return null;
|
|
4799
|
+
const normalized = String(v).replace(',', '.');
|
|
4800
|
+
return parseFloat(normalized);
|
|
4801
|
+
};
|
|
4802
|
+
// Tarih dönüştürücü (gg/aa/yyyy formatı)
|
|
4803
|
+
const toDate = (v) => {
|
|
4804
|
+
if (!v)
|
|
4805
|
+
return null;
|
|
4806
|
+
const [day, month, year] = String(v).split('/');
|
|
4807
|
+
return new Date(Number(year), Number(month) - 1, Number(day));
|
|
4808
|
+
};
|
|
4809
|
+
// Boolean dönüştürücü (Evet/Hayır, True/False, 1/0)
|
|
4810
|
+
const toBoolean = (v) => {
|
|
4811
|
+
if (v == null || v === '')
|
|
4812
|
+
return null;
|
|
4813
|
+
const str = String(v).toLowerCase();
|
|
4814
|
+
return ['evet', 'true', '1', 'yes'].includes(str);
|
|
4815
|
+
};
|
|
4816
|
+
// String dönüştürücü (trim + uppercase)
|
|
4817
|
+
const toUpperString = (v) => {
|
|
4818
|
+
if (v == null)
|
|
4819
|
+
return null;
|
|
4820
|
+
return String(v).trim().toUpperCase();
|
|
4821
|
+
};
|
|
4822
|
+
// Enum dönüştürücü (Excel’deki string değerleri enum’a çevirir)
|
|
4823
|
+
const toEnum = (v, enumObj) => {
|
|
4824
|
+
if (!v)
|
|
4825
|
+
return null;
|
|
4826
|
+
const key = String(v).toUpperCase();
|
|
4827
|
+
return enumObj[key] ?? null;
|
|
4828
|
+
};
|
|
4829
|
+
|
|
4647
4830
|
/*
|
|
4648
4831
|
* Public API Surface of ntybase
|
|
4649
4832
|
*/
|
|
@@ -4652,5 +4835,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImpor
|
|
|
4652
4835
|
* Generated bundle index. Do not edit.
|
|
4653
4836
|
*/
|
|
4654
4837
|
|
|
4655
|
-
export { AlertService, AuthenticationGuard, AuthenticationInterceptor, AuthenticationService, ButtonRenderer, CanDeactivateGuard, CheckboxRenderer, CommonService, ConfirmDialog, CredentialsService, CurrentUserPreference, ENVIRONMENT_CONFIG, EnvironmentInfo, EnvironmentInfoService, ErrorAlert, ExcelImportBase, ForgotPassword, Guid, Login, LoginDto, MFACodeDto, MfaLogin, NettyAgGridBase, NettyAgGridListBase, NettyAgGridListFilterBase, NettyAgGridLogBase, NettyAgGridSaveBase, NettyAgGridService, NettyAppsBase, NettyAppsFilterBase, NettyBaseApp, NettyHelper, NettyImageService, NettyMenuService, NtyLoadingComponent, NtyLoadingInterceptor, NtyLoadingService, Ntybase, NtybaseModule, PageTitle, RangeDateTimeFilter, RangeNumberFilter, RangeStringFilter, UrlHelperService, ntyAuthenticationInterceptor };
|
|
4838
|
+
export { AlertService, AuthenticationGuard, AuthenticationInterceptor, AuthenticationService, ButtonRenderer, CanDeactivateGuard, CheckboxRenderer, CommonService, ConfirmDialog, CredentialsService, CurrentUserPreference, ENVIRONMENT_CONFIG, EnvironmentInfo, EnvironmentInfoService, ErrorAlert, ExcelImportBase, ExcelParser, ExcelParserError, ForgotPassword, Guid, Login, LoginDto, MFACodeDto, MfaLogin, NettyAgGridBase, NettyAgGridListBase, NettyAgGridListFilterBase, NettyAgGridLogBase, NettyAgGridSaveBase, NettyAgGridService, NettyAppsBase, NettyAppsFilterBase, NettyBaseApp, NettyHelper, NettyImageService, NettyMenuService, NtyLoadingComponent, NtyLoadingInterceptor, NtyLoadingService, Ntybase, NtybaseModule, PageTitle, ParseLog, RangeDateTimeFilter, RangeNumberFilter, RangeStringFilter, UrlHelperService, ntyAuthenticationInterceptor, toBoolean, toDate, toEnum, toNumber, toUpperString };
|
|
4656
4839
|
//# sourceMappingURL=nettyapps-ntybase.mjs.map
|