
* Started the migration to bootstrap 5. Introduced a breakpoint system that bootstrap reflects for our screens. * sr only migrated * mr/ml -> me/ms * pl/pr -> ps/pe * btn-block * removed input-group-append * Added form-label to all labels * Added some style overrides for inputs * Replaced form-group with mb-3 * Ignore journal files * Update media to d-flex/flex-grow-1 * Fixed reading list detail page * For develop builds, don't inline critical styles * Fixed some downstream security issues * Fixed a layout issue in series detail * Fixed issue with btn-light not having background color. Updated layout for series detail metadata * Cleaned up nav search * Laid out the organization for custom theme components. Update _inputs.scss with variable overrides and depending on theme, it will just work. * Lots of theming work * Added inputs to the theme page * Login and input placeholder changes - Fixed login screen centering issue on all devices - Changed the format of the login screen - Change the input placeholder color * Added checkbox styles * Refactored tagbadges and removed some ngdeep selectors * Added nav bar component and refactored some styles into event widget * Cleaned nav events again and made dedicated popover body * Finished pagination component * Fixed up some styles with buttons * refactored dropdown component * Update accordion component * Refactored breadcrumbs and rating star. Fixed a missing style for cards * Fixed some styling issues on person badge, added modal component, and some global styles * Finished moving everything within dark to component files * Fixed up filter buttons, move card styles into a component theme, fixed slider style * Refactored library card and grouped typeahead * Updated normal typeahead component and reduced amount of ngdeep selector * Refactored grid breakpoints to be available by css variable, but it's hardcoded into the app * Ensure breakpoints are defined per theme * Fixed up some styling overrides and customization for nav links and alt button * Removed some deep styles, moved css out of splash container and brough back labels for login page * Finished css variable refactor * Refactored all the theme variable definitions into files for each theme. * Added back bootstrap overrides * Added a note about bootstrap theme colors being not-possible to swap out at runtime * Cleaned up some dead code * Implemented the ability to set a custom theme on the site. Cleaned up misc code throughout. * Additional changes - Fixed nav where "kavita" was not hiding correctly on small viewports - Fixed search bar to make the behavior more consistent - Fixed accordion buttons - Changed accordion buttons to be more responsive - Added radio button colors - Fixed radios on theme test page - Changed login and reset password card layouts to be more consistent. - Added primary color shade for when darker shading is needed. * Built a basic site, allow the user to apply different themes, refactored nav service code out. * Implemented the ability update a user's theme * Added unit tests for Scan and Get Content in SiteThemeService. * Fixed a bug in the login code and Pref code which wasn't joining on SiteTheme table. Wrote Unit tests and the UI component to manage current theme. * Implemented scan so that it manages custom themes with unit tests * Component updates - Repositioning style ordering - Adding indicator override - Adding select styles * SignlaR integration, some fixes when creating custom entities, one single migration. Just login functionality left. * More ui updated - Added .no-hover to prevent hover on elements where not needed - Changed all selects I could find to appropriate class - Changed up nav tabs to work more like bootstrap tabs than pills - Added padding to top of some containers to make styles consistent - Added ability to change navbar fontawesome icon colors - removed some unecessary inline styling - Changed radio button to appropriate class - Toned down primate color, a bit too bright for dark theme. - Added ability to change button fontawesome icon color * nav-tab fix for series-detail * Added themes folder to gitignore * Adding card overlay * Fixing up light theme * Everything is done. Only bug is that color-scheme isn't being set properly from css variable. * Checkboxes have pointer by default. Confirm/Confirm email use default (dark) theme by default * Fixed an error where color-scheme wasn't reflecting correctly on themes on first load * Fixed user preferences not available on login * Changing dual radios to switches and color tweaks * disabled primary APCA fix * button APCA fixes * Fixed some timing issues with first load and image service * Fixed swiper issues from upgrade * Changed themes to be scss files again and adjusted Seed code * Migrated carousel to css variables. Fixed a broken animation for search. * Cleaned up some backend smells * Fixed white border outline on nav tabs, added some variables for header * Nav bar has been css variable-ified * Added some basic eink stuff to make the app useable Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
195 lines
8.7 KiB
TypeScript
195 lines
8.7 KiB
TypeScript
import { Component, OnDestroy, OnInit } from '@angular/core';
|
|
import { FormControl, FormGroup, Validators } from '@angular/forms';
|
|
import { ToastrService } from 'ngx-toastr';
|
|
import { take } from 'rxjs/operators';
|
|
import { Options } from '@angular-slider/ngx-slider';
|
|
import { Title } from '@angular/platform-browser';
|
|
import { BookService } from 'src/app/book-reader/book.service';
|
|
import { readingDirections, scalingOptions, pageSplitOptions, readingModes, Preferences } from 'src/app/_models/preferences/preferences';
|
|
import { User } from 'src/app/_models/user';
|
|
import { AccountService } from 'src/app/_services/account.service';
|
|
import { NavService } from 'src/app/_services/nav.service';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
import { SettingsService } from 'src/app/admin/settings.service';
|
|
|
|
@Component({
|
|
selector: 'app-user-preferences',
|
|
templateUrl: './user-preferences.component.html',
|
|
styleUrls: ['./user-preferences.component.scss']
|
|
})
|
|
export class UserPreferencesComponent implements OnInit, OnDestroy {
|
|
|
|
readingDirections = readingDirections;
|
|
scalingOptions = scalingOptions;
|
|
pageSplitOptions = pageSplitOptions;
|
|
readingModes = readingModes;
|
|
|
|
settingsForm: FormGroup = new FormGroup({});
|
|
passwordChangeForm: FormGroup = new FormGroup({});
|
|
user: User | undefined = undefined;
|
|
isAdmin: boolean = false;
|
|
hasChangePasswordRole: boolean = false;
|
|
|
|
passwordsMatch = false;
|
|
resetPasswordErrors: string[] = [];
|
|
|
|
obserableHandles: Array<any> = [];
|
|
|
|
bookReaderLineSpacingOptions: Options = {
|
|
floor: 100,
|
|
ceil: 250,
|
|
step: 10,
|
|
};
|
|
bookReaderMarginOptions: Options = {
|
|
floor: 0,
|
|
ceil: 30,
|
|
step: 5,
|
|
};
|
|
bookReaderFontSizeOptions: Options = {
|
|
floor: 50,
|
|
ceil: 300,
|
|
step: 10,
|
|
};
|
|
fontFamilies: Array<string> = [];
|
|
|
|
tabs: Array<{title: string, fragment: string}> = [
|
|
{title: 'Preferences', fragment: ''},
|
|
{title: 'Bookmarks', fragment: 'bookmarks'},
|
|
{title: 'Password', fragment: 'password'},
|
|
{title: '3rd Party Clients', fragment: 'clients'},
|
|
{title: 'Theme', fragment: 'theme'},
|
|
];
|
|
active = this.tabs[0];
|
|
opdsEnabled: boolean = false;
|
|
makeUrl: (val: string) => string = (val: string) => {return this.transformKeyToOpdsUrl(val)};
|
|
|
|
constructor(private accountService: AccountService, private toastr: ToastrService, private bookService: BookService,
|
|
private navService: NavService, private titleService: Title, private route: ActivatedRoute, private settingsService: SettingsService) {
|
|
this.fontFamilies = this.bookService.getFontFamilies();
|
|
|
|
this.route.fragment.subscribe(frag => {
|
|
const tab = this.tabs.filter(item => item.fragment === frag);
|
|
if (tab.length > 0) {
|
|
this.active = tab[0];
|
|
} else {
|
|
this.active = this.tabs[0]; // Default to first tab
|
|
}
|
|
});
|
|
|
|
this.settingsService.getOpdsEnabled().subscribe(res => {
|
|
this.opdsEnabled = res;
|
|
});
|
|
}
|
|
|
|
ngOnInit(): void {
|
|
this.titleService.setTitle('Kavita - User Preferences');
|
|
this.accountService.currentUser$.pipe(take(1)).subscribe((user) => {
|
|
if (user) {
|
|
this.user = user;
|
|
this.isAdmin = this.accountService.hasAdminRole(user);
|
|
this.hasChangePasswordRole = this.accountService.hasChangePasswordRole(user);
|
|
|
|
if (this.fontFamilies.indexOf(this.user.preferences.bookReaderFontFamily) < 0) {
|
|
this.user.preferences.bookReaderFontFamily = 'default';
|
|
}
|
|
|
|
this.settingsForm.addControl('readingDirection', new FormControl(user.preferences.readingDirection, []));
|
|
this.settingsForm.addControl('scalingOption', new FormControl(user.preferences.scalingOption, []));
|
|
this.settingsForm.addControl('pageSplitOption', new FormControl(user.preferences.pageSplitOption, []));
|
|
this.settingsForm.addControl('autoCloseMenu', new FormControl(user.preferences.autoCloseMenu, []));
|
|
this.settingsForm.addControl('readerMode', new FormControl(user.preferences.readerMode, []));
|
|
this.settingsForm.addControl('bookReaderDarkMode', new FormControl(user.preferences.bookReaderDarkMode, []));
|
|
this.settingsForm.addControl('bookReaderFontFamily', new FormControl(user.preferences.bookReaderFontFamily, []));
|
|
this.settingsForm.addControl('bookReaderFontSize', new FormControl(user.preferences.bookReaderFontSize, []));
|
|
this.settingsForm.addControl('bookReaderLineSpacing', new FormControl(user.preferences.bookReaderLineSpacing, []));
|
|
this.settingsForm.addControl('bookReaderMargin', new FormControl(user.preferences.bookReaderMargin, []));
|
|
this.settingsForm.addControl('bookReaderReadingDirection', new FormControl(user.preferences.bookReaderReadingDirection, []));
|
|
this.settingsForm.addControl('bookReaderTapToPaginate', new FormControl(!!user.preferences.bookReaderTapToPaginate, []));
|
|
|
|
this.settingsForm.addControl('theme', new FormControl(user.preferences.theme, []));
|
|
}
|
|
});
|
|
|
|
this.passwordChangeForm.addControl('password', new FormControl('', [Validators.required]));
|
|
this.passwordChangeForm.addControl('confirmPassword', new FormControl('', [Validators.required]));
|
|
|
|
this.obserableHandles.push(this.passwordChangeForm.valueChanges.subscribe(() => {
|
|
const values = this.passwordChangeForm.value;
|
|
this.passwordsMatch = values.password === values.confirmPassword;
|
|
}));
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
this.obserableHandles.forEach(o => o.unsubscribe());
|
|
}
|
|
|
|
public get password() { return this.passwordChangeForm.get('password'); }
|
|
public get confirmPassword() { return this.passwordChangeForm.get('confirmPassword'); }
|
|
|
|
resetForm() {
|
|
if (this.user === undefined) { return; }
|
|
this.settingsForm.get('readingDirection')?.setValue(this.user.preferences.readingDirection);
|
|
this.settingsForm.get('scalingOption')?.setValue(this.user.preferences.scalingOption);
|
|
this.settingsForm.get('autoCloseMenu')?.setValue(this.user.preferences.autoCloseMenu);
|
|
this.settingsForm.get('readerMode')?.setValue(this.user.preferences.readerMode);
|
|
this.settingsForm.get('pageSplitOption')?.setValue(this.user.preferences.pageSplitOption);
|
|
this.settingsForm.get('bookReaderDarkMode')?.setValue(this.user.preferences.bookReaderDarkMode);
|
|
this.settingsForm.get('bookReaderFontFamily')?.setValue(this.user.preferences.bookReaderFontFamily);
|
|
this.settingsForm.get('bookReaderFontSize')?.setValue(this.user.preferences.bookReaderFontSize);
|
|
this.settingsForm.get('bookReaderLineSpacing')?.setValue(this.user.preferences.bookReaderLineSpacing);
|
|
this.settingsForm.get('bookReaderMargin')?.setValue(this.user.preferences.bookReaderMargin);
|
|
this.settingsForm.get('bookReaderTapToPaginate')?.setValue(this.user.preferences.bookReaderTapToPaginate);
|
|
this.settingsForm.get('bookReaderReadingDirection')?.setValue(this.user.preferences.bookReaderReadingDirection);
|
|
this.settingsForm.get('theme')?.setValue(this.user.preferences.theme);
|
|
}
|
|
|
|
resetPasswordForm() {
|
|
this.passwordChangeForm.get('password')?.setValue('');
|
|
this.passwordChangeForm.get('confirmPassword')?.setValue('');
|
|
this.resetPasswordErrors = [];
|
|
}
|
|
|
|
save() {
|
|
if (this.user === undefined) return;
|
|
const modelSettings = this.settingsForm.value;
|
|
const data: Preferences = {
|
|
readingDirection: parseInt(modelSettings.readingDirection, 10),
|
|
scalingOption: parseInt(modelSettings.scalingOption, 10),
|
|
pageSplitOption: parseInt(modelSettings.pageSplitOption, 10),
|
|
autoCloseMenu: modelSettings.autoCloseMenu,
|
|
readerMode: parseInt(modelSettings.readerMode),
|
|
bookReaderDarkMode: modelSettings.bookReaderDarkMode,
|
|
bookReaderFontFamily: modelSettings.bookReaderFontFamily,
|
|
bookReaderLineSpacing: modelSettings.bookReaderLineSpacing,
|
|
bookReaderFontSize: modelSettings.bookReaderFontSize,
|
|
bookReaderMargin: modelSettings.bookReaderMargin,
|
|
bookReaderTapToPaginate: modelSettings.bookReaderTapToPaginate,
|
|
bookReaderReadingDirection: parseInt(modelSettings.bookReaderReadingDirection, 10),
|
|
theme: modelSettings.theme
|
|
};
|
|
this.obserableHandles.push(this.accountService.updatePreferences(data).subscribe((updatedPrefs) => {
|
|
this.toastr.success('Server settings updated');
|
|
if (this.user) {
|
|
this.user.preferences = updatedPrefs;
|
|
}
|
|
this.resetForm();
|
|
}));
|
|
}
|
|
|
|
savePasswordForm() {
|
|
if (this.user === undefined) { return; }
|
|
|
|
const model = this.passwordChangeForm.value;
|
|
this.resetPasswordErrors = [];
|
|
this.obserableHandles.push(this.accountService.resetPassword(this.user?.username, model.confirmPassword).subscribe(() => {
|
|
this.toastr.success('Password has been updated');
|
|
this.resetPasswordForm();
|
|
}, err => {
|
|
this.resetPasswordErrors = err;
|
|
}));
|
|
}
|
|
|
|
transformKeyToOpdsUrl(key: string) {
|
|
return `${location.origin}/api/opds/${key}`;
|
|
}
|
|
}
|