Compare commits

..

No commits in common. "55cbfee2b54a1b6a8865f8ea743b42d85a07914b" and "698d0ef6ff1b6ab75850f2f612c829acccfe42ec" have entirely different histories.

8 changed files with 139 additions and 192 deletions

9
.idea/workspace.xml generated
View file

@ -6,9 +6,12 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="5e320804-68c9-4504-97d5-d421de3438b2" name="Changes" comment=""> <list default="true" id="5e320804-68c9-4504-97d5-d421de3438b2" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/Modal.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/Modal.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/admin/search.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/admin/search.vue" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/components/admin/search.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/admin/search.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/admin/showings.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/admin/showings.vue" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/components/modal-content/AddMovie.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/modal-content/AddMovie.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/types/showing.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/types/showing.ts" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/pages/admin/index.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/admin/index.vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/lists/[id].vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/lists/[id].vue" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/pages/lists/index.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/lists/index.vue" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -64,7 +67,7 @@
&quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;, &quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;, &quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
&quot;code.cleanup.on.save&quot;: &quot;true&quot;, &quot;code.cleanup.on.save&quot;: &quot;true&quot;,
&quot;git-widget-placeholder&quot;: &quot;showings-updates&quot;, &quot;git-widget-placeholder&quot;: &quot;movie-search&quot;,
&quot;last_opened_file_path&quot;: &quot;/home/tiradoe/Projects/movie-night/web/src/types&quot;, &quot;last_opened_file_path&quot;: &quot;/home/tiradoe/Projects/movie-night/web/src/types&quot;,
&quot;list.type.of.created.stylesheet&quot;: &quot;CSS&quot;, &quot;list.type.of.created.stylesheet&quot;: &quot;CSS&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,

View file

@ -32,7 +32,6 @@ 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();

View file

@ -9,56 +9,31 @@
<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 <button class="btn p-1 rounded" type="button" @click="deleteShowing(showing.id)">Delete</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 lang="ts" setup> <script>
import type { Showing } from "~/types/showing"; export default {
import { useCookie } from "#app"; name: "showings",
import type { Schedule } from "~/types/schedule"; data: () => ({
showings: [],
const showings = defineModel<Showing[]>("showings", { default: [] }); months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
const previous_showings = defineModel<Showing[]>("previous_showings", { }),
default: [], mounted() {
}); this.getShowings()
const got_previous = ref(false); },
const months = [ methods: {
"January", formatDate: function (date_string) {
"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 parsed_date = new Date(Date.parse(date_string));
let month = months[parsed_date.getMonth()]; let month = this.months[parsed_date.getMonth()];
return `${month} ${parsed_date.getDate()}, ${parsed_date.getFullYear()}`; return `${month} ${parsed_date.getDate()}, ${parsed_date.getFullYear()}`
}; },
deleteShowing: function (showing_id) {
const deleteShowing = function (showing_id: number) {
let config = useRuntimeConfig(); let config = useRuntimeConfig();
let confirmed = confirm("Delete showing?"); let confirmed = confirm("Delete showing?");
@ -66,54 +41,46 @@ const deleteShowing = function (showing_id: number) {
return false; return false;
} }
fetch(`${config.public.apiURL}/showings/${showing_id}/`, { return fetch(`${config.public.apiURL}/schedules/${showing_id}`, {
credentials: "include",
method: "DELETE", method: "DELETE",
headers: { headers: {
"Content-type": "application/json", "Content-type": "application/json",
Authorization: `Token ${useCookie("token").value}`, "token": useCookie("token").value
}, }
})
.then(response => response.json())
.then(json => {
this.showings = this.showings.filter((showing) => {
return showing.id !== showing_id
}) })
.then((_json) => {
showings.value = showings.value.filter((showing) => {
return showing.id !== showing_id;
}); });
}) },
.catch((err) => console.log(err)); getShowings: function (previous = false) {
};
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";
const { data, error } = useFetch<Schedule>( return fetch(`${config.public.apiURL}/schedules/1${params}`, {
`${config.public.apiURL}/schedules/1${params}`,
{
method: "GET", method: "GET",
headers: { headers: {"Content-type": "application/json"}
"Content-type": "application/json", })
Authorization: `Token ${useCookie("token").value}`, .then(response => response.json())
}, .then(showings => {
},
);
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; this.got_previous = true;
previous_showings.value = data.value.showings; this.previous_showings = showings;
} else { } else {
showings.value = data.value.showings; this.showings = showings
}
})
.catch(err => console.log(err));
} }
} }
} }
};
</script> </script>
<style scoped></style> <style scoped>
</style>

View file

