Aktif Şablon / Sektör:
${this.renderActiveTab()}
`; } renderActiveTab() { if (this.activeTab === 'dashboard') return this.renderDashboard(); if (this.activeTab === 'reports') return this.renderReports(); return this.renderEntityView(this.activeTab); } // --- DASHBOARD VIEW --- renderDashboard() { const stats = []; this.schema.entities.forEach(ent => { const count = (this.data[ent.id] || []).length; stats.push({ label: ent.pluralName || ent.name, val: count, unit: 'Kayıt' }); }); return `

Pano Özeti

${stats.map(s => `
${window.HH.escapeHtml(s.label)}
${s.val} ${s.unit}
`).join('')}

Hızlı Başlangıç & İşlemler

Üst menüden yönetmek istediğiniz modüle geçiş yaparak yeni kayıt ekleyebilir, arama yapabilir ve Excel formatında dışa aktarabilirsiniz.

${this.schema.entities.map(ent => ` `).join('')}
`; } // --- ENTITY CRUD VIEW --- renderEntityView(entityId) { const entity = this.schema.entities.find(e => e.id === entityId); if (!entity) return 'Modül bulunamadı.'; const records = (this.data[entityId] || []).map(r => this.processRecord(entityId, r)); const fields = entity.fields || []; return `

Yeni ${window.HH.escapeHtml(entity.name)} Ekle

${fields.map(f => this.renderFormField(f, entityId)).join('')}

${window.HH.escapeHtml(entity.pluralName || entity.name)} Listesi (${records.length})

${fields.map(f => ``).join('')} ${this.schema.calculations && this.schema.calculations[entityId] ? Object.keys(this.schema.calculations[entityId]).map(c => ``).join('') : ''} ${records.map(r => ` ${fields.map(f => ``).join('')} ${this.schema.calculations && this.schema.calculations[entityId] ? Object.keys(this.schema.calculations[entityId]).map(c => ``).join('') : ''} `).join('') || ''}
${window.HH.escapeHtml(f.label)}${window.HH.escapeHtml(c)}İşlem
${this.formatFieldValue(r[f.id], f)}${r[c] !== undefined ? (typeof r[c] === 'number' ? r[c].toFixed(2) : r[c]) : '—'}
Henüz kayıt bulunmamaktadır.
`; } renderFormField(field, entityId) { const fid = field.id; const req = field.required ? 'required' : ''; let inputHtml = ''; if (field.type === 'select') { inputHtml = ` `; } else if (field.type === 'relation') { const targetEntity = field.targetEntity; const targetRecords = this.data[targetEntity] || []; inputHtml = ` `; } else if (field.type === 'textarea') { inputHtml = ``; } else { const inputType = field.type === 'money' || field.type === 'number' ? 'number' : field.type === 'date' ? 'date' : 'text'; const step = field.type === 'money' || field.type === 'number' ? 'step="0.01"' : ''; inputHtml = ``; } return `
${inputHtml}
`; } formatFieldValue(val, field) { if (val === null || val === undefined || val === '') return '—'; if (field.type === 'money') return window.HH.IntegerMoney.format(val); if (field.type === 'relation') { const target = (this.data[field.targetEntity] || []).find(r => r.id === val); return target ? window.HH.escapeHtml(target.name || target.title || val) : window.HH.escapeHtml(val); } return window.HH.escapeHtml(String(val)); } // --- REPORTS VIEW --- renderReports() { const reports = this.schema.reports || []; return `

Dönemsel Yönetim Raporları

${reports.map(rep => { const entId = rep.entity; const records = (this.data[entId] || []).map(r => this.processRecord(entId, r)); const sumVal = records.reduce((acc, cur) => acc + (parseFloat(cur[rep.sumField]) || 0), 0); return `

${window.HH.escapeHtml(rep.title)}

Gruplama: ${window.HH.escapeHtml(rep.groupBy || 'Genel')} · Toplam: ${window.HH.IntegerMoney.format(sumVal)}

${records.map(r => ` `).join('') || ''}
Kayıt ${window.HH.escapeHtml(rep.sumField)}
${window.HH.escapeHtml(r.name || r.description || r.id)} ${window.HH.IntegerMoney.format(r[rep.sumField] || 0)}
Veri yok
`; }).join('')}
`; } // --- ACTIONS & EVENTS --- switchTab(tabId) { this.activeTab = tabId; this.render(); this.bindEvents(); } async addRecord(entityId, formData) { const record = { id: window.HH.uid(entityId + '_'), createdAt: new Date().toISOString() }; for (const [k, v] of formData.entries()) { const fDef = (this.schema.entities.find(e => e.id === entityId)?.fields || []).find(f => f.id === k); if (fDef && (fDef.type === 'number' || fDef.type === 'money')) { record[k] = parseFloat(v) || 0; } else { record[k] = v; } } if (this.hooks.beforeSave) { this.hooks.beforeSave(entityId, record); } this.data[entityId].push(record); await this.saveData(); if (this.hooks.afterSave) { this.hooks.afterSave(entityId, record); } if (window.HH && window.HH.AuditLogger) { window.HH.AuditLogger.log(entityId.toUpperCase(), 'CREATE', `Kayıt eklendi (ID: ${record.id})`); } window.HH.UI.toast('Kayıt başarıyla eklendi.', 'success'); this.render(); this.bindEvents(); } async deleteRecord(entityId, recordId) { window.HH.UI.confirm('Kayıt Silinecek', 'Bu kaydı silmek istediğinize emin misiniz?', async () => { this.data[entityId] = this.data[entityId].filter(r => r.id !== recordId); await this.saveData(); if (window.HH && window.HH.AuditLogger) { window.HH.AuditLogger.log(entityId.toUpperCase(), 'DELETE', `Kayıt silindi (ID: ${recordId})`); } window.HH.UI.toast('Kayıt silindi.', 'info'); this.render(); this.bindEvents(); }); } bindEvents() { // Tab clicks all('.tab-btn').forEach(btn => { btn.onclick = () => this.switchTab(btn.dataset.tab); }); // Form submit const form = document.getElementById('schemaEntityForm'); if (form) { form.onsubmit = e => { e.preventDefault(); const entId = form.dataset.entity; this.addRecord(entId, new FormData(form)); }; } // Exports const btnExpJson = document.getElementById('btnDomainExportJson'); if (btnExpJson) { btnExpJson.onclick = () => { window.HH.BackupManager.exportJSON(this.data, `${this.schema.domain.id}_yedek`, this.schema.domain.name); }; } const btnExpCsv = document.getElementById('btnDomainExportCsv'); if (btnExpCsv) { btnExpCsv.onclick = () => { // Export active entity records as CSV const entId = this.activeTab === 'dashboard' || this.activeTab === 'reports' ? this.schema.entities[0].id : this.activeTab; const entity = this.schema.entities.find(e => e.id === entId); const fields = entity.fields || []; const headers = ['ID', ...fields.map(f => f.label), 'Tarih']; const rows = (this.data[entId] || []).map(r => [ r.id, ...fields.map(f => r[f.id] ?? ''), r.createdAt || '' ]); window.HH.BackupManager.exportCSV(headers, rows, `${entId}_rapor`); }; } const btnPrint = document.getElementById('btnDomainPrint'); if (btnPrint) { btnPrint.onclick = () => window.print(); } } } // Export to HH if (global.HH) { global.HH.SchemaEngine = SchemaEngine; } else { global.SchemaEngine = SchemaEngine; } })(typeof window !== 'undefined' ? window : globalThis);