github.com/benoitkugler/goacve@v0.0.0-20201217100549-151ce6e55dc8/server/frontend/bv/src/pages/admin/passwords/App.vue (about)

     1  <template>
     2    <base-app title="Coffre-fort des mots de passe ACVE">
     3      <success v-if="output" :output="output"></success>
     4      <error v-if="output" :output="output"></error>
     5  
     6      <b-modal v-model="showEditPassword" hide-header hide-footer>
     7        <form-password
     8          :password="currentPassword"
     9          @done="onDoneEdit"
    10        ></form-password>
    11      </b-modal>
    12  
    13      <b-container class="my-2 mb-3 mx-auto">
    14        <b-card>
    15          <b-card-title>
    16            <b-row no-gutters class="w-100">
    17              <b-col>
    18                Mots de passe
    19              </b-col>
    20              <b-col class="text-right">
    21                <b-button
    22                  variant="success"
    23                  @click="startCreatePassword"
    24                  v-b-tooltip.top
    25                  title="Ajouter un mot de passe..."
    26                >
    27                  <b-icon-plus></b-icon-plus>
    28                  Ajouter
    29                </b-button>
    30              </b-col>
    31            </b-row>
    32          </b-card-title>
    33          <b-overlay :show="loading" class="overflow-auto" style="height: 60vh">
    34            <b-table-lite :items="passwords" :fields="fields" small striped>
    35              <template v-slot:cell(provenance)="{ item }">
    36                <a :href="asP(item).provenance" target="_blank">{{
    37                  asP(item).provenance
    38                }}</a>
    39              </template>
    40  
    41              <template v-slot:cell(buttons)="{ item }">
    42                <b-button
    43                  @click="startUpdatePassword(item)"
    44                  size="sm"
    45                  variant="secondary"
    46                  v-b-tooltip.hover.top="'Modifier...'"
    47                >
    48                  <b-icon-pencil></b-icon-pencil>
    49                </b-button>
    50                <b-button
    51                  class="ml-1"
    52                  @click="startDeletePassword(item)"
    53                  size="sm"
    54                  variant="danger"
    55                  v-b-tooltip.right="'Supprimer...'"
    56                >
    57                  <b-icon-trash></b-icon-trash>
    58                </b-button>
    59              </template>
    60            </b-table-lite>
    61          </b-overlay>
    62        </b-card>
    63      </b-container>
    64    </base-app>
    65  </template>
    66  
    67  <script lang="ts">
    68  import Vue from "vue";
    69  import Component from "vue-class-component";
    70  import BaseApp from "@/BaseApp.vue";
    71  import Success from "@/shared/notifications/Success.vue";
    72  import Error from "@/shared/notifications/Error.vue";
    73  
    74  import { C } from "./controller";
    75  import { PublicPassword } from "./types";
    76  import FormPassword from "./FormPassword.vue";
    77  
    78  const styleAlignMiddle = { style: "vertical-align:middle;" };
    79  
    80  @Component({
    81    components: { BaseApp, Success, Error, FormPassword }
    82  })
    83  export default class App extends Vue {
    84    output = C.notifications;
    85    loading = false;
    86  
    87    fields: {
    88      key: "buttons" | keyof PublicPassword;
    89      label: string;
    90      class?: string;
    91      tdAttr?: Object;
    92      thStyle?: Object;
    93    }[] = [
    94      { key: "buttons", label: "", thStyle: { width: "100px" } },
    95      {
    96        key: "provenance",
    97        label: "Site",
    98        class: "text-center",
    99        tdAttr: styleAlignMiddle
   100      },
   101      {
   102        key: "loggin",
   103        label: "Identifiant",
   104        class: "text-center",
   105        tdAttr: styleAlignMiddle
   106      },
   107      {
   108        key: "password",
   109        label: "Mot de passe",
   110        class: "text-center",
   111        tdAttr: styleAlignMiddle
   112      },
   113      { key: "description", label: "Description", tdAttr: styleAlignMiddle }
   114    ];
   115  
   116    showEditPassword = false;
   117    currentPassword: PublicPassword | null = null;
   118  
   119    asP = (item: PublicPassword) => item; // template checking
   120    C = C; // needed for reactivity
   121    created() {
   122      this.refresh();
   123    }
   124  
   125    async refresh() {
   126      this.loading = true;
   127      await C.getPasswords();
   128      this.loading = false;
   129    }
   130  
   131    get passwords() {
   132      return Object.values(C.passwords).sort((a, b) =>
   133        a.provenance.localeCompare(b.provenance)
   134      );
   135    }
   136  
   137    startCreatePassword() {
   138      this.currentPassword = null;
   139      this.showEditPassword = true;
   140    }
   141  
   142    startUpdatePassword(item: PublicPassword) {
   143      this.currentPassword = item;
   144      this.showEditPassword = true;
   145    }
   146  
   147    startDeletePassword(item: PublicPassword) {
   148      this.$bvModal
   149        .msgBoxConfirm(
   150          `Confirmer la suppression du mot de passe pour ${item.provenance}`,
   151          {
   152            title: "Suppression",
   153            okVariant: "danger",
   154            cancelTitle: "Retour"
   155          }
   156        )
   157        .then(value => {
   158          if (value) {
   159            this.deletePassword(item);
   160          }
   161        });
   162    }
   163  
   164    onDoneEdit(isCreateMode: boolean, item: PublicPassword) {
   165      this.showEditPassword = false;
   166      if (isCreateMode) {
   167        this.createPassword(item);
   168      } else {
   169        this.updatePassword(item);
   170      }
   171    }
   172  
   173    async createPassword(item: PublicPassword) {
   174      this.loading = true;
   175      await C.createPassword(item);
   176      this.loading = false;
   177    }
   178  
   179    async updatePassword(item: PublicPassword) {
   180      this.loading = true;
   181      await C.updatePassword(item);
   182      this.loading = false;
   183    }
   184  
   185    async deletePassword(item: PublicPassword) {
   186      this.loading = true;
   187      await C.deletePassword(item.id);
   188      this.loading = false;
   189    }
   190  }
   191  </script>
   192  
   193  <style>
   194  .centered {
   195    vertical-align: middle;
   196  }
   197  </style>