credential.vue 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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: this.credential,
  38. creddescList: this.descriptions
  39. }
  40. },
  41. mounted() {
  42. Echo.channel('credentials')
  43. .listen('CredentialUpdated', (e) => {
  44. // This part could potentially use a refactor.
  45. // Probably needs a credential list component to listen for this
  46. // even and update the corresponding credential. Currently every
  47. // credential on the page receives this event and checks whether it was intended
  48. // for its credential or not. I would imagine this could cause a problem
  49. // on the group page, which will potentially have a lot more credentials from
  50. // various assets. Better solution may be to have a credentials list component
  51. // That listens for credential update events and updates the appropriate credential.
  52. // There would still be multiples of those on the group credentials page, but an
  53. // order of magnitude less of those than of individual credentials.
  54. // It also may not be a big deal performance wise to do it like this, not sure.
  55. let eData = JSON.parse(e.data);
  56. if (this.data.credid === eData.credid) {
  57. this.data = eData;
  58. }
  59. });
  60. }
  61. }
  62. </script>