@initsolusidigital/worksuite-shell 0.0.0-stage → 0.3.0

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.
Files changed (75) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +122 -2
  3. package/package.json +44 -4
  4. package/src/components/ai/AppAssistantDraft.vue +120 -0
  5. package/src/components/ai/AppAssistantWidget.vue +245 -0
  6. package/src/components/ai/AppCitedAnswer.vue +86 -0
  7. package/src/components/approvals/AppApprovalInbox.vue +265 -0
  8. package/src/components/approvals/AppApprovalSubjectModal.vue +197 -0
  9. package/src/components/chat/AppChatBubble.vue +324 -0
  10. package/src/components/chat/AppChatList.vue +249 -0
  11. package/src/components/chat/AppChatPanel.vue +315 -0
  12. package/src/components/chat/AppChatWidget.vue +126 -0
  13. package/src/components/communications/AppChannelBadge.vue +47 -0
  14. package/src/components/communications/AppConversationThread.vue +439 -0
  15. package/src/components/customFields/CustomFieldFilterPanel.vue +50 -0
  16. package/src/components/customFields/CustomFieldInput.vue +422 -0
  17. package/src/components/customFields/CustomFieldValue.vue +129 -0
  18. package/src/components/customFields/CustomFieldsSection.vue +65 -0
  19. package/src/components/customFields/fieldTypes.js +23 -0
  20. package/src/components/dashboard/AppCustomWidget.vue +138 -0
  21. package/src/components/dashboard/AppCustomWidgetForm.vue +173 -0
  22. package/src/components/dashboard/AppDashboardGrid.vue +200 -0
  23. package/src/components/dashboard/AppDashboardToolbar.vue +66 -0
  24. package/src/components/dashboard/AppSubAppsCatalog.vue +89 -0
  25. package/src/components/dataTools/AppImportExport.vue +724 -0
  26. package/src/components/dataTools/AppImportSchemaGuide.vue +130 -0
  27. package/src/components/hrMetrics/AppHrMetricsDashboard.vue +231 -0
  28. package/src/components/hrMetrics/AppHrMetricsEmployees.vue +87 -0
  29. package/src/components/hrMetrics/AppHrMetricsStat.vue +61 -0
  30. package/src/components/kpi/AppKpiAppraisalConfig.vue +284 -0
  31. package/src/components/kpi/AppKpiAppraisals.vue +733 -0
  32. package/src/components/kpi/AppKpiDefinitionModal.vue +317 -0
  33. package/src/components/kpi/AppKpiEntryModal.vue +122 -0
  34. package/src/components/kpi/AppKpiLeaderboard.vue +108 -0
  35. package/src/components/kpi/AppKpiMyCard.vue +134 -0
  36. package/src/components/kpi/AppKpiPeriodPicker.vue +115 -0
  37. package/src/components/kpi/AppKpiReportTable.vue +214 -0
  38. package/src/components/kpi/AppKpiScorecard.vue +242 -0
  39. package/src/components/kpi/AppKpiTargetsModal.vue +299 -0
  40. package/src/components/kpi/AppKpiTeam.vue +221 -0
  41. package/src/components/kpi/AppKpiWeightProfiles.vue +244 -0
  42. package/src/components/kpi/AppKpiWorkspace.vue +479 -0
  43. package/src/components/layout/AppGlobalSearch.vue +149 -0
  44. package/src/components/layout/AppLanguagePopup.vue +94 -0
  45. package/src/components/layout/AppLauncherPopup.vue +147 -0
  46. package/src/components/layout/AppLegalConsentModal.vue +484 -0
  47. package/src/components/layout/AppNavbar.vue +402 -0
  48. package/src/components/layout/AppNotificationContent.vue +173 -0
  49. package/src/components/layout/AppNotificationDrawer.vue +98 -0
  50. package/src/components/layout/AppNotificationPopup.vue +67 -0
  51. package/src/components/layout/AppPlatformBanners.vue +192 -0
  52. package/src/components/layout/AppSidebar.vue +226 -0
  53. package/src/components/layout/AppSidebarNav.vue +119 -0
  54. package/src/components/layout/AppUserMenu.vue +89 -0
  55. package/src/components/layout/AppUserMenuContent.vue +59 -0
  56. package/src/composables/useKpi.js +232 -0
  57. package/src/composables/useLgViewport.js +25 -0
  58. package/src/composables/useNavigation.js +177 -0
  59. package/src/layouts/AppLayout.vue +207 -0
  60. package/src/locales/en.json +1362 -0
  61. package/src/locales/id.json +1396 -0
  62. package/src/pages/auth/AccountBlocked.vue +55 -0
  63. package/src/pages/auth/IdentityRedirect.vue +37 -0
  64. package/src/pages/profile/Layout.vue +210 -0
  65. package/src/pages/profile/partials/AccountSection.vue +139 -0
  66. package/src/pages/profile/partials/ApprovalDelegationSection.vue +389 -0
  67. package/src/pages/profile/partials/DevicesCard.vue +222 -0
  68. package/src/pages/profile/partials/PreferencesSection.vue +87 -0
  69. package/src/pages/profile/partials/SecuritySection.vue +93 -0
  70. package/src/pages/profile/partials/SessionsCard.vue +418 -0
  71. package/src/pages/profile/partials/SessionsSection.vue +58 -0
  72. package/src/pages/profile/partials/SupportAccessSection.vue +173 -0
  73. package/src/pages/profile/partials/TrustedDevicesCard.vue +141 -0
  74. package/src/pages/profile/partials/TwoFactorSection.vue +304 -0
  75. package/src/shellSetup.js +46 -0
