Users.vue 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div id="users">
  3. <md-card>
  4. <md-card-header>
  5. <span class="md-title">Users</span>
  6. </md-card-header>
  7. <md-card-content>
  8. <md-table>
  9. <md-table-header>
  10. <md-table-row>
  11. <md-table-head>Username</md-table-head>
  12. <md-table-head>Email</md-table-head>
  13. </md-table-row>
  14. </md-table-header>
  15. <md-table-body>
  16. <md-table-row v-for="(user, index) in users" :key="user._id">
  17. <md-table-cell>
  18. <router-link :to="userLink(user._id)" class="md-raised md-primary">
  19. {{user.username}}
  20. </router-link>
  21. </md-table-cell>
  22. <md-table-cell>
  23. {{user.email}}
  24. </md-table-cell>
  25. </md-table-row>
  26. </md-table-body>
  27. </md-table>
  28. </md-card-content>
  29. </md-card>
  30. <ibt-dialog ref="dialogObj" />
  31. </div>
  32. </template>
  33. <script>
  34. import IbtDialog from './IbtDialog.vue';
  35. export default {
  36. data () {
  37. return {
  38. users: []
  39. }
  40. },
  41. computed: {
  42. loggedInUser() {
  43. return this.$store.state.loggedInUser;
  44. }
  45. },
  46. beforeCreate: function() {
  47. this.usersUrl = this.$resource('users{/id}');
  48. },
  49. mounted: function() {
  50. this.getUsers();
  51. },
  52. methods: {
  53. userLink(id) {
  54. return '/user/' + id;
  55. },
  56. getUsers() {
  57. this.usersUrl.get().then((response) => {
  58. return response.json();
  59. }, (response) => {
  60. this.$refs.dialogObj.show({text: 'unable to get the list of users'});
  61. }).then((data) => {
  62. this.users = data.users || [];
  63. });
  64. },
  65. deleteUser(userId) {
  66. this.usersUrl.update({id: userId}).then((response) => {
  67. return response.json();
  68. }, (response) => {
  69. this.$refs.dialogObj.show({text: 'unable to delete the user'});
  70. }).then((data) => {
  71. });
  72. }
  73. },
  74. components: { IbtDialog }
  75. }
  76. </script>
  77. <style>
  78. #users {
  79. padding: 10px;
  80. }
  81. </style>