Skip to content

Commit

Permalink
Merge pull request #73 from SayakMukhopadhyay/wip
Browse files Browse the repository at this point in the history
Added Admin Component
  • Loading branch information
SayakMukhopadhyay authored Dec 23, 2017
2 parents 4736a12 + 17a3fbd commit fd96cb8
Show file tree
Hide file tree
Showing 29 changed files with 836 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elitebgs",
"version": "1.3.0",
"version": "1.4.0",
"license": "Apache-2.0",
"scripts": {
"ng": "ng",
Expand Down
5 changes: 5 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ passport.use(new DiscordStrategy({
avatar: profile.avatar,
discriminator: profile.discriminator,
access: 1,
os_contribution: 0,
patronage: {
level: 0,
since: null
},
invite: invitePromise.code,
invite_used: false,
guilds: profile.guilds
Expand Down
4 changes: 4 additions & 0 deletions server/models/ebgs_users.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

"use strict";

let mongoosePaginate = require('mongoose-paginate');

module.exports = new Promise((resolve, reject) => {
let db = require('../db');
let connection = db.elite_bgs;
Expand Down Expand Up @@ -63,6 +65,8 @@ module.exports = new Promise((resolve, reject) => {
}]
});

user.plugin(mongoosePaginate);

let model = connection.model('ebgsUsers', user);

resolve(model);
Expand Down
119 changes: 119 additions & 0 deletions server/routes/front_end.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,86 @@ router.get('/credits', (req, res, next) => {
});
});

router.get('/users', (req, res, next) => {
if (req.user.access === 0) {
require('../models/ebgs_users')
.then(users => {
let query = new Object;
let page = 1;
if (req.query.id) {
query._id = req.query.id;
}
if (req.query.beginsWith) {
query["$or"] = [
{
username: {
$regex: new RegExp(`^${_.escapeRegExp(req.query.beginsWith.toLowerCase())}`, 'i')
}
},
{
email: {
$regex: new RegExp(`^${_.escapeRegExp(req.query.beginsWith.toLowerCase())}`, 'i')
}
},
{
id: {
$regex: new RegExp(`^${_.escapeRegExp(req.query.beginsWith.toLowerCase())}`, 'i')
}
}
]
}
if (req.query.page) {
page = req.query.page;
}
let paginateOptions = {
lean: true,
page: page,
limit: 10,
leanWithId: false
};
users.paginate(query, paginateOptions)
.then(result => {
res.status(200).json(result);
})
.catch(next)
})
.catch(next)
}
});

router.put('/users', (req, res, next) => {
if (req.user.access === 0) {
require('../models/ebgs_users')
.then(users => {
let body = req.body;
if (validateUser(req.body)) {
users.findOneAndUpdate(
{
_id: req.body._id
},
req.body,
{
upsert: false,
runValidators: true
}).then(data => {
res.send(true);
}).catch((err) => {
console.log(err);
res.send(false);
});
} else {
res.send(false);
}
})
.catch(err => {
console.log(err);
res.send(false);
})
} else {
res.send(false);
}
});

router.post('/edit', (req, res, next) => {
userAllowed(req)
.then(allowed => {
Expand Down Expand Up @@ -464,6 +544,45 @@ router.post('/edit', (req, res, next) => {
});
});

let validateUser = user => {
if (_.has(user, '_id')
&& _.has(user, 'username')
&& _.has(user, 'email')
&& _.has(user, 'discriminator')
&& _.has(user, 'access')
&& _.has(user, 'os_contribution')
&& _.has(user, 'patronage')
) {
user.factions.forEach(faction => {
if (!_.has(faction, 'name')
|| !_.has(faction, 'name_lower')
|| faction.name.toLowerCase() !== faction.name_lower
) {
return false;
}
});
user.systems.forEach(system => {
if (!_.has(system, 'name')
|| !_.has(system, 'name_lower')
|| system.name.toLowerCase() !== system.name_lower
) {
return false;
}
});
user.editable_factions.forEach(faction => {
if (!_.has(faction, 'name')
|| !_.has(faction, 'name_lower')
|| faction.name.toLowerCase() !== faction.name_lower
) {
return false;
}
});
return true;
} else {
return false;
}
}

let validateEdit = data => {
let valid = true;
if (_.has(data, '_id')
Expand Down
47 changes: 47 additions & 0 deletions src/app/admin/admin-routing.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { AdminComponent } from './admin.component';
import { AdminOverviewComponent } from './overview/admin-overview.component';
import { AdminUsersListComponent } from './users/admin-users-list.component';
import { AdminUsersViewComponent } from './users/admin-users-view.component';
import { AdminSystemsComponent } from './systems/admin-systems.component';
import { AdminFactionsComponent } from './factions/admin-factions.component';

const adminRoutes: Routes = [
{
path: 'admin',
component: AdminComponent,
children: [
{
path: '',
component: AdminOverviewComponent
},
{
path: 'users',
component: AdminUsersListComponent
},
{
path: 'users/:userid',
component: AdminUsersViewComponent
},
{
path: 'systems',
component: AdminSystemsComponent
},
{
path: 'factions',
component: AdminFactionsComponent
}
]
}
];

@NgModule({
imports: [
RouterModule.forChild(adminRoutes)
],
exports: [
RouterModule
]
})
export class AdminRoutingModule { }
17 changes: 17 additions & 0 deletions src/app/admin/admin.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<nav class="subnav">
<ul class="nav">
<li class="nav-item">
<button routerLink="/admin" routerLinkActive="active" [routerLinkActiveOptions]="{ exact: true }" class="btn btn-link nav-link nav-item">Overview</button>
</li>
<li class="nav-item">
<button routerLink="/admin/users" routerLinkActive="active" class="btn btn-link nav-link nav-item">Users</button>
</li>
<li class="nav-item">
<button routerLink="/admin/systems" routerLinkActive="active" class="btn btn-link nav-link nav-item">Systems</button>
</li>
<li class="nav-item">
<button routerLink="/admin/factions" routerLinkActive="active" class="btn btn-link nav-link nav-item">Factions</button>
</li>
</ul>
</nav>
<router-outlet></router-outlet>
22 changes: 22 additions & 0 deletions src/app/admin/admin.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.profile-header {
height: 200px;
flex: 0 0 auto;
display: flex;
flex-direction: column;
justify-content: space-evenly;
width: 100%;
background-image: url('/assets/profile-background.png');
}

.profile-image {
align-self: center;
}

.profile-image img {
border-radius: 50%;
}

.profile-name {
align-self: center;
color: #ffffff;
}
11 changes: 11 additions & 0 deletions src/app/admin/admin.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Component, HostBinding } from '@angular/core';

@Component({
selector: 'app-admin',
templateUrl: './admin.component.html',
styleUrls: ['./admin.component.scss']
})
export class AdminComponent {
@HostBinding('class.u-main-container') mainContainer = true;
constructor() { }
}
32 changes: 32 additions & 0 deletions src/app/admin/admin.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ClarityModule } from 'clarity-angular';

import { AdminComponent } from './admin.component';
import { AdminOverviewComponent } from './overview/admin-overview.component';
import { AdminUsersListComponent } from './users/admin-users-list.component';
import { AdminUsersViewComponent } from './users/admin-users-view.component';
import { AdminSystemsComponent } from './systems/admin-systems.component';
import { AdminFactionsComponent } from './factions/admin-factions.component';
import { AdminRoutingModule } from './admin-routing.module';
@NgModule({
declarations: [
AdminComponent,
AdminOverviewComponent,
AdminUsersListComponent,
AdminUsersViewComponent,
AdminSystemsComponent,
AdminFactionsComponent
],
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
ClarityModule.forRoot(),
AdminRoutingModule
],
providers: [],
exports: [AdminComponent]
})
export class AdminModule { }
3 changes: 3 additions & 0 deletions src/app/admin/factions/admin-factions.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="content-area">
<h1>Factions</h1>
</div>
10 changes: 10 additions & 0 deletions src/app/admin/factions/admin-factions.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component, HostBinding } from '@angular/core';

@Component({
selector: 'app-admin-factions',
templateUrl: './admin-factions.component.html'
})
export class AdminFactionsComponent {
@HostBinding('class.content-container') contentContainer = true;
constructor() { }
}
32 changes: 32 additions & 0 deletions src/app/admin/overview/admin-overview.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="content-area">
<h1>Overview</h1>
<div class="card">
<div class="card-header">
User Overview
</div>
<div class="card-block">
<div class="card-title">
User Stats
</div>
<div class="card-text">
Total Number of Users: {{userCount}}
<br> Latest User: {{latestUser}}
</div>
</div>
<div class="card-block">
<div class="card-title">
Users with Edit Access to Factions
</div>
<div class="card-text">
<clr-tree-node *ngFor="let user of userEditFaction">
<a routerLink="/admin/users/{{user.id}}">{{user.username}}</a>
<ng-template clrIfExpanded>
<clr-tree-node *ngFor="let faction of user.editable_factions">
{{faction.name}}
</clr-tree-node>
</ng-template>
</clr-tree-node>
</div>
</div>
</div>
</div>
24 changes: 24 additions & 0 deletions src/app/admin/overview/admin-overview.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Component, HostBinding, OnInit } from '@angular/core';
import { ServerService } from '../../services/server.service';
import { EBGSUser } from '../../typings';

@Component({
selector: 'app-admin-overview',
templateUrl: './admin-overview.component.html'
})
export class AdminOverviewComponent implements OnInit {
@HostBinding('class.content-container') contentContainer = true;
userCount: number;
latestUser: string;
userEditFaction: EBGSUser
constructor(
private serverService: ServerService,
) {
this.userCount = 0;
this.latestUser = '';
}

ngOnInit() {

}
}
3 changes: 3 additions & 0 deletions src/app/admin/systems/admin-systems.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="content-area">
<h1>Systems</h1>
</div>
Loading

0 comments on commit fd96cb8

Please sign in to comment.