credential.vue 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. <modal :id="'credential'+this.data.credid+'deleteModal'" tabindex="-1">
  5. <h5 slot="header" class="modal-title" :id="'credential'+this.data.credid+'deleteModalLabel'">
  6. Delete Credential
  7. </h5>
  8. <div slot="body">
  9. Are you sure?
  10. </div>
  11. <div slot="footer">
  12. <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
  13. <button type="button" class="btn btn-danger" @click=deleteCredential()>Confirm</button>
  14. </div>
  15. </modal>
  16. <div class="row no-gutters">
  17. <div class="h5 col-3 text-left">{{this.data.creddesc}}</div>
  18. <div class="col-9 text-right">{{this.data.creddate}}</div>
  19. </div>
  20. <div class="row">
  21. <div class="col-lg-9">
  22. <div>
  23. <label for="username"><i class="fas fa-fw fa-user"></i></label>
  24. <input type="text" v-bind:id="'username' + this.data.credid" class="border-0 credential" v-bind:value=this.data.creduser readonly/>
  25. <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">
  26. <i class="far fa-clone"></i>
  27. </button>
  28. </div>
  29. <div>
  30. <label for="password"><i class="fas fa-fw fa-key"></i></label>
  31. <input type="text" v-bind:id="'password' + this.data.credid" class="border-0 credential" v-bind:value=this.data.credpass readonly/>
  32. <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">
  33. <i class="far fa-clone"></i>
  34. </button>
  35. </div>
  36. </div>
  37. <div class="btn-group col-lg-2 align-self-end w-25 w-lg-auto" role="group" aria-label="Edit and Delete">
  38. <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>
  39. <button type="button" class="btn btn-sm btn-danger p-lg-1" data-toggle="modal" :data-target="'#credential'+this.data.credid+'deleteModal'"><i class="fas fa-fw fa-trash-alt"></i></button>
  40. </div>
  41. </div>
  42. </div>
  43. </template>
  44. <script>
  45. export default {
  46. props: ['credential', 'descriptions'],
  47. data() {
  48. return {
  49. data: this.credential,
  50. creddescList: this.descriptions
  51. }
  52. },
  53. mounted() {
  54. console.log('credential.'+this.data.credid)
  55. Echo.channel('credential.'+this.data.credid)
  56. .listen('CredentialUpdated', (e) => {
  57. // This part could potentially use a refactor.
  58. // Probably needs a credential list component to listen for this
  59. // even and update the corresponding credential. Currently every
  60. // credential on the page receives this event and checks whether it was intended
  61. // for its credential or not. I would imagine this could cause a problem
  62. // on the group page, which will potentially have a lot more credentials from
  63. // various assets. Better solution may be to have a credentials list component
  64. // That listens for credential update events and updates the appropriate credential.
  65. // There would still be multiples of those on the group credentials page, but an
  66. // order of magnitude less of those than of individual credentials.
  67. // It also may not be a big deal performance wise to do it like this, not sure.
  68. this.data = e.credential;
  69. });
  70. },
  71. methods: {
  72. deleteCredential() {
  73. axios.delete('/api/credentials/' + this.data.credid, this.data)
  74. .then(response => {
  75. $('#credential'+this.data.credid+'deleteModal').modal('hide');
  76. }).catch(error => { console.error(error) })
  77. }
  78. }
  79. }
  80. </script>