credential.vue 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <div class="bg-lightgray m-1 p-2 border rounded container-fluid">
  3. <credential-form-modal :descriptions="creddescList" :modal-id="'credential'+this.data.credid+'editModal'" :populateWith="this.data"></credential-form-modal>
  4. <div class="row no-gutters">
  5. <div class="h5 col-3 text-left">{{this.data.creddesc}}</div>
  6. <div class="col-9 text-right">{{this.data.creddate}}</div>
  7. </div>
  8. <div class="row">
  9. <div class="col-lg-9">
  10. <div>
  11. <label for="username"><i class="fas fa-fw fa-user"></i></label>
  12. <input type="text" v-bind:id="'username' + this.data.credid" class="border-0 credential" v-bind:value=this.data.creduser readonly/>
  13. <button v-bind:id="'btn-username' + this.data.credid" class="btn-clip btn btn-sm btn-primary rounded-pill" v-bind:data-clipboard-target="'#username' + this.data.credid">
  14. <i class="far fa-clone"></i>
  15. </button>
  16. </div>
  17. <div>
  18. <label for="password"><i class="fas fa-fw fa-key"></i></label>
  19. <input type="text" v-bind:id="'password' + this.data.credid" class="border-0 credential" v-bind:value=this.data.credpass readonly/>
  20. <button v-bind:id="'btn-password' + this.data.credid" class="btn-clip btn btn-sm btn-primary rounded-pill" v-bind:data-clipboard-target="'#password' + this.data.credid">
  21. <i class="far fa-clone"></i>
  22. </button>
  23. </div>
  24. </div>
  25. <div class="btn-group col-lg-2 align-self-end w-25 w-lg-auto" role="group" aria-label="Edit and Delete">
  26. <button type="button" class="btn btn-sm btn-secondary p-lg-1" data-toggle="modal" :data-target="'#credential'+this.data.credid+'editModal'"><i class="fas fa-fw fa-edit"></i></button>
  27. <button type="button" class="btn btn-sm btn-danger p-lg-1"><i class="fas fa-fw fa-trash-alt"></i></button>
  28. </div>
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. export default {
  34. props: ['credential', 'descriptions'],
  35. data() {
  36. return {
  37. data: JSON.parse(this.credential),
  38. }
  39. },
  40. computed : {
  41. creddescList: function () {
  42. let list = {}
  43. JSON.parse(this.descriptions).map(val => {
  44. list[val.creddescid] = val.credtitle
  45. })
  46. return list
  47. }
  48. },
  49. mounted() {
  50. Echo.channel('credentials')
  51. .listen('CredentialUpdated', (e) => {
  52. // This part could potentially use a refactor.
  53. // Probably needs a credential list component to listen for this
  54. // even and update the corresponding credential. Currently every
  55. // credential on the page receives this event and checks whether it was intended
  56. // for its credential or not. I would imagine this could cause a problem
  57. // on the group page, which will potentially have a lot more credentials from
  58. // various assets. Better solution may be to have a credentials list component
  59. // That listens for credential update events and updates the appropriate credential.
  60. // There would still be multiples of those on the group credentials page, but an
  61. // order of magnitude less of those than of individual credentials.
  62. // It also may not be a big deal performance wise to do it like this, not sure.
  63. let eData = JSON.parse(e.data);
  64. if (this.data.credid === eData.credid) {
  65. this.data = eData;
  66. }
  67. });
  68. }
  69. }
  70. </script>