Skip to content

Commit

Permalink
Add User, Project and Group classes (#481)
Browse files Browse the repository at this point in the history
* create Group class

* create Project class

* create User class

* add static typing

* add static typing

* fix static typing

* fix static typing

* fix typing

* remove redundancies

* fix projects.components.ts

Co-authored-by: mboudet <[email protected]>

* fix projects.component.ts

Co-authored-by: mboudet <[email protected]>

* fix typo

Co-authored-by: mboudet <[email protected]>

* bring back missing_group in user.component

---------

Co-authored-by: mboudet <[email protected]>
  • Loading branch information
rsiminel and mboudet authored Oct 25, 2024
1 parent d0fd1c4 commit d69db2f
Show file tree
Hide file tree
Showing 38 changed files with 593 additions and 536 deletions.
3 changes: 2 additions & 1 deletion manager2/src/app/admin/adminplugin/adminplugin.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { PluginService } from 'src/app/plugin/plugin.service';
import { AuthService } from 'src/app/auth/auth.service';
import { User } from '../../user/user.service';

@Component({
selector: 'app-adminplugin',
Expand All @@ -11,7 +12,7 @@ import { AuthService } from 'src/app/auth/auth.service';
export class AdminpluginComponent implements OnInit {

pluginId: string
user: any
user: User

constructor(
private route: ActivatedRoute,
Expand Down
28 changes: 9 additions & 19 deletions manager2/src/app/admin/databases/databases.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { Database, DatabaseService } from 'src/app/user/database.service';
import { UserService } from 'src/app/user/user.service';
import { User, UserService } from 'src/app/user/user.service';

import { Table } from 'primeng/table';

Expand All @@ -13,17 +13,17 @@ export class DatabasesComponent implements OnInit {
@ViewChild('dtp') table: Table;

db: Database
owner_db_name: any
owner_db_owner: any
owner_db_name: Database
owner_db_owner: User
chowner_msg: string
chowner_err_msg: string

databases: Database[]
users: any
users: User[]
selecteddb: Database[]

requests_visible: boolean
pending_databases: any
pending_databases: Database[]
pending_number: number

msg: string
Expand All @@ -42,7 +42,7 @@ export class DatabasesComponent implements OnInit {


ngOnInit() {
this.db = new Database('', 'mysql', '', '', false, "", "", 0, true);
this.db = new Database();
this.db_list();
this.userService.list().subscribe(
resp => { this.users = resp; },
Expand Down Expand Up @@ -99,7 +99,7 @@ export class DatabasesComponent implements OnInit {
this.dbService.declare(this.db).subscribe(
resp => {
this.msg = resp['message'];
this.db = new Database('', 'mysql', '', '', false, "", "", 0, true);
this.db = new Database();
this.dbService.list().subscribe(
resp => { this.databases = resp; },
err => { console.log('failed to list databases'); }
Expand All @@ -122,7 +122,7 @@ export class DatabasesComponent implements OnInit {
if (data.length > 0) {
this.requests_visible = true;
for (let i = 0; i < data.length; i++) {
data[i].created_at = parseInt(data[i]['_id'].substring(0, 8), 16) * 1000;
data[i].created_at = parseInt(data[i]._id.substring(0, 8), 16) * 1000;
}
}
this.pending_number = data.length;
Expand Down Expand Up @@ -164,17 +164,7 @@ export class DatabasesComponent implements OnInit {
for (var i = 0; i < this.selecteddb.length; i++) {
this.dbmsg='';
this.dbmsg_error='';
this.dbService.create(new Database(
this.selecteddb[i].name,
this.selecteddb[i].type,
this.selecteddb[i].host,
this.selecteddb[i].owner,
this.selecteddb[i].create,
this.selecteddb[i].usage,
this.selecteddb[i].size,
this.selecteddb[i].expire,
this.selecteddb[i].single_user
)).subscribe(
this.dbService.create(this.selecteddb[i]).subscribe(
resp => {
this.dbmsg = resp['message'];
},
Expand Down
4 changes: 2 additions & 2 deletions manager2/src/app/admin/groups/groups.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ <h5>Group members</h5>
<tr>
<td><a routerLink="/user/{{user.uid}}"><span class="p-button p-button-sm p-button-primary">{{user.uid}}</span></a></td>
<td>{{user.email}}</td>
<td><span *ngIf="user.authorized">x</span></td>
<td><span *ngIf="user.temp?.authorized">x</span></td>
<td><span *ngIf="user.group == selectedGroup.name">x</span></td>
</tr>
</ng-template>
</p-table>
</div>
<button class="p-button p-button-sm p-button-danger" (click)="delete_group(selectedGroup)">Delete</button>
<button class="p-button p-button-sm p-button-danger" (click)="delete_group()">Delete</button>
</div>
</div>
</div>
Expand Down
28 changes: 13 additions & 15 deletions manager2/src/app/admin/groups/groups.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { GroupsService } from './groups.service';
import { ProjectsService } from 'src/app/admin/projects/projects.service';
import { Group, GroupsService } from './groups.service';
import { Project, ProjectsService } from 'src/app/admin/projects/projects.service';
import { User } from '../../user/user.service';

import { Table } from 'primeng/table';

Expand All @@ -19,23 +20,19 @@ export class GroupsComponent implements OnInit {
rm_grp_err_msg: string
msg: string

selectedGroup: any
new_group: any
selectedGroup: Group
new_group: Group

projects: any[]
groups: any[]
users: any[]
projects: Project[]
groups: Group[]
users: User[]

constructor(
private groupsService: GroupsService,
private projectsService: ProjectsService
) {
this.selectedGroup = null;
this.new_group = {
name: '',
owner: '',
description: '',
}
this.new_group = new Group();
this.projects = [];
this.groups = [];
this.users = [];
Expand Down Expand Up @@ -81,7 +78,7 @@ export class GroupsComponent implements OnInit {
)
}

delete_group(group){
delete_group(){
this.groupsService.delete(this.selectedGroup.name).subscribe(
resp => {
this.groupsService.list().subscribe(
Expand Down Expand Up @@ -117,7 +114,8 @@ export class GroupsComponent implements OnInit {
)
}

show_group_users(group) {
show_group_users(input_group: any) {
const group: Group = this.groupsService.mapToGroup(input_group);
this.msg = '';
this.rm_grp_err_msg = '';
this.rm_grp_msg_ok = '';
Expand All @@ -138,7 +136,7 @@ export class GroupsComponent implements OnInit {
}
}
}
this.users[i].authorized = is_authorized;
this.users[i].temp = { ...this.users[i].temp, 'authorized': is_authorized };
}
},
err => console.log('failed to get users in group', group)
Expand Down
55 changes: 46 additions & 9 deletions manager2/src/app/admin/groups/groups.service.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../../../environments/environment';
import { User, UserService } from 'src/app/user/user.service';
import { AuthService } from '../../auth/auth.service';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

export class Group {
gid: string
name: string
owner: string
description: string
tags: string[]
new: boolean

constructor(
gid: string = '', name: string = '', owner: string = '',
description: string = '', tags: string[] = null, is_new: boolean = false
) {
this.gid = gid; this.name = name; this.owner = owner;
this.description = description; this.tags = tags; this.new = is_new;
}
}

@Injectable({
providedIn: 'root'
})
export class GroupsService {

constructor(private http: HttpClient, private authService: AuthService) { }
constructor(
private http: HttpClient,
private authService: AuthService,
private userService: UserService
) { }

mapToGroup(resp: any): Group {
return new Group(
resp.gid || '', resp.name || '', resp.owner || '',
resp.description || '', resp.tags || null, resp.new || false
);
}


list(): Observable<any[]> {
list(): Observable<Group[]> {
// let user = this.authService.profile;
let httpOptions = {
//headers: new HttpHeaders({
Expand All @@ -25,13 +54,16 @@ export class GroupsService {
environment.apiUrl + '/group',
httpOptions
).pipe(map((response: any[]) => {
return response.sort(function (a,b) {
response.sort(function (a,b) {
return a.name.localeCompare(b.name);
});
return response.map(item => {
return this.mapToGroup(item);
});
}));
}

get(groupId): Observable<any> {
get(groupId: string): Observable<User[]> {
// let user = this.authService.profile;
let httpOptions = {
//headers: new HttpHeaders({
Expand All @@ -41,10 +73,14 @@ export class GroupsService {
return this.http.get(
environment.apiUrl + '/group/' + groupId,
httpOptions
);
).pipe(map((response: any[]) => {
return response.map(item => {
return this.userService.mapToUser(item);
});
}));
}

update(group) {
update(group: Group) {
// let user = this.authService.profile;
let httpOptions = {
//headers: new HttpHeaders({
Expand All @@ -58,7 +94,7 @@ export class GroupsService {
);
}

delete(groupId) {
delete(groupId: string) {
// let user = this.authService.profile;
let httpOptions = {
//headers: new HttpHeaders({
Expand All @@ -68,9 +104,10 @@ export class GroupsService {
return this.http.delete(
environment.apiUrl + '/group/' + groupId,
httpOptions
); }
);
}

add(group) {
add(group: Group) {
// let user = this.authService.profile;
let httpOptions = {
//headers: new HttpHeaders({
Expand Down
2 changes: 1 addition & 1 deletion manager2/src/app/admin/logs/logs.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h3>Event logs</h3>
<tr>
<td (class)="get_status(log.status)">{{log._id}}</td>
<td>{{log.owner}}</td>
<td>{{date_convert(log.date)}}</td>
<td>{{log.date | date}}</td>
<td>{{log.action}}</td>
<td>
<span *ngFor="let event of log.logs">
Expand Down
12 changes: 0 additions & 12 deletions manager2/src/app/admin/logs/logs.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,6 @@ export class LogsComponent implements OnInit {
return (n < 10 ? '0' : '') + n;
}

date_convert = function timeConverter(tsp){
let res;
try {
var a = new Date(tsp);
res = a.toISOString().substring(0, 10);
}
catch (e) {
res = '';
}
return res;
}

getLogs(): Observable<any> {
//let user = this.authService.profile;
let httpOptions = {
Expand Down
8 changes: 4 additions & 4 deletions manager2/src/app/admin/project/project.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h4>Project <strong>{{project.id}}</strong></h4>
</div>
<div class="col-sm-3" >
<button class="p-button p-button-sm p-button-danger" (click)="delete_project(project, users)">Delete project</button>
<button class="p-button p-button-sm p-button-danger" (click)="delete_project()">Delete project</button>
</div>
</div>
</div>
Expand Down Expand Up @@ -45,7 +45,7 @@ <h4>Project <strong>{{project.id}}</strong></h4>
</div>
<div class="col-sm-2">
<label for="update_project_exp">Expiration date</label>
<input type="date" id="update_project_exp" [ngModelOptions]="{standalone: true}" [(ngModel)]="project.expire" class="form-control"/>
<input type="date" id="update_project_exp" [ngModelOptions]="{standalone: true}" [(ngModel)]="project_expire" class="form-control"/>
</div>
<div class="col-sm-2">
<label >Financing</label>
Expand Down Expand Up @@ -76,7 +76,7 @@ <h4>Project <strong>{{project.id}}</strong></h4>
<div class="form-group row">
<div class="col-sm-2">
<label style="opacity: 0;">Update project</label>
<button type="button" class="p-button p-button-sm p-button-success" (click)="update_project(project)">Update project</button>
<button type="button" class="p-button p-button-sm p-button-success" (click)="update_project()">Update project</button>
</div>
</div>
</form>
Expand Down Expand Up @@ -127,7 +127,7 @@ <h4>Project <strong>{{project.id}}</strong></h4>
<tr>
<td><a routerLink="/user/{{user_l.uid}}"><span class="p-button p-button-sm p-button-primary">{{user_l.uid}}</span></a></td>
<td>{{user_l.email}}</td>
<td><span *ngIf="user_l.access">x</span></td>
<td><span *ngIf="user_l.temp?.access">x</span></td>
<td><span *ngIf="user_l.uid === project.owner">x</span></td>
</tr>
</ng-template>
Expand Down
Loading

0 comments on commit d69db2f

Please sign in to comment.