showings-updates #3
3 changed files with 97 additions and 61 deletions
|
@ -32,6 +32,7 @@ const movies = defineModel<Movie[]>("movie_list", { default: [] });
|
||||||
const showModal = (movie: Movie) => {
|
const showModal = (movie: Movie) => {
|
||||||
emit("show-modal", movie);
|
emit("show-modal", movie);
|
||||||
};
|
};
|
||||||
|
|
||||||
const findMovies = async function (e: Event) {
|
const findMovies = async function (e: Event) {
|
||||||
let config = useRuntimeConfig();
|
let config = useRuntimeConfig();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
|
@ -9,31 +9,56 @@
|
||||||
<li class="pb-2">
|
<li class="pb-2">
|
||||||
<span class="mb-3">{{ formatDate(showing.showtime) }} </span>
|
<span class="mb-3">{{ formatDate(showing.showtime) }} </span>
|
||||||
</li>
|
</li>
|
||||||
<button class="btn p-1 rounded" type="button" @click="deleteShowing(showing.id)">Delete</button>
|
<button
|
||||||
|
class="btn p-1 rounded"
|
||||||
|
type="button"
|
||||||
|
@click="deleteShowing(showing.id)"
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script lang="ts" setup>
|
||||||
export default {
|
import type { Showing } from "~/types/showing";
|
||||||
name: "showings",
|
import { useCookie } from "#app";
|
||||||
data: () => ({
|
import type { Schedule } from "~/types/schedule";
|
||||||
showings: [],
|
|
||||||
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
|
|
||||||
}),
|
|
||||||
mounted() {
|
|
||||||
this.getShowings()
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
formatDate: function (date_string) {
|
|
||||||
let parsed_date = new Date(Date.parse(date_string));
|
|
||||||
let month = this.months[parsed_date.getMonth()];
|
|
||||||
|
|
||||||
return `${month} ${parsed_date.getDate()}, ${parsed_date.getFullYear()}`
|
const showings = defineModel<Showing[]>("showings", { default: [] });
|
||||||
},
|
const previous_showings = defineModel<Showing[]>("previous_showings", {
|
||||||
deleteShowing: function (showing_id) {
|
default: [],
|
||||||
|
});
|
||||||
|
const got_previous = ref(false);
|
||||||
|
const months = [
|
||||||
|
"January",
|
||||||
|
"February",
|
||||||
|
"March",
|
||||||
|
"April",
|
||||||
|
"May",
|
||||||
|
"June",
|
||||||
|
"July",
|
||||||
|
"August",
|
||||||
|
"September",
|
||||||
|
"October",
|
||||||
|
"November",
|
||||||
|
"December",
|
||||||
|
];
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
getShowings();
|
||||||
|
});
|
||||||
|
|
||||||
|
const formatDate = function (date_string: string) {
|
||||||
|
let parsed_date = new Date(Date.parse(date_string));
|
||||||
|
let month = months[parsed_date.getMonth()];
|
||||||
|
|
||||||
|
return `${month} ${parsed_date.getDate()}, ${parsed_date.getFullYear()}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteShowing = function (showing_id: number) {
|
||||||
let config = useRuntimeConfig();
|
let config = useRuntimeConfig();
|
||||||
let confirmed = confirm("Delete showing?");
|
let confirmed = confirm("Delete showing?");
|
||||||
|
|
||||||
|
@ -41,46 +66,54 @@ export default {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fetch(`${config.public.apiURL}/schedules/${showing_id}`, {
|
fetch(`${config.public.apiURL}/showings/${showing_id}/`, {
|
||||||
credentials: "include",
|
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-type": "application/json",
|
"Content-type": "application/json",
|
||||||
"token": useCookie("token").value
|
Authorization: `Token ${useCookie("token").value}`,
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(json => {
|
|
||||||
this.showings = this.showings.filter((showing) => {
|
|
||||||
return showing.id !== showing_id
|
|
||||||
})
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
getShowings: function (previous = false) {
|
})
|
||||||
|
.then((_json) => {
|
||||||
|
showings.value = showings.value.filter((showing) => {
|
||||||
|
return showing.id !== showing_id;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => console.log(err));
|
||||||
|
};
|
||||||
|
|
||||||
|
const getShowings = function (previous = false) {
|
||||||
let config = useRuntimeConfig();
|
let config = useRuntimeConfig();
|
||||||
let params = "";
|
let params = "";
|
||||||
if (previous) params = "?previous=true";
|
if (previous) params = "?previous=true";
|
||||||
|
|
||||||
return fetch(`${config.public.apiURL}/schedules/1${params}`, {
|
const { data, error } = useFetch<Schedule>(
|
||||||
|
`${config.public.apiURL}/schedules/1${params}`,
|
||||||
|
{
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {"Content-type": "application/json"}
|
headers: {
|
||||||
})
|
"Content-type": "application/json",
|
||||||
.then(response => response.json())
|
Authorization: `Token ${useCookie("token").value}`,
|
||||||
.then(showings => {
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
if (previous) {
|
if (error.value) {
|
||||||
this.got_previous = true;
|
if (error.value.statusCode === 401) {
|
||||||
this.previous_showings = showings;
|
alert("Unauthorized");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.showings = showings
|
if (!data.value) {
|
||||||
}
|
alert("No showings found for schedule.");
|
||||||
})
|
} else {
|
||||||
.catch(err => console.log(err));
|
if (previous) {
|
||||||
|
got_previous.value = true;
|
||||||
|
previous_showings.value = data.value.showings;
|
||||||
|
} else {
|
||||||
|
showings.value = data.value.showings;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped></style>
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import type { Movie } from "~/types/movie";
|
import type { Movie } from "~/types/movie";
|
||||||
|
|
||||||
export type Showing = {
|
export type Showing = {
|
||||||
|
id: number;
|
||||||
owner: number;
|
owner: number;
|
||||||
public: boolean;
|
public: boolean;
|
||||||
|
title: string;
|
||||||
movie: Movie;
|
movie: Movie;
|
||||||
showtime: string;
|
showtime: string;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue