Skip to content

Commit

Permalink
Documents: Improve file variation - refs chamilo#5956
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbeeznest committed Jan 3, 2025
1 parent 37d6e93 commit 2fc1932
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
40 changes: 37 additions & 3 deletions assets/vue/views/documents/AddVariation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@
</template>
</Column>
<Column field="creator" :header="t('Creator')" />
<Column field="accessUrl" :header="t('Associated URL')">
<template #body="slotProps">
<span>
{{ slotProps.data.url ? slotProps.data.url : t('Default (No URL)') }}
</span>
</template>
</Column>
<Column>
<template #header>{{ t('Actions') }}</template>
<template #body="slotProps">
<BaseButton
:label="t('Delete')"
icon="delete"
type="danger"
@click="deleteVariant(slotProps.data.id)"
/>
</template>
</Column>
</DataTable>
</div>
</div>
Expand All @@ -90,22 +108,28 @@ import SectionHeader from "../../components/layout/SectionHeader.vue"
import BaseButton from "../../components/basecomponents/BaseButton.vue"
import BaseFileUpload from "../../components/basecomponents/BaseFileUpload.vue"
import prettyBytes from 'pretty-bytes'
import { useStore } from "vuex"
import { useCidReq } from "../../composables/cidReq"
import { useSecurityStore } from "../../store/securityStore"
const store = useStore()
const securityStore = useSecurityStore()
const route = useRoute()
const router = useRouter()
const { t } = useI18n()
const { cid, sid, gid } = useCidReq()
const file = ref(null)
const variations = ref([])
const originalFile = ref(null)
const resourceFileId = route.params.resourceFileId;
const resourceFileId = route.params.resourceFileId
const selectedAccessUrl = ref(null)
const accessUrls = ref([])
const isAdmin = computed(() => securityStore.isAdmin)
onMounted(async () => {
if (!isAdmin.value) {
await router.push({ name: 'DocumentsList' })
return
}
await fetchOriginalFile()
await fetchVariations()
await fetchAccessUrls()
Expand Down Expand Up @@ -178,6 +202,16 @@ async function uploadVariant(file, resourceNodeId, accessUrlId) {
}
}
async function deleteVariant(variantId) {
try {
await axios.delete(`/r/resource_files/${variantId}/delete_variant`)
console.log('Variant deleted successfully.')
await fetchVariations()
} catch (error) {
console.error('Error deleting variant:', error)
}
}
function onFileSelected(selectedFile) {
file.value = selectedFile
}
Expand Down
2 changes: 1 addition & 1 deletion assets/vue/views/documents/DocumentsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
/>

<BaseButton
v-if="canEdit(slotProps.data) && allowAccessUrlFiles && isFile(slotProps.data)"
v-if="canEdit(slotProps.data) && allowAccessUrlFiles && isFile(slotProps.data) && securityStore.isAdmin"
icon="file-replace"
size="small"
type="secondary"
Expand Down
14 changes: 14 additions & 0 deletions src/CoreBundle/Controller/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,20 @@ public function getVariants(string $resourceNodeId, EntityManagerInterface $em):
return $this->json($data);
}

#[Route('/resource_files/{id}/delete_variant', methods: ['DELETE'], name: 'chamilo_core_resource_files_delete_variant')]
public function deleteVariant(int $id, EntityManagerInterface $em): JsonResponse
{
$variant = $em->getRepository(ResourceFile::class)->find($id);
if (!$variant) {
return $this->json(['error' => 'Variant not found'], Response::HTTP_NOT_FOUND);
}

$em->remove($variant);
$em->flush();

return $this->json(['success' => true]);
}

private function processFile(Request $request, ResourceNode $resourceNode, string $mode = 'show', string $filter = '', ?array $allUserInfo = null, ?ResourceFile $resourceFile = null): mixed
{
$this->denyAccessUnlessGranted(
Expand Down

0 comments on commit 2fc1932

Please sign in to comment.