fixed errors in admin
This commit is contained in:
parent
f7af5501da
commit
002d3c88a9
2 changed files with 95 additions and 92 deletions
|
@ -3,90 +3,98 @@
|
||||||
<div id="add-list-container" class="my-5">
|
<div id="add-list-container" class="my-5">
|
||||||
<label class="text-md font-bold" for="add-list">Add List</label>
|
<label class="text-md font-bold" for="add-list">Add List</label>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<input id="add-list" class="p-1 rounded-l" placeholder="List Title" type="text" v-on:keyup.enter="addList"/>
|
<input
|
||||||
|
id="add-list"
|
||||||
|
class="p-1 rounded-l"
|
||||||
|
placeholder="List Title"
|
||||||
|
type="text"
|
||||||
|
v-on:keyup.enter="addList"
|
||||||
|
/>
|
||||||
|
|
||||||
<button class="btn p-1 rounded-r" @click="addList">Add</button>
|
<button class="btn p-1 rounded-r" @click="addList">Add</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ul class="grid grid-rows gap-2">
|
<ul class="grid grid-rows gap-2">
|
||||||
<li v-for="list in lists" class="movie-card p-3 neon-border">
|
<li v-for="list in lists" class="movie-card p-3 neon-border">
|
||||||
<span class="mb-2">{{ list.name }}</span> <br/>
|
<span class="mb-2">{{ list.name }}</span> <br />
|
||||||
<button class="btn mt-2 p-1 rounded" type="button" @click="deleteList(list.id)">Delete</button>
|
<button
|
||||||
|
class="btn mt-2 p-1 rounded"
|
||||||
|
type="button"
|
||||||
|
@click="deleteList(list.id)"
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script lang="ts" setup>
|
||||||
export default {
|
import type { MovieList } from "~/types/movielist";
|
||||||
name: "lists",
|
|
||||||
data: () => ({
|
|
||||||
lists: [],
|
|
||||||
}),
|
|
||||||
methods: {
|
|
||||||
addList: async function () {
|
|
||||||
let config = useRuntimeConfig();
|
|
||||||
const list_name = document.getElementById("add-list").value;
|
|
||||||
if (!list_name) {
|
|
||||||
alert("Please add list name.");
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let list_json = await fetch(`${config.public.apiURL}/lists`, {
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify({
|
|
||||||
name: list_name,
|
|
||||||
public: false
|
|
||||||
}),
|
|
||||||
headers: {
|
|
||||||
"Content-type": "application/json",
|
|
||||||
"token": useCookie("token").value,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(json => json)
|
|
||||||
.catch(err => console.log(err))
|
|
||||||
|
|
||||||
list_json.list.movie_count = 0;
|
const lists = defineModel<MovieList[]>("lists", { default: [] });
|
||||||
this.lists.push(list_json.list);
|
|
||||||
},
|
|
||||||
deleteList: function (list_id) {
|
|
||||||
const config = useRuntimeConfig();
|
|
||||||
let confirmed = confirm("Delete list?");
|
|
||||||
|
|
||||||
if (!confirmed) {
|
const addList = async function () {
|
||||||
return false;
|
let config = useRuntimeConfig();
|
||||||
}
|
let list_name = (document.getElementById("add-list") as HTMLInputElement)
|
||||||
|
.value;
|
||||||
|
|
||||||
return fetch(`${config.public.apiURL}/lists/${list_id}`, {
|
if (!list_name) {
|
||||||
credentials: "include",
|
alert("Please add list name.");
|
||||||
method: "DELETE",
|
return;
|
||||||
headers: {
|
|
||||||
"Content-type": "application/json",
|
|
||||||
"token": useCookie("token").value,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(_json => {
|
|
||||||
window.location.reload();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
getLists: function () {
|
|
||||||
const config = useRuntimeConfig();
|
|
||||||
fetch(`${config.public.apiURL}/lists`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: {"Content-type": "application/json"}
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(json => this.lists = json)
|
|
||||||
.catch(err => console.log(err))
|
|
||||||
},
|
|
||||||
},
|
|
||||||
mounted() {
|
|
||||||
this.getLists();
|
|
||||||
}
|
}
|
||||||
}
|
await $fetch<MovieList>(`${config.public.apiURL}/lists/`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({
|
||||||
|
name: list_name,
|
||||||
|
public: false,
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json",
|
||||||
|
Authorization: `Token ${useCookie("token").value}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((data) => {
|
||||||
|
lists.value = [...lists.value, data];
|
||||||
|
(document.getElementById("add-list") as HTMLInputElement).value = "";
|
||||||
|
})
|
||||||
|
.catch((err) => console.log(err));
|
||||||
|
};
|
||||||
|
const deleteList = function (list_id: number) {
|
||||||
|
const config = useRuntimeConfig();
|
||||||
|
let confirmed = confirm("Delete list?");
|
||||||
|
|
||||||
|
if (!confirmed) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$fetch(`${config.public.apiURL}/lists/${list_id}/`, {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json",
|
||||||
|
Authorization: `Token ${useCookie("token").value}`,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
lists.value = lists.value.filter((list) => {
|
||||||
|
return list.id !== list_id;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => console.log(err));
|
||||||
|
};
|
||||||
|
const getLists = function () {
|
||||||
|
const config = useRuntimeConfig();
|
||||||
|
$fetch<MovieList[]>(`${config.public.apiURL}/lists`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: { "Content-type": "application/json" },
|
||||||
|
})
|
||||||
|
.then((data) => (lists.value = data))
|
||||||
|
.catch((err) => console.log(err));
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
getLists();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped></style>
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
import type { Showing } from "~/types/showing";
|
import type { Showing } from "~/types/showing";
|
||||||
import { useCookie } from "#app";
|
import { useCookie } from "#app";
|
||||||
import type { Schedule } from "~/types/schedule";
|
import type { Schedule } from "~/types/schedule";
|
||||||
|
import { $fetch } from "ofetch";
|
||||||
|
|
||||||
const showings = defineModel<Showing[]>("showings", { default: [] });
|
const showings = defineModel<Showing[]>("showings", { default: [] });
|
||||||
const previous_showings = defineModel<Showing[]>("previous_showings", {
|
const previous_showings = defineModel<Showing[]>("previous_showings", {
|
||||||
|
@ -86,33 +87,27 @@ const getShowings = function (previous = false) {
|
||||||
let params = "";
|
let params = "";
|
||||||
if (previous) params = "?previous=true";
|
if (previous) params = "?previous=true";
|
||||||
|
|
||||||
const { data, error } = useFetch<Schedule>(
|
$fetch<Schedule>(`${config.public.apiURL}/schedules/1${params}`, {
|
||||||
`${config.public.apiURL}/schedules/1${params}`,
|
method: "GET",
|
||||||
{
|
headers: {
|
||||||
method: "GET",
|
"Content-type": "application/json",
|
||||||
headers: {
|
Authorization: `Token ${useCookie("token").value}`,
|
||||||
"Content-type": "application/json",
|
|
||||||
Authorization: `Token ${useCookie("token").value}`,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
})
|
||||||
|
.then((data) => {
|
||||||
if (error.value) {
|
|
||||||
if (error.value.statusCode === 401) {
|
|
||||||
alert("Unauthorized");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!data.value) {
|
|
||||||
alert("No showings found for schedule.");
|
|
||||||
} else {
|
|
||||||
if (previous) {
|
if (previous) {
|
||||||
got_previous.value = true;
|
got_previous.value = true;
|
||||||
previous_showings.value = data.value.showings;
|
previous_showings.value = data.showings;
|
||||||
} else {
|
} else {
|
||||||
showings.value = data.value.showings;
|
showings.value = data.showings;
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
.catch((err) => {
|
||||||
|
if (err.statusCode === 401) {
|
||||||
|
useCookie("token").value = null;
|
||||||
|
navigateTo("/");
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue