Merge branch 'max_dev' of Software_Engineering_I/greenvironment-frontend into master

master
Max_ES 5 years ago committed by Gitea
commit c916430837

@ -59,11 +59,12 @@ import {MatDialogModule} from '@angular/material/dialog';
import {MatTooltipModule} from '@angular/material/tooltip'; import {MatTooltipModule} from '@angular/material/tooltip';
import {MatExpansionModule} from '@angular/material/expansion'; import {MatExpansionModule} from '@angular/material/expansion';
import {MatDatepickerModule} from '@angular/material/datepicker'; import {MatDatepickerModule} from '@angular/material/datepicker';
import {MatNativeDateModule, MatProgressBarModule} from '@angular/material/'; import {MatGridListModule, MatNativeDateModule, MatProgressBarModule} from '@angular/material/';
import {MatSnackBarModule} from '@angular/material/snack-bar'; import {MatSnackBarModule} from '@angular/material/snack-bar';
import { ServiceWorkerModule } from '@angular/service-worker'; import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment'; import { environment } from '../environments/environment';
import {LightboxModule} from 'ngx-lightbox'; import {LightboxModule} from 'ngx-lightbox';
import { AdminpageComponent } from './components/adminpage/adminpage.component';
const config: SocketIoConfig = {url: 'http://localhost:4444', options: {}}; const config: SocketIoConfig = {url: 'http://localhost:4444', options: {}};
@ -76,6 +77,7 @@ const appRoutes: Routes = [
{path: 'register', component: RegisterComponent}, {path: 'register', component: RegisterComponent},
{path: 'about', component: AboutComponent}, {path: 'about', component: AboutComponent},
{path: 'imprint', component: ImprintComponent}, {path: 'imprint', component: ImprintComponent},
{path: 'admin', component: AdminpageComponent},
]; ];
@NgModule({ @NgModule({
@ -104,6 +106,7 @@ const appRoutes: Routes = [
UserlistComponent, UserlistComponent,
DialogFileUploadComponent, DialogFileUploadComponent,
DialogGroupFileUploadComponent, DialogGroupFileUploadComponent,
AdminpageComponent,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
@ -150,6 +153,7 @@ const appRoutes: Routes = [
MatProgressBarModule, MatProgressBarModule,
LightboxModule, LightboxModule,
ServiceWorkerModule.register('ngsw-worker.js', {enabled: environment.production}), ServiceWorkerModule.register('ngsw-worker.js', {enabled: environment.production}),
MatGridListModule,
], ],
entryComponents: [ entryComponents: [
DialogCreateGroupComponent, DialogCreateGroupComponent,

@ -0,0 +1,46 @@
<div id="adminpage">
<h1>Administration</h1>
<div class="grid">
<div class="column">
<div class="column-header">
<h2>Levels</h2>
</div>
</div>
<div class="column">
<div class="column-header">
<h2>Activities</h2>
</div>
<div>
<mat-form-field class="input">
<input matInput type="text" placeholder="Activity name">
</mat-form-field>
<mat-table [dataSource]="activitySource" matSort>
<ng-container matColumnDef="points">
<th mat-header-cell *matHeaderCellDef mat-sort-header> points</th>
<td mat-cell *matCellDef="let action"> {{action.points}} </td>
</ng-container>
<!-- Name Column -->
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> action</th>
<td mat-cell *matCellDef="let action"> {{action.name}} </td>
</ng-container>
<!-- description Column -->
<ng-container matColumnDef="description">
<th mat-header-cell *matHeaderCellDef mat-sort-header> description</th>
<td mat-cell *matCellDef="let action"> {{action.description}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedActivityColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedActivityColumns;"></tr>
</mat-table>
</div>
</div>
<div class="column">
<div class="column-header">
<h2>Blacklist</h2>
</div>
</div>
</div>
</div>

@ -0,0 +1,18 @@
@import "../../../styles/mixins.sass"
#adminpage
margin: 1em
.grid
display: grid
grid-template: 100% / 33% 33% 33%
.column-header
text-align: center
.column
&:nth-child(1)
@include gridPosition(1, 2, 1, 2)
&:nth-child(2)
@include gridPosition(1, 2, 2, 3)
&:nth-child(3)
@include gridPosition(1, 2, 3, 4)

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AdminpageComponent } from './adminpage.component';
describe('AdminpageComponent', () => {
let component: AdminpageComponent;
let fixture: ComponentFixture<AdminpageComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AdminpageComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AdminpageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

@ -0,0 +1,31 @@
import {Component, OnInit, ViewChild} from '@angular/core';
import {LevelList} from '../../models/levellist';
import {ActivityService} from '../../services/activity/activity.service';
import {Activitylist} from '../../models/activity';
import {MatTableDataSource} from '@angular/material/table';
import {MatSort} from '@angular/material/sort';
@Component({
selector: 'app-adminpage',
templateUrl: './adminpage.component.html',
styleUrls: ['./adminpage.component.sass']
})
export class AdminpageComponent implements OnInit {
public activitySource: MatTableDataSource<any>;
public displayedActivityColumns = ['points', 'name', 'description'];
@ViewChild(MatSort, {static: true}) activitySort: MatSort;
constructor(private activityService: ActivityService) {
}
ngOnInit() {
this.activityService.getActivities();
this.activityService.activitylist.subscribe(response => {
this.activitySource = new MatTableDataSource(response.Actions);
this.activitySource.sort = this.activitySort;
});
}
}

@ -134,7 +134,7 @@
</div> </div>
<mat-card-title class="pointer" (click)="showUserProfile(user)">{{user.username}}</mat-card-title> <mat-card-title class="pointer" (click)="showUserProfile(user)">{{user.username}}</mat-card-title>
<mat-card-subtitle class="pointer" (click)="showUserProfile(user)">{{user.handle}}</mat-card-subtitle> <mat-card-subtitle class="pointer" (click)="showUserProfile(user)">{{user.handle}}</mat-card-subtitle>
<mat-card-subtitle hidden class="pointer" (click)="showUserProfile(user)">[admin] <mat-card-subtitle *ngIf="user.isGroupAdmin" class="pointer" (click)="showUserProfile(user)">[admin]
</mat-card-subtitle> </mat-card-subtitle>
<div id="icon-box" *ngIf="isCreator"> <div id="icon-box" *ngIf="isCreator">
<button mat-icon-button [matMenuTriggerFor]="menu"> <button mat-icon-button [matMenuTriggerFor]="menu">

@ -111,8 +111,8 @@ export class GroupComponent implements OnInit {
}); });
this.groupService.getGroupData(this.id).subscribe(); this.groupService.getGroupData(this.id).subscribe();
this.groupService.group.subscribe(response => { this.groupService.group.subscribe(response => {
this.isAdmin = false;
if (response) { if (response) {
this.isAdmin = false;
this.groupProfile = response; this.groupProfile = response;
// tslint:disable-next-line:max-line-length // tslint:disable-next-line:max-line-length
this.groupProfile.allowedToJoinGroup = this.requestService.isAllowedToJoinGroup(this.groupProfile.id, this.self); this.groupProfile.allowedToJoinGroup = this.requestService.isAllowedToJoinGroup(this.groupProfile.id, this.self);

@ -125,7 +125,13 @@
<div [hidden]="loggedIn"> <div [hidden]="loggedIn">
<button mat-menu-item routerLink="/login"> <button mat-menu-item routerLink="/login">
<mat-icon>exit_to_app</mat-icon> <mat-icon>exit_to_app</mat-icon>
<span>login</span> <span>Login</span>
</button>
</div>
<div [hidden]="!user.isAdmin">
<button mat-menu-item routerLink="/admin">
<mat-icon>settings</mat-icon>
<span>Administration</span>
</button> </button>
</div> </div>
</mat-menu> </mat-menu>

@ -52,12 +52,10 @@ export class Group {
const user = new User(); const user = new User();
this.admins.push(user.assignFromResponse(admin)); this.admins.push(user.assignFromResponse(admin));
} }
for (const admin of this.admins) {
for (const member of this.members) { for (const member of this.members) {
if (member.userID === admin.userID) { member.isGroupAdmin = !!this.admins.find((a: User) => {
member.isGroupAdmin = true; return a.userID === member.userID;
} });
}
} }
} }

@ -45,4 +45,6 @@ export interface IUser {
eventCount: number; eventCount: number;
events: any[]; events: any[];
isAdmin?: boolean;
} }

@ -18,6 +18,7 @@ export class User {
joinedAt: string; joinedAt: string;
friendCount: number; friendCount: number;
groupCount: number; groupCount: number;
isAdmin: boolean = false;
isGroupAdmin: boolean; isGroupAdmin: boolean;
darkmode = false; darkmode = false;
@ -80,6 +81,9 @@ export class User {
this.receivedRequests = userDataResponse.receivedRequests this.receivedRequests = userDataResponse.receivedRequests
.map(request => new FriendRequest(request.id, request.sender.id, request.sender.handle, request.sender.name)); .map(request => new FriendRequest(request.id, request.sender.id, request.sender.handle, request.sender.name));
} }
if (userDataResponse.isAdmin) {
this.isAdmin = true;
}
return this; return this;
} }

@ -95,9 +95,6 @@ export class GroupService extends BaseService {
groupId groupId
} }
}; };
const group = this.group.getValue();
group.admins = [];
this.group.next(group);
return this.postGraphql(body, null, 0) return this.postGraphql(body, null, 0)
.pipe(tap(response => { .pipe(tap(response => {
const group = this.group.getValue(); const group = this.group.getValue();
@ -117,9 +114,6 @@ export class GroupService extends BaseService {
groupId groupId
} }
}; };
const group = this.group.getValue();
group.admins = [];
this.group.next(group);
return this.postGraphql(body, null, 0) return this.postGraphql(body, null, 0)
.pipe(tap(response => { .pipe(tap(response => {
const group = this.group.getValue(); const group = this.group.getValue();

@ -47,6 +47,7 @@ const graphqlQuery = `mutation($email: String!, $pwHash: String!) {
id id
}, },
settings settings
isAdmin
} }
}`; }`;

Loading…
Cancel
Save