23
23
:header =" t('Title')"
24
24
:sortable =" true"
25
25
field =" title"
26
- />
26
+ >
27
+ <template #body =" slotProps " >
28
+ <div class =" flex items-center" >
29
+ <BaseIcon v-if =" isAllowedToEdit && getSessionId(slotProps.data)" icon =" session-star" size =" small" class =" mr-2" />
30
+ {{ slotProps.data.title }}
31
+ </div >
32
+ </template >
33
+ </Column >
27
34
<Column
28
35
:header =" t('Send date')"
29
36
:sortable =" true"
55
62
body-class =" space-x-2"
56
63
>
57
64
<template #body =" slotProps " >
58
- <BaseButton
59
- :icon ="
60
- RESOURCE_LINK_PUBLISHED === slotProps.data.firstResourceLink.visibility
61
- ? 'eye-on'
62
- : RESOURCE_LINK_DRAFT === slotProps.data.firstResourceLink.visibility
63
- ? 'eye-off'
64
- : ''
65
- "
66
- :label =" t('Visibility')"
67
- only-icon
68
- size =" small"
69
- type =" black"
70
- @click =" onClickVisibility(slotProps.data)"
71
- />
72
- <BaseButton
73
- :label =" t('Upload corrections')"
74
- icon =" file-upload"
75
- only-icon
76
- size =" small"
77
- type =" black"
78
- />
79
- <BaseButton
80
- :disabled =" 0 === slotProps.data.uniqueStudentAttemptsTotal"
81
- :label =" t('Save')"
82
- icon =" download"
83
- only-icon
84
- size =" small"
85
- type =" black"
86
- />
87
- <BaseButton
88
- :label =" t('Edit')"
89
- icon =" edit"
90
- only-icon
91
- size =" small"
92
- type =" black"
93
- @click =" onClickEdit(slotProps.data)"
94
- />
65
+ <div v-if =" canEdit(slotProps.data)" >
66
+ <BaseButton
67
+ :icon ="
68
+ RESOURCE_LINK_PUBLISHED === slotProps.data.firstResourceLink.visibility
69
+ ? 'eye-on'
70
+ : RESOURCE_LINK_DRAFT === slotProps.data.firstResourceLink.visibility
71
+ ? 'eye-off'
72
+ : ''
73
+ "
74
+ :label =" t('Visibility')"
75
+ only-icon
76
+ size =" small"
77
+ type =" black"
78
+ @click =" onClickVisibility(slotProps.data)"
79
+ />
80
+ <BaseButton
81
+ :label =" t('Upload corrections')"
82
+ icon =" file-upload"
83
+ only-icon
84
+ size =" small"
85
+ type =" black"
86
+ />
87
+ <BaseButton
88
+ :disabled =" 0 === slotProps.data.uniqueStudentAttemptsTotal"
89
+ :label =" t('Save')"
90
+ icon =" download"
91
+ only-icon
92
+ size =" small"
93
+ type =" black"
94
+ />
95
+ <BaseButton
96
+ :label =" t('Edit')"
97
+ icon =" edit"
98
+ only-icon
99
+ size =" small"
100
+ type =" black"
101
+ @click =" onClickEdit(slotProps.data)"
102
+ />
103
+ </div >
95
104
</template >
96
105
</Column >
97
106
110
119
<script setup>
111
120
import DataTable from " primevue/datatable"
112
121
import Column from " primevue/column"
113
- import { onMounted , reactive , ref , watch } from " vue"
122
+ import { onMounted , reactive , ref , watch , computed } from " vue"
114
123
import { useI18n } from " vue-i18n"
115
124
import cStudentPublicationService from " ../../services/cstudentpublication"
116
125
import { useCidReq } from " ../../composables/cidReq"
117
126
import { useFormatDate } from " ../../composables/formatDate"
118
127
import BaseTag from " ../basecomponents/BaseTag.vue"
119
128
import BaseButton from " ../basecomponents/BaseButton.vue"
129
+ import BaseIcon from " ../basecomponents/BaseIcon.vue"
120
130
import { RESOURCE_LINK_DRAFT , RESOURCE_LINK_PUBLISHED } from " ../../constants/entity/resourcelink"
121
131
import { useNotification } from " ../../composables/notification"
122
132
import { useConfirm } from " primevue/useconfirm"
123
133
import resourceLinkService from " ../../services/resourcelink"
124
- import { useRouter } from " vue-router"
134
+ import { useRoute , useRouter } from " vue-router"
135
+ import { checkIsAllowedToEdit } from " ../../composables/userPermissions"
136
+ import { useSecurityStore } from " ../../store/securityStore"
125
137
126
138
const { t } = useI18n ()
139
+ const route = useRoute ();
127
140
const router = useRouter ()
128
141
129
142
const assignments = ref ([])
@@ -136,6 +149,8 @@ const { cid, sid, gid } = useCidReq()
136
149
const notification = useNotification ()
137
150
138
151
const confirm = useConfirm ()
152
+ const securityStore = useSecurityStore ()
153
+ const isCurrentTeacher = computed (() => securityStore .isCurrentTeacher )
139
154
140
155
const { abbreviatedDatetime } = useFormatDate ()
141
156
@@ -145,20 +160,33 @@ const loadParams = reactive({
145
160
itemsPerPage: 10 ,
146
161
})
147
162
148
- function loadData () {
163
+ const isAllowedToEdit = ref (false )
164
+
165
+ onMounted (async () => {
166
+ isAllowedToEdit .value = await checkIsAllowedToEdit (true , true , true )
167
+ loadData ()
168
+ })
169
+
170
+ watch (loadParams, () => {
171
+ loadData ()
172
+ })
173
+
174
+ async function loadData () {
149
175
loading .value = true
150
176
151
- cStudentPublicationService
152
- .findAll ({
177
+ try {
178
+ const response = await cStudentPublicationService .findAll ({
153
179
params: { ... loadParams, cid, sid, gid },
154
180
})
155
- .then ((response ) => response .json ())
156
- .then ((json ) => {
157
- assignments .value = json[" hydra:member" ]
158
- totalRecords .value = json[" hydra:totalItems" ]
181
+ const json = await response .json ()
159
182
160
- loading .value = false
161
- })
183
+ assignments .value = json[" hydra:member" ]
184
+ totalRecords .value = json[" hydra:totalItems" ]
185
+ } catch (error) {
186
+ notification .showErrorNotification (error)
187
+ } finally {
188
+ loading .value = false
189
+ }
162
190
}
163
191
164
192
const onPage = (event ) => {
@@ -175,14 +203,6 @@ const onSort = (event) => {
175
203
})
176
204
}
177
205
178
- onMounted (() => {
179
- loadData ()
180
- })
181
-
182
- watch (loadParams, () => {
183
- loadData ()
184
- })
185
-
186
206
function onClickMultipleDelete () {
187
207
confirm .require ({
188
208
header: t (" Confirmation" ),
@@ -226,9 +246,37 @@ async function onClickVisibility(assignment) {
226
246
}
227
247
228
248
function onClickEdit (assignment ) {
249
+ const assignmentId = parseInt (assignment[" @id" ].split (' /' ).pop (), 10 );
250
+
251
+ console .log (' onClickEdit id :::' , assignmentId);
252
+
229
253
router .push ({
230
- name: " AssigmnentsUpdate" ,
231
- query: { id: assignment[" @id" ], cid, sid, gid },
232
- })
254
+ name: " AssignmentsUpdate" ,
255
+ params: { id: assignment[" @id" ] },
256
+ query: route .query ,
257
+ });
258
+ }
259
+
260
+ const getSessionId = (item ) => {
261
+ if (! item .firstResourceLink || ! item .firstResourceLink .session ) {
262
+ return null ;
263
+ }
264
+
265
+ const sessionParts = item .firstResourceLink .session .split (' /' );
266
+ return parseInt (sessionParts[sessionParts .length - 1 ]);
267
+ }
268
+
269
+ const canEdit = (item ) => {
270
+ const sessionId = getSessionId (item);
271
+
272
+ console .log (' sessionId ::: ' , sessionId)
273
+
274
+ const isSessionDocument = sessionId && sessionId === sid;
275
+ const isBaseCourse = ! sessionId;
276
+
277
+ return (
278
+ (isSessionDocument && isAllowedToEdit .value ) ||
279
+ (isBaseCourse && ! sid && isCurrentTeacher .value )
280
+ );
233
281
}
234
282
</script >
0 commit comments