From 263ddddf0b565c5e9a960dea7b8038014148cf93 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Mon, 26 Oct 2020 13:01:22 +0100 Subject: [PATCH] Start using Vuex --- htdocs/package.json | 4 +- htdocs/src/api/api.js | 41 +++++++++++++++++++ htdocs/src/api/domains.js | 38 ++++++++++++++++++ htdocs/src/main.js | 4 +- htdocs/src/store/index.js | 46 +++++++++++++++++++++ htdocs/src/store/module/domains.js | 64 ++++++++++++++++++++++++++++++ htdocs/yarn.lock | 5 +++ 7 files changed, 200 insertions(+), 2 deletions(-) create mode 100644 htdocs/src/api/api.js create mode 100644 htdocs/src/api/domains.js create mode 100644 htdocs/src/store/index.js create mode 100644 htdocs/src/store/module/domains.js diff --git a/htdocs/package.json b/htdocs/package.json index 9bab1d5..94ba990 100644 --- a/htdocs/package.json +++ b/htdocs/package.json @@ -14,12 +14,14 @@ "bootstrap-vue": "^2.18.1", "vue": "^2.6.11", "vue-i18n": "^8.22.1", - "vue-router": "^3.4.7" + "vue-router": "^3.4.7", + "vuex": "^3.5.1" }, "devDependencies": { "@intlify/vue-i18n-loader": "^1.0.0", "@vue/cli-plugin-eslint": "^4.5.8", "@vue/cli-plugin-router": "^4.5.8", + "@vue/cli-plugin-vuex": "^4.5.8", "@vue/cli-service": "^4.5.8", "@vue/eslint-config-standard": "^5.1.2", "babel-eslint": "^10.0.1", diff --git a/htdocs/src/api/api.js b/htdocs/src/api/api.js new file mode 100644 index 0000000..c88bbe4 --- /dev/null +++ b/htdocs/src/api/api.js @@ -0,0 +1,41 @@ +// Copyright or © or Copr. happyDNS (2020) +// +// contact@happydns.org +// +// This software is a computer program whose purpose is to provide a modern +// interface to interact with DNS systems. +// +// This software is governed by the CeCILL license under French law and abiding +// by the rules of distribution of free software. You can use, modify and/or +// redistribute the software under the terms of the CeCILL license as +// circulated by CEA, CNRS and INRIA at the following URL +// "http://www.cecill.info". +// +// As a counterpart to the access to the source code and rights to copy, modify +// and redistribute granted by the license, users are provided only with a +// limited warranty and the software's author, the holder of the economic +// rights, and the successive licensors have only limited liability. +// +// In this respect, the user's attention is drawn to the risks associated with +// loading, using, modifying and/or developing or reproducing the software by +// the user in light of its specific status of free software, that may mean +// that it is complicated to manipulate, and that also therefore means that it +// is reserved for developers and experienced professionals having in-depth +// computer knowledge. Users are therefore encouraged to load and test the +// software's suitability as regards their requirements in conditions enabling +// the security of their systems and/or data to be ensured and, more generally, +// to use and operate it in the same conditions as regards security. +// +// The fact that you are presently reading this means that you have had +// knowledge of the CeCILL license and that you accept its terms. + +import axios from 'axios' + +export default () => { + return axios.create({ + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json' + } + }) +} diff --git a/htdocs/src/api/domains.js b/htdocs/src/api/domains.js new file mode 100644 index 0000000..cca6393 --- /dev/null +++ b/htdocs/src/api/domains.js @@ -0,0 +1,38 @@ +// Copyright or © or Copr. happyDNS (2020) +// +// contact@happydns.org +// +// This software is a computer program whose purpose is to provide a modern +// interface to interact with DNS systems. +// +// This software is governed by the CeCILL license under French law and abiding +// by the rules of distribution of free software. You can use, modify and/or +// redistribute the software under the terms of the CeCILL license as +// circulated by CEA, CNRS and INRIA at the following URL +// "http://www.cecill.info". +// +// As a counterpart to the access to the source code and rights to copy, modify +// and redistribute granted by the license, users are provided only with a +// limited warranty and the software's author, the holder of the economic +// rights, and the successive licensors have only limited liability. +// +// In this respect, the user's attention is drawn to the risks associated with +// loading, using, modifying and/or developing or reproducing the software by +// the user in light of its specific status of free software, that may mean +// that it is complicated to manipulate, and that also therefore means that it +// is reserved for developers and experienced professionals having in-depth +// computer knowledge. Users are therefore encouraged to load and test the +// software's suitability as regards their requirements in conditions enabling +// the security of their systems and/or data to be ensured and, more generally, +// to use and operate it in the same conditions as regards security. +// +// The fact that you are presently reading this means that you have had +// knowledge of the CeCILL license and that you accept its terms. + +import Api from '@/api/api' + +export default { + listDomains () { + return Api().get('/api/domains') + } +} diff --git a/htdocs/src/main.js b/htdocs/src/main.js index 067a8d9..92bae0e 100644 --- a/htdocs/src/main.js +++ b/htdocs/src/main.js @@ -88,6 +88,7 @@ import './registerServiceWorker.js' import './app.scss' import i18n from './i18n' +import store from './store' Vue.use(AlertPlugin) Vue.use(BadgePlugin) @@ -143,9 +144,10 @@ Vue.component('HLogo', HLogo) Vue.config.productionTip = process.env.NODE_ENV === 'production' new Vue({ + store, router, i18n, - render: function (h) { return h(App) } + render: h => h(App) }).$mount('#app') var tagsToReplace = { diff --git a/htdocs/src/store/index.js b/htdocs/src/store/index.js new file mode 100644 index 0000000..fa83c14 --- /dev/null +++ b/htdocs/src/store/index.js @@ -0,0 +1,46 @@ +// Copyright or © or Copr. happyDNS (2020) +// +// contact@happydns.org +// +// This software is a computer program whose purpose is to provide a modern +// interface to interact with DNS systems. +// +// This software is governed by the CeCILL license under French law and abiding +// by the rules of distribution of free software. You can use, modify and/or +// redistribute the software under the terms of the CeCILL license as +// circulated by CEA, CNRS and INRIA at the following URL +// "http://www.cecill.info". +// +// As a counterpart to the access to the source code and rights to copy, modify +// and redistribute granted by the license, users are provided only with a +// limited warranty and the software's author, the holder of the economic +// rights, and the successive licensors have only limited liability. +// +// In this respect, the user's attention is drawn to the risks associated with +// loading, using, modifying and/or developing or reproducing the software by +// the user in light of its specific status of free software, that may mean +// that it is complicated to manipulate, and that also therefore means that it +// is reserved for developers and experienced professionals having in-depth +// computer knowledge. Users are therefore encouraged to load and test the +// software's suitability as regards their requirements in conditions enabling +// the security of their systems and/or data to be ensured and, more generally, +// to use and operate it in the same conditions as regards security. +// +// The fact that you are presently reading this means that you have had +// knowledge of the CeCILL license and that you accept its terms. + +import Vue from 'vue' +import Vuex from 'vuex' + +import domains from './module/domains' + +Vue.use(Vuex) + +const debug = process.env.NODE_ENV !== 'production' + +export default new Vuex.Store({ + modules: { + domains + }, + strict: debug +}) diff --git a/htdocs/src/store/module/domains.js b/htdocs/src/store/module/domains.js new file mode 100644 index 0000000..eae4b51 --- /dev/null +++ b/htdocs/src/store/module/domains.js @@ -0,0 +1,64 @@ +// Copyright or © or Copr. happyDNS (2020) +// +// contact@happydns.org +// +// This software is a computer program whose purpose is to provide a modern +// interface to interact with DNS systems. +// +// This software is governed by the CeCILL license under French law and abiding +// by the rules of distribution of free software. You can use, modify and/or +// redistribute the software under the terms of the CeCILL license as +// circulated by CEA, CNRS and INRIA at the following URL +// "http://www.cecill.info". +// +// As a counterpart to the access to the source code and rights to copy, modify +// and redistribute granted by the license, users are provided only with a +// limited warranty and the software's author, the holder of the economic +// rights, and the successive licensors have only limited liability. +// +// In this respect, the user's attention is drawn to the risks associated with +// loading, using, modifying and/or developing or reproducing the software by +// the user in light of its specific status of free software, that may mean +// that it is complicated to manipulate, and that also therefore means that it +// is reserved for developers and experienced professionals having in-depth +// computer knowledge. Users are therefore encouraged to load and test the +// software's suitability as regards their requirements in conditions enabling +// the security of their systems and/or data to be ensured and, more generally, +// to use and operate it in the same conditions as regards security. +// +// The fact that you are presently reading this means that you have had +// knowledge of the CeCILL license and that you accept its terms. + +import Vue from 'vue' +import DomainsApi from '@/api/domains' +import { domainCompare } from '@/utils/domainCompare' + +export default { + namespaced: true, + + state: { + all: null + }, + + getters: { + sortedDomains: state => state.all + }, + + actions: { + getAllMyDomains ({ commit }) { + DomainsApi.listDomains() + .then( + response => { + commit('setDomains', response.data) + }) + // TODO: handle errors here + } + }, + + mutations: { + setDomains (state, domains) { + domains.sort(function (a, b) { return domainCompare(a.domain, b.domain) }) + Vue.set(state, 'all', domains) + } + } +} diff --git a/htdocs/yarn.lock b/htdocs/yarn.lock index c4cbc61..3301d79 100644 --- a/htdocs/yarn.lock +++ b/htdocs/yarn.lock @@ -9307,6 +9307,11 @@ vue@^2.6.11: resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.12.tgz#f5ebd4fa6bd2869403e29a896aed4904456c9123" integrity sha512-uhmLFETqPPNyuLLbsKz6ioJ4q7AZHzD8ZVFNATNyICSZouqP2Sz0rotWQC8UNBF6VGSCs5abnKJoStA6JbCbfg== +vuex@^3.5.1: + version "3.5.1" + resolved "https://registry.yarnpkg.com/vuex/-/vuex-3.5.1.tgz#f1b8dcea649bc25254cf4f4358081dbf5da18b3d" + integrity sha512-w7oJzmHQs0FM9LXodfskhw9wgKBiaB+totOdb8sNzbTB2KDCEEwEs29NzBZFh/lmEK1t5tDmM1vtsO7ubG1DFw== + watchpack-chokidar2@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/watchpack-chokidar2/-/watchpack-chokidar2-2.0.0.tgz#9948a1866cbbd6cb824dea13a7ed691f6c8ddff0"