Add ability to mark magic shelves as public (#1489)
Adds a checkbox to the create/edit magic shelf dialog to set the shelf as public. If public then it shows up for all users. Only admins can edit public shelves (edit options disabled for non-admin)
This commit is contained in:
@@ -16,6 +16,8 @@ import {MultiSelect} from 'primeng/multiselect';
|
||||
import {AutoComplete} from 'primeng/autocomplete';
|
||||
import {EMPTY_CHECK_OPERATORS, MULTI_VALUE_OPERATORS, parseValue, removeNulls, serializeDateRules} from '../service/magic-shelf-utils';
|
||||
import {IconPickerService} from '../../../shared/service/icon-picker.service';
|
||||
import {CheckboxModule} from "primeng/checkbox";
|
||||
import {UserService} from "../../settings/user-management/user.service";
|
||||
|
||||
export type RuleOperator =
|
||||
| 'equals'
|
||||
@@ -150,7 +152,8 @@ const FIELD_CONFIGS: Record<RuleField, FullFieldConfig> = {
|
||||
DatePicker,
|
||||
InputNumber,
|
||||
MultiSelect,
|
||||
AutoComplete
|
||||
AutoComplete,
|
||||
CheckboxModule
|
||||
]
|
||||
})
|
||||
export class MagicShelfComponent implements OnInit {
|
||||
@@ -190,15 +193,18 @@ export class MagicShelfComponent implements OnInit {
|
||||
form = new FormGroup({
|
||||
name: new FormControl<string | null>(null),
|
||||
icon: new FormControl<string | null>(null),
|
||||
isPublic: new FormControl<boolean>(false),
|
||||
group: this.createGroup()
|
||||
});
|
||||
|
||||
shelfId: number | null = null;
|
||||
isAdmin: boolean = false;
|
||||
|
||||
libraryService = inject(LibraryService);
|
||||
magicShelfService = inject(MagicShelfService);
|
||||
messageService = inject(MessageService);
|
||||
config = inject(DynamicDialogConfig);
|
||||
userService = inject(UserService);
|
||||
private iconPicker = inject(IconPickerService);
|
||||
|
||||
trackByFn(ruleCtrl: AbstractControl, index: number): any {
|
||||
@@ -206,6 +212,7 @@ export class MagicShelfComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.isAdmin = this.userService.getCurrentUser()?.permissions.admin ?? false;
|
||||
const id = this.config?.data?.id;
|
||||
|
||||
if (id) {
|
||||
@@ -214,6 +221,7 @@ export class MagicShelfComponent implements OnInit {
|
||||
this.form = new FormGroup({
|
||||
name: new FormControl<string | null>(data?.name ?? null, {nonNullable: true, validators: [Validators.required]}),
|
||||
icon: new FormControl<string | null>(data?.icon ?? null, {nonNullable: true, validators: [Validators.required]}),
|
||||
isPublic: new FormControl<boolean>(data?.isPublic ?? false),
|
||||
group: data?.filterJson ? this.buildGroupFromData(JSON.parse(data.filterJson)) : this.createGroup()
|
||||
});
|
||||
});
|
||||
@@ -221,6 +229,7 @@ export class MagicShelfComponent implements OnInit {
|
||||
this.form = new FormGroup({
|
||||
name: new FormControl<string | null>(null, {nonNullable: true, validators: [Validators.required]}),
|
||||
icon: new FormControl<string | null>(null, {nonNullable: true, validators: [Validators.required]}),
|
||||
isPublic: new FormControl<boolean>(false),
|
||||
group: this.createGroup()
|
||||
});
|
||||
}
|
||||
@@ -432,25 +441,36 @@ export class MagicShelfComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
onIsPublicChange(event: any) {
|
||||
this.form.get('isPublic')?.setValue(event.checked);
|
||||
}
|
||||
|
||||
submit() {
|
||||
if (!this.hasAtLeastOneValidRule(this.group)) {
|
||||
this.messageService.add({severity: 'warn', summary: 'Validation Error', detail: 'You must add at least one valid rule before saving.'});
|
||||
return;
|
||||
}
|
||||
|
||||
const value = this.form.value as { name: string | null; icon: string | null; group: GroupRule };
|
||||
const value = this.form.value as { name: string | null; icon: string | null; group: GroupRule, isPublic: boolean | null };
|
||||
const cleanedGroup = removeNulls(serializeDateRules(value.group));
|
||||
|
||||
this.magicShelfService.saveShelf({
|
||||
id: this.shelfId ?? undefined,
|
||||
name: value.name,
|
||||
icon: value.icon,
|
||||
isPublic: !!value.isPublic, // Ensure it's a boolean
|
||||
group: cleanedGroup
|
||||
}).subscribe({
|
||||
next: (savedShelf) => {
|
||||
this.messageService.add({severity: 'success', summary: 'Success', detail: 'Magic shelf saved successfully.'});
|
||||
if (savedShelf?.id) {
|
||||
this.shelfId = savedShelf.id;
|
||||
// Update the form with the saved data to reflect changes immediately
|
||||
this.form.patchValue({
|
||||
name: savedShelf.name,
|
||||
icon: savedShelf.icon,
|
||||
isPublic: savedShelf.isPublic
|
||||
});
|
||||
}
|
||||
},
|
||||
error: (err) => {
|
||||
|
||||
Reference in New Issue
Block a user