bug fixes

This commit is contained in:
2023-04-23 19:53:10 +10:00
parent 031db78590
commit 0fadfed7f6
4 changed files with 57 additions and 73 deletions

View File

@@ -157,6 +157,15 @@ if (props.form !== undefined) {
); );
} }
if (props.disabled !== undefined) {
watch(
() => props.disabled,
(newValue) => {
disabled.value = newValue;
}
);
}
onMounted(() => { onMounted(() => {
if (buttonRef.value) { if (buttonRef.value) {
minWidth.value = `${buttonRef.value.clientWidth}px`; minWidth.value = `${buttonRef.value.clientWidth}px`;

View File

@@ -132,6 +132,7 @@ import SMControl from "./SMControl.vue";
import SMButton from "./SMButton.vue"; import SMButton from "./SMButton.vue";
import { openDialog } from "./SMDialog"; import { openDialog } from "./SMDialog";
import SMDialogMedia from "./dialogs/SMDialogMedia.vue"; import SMDialogMedia from "./dialogs/SMDialogMedia.vue";
import { Media } from "../helpers/api.types";
const emits = defineEmits(["update:modelValue", "blur", "keyup"]); const emits = defineEmits(["update:modelValue", "blur", "keyup"]);
const props = defineProps({ const props = defineProps({
@@ -357,17 +358,17 @@ const handleChange = (event) => {
} }
}; };
const handleMediaSelect = async (event) => { const handleMediaSelect = async () => {
let result = await openDialog(SMDialogMedia); let result = await openDialog(SMDialogMedia);
if (result) { if (result) {
console.log(result); const mediaResult = result as Media;
// mediaUrl.value = result.url; mediaUrl.value = mediaResult.url;
// emits("update:modelValue", result.id); emits("update:modelValue", mediaResult);
// if (control) { if (control) {
// control.value = result.id; control.value = mediaResult;
// feedbackInvalid.value = ""; feedbackInvalid.value = "";
// } }
} }
}; };
</script> </script>

View File

@@ -23,7 +23,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed } from "vue"; import { computed, watch } from "vue";
const props = defineProps({ const props = defineProps({
modelValue: { modelValue: {
@@ -127,10 +127,10 @@ const handleClickPage = (page: number): void => {
emits("update:modelValue", page); emits("update:modelValue", page);
}; };
if (props.modelValue < 1) { const totalPages = computedTotalPages.value;
if (props.modelValue < 1 || totalPages < 1) {
emits("update:modelValue", 1); emits("update:modelValue", 1);
} else { } else {
const totalPages = computedTotalPages.value;
if (totalPages < props.modelValue) { if (totalPages < props.modelValue) {
emits("update:modelValue", totalPages); emits("update:modelValue", totalPages);
} }

View File

@@ -20,7 +20,8 @@
label="Search" label="Search"
class="toolbar-search" class="toolbar-search"
size="small" size="small"
@keyup.enter="handleSearch"> @keyup.enter="handleSearch"
@blur="handleSearch">
<template #append> <template #append>
<SMButton <SMButton
type="primary" type="primary"
@@ -55,16 +56,12 @@
}" }"
class="media-image"></div> class="media-image"></div>
<span class="media-title">{{ item.title }}</span> <span class="media-title">{{ item.title }}</span>
<span class="media-size">{{
bytesReadable(item.size)
}}</span>
</li> </li>
</ul> </ul>
</div> </div>
</div> </div>
<SMRow> <SMRow>
<SMPagination <SMPagination
v-if="mediaItems.length < totalItems"
v-model="page" v-model="page"
:total="totalItems" :total="totalItems"
:per-page="perPage" :per-page="perPage"
@@ -194,20 +191,6 @@ const perPage = ref(24);
const applicationStore = useApplicationStore(); const applicationStore = useApplicationStore();
/**
* Returns the pagination info
*/
const computedPaginationInfo = computed(() => {
if (totalItems.value == 0) {
return "0 - 0 of 0";
}
const start = (page.value - 1) * perPage.value + 1;
const end = start + perPage.value - 1;
return `${start} - ${end} of ${totalItems.value}`;
});
/** /**
* Returns the file types accepted. * Returns the file types accepted.
*/ */
@@ -223,27 +206,6 @@ const computedAccepts = computed(() => {
return props.mime; return props.mime;
}); });
/**
* Return the total number of pages.
*/
const computedTotalPages = computed(() => {
return Math.ceil(totalItems.value / perPage.value);
});
/**
* Return if the previous button should be disabled.
*/
const computedDisablePrevButton = computed(() => {
return page.value <= 1;
});
/**
* Return if the next button should be disabled.
*/
const computedDisableNextButton = computed(() => {
return page.value >= computedTotalPages.value;
});
/** /**
* Get the media item by id. * Get the media item by id.
* *
@@ -435,18 +397,37 @@ const handleChangeUpload = async () => {
} }
}; };
const itemSearch = ref("");
const handleSearch = () => {
mediaItems.value = [];
totalItems.value = 0;
page.value = 1;
handleLoad();
};
/** /**
* Load the data of the dialog * Load the data of the dialog
*/ */
const handleLoad = async () => { const handleLoad = async () => {
mediaLoading.value = true; mediaLoading.value = true;
let params = {
page: page.value,
limit: perPage.value,
};
if (itemSearch.value.length > 0) {
let value = itemSearch.value.replace(/"/g, '\\"');
params[
"filter"
] = `(title:"${value}",OR,name:"${value}",OR,description:"${value}")`;
}
api.get({ api.get({
url: "/media", url: "/media",
params: { params: params,
page: page.value,
limit: perPage.value,
},
}) })
.then((result) => { .then((result) => {
if (result.data) { if (result.data) {
@@ -518,15 +499,15 @@ handleLoad();
background-color: #fff; background-color: #fff;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
margin: 0 0 1rem 0; margin: 0 0 16px 0;
.media-none { .media-none {
font-size: 1.5rem; font-size: 150%;
text-align: center; text-align: center;
ion-icon { ion-icon {
font-size: 3rem; font-size: 200%;
margin-bottom: 0.5rem; margin-bottom: 16px;
} }
} }
@@ -537,9 +518,9 @@ handleLoad();
max-height: 40vh; max-height: 40vh;
height: 100%; height: 100%;
width: 100%; width: 100%;
gap: 1rem; gap: 8px;
justify-content: center; justify-content: center;
padding: map-get($spacer, 3); padding: 0;
li { li {
display: flex; display: flex;
@@ -576,17 +557,13 @@ handleLoad();
.media-image { .media-image {
width: 64px; width: 64px;
height: 64px; height: 64px;
margin-right: map-get($spacer, 1); margin-right: 8px;
} }
.media-title { .media-title {
flex: 1; flex: 1;
text-align: left; text-align: left;
} }
.media-size {
font-size: 75%;
}
} }
&.media-browser-grid { &.media-browser-grid {
@@ -598,7 +575,7 @@ handleLoad();
li { li {
flex-direction: column; flex-direction: column;
height: 194px; height: 160px;
width: 220px; width: 220px;
.media-image { .media-image {
@@ -608,17 +585,14 @@ handleLoad();
.media-title { .media-title {
text-align: center; text-align: center;
padding: map-get($spacer, 1) 4px; padding: 4px;
width: 13rem; font-size: 80%;
width: 224px;
display: block; display: block;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
.media-size {
font-size: 75%;
}
} }
} }
} }