feat: add support for inverting the selection on libraries and tags

This commit is contained in:
Divyang Joshi 2023-04-27 17:02:15 -04:00
parent 7685ead000
commit 0387436111
No known key found for this signature in database
GPG Key ID: 4155AEF0D685BA17
13 changed files with 71 additions and 22 deletions

View File

@ -6,7 +6,7 @@
</div> </div>
</template> </template>
<form @submit.prevent="submitForm"> <form @submit.prevent="submitForm">
<div class="px-4 w-full text-sm py-6 rounded-lg bg-bg shadow-lg border border-black-300"> <div class="px-4 w-full text-sm py-6 rounded-lg bg-bg shadow-lg border border-black-300 overflow-y-auto overflow-x-hidden" style="min-height: 400px; max-height: 80vh">
<div class="w-full p-8"> <div class="w-full p-8">
<div class="flex py-2"> <div class="flex py-2">
<div class="w-1/2 px-2"> <div class="w-1/2 px-2">
@ -96,7 +96,14 @@
</div> </div>
</div> </div>
<div v-if="!newUser.permissions.accessAllTags" class="my-4"> <div v-if="!newUser.permissions.accessAllTags" class="my-4">
<ui-multi-select-dropdown v-model="newUser.itemTagsAccessible" :items="itemTags" :label="$strings.LabelTagsAccessibleToUser" /> <div class="flex items-center">
<ui-multi-select-dropdown v-model="newUser.itemTagsSelected" :items="itemTags" :label="tagsSelectionText" />
<div class="flex items-center pt-4 px-2">
<p class="px-3 font-semibold" id="selected-tags-not-accessible--permissions-toggle">{{ $strings.LabelInvert }}</p>
<ui-toggle-switch labeledBy="selected-tags-not-accessible--permissions-toggle" v-model="newUser.permissions.selectedTagsNotAccessible" />
</div>
</div>
</div> </div>
</div> </div>
@ -185,6 +192,9 @@ export default {
value: t value: t
} }
}) })
},
tagsSelectionText() {
return this.newUser.permissions.selectedTagsNotAccessible ? this.$strings.LabelTagsNotAccessibleToUser : this.$strings.LabelTagsAccessibleToUser
} }
}, },
methods: { methods: {
@ -193,8 +203,11 @@ export default {
if (this.$refs.modal) this.$refs.modal.setHide() if (this.$refs.modal) this.$refs.modal.setHide()
}, },
accessAllTagsToggled(val) { accessAllTagsToggled(val) {
if (val && this.newUser.itemTagsAccessible.length) { if (val) {
this.newUser.itemTagsAccessible = [] if (this.newUser.itemTagsSelected?.length) {
this.newUser.itemTagsSelected = []
}
this.newUser.permissions.selectedTagsNotAccessible = false
} }
}, },
fetchAllTags() { fetchAllTags() {
@ -226,7 +239,7 @@ export default {
this.$toast.error('Must select at least one library') this.$toast.error('Must select at least one library')
return return
} }
if (!this.newUser.permissions.accessAllTags && !this.newUser.itemTagsAccessible.length) { if (!this.newUser.permissions.accessAllTags && !this.newUser.itemTagsSelected.length) {
this.$toast.error('Must select at least one tag') this.$toast.error('Must select at least one tag')
return return
} }
@ -307,12 +320,12 @@ export default {
delete: type === 'admin', delete: type === 'admin',
upload: type === 'admin', upload: type === 'admin',
accessAllLibraries: true, accessAllLibraries: true,
accessAllTags: true accessAllTags: true,
selectedTagsNotAccessible: false
} }
}, },
init() { init() {
this.fetchAllTags() this.fetchAllTags()
this.isNew = !this.account this.isNew = !this.account
if (this.account) { if (this.account) {
this.newUser = { this.newUser = {
@ -322,9 +335,10 @@ export default {
isActive: this.account.isActive, isActive: this.account.isActive,
permissions: { ...this.account.permissions }, permissions: { ...this.account.permissions },
librariesAccessible: [...(this.account.librariesAccessible || [])], librariesAccessible: [...(this.account.librariesAccessible || [])],
itemTagsAccessible: [...(this.account.itemTagsAccessible || [])] itemTagsSelected: [...(this.account.itemTagsSelected || [])]
} }
} else { } else {
this.fetchAllTags()
this.newUser = { this.newUser = {
username: null, username: null,
password: null, password: null,
@ -336,7 +350,8 @@ export default {
delete: false, delete: false,
upload: false, upload: false,
accessAllLibraries: true, accessAllLibraries: true,
accessAllTags: true accessAllTags: true,
selectedTagsNotAccessible: false
}, },
librariesAccessible: [] librariesAccessible: []
} }

View File

@ -254,6 +254,7 @@
"LabelIntervalEveryDay": "Jeden Tag", "LabelIntervalEveryDay": "Jeden Tag",
"LabelIntervalEveryHour": "Jede Stunde", "LabelIntervalEveryHour": "Jede Stunde",
"LabelInvalidParts": "Ungültige Teile", "LabelInvalidParts": "Ungültige Teile",
"LabelInvert": "Invert",
"LabelItem": "Medium", "LabelItem": "Medium",
"LabelLanguage": "Sprache", "LabelLanguage": "Sprache",
"LabelLanguageDefaultServer": "Standard-Server-Sprache", "LabelLanguageDefaultServer": "Standard-Server-Sprache",
@ -412,6 +413,7 @@
"LabelTag": "Schlagwort", "LabelTag": "Schlagwort",
"LabelTags": "Schlagwörter", "LabelTags": "Schlagwörter",
"LabelTagsAccessibleToUser": "Für Benutzer zugängliche Schlagwörter", "LabelTagsAccessibleToUser": "Für Benutzer zugängliche Schlagwörter",
"LabelTagsNotAccessibleToUser": "Tags not Accessible to User",
"LabelTasks": "Laufende Aufgaben", "LabelTasks": "Laufende Aufgaben",
"LabelTimeBase": "Basiszeit", "LabelTimeBase": "Basiszeit",
"LabelTimeListened": "Gehörte Zeit", "LabelTimeListened": "Gehörte Zeit",

View File

@ -254,6 +254,7 @@
"LabelIntervalEveryDay": "Every day", "LabelIntervalEveryDay": "Every day",
"LabelIntervalEveryHour": "Every hour", "LabelIntervalEveryHour": "Every hour",
"LabelInvalidParts": "Invalid Parts", "LabelInvalidParts": "Invalid Parts",
"LabelInvert": "Invert",
"LabelItem": "Item", "LabelItem": "Item",
"LabelLanguage": "Language", "LabelLanguage": "Language",
"LabelLanguageDefaultServer": "Default Server Language", "LabelLanguageDefaultServer": "Default Server Language",
@ -412,6 +413,7 @@
"LabelTag": "Tag", "LabelTag": "Tag",
"LabelTags": "Tags", "LabelTags": "Tags",
"LabelTagsAccessibleToUser": "Tags Accessible to User", "LabelTagsAccessibleToUser": "Tags Accessible to User",
"LabelTagsNotAccessibleToUser": "Tags not Accessible to User",
"LabelTasks": "Tasks Running", "LabelTasks": "Tasks Running",
"LabelTimeBase": "Time Base", "LabelTimeBase": "Time Base",
"LabelTimeListened": "Time Listened", "LabelTimeListened": "Time Listened",

View File

@ -254,6 +254,7 @@
"LabelIntervalEveryDay": "Cada Dia", "LabelIntervalEveryDay": "Cada Dia",
"LabelIntervalEveryHour": "Cada Hora", "LabelIntervalEveryHour": "Cada Hora",
"LabelInvalidParts": "Partes Invalidas", "LabelInvalidParts": "Partes Invalidas",
"LabelInvert": "Invert",
"LabelItem": "Elemento", "LabelItem": "Elemento",
"LabelLanguage": "Lenguaje", "LabelLanguage": "Lenguaje",
"LabelLanguageDefaultServer": "Lenguaje Predeterminado del Servidor", "LabelLanguageDefaultServer": "Lenguaje Predeterminado del Servidor",
@ -412,6 +413,7 @@
"LabelTag": "Etiqueta", "LabelTag": "Etiqueta",
"LabelTags": "Etiquetas", "LabelTags": "Etiquetas",
"LabelTagsAccessibleToUser": "Etiquetas Accessible para el Usuario", "LabelTagsAccessibleToUser": "Etiquetas Accessible para el Usuario",
"LabelTagsNotAccessibleToUser": "Tags not Accessible to User",
"LabelTasks": "Tareas Corriendo", "LabelTasks": "Tareas Corriendo",
"LabelTimeBase": "Time Base", "LabelTimeBase": "Time Base",
"LabelTimeListened": "Tiempo Escuchando", "LabelTimeListened": "Tiempo Escuchando",

View File

@ -254,6 +254,7 @@
"LabelIntervalEveryDay": "Tous les jours", "LabelIntervalEveryDay": "Tous les jours",
"LabelIntervalEveryHour": "Toutes les heures", "LabelIntervalEveryHour": "Toutes les heures",
"LabelInvalidParts": "Parties invalides", "LabelInvalidParts": "Parties invalides",
"LabelInvert": "Invert",
"LabelItem": "Article", "LabelItem": "Article",
"LabelLanguage": "Langue", "LabelLanguage": "Langue",
"LabelLanguageDefaultServer": "Langue par défaut", "LabelLanguageDefaultServer": "Langue par défaut",
@ -412,6 +413,7 @@
"LabelTag": "Étiquette", "LabelTag": "Étiquette",
"LabelTags": "Étiquettes", "LabelTags": "Étiquettes",
"LabelTagsAccessibleToUser": "Étiquettes accessibles à lutilisateur", "LabelTagsAccessibleToUser": "Étiquettes accessibles à lutilisateur",
"LabelTagsNotAccessibleToUser": "Tags not Accessible to User",
"LabelTasks": "Tâches en cours", "LabelTasks": "Tâches en cours",
"LabelTimeBase": "Base de temps", "LabelTimeBase": "Base de temps",
"LabelTimeListened": "Temps découte", "LabelTimeListened": "Temps découte",

View File

@ -254,6 +254,7 @@
"LabelIntervalEveryDay": "Every day", "LabelIntervalEveryDay": "Every day",
"LabelIntervalEveryHour": "Every hour", "LabelIntervalEveryHour": "Every hour",
"LabelInvalidParts": "Invalid Parts", "LabelInvalidParts": "Invalid Parts",
"LabelInvert": "Invert",
"LabelItem": "Item", "LabelItem": "Item",
"LabelLanguage": "Language", "LabelLanguage": "Language",
"LabelLanguageDefaultServer": "Default Server Language", "LabelLanguageDefaultServer": "Default Server Language",
@ -412,6 +413,7 @@
"LabelTag": "Tag", "LabelTag": "Tag",
"LabelTags": "Tags", "LabelTags": "Tags",
"LabelTagsAccessibleToUser": "Tags Accessible to User", "LabelTagsAccessibleToUser": "Tags Accessible to User",
"LabelTagsNotAccessibleToUser": "Tags not Accessible to User",
"LabelTasks": "Tasks Running", "LabelTasks": "Tasks Running",
"LabelTimeBase": "Time Base", "LabelTimeBase": "Time Base",
"LabelTimeListened": "Time Listened", "LabelTimeListened": "Time Listened",

View File

@ -254,6 +254,7 @@
"LabelIntervalEveryDay": "Every day", "LabelIntervalEveryDay": "Every day",
"LabelIntervalEveryHour": "Every hour", "LabelIntervalEveryHour": "Every hour",
"LabelInvalidParts": "Invalid Parts", "LabelInvalidParts": "Invalid Parts",
"LabelInvert": "Invert",
"LabelItem": "Item", "LabelItem": "Item",
"LabelLanguage": "Language", "LabelLanguage": "Language",
"LabelLanguageDefaultServer": "Default Server Language", "LabelLanguageDefaultServer": "Default Server Language",
@ -412,6 +413,7 @@
"LabelTag": "Tag", "LabelTag": "Tag",
"LabelTags": "Tags", "LabelTags": "Tags",
"LabelTagsAccessibleToUser": "Tags Accessible to User", "LabelTagsAccessibleToUser": "Tags Accessible to User",
"LabelTagsNotAccessibleToUser": "Tags not Accessible to User",
"LabelTasks": "Tasks Running", "LabelTasks": "Tasks Running",
"LabelTimeBase": "Time Base", "LabelTimeBase": "Time Base",
"LabelTimeListened": "Time Listened", "LabelTimeListened": "Time Listened",

View File

@ -254,6 +254,7 @@
"LabelIntervalEveryDay": "Every day", "LabelIntervalEveryDay": "Every day",
"LabelIntervalEveryHour": "Every hour", "LabelIntervalEveryHour": "Every hour",
"LabelInvalidParts": "Nevaljajuči dijelovi", "LabelInvalidParts": "Nevaljajuči dijelovi",
"LabelInvert": "Invert",
"LabelItem": "Stavka", "LabelItem": "Stavka",
"LabelLanguage": "Jezik", "LabelLanguage": "Jezik",
"LabelLanguageDefaultServer": "Default jezik servera", "LabelLanguageDefaultServer": "Default jezik servera",
@ -412,6 +413,7 @@
"LabelTag": "Tag", "LabelTag": "Tag",
"LabelTags": "Tags", "LabelTags": "Tags",
"LabelTagsAccessibleToUser": "Tags dostupni korisniku", "LabelTagsAccessibleToUser": "Tags dostupni korisniku",
"LabelTagsNotAccessibleToUser": "Tags not Accessible to User",
"LabelTasks": "Tasks Running", "LabelTasks": "Tasks Running",
"LabelTimeBase": "Time Base", "LabelTimeBase": "Time Base",
"LabelTimeListened": "Vremena odslušano", "LabelTimeListened": "Vremena odslušano",

View File

@ -254,6 +254,7 @@
"LabelIntervalEveryDay": "Ogni Giorno", "LabelIntervalEveryDay": "Ogni Giorno",
"LabelIntervalEveryHour": "Ogni ora", "LabelIntervalEveryHour": "Ogni ora",
"LabelInvalidParts": "Parti Invalide", "LabelInvalidParts": "Parti Invalide",
"LabelInvert": "Invert",
"LabelItem": "Oggetti", "LabelItem": "Oggetti",
"LabelLanguage": "Lingua", "LabelLanguage": "Lingua",
"LabelLanguageDefaultServer": "Lingua di Default", "LabelLanguageDefaultServer": "Lingua di Default",
@ -412,6 +413,7 @@
"LabelTag": "Tag", "LabelTag": "Tag",
"LabelTags": "Tags", "LabelTags": "Tags",
"LabelTagsAccessibleToUser": "Tags permessi agli Utenti", "LabelTagsAccessibleToUser": "Tags permessi agli Utenti",
"LabelTagsNotAccessibleToUser": "Tags not Accessible to User",
"LabelTasks": "Processi in esecuzione", "LabelTasks": "Processi in esecuzione",
"LabelTimeBase": "Time Base", "LabelTimeBase": "Time Base",
"LabelTimeListened": "Tempo di Ascolto", "LabelTimeListened": "Tempo di Ascolto",

View File

@ -254,6 +254,7 @@
"LabelIntervalEveryDay": "Każdego dnia", "LabelIntervalEveryDay": "Każdego dnia",
"LabelIntervalEveryHour": "Każdej godziny", "LabelIntervalEveryHour": "Każdej godziny",
"LabelInvalidParts": "Nieprawidłowe części", "LabelInvalidParts": "Nieprawidłowe części",
"LabelInvert": "Invert",
"LabelItem": "Pozycja", "LabelItem": "Pozycja",
"LabelLanguage": "Język", "LabelLanguage": "Język",
"LabelLanguageDefaultServer": "Domyślny język serwera", "LabelLanguageDefaultServer": "Domyślny język serwera",
@ -412,6 +413,7 @@
"LabelTag": "Tag", "LabelTag": "Tag",
"LabelTags": "Tagi", "LabelTags": "Tagi",
"LabelTagsAccessibleToUser": "Tagi dostępne dla użytkownika", "LabelTagsAccessibleToUser": "Tagi dostępne dla użytkownika",
"LabelTagsNotAccessibleToUser": "Tags not Accessible to User",
"LabelTasks": "Tasks Running", "LabelTasks": "Tasks Running",
"LabelTimeBase": "Time Base", "LabelTimeBase": "Time Base",
"LabelTimeListened": "Czas odtwarzania", "LabelTimeListened": "Czas odtwarzania",

View File

@ -254,6 +254,7 @@
"LabelIntervalEveryDay": "Каждый день", "LabelIntervalEveryDay": "Каждый день",
"LabelIntervalEveryHour": "Каждый час", "LabelIntervalEveryHour": "Каждый час",
"LabelInvalidParts": "Неверные части", "LabelInvalidParts": "Неверные части",
"LabelInvert": "Invert",
"LabelItem": "Элемент", "LabelItem": "Элемент",
"LabelLanguage": "Язык", "LabelLanguage": "Язык",
"LabelLanguageDefaultServer": "Язык сервера по умолчанию", "LabelLanguageDefaultServer": "Язык сервера по умолчанию",
@ -412,6 +413,7 @@
"LabelTag": "Тег", "LabelTag": "Тег",
"LabelTags": "Теги", "LabelTags": "Теги",
"LabelTagsAccessibleToUser": "Теги доступные для пользователя", "LabelTagsAccessibleToUser": "Теги доступные для пользователя",
"LabelTagsNotAccessibleToUser": "Tags not Accessible to User",
"LabelTasks": "Запущенные задачи", "LabelTasks": "Запущенные задачи",
"LabelTimeBase": "Time Base", "LabelTimeBase": "Time Base",
"LabelTimeListened": "Время прослушивания", "LabelTimeListened": "Время прослушивания",

View File

@ -254,6 +254,7 @@
"LabelIntervalEveryDay": "每天", "LabelIntervalEveryDay": "每天",
"LabelIntervalEveryHour": "每小时", "LabelIntervalEveryHour": "每小时",
"LabelInvalidParts": "无效部件", "LabelInvalidParts": "无效部件",
"LabelInvert": "Invert",
"LabelItem": "项目", "LabelItem": "项目",
"LabelLanguage": "语言", "LabelLanguage": "语言",
"LabelLanguageDefaultServer": "默认服务器语言", "LabelLanguageDefaultServer": "默认服务器语言",
@ -412,6 +413,7 @@
"LabelTag": "标签", "LabelTag": "标签",
"LabelTags": "标签", "LabelTags": "标签",
"LabelTagsAccessibleToUser": "用户可访问的标签", "LabelTagsAccessibleToUser": "用户可访问的标签",
"LabelTagsNotAccessibleToUser": "Tags not Accessible to User",
"LabelTasks": "正在运行的任务", "LabelTasks": "正在运行的任务",
"LabelTimeBase": "Time Base", "LabelTimeBase": "Time Base",
"LabelTimeListened": "收听时间", "LabelTimeListened": "收听时间",

View File

@ -20,7 +20,7 @@ class User {
this.permissions = {} this.permissions = {}
this.librariesAccessible = [] // Library IDs (Empty if ALL libraries) this.librariesAccessible = [] // Library IDs (Empty if ALL libraries)
this.itemTagsAccessible = [] // Empty if ALL item tags accessible this.itemTagsSelected = [] // Empty if ALL item tags accessible
if (user) { if (user) {
this.construct(user) this.construct(user)
@ -86,7 +86,7 @@ class User {
createdAt: this.createdAt, createdAt: this.createdAt,
permissions: this.permissions, permissions: this.permissions,
librariesAccessible: [...this.librariesAccessible], librariesAccessible: [...this.librariesAccessible],
itemTagsAccessible: [...this.itemTagsAccessible] itemTagsSelected: [...this.itemTagsSelected]
} }
} }
@ -105,7 +105,7 @@ class User {
createdAt: this.createdAt, createdAt: this.createdAt,
permissions: this.permissions, permissions: this.permissions,
librariesAccessible: [...this.librariesAccessible], librariesAccessible: [...this.librariesAccessible],
itemTagsAccessible: [...this.itemTagsAccessible] itemTagsSelected: [...this.itemTagsSelected]
} }
if (minimal) { if (minimal) {
delete json.mediaProgress delete json.mediaProgress
@ -169,9 +169,15 @@ class User {
if (this.permissions.accessAllTags === undefined) this.permissions.accessAllTags = true if (this.permissions.accessAllTags === undefined) this.permissions.accessAllTags = true
// Explicit content restriction permission added v2.0.18 // Explicit content restriction permission added v2.0.18
if (this.permissions.accessExplicitContent === undefined) this.permissions.accessExplicitContent = true if (this.permissions.accessExplicitContent === undefined) this.permissions.accessExplicitContent = true
// itemTagsAccessible was renamed to itemTagsSelected in version v2.x
if (this.itemTagsAccessible) {
this.permissions.selectedTagsNotAccessible = false
this.itemTagsSelected = this.itemTagsAccessible
this.itemTagsAccessible = undefined
}
this.librariesAccessible = [...(user.librariesAccessible || [])] this.librariesAccessible = [...(user.librariesAccessible || [])]
this.itemTagsAccessible = [...(user.itemTagsAccessible || [])] this.itemTagsSelected = [...(user.itemTagsSelected || [])]
} }
update(payload) { update(payload) {
@ -228,19 +234,21 @@ class User {
// Update accessible tags // Update accessible tags
if (this.permissions.accessAllTags) { if (this.permissions.accessAllTags) {
// Access all tags // Access all tags
if (this.itemTagsAccessible.length) { if (this.itemTagsSelected.length) {
this.itemTagsAccessible = [] this.itemTagsSelected = []
this.permissions.selectedTagsNotAccessible = false
hasUpdates = true hasUpdates = true
} }
} else if (payload.itemTagsAccessible !== undefined) { } else if (payload.itemTagsSelected !== undefined) {
if (payload.itemTagsAccessible.length) { if (payload.itemTagsSelected.length) {
if (payload.itemTagsAccessible.join(',') !== this.itemTagsAccessible.join(',')) { if (payload.itemTagsSelected.join(',') !== this.itemTagsSelected.join(',')) {
hasUpdates = true hasUpdates = true
this.itemTagsAccessible = [...payload.itemTagsAccessible] this.itemTagsSelected = [...payload.itemTagsSelected]
} }
} else if (this.itemTagsAccessible.length > 0) { } else if (this.itemTagsSelected.length > 0) {
hasUpdates = true hasUpdates = true
this.itemTagsAccessible = [] this.itemTagsSelected = []
this.permissions.selectedTagsNotAccessible = false
} }
} }
return hasUpdates return hasUpdates
@ -343,8 +351,12 @@ class User {
checkCanAccessLibraryItemWithTags(tags) { checkCanAccessLibraryItemWithTags(tags) {
if (this.permissions.accessAllTags) return true if (this.permissions.accessAllTags) return true
if (this.permissions.selectedTagsNotAccessible) {
if (!tags || !tags.length) return true
return tags.every(tag => !this.itemTagsSelected.includes(tag))
}
if (!tags || !tags.length) return false if (!tags || !tags.length) return false
return this.itemTagsAccessible.some(tag => tags.includes(tag)) return this.itemTagsSelected.some(tag => tags.includes(tag))
} }
checkCanAccessLibraryItem(libraryItem) { checkCanAccessLibraryItem(libraryItem) {