mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-03 00:06:46 +01:00
Update email page to only load users when needed
This commit is contained in:
parent
aaaa314761
commit
2f72300636
@ -46,7 +46,12 @@ export default {
|
|||||||
ereaderDevice: {
|
ereaderDevice: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => null
|
default: () => null
|
||||||
}
|
},
|
||||||
|
users: {
|
||||||
|
type: Array,
|
||||||
|
default: () => []
|
||||||
|
},
|
||||||
|
loadUsers: Function
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -56,8 +61,7 @@ export default {
|
|||||||
email: '',
|
email: '',
|
||||||
availabilityOption: 'adminAndUp',
|
availabilityOption: 'adminAndUp',
|
||||||
users: []
|
users: []
|
||||||
},
|
}
|
||||||
users: []
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -108,25 +112,13 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
availabilityOptionChanged(option) {
|
availabilityOptionChanged(option) {
|
||||||
if (option === 'specificUsers' && !this.users.length) {
|
if (option === 'specificUsers' && !this.users.length) {
|
||||||
this.loadUsers()
|
this.callLoadUsers()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async loadUsers() {
|
async callLoadUsers() {
|
||||||
this.processing = true
|
this.processing = true
|
||||||
this.users = await this.$axios
|
await this.loadUsers()
|
||||||
.$get('/api/users')
|
this.processing = false
|
||||||
.then((res) => {
|
|
||||||
return res.users.sort((a, b) => {
|
|
||||||
return a.createdAt - b.createdAt
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error('Failed', error)
|
|
||||||
return []
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.processing = false
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
submitForm() {
|
submitForm() {
|
||||||
this.$refs.ereaderNameInput.blur()
|
this.$refs.ereaderNameInput.blur()
|
||||||
@ -226,10 +218,6 @@ export default {
|
|||||||
this.newDevice.email = this.ereaderDevice.email
|
this.newDevice.email = this.ereaderDevice.email
|
||||||
this.newDevice.availabilityOption = this.ereaderDevice.availabilityOption || 'adminOrUp'
|
this.newDevice.availabilityOption = this.ereaderDevice.availabilityOption || 'adminOrUp'
|
||||||
this.newDevice.users = this.ereaderDevice.users || []
|
this.newDevice.users = this.ereaderDevice.users || []
|
||||||
|
|
||||||
if (this.newDevice.availabilityOption === 'specificUsers' && !this.users.length) {
|
|
||||||
this.loadUsers()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this.newDevice.name = ''
|
this.newDevice.name = ''
|
||||||
this.newDevice.email = ''
|
this.newDevice.email = ''
|
||||||
|
@ -91,12 +91,12 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<div v-else class="text-center py-4">
|
<div v-else-if="!loading" class="text-center py-4">
|
||||||
<p class="text-lg text-gray-100">No Devices</p>
|
<p class="text-lg text-gray-100">No Devices</p>
|
||||||
</div>
|
</div>
|
||||||
</app-settings-content>
|
</app-settings-content>
|
||||||
|
|
||||||
<modals-emails-e-reader-device-modal v-model="showEReaderDeviceModal" :existing-devices="existingEReaderDevices" :ereader-device="selectedEReaderDevice" @update="ereaderDevicesUpdated" />
|
<modals-emails-e-reader-device-modal v-model="showEReaderDeviceModal" :users="users" :existing-devices="existingEReaderDevices" :ereader-device="selectedEReaderDevice" @update="ereaderDevicesUpdated" :loadUsers="loadUsers" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -152,6 +152,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async loadUsers() {
|
async loadUsers() {
|
||||||
|
if (this.users.length) return
|
||||||
this.users = await this.$axios
|
this.users = await this.$axios
|
||||||
.$get('/api/users')
|
.$get('/api/users')
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
@ -161,6 +162,7 @@ export default {
|
|||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error('Failed', error)
|
console.error('Failed', error)
|
||||||
|
this.$toast.error(this.$strings.ToastFailedToLoadData)
|
||||||
return []
|
return []
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -169,7 +171,6 @@ export default {
|
|||||||
if (user === 'userOrUp') return 'Users (excluding Guests)'
|
if (user === 'userOrUp') return 'Users (excluding Guests)'
|
||||||
if (user === 'guestOrUp') return 'Users (including Guests)'
|
if (user === 'guestOrUp') return 'Users (including Guests)'
|
||||||
if (user === 'specificUsers') {
|
if (user === 'specificUsers') {
|
||||||
this.loadUsers()
|
|
||||||
return device.users.map((id) => this.users.find((u) => u.id === id)?.username).join(', ')
|
return device.users.map((id) => this.users.find((u) => u.id === id)?.username).join(', ')
|
||||||
}
|
}
|
||||||
return 'Admins Only'
|
return 'Admins Only'
|
||||||
@ -212,6 +213,11 @@ export default {
|
|||||||
ereaderDevicesUpdated(ereaderDevices) {
|
ereaderDevicesUpdated(ereaderDevices) {
|
||||||
this.settings.ereaderDevices = ereaderDevices
|
this.settings.ereaderDevices = ereaderDevices
|
||||||
this.newSettings.ereaderDevices = ereaderDevices.map((d) => ({ ...d }))
|
this.newSettings.ereaderDevices = ereaderDevices.map((d) => ({ ...d }))
|
||||||
|
|
||||||
|
// Load users if a device has availability set to specific users
|
||||||
|
if (ereaderDevices.some((device) => device.availabilityOption === 'specificUsers')) {
|
||||||
|
this.loadUsers()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
addNewDeviceClick() {
|
addNewDeviceClick() {
|
||||||
this.selectedEReaderDevice = null
|
this.selectedEReaderDevice = null
|
||||||
@ -279,7 +285,12 @@ export default {
|
|||||||
|
|
||||||
this.$axios
|
this.$axios
|
||||||
.$get(`/api/emails/settings`)
|
.$get(`/api/emails/settings`)
|
||||||
.then((data) => {
|
.then(async (data) => {
|
||||||
|
// Load users if a device has availability set to specific users
|
||||||
|
if (data.settings.ereaderDevices.some((device) => device.availabilityOption === 'specificUsers')) {
|
||||||
|
await this.loadUsers()
|
||||||
|
}
|
||||||
|
|
||||||
this.settings = data.settings
|
this.settings = data.settings
|
||||||
this.newSettings = {
|
this.newSettings = {
|
||||||
...this.settings
|
...this.settings
|
||||||
|
Loading…
Reference in New Issue
Block a user