77 lines
No EOL
2.3 KiB
TypeScript
77 lines
No EOL
2.3 KiB
TypeScript
import {reactive, ref} from "vue";
|
|
import axios from "axios";
|
|
|
|
export function playlist_page() {
|
|
const items = ref([])
|
|
const selected = ref([])
|
|
const loading = ref(false)
|
|
const search = ref('')
|
|
const listData = reactive({
|
|
'itemsPerPage': 5,
|
|
'first_page': null,
|
|
'last_page': null,
|
|
'total_items': 0,
|
|
'page': 1,
|
|
})
|
|
|
|
const headers = [
|
|
// {title: '', key: 'artwork'},
|
|
{title: 'Nome playlist', value: 'name'},
|
|
{title: 'Creato da', value: 'creator.login'},
|
|
{title: 'Durata', value: 'length'},
|
|
{title: 'Ultima modifica', value: 'utime'},
|
|
{title: 'Azioni', value: 'actions'}
|
|
];
|
|
|
|
const getItems = async (page_info) => {
|
|
loading.value = true;
|
|
return await axios.get(`/playlist`, {
|
|
params: {
|
|
page: page_info.page,
|
|
per_page: page_info.itemsPerPage,
|
|
all: search.value
|
|
}
|
|
}).then((response) => {
|
|
console.log(response)
|
|
listData.itemsPerPage = response.data.per_page;
|
|
listData.first_page = response.data.from;
|
|
listData.last_page = response.data.last_page;
|
|
listData.page = response.data.current_page;
|
|
listData.total_items = response.data.total;
|
|
|
|
items.value = response.data.data
|
|
loading.value = false;
|
|
|
|
}).catch((error) => {
|
|
console.log("Error: "+error);
|
|
})
|
|
}
|
|
|
|
const createItem = async (item) => {
|
|
return await axios.post(`playlist`, item
|
|
).then((response) => {
|
|
console.log(response)
|
|
})
|
|
}
|
|
|
|
const editItem = async (item) => {
|
|
item['_method'] = 'PUT'
|
|
|
|
return await axios.post(`playlist/${item.id}`, item
|
|
).then((response) => {
|
|
console.log(response)
|
|
})
|
|
}
|
|
|
|
const deleteItem = (id) => {
|
|
|
|
return axios.post(`playlist/${id}`, {
|
|
_method: 'DELETE'
|
|
}).then((response) => {
|
|
getItems(listData)
|
|
// items.value = response.status === 200 ? items.value.filter(obj => obj.id !== id) : items
|
|
})
|
|
}
|
|
|
|
return { items, listData, headers, selected, loading, search, getItems, createItem, editItem, deleteItem }
|
|
} |