wad-lab 1.1.6 → 1.1.8
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.
- package/package.json +1 -1
- package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/controller/CompanyController.java +88 -74
- package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/model/Employee.java +73 -73
- package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/service/CompanyService.java +90 -60
- package/templates/fullstack-springboot-vue/frontend/vue-axios-basic/src/App.vue +429 -405
- package/templates/fullstack-springboot-vue/frontend/vue-axios-interceptor/src/App.vue +177 -159
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia/src/App.vue +441 -427
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia/src/stores/companyStore.js +126 -96
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/App.vue +84 -69
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/components/DepartmentSection.vue +164 -152
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/components/EmployeeSection.vue +193 -181
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/stores/companyStore.js +126 -35
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/App.vue +191 -167
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/DepartmentForm.vue +98 -98
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/DepartmentList.vue +92 -91
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/EmployeeForm.vue +128 -128
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/EmployeeList.vue +95 -94
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/App.vue +90 -90
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/AddEmployeeView.vue +247 -247
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/DepartmentView.vue +296 -273
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/EmployeeView.vue +219 -196
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/HomeDashboardView.vue +263 -263
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/DepartmentListView.vue +250 -231
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/EmployeeDetailView.vue +181 -159
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/EmployeeListView.vue +315 -295
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/stores/companyStore.js +137 -70
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/views/DepartmentView.vue +229 -209
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/views/EmployeeView.vue +257 -237
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/components/EntityTable.vue +106 -92
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/stores/companyStore.js +139 -84
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/views/ManageDepartmentsView.vue +73 -64
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/views/ManageEmployeesView.vue +76 -67
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/App.vue +59 -59
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/components/DataCard.vue +72 -53
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/views/DepartmentPage.vue +89 -77
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/views/EmployeePage.vue +128 -116
- package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/controller/CompanyController.java +88 -74
- package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/model/Employee.java +73 -73
- package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/service/CompanyService.java +90 -60
- package/templates/springboot-course-registration/src/main/java/com/example/coursereg/controller/CourseController.java +46 -42
- package/templates/springboot-course-registration/src/main/java/com/example/coursereg/service/CourseService.java +70 -60
- package/templates/springboot-hospital-api/src/main/java/com/example/hospital/controller/HospitalController.java +54 -50
- package/templates/springboot-hospital-api/src/main/java/com/example/hospital/service/HospitalService.java +65 -54
- package/templates/springboot-library-api/src/main/java/com/example/library/controller/LibraryController.java +57 -51
- package/templates/springboot-library-api/src/main/java/com/example/library/service/LibraryService.java +70 -60
- package/templates/springboot-mockmvc/src/main/java/com/example/mockmvc/controller/ItemController.java +45 -41
- package/templates/springboot-mockmvc/src/main/java/com/example/mockmvc/service/ItemService.java +48 -38
- package/templates/springboot-mongo-aggregation/src/main/java/com/example/aggregation/controller/ItemController.java +45 -41
- package/templates/springboot-mongo-aggregation/src/main/java/com/example/aggregation/service/ItemService.java +48 -38
- package/templates/springboot-mongo-aggregation-mockmvc/src/main/java/com/example/aggmockmvc/controller/ItemController.java +45 -41
- package/templates/springboot-mongo-aggregation-mockmvc/src/main/java/com/example/aggmockmvc/service/ItemService.java +48 -38
- package/templates/springboot-mongo-crud/src/main/java/com/example/crud/controller/ItemController.java +45 -41
- package/templates/springboot-mongo-crud/src/main/java/com/example/crud/service/ItemService.java +48 -38
- package/templates/vue-axios/src/App.vue +264 -243
- package/templates/vue-axios/src/services/ItemService.js +27 -21
- package/templates/vue-axios-basic/src/App.vue +24 -0
- package/templates/vue-axios-interceptor/src/App.vue +177 -159
- package/templates/vue-axios-pinia/src/App.vue +14 -0
- package/templates/vue-axios-pinia/src/stores/companyStore.js +126 -96
- package/templates/vue-axios-pinia-props/src/App.vue +84 -69
- package/templates/vue-axios-pinia-props/src/components/DepartmentSection.vue +164 -152
- package/templates/vue-axios-pinia-props/src/components/EmployeeSection.vue +193 -181
- package/templates/vue-axios-pinia-props/src/stores/companyStore.js +126 -35
- package/templates/vue-axios-props-emits/src/App.vue +24 -0
- package/templates/vue-axios-props-emits/src/components/DepartmentList.vue +2 -1
- package/templates/vue-axios-props-emits/src/components/EmployeeList.vue +2 -1
- package/templates/vue-axios-router/src/views/DepartmentView.vue +23 -0
- package/templates/vue-axios-router/src/views/EmployeeView.vue +23 -0
- package/templates/vue-axios-router-children/src/views/DepartmentListView.vue +250 -231
- package/templates/vue-axios-router-children/src/views/EmployeeDetailView.vue +181 -159
- package/templates/vue-axios-router-children/src/views/EmployeeListView.vue +315 -295
- package/templates/vue-axios-router-pinia/src/stores/companyStore.js +137 -70
- package/templates/vue-axios-router-pinia/src/views/DepartmentView.vue +229 -209
- package/templates/vue-axios-router-pinia/src/views/EmployeeView.vue +257 -237
- package/templates/vue-axios-router-pinia-props/src/components/EntityTable.vue +106 -92
- package/templates/vue-axios-router-pinia-props/src/stores/companyStore.js +139 -84
- package/templates/vue-axios-router-pinia-props/src/views/ManageDepartmentsView.vue +73 -64
- package/templates/vue-axios-router-pinia-props/src/views/ManageEmployeesView.vue +76 -67
- package/templates/vue-axios-router-props/src/components/DataCard.vue +72 -53
- package/templates/vue-axios-router-props/src/views/DepartmentPage.vue +89 -77
- package/templates/vue-axios-router-props/src/views/EmployeePage.vue +128 -116
- package/templates/vue-fetch/src/App.vue +285 -259
- package/templates/vue-router-pinia-springboot/backend/src/main/java/com/example/crud/controller/ItemController.java +45 -41
- package/templates/vue-router-pinia-springboot/backend/src/main/java/com/example/crud/service/ItemService.java +45 -35
- package/templates/vue-router-pinia-springboot/frontend/src/services/ItemService.js +24 -21
- package/templates/vue-router-pinia-springboot/frontend/src/stores/itemStore.js +42 -37
- package/templates/vue-router-pinia-springboot/frontend/src/views/ListView.vue +76 -67
- package/templates/vue-springboot-mongo-aggregation/backend/src/main/java/com/example/aggregation/controller/ItemController.java +45 -41
- package/templates/vue-springboot-mongo-aggregation/backend/src/main/java/com/example/aggregation/service/ItemService.java +45 -35
- package/templates/vue-springboot-mongo-crud/backend/src/main/java/com/example/crud/controller/ItemController.java +45 -41
- package/templates/vue-springboot-mongo-crud/backend/src/main/java/com/example/crud/service/ItemService.java +45 -35
- package/templates/vue-springboot-mongo-crud/frontend/src/App.vue +158 -149
- package/templates/vue-springboot-mongo-crud/frontend/src/services/ItemService.js +24 -21
|
@@ -1,295 +1,315 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="employees-page">
|
|
3
|
-
<header class="page-header">
|
|
4
|
-
<h1>Employees</h1>
|
|
5
|
-
<p>Manage company employees and view their profiles.</p>
|
|
6
|
-
</header>
|
|
7
|
-
|
|
8
|
-
<section class="card form-card">
|
|
9
|
-
<h2>Add New Employee</h2>
|
|
10
|
-
<form @submit.prevent="createEmployee" class="form">
|
|
11
|
-
<div class="form-row">
|
|
12
|
-
<div class="form-group">
|
|
13
|
-
<label for="emp-name">Full Name</label>
|
|
14
|
-
<input
|
|
15
|
-
id="emp-name"
|
|
16
|
-
v-model="form.name"
|
|
17
|
-
type="text"
|
|
18
|
-
required
|
|
19
|
-
placeholder="e.g. Jane Doe"
|
|
20
|
-
/>
|
|
21
|
-
</div>
|
|
22
|
-
<div class="form-group">
|
|
23
|
-
<label for="emp-email">Email</label>
|
|
24
|
-
<input
|
|
25
|
-
id="emp-email"
|
|
26
|
-
v-model="form.email"
|
|
27
|
-
type="email"
|
|
28
|
-
required
|
|
29
|
-
placeholder="e.g. jane@example.com"
|
|
30
|
-
/>
|
|
31
|
-
</div>
|
|
32
|
-
</div>
|
|
33
|
-
<div class="form-row">
|
|
34
|
-
<div class="form-group">
|
|
35
|
-
<label for="emp-dept">Department</label>
|
|
36
|
-
<select id="emp-dept" v-model="form.departmentId" required>
|
|
37
|
-
<option value="" disabled>Select Department</option>
|
|
38
|
-
<option v-for="dept in departments" :key="dept.id" :value="dept.id">
|
|
39
|
-
{{ dept.name }} ({{ dept.code }})
|
|
40
|
-
</option>
|
|
41
|
-
</select>
|
|
42
|
-
</div>
|
|
43
|
-
<div class="form-group">
|
|
44
|
-
<label for="emp-salary">Salary</label>
|
|
45
|
-
<input
|
|
46
|
-
id="emp-salary"
|
|
47
|
-
v-model.number="form.salary"
|
|
48
|
-
type="number"
|
|
49
|
-
min="0"
|
|
50
|
-
step="any"
|
|
51
|
-
required
|
|
52
|
-
placeholder="e.g. 75000"
|
|
53
|
-
/>
|
|
54
|
-
</div>
|
|
55
|
-
</div>
|
|
56
|
-
<button type="submit" class="btn btn-primary">Add Employee</button>
|
|
57
|
-
</form>
|
|
58
|
-
</section>
|
|
59
|
-
|
|
60
|
-
<section class="card table-card">
|
|
61
|
-
<h2>All Employees</h2>
|
|
62
|
-
<table class="data-table">
|
|
63
|
-
<thead>
|
|
64
|
-
<tr>
|
|
65
|
-
<th>ID</th>
|
|
66
|
-
<th>Name</th>
|
|
67
|
-
<th>Email</th>
|
|
68
|
-
<th>Department</th>
|
|
69
|
-
<th>Salary</th>
|
|
70
|
-
<th>Actions</th>
|
|
71
|
-
</tr>
|
|
72
|
-
</thead>
|
|
73
|
-
<tbody>
|
|
74
|
-
<tr v-if="employees.length === 0">
|
|
75
|
-
<td colspan="6" class="empty">No employees found.</td>
|
|
76
|
-
</tr>
|
|
77
|
-
<tr v-for="emp in employees" :key="emp.id">
|
|
78
|
-
<td>{{ emp.id }}</td>
|
|
79
|
-
<td>{{ emp.name }}</td>
|
|
80
|
-
<td>{{ emp.email }}</td>
|
|
81
|
-
<td>{{ getDepartmentName(emp.departmentId) }}</td>
|
|
82
|
-
<td>${{ Number(emp.salary).toLocaleString() }}</td>
|
|
83
|
-
<td class="action-cell">
|
|
84
|
-
<router-link :to="'/company/employees/' + emp.id" class="btn btn-info">View</router-link>
|
|
85
|
-
<button @click="
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
</
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
import
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
form.
|
|
136
|
-
form.
|
|
137
|
-
form.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
await
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
margin-bottom:
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
padding: 8px
|
|
232
|
-
border:
|
|
233
|
-
border-radius: 6px;
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
.btn
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
color: #
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<div class="employees-page">
|
|
3
|
+
<header class="page-header">
|
|
4
|
+
<h1>Employees</h1>
|
|
5
|
+
<p>Manage company employees and view their profiles.</p>
|
|
6
|
+
</header>
|
|
7
|
+
|
|
8
|
+
<section class="card form-card">
|
|
9
|
+
<h2>Add New Employee</h2>
|
|
10
|
+
<form @submit.prevent="createEmployee" class="form">
|
|
11
|
+
<div class="form-row">
|
|
12
|
+
<div class="form-group">
|
|
13
|
+
<label for="emp-name">Full Name</label>
|
|
14
|
+
<input
|
|
15
|
+
id="emp-name"
|
|
16
|
+
v-model="form.name"
|
|
17
|
+
type="text"
|
|
18
|
+
required
|
|
19
|
+
placeholder="e.g. Jane Doe"
|
|
20
|
+
/>
|
|
21
|
+
</div>
|
|
22
|
+
<div class="form-group">
|
|
23
|
+
<label for="emp-email">Email</label>
|
|
24
|
+
<input
|
|
25
|
+
id="emp-email"
|
|
26
|
+
v-model="form.email"
|
|
27
|
+
type="email"
|
|
28
|
+
required
|
|
29
|
+
placeholder="e.g. jane@example.com"
|
|
30
|
+
/>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
<div class="form-row">
|
|
34
|
+
<div class="form-group">
|
|
35
|
+
<label for="emp-dept">Department</label>
|
|
36
|
+
<select id="emp-dept" v-model="form.departmentId" required>
|
|
37
|
+
<option value="" disabled>Select Department</option>
|
|
38
|
+
<option v-for="dept in departments" :key="dept.id" :value="dept.id">
|
|
39
|
+
{{ dept.name }} ({{ dept.code }})
|
|
40
|
+
</option>
|
|
41
|
+
</select>
|
|
42
|
+
</div>
|
|
43
|
+
<div class="form-group">
|
|
44
|
+
<label for="emp-salary">Salary</label>
|
|
45
|
+
<input
|
|
46
|
+
id="emp-salary"
|
|
47
|
+
v-model.number="form.salary"
|
|
48
|
+
type="number"
|
|
49
|
+
min="0"
|
|
50
|
+
step="any"
|
|
51
|
+
required
|
|
52
|
+
placeholder="e.g. 75000"
|
|
53
|
+
/>
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
<button type="submit" class="btn btn-primary">Add Employee</button>
|
|
57
|
+
</form>
|
|
58
|
+
</section>
|
|
59
|
+
|
|
60
|
+
<section class="card table-card">
|
|
61
|
+
<h2>All Employees</h2>
|
|
62
|
+
<table class="data-table">
|
|
63
|
+
<thead>
|
|
64
|
+
<tr>
|
|
65
|
+
<th>ID</th>
|
|
66
|
+
<th>Name</th>
|
|
67
|
+
<th>Email</th>
|
|
68
|
+
<th>Department</th>
|
|
69
|
+
<th>Salary</th>
|
|
70
|
+
<th>Actions</th>
|
|
71
|
+
</tr>
|
|
72
|
+
</thead>
|
|
73
|
+
<tbody>
|
|
74
|
+
<tr v-if="employees.length === 0">
|
|
75
|
+
<td colspan="6" class="empty">No employees found.</td>
|
|
76
|
+
</tr>
|
|
77
|
+
<tr v-for="emp in employees" :key="emp.id">
|
|
78
|
+
<td>{{ emp.id }}</td>
|
|
79
|
+
<td>{{ emp.name }}</td>
|
|
80
|
+
<td>{{ emp.email }}</td>
|
|
81
|
+
<td>{{ getDepartmentName(emp.departmentId) }}</td>
|
|
82
|
+
<td>${{ Number(emp.salary).toLocaleString() }}</td>
|
|
83
|
+
<td class="action-cell">
|
|
84
|
+
<router-link :to="'/company/employees/' + emp.id" class="btn btn-info">View</router-link>
|
|
85
|
+
<button @click="handlePatch(emp.id, emp.salary)" class="btn btn-warning">Patch</button>
|
|
86
|
+
<button @click="deleteEmployee(emp.id)" class="btn btn-danger">Delete</button>
|
|
87
|
+
</td>
|
|
88
|
+
</tr>
|
|
89
|
+
</tbody>
|
|
90
|
+
</table>
|
|
91
|
+
</section>
|
|
92
|
+
</div>
|
|
93
|
+
</template>
|
|
94
|
+
|
|
95
|
+
<script setup>
|
|
96
|
+
import { ref, reactive, onMounted } from 'vue'
|
|
97
|
+
import api from '../services/api'
|
|
98
|
+
|
|
99
|
+
const employees = ref([])
|
|
100
|
+
const departments = ref([])
|
|
101
|
+
|
|
102
|
+
const form = reactive({
|
|
103
|
+
name: '',
|
|
104
|
+
email: '',
|
|
105
|
+
departmentId: '',
|
|
106
|
+
salary: ''
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
const fetchDepartments = async () => {
|
|
110
|
+
try {
|
|
111
|
+
const res = await api.get('/departments')
|
|
112
|
+
departments.value = Array.isArray(res.data) ? res.data : []
|
|
113
|
+
} catch (err) {
|
|
114
|
+
departments.value = []
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const fetchEmployees = async () => {
|
|
119
|
+
try {
|
|
120
|
+
const res = await api.get('/employees')
|
|
121
|
+
employees.value = Array.isArray(res.data) ? res.data : []
|
|
122
|
+
} catch (err) {
|
|
123
|
+
employees.value = []
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const createEmployee = async () => {
|
|
128
|
+
try {
|
|
129
|
+
await api.post('/employees', {
|
|
130
|
+
name: form.name,
|
|
131
|
+
email: form.email,
|
|
132
|
+
departmentId: Number(form.departmentId),
|
|
133
|
+
salary: Number(form.salary)
|
|
134
|
+
})
|
|
135
|
+
form.name = ''
|
|
136
|
+
form.email = ''
|
|
137
|
+
form.departmentId = ''
|
|
138
|
+
form.salary = ''
|
|
139
|
+
await fetchEmployees()
|
|
140
|
+
} catch (err) {
|
|
141
|
+
alert('Failed to add employee')
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const deleteEmployee = async (id) => {
|
|
146
|
+
try {
|
|
147
|
+
await api.delete(`/employees/${id}`)
|
|
148
|
+
await fetchEmployees()
|
|
149
|
+
} catch (err) {
|
|
150
|
+
alert('Failed to delete employee')
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const handlePatch = async (id, salary) => {
|
|
155
|
+
const newSalary = prompt('New salary:', salary)
|
|
156
|
+
if (newSalary !== null && newSalary !== '') {
|
|
157
|
+
try {
|
|
158
|
+
await api.patch(`/employees/${id}`, { salary: Number(newSalary) })
|
|
159
|
+
await fetchEmployees()
|
|
160
|
+
} catch (err) {
|
|
161
|
+
alert('Failed to patch employee')
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const getDepartmentName = (deptId) => {
|
|
167
|
+
const dept = departments.value.find((d) => d.id === deptId)
|
|
168
|
+
return dept ? dept.name : `Dept #${deptId}`
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
onMounted(() => {
|
|
172
|
+
fetchDepartments()
|
|
173
|
+
fetchEmployees()
|
|
174
|
+
})
|
|
175
|
+
</script>
|
|
176
|
+
|
|
177
|
+
<style scoped>
|
|
178
|
+
.employees-page {
|
|
179
|
+
max-width: 960px;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.page-header {
|
|
183
|
+
margin-bottom: 24px;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.page-header h1 {
|
|
187
|
+
font-size: 1.75rem;
|
|
188
|
+
margin-bottom: 6px;
|
|
189
|
+
color: #1e293b;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
.page-header p {
|
|
193
|
+
color: #64748b;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.card {
|
|
197
|
+
background: #ffffff;
|
|
198
|
+
padding: 24px;
|
|
199
|
+
border-radius: 8px;
|
|
200
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
|
201
|
+
margin-bottom: 24px;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.card h2 {
|
|
205
|
+
font-size: 1.2rem;
|
|
206
|
+
margin-bottom: 16px;
|
|
207
|
+
color: #334155;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
.form-row {
|
|
211
|
+
display: flex;
|
|
212
|
+
gap: 16px;
|
|
213
|
+
margin-bottom: 16px;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.form-group {
|
|
217
|
+
flex: 1;
|
|
218
|
+
display: flex;
|
|
219
|
+
flex-direction: column;
|
|
220
|
+
gap: 6px;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
label {
|
|
224
|
+
font-size: 0.875rem;
|
|
225
|
+
font-weight: 500;
|
|
226
|
+
color: #475569;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
input,
|
|
230
|
+
select {
|
|
231
|
+
padding: 8px 12px;
|
|
232
|
+
border: 1px solid #cbd5e1;
|
|
233
|
+
border-radius: 6px;
|
|
234
|
+
font-size: 0.95rem;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
input:focus,
|
|
238
|
+
select:focus {
|
|
239
|
+
outline: none;
|
|
240
|
+
border-color: #2563eb;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.btn {
|
|
244
|
+
padding: 8px 16px;
|
|
245
|
+
border: none;
|
|
246
|
+
border-radius: 6px;
|
|
247
|
+
cursor: pointer;
|
|
248
|
+
font-weight: 500;
|
|
249
|
+
text-decoration: none;
|
|
250
|
+
display: inline-flex;
|
|
251
|
+
align-items: center;
|
|
252
|
+
justify-content: center;
|
|
253
|
+
transition: opacity 0.2s;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.btn:hover {
|
|
257
|
+
opacity: 0.9;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.btn-primary {
|
|
261
|
+
background-color: #2563eb;
|
|
262
|
+
color: #ffffff;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
.btn-info {
|
|
266
|
+
background-color: #0284c7;
|
|
267
|
+
color: #ffffff;
|
|
268
|
+
font-size: 0.875rem;
|
|
269
|
+
padding: 6px 12px;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.btn-danger {
|
|
273
|
+
background-color: #ef4444;
|
|
274
|
+
color: #ffffff;
|
|
275
|
+
font-size: 0.875rem;
|
|
276
|
+
padding: 6px 12px;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
.btn-warning {
|
|
280
|
+
background-color: #f59e0b;
|
|
281
|
+
color: #ffffff;
|
|
282
|
+
font-size: 0.875rem;
|
|
283
|
+
padding: 6px 12px;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
.action-cell {
|
|
287
|
+
display: flex;
|
|
288
|
+
gap: 8px;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
.data-table {
|
|
292
|
+
width: 100%;
|
|
293
|
+
border-collapse: collapse;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.data-table th,
|
|
297
|
+
.data-table td {
|
|
298
|
+
padding: 12px;
|
|
299
|
+
text-align: left;
|
|
300
|
+
border-bottom: 1px solid #e2e8f0;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
.data-table th {
|
|
304
|
+
background-color: #f8fafc;
|
|
305
|
+
font-size: 0.875rem;
|
|
306
|
+
color: #475569;
|
|
307
|
+
font-weight: 600;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
.empty {
|
|
311
|
+
text-align: center;
|
|
312
|
+
color: #94a3b8;
|
|
313
|
+
padding: 24px;
|
|
314
|
+
}
|
|
315
|
+
</style>
|