wad-lab 1.1.5 → 1.1.7
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/bin/index.js +30 -3
- 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 +429 -405
- package/templates/vue-axios-interceptor/src/App.vue +177 -159
- package/templates/vue-axios-pinia/src/App.vue +441 -427
- 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 +191 -167
- package/templates/vue-axios-props-emits/src/components/DepartmentForm.vue +98 -98
- package/templates/vue-axios-props-emits/src/components/DepartmentList.vue +92 -91
- package/templates/vue-axios-props-emits/src/components/EmployeeForm.vue +128 -128
- package/templates/vue-axios-props-emits/src/components/EmployeeList.vue +95 -94
- package/templates/vue-axios-router/src/App.vue +90 -90
- package/templates/vue-axios-router/src/views/AddEmployeeView.vue +247 -247
- package/templates/vue-axios-router/src/views/DepartmentView.vue +296 -273
- package/templates/vue-axios-router/src/views/EmployeeView.vue +219 -196
- package/templates/vue-axios-router/src/views/HomeDashboardView.vue +263 -263
- 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/App.vue +59 -59
- 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,67 +1,76 @@
|
|
|
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
|
-
{ key: '
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
{ key: '
|
|
19
|
-
{ key: '
|
|
20
|
-
{ key: '
|
|
21
|
-
{ key: '
|
|
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
|
-
|
|
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 employeeFields = [
|
|
11
|
+
{ key: 'name', label: 'Employee Name', type: 'text', placeholder: 'e.g. Jane Doe' },
|
|
12
|
+
{ key: 'email', label: 'Email Address', type: 'email', placeholder: 'e.g. jane@example.com' },
|
|
13
|
+
{ key: 'role', label: 'Job Role', type: 'text', placeholder: 'e.g. Developer' },
|
|
14
|
+
{ key: 'department', label: 'Department', type: 'text', placeholder: 'e.g. Engineering' }
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
const employeeColumns = [
|
|
18
|
+
{ key: 'id', label: 'ID' },
|
|
19
|
+
{ key: 'name', label: 'Name' },
|
|
20
|
+
{ key: 'email', label: 'Email' },
|
|
21
|
+
{ key: 'role', label: 'Role' },
|
|
22
|
+
{ key: 'department', label: 'Department' }
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
const handleAddEmployee = (formData) => {
|
|
26
|
+
store.addEmployee({
|
|
27
|
+
name: formData.name,
|
|
28
|
+
email: formData.email,
|
|
29
|
+
role: formData.role,
|
|
30
|
+
department: formData.department
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const handleDeleteEmployee = (id) => {
|
|
35
|
+
store.removeEmployee(id)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const handlePatch = (item) => {
|
|
39
|
+
const salary = prompt('New salary:', item.salary)
|
|
40
|
+
if (salary !== null && salary !== '') {
|
|
41
|
+
companyStore.patchEmployee(item.id, { salary: Number(salary) })
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
onMounted(() => {
|
|
46
|
+
store.fetchEmployees()
|
|
47
|
+
})
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<template>
|
|
51
|
+
<div class="manage-employees-view">
|
|
52
|
+
<h2>Manage Employees</h2>
|
|
53
|
+
<EntityForm
|
|
54
|
+
:fields="employeeFields"
|
|
55
|
+
title="Add New Employee"
|
|
56
|
+
@submit-form="handleAddEmployee"
|
|
57
|
+
/>
|
|
58
|
+
<EntityTable
|
|
59
|
+
:items="store.employees"
|
|
60
|
+
:columns="employeeColumns"
|
|
61
|
+
title="All Employees"
|
|
62
|
+
@delete-item="handleDeleteEmployee"
|
|
63
|
+
@patch-item="handlePatch"
|
|
64
|
+
/>
|
|
65
|
+
</div>
|
|
66
|
+
</template>
|
|
67
|
+
|
|
68
|
+
<style scoped>
|
|
69
|
+
.manage-employees-view {
|
|
70
|
+
padding: 16px 0;
|
|
71
|
+
}
|
|
72
|
+
.manage-employees-view h2 {
|
|
73
|
+
font-size: 1.5rem;
|
|
74
|
+
margin-bottom: 20px;
|
|
75
|
+
}
|
|
76
|
+
</style>
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
</script>
|
|
3
|
-
|
|
4
|
-
<template>
|
|
5
|
-
<div class="app-container">
|
|
6
|
-
<header class="navbar">
|
|
7
|
-
<h2>Company Management</h2>
|
|
8
|
-
<nav class="nav-links">
|
|
9
|
-
<router-link to="/">Departments</router-link>
|
|
10
|
-
<router-link to="/employees">Employees</router-link>
|
|
11
|
-
</nav>
|
|
12
|
-
</header>
|
|
13
|
-
<main class="content">
|
|
14
|
-
<router-view />
|
|
15
|
-
</main>
|
|
16
|
-
</div>
|
|
17
|
-
</template>
|
|
18
|
-
|
|
19
|
-
<style scoped>
|
|
20
|
-
.app-container {
|
|
21
|
-
max-width: 800px;
|
|
22
|
-
margin: 0 auto;
|
|
23
|
-
padding: 24px 16px;
|
|
24
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
|
25
|
-
color: #2d3748;
|
|
26
|
-
}
|
|
27
|
-
.navbar {
|
|
28
|
-
display: flex;
|
|
29
|
-
justify-content: space-between;
|
|
30
|
-
align-items: center;
|
|
31
|
-
border-bottom: 2px solid #e2e8f0;
|
|
32
|
-
padding-bottom: 16px;
|
|
33
|
-
margin-bottom: 24px;
|
|
34
|
-
}
|
|
35
|
-
.navbar h2 {
|
|
36
|
-
margin: 0;
|
|
37
|
-
font-size: 22px;
|
|
38
|
-
}
|
|
39
|
-
.nav-links {
|
|
40
|
-
display: flex;
|
|
41
|
-
gap: 12px;
|
|
42
|
-
}
|
|
43
|
-
.nav-links a {
|
|
44
|
-
text-decoration: none;
|
|
45
|
-
color: #4a5568;
|
|
46
|
-
font-weight: 500;
|
|
47
|
-
padding: 6px 14px;
|
|
48
|
-
border-radius: 4px;
|
|
49
|
-
border: 1px solid #cbd5e0;
|
|
50
|
-
}
|
|
51
|
-
.nav-links a.router-link-active {
|
|
52
|
-
background-color: #3182ce;
|
|
53
|
-
border-color: #3182ce;
|
|
54
|
-
color: #fff;
|
|
55
|
-
}
|
|
56
|
-
.content {
|
|
57
|
-
margin-top: 10px;
|
|
58
|
-
}
|
|
59
|
-
</style>
|
|
1
|
+
<script setup>
|
|
2
|
+
</script>
|
|
3
|
+
|
|
4
|
+
<template>
|
|
5
|
+
<div class="app-container">
|
|
6
|
+
<header class="navbar">
|
|
7
|
+
<h2>Company Management</h2>
|
|
8
|
+
<nav class="nav-links">
|
|
9
|
+
<router-link to="/">Departments</router-link>
|
|
10
|
+
<router-link to="/employees">Employees</router-link>
|
|
11
|
+
</nav>
|
|
12
|
+
</header>
|
|
13
|
+
<main class="content">
|
|
14
|
+
<router-view />
|
|
15
|
+
</main>
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<style scoped>
|
|
20
|
+
.app-container {
|
|
21
|
+
max-width: 800px;
|
|
22
|
+
margin: 0 auto;
|
|
23
|
+
padding: 24px 16px;
|
|
24
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
|
25
|
+
color: #2d3748;
|
|
26
|
+
}
|
|
27
|
+
.navbar {
|
|
28
|
+
display: flex;
|
|
29
|
+
justify-content: space-between;
|
|
30
|
+
align-items: center;
|
|
31
|
+
border-bottom: 2px solid #e2e8f0;
|
|
32
|
+
padding-bottom: 16px;
|
|
33
|
+
margin-bottom: 24px;
|
|
34
|
+
}
|
|
35
|
+
.navbar h2 {
|
|
36
|
+
margin: 0;
|
|
37
|
+
font-size: 22px;
|
|
38
|
+
}
|
|
39
|
+
.nav-links {
|
|
40
|
+
display: flex;
|
|
41
|
+
gap: 12px;
|
|
42
|
+
}
|
|
43
|
+
.nav-links a {
|
|
44
|
+
text-decoration: none;
|
|
45
|
+
color: #4a5568;
|
|
46
|
+
font-weight: 500;
|
|
47
|
+
padding: 6px 14px;
|
|
48
|
+
border-radius: 4px;
|
|
49
|
+
border: 1px solid #cbd5e0;
|
|
50
|
+
}
|
|
51
|
+
.nav-links a.router-link-active {
|
|
52
|
+
background-color: #3182ce;
|
|
53
|
+
border-color: #3182ce;
|
|
54
|
+
color: #fff;
|
|
55
|
+
}
|
|
56
|
+
.content {
|
|
57
|
+
margin-top: 10px;
|
|
58
|
+
}
|
|
59
|
+
</style>
|
|
@@ -1,53 +1,72 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
const props = defineProps(['title', 'subtitle', 'id'])
|
|
3
|
-
const emit = defineEmits(['remove'])
|
|
4
|
-
|
|
5
|
-
const handleRemove = () => {
|
|
6
|
-
emit('remove', props.id)
|
|
7
|
-
}
|
|
8
|
-
</script>
|
|
9
|
-
|
|
10
|
-
<template>
|
|
11
|
-
<div class="data-card">
|
|
12
|
-
<div class="card-info">
|
|
13
|
-
<h4>{{ title }}</h4>
|
|
14
|
-
<p>{{ subtitle }}</p>
|
|
15
|
-
</div>
|
|
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
|
-
|
|
1
|
+
<script setup>
|
|
2
|
+
const props = defineProps(['title', 'subtitle', 'id'])
|
|
3
|
+
const emit = defineEmits(['remove', 'patch'])
|
|
4
|
+
|
|
5
|
+
const handleRemove = () => {
|
|
6
|
+
emit('remove', props.id)
|
|
7
|
+
}
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<div class="data-card">
|
|
12
|
+
<div class="card-info">
|
|
13
|
+
<h4>{{ title }}</h4>
|
|
14
|
+
<p>{{ subtitle }}</p>
|
|
15
|
+
</div>
|
|
16
|
+
<div class="card-actions">
|
|
17
|
+
<button class="btn-patch" @click="$emit('patch', id)">Patch</button>
|
|
18
|
+
<button class="btn-remove" @click="handleRemove">Delete</button>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<style scoped>
|
|
24
|
+
.data-card {
|
|
25
|
+
display: flex;
|
|
26
|
+
justify-content: space-between;
|
|
27
|
+
align-items: center;
|
|
28
|
+
border: 1px solid #e2e8f0;
|
|
29
|
+
border-radius: 6px;
|
|
30
|
+
padding: 12px 16px;
|
|
31
|
+
margin-bottom: 10px;
|
|
32
|
+
background-color: #fff;
|
|
33
|
+
}
|
|
34
|
+
.card-info h4 {
|
|
35
|
+
margin: 0 0 4px 0;
|
|
36
|
+
font-size: 16px;
|
|
37
|
+
color: #2d3748;
|
|
38
|
+
}
|
|
39
|
+
.card-info p {
|
|
40
|
+
margin: 0;
|
|
41
|
+
font-size: 14px;
|
|
42
|
+
color: #718096;
|
|
43
|
+
}
|
|
44
|
+
.card-actions {
|
|
45
|
+
display: flex;
|
|
46
|
+
gap: 8px;
|
|
47
|
+
}
|
|
48
|
+
.btn-patch {
|
|
49
|
+
background-color: #3182ce;
|
|
50
|
+
color: white;
|
|
51
|
+
border: none;
|
|
52
|
+
border-radius: 4px;
|
|
53
|
+
padding: 6px 12px;
|
|
54
|
+
cursor: pointer;
|
|
55
|
+
font-size: 13px;
|
|
56
|
+
}
|
|
57
|
+
.btn-patch:hover {
|
|
58
|
+
background-color: #2b6cb0;
|
|
59
|
+
}
|
|
60
|
+
.btn-remove {
|
|
61
|
+
background-color: #e53e3e;
|
|
62
|
+
color: white;
|
|
63
|
+
border: none;
|
|
64
|
+
border-radius: 4px;
|
|
65
|
+
padding: 6px 12px;
|
|
66
|
+
cursor: pointer;
|
|
67
|
+
font-size: 13px;
|
|
68
|
+
}
|
|
69
|
+
.btn-remove:hover {
|
|
70
|
+
background-color: #c53030;
|
|
71
|
+
}
|
|
72
|
+
</style>
|
|
@@ -1,77 +1,89 @@
|
|
|
1
|
-
<script setup>
|
|
2
|
-
import { ref, onMounted } from 'vue'
|
|
3
|
-
import api from '../services/api'
|
|
4
|
-
import EntryForm from '../components/EntryForm.vue'
|
|
5
|
-
import DataCard from '../components/DataCard.vue'
|
|
6
|
-
|
|
7
|
-
const departments = ref([])
|
|
8
|
-
|
|
9
|
-
const deptFields = [
|
|
10
|
-
{ key: 'name', label: 'Department Name', placeholder: 'e.g. Engineering' },
|
|
11
|
-
{ key: 'code', label: 'Department Code', placeholder: 'e.g. ENG' }
|
|
12
|
-
]
|
|
13
|
-
|
|
14
|
-
const fetchDepartments = async () => {
|
|
15
|
-
try {
|
|
16
|
-
const res = await api.get('/departments')
|
|
17
|
-
departments.value = res.data
|
|
18
|
-
} catch (error) {
|
|
19
|
-
console.error(error)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const handleCreateDepartment = async (formData) => {
|
|
24
|
-
try {
|
|
25
|
-
const res = await api.post('/departments', formData)
|
|
26
|
-
departments.value.push(res.data)
|
|
27
|
-
} catch (error) {
|
|
28
|
-
console.error(error)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const handleRemoveDepartment = async (id) => {
|
|
33
|
-
try {
|
|
34
|
-
await api.delete(`/departments/${id}`)
|
|
35
|
-
departments.value = departments.value.filter(dept => dept.id !== id)
|
|
36
|
-
} catch (error) {
|
|
37
|
-
console.error(error)
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
1
|
+
<script setup>
|
|
2
|
+
import { ref, onMounted } from 'vue'
|
|
3
|
+
import api from '../services/api'
|
|
4
|
+
import EntryForm from '../components/EntryForm.vue'
|
|
5
|
+
import DataCard from '../components/DataCard.vue'
|
|
6
|
+
|
|
7
|
+
const departments = ref([])
|
|
8
|
+
|
|
9
|
+
const deptFields = [
|
|
10
|
+
{ key: 'name', label: 'Department Name', placeholder: 'e.g. Engineering' },
|
|
11
|
+
{ key: 'code', label: 'Department Code', placeholder: 'e.g. ENG' }
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
const fetchDepartments = async () => {
|
|
15
|
+
try {
|
|
16
|
+
const res = await api.get('/departments')
|
|
17
|
+
departments.value = res.data
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error(error)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const handleCreateDepartment = async (formData) => {
|
|
24
|
+
try {
|
|
25
|
+
const res = await api.post('/departments', formData)
|
|
26
|
+
departments.value.push(res.data)
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error(error)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const handleRemoveDepartment = async (id) => {
|
|
33
|
+
try {
|
|
34
|
+
await api.delete(`/departments/${id}`)
|
|
35
|
+
departments.value = departments.value.filter(dept => dept.id !== id)
|
|
36
|
+
} catch (error) {
|
|
37
|
+
console.error(error)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const handlePatch = async (id, code) => {
|
|
42
|
+
const newCode = prompt('New code:', code)
|
|
43
|
+
if (!newCode || newCode === code) return
|
|
44
|
+
try {
|
|
45
|
+
await api.patch(`/departments/${id}`, { code: newCode })
|
|
46
|
+
await fetchDepartments()
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error(error)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
onMounted(() => {
|
|
53
|
+
fetchDepartments()
|
|
54
|
+
})
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<template>
|
|
58
|
+
<div class="page-container">
|
|
59
|
+
<h2>Departments</h2>
|
|
60
|
+
<EntryForm :fields="deptFields" @submit-data="handleCreateDepartment" />
|
|
61
|
+
<div class="card-list">
|
|
62
|
+
<p v-if="departments.length === 0" class="empty-state">No departments available.</p>
|
|
63
|
+
<DataCard
|
|
64
|
+
v-for="dept in departments"
|
|
65
|
+
:key="dept.id"
|
|
66
|
+
:id="dept.id"
|
|
67
|
+
:title="dept.name"
|
|
68
|
+
:subtitle="dept.code"
|
|
69
|
+
@remove="handleRemoveDepartment"
|
|
70
|
+
@patch="handlePatch(dept.id, dept.code)"
|
|
71
|
+
/>
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
</template>
|
|
75
|
+
|
|
76
|
+
<style scoped>
|
|
77
|
+
.page-container {
|
|
78
|
+
display: flex;
|
|
79
|
+
flex-direction: column;
|
|
80
|
+
}
|
|
81
|
+
.empty-state {
|
|
82
|
+
color: #a0aec0;
|
|
83
|
+
font-style: italic;
|
|
84
|
+
}
|
|
85
|
+
.card-list {
|
|
86
|
+
display: flex;
|
|
87
|
+
flex-direction: column;
|
|
88
|
+
}
|
|
89
|
+
</style>
|