view client/src/components/importschedule/Importschedule.vue @ 2299:41218dd386a9

import_schedule: display of cron and email again
author Thomas Junk <thomas.junk@intevation.de>
date Mon, 18 Feb 2019 12:07:03 +0100
parents 431f97fd873b
children 7b79d4966a87
line wrap: on
line source

<template>
  <div class="d-flex flex-row">
    <Spacer></Spacer>
    <div class="mt-3 w-100">
      <div class="card flex-grow-1 schedulecard shadow-xs">
        <h6
          class="mb-0 py-2 px-3 border-bottom d-flex text-info align-items-center"
        >
          <font-awesome-icon icon="clock" class="mr-2"></font-awesome-icon>
          <translate class="headline">Imports</translate>
        </h6>
        <div class="card-body schedulecardbody">
          <div class="card-body schedulecardbody">
            <div class="searchandfilter mb-3  w-50 d-flex flex-row">
              <div class="searchgroup input-group">
                <div class="input-group-prepend">
                  <span class="input-group-text" id="search">
                    <font-awesome-icon icon="search"></font-awesome-icon>
                  </span>
                </div>
                <input
                  v-model="searchQuery"
                  type="text"
                  class="form-control"
                  placeholder
                  aria-label="Search"
                  aria-describedby="search"
                />
              </div>
            </div>
            <table v-if="schedules.length" class="table">
              <thead>
                <tr>
                  <th><translate>Import</translate></th>
                  <th><translate>Type</translate></th>
                  <th><translate>Author</translate></th>
                  <th><translate>Schedule</translate></th>
                  <th><translate>Email</translate></th>
                  <th>&nbsp;</th>
                  <th>&nbsp;</th>
                  <th>&nbsp;</th>
                </tr>
              </thead>
              <tbody>
                <tr v-for="schedule in schedules" :key="schedule.id">
                  <td>{{ schedule.id }}</td>
                  <td>{{ schedule.kind.toUpperCase() }}</td>
                  <td>{{ schedule.user }}</td>
                  <td>{{ schedule.config.cron }}</td>
                  <td>
                    <font-awesome-icon
                      v-if="schedule.config['send-email']"
                      class="fa-fw mr-2"
                      fixed-width
                      icon="check"
                    ></font-awesome-icon>
                  </td>
                  <td>
                    <font-awesome-icon
                      :style="activeStyle"
                      @click="editSchedule(schedule.id)"
                      icon="pencil-alt"
                      fixed-width
                    ></font-awesome-icon>
                  </td>
                  <td>
                    <font-awesome-icon
                      :style="activeStyle"
                      @click="deleteSchedule(schedule.id)"
                      icon="trash"
                      fixed-width
                    ></font-awesome-icon>
                  </td>
                  <td>
                    <font-awesome-icon
                      @click="triggerManualImport(schedule.id)"
                      class="fa-fw mr-2"
                      fixed-width
                      icon="play"
                    ></font-awesome-icon>
                  </td>
                </tr>
              </tbody>
            </table>
            <div v-else class="mt-4 small text-center py-3">
              <translate>No scheduled imports</translate>
            </div>
            <div class="text-right">
              <button
                :disabled="importScheduleDetailVisible"
                @click="newImport"
                class="btn btn-info newbutton"
              >
                <translate>New Import</translate>
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <Importscheduledetail></Importscheduledetail>
  </div>
</template>

<script>
/* This is Free Software under GNU Affero General Public License v >= 3.0
 * without warranty, see README.md and license for details.
 *
 * SPDX-License-Identifier: AGPL-3.0-or-later
 * License-Filename: LICENSES/AGPL-3.0.txt
 *
 * Copyright (C) 2018 by via donau
 *   – Österreichische Wasserstraßen-Gesellschaft mbH
 * Software engineering by Intevation GmbH
 *
 * Author(s):
 * Thomas Junk <thomas.junk@intevation.de>
 */

import { mapState } from "vuex";
import { HTTP } from "@/lib/http";
import { displayInfo, displayError } from "@/lib/errors.js";

export default {
  name: "importschedule",
  components: {
    Importscheduledetail: () => import("./Importscheduledetail"),
    Spacer: () => import("@/components/Spacer")
  },
  data() {
    return {
      searchQuery: ""
    };
  },
  mounted() {
    this.getSchedules();
  },
  methods: {
    editSchedule(id) {
      this.$store
        .dispatch("importschedule/loadSchedule", id)
        .then(() => {
          this.$store.commit("importschedule/setImportScheduleDetailVisible");
        })
        .catch(error => {
          const { status, data } = error.response;
          displayError({
            title: this.$gettext("Backend Error"),
            message: `${status}: ${data.message || data}`
          });
        });
    },
    triggerManualImport(id) {
      HTTP.get("/imports/config/" + id + "/run", {
        headers: { "X-Gemma-Auth": localStorage.getItem("token") }
      })
        .then(response => {
          const { id } = response.data;
          displayInfo({
            title: this.$gettext("Imports"),
            message: this.$gettext("Manually triggered import: #") + id
          });
        })
        .catch(error => {
          const { status, data } = error.response;
          displayError({
            title: this.$gettext("Backend Error"),
            message: `${status}: ${data.message || data}`
          });
        });
    },
    getSchedules() {
      this.$store.dispatch("importschedule/loadSchedules").catch(error => {
        const { status, data } = error.response;
        displayError({
          title: this.$gettext("Backend Error"),
          message: `${status}: ${data.message || data}`
        });
      });
    },
    newImport() {
      this.$store.commit("importschedule/setImportScheduleDetailVisible");
    },
    deleteSchedule(index) {
      if (this.importScheduleDetailVisible) return;
      this.$store
        .dispatch("importschedule/deleteSchedule", index)
        .then(() => {
          this.getSchedules();
          displayInfo({
            title: this.$gettext("Imports"),
            message: this.$gettext("Deleted import: #") + index
          });
        })
        .catch(error => {
          const { status, data } = error.response;
          displayError({
            title: this.$gettext("Backend Error"),
            message: `${status}: ${data.message || data}`
          });
        });
    }
  },
  computed: {
    ...mapState("application", ["showSidebar"]),
    ...mapState("importschedule", ["schedules", "importScheduleDetailVisible"]),
    activeStyle() {
      const color = this.importScheduleDetailVisible ? "#aeaeae" : "#000000";
      return { color: color };
    },
    spacerStyle() {
      return [
        "spacer ml-3",
        {
          "spacer-expanded": this.showSidebar,
          "spacer-collapsed": !this.showSidebar
        }
      ];
    }
  }
};
</script>

<style lang="scss" scoped>
th {
  border-top: 0px;
}

.card-body {
  padding-bottom: $small-offset;
}

.schedulecard {
  margin-right: $offset;
  min-height: 20rem;
}

.schedulecard-body {
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}
</style>