diff options
| author | Santo Cariotti <santo@dcariotti.me> | 2022-09-26 18:21:28 +0200 | 
|---|---|---|
| committer | Santo Cariotti <santo@dcariotti.me> | 2022-09-26 18:21:28 +0200 | 
| commit | 53a32a36666d58b510d53ce2d78e7e2156c319aa (patch) | |
| tree | 021795cd4c9b185c2cb4a4dc517b44c8c7c1d0a2 | |
| parent | a70c5c0a7164486568ffaec1e67a6e87de1bba93 (diff) | |
See reports (warnings on backend)
| -rw-r--r-- | components/ModelReportsList.vue | 39 | ||||
| -rw-r--r-- | pages/models/_id/index.vue | 3 | ||||
| -rw-r--r-- | store/warnings.js | 27 | 
3 files changed, 69 insertions, 0 deletions
diff --git a/components/ModelReportsList.vue b/components/ModelReportsList.vue new file mode 100644 index 0000000..a46e6d1 --- /dev/null +++ b/components/ModelReportsList.vue @@ -0,0 +1,39 @@ +<template lang="pug"> +  .shadow-sm.rounded-lg.bg-white.p-4.w-full.mb-5(v-if="warnings.length") +    h2.text-xl.font-bold(v-if="me && me.is_staff") Reports  +    h2.text-xl.font-bold(v-else) My reports + +    ul.divide-y.divide-gray-200.rounded-md.border.border-gray-200.mt-3(role="list" v-if="me && !me.is_staff") +      li.py-3.pl-3.pr-4.text-sm(v-for="warning in warnings" :key="warning.id") +        h3.flex.leading-6.mb-2.float-right +          <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="mr-2 w-6 h-6"> +            <path stroke-linecap="round" stroke-linejoin="round" d="M12 6v6h4.5m4.5 0a9 9 0 11-18 0 9 9 0 0118 0z" /> +          </svg> +          | {{ warning.created|moment("DD/MM/YYYY HH:mm") }} +        p {{ warning.note }} +    ul.divide-y.divide-gray-200.rounded-md.border.border-gray-200.mt-3(role="list" v-else-if="me && me.is_staff") +      li.py-3.pl-3.pr-4.text-sm(v-for="warning in warnings" :key="warning.id") +        h3.flex.leading-6.mb-2.float-right +          <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="mr-2 w-6 h-6"> +            <path stroke-linecap="round" stroke-linejoin="round" d="M12 6v6h4.5m4.5 0a9 9 0 11-18 0 9 9 0 0118 0z" /> +          </svg> +          | {{ warning.created|moment("DD/MM/YYYY HH:mm") }} +        p {{ warning.note }} + +</template> + +<script> +import { mapGetters } from "vuex"; + +export default { +  name: "ModelReportsList", +  props: ["model"], +  computed: { +    ...mapGetters("auth", ["me"]), +    ...mapGetters("warnings", ["warnings"]), +  }, +  mounted() { +    this.$store.dispatch("warnings/filterWarnings", { model_id: this.model }); +  }, +}; +</script> diff --git a/pages/models/_id/index.vue b/pages/models/_id/index.vue index 69510cc..ee51035 100644 --- a/pages/models/_id/index.vue +++ b/pages/models/_id/index.vue @@ -110,6 +110,7 @@            <path stroke-linecap="round" stroke-linejoin="round" d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" />          </svg>          | Delete +    model-reports-list(:model="model.id" v-if="me && model.id")      .images.shadow-sm.rounded-lg.bg-white.p-4.w-full(v-if="model.uploads")        .block.gap-4.h-full(class="md:flex")          .w-full(class="md:w-4/5") @@ -186,6 +187,7 @@  <script>  import FilePreview from "@/components/FilePreview.vue"; +import ModelReportsList from "@/components/ModelReportsList.vue";  import UserAvatar from "@/components/UserAvatar.vue";  import { mapGetters } from "vuex"; @@ -213,6 +215,7 @@ export default {    components: {      "user-avatar": UserAvatar,      "file-preview": FilePreview, +    "model-reports-list": ModelReportsList,    },    computed: {      ...mapGetters(["isLoading"]), diff --git a/store/warnings.js b/store/warnings.js index 07767ae..4c94459 100644 --- a/store/warnings.js +++ b/store/warnings.js @@ -15,6 +15,33 @@ export const mutations = {  };  export const actions = { +  // Filter warnings +  async filterWarnings({ commit, rootGetters }, payload) { +    commit("loadingStatus", true, { root: true }); +    let res = { status: 0, data: null }; +    let api = this.$config.api; + +    await fetch(`${api}/v1/warnings/filter`, { +      method: "POST", +      headers: { +        "Content-Type": "application/json", +        Authorization: `Bearer ${rootGetters["auth/accessToken"]}`, +      }, +      body: JSON.stringify(payload), +    }) +      .then(async (response) => { +        res.status = response.status; +        const data = await response.json(); +        if (res.status == 200) { +          commit("saveWarnings", data.results); +        } +      }) +      .catch((e) => { +        res.status = e.status; +      }); + +    commit("loadingStatus", false, { root: true }); +  },    // Create a new warning    async createWarning({ commit, rootGetters }, payload) {      commit("loadingStatus", true, { root: true });  |