Users.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div id="app">
  3. <app-navigation :menu="menu">
  4. <template slot="settings-content">
  5. <div>
  6. <input type="checkbox" id="showLastLogin" class="checkbox"
  7. :checked="showLastLogin" v-model="showLastLogin">
  8. <label for="showLastLogin">{{t('settings', 'Show last login')}}</label>
  9. </div>
  10. <div>
  11. <input type="checkbox" id="showUserBackend" class="checkbox"
  12. :checked="showUserBackend" v-model="showUserBackend">
  13. <label for="showUserBackend">{{t('settings', 'Show user backend')}}</label>
  14. </div>
  15. <div>
  16. <input type="checkbox" id="showStoragePath" class="checkbox"
  17. :checked="showStoragePath" v-model="showStoragePath">
  18. <label for="showStoragePath">{{t('settings', 'Show storage path')}}</label>
  19. </div>
  20. </template>
  21. </app-navigation>
  22. <user-list :users="users" :showConfig="showConfig" />
  23. </div>
  24. </template>
  25. <script>
  26. import appNavigation from '../components/appNavigation';
  27. import userList from '../components/userList';
  28. import Vue from 'vue';
  29. import VueLocalStorage from 'vue-localstorage'
  30. Vue.use(VueLocalStorage)
  31. export default {
  32. name: 'Users',
  33. components: {
  34. appNavigation,
  35. userList
  36. },
  37. beforeMount() {
  38. this.$store.commit('initGroups', {
  39. groups: this.$store.getters.getServerData.groups,
  40. orderBy: this.$store.getters.getServerData.sortGroups
  41. });
  42. this.$store.dispatch('getPasswordPolicyMinLength');
  43. },
  44. data() {
  45. return {
  46. showConfig: {
  47. showStoragePath: false,
  48. showUserBackend: false,
  49. showLastLogin: false,
  50. showNewUserForm: false
  51. }
  52. }
  53. },
  54. methods: {
  55. getLocalstorage(key) {
  56. // force initialization
  57. this.showConfig[key] = this.$localStorage.get(key) === 'true';
  58. return this.showConfig[key];
  59. },
  60. setLocalStorage(key, status) {
  61. this.showConfig[key] = status;
  62. this.$localStorage.set(key, status);
  63. return status;
  64. }
  65. },
  66. computed: {
  67. users() {
  68. return this.$store.getters.getUsers;
  69. },
  70. loading() {
  71. return Object.keys(this.users).length === 0;
  72. },
  73. usersOffset() {
  74. return this.$store.getters.getUsersOffset;
  75. },
  76. usersLimit() {
  77. return this.$store.getters.getUsersLimit;
  78. },
  79. showLastLogin: {
  80. get: function() {return this.getLocalstorage('showLastLogin')},
  81. set: function(status) {
  82. this.setLocalStorage('showLastLogin', status);
  83. }
  84. },
  85. showUserBackend: {
  86. get: function() {return this.getLocalstorage('showUserBackend')},
  87. set: function(status) {
  88. this.setLocalStorage('showUserBackend', status);
  89. }
  90. },
  91. showStoragePath: {
  92. get: function() {return this.getLocalstorage('showStoragePath')},
  93. set: function(status) {
  94. this.setLocalStorage('showStoragePath', status);
  95. }
  96. },
  97. menu() {
  98. let self = this;
  99. // Data provided php side
  100. let groups = this.$store.getters.getGroups;
  101. groups = Array.isArray(groups) ? groups : [];
  102. // Map groups
  103. groups = groups.map(group => {
  104. let item = {};
  105. item.id = group.id.replace(' ', '_');
  106. item.classes = [];
  107. item.href = '#group'+group.id.replace(' ', '_');
  108. item.text = group.name;
  109. item.utils = {counter: group.usercount};
  110. return item;
  111. });
  112. // Adjust data
  113. if (groups[0].id === 'admin') {
  114. groups[0].text = t('settings', 'Admins');} // rename admin group
  115. if (groups[1].id === '_disabled') {
  116. groups[1].text = t('settings', 'Disabled users'); // rename disabled group
  117. if (groups[1].utils.counter === 0) {
  118. groups.splice(1, 1); // remove disabled if empty
  119. }
  120. }
  121. // Add everyone group
  122. groups.unshift({
  123. id: '_everyone',
  124. classes: ['active'],
  125. href:'#group_everyone',
  126. text: t('settings', 'Everyone'),
  127. utils: {counter: this.users.length}
  128. });
  129. // Return
  130. return {
  131. id: 'usergrouplist',
  132. new: {
  133. id:'new-user-button',
  134. text: t('settings','New user'),
  135. icon: 'icon-add',
  136. action: function(){self.showConfig.showNewUserForm=!self.showConfig.showNewUserForm}
  137. },
  138. items: groups
  139. }
  140. }
  141. }
  142. }
  143. </script>
  144. <style lang="scss">
  145. </style>