view client/src/store/imports.js @ 1310:d675e6439aa5

staging view: prepare retrieving list of pending imports for staging
author Thomas Junk <thomas.junk@intevation.de>
date Fri, 23 Nov 2018 13:20:10 +0100
parents 99c039e86624
children d5eda9f79610
line wrap: on
line source

/*
 * 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 { HTTP } from "../lib/http";

// initial state
const init = () => {
  return {
    imports: [],
    staging: []
  };
};

export default {
  init,
  namespaced: true,
  state: init(),
  mutations: {
    setImports: (state, imports) => {
      state.imports = imports;
    },
    setStaging: (state, staging) => {
      state.staging = staging;
    }
  },
  actions: {
    getImports({ commit }) {
      return new Promise((resolve, reject) => {
        HTTP.get("/imports", {
          headers: { "X-Gemma-Auth": localStorage.getItem("token") }
        })
          .then(response => {
            commit("setImports", response.data.imports);
            resolve(response);
          })
          .catch(error => {
            reject(error);
          });
      });
    },
    getStaging({ commit }) {
      return new Promise((resolve, reject) => {
        HTTP.get("/imports?states=pending", {
          headers: { "X-Gemma-Auth": localStorage.getItem("token") }
        })
          .then(response => {
            commit("setStaging", response.data.imports);
            resolve(response);
          })
          .catch(error => {
            reject(error);
          });
      });
    }
  }
};