wip ref(core): ProfileGroup avoid direct config interraction outside of profiles.services

This commit is contained in:
Clem Fern
2023-07-23 18:14:55 +02:00
parent 1903ec5995
commit 8e9156e250
3 changed files with 56 additions and 16 deletions

View File

@@ -36,7 +36,7 @@ export class EditProfileModalComponent<P extends Profile> {
private modalInstance: NgbActiveModal,
) {
if (!this.defaultsMode) {
this.profilesService.getProfileGroups().then(groups => {
this.profilesService.getProfileGroups().then(groups => {
this.groups = groups
this.profileGroup = groups.find(g => g.id === this.profile.group)
})
@@ -97,9 +97,9 @@ export class EditProfileModalComponent<P extends Profile> {
if (typeof this.profileGroup === 'string') {
const newGroup: PartialProfileGroup<ProfileGroup> = {
id: uuidv4(),
name: this.profileGroup
name: this.profileGroup,
}
this.groups.push(newGroup)
this.profilesService.writeProfileGroup(newGroup, false)
this.profileGroup = newGroup
}
this.profile.group = this.profileGroup.id

View File

@@ -167,7 +167,7 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
const result = await modal.result
if (result) {
group.name = result.value
await this.config.save()
await this.profilesService.writeProfileGroup(group)
}
}
@@ -184,7 +184,8 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
cancelId: 1,
},
)).response === 0) {
if ((await this.platform.showMessageBox(
let deleteProfiles = false
if ((group.profiles?.length ?? 0) > 0 && (await this.platform.showMessageBox(
{
type: 'warning',
message: this.translate.instant('Delete the group\'s profiles?'),
@@ -195,14 +196,11 @@ export class ProfilesSettingsTabComponent extends BaseComponent {
defaultId: 0,
cancelId: 0,
},
)).response === 0) {
for (const profile of this.profiles.filter(x => x.group === group.id)) {
delete profile.group
}
} else {
this.config.store.profiles = this.config.store.profiles.filter(x => x.group !== group.id)
)).response !== 0) {
deleteProfiles = true
}
await this.config.save()
await this.profilesService.deleteProfileGroup(group, true, deleteProfiles)
}
}