showings-updates #3
8 changed files with 192 additions and 139 deletions
9
.idea/workspace.xml
generated
9
.idea/workspace.xml
generated
|
@ -6,12 +6,9 @@
|
||||||
<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/modal-content/AddMovie.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/modal-content/AddMovie.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/pages/admin/index.vue" beforeDir="false" afterPath="$PROJECT_DIR$/src/pages/admin/index.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/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" />
|
||||||
|
@ -67,7 +64,7 @@
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"WebServerToolWindowFactoryState": "false",
|
"WebServerToolWindowFactoryState": "false",
|
||||||
"code.cleanup.on.save": "true",
|
"code.cleanup.on.save": "true",
|
||||||
"git-widget-placeholder": "movie-search",
|
"git-widget-placeholder": "showings-updates",
|
||||||
"last_opened_file_path": "/home/tiradoe/Projects/movie-night/web/src/types",
|
"last_opened_file_path": "/home/tiradoe/Projects/movie-night/web/src/types",
|
||||||
"list.type.of.created.stylesheet": "CSS",
|
"list.type.of.created.stylesheet": "CSS",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
|
|
|
@ -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,78 +9,111 @@
|
||||||
<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", {
|
||||||
|
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 confirmed = confirm("Delete showing?");
|
||||||
|
|
||||||
|
if (!confirmed) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fetch(`${config.public.apiURL}/showings/${showing_id}/`, {
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json",
|
||||||
|
Authorization: `Token ${useCookie("token").value}`,
|
||||||
},
|
},
|
||||||
deleteShowing: function (showing_id) {
|
})
|
||||||
let config = useRuntimeConfig();
|
.then((_json) => {
|
||||||
let confirmed = confirm("Delete showing?");
|
showings.value = showings.value.filter((showing) => {
|
||||||
|
return showing.id !== showing_id;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => console.log(err));
|
||||||
|
};
|
||||||
|
|
||||||
if (!confirmed) {
|
const getShowings = function (previous = false) {
|
||||||
return false;
|
let config = useRuntimeConfig();
|
||||||
|
let params = "";
|
||||||
|
if (previous) params = "?previous=true";
|
||||||
|
|
||||||
|
const { data, error } = useFetch<Schedule>(
|
||||||
|
`${config.public.apiURL}/schedules/1${params}`,
|
||||||
|
{
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json",
|
||||||
|
Authorization: `Token ${useCookie("token").value}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (error.value) {
|
||||||
|
if (error.value.statusCode === 401) {
|
||||||
|
alert("Unauthorized");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!data.value) {
|
||||||
|
alert("No showings found for schedule.");
|
||||||
|
} else {
|
||||||
|
if (previous) {
|
||||||
|
got_previous.value = true;
|
||||||
|
previous_showings.value = data.value.showings;
|
||||||
|
} else {
|
||||||
|
showings.value = data.value.showings;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fetch(`${config.public.apiURL}/schedules/${showing_id}`, {
|
|
||||||
credentials: "include",
|
|
||||||
method: "DELETE",
|
|
||||||
headers: {
|
|
||||||
"Content-type": "application/json",
|
|
||||||
"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) {
|
|
||||||
let config = useRuntimeConfig();
|
|
||||||
let params = "";
|
|
||||||
if (previous) params = "?previous=true";
|
|
||||||
|
|
||||||
return fetch(`${config.public.apiURL}/schedules/1${params}`, {
|
|
||||||
method: "GET",
|
|
||||||
headers: {"Content-type": "application/json"}
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(showings => {
|
|
||||||
|
|
||||||
if (previous) {
|
|
||||||
this.got_previous = true;
|
|
||||||
this.previous_showings = showings;
|
|
||||||
} else {
|
|
||||||
this.showings = showings
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(err => console.log(err));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped></style>
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|
|
@ -1,58 +1,69 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<form id="schedule-form" class="visually-hidden" method="post" onsubmit="return false">
|
<form
|
||||||
|
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><br/>
|
<label class="pb-1 text-start font-bold" for="schedule-date">Date</label
|
||||||
<input id="schedule-input" class="rounded-l p-1" name="schedule-date"
|
><br />
|
||||||
type="date"/>
|
<input
|
||||||
<button class="btn mt-5 sm:mt-0 p-1 rounded sm:rounded-none sm:rounded-r" type="button" @click="schedule">Schedule
|
id="schedule-input"
|
||||||
|
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>
|
<script lang="ts" setup>
|
||||||
export default {
|
const props = defineProps(["movie"]);
|
||||||
name: "ScheduleMovie",
|
const emits = defineEmits(["closeModal"]);
|
||||||
methods: {
|
|
||||||
schedule: function (e) {
|
|
||||||
const config = useRuntimeConfig();
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
let showtime_input = document.getElementById("schedule-input").value;
|
const schedule = function (e: Event) {
|
||||||
if (!showtime_input) {
|
const config = useRuntimeConfig();
|
||||||
alert("Please set showtime.");
|
e.preventDefault();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
let showtime = showtime_input + " " + "00:00:00";
|
|
||||||
|
|
||||||
fetch(`${config.public.apiURL}/schedules/movie`, {
|
let showtime_input = (
|
||||||
credentials: "include",
|
document.getElementById("schedule-input") as HTMLInputElement
|
||||||
method: "POST",
|
).value;
|
||||||
body: JSON.stringify({
|
|
||||||
"schedule_id": 1,
|
if (!showtime_input) {
|
||||||
"movie_id": this.movie.id,
|
alert("Please set showtime.");
|
||||||
"showtime": showtime,
|
return false;
|
||||||
"owner": 1,
|
}
|
||||||
"public": false
|
|
||||||
}),
|
const date = new Date(`${showtime_input}T00:00:00`);
|
||||||
headers: {
|
|
||||||
"Content-type": "application/json",
|
fetch(`${config.public.apiURL}/showings/`, {
|
||||||
"token": useCookie("token").value,
|
method: "POST",
|
||||||
}
|
body: JSON.stringify({
|
||||||
})
|
schedule: 1,
|
||||||
.then(response => response.json())
|
movie: props.movie.id,
|
||||||
.then(_json => {
|
showtime: date.toISOString(),
|
||||||
this.$parent.$parent.closeModal();
|
public: "False",
|
||||||
}
|
}),
|
||||||
)
|
headers: {
|
||||||
.catch(err => alert("Unable to schedule movie. Error:\n" + err))
|
"Content-type": "application/json",
|
||||||
}
|
Authorization: `Token ${useCookie("token").value}`,
|
||||||
},
|
},
|
||||||
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 scoped></style>
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|
|
@ -5,36 +5,38 @@
|
||||||
{{ 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 :src="movie.poster" alt="movie poster" class="mx-auto sm:mx-0 neon-border"/>
|
<img
|
||||||
|
: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 v-if="logged_in" :movie="movie" class="mt-5"/>
|
<ScheduleMovie
|
||||||
|
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>
|
<script lang="ts" setup>
|
||||||
import ScheduleMovie from "~/components/forms/ScheduleMovie.vue";
|
import ScheduleMovie from "~/components/forms/ScheduleMovie.vue";
|
||||||
|
|
||||||
export default {
|
const props = defineProps(["movie"]);
|
||||||
name: "ShowMovie",
|
const emits = defineEmits(["close-modal"]);
|
||||||
data: () => ({
|
const logged_in = ref(false);
|
||||||
logged_in: false,
|
|
||||||
}),
|
onMounted(() => {
|
||||||
components: {ScheduleMovie},
|
const token = useCookie("token").value;
|
||||||
props: ["movie"],
|
if (token) {
|
||||||
mounted() {
|
logged_in.value = true;
|
||||||
const token = useCookie("token").value;
|
|
||||||
if (token) {
|
|
||||||
this.logged_in = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped></style>
|
||||||
|
|
||||||
</style>
|
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
<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 v-if="modal_movie" :movie="modal_movie"></ShowMovie>
|
<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">
|
||||||
|
@ -66,8 +70,6 @@ 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);
|
||||||
|
@ -182,6 +184,11 @@ 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") {
|
||||||
|
|
|
@ -83,10 +83,10 @@ const months = [
|
||||||
];
|
];
|
||||||
|
|
||||||
const formatDate = function (date_string: string) {
|
const formatDate = function (date_string: string) {
|
||||||
let parsed_date = new Date(Date.parse(date_string));
|
let date = new Date(date_string);
|
||||||
let month = months[parsed_date.getMonth()];
|
let month = months[date.getMonth()];
|
||||||
|
|
||||||
return `${month} ${parsed_date.getDate()}, ${parsed_date.getFullYear()}`;
|
return `${month} ${date.getDate()}, ${date.getFullYear()}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getSchedule = async function (previous = false) {
|
const getSchedule = async function (previous = false) {
|
||||||
|
|
|
@ -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