From fb0bac6bb801ff7b017ae18fe3c0ad74eb6853ac Mon Sep 17 00:00:00 2001 From: remy siminel Date: Wed, 18 Dec 2024 14:18:21 +0100 Subject: [PATCH] fixes --- .../src/app/admin/group/group.component.ts | 132 ++++++++++-------- .../src/app/admin/groups/groups.component.ts | 13 +- manager2/src/app/app-routing.module.ts | 6 +- 3 files changed, 83 insertions(+), 68 deletions(-) diff --git a/manager2/src/app/admin/group/group.component.ts b/manager2/src/app/admin/group/group.component.ts index f04e5ad7..924b0fc7 100644 --- a/manager2/src/app/admin/group/group.component.ts +++ b/manager2/src/app/admin/group/group.component.ts @@ -6,70 +6,88 @@ import { User } from "../../user/user.service"; import { Table } from "primeng/table"; @Component({ - selector: "app-groups", - templateUrl: "./group.component.html", - // styleUrls: ['./group.component.css'] + selector: "app-groups", + templateUrl: "./group.component.html" + // styleUrls: ['./group.component.css'] }) export class GroupComponent implements OnInit { - @ViewChild("dtg") tableGroups: Table; - @ViewChild("dtu") tableUsers: Table; + @ViewChild("dtg") tableGroups: Table; + @ViewChild("dtu") tableUsers: Table; - msg: string; - err_msg: string; - del_err_msg: string; - group: Group; - projects: Project[]; - users: User[]; + msg: string; + err_msg: string; + del_err_msg: string; + group: Group; + projects: Project[]; + users: User[]; - constructor( - private route: ActivatedRoute, - private router: Router, - private groupsService: GroupsService, - private projectsService: ProjectsService - ) { - this.group = new Group(); - this.projects = null; - this.users = null; - } + constructor( + private route: ActivatedRoute, + private router: Router, + private groupsService: GroupsService, + private projectsService: ProjectsService + ) { + this.group = new Group(); + this.projects = null; + this.users = null; + } - ngOnDestroy(): void {} + ngOnDestroy(): void {} - ngAfterViewInit(): void {} + ngAfterViewInit(): void {} - ngOnInit() { - this.route.params.subscribe((params) => { - let group_name = params.id; - this.groupsService.get(group_name).subscribe( - (resp) => (this.group = resp), - (err) => console.log("failed to get group") - ); - this.projectsService.getProjectsInGroup(group_name).subscribe( - (resp) => (this.projects = resp), - (err) => console.log("failed to get projects in group") - ); - this.groupsService.getUsers(group_name).subscribe( - (resp) => (this.users = resp), - (err) => console.log("failed to get group's users") - ); - }); - } + ngOnInit() { + this.deleteGroup = this.deleteGroup.bind(this); + this.route.params.subscribe((params) => { + let group_name = params.id; + this.groupsService.get(group_name).subscribe( + (group) => (this.group = group), + (err) => console.log("failed to get group") + ); + this.projectsService.getProjectsInGroup(group_name).subscribe( + (project_list) => (this.projects = project_list), + (err) => console.log("failed to get projects in group") + ); + this.groupsService.getUsers(group_name).subscribe( + (user_list) => { + this.users = user_list; + for (var i = 0; i < user_list.length; i++) { + var is_authorized = false; + if (user_list[i].projects) { + for (var j = 0; j < this.projects.length; j++) { + if (user_list[i].projects.indexOf(this.projects[j].id) >= 0) { + is_authorized = true; + break; + } + } + } + this.users[i].temp = { + ...this.users[i].temp, + authorized: is_authorized + }; + } + }, + (err) => console.log("failed to get group's users") + ); + }); + } - deleteGroup() { - this.groupsService.delete(this.group.name).subscribe( - (resp) => - this.router.navigate(["/admin/group"], { - queryParams: { deleted: "ok" }, - }), - (err) => (this.del_err_msg = err.error.message) - ); - } + deleteGroup() { + this.groupsService.delete(this.group.name).subscribe( + (resp) => + this.router.navigate(["/admin/group"], { + queryParams: { deleted: "ok" } + }), + (err) => (this.del_err_msg = err.error.message) + ); + } - updateGroup() { - this.msg = ""; - this.err_msg = ""; - this.groupsService.update(this.group).subscribe( - (resp) => (this.msg = "Group updated"), - (err) => (this.err_msg = err.error.message) - ); - } + updateGroup() { + this.msg = ""; + this.err_msg = ""; + this.groupsService.update(this.group).subscribe( + (resp) => (this.msg = "Group updated"), + (err) => (this.err_msg = err.error.message) + ); + } } diff --git a/manager2/src/app/admin/groups/groups.component.ts b/manager2/src/app/admin/groups/groups.component.ts index 817ace63..811ec5fb 100644 --- a/manager2/src/app/admin/groups/groups.component.ts +++ b/manager2/src/app/admin/groups/groups.component.ts @@ -2,7 +2,6 @@ import { Component, OnInit, ViewChild } from '@angular/core'; import { Group, GroupsService } from './groups.service'; import { ActivatedRoute } from '@angular/router'; import { User } from '../../user/user.service'; - import { Table } from 'primeng/table'; @Component({ @@ -42,18 +41,16 @@ export class GroupsComponent implements OnInit { ngOnInit() { this.route.queryParams .subscribe(params => { - if (params.deleted == "ok") { - this.notification = "Project was deleted successfully"; + if (params.deleted == 'ok') { + this.notification = 'Group was deleted successfully'; }; }); this.listGroups(); } - addGroup(){ - this.notification = ""; - if (this.new_group.name === '') { - return; - } + addGroup() { + this.notification = ''; + if (this.new_group.name === '') { return; } this.err_msg = ''; this.success_msg = ''; this.groupsService.add(this.new_group).subscribe( diff --git a/manager2/src/app/app-routing.module.ts b/manager2/src/app/app-routing.module.ts index a1fa7fc1..d87e1216 100644 --- a/manager2/src/app/app-routing.module.ts +++ b/manager2/src/app/app-routing.module.ts @@ -9,9 +9,9 @@ import { RegisterComponent } from './auth/register/register.component'; import { LogoutComponent } from './auth/logout/logout.component'; import { TpsComponent } from './tps/tps.component'; import { ProjectComponent } from './project/project.component'; -import { DatabasesComponent as AdminDatabaseComponent} from './admin/databases/databases.component'; -import { GroupsComponent as AdminGroupsComponent} from './admin/groups/groups.component'; -import { GroupComponent as AdminGroupComponent} from './admin/group/group.component'; +import { DatabasesComponent as AdminDatabaseComponent } from './admin/databases/databases.component'; +import { GroupsComponent as AdminGroupsComponent } from './admin/groups/groups.component'; +import { GroupComponent as AdminGroupComponent } from './admin/group/group.component'; import { LogsComponent as AdminLogComponent} from './admin/logs/logs.component'; import { MessagesComponent as AdminMessageComponent} from './admin/messages/messages.component'; import { ProjectsComponent as AdminProjectsComponent} from './admin/projects/projects.component';