123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <template>
- <modal title="View API Request">
- <template #body>
- <div v-if="!loaded" class="vertical-padding">
- <p>Request hasn't loaded yet</p>
- </div>
- <div v-else class="vertical-padding">
- <p><b>ID:</b> {{ request._id }}</p>
- <p><b>URL:</b> {{ request.url }}</p>
- <div>
- <b>Params:</b>
- <ul v-if="request.params">
- <li
- v-for="[paramKey, paramValue] in Object.entries(
- request.params
- )"
- :key="paramKey"
- >
- <b>{{ paramKey }}</b
- >: {{ paramValue }}
- </li>
- </ul>
- <span v-else>None/Not found</span>
- </div>
- <div>
- <b>Results:</b>
- <vue-json-pretty
- :data="request.results"
- :show-length="true"
- ></vue-json-pretty>
- </div>
- <p><b>Date:</b> {{ request.date }}</p>
- <p><b>Quota cost:</b> {{ request.quotaCost }}</p>
- </div>
- </template>
- <template #footer>
- <quick-confirm v-if="removeAction" @confirm="remove()">
- <a class="button is-danger"> Remove API request</a>
- </quick-confirm>
- </template>
- </modal>
- </template>
- <script>
- import { mapActions, mapGetters } from "vuex";
- import VueJsonPretty from "vue-json-pretty";
- import "vue-json-pretty/lib/styles.css";
- import Toast from "toasters";
- import ws from "@/ws";
- import { mapModalState, mapModalActions } from "@/vuex_helpers";
- export default {
- components: {
- VueJsonPretty
- },
- props: {
- modalUuid: { type: String, default: "" }
- },
- data() {
- return {
- loaded: false
- };
- },
- computed: {
- ...mapModalState("modals/viewApiRequest/MODAL_UUID", {
- requestId: state => state.requestId,
- request: state => state.request,
- removeAction: state => state.removeAction
- }),
- ...mapGetters({
- socket: "websockets/getSocket"
- })
- },
- mounted() {
- ws.onConnect(this.init);
- },
- beforeUnmount() {
- this.socket.dispatch(
- "apis.leaveRoom",
- `view-api-request.${this.requestId}`,
- () => {}
- );
- // Delete the VueX module that was created for this modal, after all other cleanup tasks are performed
- this.$store.unregisterModule([
- "modals",
- "viewApiRequest",
- this.modalUuid
- ]);
- },
- methods: {
- init() {
- this.loaded = false;
- this.socket.dispatch(
- "youtube.getApiRequest",
- this.requestId,
- res => {
- if (res.status === "success") {
- const { apiRequest } = res.data;
- this.viewApiRequest(apiRequest);
- this.loaded = true;
- this.socket.dispatch(
- "apis.joinRoom",
- `view-api-request.${this.requestId}`
- );
- this.socket.on(
- "event:youtubeApiRequest.removed",
- () => {
- new Toast("This API request was removed.");
- this.closeCurrentModal();
- },
- { modalUuid: this.modalUuid }
- );
- } else {
- new Toast("API request with that ID not found");
- this.closeCurrentModal();
- }
- }
- );
- },
- remove() {
- if (this.removeAction)
- this.socket.dispatch(this.removeAction, this.requestId, res => {
- if (res.status === "success") {
- new Toast("API request successfully removed.");
- this.closeCurrentModal();
- } else {
- new Toast("API request with that ID not found.");
- }
- });
- },
- ...mapModalActions("modals/viewApiRequest/MODAL_UUID", [
- "viewApiRequest"
- ]),
- ...mapActions("modalVisibility", ["closeCurrentModal"])
- }
- };
- </script>
- <style lang="less" scoped>
- ul {
- list-style-type: disc;
- padding-left: 20px;
- }
- </style>
|