Added all setting's group (except add user to group)

This commit is contained in:
2026-04-26 17:08:11 +01:00
parent 4dbf052437
commit 4e9a4cf428
12 changed files with 278 additions and 0 deletions
@@ -0,0 +1,152 @@
import {Component, computed, inject, input, OnInit, signal} from '@angular/core';
import {GetGroupDetailsDto, GroupsService} from "../../services/api";
import {addIcons} from "ionicons";
import {peopleOutline, banOutline, arrowUpCircleOutline} from "ionicons/icons";
import {IonicModule, LoadingController, ToastController} from "@ionic/angular";
import moment from 'moment';
import {TitlePartComponent} from "../title-part/title-part.component";
import {firstValueFrom} from "rxjs";
import {PipeComponent} from "../pipe/pipe.component";
addIcons({
'avatars': peopleOutline,
'ban': banOutline,
'arrow-up-circle-outline': arrowUpCircleOutline,
})
@Component({
selector: 'app-group-info',
templateUrl: './group-info.component.html',
styleUrls: ['./group-info.component.scss'],
imports: [
IonicModule,
TitlePartComponent,
PipeComponent
]
})
export class GroupInfoComponent implements OnInit {
private groupsService = inject(GroupsService);
private toastCtrl = inject(ToastController);
private loadCtrl = inject(LoadingController);
groupSelected = input.required<GetGroupDetailsDto>();
group = signal<GetGroupDetailsDto>({});
date = computed<string>(() => moment(this.group().creationDate).format('DD/MM/YYYY'));
options = [1, 2, 3];
ngOnInit() {
this.group.set(this.groupSelected());
}
async deleteUser(id: number) {
const loading = await this.loadCtrl.create({
message: 'Suppression...',
spinner: 'lines-sharp-small'
});
await loading.present();
try {
await firstValueFrom(this.groupsService.deleteUserFromGroupEndpoint(this.group().id, id));
this.group.update(x => ({
...x,
users: x.users.filter(u => u.id != id)
}));
const toast = await this.toastCtrl.create({
message: 'Utilisateur retiré du groupe',
duration: 2000,
color: 'success'
});
await toast.present();
} catch (e) {
const toast = await this.toastCtrl.create({
message: 'Vous devez être administrateur pour faire cela',
duration: 2000,
color: 'danger'
});
await toast.present();
}
await loading.dismiss();
}
async leaveGroup(){
const loading = await this.loadCtrl.create({
message: 'Chargement...',
spinner: 'lines-sharp-small'
});
await loading.present();
try {
await firstValueFrom(this.groupsService.leaveGroupEndpoint(this.group().id));
const toast = await this.toastCtrl.create({
message: 'Vous avez quitter ce groupe',
duration: 2000,
color: 'success'
});
await toast.present();
} catch {
const toast = await this.toastCtrl.create({
message: 'Impossible de quitter le groupe',
duration: 2000,
color: 'danger'
});
await toast.present();
}
await loading.dismiss();
}
addToGroup(){}
async deleteGroup(){
const loading = await this.loadCtrl.create({
message: 'Suppression...',
spinner: 'lines-sharp-small'
});
await loading.present();
try {
await firstValueFrom(this.groupsService.deleteGroupEndpoint(this.group().id));
const toast = await this.toastCtrl.create({
message: 'Groupe supprimé',
duration: 2000,
color: 'success'
});
await toast.present();
} catch (e) {
const toast = await this.toastCtrl.create({
message: 'Vous devez être administrateur pour faire cela',
duration: 2000,
color: 'danger'
});
await toast.present();
}
await loading.dismiss();
}
async promoteUser(id: number){
const loading = await this.loadCtrl.create({
message: 'Promotion...',
spinner: 'lines-sharp-small'
});
await loading.present();
try {
const group = await firstValueFrom(this.groupsService.patchGroupUserRoleEndpoint(this.group().id, id));
this.group.set(group);
const toast = await this.toastCtrl.create({
message: 'Utilisateur promu avec succès',
duration: 2000,
color: 'success'
});
await toast.present();
} catch (e) {
const toast = await this.toastCtrl.create({
message: 'Vous devez être administrateur pour faire cela',
duration: 2000,
color: 'danger'
});
await toast.present();
}
await loading.dismiss();
}
}