Mercurial > gemma
view client/src/components/usermanagement/Usermanagement.vue @ 5521:3cfbc5769e8b
Make invalid output of ISRSrange_area() less likely
Since ST_Transform() might produce an invalid polygon, add an extra
ST_MakeValid().
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 21 Oct 2021 20:20:30 +0200 |
parents | b7792e8d5c62 |
children | 84d01a536bec |
line wrap: on
line source
<template> <div class="main d-flex flex-row" style="position: relative;"> <Spacer /> <div class="d-flex content py-2"> <div :class="userlistStyle"> <div class="card shadow-xs"> <UIBoxHeader icon="users-cog" :title="usersLabel" :checkBox="checkboxObject" /> <UITableHeader :columns="[ { id: 'role', title: `${roleForColumLabel}`, class: 'col-1' }, { id: 'user', title: `${usernameLabel}`, class: 'col-4' }, { id: 'country', title: `${countryLabel}`, class: 'col-1' }, { id: 'email', title: `${emailLabel}`, class: 'col-3' }, { id: 'reports', title: `${reportsLabel}`, class: 'col-1' } ]" /> <UITableBody :data=" usersForTable | sortTable(sortColumn, sortDirection, page, pageSize) " :isActive="item => item === currentUser" maxHeight="47rem" > <template v-slot:row="{ item: user }"> <div class="table-cell center col-1" :style="{ opacity: user.active ? '1' : '0.7' }" > <font-awesome-icon v-tooltip="roleLabel(user.role)" :icon="roleIcon(user.role)" class="fa-lg" /> </div> <div class="table-cell col-4" :style="{ opacity: user.active ? '1' : '0.7' }" > {{ user.user }} </div> <div :style="{ opacity: user.active ? '1' : '0.7' }" class="table-cell center col-1" > {{ user.country }} </div> <div class="table-cell col-3" :style="{ opacity: user.active ? '1' : '0.7' }" > {{ user.email }} </div> <div class="table-cell center col-1"> <toggle-button :value="user.reports" v-model="user.reports" class="pt-1" :sync="true" :speed="100" @change="toggleReport(user)" v-tooltip="receivesReportLabel" :width="40" :disabled="!user.active" :height="20" /> </div> <div class="table-cell col text-right justify-content-end"> <button @click="selectUser(user.user)" class="btn btn-xs btn-dark mr-1" v-tooltip="getEditLabel(user.active)" > <font-awesome-icon v-if="user.active" icon="pencil-alt" fixed-width /> <font-awesome-icon v-else icon="undo" fixed-width /> </button> <button @click="sendTestMail(user.user)" class="btn btn-xs btn-dark mr-1" v-tooltip="sendMailLabel" v-if="user.email" :disabled="!user.active" :style="{ cursor: user.active ? 'pointer' : 'default' }" > <font-awesome-icon icon="paper-plane" fixed-width /> </button> <button @click="deleteUser(user.user)" class="btn btn-xs btn-dark" v-tooltip="deleteUserLabel" :style="{ cursor: user.active ? 'pointer' : 'default' }" :disabled="!user.active" > <font-awesome-icon icon="trash" fixed-width /> </button> </div> </template> </UITableBody> <div class="p-3 border-top d-flex justify-content-between"> <div></div> <div> <button @click="prevPage" v-if="this.page !== 1" class="mr-2 btn btn-sm btn-light align-self-center" > <font-awesome-icon icon="angle-left" /> </button> {{ this.page }} / {{ this.pages }} <button @click="nextPage" v-if="this.page !== this.pages" class="ml-2 btn btn-sm btn-light align-self-center" > <font-awesome-icon icon="angle-right" /> </button> </div> <button @click="addUser" class="btn btn-info addbutton shadow-sm"> <translate>Add User</translate> </button> </div> </div> </div> <Userdetail :reportToggled="reportToggled" v-if="isUserDetailsVisible" /> </div> </div> </template> <style lang="sass" scoped> .content width: 100% .userdetails width: 50% .main height: 100% .icon font-size: large .userlist min-width: 520px height: 100% .userlistsmall width: 100% .userlistextended width: 100% </style> <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 store from "@/store"; import { mapGetters, mapState } from "vuex"; import { displayError, displayInfo } from "@/lib/errors"; import { HTTP } from "@/lib/http"; import { sortTable } from "@/lib/mixins"; export default { name: "userview", mixins: [sortTable], data() { return { sortColumn: "user", // overriding the sortTable mixin's empty default value reportToggled: false, usersForTable: [], areSomeUsersHidden: false }; }, components: { Userdetail: () => import("./Userdetail"), Spacer: () => import("@/components/Spacer") }, computed: { ...mapGetters("usermanagement", ["isUserDetailsVisible", "users"]), ...mapState("application", ["showSidebar"]), ...mapState("usermanagement", ["currentUser"]), usersLabel() { return this.$gettext("Users"); }, reportsLabel() { return this.$gettext("DQL Report"); }, receivesReportLabel() { return this.$gettext("User receives Data Quality Report"); }, sendMailLabel() { return this.$gettext("Send testmail"); }, deleteUserLabel() { return this.$gettext("Delete user"); }, roleForColumLabel() { return this.$gettext("Role"); }, usernameLabel() { return this.$gettext("Username"); }, countryLabel() { return this.$gettext("Country"); }, emailLabel() { return this.$gettext("Email"); }, pages() { return Math.ceil(this.usersForTable.length / this.pageSize); }, tableStyle() { return { table: true, "table-hover": true, "table-sm": this.isUserDetailsVisible, fadeIn: true, animated: true }; }, userlistStyle() { return [ "userlist mr-2", { userlistsmall: this.isUserDetailsVisible, userlistextended: !this.isUserDetailsVisible } ]; }, checkboxObject() { // Hide checkbox in case there are no deactivated users if (this.users.some(u => !u.active)) { return { value: this.areSomeUsersHidden, label: "Hide inactive users", callback: () => { this.changeDisplayingState(); } }; } else { return undefined; } } }, watch: { users() { this.filterUsers(); } }, mounted() { this.usersForTable = this.users; }, methods: { getEditLabel(active) { if (active) return this.$gettext("Edit user"); return this.$gettext("Reactivate user"); }, changeDisplayingState() { this.areSomeUsersHidden = !this.areSomeUsersHidden; this.filterUsers(); }, filterUsers() { if (this.areSomeUsersHidden) { this.usersForTable = this.users.filter(u => u.active); } else { this.usersForTable = this.users; } }, toggleReport(user) { HTTP.patch( `/users/${user.user}`, { reports: user.reports }, { headers: { "X-Gemma-Auth": localStorage.getItem("token"), "Content-type": "application/json; charset=UTF-8" } } ) .then(() => { if (this.currentUser && this.currentUser.user === user.user) { this.reportToggled = !this.reportToggled; } }) .catch(error => { let message = "Backend not reachable"; if (error.response) { const { status, data } = error.response; message = `${status}: ${data.message || data}`; } displayError({ title: this.$gettext("Backend Error"), message: message }); user.reports = !user.reports; }); }, sendTestMail(user) { HTTP.get("/testmail/" + encodeURIComponent(user), { headers: { "X-Gemma-Auth": localStorage.getItem("token"), "Content-type": "text/xml; charset=UTF-8" } }) .then(() => { displayInfo({ message: this.$gettext("Testmail sent") }); }) .catch(error => { this.loginFailed = true; let message = "Backend not reachable"; if (error.response) { const { status, data } = error.response; message = `${status}: ${data.message || data}`; } displayError({ title: this.$gettext("Backend Error"), message: message }); }); }, nextPage() { if (this.page < this.pages) { this.page += 1; } }, prevPage() { if (this.page > 0) { this.page -= 1; } }, deleteUser(name) { this.$store.commit("application/popup", { icon: "trash", title: this.$gettext("Delete User"), content: this.$gettext( "Do you really want to delete the following user account:" ) + `<br> <b>${name}</b>`, confirm: { label: this.$gettext("Delete"), icon: "trash", callback: () => { this.$store .dispatch("usermanagement/deleteUser", { name }) .then(response => { displayInfo({ message: name + // Exclude whitespaces from the string passed to "gettext" function " " + this.$gettext("user account") + " " + response.data.action + " " + this.$gettext("successfully") }); this.$store .dispatch("usermanagement/loadUsers") .catch(error => { let message = "Backend not reachable"; if (error.response) { const { status, data } = error.response; message = `${status}: ${data.message || data}`; } displayError({ title: this.$gettext("Backend Error"), message: message }); }); }) .catch(error => { let message = "Backend not reachable"; if (error.response) { const { status, data } = error.response; message = `${status}: ${data.message || data}`; } displayError({ title: this.$gettext("Backend Error"), message: message }); }); } }, cancel: { label: this.$gettext("Cancel"), icon: "times" } }); }, addUser() { this.$store.commit("usermanagement/clearCurrentUser"); this.$store.commit("usermanagement/setUserDetailsVisible"); }, selectUser(name) { const user = this.$store.getters["usermanagement/getUserByName"](name); this.$store.commit("usermanagement/setCurrentUser", user); }, roleIcon(role) { if (role === "sys_admin") return "star"; if (role === "waterway_admin") return ["fab", "adn"]; return "user"; }, roleLabel(role) { const labels = { sys_admin: this.$gettext("System-Administrator"), waterway_admin: this.$gettext("Waterway Admin"), waterway_user: this.$gettext("Waterway User") }; return labels[role]; } }, beforeRouteEnter(to, from, next) { store .dispatch("usermanagement/loadUsers") .then(next) .catch(error => { let message = "Backend not reachable"; if (error.response) { const { status, data } = error.response; message = `${status}: ${data.message || data}`; } displayError({ title: this.$gettext("Backend Error"), message: message }); }); }, beforeRouteLeave(to, from, next) { store.commit("usermanagement/clearCurrentUser"); store.commit("usermanagement/setUserDetailsInvisible"); next(); } }; </script>