summaryrefslogtreecommitdiffstats
path: root/settings/src/views/Users.vue
blob: cad152f71efff34c8f1831485dae4e345d4ba628 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<template>
	<div id="app">
		<app-navigation :menu="menu">
			<template slot="settings-content">
				<div>
					<input type="checkbox" id="showLanguages" class="checkbox"
						   :checked="showLanguages" v-model="showLanguages">
					<label for="showLanguages">{{t('settings', 'Show Languages')}}</label>
				</div>
				<div>
					<input type="checkbox" id="showLastLogin" class="checkbox"
						   :checked="showLastLogin" v-model="showLastLogin">
					<label for="showLastLogin">{{t('settings', 'Show last login')}}</label>
				</div>
				<div>
					<input type="checkbox" id="showUserBackend" class="checkbox"
						   :checked="showUserBackend" v-model="showUserBackend">
					<label for="showUserBackend">{{t('settings', 'Show user backend')}}</label>
				</div>
				<div>
					<input type="checkbox" id="showStoragePath" class="checkbox"
						   :checked="showStoragePath" v-model="showStoragePath">
					<label for="showStoragePath">{{t('settings', 'Show storage path')}}</label>
				</div>
			</template>
		</app-navigation>
		<user-list :users="users" :showConfig="showConfig" :selectedGroup="selectedGroup" />
	</div>
</template>

<script>
import appNavigation from '../components/appNavigation';
import userList from '../components/userList';
import Vue from 'vue';
import VueLocalStorage from 'vue-localstorage'
Vue.use(VueLocalStorage)

export default {
	name: 'Users',
	props: ['selectedGroup'],
	components: {
		appNavigation,
		userList
	},
	beforeMount() {
		this.$store.commit('initGroups', {
			groups: this.$store.getters.getServerData.groups,
			orderBy: this.$store.getters.getServerData.sortGroups,
			userCount: this.$store.getters.getServerData.userCount
		});
		this.$store.dispatch('getPasswordPolicyMinLength');
	},
	data() {
		return {
			showConfig: {
				showStoragePath: false,
				showUserBackend: false,
				showLastLogin: false,
				showNewUserForm: false,
				showLanguages: false
			}
		}
	},
	methods: {
		getLocalstorage(key) {
			// force initialization
			this.showConfig[key] = this.$localStorage.get(key) === 'true';
			return this.showConfig[key];
		},
		setLocalStorage(key, status) {
			this.showConfig[key] = status;
			this.$localStorage.set(key, status);
			return status;
		}
	},
	computed: {
		route() {
			return this.$store.getters.getRoute;
		},
		users() {
			return this.$store.getters.getUsers;
		},
		loading() {
			return Object.keys(this.users).length === 0;
		},
		usersOffset() {
			return this.$store.getters.getUsersOffset;
		},
		usersLimit() {
			return this.$store.getters.getUsersLimit;
		},

		// Local settings
		showLanguages: {
			get: function() {return this.getLocalstorage('showLanguages')},
			set: function(status) {
				this.setLocalStorage('showLanguages', status);
			}
		},
		showLastLogin: {
			get: function() {return this.getLocalstorage('showLastLogin')},
			set: function(status) {
				this.setLocalStorage('showLastLogin', status);
			}
		},
		showUserBackend: {
			get: function() {return this.getLocalstorage('showUserBackend')},
			set: function(status) {
				this.setLocalStorage('showUserBackend', status);
			}
		},
		showStoragePath: {
			get: function() {return this.getLocalstorage('showStoragePath')},
			set: function(status) {
				this.setLocalStorage('showStoragePath', status);
			}
		},

		userCount() {
			return this.$store.getters.getUserCount;
		},

		menu() {
			// Data provided php side
			let groups = this.$store.getters.getGroups;
			groups = Array.isArray(groups) ? groups : [];

			// Map groups
			groups = groups.map(group => {
				let item = {};
				item.id = group.id.replace(' ', '_');
				item.classes = [];							// empty classes, active will be set later
				item.router = {								// router link to
					name: 'group',
					params: {selectedGroup: group.id}
				};
				item.text = group.name;						// group name
				item.utils = {counter: group.usercount};	// users count

				if (item.id !== 'admin' && item.id !== 'disabled') {
					// add delete button on real groups
					let self = this;
					item.utils.actions = [{
						icon: 'icon-delete',
						text: t('settings', 'Remove group'),
						action: () => {}
					}];
				};
				return item;
			});

			// Adjust data
			let adminGroup = groups.find(group => group.id == 'admin');
			   let disabledGroupIndex = groups.findIndex(group => group.id == 'disabled');
			   let disabledGroup = groups[disabledGroupIndex];
			if (adminGroup.text) {
				adminGroup.text = t('settings', 'Admins'); // rename admin group
			}
			if (disabledGroup.text) {
				disabledGroup.text = t('settings', 'Disabled users'); // rename disabled group
				if (disabledGroup.utils.counter === 0) {
					groups.splice(disabledGroupIndex, 1); // remove disabled if empty
				}
			}

			// Add everyone group
			groups.unshift({
				id: 'everyone',
				classes: [],
				router: {name:'users'},
				text: t('settings', 'Everyone'),
				utils: {counter: this.userCount}
			});

			// Set current group as active
			let activeGroup = groups.findIndex(group => group.id === this.selectedGroup);
			if (activeGroup >= 0) {
				groups[activeGroup].classes.push('active');
			} else {
				groups[0].classes.push('active');
			}

			// Return
			return {
				id: 'usergrouplist',
				new: {
					id:'new-user-button',
					text: t('settings','New user'),
					icon: 'icon-add',
					action: () => this.showConfig.showNewUserForm=!this.showConfig.showNewUserForm
				},
				items: groups
			}
		},
		removeGroup(groupid) {
			console.trace(this);
			return this.$store.dispatch('removeGroup', groupid);
		}
	}
}
</script>