group page cleanup

This commit is contained in:
Patrick Haßel 2024-10-29 11:58:12 +01:00
parent 63231e0181
commit 7dc4c3ca7c
7 changed files with 43 additions and 24 deletions

View File

@ -16,4 +16,8 @@ export class UserPublic {
); );
} }
static compareName(a: UserPublic, b: UserPublic) {
return a.name.localeCompare(b.name);
}
} }

View File

@ -15,6 +15,10 @@ export class Group {
// - // -
} }
isOwner(user: UserPublic) {
return this.owner.publicUuid === user.publicUuid;
}
static fromJson(json: any): Group { static fromJson(json: any): Group {
return new Group( return new Group(
validateString(json['uuid']), validateString(json['uuid']),
@ -31,5 +35,16 @@ export class Group {
return a.created.getTime() - b.created.getTime(); return a.created.getTime() - b.created.getTime();
} }
usersByNameOwnerFirst() {
return this.users.sort(this.compareOwnerFirstThenName);
}
private compareOwnerFirstThenName(a: UserPublic, b: UserPublic): number {
if (a.publicUuid === this.owner.publicUuid) {
return -1;
}
return UserPublic.compareName(a, b);
}
} }

View File

@ -1,16 +1,12 @@
import {UserPublic} from "../../User/UserPublic"; import {validateString} from "../../common/validators";
import {validateBoolean, validateDate, validateList, validateString} from "../../common/validators"; import {Group} from "../../group/Group";
export class Numbers { export class Numbers {
constructor( constructor(
readonly uuid: string, readonly uuid: string,
readonly title: string, readonly name: string,
readonly owner: UserPublic, readonly group: Group,
readonly created: Date,
readonly password: string,
readonly users: UserPublic[],
readonly initial: boolean,
) { ) {
// - // -
} }
@ -18,12 +14,8 @@ export class Numbers {
static fromJson(json: any): Numbers { static fromJson(json: any): Numbers {
return new Numbers( return new Numbers(
validateString(json['uuid']), validateString(json['uuid']),
validateString(json['title']), validateString(json['name']),
UserPublic.fromJson(json['owner']), Group.fromJson(json['group']),
validateDate(json['created']),
validateString(json['password']),
validateList(json['users'], UserPublic.fromJson),
validateBoolean(json['initial']),
); );
} }

View File

@ -19,14 +19,10 @@
<ng-container *ngIf="!userService.owns(group)"></ng-container> <ng-container *ngIf="!userService.owns(group)"></ng-container>
</td> </td>
</tr> </tr>
<tr>
<th>Besitzer</th>
<td class="user" (click)="userService.goto(group.owner)">{{ group.owner.name }}</td>
</tr>
<tr> <tr>
<th>Teilnehmer</th> <th>Teilnehmer</th>
<td> <td>
<div class="user" *ngFor="let user of group.users" (click)="userService.goto(user)">{{ user.name }}</div> <div class="user" [class.user_owner]="group.isOwner(user)" *ngFor="let user of group.usersByNameOwnerFirst()" (click)="userService.goto(user)">{{ user.name }}</div>
</td> </td>
</tr> </tr>
</table> </table>
@ -35,4 +31,5 @@
<ng-container *ngIf="uuid && !group && accessDenied"> <ng-container *ngIf="uuid && !group && accessDenied">
<h1>Passwort</h1> <h1>Passwort</h1>
<input type="text" [(ngModel)]="password" (keydown.enter)="join()"> <input type="text" [(ngModel)]="password" (keydown.enter)="join()">
<button (click)="join()">Beitreten</button>
</ng-container> </ng-container>

View File

@ -1 +1,5 @@
@import "../../../../common.less"; @import "../../../../common.less";
th {
text-align: left;
}

View File

@ -2,10 +2,10 @@ import {Component, OnInit} from '@angular/core';
import {DatePipe, NgForOf, NgIf} from "@angular/common"; import {DatePipe, NgForOf, NgIf} from "@angular/common";
import {FormsModule, ReactiveFormsModule} from "@angular/forms"; import {FormsModule, ReactiveFormsModule} from "@angular/forms";
import {TextComponent} from "../../../shared/text/text.component"; import {TextComponent} from "../../../shared/text/text.component";
import {Numbers} from "../../../api/tools/Numbers/Numbers";
import {ActivatedRoute, Router} from "@angular/router"; import {ActivatedRoute, Router} from "@angular/router";
import {GroupService} from "../../../api/group/GroupService"; import {GroupService} from "../../../api/group/GroupService";
import {UserService} from "../../../api/User/user.service"; import {UserService} from "../../../api/User/user.service";
import {Group} from "../../../api/group/Group";
@Component({ @Component({
selector: 'app-group', selector: 'app-group',
@ -23,7 +23,7 @@ import {UserService} from "../../../api/User/user.service";
}) })
export class GroupComponent implements OnInit { export class GroupComponent implements OnInit {
protected group: Numbers | null = null; protected group: Group | null = null;
protected uuid: string | null = null; protected uuid: string | null = null;
@ -56,7 +56,7 @@ export class GroupComponent implements OnInit {
}); });
} }
private setGroup(group: Numbers): void { private setGroup(group: Group): void {
this.group = group; this.group = group;
} }
@ -66,11 +66,11 @@ export class GroupComponent implements OnInit {
} }
} }
protected changeTitle(group: Numbers, title: string) { protected changeTitle(group: Group, title: string) {
this.groupService.changeTitle(group, title, group => this.setGroup(group)); this.groupService.changeTitle(group, title, group => this.setGroup(group));
} }
protected changePassword(group: Numbers, password: string) { protected changePassword(group: Group, password: string) {
this.groupService.changePassword(group, password, group => this.setGroup(group)); this.groupService.changePassword(group, password, group => this.setGroup(group));
} }

View File

@ -1,10 +1,17 @@
@import "./config.less"; @import "./config.less";
.user { .user {
clear: left;
float: left; float: left;
padding: @halfSpace; padding: @halfSpace;
background-color: lightskyblue; background-color: lightskyblue;
border-radius: @halfSpace; border-radius: @halfSpace;
margin-right: @halfSpace;
margin-bottom: @halfSpace;
}
.user_owner {
border: 1px solid black;
} }
.user:hover { .user:hover {