Skip to content

Commit

Permalink
Added Settings Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekTBrown committed Aug 23, 2017
1 parent 31e6510 commit fff0357
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 6 deletions.
2 changes: 1 addition & 1 deletion client/imports/account/account.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h1>Account</h1>
<div class="actions" fxLayout="row">

<!-- Change Password -->
<button md-raised-button>
<button md-raised-button routerLink="/account/reset">
<md-icon>security</md-icon>
Change Password
</button>
Expand Down
18 changes: 18 additions & 0 deletions client/imports/admin/admin_settings.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="tuxlab-admin-settings" fxLayout="column" fxLayoutAlign="flex-start center">

<h1> Settings </h1>

<textarea mdInput mdTextareaAutosize *ngIf="settings" [(ngModel)]="settings" [disabled]="!edit_mode"></textarea>

<div class="fab" fxLayout="row" fxLayoutAlign="flex-end center">
<ng-container [ngSwitch]="edit_mode">
<button md-fab *ngSwitchCase="true" (click)="update()">
<md-icon>save</md-icon>
</button>
<button md-fab *ngSwitchCase="false" (click)="edit_mode = true">
<md-icon>edit</md-icon>
</button>
</ng-container>
</div>

</div>
30 changes: 30 additions & 0 deletions client/imports/admin/admin_settings.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.tuxlab-admin-settings{
width: 100%;
max-width: 960px !important;
min-height: 80vh;

margin:0 auto;

h1{
font-weight: 300;
width: 100%;
}

textarea{
width: 100%;
min-height: 800px;
padding: 15px;

color: #000 !important;
background-color: #fff;
font-family: "Courier New", courier, monospace;
}

div.fab{
width: 100%;
position: relative;
top: -100px;

padding: 10px;
}
}
38 changes: 38 additions & 0 deletions client/imports/admin/admin_settings.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Meteor Imports
import { Meteor } from 'meteor/meteor';
import { MeteorComponent } from 'angular2-meteor';

// Angular Imports
import { Component, NgZone } from '@angular/core';

// Admin Settings Component
import template from "./admin_settings.component.html";
import style from "./admin_settings.component.scss";

@Component({
selector: 'tuxlab-admin-settings',
template,
styles: [ style ]
})

// Export Dashboard Class
export class AdminSettings extends MeteorComponent {
private settings : any;
private edit_mode : boolean = false;

constructor(private zone : NgZone) {
super();
}

ngOnInit(){
Meteor.call('Settings.get', (err, res) => {
this.settings = JSON.stringify(res, null, 2);
})
}

update(){
Meteor.call('Settings.set', JSON.parse(this.settings), () => {
this.edit_mode = false;
});
}
}
3 changes: 3 additions & 0 deletions client/imports/admin/admin_view.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ <h1> Administration </h1>
<md-tab label="Users">
<tuxlab-user-list></tuxlab-user-list>
</md-tab>
<md-tab label="Settings">
<tuxlab-admin-settings></tuxlab-admin-settings>
</md-tab>
</md-tab-group>

</div>
11 changes: 6 additions & 5 deletions client/imports/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import CreateUser from './account/create.component';
// Admin
import { AdminView } from './admin/admin_view.component';
import { UserList, UserItem, UserCourseItem, UserSessionItem } from './admin/admin_user_list.component';
import { AdminSettings } from './admin/admin_settings.component';

// Course
import CourseList from './course/course_list.component';
Expand Down Expand Up @@ -98,6 +99,11 @@ export const AppRoutes : Routes = [

// Admin
AdminView,
AdminSettings,
UserList,
UserItem,
UserCourseItem,
UserSessionItem,

// Course
CourseList,
Expand All @@ -112,11 +118,6 @@ export const AppRoutes : Routes = [
SessionList,
SessionListItem,

// Admin
UserList,
UserItem,
UserCourseItem,
UserSessionItem
],
imports: [
RouterModule.forRoot(
Expand Down
26 changes: 26 additions & 0 deletions server/methods/settings.methods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Meteor } from 'meteor/meteor';
import { Users } from '../../both/collections/user.collection';

Meteor.methods({

'Settings.get'(){
if (!Meteor.userId()){
throw new Meteor.Error("Unauthorized");
} else if (Users.isGlobalAdministrator(Meteor.userId())){
return Meteor.settings;
} else {
throw new Meteor.Error("Unauthorized");
}
},

'Settings.set'({settings}){
if (!Meteor.userId()){
throw new Meteor.Error("Unauthorized");
} else if (Users.isGlobalAdministrator(Meteor.userId())){
return Meteor.settings = settings;
} else {
throw new Meteor.Error("Unauthorized");
}
}

});

0 comments on commit fff0357

Please sign in to comment.