@ -1,69 +1,58 @@
<template> <template>
<div> <div>
<form <form id="schedule-form" class="visually-hidden" method="post" onsubmit="return false">
id="schedule-form"
class="visually-hidden"
method="post"
onsubmit="return false"
>
<!-- SCHEDULE --> <!-- SCHEDULE -->
<label class="pb-1 text-start font-bold" for="schedule-date">Date</label <label class="pb-1 text-start font-bold" for="schedule-date">Date</label><br/>
><br /> <input id="schedule-input" class="rounded-l p-1" name="schedule-date"
<input type="date"/>
id="schedule-input" <button class="btn mt-5 sm:mt-0 p-1 rounded sm:rounded-none sm:rounded-r" type="button" @click="schedule">Schedule
class="rounded-l p-1"
name="schedule-date"
type="date"
/>
<button
class="btn mt-5 sm:mt-0 p-1 rounded sm:rounded-none sm:rounded-r"
type="button"
@click="schedule"
>
Schedule
</button> </button>
</form> </form>
</div> </div>
</template> </template>
<script lang="ts" setup> <script>
const props = defineProps(["movie"]); export default {
const emits = defineEmits(["closeModal"]); name: "ScheduleMovie",
methods: {
const schedule = function (e: Event) { schedule: function (e) {
const config = useRuntimeConfig(); const config = useRuntimeConfig();
e.preventDefault(); e.preventDefault();
let showtime_input = ( let showtime_input = document.getElementById("schedule-input").value;
document.getElementById("schedule-input") as HTMLInputElement
).value;
if (!showtime_input) { if (!showtime_input) {
alert("Please set showtime."); alert("Please set showtime.");
return false; return false;
} }
let showtime = showtime_input + " " + "00:00:00";
const date = new Date(`${showtime_input}T00:00:00`); fetch(`${config.public.apiURL}/schedules/movie`, {
credentials: "include",
fetch(`${config.public.apiURL}/showings/`, {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
schedule: 1, "schedule_id": 1,
movie: props.movie.id, "movie_id": this.movie.id,
showtime: date.toISOString(), "showtime": showtime,
public: "False", "owner": 1,
"public": false
}), }),
headers: { headers: {
"Content-type": "application/json", "Content-type": "application/json",
Authorization: `Token ${useCookie("token").value}`, "token": useCookie("token").value,
}
})
.then(response => response.json())
.then(_json => {
this.$parent.$parent.closeModal();
}
)
.catch(err => alert("Unable to schedule movie. Error:\n" + err))
}
}, },
}) props: ["movie"]
.then((response) => response.json()) }
.then((_json) => {
emits("closeModal");
})
.catch((err) => alert("Unable to schedule movie. Error:\n" + err));
};
</script> </script>
<style scoped></style> <style scoped>
</style>

View file

@ -5,38 +5,36 @@
{{ movie.title }} ({{ movie.year }}) {{ movie.title }} ({{ movie.year }})
</h2> </h2>
<div class="sm:inline-flex sm:space-x-5"> <div class="sm:inline-flex sm:space-x-5">
<img <img :src="movie.poster" alt="movie poster" class="mx-auto sm:mx-0 neon-border"/>
:src="movie.poster"
alt="movie poster"
class="mx-auto sm:mx-0 neon-border"
/>
<div class="pt-5 sm:pt-0"> <div class="pt-5 sm:pt-0">
<p>{{ movie.plot }}</p> <p>{{ movie.plot }}</p>
<ScheduleMovie <ScheduleMovie v-if="logged_in" :movie="movie" class="mt-5"/>
v-if="logged_in"
:movie="movie"
class="mt-5"
@close-modal="$emit('close-modal')"
/>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script lang="ts" setup> <script>
import ScheduleMovie from "~/components/forms/ScheduleMovie.vue"; import ScheduleMovie from "~/components/forms/ScheduleMovie.vue";
const props = defineProps(["movie"]); export default {
const emits = defineEmits(["close-modal"]); name: "ShowMovie",
const logged_in = ref(false); data: () => ({
logged_in: false,
onMounted(() => { }),
components: {ScheduleMovie},
props: ["movie"],
mounted() {
const token = useCookie("token").value; const token = useCookie("token").value;
if (token) { if (token) {
logged_in.value = true; this.logged_in = true;
}
}
} }
});
</script> </script>
<style scoped></style> <style scoped>
</style>

View file

@ -1,11 +1,7 @@
<template> <template>
<div v-if="list_id !== 0" class="p-5 sm:p-0"> <div v-if="list_id !== 0" class="p-5 sm:p-0">
<Modal ref="movie_modal"> <Modal ref="movie_modal">
<ShowMovie <ShowMovie v-if="modal_movie" :movie="modal_movie"></ShowMovie>
v-if="modal_movie"
:movie="modal_movie"
@close-modal="closeModal"
></ShowMovie>
</Modal> </Modal>
<h2 class="text-xl font-bold pb-5">{{ list.name }}</h2> <h2 class="text-xl font-bold pb-5">{{ list.name }}</h2>
<div class="grid grid-cols-2 rounded movie-card neon-border p-5"> <div class="grid grid-cols-2 rounded movie-card neon-border p-5">
@ -70,6 +66,8 @@ import type { MovieList } from "~/types/movielist";
import type { Movie } from "~/types/movie"; import type { Movie } from "~/types/movie";
import Modal from "~/components/Modal.vue"; import Modal from "~/components/Modal.vue";
const movie_modal = ref<InstanceType<typeof Modal> | null>(null);
const list_id = ref(0); const list_id = ref(0);
const list = defineModel<MovieList>("movie_list", { default: [] }); const list = defineModel<MovieList>("movie_list", { default: [] });
const modal_movie: Ref<Movie | null> = ref(null); const modal_movie: Ref<Movie | null> = ref(null);
@ -184,11 +182,6 @@ const showModal = function (movie: Movie) {
movie_modal.value?.toggleModal(); movie_modal.value?.toggleModal();
}; };
const movie_modal = ref<InstanceType<typeof Modal> | null>(null);
const closeModal = function (movie: Movie) {
movie_modal.value?.toggleModal();
};
onMounted(() => { onMounted(() => {
const route = useRoute(); const route = useRoute();
if (typeof route.params.id === "string") { if (typeof route.params.id === "string") {

View file

@ -83,10 +83,10 @@ const months = [
]; ];
const formatDate = function (date_string: string) { const formatDate = function (date_string: string) {
let date = new Date(date_string); let parsed_date = new Date(Date.parse(date_string));
let month = months[date.getMonth()]; let month = months[parsed_date.getMonth()];
return `${month} ${date.getDate()}, ${date.getFullYear()}`; return `${month} ${parsed_date.getDate()}, ${parsed_date.getFullYear()}`;
}; };
const getSchedule = async function (previous = false) { const getSchedule = async function (previous = false) {

View file

@ -1,10 +1,8 @@
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;
}; };