mirror of
https://github.com/Eugeny/tabby
synced 2025-03-04 15:17:17 +00:00
wip ref(core): move group collapsed status into profileSettingsTab
This commit is contained in:
parent
1c06a510bd
commit
44c449bd4c
3 changed files with 34 additions and 21 deletions
|
@ -37,7 +37,6 @@ export interface ProfileGroup {
|
||||||
profiles: PartialProfile<Profile>[]
|
profiles: PartialProfile<Profile>[]
|
||||||
defaults: any
|
defaults: any
|
||||||
editable: boolean
|
editable: boolean
|
||||||
collapsed: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PartialProfileGroup<T extends ProfileGroup> = Omit<Omit<{
|
export type PartialProfileGroup<T extends ProfileGroup> = Omit<Omit<{
|
||||||
|
|
|
@ -398,11 +398,9 @@ export class ProfilesService {
|
||||||
profiles = await this.getProfiles(includeNonUserGroup, true)
|
profiles = await this.getProfiles(includeNonUserGroup, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const profileGroupCollapsed = JSON.parse(window.localStorage.profileGroupCollapsed ?? '{}')
|
|
||||||
let groups: PartialProfileGroup<ProfileGroup>[] = deepClone(this.config.store.groups ?? [])
|
let groups: PartialProfileGroup<ProfileGroup>[] = deepClone(this.config.store.groups ?? [])
|
||||||
groups = groups.map(x => {
|
groups = groups.map(x => {
|
||||||
x.editable = true
|
x.editable = true
|
||||||
x.collapsed = profileGroupCollapsed[x.id] ?? false
|
|
||||||
|
|
||||||
if (includeProfiles) {
|
if (includeProfiles) {
|
||||||
x.profiles = profiles.filter(p => p.group === x.id)
|
x.profiles = profiles.filter(p => p.group === x.id)
|
||||||
|
@ -418,14 +416,12 @@ export class ProfilesService {
|
||||||
name: this.translate.instant('Built-in'),
|
name: this.translate.instant('Built-in'),
|
||||||
editable: false,
|
editable: false,
|
||||||
}
|
}
|
||||||
builtIn.collapsed = profileGroupCollapsed[builtIn.id] ?? false
|
|
||||||
|
|
||||||
const ungrouped: PartialProfileGroup<ProfileGroup> = {
|
const ungrouped: PartialProfileGroup<ProfileGroup> = {
|
||||||
id: 'ungrouped',
|
id: 'ungrouped',
|
||||||
name: this.translate.instant('Ungrouped'),
|
name: this.translate.instant('Ungrouped'),
|
||||||
editable: false,
|
editable: false,
|
||||||
}
|
}
|
||||||
ungrouped.collapsed = profileGroupCollapsed[ungrouped.id] ?? false
|
|
||||||
|
|
||||||
if (includeProfiles) {
|
if (includeProfiles) {
|
||||||
builtIn.profiles = profiles.filter(p => p.isBuiltin)
|
builtIn.profiles = profiles.filter(p => p.isBuiltin)
|
||||||
|
@ -470,7 +466,6 @@ export class ProfilesService {
|
||||||
async writeProfileGroup (group: PartialProfileGroup<ProfileGroup>, saveConfig = true): Promise<void> {
|
async writeProfileGroup (group: PartialProfileGroup<ProfileGroup>, saveConfig = true): Promise<void> {
|
||||||
delete group.profiles
|
delete group.profiles
|
||||||
delete group.editable
|
delete group.editable
|
||||||
delete group.collapsed
|
|
||||||
|
|
||||||
const cGroup = this.config.store.groups.find(g => g.id === group.id)
|
const cGroup = this.config.store.groups.find(g => g.id === group.id)
|
||||||
if (cGroup) {
|
if (cGroup) {
|
||||||
|
@ -508,13 +503,4 @@ export class ProfilesService {
|
||||||
return this.config.store.groups.find(g => g.id === groupId)?.name ?? ''
|
return this.config.store.groups.find(g => g.id === groupId)?.name ?? ''
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Save ProfileGroup collapse state in localStorage
|
|
||||||
*/
|
|
||||||
saveProfileGroupCollapse (group: PartialProfileGroup<ProfileGroup>): void {
|
|
||||||
const profileGroupCollapsed = JSON.parse(window.localStorage.profileGroupCollapsed ?? '{}')
|
|
||||||
profileGroupCollapsed[group.id] = group.collapsed
|
|
||||||
window.localStorage.profileGroupCollapsed = JSON.stringify(profileGroupCollapsed)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,10 @@ import { EditProfileModalComponent } from './editProfileModal.component'
|
||||||
_('Filter')
|
_('Filter')
|
||||||
_('Ungrouped')
|
_('Ungrouped')
|
||||||
|
|
||||||
|
interface CollapsableProfileGroup extends ProfileGroup {
|
||||||
|
collapsed: boolean
|
||||||
|
}
|
||||||
|
|
||||||
/** @hidden */
|
/** @hidden */
|
||||||
@Component({
|
@Component({
|
||||||
templateUrl: './profilesSettingsTab.component.pug',
|
templateUrl: './profilesSettingsTab.component.pug',
|
||||||
|
@ -16,7 +20,7 @@ _('Ungrouped')
|
||||||
export class ProfilesSettingsTabComponent extends BaseComponent {
|
export class ProfilesSettingsTabComponent extends BaseComponent {
|
||||||
builtinProfiles: PartialProfile<Profile>[] = []
|
builtinProfiles: PartialProfile<Profile>[] = []
|
||||||
templateProfiles: PartialProfile<Profile>[] = []
|
templateProfiles: PartialProfile<Profile>[] = []
|
||||||
profileGroups: PartialProfileGroup<ProfileGroup>[]
|
profileGroups: PartialProfileGroup<CollapsableProfileGroup>[]
|
||||||
filter = ''
|
filter = ''
|
||||||
Platform = Platform
|
Platform = Platform
|
||||||
|
|
||||||
|
@ -137,21 +141,22 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
async refresh (): Promise<void> {
|
async refresh (): Promise<void> {
|
||||||
|
const profileGroupCollapsed = JSON.parse(window.localStorage.profileGroupCollapsed ?? '{}')
|
||||||
const groups = await this.profilesService.getProfileGroups(true, true)
|
const groups = await this.profilesService.getProfileGroups(true, true)
|
||||||
groups.sort((a, b) => a.name.localeCompare(b.name))
|
groups.sort((a, b) => a.name.localeCompare(b.name))
|
||||||
groups.sort((a, b) => (a.id === 'built-in' ? 1 : 0) - (b.id === 'built-in' ? 1 : 0))
|
groups.sort((a, b) => (a.id === 'built-in' ? 1 : 0) - (b.id === 'built-in' ? 1 : 0))
|
||||||
groups.sort((a, b) => (a.id === 'ungrouped' ? 0 : 1) - (b.id === 'ungrouped' ? 0 : 1))
|
groups.sort((a, b) => (a.id === 'ungrouped' ? 0 : 1) - (b.id === 'ungrouped' ? 0 : 1))
|
||||||
this.profileGroups = groups
|
this.profileGroups = groups.map(g => ProfilesSettingsTabComponent.intoPartialCollapsableProfileGroup(g, profileGroupCollapsed[g.id] ?? false))
|
||||||
}
|
}
|
||||||
|
|
||||||
async editGroup (group: PartialProfileGroup<ProfileGroup>): Promise<void> {
|
async editGroup (group: PartialProfileGroup<CollapsableProfileGroup>): Promise<void> {
|
||||||
const modal = this.ngbModal.open(PromptModalComponent)
|
const modal = this.ngbModal.open(PromptModalComponent)
|
||||||
modal.componentInstance.prompt = this.translate.instant('New name')
|
modal.componentInstance.prompt = this.translate.instant('New name')
|
||||||
modal.componentInstance.value = group.name
|
modal.componentInstance.value = group.name
|
||||||
const result = await modal.result
|
const result = await modal.result
|
||||||
if (result) {
|
if (result) {
|
||||||
group.name = result.value
|
group.name = result.value
|
||||||
await this.profilesService.writeProfileGroup(group)
|
await this.profilesService.writeProfileGroup(ProfilesSettingsTabComponent.collapsableIntoPartialProfileGroup(group))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,9 +222,9 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
|
||||||
}[this.profilesService.providerForProfile(profile)?.id ?? ''] ?? 'warning'
|
}[this.profilesService.providerForProfile(profile)?.id ?? ''] ?? 'warning'
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleGroupCollapse (group: PartialProfileGroup<ProfileGroup>): void {
|
toggleGroupCollapse (group: PartialProfileGroup<CollapsableProfileGroup>): void {
|
||||||
group.collapsed = !group.collapsed
|
group.collapsed = !group.collapsed
|
||||||
this.profilesService.saveProfileGroupCollapse(group)
|
this.saveProfileGroupCollapse(group)
|
||||||
}
|
}
|
||||||
|
|
||||||
async editDefaults (provider: ProfileProvider<Profile>): Promise<void> {
|
async editDefaults (provider: ProfileProvider<Profile>): Promise<void> {
|
||||||
|
@ -261,4 +266,27 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
|
||||||
getQuickConnectProviders (): ProfileProvider<Profile>[] {
|
getQuickConnectProviders (): ProfileProvider<Profile>[] {
|
||||||
return this.profileProviders.filter(x => x.supportsQuickConnect)
|
return this.profileProviders.filter(x => x.supportsQuickConnect)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save ProfileGroup collapse state in localStorage
|
||||||
|
*/
|
||||||
|
private saveProfileGroupCollapse (group: PartialProfileGroup<CollapsableProfileGroup>): void {
|
||||||
|
const profileGroupCollapsed = JSON.parse(window.localStorage.profileGroupCollapsed ?? '{}')
|
||||||
|
profileGroupCollapsed[group.id] = group.collapsed
|
||||||
|
window.localStorage.profileGroupCollapsed = JSON.stringify(profileGroupCollapsed)
|
||||||
|
}
|
||||||
|
|
||||||
|
private static collapsableIntoPartialProfileGroup (group: PartialProfileGroup<CollapsableProfileGroup>): PartialProfileGroup<ProfileGroup> {
|
||||||
|
const g: any = { ...group }
|
||||||
|
delete g.collapsed
|
||||||
|
return g
|
||||||
|
}
|
||||||
|
|
||||||
|
private static intoPartialCollapsableProfileGroup (group: PartialProfileGroup<ProfileGroup>, collapsed: boolean): PartialProfileGroup<CollapsableProfileGroup> {
|
||||||
|
const collapsableGroup = {
|
||||||
|
...group,
|
||||||
|
collapsed,
|
||||||
|
}
|
||||||
|
return collapsableGroup
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue