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,92 +1,106 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
defineProps({
|
|
3
|
-
items: {
|
|
4
|
-
type: Array,
|
|
5
|
-
default: () => []
|
|
6
|
-
},
|
|
7
|
-
columns: {
|
|
8
|
-
type: Array,
|
|
9
|
-
default: () => []
|
|
10
|
-
},
|
|
11
|
-
title: {
|
|
12
|
-
type: String,
|
|
13
|
-
default: ''
|
|
14
|
-
}
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
const emit = defineEmits(['delete-item'])
|
|
18
|
-
|
|
19
|
-
const getColKey = (col) => (typeof col === 'object' && col.key ? col.key : col)
|
|
20
|
-
const getColLabel = (col) => (typeof col === 'object' && col.label ? col.label : col)
|
|
21
|
-
|
|
22
|
-
const handleDelete = (id) => {
|
|
23
|
-
emit('delete-item', id)
|
|
24
|
-
}
|
|
25
|
-
</script>
|
|
26
|
-
|
|
27
|
-
<template>
|
|
28
|
-
<div class="entity-table-container">
|
|
29
|
-
<h3 v-if="title" class="table-title">{{ title }}</h3>
|
|
30
|
-
<table v-if="items && items.length > 0" class="entity-table">
|
|
31
|
-
<thead>
|
|
32
|
-
<tr>
|
|
33
|
-
<th v-for="col in columns" :key="getColKey(col)">
|
|
34
|
-
{{ getColLabel(col) }}
|
|
35
|
-
</th>
|
|
36
|
-
<th>Actions</th>
|
|
37
|
-
</tr>
|
|
38
|
-
</thead>
|
|
39
|
-
<tbody>
|
|
40
|
-
<tr v-for="item in items" :key="item.id">
|
|
41
|
-
<td v-for="col in columns" :key="getColKey(col)">
|
|
42
|
-
{{ item[getColKey(col)] }}
|
|
43
|
-
</td>
|
|
44
|
-
<td>
|
|
45
|
-
<button
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
</
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
.entity-table
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
color: #
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
1
|
+
<script setup>
|
|
2
|
+
defineProps({
|
|
3
|
+
items: {
|
|
4
|
+
type: Array,
|
|
5
|
+
default: () => []
|
|
6
|
+
},
|
|
7
|
+
columns: {
|
|
8
|
+
type: Array,
|
|
9
|
+
default: () => []
|
|
10
|
+
},
|
|
11
|
+
title: {
|
|
12
|
+
type: String,
|
|
13
|
+
default: ''
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const emit = defineEmits(['delete-item', 'patch-item'])
|
|
18
|
+
|
|
19
|
+
const getColKey = (col) => (typeof col === 'object' && col.key ? col.key : col)
|
|
20
|
+
const getColLabel = (col) => (typeof col === 'object' && col.label ? col.label : col)
|
|
21
|
+
|
|
22
|
+
const handleDelete = (id) => {
|
|
23
|
+
emit('delete-item', id)
|
|
24
|
+
}
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<div class="entity-table-container">
|
|
29
|
+
<h3 v-if="title" class="table-title">{{ title }}</h3>
|
|
30
|
+
<table v-if="items && items.length > 0" class="entity-table">
|
|
31
|
+
<thead>
|
|
32
|
+
<tr>
|
|
33
|
+
<th v-for="col in columns" :key="getColKey(col)">
|
|
34
|
+
{{ getColLabel(col) }}
|
|
35
|
+
</th>
|
|
36
|
+
<th>Actions</th>
|
|
37
|
+
</tr>
|
|
38
|
+
</thead>
|
|
39
|
+
<tbody>
|
|
40
|
+
<tr v-for="item in items" :key="item.id">
|
|
41
|
+
<td v-for="col in columns" :key="getColKey(col)">
|
|
42
|
+
{{ item[getColKey(col)] }}
|
|
43
|
+
</td>
|
|
44
|
+
<td>
|
|
45
|
+
<button @click="$emit('patch-item', item)" class="btn-patch">Patch</button>
|
|
46
|
+
<button class="btn-delete" @click="handleDelete(item.id)">Delete</button>
|
|
47
|
+
</td>
|
|
48
|
+
</tr>
|
|
49
|
+
</tbody>
|
|
50
|
+
</table>
|
|
51
|
+
<p v-else class="empty-msg">No records found.</p>
|
|
52
|
+
</div>
|
|
53
|
+
</template>
|
|
54
|
+
|
|
55
|
+
<style scoped>
|
|
56
|
+
.entity-table-container {
|
|
57
|
+
margin-top: 16px;
|
|
58
|
+
}
|
|
59
|
+
.table-title {
|
|
60
|
+
margin-bottom: 12px;
|
|
61
|
+
font-size: 1.2rem;
|
|
62
|
+
}
|
|
63
|
+
.entity-table {
|
|
64
|
+
width: 100%;
|
|
65
|
+
border-collapse: collapse;
|
|
66
|
+
}
|
|
67
|
+
.entity-table th,
|
|
68
|
+
.entity-table td {
|
|
69
|
+
border: 1px solid #d0d7de;
|
|
70
|
+
padding: 10px 12px;
|
|
71
|
+
text-align: left;
|
|
72
|
+
}
|
|
73
|
+
.entity-table th {
|
|
74
|
+
background-color: #f6f8fa;
|
|
75
|
+
font-weight: 600;
|
|
76
|
+
}
|
|
77
|
+
.btn-patch {
|
|
78
|
+
background-color: #0969da;
|
|
79
|
+
color: #ffffff;
|
|
80
|
+
border: none;
|
|
81
|
+
padding: 6px 12px;
|
|
82
|
+
border-radius: 4px;
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
font-size: 0.85rem;
|
|
85
|
+
margin-right: 6px;
|
|
86
|
+
}
|
|
87
|
+
.btn-patch:hover {
|
|
88
|
+
background-color: #0856b3;
|
|
89
|
+
}
|
|
90
|
+
.btn-delete {
|
|
91
|
+
background-color: #cf222e;
|
|
92
|
+
color: #ffffff;
|
|
93
|
+
border: none;
|
|
94
|
+
padding: 6px 12px;
|
|
95
|
+
border-radius: 4px;
|
|
96
|
+
cursor: pointer;
|
|
97
|
+
font-size: 0.85rem;
|
|
98
|
+
}
|
|
99
|
+
.btn-delete:hover {
|
|
100
|
+
background-color: #a40e26;
|
|
101
|
+
}
|
|
102
|
+
.empty-msg {
|
|
103
|
+
color: #57606a;
|
|
104
|
+
padding: 12px 0;
|
|
105
|
+
}
|
|
106
|
+
</style>
|
|
@@ -1,84 +1,139 @@
|
|
|
1
|
-
import { defineStore } from 'pinia'
|
|
2
|
-
import api from '../services/api'
|
|
3
|
-
|
|
4
|
-
export const useCompanyStore = defineStore('company', {
|
|
5
|
-
state: () => ({
|
|
6
|
-
departments: [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
async
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
1
|
+
import { defineStore } from 'pinia'
|
|
2
|
+
import api from '../services/api'
|
|
3
|
+
|
|
4
|
+
export const useCompanyStore = defineStore('company', {
|
|
5
|
+
state: () => ({
|
|
6
|
+
departments: [],
|
|
7
|
+
employees: [],
|
|
8
|
+
loading: false,
|
|
9
|
+
error: null
|
|
10
|
+
}),
|
|
11
|
+
getters: {
|
|
12
|
+
totalDepartments: (state) => state.departments.length,
|
|
13
|
+
totalEmployees: (state) => state.employees.length,
|
|
14
|
+
totalPayroll: (state) => state.employees.reduce((sum, emp) => sum + (Number(emp.salary) || 0), 0),
|
|
15
|
+
totalBudget: (state) => state.departments.reduce((sum, d) => sum + Number(d.budget || 0), 0)
|
|
16
|
+
},
|
|
17
|
+
actions: {
|
|
18
|
+
async fetchDepartments() {
|
|
19
|
+
this.loading = true
|
|
20
|
+
this.error = null
|
|
21
|
+
try {
|
|
22
|
+
const response = await api.get('/departments')
|
|
23
|
+
this.departments = response.data
|
|
24
|
+
} catch (err) {
|
|
25
|
+
this.error = err.response?.data?.message || err.message
|
|
26
|
+
} finally {
|
|
27
|
+
this.loading = false
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
async addDepartment(dept) {
|
|
31
|
+
return this.createDepartment(dept)
|
|
32
|
+
},
|
|
33
|
+
async removeDepartment(id) {
|
|
34
|
+
return this.deleteDepartment(id)
|
|
35
|
+
},
|
|
36
|
+
async createDepartment(data) {
|
|
37
|
+
this.loading = true
|
|
38
|
+
this.error = null
|
|
39
|
+
try {
|
|
40
|
+
const response = await api.post('/departments', data)
|
|
41
|
+
this.departments.push(response.data)
|
|
42
|
+
return response.data
|
|
43
|
+
} catch (err) {
|
|
44
|
+
this.error = err.response?.data?.message || err.message
|
|
45
|
+
throw err
|
|
46
|
+
} finally {
|
|
47
|
+
this.loading = false
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
async deleteDepartment(id) {
|
|
51
|
+
this.loading = true
|
|
52
|
+
this.error = null
|
|
53
|
+
try {
|
|
54
|
+
await api.delete(`/departments/${id}`)
|
|
55
|
+
this.departments = this.departments.filter(dept => dept.id !== id)
|
|
56
|
+
} catch (err) {
|
|
57
|
+
this.error = err.response?.data?.message || err.message
|
|
58
|
+
throw err
|
|
59
|
+
} finally {
|
|
60
|
+
this.loading = false
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
async fetchEmployees() {
|
|
64
|
+
this.loading = true
|
|
65
|
+
this.error = null
|
|
66
|
+
try {
|
|
67
|
+
const response = await api.get('/employees')
|
|
68
|
+
this.employees = response.data
|
|
69
|
+
} catch (err) {
|
|
70
|
+
this.error = err.response?.data?.message || err.message
|
|
71
|
+
} finally {
|
|
72
|
+
this.loading = false
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
async addEmployee(emp) {
|
|
76
|
+
return this.createEmployee(emp)
|
|
77
|
+
},
|
|
78
|
+
async removeEmployee(id) {
|
|
79
|
+
return this.deleteEmployee(id)
|
|
80
|
+
},
|
|
81
|
+
async createEmployee(data) {
|
|
82
|
+
this.loading = true
|
|
83
|
+
this.error = null
|
|
84
|
+
try {
|
|
85
|
+
const response = await api.post('/employees', data)
|
|
86
|
+
this.employees.push(response.data)
|
|
87
|
+
return response.data
|
|
88
|
+
} catch (err) {
|
|
89
|
+
this.error = err.response?.data?.message || err.message
|
|
90
|
+
throw err
|
|
91
|
+
} finally {
|
|
92
|
+
this.loading = false
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
async deleteEmployee(id) {
|
|
96
|
+
this.loading = true
|
|
97
|
+
this.error = null
|
|
98
|
+
try {
|
|
99
|
+
await api.delete(`/employees/${id}`)
|
|
100
|
+
this.employees = this.employees.filter(emp => emp.id !== id)
|
|
101
|
+
} catch (err) {
|
|
102
|
+
this.error = err.response?.data?.message || err.message
|
|
103
|
+
throw err
|
|
104
|
+
} finally {
|
|
105
|
+
this.loading = false
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
async patchDepartment(id, data) {
|
|
109
|
+
this.loading = true
|
|
110
|
+
this.error = null
|
|
111
|
+
try {
|
|
112
|
+
const response = await api.patch(`/departments/${id}`, data)
|
|
113
|
+
const idx = this.departments.findIndex(dept => dept.id === id)
|
|
114
|
+
if (idx !== -1) this.departments[idx] = response.data
|
|
115
|
+
return response.data
|
|
116
|
+
} catch (err) {
|
|
117
|
+
this.error = err.response?.data?.message || err.message
|
|
118
|
+
throw err
|
|
119
|
+
} finally {
|
|
120
|
+
this.loading = false
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
async patchEmployee(id, data) {
|
|
124
|
+
this.loading = true
|
|
125
|
+
this.error = null
|
|
126
|
+
try {
|
|
127
|
+
const response = await api.patch(`/employees/${id}`, data)
|
|
128
|
+
const idx = this.employees.findIndex(emp => emp.id === id)
|
|
129
|
+
if (idx !== -1) this.employees[idx] = response.data
|
|
130
|
+
return response.data
|
|
131
|
+
} catch (err) {
|
|
132
|
+
this.error = err.response?.data?.message || err.message
|
|
133
|
+
throw err
|
|
134
|
+
} finally {
|
|
135
|
+
this.loading = false
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
})
|
|
@@ -1,64 +1,73 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import { onMounted } from 'vue'
|
|
3
|
-
import { useCompanyStore } from '../stores/companyStore'
|
|
4
|
-
import EntityTable from '../components/EntityTable.vue'
|
|
5
|
-
import EntityForm from '../components/EntityForm.vue'
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
{ key: '
|
|
12
|
-
{ key: '
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
{ key: '
|
|
18
|
-
{ key: '
|
|
19
|
-
{ key: '
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
<script setup>
|
|
2
|
+
import { onMounted } from 'vue'
|
|
3
|
+
import { useCompanyStore } from '../stores/companyStore'
|
|
4
|
+
import EntityTable from '../components/EntityTable.vue'
|
|
5
|
+
import EntityForm from '../components/EntityForm.vue'
|
|
6
|
+
|
|
7
|
+
const companyStore = useCompanyStore()
|
|
8
|
+
const store = companyStore
|
|
9
|
+
|
|
10
|
+
const departmentFields = [
|
|
11
|
+
{ key: 'name', label: 'Department Name', type: 'text', placeholder: 'e.g. Finance' },
|
|
12
|
+
{ key: 'code', label: 'Department Code', type: 'text', placeholder: 'e.g. FIN' },
|
|
13
|
+
{ key: 'budget', label: 'Annual Budget ($)', type: 'number', placeholder: 'e.g. 50000' }
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
const departmentColumns = [
|
|
17
|
+
{ key: 'id', label: 'ID' },
|
|
18
|
+
{ key: 'name', label: 'Name' },
|
|
19
|
+
{ key: 'code', label: 'Code' },
|
|
20
|
+
{ key: 'budget', label: 'Budget' }
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
const handleAddDepartment = (formData) => {
|
|
24
|
+
store.addDepartment({
|
|
25
|
+
name: formData.name,
|
|
26
|
+
code: formData.code,
|
|
27
|
+
budget: Number(formData.budget)
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const handleDeleteDepartment = (id) => {
|
|
32
|
+
store.removeDepartment(id)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const handlePatch = (item) => {
|
|
36
|
+
const code = prompt('New code:', item.code)
|
|
37
|
+
if (code) {
|
|
38
|
+
companyStore.patchDepartment(item.id, { code })
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
onMounted(() => {
|
|
43
|
+
store.fetchDepartments()
|
|
44
|
+
})
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<template>
|
|
48
|
+
<div class="manage-departments-view">
|
|
49
|
+
<h2>Manage Departments</h2>
|
|
50
|
+
<EntityForm
|
|
51
|
+
:fields="departmentFields"
|
|
52
|
+
title="Add New Department"
|
|
53
|
+
@submit-form="handleAddDepartment"
|
|
54
|
+
/>
|
|
55
|
+
<EntityTable
|
|
56
|
+
:items="store.departments"
|
|
57
|
+
:columns="departmentColumns"
|
|
58
|
+
title="All Departments"
|
|
59
|
+
@delete-item="handleDeleteDepartment"
|
|
60
|
+
@patch-item="handlePatch"
|
|
61
|
+
/>
|
|
62
|
+
</div>
|
|
63
|
+
</template>
|
|
64
|
+
|
|
65
|
+
<style scoped>
|
|
66
|
+
.manage-departments-view {
|
|
67
|
+
padding: 16px 0;
|
|
68
|
+
}
|
|
69
|
+
.manage-departments-view h2 {
|
|
70
|
+
font-size: 1.5rem;
|
|
71
|
+
margin-bottom: 20px;
|
|
72
|
+
}
|
|
73
|
+
</style>
|