@@ -0,0 +1,479 @@
1
+ <script setup>
2
+ // Permukaan KPI lengkap — Laporan · Definisi · Leaderboard · Tim Saya · Bobot · Penilaian ·
3
+ // Konfigurasi Penilaian (empat terakhir hanya di app ber-master karyawan, `hrisSurface`).
4
+ //
5
+ // **Satu komponen untuk tiga app** (HRIS tingkat 2, CRM & Project tingkat 1) karena bedanya
6
+ // bukan bentuk layar melainkan IZIN, dan izin itu sudah ditegakkan server: `catalog` hanya
7
+ // mengembalikan definisi yang boleh dibaca, `report` hanya baris yang boleh dilihat, dan
8
+ // `leaderboard` menjawab 403 untuk yang bukan manajemen. Membangun tiga layar kembar hanya
9
+ // melahirkan tiga tempat yang harus ingat aturan yang sama.
10
+ //
11
+ // Halaman pemanggil tinggal membungkusnya dengan `AppLayout` + judul modulnya sendiri.
12
+ import { ref, computed, onMounted, watch } from 'vue'
13
+ import { useI18n } from 'vue-i18n'
14
+ import { kpiApi } from '@initsolusidigital/worksuite-core/api/endpoints/kpi.js'
15
+ import { useKpi } from '../../composables/useKpi.js'
16
+ import { useFormSubmit } from '@initsolusidigital/worksuite-core/composables/useFormSubmit.js'
17
+ import { normalizeApiError } from '@initsolusidigital/worksuite-core/api/errors.js'
18
+ import { ArrowDown, ArrowUp, Target, Plus } from '@lucide/vue'
19
+ import AppCard from '@initsolusidigital/worksuite-ui/AppCard.vue'
20
+ import AppTabs from '@initsolusidigital/worksuite-ui/AppTabs.vue'
21
+ import AppButton from '@initsolusidigital/worksuite-ui/AppButton.vue'
22
+ import AppBadge from '@initsolusidigital/worksuite-ui/AppBadge.vue'
23
+ import AppAlert from '@initsolusidigital/worksuite-ui/AppAlert.vue'
24
+ import AppCombobox from '@initsolusidigital/worksuite-ui/AppCombobox.vue'
25
+ import AppModal from '@initsolusidigital/worksuite-ui/AppModal.vue'
26
+ import AppSpinner from '@initsolusidigital/worksuite-ui/AppSpinner.vue'
27
+ import AppEmptyState from '@initsolusidigital/worksuite-ui/AppEmptyState.vue'
28
+ import AppKpiPeriodPicker from './AppKpiPeriodPicker.vue'
29
+ import AppKpiReportTable from './AppKpiReportTable.vue'
30
+ import AppKpiDefinitionModal from './AppKpiDefinitionModal.vue'
31
+ import AppKpiTargetsModal from './AppKpiTargetsModal.vue'
32
+ import AppKpiEntryModal from './AppKpiEntryModal.vue'
33
+ import AppKpiLeaderboard from './AppKpiLeaderboard.vue'
34
+ import AppKpiWeightProfiles from './AppKpiWeightProfiles.vue'
35
+ import AppKpiAppraisals from './AppKpiAppraisals.vue'
36
+ import AppKpiTeam from './AppKpiTeam.vue'
37
+ import AppKpiAppraisalConfig from './AppKpiAppraisalConfig.vue'
38
+
39
+ const props = defineProps({
40
+ companyId: { type: String, required: true },
41
+ /** Daftar jabatan `{value,label}` untuk penambat jobdesk — hanya app yang punya masternya. */
42
+ occupations: { type: Array, default: () => [] },
43
+ /**
44
+ * Tab **Bobot** & **Penilaian** hanya masuk akal di app yang punya master JABATAN & KARYAWAN
45
+ * (hari ini HRIS): bobot melekat pada occupation, appraisal pada employee + atasan langsung.
46
+ * Di app tingkat 1 keduanya tak dirender sama sekali — bukan dirender lalu kosong.
47
+ */
48
+ hrisSurface: { type: Boolean, default: false },
49
+ /** Karyawan `{value,label}` — pemilih subjek appraisal. */
50
+ employees: { type: Array, default: () => [] },
51
+ /** `employees.id` user yang login; penentu tombol Acknowledge. */
52
+ myEmployeeId: { type: String, default: '' },
53
+ /** Template berita acara jenis `appraisal` `{value,label}` (dipasok app, paket tak kenal doc-gen). */
54
+ appraisalTemplates: { type: Array, default: () => [] },
55
+ /** Boleh mengelola siklus appraisal (`kpis,can_update` / super admin). */
56
+ canManageAppraisals: { type: Boolean, default: false },
57
+ /** `kpis,can_configure` — tab Konfigurasi Penilaian (master aspek + bobot nilai akhir). */
58
+ canConfigureAppraisal: { type: Boolean, default: false },
59
+ /** Departemen `{value,label}` untuk aspek ber-`applies_to: department`. */
60
+ departments: { type: Array, default: () => [] },
61
+ })
62
+ const emit = defineEmits(['open-document'])
63
+
64
+ const { t } = useI18n()
65
+ const kpi = useKpi(() => props.companyId)
66
+ const aksi = useFormSubmit()
67
+
68
+ const tab = ref('report')
69
+ const period = ref('')
70
+ const definitionFilter = ref('')
71
+ const includeInactive = ref(false)
72
+
73
+ const editing = ref(null) // definisi yang diubah / {} untuk baru
74
+ const targeting = ref(null) // definisi yang dipasangi target
75
+ const targetingPreset = ref(null) // `{subject, target}` saat dibuka dari Tim / baris Laporan
76
+ const teamCount = ref(0) // > 0 = pemanggil memimpin orang → tab Tim Saya
77
+ const openAppraisalId = ref('')
78
+ const entering = ref(null) // baris laporan yang diisi realisasinya
79
+ const enteringPeriod = ref('') // periode form isian bila dibuka dari luar tab Laporan
80
+ const confirmDelete = ref(null)
81
+ const refreshToken = ref(0) // dinaikkan tiap isian tersimpan → scorecard appraisal dimuat ulang
82
+
83
+ const lbDefinition = ref('')
84
+ const lbRows = ref([])
85
+ const lbDepartments = ref([])
86
+ const lbLoading = ref(false)
87
+ const lbError = ref('')
88
+ const lbAllowed = ref(true)
89
+
90
+ const tabs = computed(() => [
91
+ { key: 'report', label: t('kpi.tab.report') },
92
+ { key: 'definitions', label: t('kpi.tab.definitions') },
93
+ ...(lbAllowed.value ? [{ key: 'leaderboard', label: t('kpi.tab.leaderboard') }] : []),
94
+ ...(props.hrisSurface && teamCount.value > 0 ? [{ key: 'team', label: t('kpi.tab.team') }] : []),
95
+ ...(props.hrisSurface ? [
96
+ { key: 'weights', label: t('kpi.tab.weights') },
97
+ { key: 'appraisals', label: t('kpi.tab.appraisals') },
98
+ ] : []),
99
+ ...(props.hrisSurface && props.canConfigureAppraisal ? [{ key: 'appraisalConfig', label: t('kpi.tab.appraisalConfig') }] : []),
100
+ ])
101
+
102
+ /**
103
+ * Pemanggil memimpin orang? Ditanyakan SEKALI lewat `/kpi/team` bulan berjalan — tab Tim Saya hanya
104
+ * dirender bila ada anggota, sebab tab yang selalu kosong bagi karyawan biasa terbaca sebagai fitur
105
+ * rusak. 403 (tenant tanpa `kpis`) = tak ada tim, bukan galat yang perlu ditampilkan.
106
+ */
107
+ async function cekTim() {
108
+ if (!props.hrisSurface) return
109
+ const d = new Date()
110
+ try {
111
+ const { data } = await kpiApi.team(props.companyId, { period: `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}` })
112
+ teamCount.value = (data.data ?? data).members?.length ?? 0
113
+ } catch { teamCount.value = 0 }
114
+ }
115
+
116
+ const definitionOptions = computed(() => [
117
+ { value: '', label: t('kpi.report.allDefinitions') },
118
+ ...kpi.activeDefinitions.value.map(d => ({ value: d.id, label: kpi.definitionLabel(d) })),
119
+ ])
120
+ const lbDefinitionOptions = computed(() =>
121
+ kpi.activeDefinitions.value.map(d => ({ value: d.id, label: kpi.definitionLabel(d) })))
122
+
123
+ /** Ada minimal satu definisi yang boleh dikelola → tombol "KPI baru" pantas ditawarkan. */
124
+ const bisaKelola = computed(() =>
125
+ kpi.definitions.value.some(d => d.can_manage) || kpi.resolvers.value.length > 0)
126
+
127
+ function muatLaporan() {
128
+ if (!period.value) return
129
+ kpi.fetchReport({
130
+ period: period.value,
131
+ ...(definitionFilter.value ? { definition_id: definitionFilter.value } : {}),
132
+ })
133
+ }
134
+
135
+ async function muatLeaderboard() {
136
+ if (!lbDefinition.value || !period.value) return
137
+ lbLoading.value = true
138
+ lbError.value = ''
139
+ try {
140
+ const { data } = await kpiApi.leaderboard(props.companyId, {
141
+ definition_id: lbDefinition.value,
142
+ period: period.value,
143
+ })
144
+ const body = data.data ?? data
145
+ lbRows.value = body.rows ?? []
146
+ lbDepartments.value = body.by_department ?? []
147
+ } catch (err) {
148
+ const e = normalizeApiError(err)
149
+ // 403 di sini bukan kerusakan melainkan kebijakan: papan peringkat lintas-orang menuntut
150
+ // izin manajemen. Tabnya dicabut supaya tak ditawarkan lagi di sesi ini.
151
+ if (e.isForbidden) {
152
+ lbAllowed.value = false
153
+ if (tab.value === 'leaderboard') tab.value = 'report'
154
+ } else {
155
+ lbError.value = e.backendMessage || t('common.serverError')
156
+ }
157
+ lbRows.value = []
158
+ lbDepartments.value = []
159
+ } finally {
160
+ lbLoading.value = false
161
+ }
162
+ }
163
+
164
+ onMounted(async () => {
165
+ await kpi.fetchCatalog(includeInactive.value)
166
+ await kpi.fetchSubjects()
167
+ if (!lbDefinition.value) lbDefinition.value = kpi.activeDefinitions.value[0]?.id ?? ''
168
+ await cekTim()
169
+ })
170
+
171
+ watch([period, definitionFilter], muatLaporan)
172
+ watch([tab, lbDefinition, period], () => { if (tab.value === 'leaderboard') muatLeaderboard() })
173
+ watch(includeInactive, (v) => kpi.fetchCatalog(v))
174
+
175
+ async function hapusDefinisi() {
176
+ const def = confirmDelete.value
177
+ const ok = await aksi.submit(
178
+ () => kpiApi.deleteDefinition(props.companyId, def.id),
179
+ {
180
+ successKey: 'kpi.form.deleted',
181
+ onError: (e) => {
182
+ // `has_data` bukan kegagalan yang bisa diulang — jalan keluarnya menonaktifkan,
183
+ // dan pesannya mengatakan itu alih-alih menyuruh mencoba lagi.
184
+ if (e.reason === 'has_data') aksi.formError.value = t('kpi.form.errHasData')
185
+ },
186
+ },
187
+ )
188
+ confirmDelete.value = null
189
+ if (ok) kpi.fetchCatalog(includeInactive.value)
190
+ }
191
+
192
+ /**
193
+ * Form target untuk SATU subjek (dari Tim / baris Laporan). Definisi diambil dari katalog bila ada
194
+ * — baris laporan & tim tak membawa `percent_bounded`/pengali, yang dibutuhkan pratinjau tier.
195
+ * Mode pimpinan = definisi yang tak boleh dikelola pemanggil (bobot override disembunyikan).
196
+ */
197
+ function aturTarget({ definition, subject, target }) {
198
+ targeting.value = kpi.definitions.value.find(d => d.id === definition.id) ?? definition
199
+ targetingPreset.value = { subject, target }
200
+ }
201
+ function targetDariLaporan(row) {
202
+ aturTarget({
203
+ definition: row.definition,
204
+ subject: { type: row.subject_type, id: row.subject_id, label: row.subject_name },
205
+ target: row.target,
206
+ })
207
+ }
208
+ function tutupTarget() { targeting.value = null; targetingPreset.value = null }
209
+
210
+ function bukaPenilaian(id) {
211
+ tab.value = 'appraisals'
212
+ openAppraisalId.value = ''
213
+ // Diset sesudah nilai dikosongkan supaya membuka siklus yang SAMA dua kali tetap memicu watch.
214
+ setTimeout(() => { openAppraisalId.value = id })
215
+ }
216
+
217
+ function sesudahSimpan() {
218
+ editing.value = null
219
+ targeting.value = null
220
+ targetingPreset.value = null
221
+ entering.value = null
222
+ enteringPeriod.value = ''
223
+ refreshToken.value++
224
+ kpi.fetchCatalog(includeInactive.value)
225
+ muatLaporan()
226
+ }
227
+
228
+ function isiDariLaporan(row) {
229
+ enteringPeriod.value = ''
230
+ entering.value = row
231
+ }
232
+
233
+ /**
234
+ * KPI belum diisi yang ditunjuk Penilaian (scorecard / 422 `scorecard_incomplete`). Bentuk barisnya
235
+ * disusun dari katalog karena `missing[]` hanya membawa id-kode-nama-periode, sedangkan form isian
236
+ * butuh `metric_type`/`allow_na` definisinya. KPI yang tak ada di katalog atau ber-resolver tak
237
+ * diisi lewat form ini — pengguna diantar ke Laporan periode itu supaya tetap tahu harus ke mana.
238
+ */
239
+ function isiDariPenilaian(mi) {
240
+ const def = kpi.definitions.value.find(d => d.id === mi.kpi_definition_id)
241
+ if (!def || def.resolver_key) {
242
+ tab.value = 'report'
243
+ period.value = mi.period
244
+ definitionFilter.value = def ? def.id : ''
245
+ return
246
+ }
247
+ enteringPeriod.value = mi.period
248
+ entering.value = {
249
+ definition: def,
250
+ subject_type: 'employee',
251
+ subject_id: mi.employee_id,
252
+ subject_name: mi.employee_name,
253
+ }
254
+ }
255
+ </script>
256
+
257
+ <template>
258
+ <div>
259
+ <AppAlert v-if="kpi.catalogError.value" variant="error" class="mb-4">{{ kpi.catalogError.value }}</AppAlert>
260
+ <AppAlert v-if="aksi.formError.value" variant="error" class="mb-4">{{ aksi.formError.value }}</AppAlert>
261
+
262
+ <div class="bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm overflow-hidden mb-6">
263
+ <AppTabs :tabs="tabs" surface="card" :model-value="tab" @update:model-value="tab = $event" />
264
+
265
+ <div class="p-4 sm:p-5 flex flex-wrap items-start justify-between gap-3">
266
+ <AppKpiPeriodPicker v-model="period" />
267
+
268
+ <div class="flex flex-wrap items-center gap-2">
269
+ <div v-if="tab === 'report'" class="w-56">
270
+ <AppCombobox
271
+ v-model="definitionFilter"
272
+ :options="definitionOptions"
273
+ :aria-label="t('kpi.report.filterDefinition')"
274
+ dense
275
+ />
276
+ </div>
277
+ <div v-if="tab === 'leaderboard'" class="w-56">
278
+ <AppCombobox
279
+ v-model="lbDefinition"
280
+ :options="lbDefinitionOptions"
281
+ :aria-label="t('kpi.leaderboard.pickDefinition')"
282
+ hide-clear
283
+ dense
284
+ />
285
+ </div>
286
+ <AppButton v-if="tab === 'definitions' && bisaKelola" @click="editing = {}">
287
+ <Plus class="w-4 h-4" />{{ t('kpi.form.create') }}
288
+ </AppButton>
289
+ </div>
290
+ </div>
291
+ </div>
292
+
293
+ <!-- ── Laporan ────────────────────────────────────────────────────────── -->
294
+ <template v-if="tab === 'report'">
295
+ <AppAlert v-if="kpi.reportError.value" variant="error" class="mb-4">{{ kpi.reportError.value }}</AppAlert>
296
+
297
+ <AppCard
298
+ :title="t('kpi.report.title')"
299
+ :description="kpi.reportClosed.value ? t('kpi.report.closedHint') : t('kpi.report.openHint')"
300
+ padding="none"
301
+ title-tag="h3"
302
+ >
303
+ <AppKpiReportTable
304
+ :rows="kpi.rows.value"
305
+ :loading="kpi.loadingReport.value"
306
+ :format-metric="kpi.formatMetric"
307
+ :format-achievement="kpi.formatAchievement"
308
+ :format-score="kpi.formatScore"
309
+ :status-tone="kpi.statusTone"
310
+ :format-tiers="kpi.formatTiers"
311
+ :definition-label="kpi.definitionLabel"
312
+ :can-enter="bisaKelola"
313
+ @enter="isiDariLaporan"
314
+ @target="targetDariLaporan"
315
+ />
316
+ </AppCard>
317
+ </template>
318
+
319
+ <!-- ── Definisi ───────────────────────────────────────────────────────── -->
320
+ <template v-else-if="tab === 'definitions'">
321
+ <AppCard :title="t('kpi.definitions.title')" :description="t('kpi.definitions.subtitle')" padding="none" title-tag="h3">
322
+ <template #actions>
323
+ <label class="inline-flex items-center gap-2 text-xs text-gray-600 dark:text-gray-300">
324
+ <input v-model="includeInactive" type="checkbox" class="rounded border-gray-300 dark:border-gray-600">
325
+ {{ t('kpi.definitions.showInactive') }}
326
+ </label>
327
+ </template>
328
+
329
+ <div v-if="kpi.loadingCatalog.value" class="py-12 text-center"><AppSpinner /></div>
330
+
331
+ <div v-else-if="!kpi.definitions.value.length" class="p-6">
332
+ <AppEmptyState :label="t('kpi.definitions.empty')" :description="t('kpi.definitions.emptyHint')">
333
+ <template #icon><Target class="w-6 h-6 text-gray-400 dark:text-gray-500" :stroke-width="1.5" /></template>
334
+ </AppEmptyState>
335
+ </div>
336
+
337
+ <ul v-else class="divide-y divide-gray-100 dark:divide-gray-700">
338
+ <li v-for="d in kpi.definitions.value" :key="d.id" class="px-6 py-4 flex flex-wrap items-start gap-3">
339
+ <div class="min-w-0 grow">
340
+ <div class="flex items-center gap-1.5">
341
+ <component
342
+ :is="d.direction === 'down' ? ArrowDown : ArrowUp"
343
+ class="w-3.5 h-3.5 shrink-0"
344
+ :class="d.direction === 'down' ? 'text-blue-500' : 'text-gray-400'"
345
+ :aria-label="t(`kpi.direction.${d.direction || 'up'}`)"
346
+ />
347
+ <span class="text-sm text-gray-900 dark:text-white truncate">{{ kpi.definitionLabel(d) }}</span>
348
+ <AppBadge v-if="d.is_active === false" color="gray">{{ t('kpi.definitions.inactive') }}</AppBadge>
349
+ </div>
350
+ <p class="text-xs text-gray-500 dark:text-gray-400 mt-0.5">
351
+ {{ t(`kpi.metric.${d.metric_type}`) }}
352
+ · {{ d.resolver_key ? t('kpi.definitions.computed') : t('kpi.definitions.manual') }}
353
+ <template v-if="d.allow_na"> · {{ t('kpi.definitions.allowsNa') }}</template>
354
+ <template v-if="d.occupation?.name"> · {{ d.occupation.name }}</template>
355
+ </p>
356
+ <p v-if="d.description" class="text-xs text-gray-500 dark:text-gray-400 mt-0.5">{{ d.description }}</p>
357
+ </div>
358
+
359
+ <div v-if="d.can_manage" class="flex items-center gap-1 shrink-0">
360
+ <AppButton variant="secondary" size="sm" @click="targeting = d">{{ t('kpi.definitions.setTargets') }}</AppButton>
361
+ <AppButton variant="ghost" size="sm" @click="editing = d">{{ t('common.edit') }}</AppButton>
362
+ <AppButton variant="danger" size="sm" @click="confirmDelete = d">{{ t('common.delete') }}</AppButton>
363
+ </div>
364
+ </li>
365
+ </ul>
366
+ </AppCard>
367
+ </template>
368
+
369
+ <!-- ── Leaderboard ────────────────────────────────────────────────────── -->
370
+ <!-- ⚠️ `v-else-if` yang EKSPLISIT, bukan `v-else`: sejak ada tab Bobot & Penilaian, fallback
371
+ akan membuat kedua tab itu ikut merender leaderboard. -->
372
+ <AppKpiLeaderboard
373
+ v-else-if="tab === 'leaderboard'"
374
+ :definition="kpi.activeDefinitions.value.find(d => d.id === lbDefinition) ?? null"
375
+ :rows="lbRows"
376
+ :by-department="lbDepartments"
377
+ :loading="lbLoading"
378
+ :error="lbError"
379
+ :format-metric="kpi.formatMetric"
380
+ :format-achievement="kpi.formatAchievement"
381
+ :format-score="kpi.formatScore"
382
+ :status-tone="kpi.statusTone"
383
+ :definition-label="kpi.definitionLabel"
384
+ />
385
+
386
+ <!-- ── Profil bobot per jobdesk ───────────────────────────────────────── -->
387
+ <AppKpiWeightProfiles
388
+ v-else-if="tab === 'weights'"
389
+ :company-id="companyId"
390
+ :occupations="occupations"
391
+ :definitions="kpi.activeDefinitions.value"
392
+ :can-manage="bisaKelola"
393
+ />
394
+
395
+ <!-- ── Siklus penilaian ───────────────────────────────────────────────── -->
396
+ <AppKpiAppraisals
397
+ v-else-if="tab === 'appraisals'"
398
+ :company-id="companyId"
399
+ :employees="employees"
400
+ :can-manage="canManageAppraisals"
401
+ :my-employee-id="myEmployeeId"
402
+ :document-templates="appraisalTemplates"
403
+ :format-metric="kpi.formatMetric"
404
+ :format-achievement="kpi.formatAchievement"
405
+ :can-fill="bisaKelola || teamCount > 0"
406
+ :refresh-token="refreshToken"
407
+ :can-bulk="canManageAppraisals || teamCount > 0"
408
+ :period="period"
409
+ :open-id="openAppraisalId"
410
+ @open-document="emit('open-document', $event)"
411
+ @fill="isiDariPenilaian"
412
+ />
413
+
414
+ <!-- ── Tim Saya ───────────────────────────────────────────────────────── -->
415
+ <AppKpiTeam
416
+ v-else-if="tab === 'team'"
417
+ :company-id="companyId"
418
+ :period="period"
419
+ :definitions="kpi.definitions.value"
420
+ :refresh-token="refreshToken"
421
+ @enter="isiDariLaporan"
422
+ @target="aturTarget"
423
+ @open-appraisal="bukaPenilaian"
424
+ />
425
+
426
+ <!-- ── Konfigurasi penilaian ──────────────────────────────────────────── -->
427
+ <AppKpiAppraisalConfig
428
+ v-else-if="tab === 'appraisalConfig'"
429
+ :company-id="companyId"
430
+ :departments="departments"
431
+ />
432
+
433
+ <AppKpiDefinitionModal
434
+ v-if="editing"
435
+ :company-id="companyId"
436
+ :definition="editing.id ? editing : null"
437
+ :resolvers="kpi.resolvers.value"
438
+ :hris-tier="kpi.hrisTier.value"
439
+ :occupations="occupations"
440
+ :resolver-label="kpi.resolverLabel"
441
+ :resolver-description="kpi.resolverDescription"
442
+ @close="editing = null"
443
+ @saved="sesudahSimpan"
444
+ />
445
+
446
+ <AppKpiTargetsModal
447
+ v-if="targeting"
448
+ :company-id="companyId"
449
+ :definition="targeting"
450
+ :users="kpi.users.value"
451
+ :employees="kpi.employees.value"
452
+ :hris-tier="kpi.hrisTier.value"
453
+ :period="period"
454
+ :default-tiers="kpi.defaultTiers.value"
455
+ :leader-mode="!targeting.can_manage"
456
+ :preset-subject="targetingPreset?.subject ?? null"
457
+ :preset-values="targetingPreset ? { target: targetingPreset.target } : null"
458
+ @close="tutupTarget"
459
+ @saved="sesudahSimpan"
460
+ />
461
+
462
+ <AppKpiEntryModal
463
+ v-if="entering"
464
+ :company-id="companyId"
465
+ :row="entering"
466
+ :period="enteringPeriod || period"
467
+ @close="entering = null; enteringPeriod = ''"
468
+ @saved="sesudahSimpan"
469
+ />
470
+
471
+ <AppModal v-if="confirmDelete" :title="t('kpi.form.deleteTitle')" size="sm" @close="confirmDelete = null">
472
+ <p class="text-sm text-gray-600 dark:text-gray-300">{{ t('kpi.form.deleteBody', { name: confirmDelete.name }) }}</p>
473
+ <template #footer>
474
+ <AppButton variant="secondary" @click="confirmDelete = null">{{ t('common.cancel') }}</AppButton>
475
+ <AppButton variant="danger" :loading="aksi.saving.value" @click="hapusDefinisi">{{ t('common.delete') }}</AppButton>
476
+ </template>
477
+ </AppModal>
478
+ </div>
479
+ </template>
@@ -0,0 +1,149 @@
1
+ <script setup>
2
+ // Pencarian global — palet ala Ctrl/⌘+K di semua app staf. Hasil dikelompokkan
3
+ // per modul dan tiap hasil membawa `target_app` + `target_path` dari backend; navigasinya lewat
4
+ // `useCrossAppLink`, jadi app sendiri = router.push, app lain = tab baru (pagar N-A ikut berlaku).
5
+ //
6
+ // ⚠️ Balasan permintaan lama yang tiba belakangan dibuang lewat nomor urut — tanpa itu hasil "ab"
7
+ // bisa menimpa hasil "abc" yang sudah tampil, dan daftar berganti sendiri di depan mata pengguna.
8
+ import { ref, computed, watch, nextTick, onMounted, onUnmounted } from 'vue'
9
+ import { useI18n } from 'vue-i18n'
10
+ import { Search, X, CornerDownLeft } from '@lucide/vue'
11
+ import { useAuthStore } from '@initsolusidigital/worksuite-core/stores/auth.js'
12
+ import { useGlobalSearch } from '@initsolusidigital/worksuite-core/composables/useGlobalSearch.js'
13
+ import { useCrossAppLink } from '@initsolusidigital/worksuite-core/composables/useCrossAppLink.js'
14
+ import { globalSearchApi } from '@initsolusidigital/worksuite-core/api/endpoints/globalSearch.js'
15
+ import AppSpinner from '@initsolusidigital/worksuite-ui/AppSpinner.vue'
16
+
17
+ const { t, te } = useI18n()
18
+ const authStore = useAuthStore()
19
+ const { isOpen, openSearch, closeSearch } = useGlobalSearch()
20
+ const { openTarget, fetchApps } = useCrossAppLink()
21
+
22
+ const companyId = computed(() => authStore.user?.company?.id ?? authStore.user?.company_id)
23
+ const q = ref('')
24
+ const groups = ref([])
25
+ const loading = ref(false)
26
+ const error = ref('')
27
+ const inputEl = ref(null)
28
+ const activeIndex = ref(0)
29
+ let seq = 0
30
+ let timer = null
31
+
32
+ const flat = computed(() => groups.value.flatMap((g) => g.items.map((it) => ({ ...it, module: g.module }))))
33
+ const moduleLabel = (m) => (te(`modules.items.${m}`) ? t(`modules.items.${m}`) : m)
34
+
35
+ watch(q, (v) => {
36
+ clearTimeout(timer)
37
+ error.value = ''
38
+ if (v.trim().length < 2) { groups.value = []; loading.value = false; return }
39
+ loading.value = true
40
+ timer = setTimeout(() => run(v.trim()), 300)
41
+ })
42
+
43
+ async function run(term) {
44
+ const mine = ++seq
45
+ try {
46
+ const { data } = await globalSearchApi.search(companyId.value, term)
47
+ if (mine !== seq) return
48
+ groups.value = data?.data?.groups ?? []
49
+ activeIndex.value = 0
50
+ } catch (err) {
51
+ if (mine !== seq) return
52
+ groups.value = []
53
+ error.value = err?.response?.status === 429 ? t('search.tooFast') : t('search.error')
54
+ } finally {
55
+ if (mine === seq) loading.value = false
56
+ }
57
+ }
58
+
59
+ function go(item) {
60
+ if (!item) return
61
+ const ok = openTarget({ target_app: item.target_app, target_path: item.target_path }, { beforeNavigate: closeSearch })
62
+ if (ok) closeSearch()
63
+ else error.value = t('search.cannotOpen')
64
+ }
65
+
66
+ function onKey(e) {
67
+ if (e.key === 'ArrowDown') { e.preventDefault(); activeIndex.value = Math.min(activeIndex.value + 1, flat.value.length - 1) }
68
+ else if (e.key === 'ArrowUp') { e.preventDefault(); activeIndex.value = Math.max(activeIndex.value - 1, 0) }
69
+ else if (e.key === 'Enter') { e.preventDefault(); go(flat.value[activeIndex.value]) }
70
+ else if (e.key === 'Escape') closeSearch()
71
+ }
72
+
73
+ // Pintasan global. Ctrl/⌘+K dipakai juga sebagai "sisipkan tautan" di editor kaya teks, jadi
74
+ // pintasan diabaikan saat fokus ada di dalam editor `contenteditable`.
75
+ function onGlobalKey(e) {
76
+ if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === 'k') {
77
+ if (e.target?.closest?.('[contenteditable="true"]')) return
78
+ e.preventDefault()
79
+ isOpen.value ? closeSearch() : openSearch()
80
+ }
81
+ }
82
+ onMounted(() => window.addEventListener('keydown', onGlobalKey))
83
+ onUnmounted(() => window.removeEventListener('keydown', onGlobalKey))
84
+
85
+ watch(isOpen, async (open) => {
86
+ if (!open) return
87
+ fetchApps()
88
+ await nextTick()
89
+ inputEl.value?.focus()
90
+ inputEl.value?.select()
91
+ })
92
+
93
+ const indexOf = (item) => flat.value.findIndex((f) => f.module === item.module && f.id === item.id)
94
+ </script>
95
+
96
+ <template>
97
+ <Teleport to="body">
98
+ <div v-if="isOpen" class="fixed inset-0 z-[60] flex items-start justify-center px-4 pt-[12vh]" data-global-search>
99
+ <div class="absolute inset-0 bg-black/40 backdrop-blur-sm" @click="closeSearch"></div>
100
+ <div class="relative w-full max-w-xl rounded-xl bg-white dark:bg-gray-800 shadow-2xl border border-gray-200 dark:border-gray-700 overflow-hidden" role="dialog" aria-modal="true" :aria-label="t('search.title')">
101
+ <div class="flex items-center gap-2 px-4 border-b border-gray-200 dark:border-gray-700">
102
+ <Search class="w-4 h-4 text-gray-400 shrink-0" />
103
+ <input
104
+ ref="inputEl"
105
+ v-model="q"
106
+ type="text"
107
+ :placeholder="t('search.placeholder')"
108
+ :aria-label="t('search.title')"
109
+ role="combobox"
110
+ aria-autocomplete="list"
111
+ :aria-expanded="flat.length > 0"
112
+ aria-describedby="global-search-msg"
113
+ class="flex-1 py-3.5 text-sm bg-transparent text-gray-900 dark:text-white focus:outline-none"
114
+ @keydown="onKey"
115
+ />
116
+ <AppSpinner v-if="loading" size="sm" />
117
+ <button type="button" class="p-1 rounded text-gray-400 hover:text-gray-600" :aria-label="t('common.close')" @click="closeSearch"><X class="w-4 h-4" /></button>
118
+ </div>
119
+
120
+ <div class="max-h-[55vh] overflow-y-auto scrollbar-rounded" role="listbox">
121
+ <p v-if="error" id="global-search-msg" role="alert" class="px-4 py-3 text-sm text-red-600 dark:text-red-400">{{ error }}</p>
122
+ <p v-else-if="q.trim().length < 2" id="global-search-msg" class="px-4 py-6 text-sm text-center text-gray-400">{{ t('search.hint') }}</p>
123
+ <p v-else-if="!loading && !groups.length" id="global-search-msg" class="px-4 py-6 text-sm text-center text-gray-400" data-search-empty>{{ t('search.empty', { q: q.trim() }) }}</p>
124
+ <section v-for="g in groups" :key="g.module" class="py-1" :data-search-group="g.module">
125
+ <h3 class="px-4 pt-2 pb-1 text-[11px] font-semibold uppercase tracking-wide text-gray-400">{{ moduleLabel(g.module) }}</h3>
126
+ <button
127
+ v-for="it in g.items"
128
+ :key="it.id"
129
+ type="button"
130
+ role="option"
131
+ :aria-selected="flat[activeIndex]?.id === it.id && flat[activeIndex]?.module === g.module"
132
+ class="w-full text-left px-4 py-2 flex items-center gap-3"
133
+ :class="flat[activeIndex]?.id === it.id && flat[activeIndex]?.module === g.module ? 'bg-blue-50 dark:bg-blue-900/30' : 'hover:bg-gray-50 dark:hover:bg-gray-700/40'"
134
+ @mouseenter="activeIndex = indexOf({ ...it, module: g.module })"
135
+ @click="go({ ...it, module: g.module })"
136
+ >
137
+ <span class="min-w-0 flex-1">
138
+ <span class="block text-sm text-gray-900 dark:text-white truncate">{{ it.title || '—' }}</span>
139
+ <span v-if="it.subtitle" class="block text-xs text-gray-500 dark:text-gray-400 truncate">{{ it.subtitle }}</span>
140
+ </span>
141
+ <CornerDownLeft v-if="flat[activeIndex]?.id === it.id && flat[activeIndex]?.module === g.module" class="w-3.5 h-3.5 text-gray-400 shrink-0" />
142
+ </button>
143
+ </section>
144
+ </div>
145
+ <p class="px-4 py-2 border-t border-gray-100 dark:border-gray-700 text-[11px] text-gray-400">{{ t('search.footer') }}</p>
146
+ </div>
147
+ </div>
148
+ </Teleport>
149
+ </template>