Commit 206220cc authored by Muhammad Saroosh Asif's avatar Muhammad Saroosh Asif
Browse files

Services

parent e888e10e
<div style="text-align:center">
<h1>
Welcome User with E-Mail {{userName}}!
</h1>
<p>
<button mat-button color="warn" (click)="logout()">
<h1>
Welcome Admin
</h1>
<p>
<button mat-button color="warn" (click)="logout()">
Logout
</button>
</p>
</div>
</p>
</div>
\ No newline at end of file
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AdminComponent } from './admin.component';
import { RouterTestingModule } from '@angular/router/testing';
import { JwtService } from '../jwt.service';
describe('AdminComponent', () => {
let component: AdminComponent;
let fixture: ComponentFixture<AdminComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AdminComponent],
imports: [RouterTestingModule],
providers: [JwtService]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AdminComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should set an Item', () => {
localStorage.setItem('access_token', 'u;p'); // u;p
expect(localStorage.getItem('access_token')).toBeDefined(); // u;p .toBe('u;p')
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
......@@ -12,11 +12,8 @@ export class AdminComponent implements OnInit {
constructor(private jwtService: JwtService, private router: Router) { }
ngOnInit(): void {
this.userName = localStorage.getItem('access_token').split(";")[0];
}
userName = "";
logout() {
this.jwtService.logout();
this.router.navigateByUrl('/login');
......
......@@ -43,4 +43,9 @@
.mat-icon {
font-size: 2em !important;
color: #000;
}
.pad {
padding-left: 10%;
padding-right: 10%;
}
\ No newline at end of file
......@@ -51,15 +51,11 @@
<button mat-icon-button routerLink="/international">
{{'cInternational'|translate}}
</button>
<button mat-icon-button routerLink="/navigation">
{{'cNavigation'|translate}}
</button>
</div>
</mat-toolbar>
</div>
<router-outlet></router-outlet>
<!-- <br>
<hr class="line">
<br> -->
\ No newline at end of file
<div class="pad">
<router-outlet></router-outlet>
</div>
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';
import { TranslateModule } from "@ngx-translate/core";
describe('AppComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
imports: [
TranslateModule.forRoot(),
]
}).compileComponents();
}));
it('should create the app', () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app).toBeTruthy();
});
it(`should have as title 'mit-ws'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.componentInstance;
expect(app.title).toEqual('mit-ws');
});
it('should render title', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement;
expect(compiled.querySelector('.content span').textContent).toContain('mit-ws app is running!');
});
});
......@@ -15,13 +15,13 @@ import { AppComponent } from './app.component';
import { RouterModule } from '@angular/router';
import { HomepageComponent } from './homepage/homepage.component';
import { NavigationComponent } from './navigation/navigation.component';
// import { RoomsComponent } from './rooms/rooms.component';
import { RoomsComponent } from './rooms/rooms.component';
import { LoginComponent } from './login/login.component';
import { InternationalComponent } from './international/international.component';
import { AdminComponent } from './admin/admin.component';
import { MatTableModule } from '@angular/material/table';
import { NewsComponent } from './news/news.component';
import { EventsComponent } from './events/events.component';
import { RegisterComponent } from './register/register.component';
import { UserComponent } from './user/user.component';
import { InternalinfoComponent } from './internalinfo/internalinfo.component';
import { JwtGuard } from './jwt.guard';
......@@ -30,6 +30,8 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FlexLayoutModule } from "@angular/flex-layout";
import { I18nModule } from './i18n/i18n.module';
// Material Components
import { MatTableModule } from '@angular/material/table';
import {MatExpansionModule} from '@angular/material/expansion';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatSidenavModule } from '@angular/material/sidenav';
......@@ -42,19 +44,24 @@ import { MatCardModule } from '@angular/material/card';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import {MatDatepickerModule } from '@angular/material/datepicker';
import { MatNativeDateModule } from '@angular/material/core';
import { AppointmentsComponent } from './appointments/appointments.component';
@NgModule({
declarations: [
AppComponent,
HomepageComponent,
NavigationComponent,
// RoomsComponent,
RoomsComponent,
LoginComponent,
AdminComponent,
NewsComponent,
EventsComponent,
RegisterComponent,
UserComponent,
InternalinfoComponent,
InternationalComponent,
AppointmentsComponent,
],
imports: [
......@@ -63,17 +70,17 @@ import { MatSelectModule } from '@angular/material/select';
{ path: '', component: HomepageComponent },
{ path: 'navigation', component: NavigationComponent },
{ path: 'events', component: EventsComponent },
{ path: 'news', component: NewsComponent },
// { path: 'rooms', component: RoomsComponent },
{ path: 'rooms', component: RoomsComponent },
{ path: 'international', component: InternationalComponent },
// { path: 'international', loadChildren: './international/international.module#InternationalModule' },
{ path: 'admin', component: AdminComponent, canActivate: [JwtGuard] },
{ path: 'user', component: UserComponent, canActivate: [JwtGuard] },
{ path: 'login', component: LoginComponent },
{ path: 'internalinfo', component: InternalinfoComponent }
]),
FlexLayoutModule,
MatButtonModule,
MatExpansionModule,
MatIconModule,
MatCardModule,
MatListModule,
......@@ -86,14 +93,17 @@ import { MatSelectModule } from '@angular/material/select';
MatInputModule,
ReactiveFormsModule,
MatSelectModule,
MatDatepickerModule,
MatNativeDateModule,
MatGridListModule,
// MatGridTile,
BrowserAnimationsModule,
I18nModule],
exports: [
RouterModule,
],
entryComponents: [LoginComponent],
providers: [], // SocketioService
providers: [MatDatepickerModule, MatNativeDateModule ], // SocketioService
bootstrap: [AppComponent]
})
export class AppModule { }
import { Room } from './room';
export interface Event {
eventId: string;
description: string;
organiser: string;
participants: string;
}
\ No newline at end of file
_id: string
title: string
description: string
organiser: string
participants: string
room: Room
event_from: Date
event_to: Date
created_at: Date
updated_at: Date
}
export interface CreateEvent {
title: string
description: string
organiser: string
participants: string
room: Room
event_from: Date
event_to: Date
}
.text {
width: 90%;
margin-left: 5%;
}
.tile {
text-align: center;
}
\ No newline at end of file
<div class="evhd">
<h2>EVENTS</h2>
<div>
<h1>{{'cEvents'|translate}}</h1>
<hr>
<div class="text">
<mat-expansion-panel>
<mat-expansion-panel-header>
<mat-panel-title>
<b> Add Event</b>
</mat-panel-title>
<mat-icon>arrow</mat-icon>
</mat-expansion-panel-header>
<form [formGroup]="createForm" (ngSubmit)="createEvent()">
<div>
<mat-label>Title</mat-label><br>
<input type="text" id="title" name="title" placeholder="Title" required formControlName="title" [ngClass]="{ 'has-error': formControls.title.errors }" />
<div *ngIf="formControls.title.errors">
<mat-error *ngIf="formControls.title.errors?.required">Title is required</mat-error>
<mat-error *ngIf="formControls.title.errors?.title">Title must be valid</mat-error>
</div>
</div>
<br>
<div>
<mat-label>Description</mat-label><br>
<input type="text" id="description" name="description" placeholder="Description" required formControlName="description" [ngClass]="{ 'has-error': formControls.description.errors }" />
<div *ngIf="formControls.description.errors">
<mat-error *ngIf="formControls.description.errors?.required">Description is required</mat-error>
<mat-error *ngIf="formControls.description.errors?.description">Description must be valid</mat-error>
</div>
</div>
<br>
<div>
<mat-label>Organiser</mat-label><br>
<input type="text" id="organiser" name="organiser" placeholder="Organiser" required formControlName="organiser" [ngClass]="{ 'has-error': formControls.organiser.errors }">
<div *ngIf="formControls.organiser.errors">
<mat-error *ngIf="formControls.organiser.errors?.required">Organiser is required</mat-error>
<mat-error *ngIf="formControls.organiser.errors?.organiser">Organiser must be valid</mat-error>
</div>
</div>
<br>
<div>
<mat-label>Participants</mat-label><br>
<input type="text" id="participants" name="participants" placeholder="Participants" required formControlName="participants" [ngClass]="{ 'has-error': formControls.participants.errors }">
<div *ngIf="formControls.participants.errors">
<mat-error *ngIf="formControls.participants.errors?.required">Participants is required</mat-error>
<mat-error *ngIf="formControls.participants.errors?.participants">Participants must be valid</mat-error>
</div>
</div>
<br>
<div>
<div>
<mat-label>Room</mat-label>
<mat-select formControlName="room" [ngClass]="{ 'has-error': formControls.room.errors }">
<mat-option *ngFor="let eventRoom of rooms" [value]="eventRoom._id">
{{eventRoom.name}}&#8212;{{eventRoom.roomId}}
</mat-option>
</mat-select>
<div *ngIf="formControls.room.errors">
<mat-error *ngIf="formControls.room.errors?.required">Room is required</mat-error>
<mat-error *ngIf="formControls.room.errors?.room">Room must be valid</mat-error>
</div>
</div>
</div>
<br>
<div>
<mat-label>Date</mat-label><br>
<mat-date-range-input [rangePicker]="picker">
<input matStartDate placeholder="Start date" required formControlName="fromDate" [ngClass]="{ 'has-error': formControls.fromDate.errors }">
<input matEndDate placeholder="End date" required formControlName="toDate" [ngClass]="{ 'has-error': formControls.toDate.errors }">
</mat-date-range-input>
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-date-range-picker #picker></mat-date-range-picker>
<div *ngIf="formControls.fromDate.errors">
<mat-error *ngIf="formControls.fromDate.errors?.required">Start Date is required</mat-error>
<mat-error *ngIf="formControls.fromDate.hasError('matStartDateInvalid')">Start Date must be valid</mat-error>
</div>
<div *ngIf="formControls.toDate.errors">
<mat-error *ngIf="formControls.toDate.errors?.required">End Date is required</mat-error>
<mat-error *ngIf="formControls.toDate.hasError('matEndDateInvalid')">End Date must be valid</mat-error>
</div>
</div>
<mat-action-row>
<button mat-raised-button class="button"><b>Create</b></button>
</mat-action-row>
</form>
</mat-expansion-panel>
</div>
<br>
<br>
<hr class="line">
<div class="events">
<mat-grid-list cols="3" rowHeight="1:1" gutterSize="10px">
<mat-grid-tile>
<span class="big">26</span>
<span>NOV</span>
<div>
<mat-grid-list cols="2" rowHeight="50" role="list" gutterSize="1px">
<mat-grid-tile role="listitem">
<strong>Date</strong>
</mat-grid-tile>
<mat-grid-tile role="listitem">
<strong>Description</strong>
</mat-grid-tile>
<mat-grid-tile>
<span class="big">27</span>
<span>NOV</span>
</mat-grid-list>
</div>
<div *ngFor="let event of events">
<mat-grid-list cols="2" rowHeight="50" role="list" gutterSize="1px">
<mat-grid-tile role="listitem">
{{ event.created_at | date }}
</mat-grid-tile>
<mat-grid-tile>
<span class="big">28</span>
<span>NOV</span>
<mat-grid-tile class="tile" role="listitem">
{{ event.title }} <br> {{ event.description}}
</mat-grid-tile>
</mat-grid-list>
<br>
</div>
</div>
\ No newline at end of file
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { EventsComponent } from './events.component';
describe('EventsComponent', () => {
let component: EventsComponent;
let fixture: ComponentFixture<EventsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ EventsComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(EventsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { EventService } from './event.service';
import { RoomsService } from './../rooms/rooms.service';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { CreateEvent } from '../event';
import { Router } from '@angular/router';
@Component({
selector: 'app-events',
......@@ -7,9 +12,142 @@ import { Component, OnInit } from '@angular/core';
})
export class EventsComponent implements OnInit {
constructor() { }
constructor(private service: EventService, private roomsService: RoomsService, private router: Router, private formBuilder: FormBuilder) { }
event: object;
events = [];
successMsg: string;
createForm: FormGroup;
rooms = []
get formControls() { return this.createForm.controls; }
ngOnInit(): void {
this.getAll()
this.initializeForm()
}
getAll(): void {
this.service.getEvent().subscribe({
next: data => {
this.events = data['result'];
for (let i = 0; i < this.events.length; i++) {
this.roomsService.getRoomById(this.events[i]['room']).subscribe(data => {
this.events[i]['room'] = data['result'];
});
}
},
error: error => {
if (error['statusText'] == "Not Found") {
this.successMsg = "No Record Exist"
} else {
this.successMsg = "No Record Found"
}
}
});
}
gotoDetail(id: string): void {
this.service.getEventById(id).subscribe({
next: data => {
this.event = data['result'];
this.roomsService.getRoomById(this.event['room']).subscribe(data => {
this.event['room'] = data['result'];
});
},
error: error => {
if (error['statusText'] == "Not Found") {
this.successMsg = "No Detail Exist"
} else {
this.successMsg = "No Detail Found"
}
}
});
}
getRoomsFromDb(): void {
this.roomsService.getFreeRooms().subscribe({
next: data => {
this.rooms = data['result'];
},
error: error => {
if (error['statusText'] == "Not Found") {
this.successMsg = "Please Create Room First"
} else {
this.successMsg = "No Room Found"
}
}
});
}
initializeForm() {
this.createForm = this.formBuilder.group({
title: new FormControl('', Validators.required),
description: new FormControl('', Validators.required),
organiser: new FormControl('', Validators.required),
participants: new FormControl('', Validators.required),
room: new FormControl('', Validators.required),
fromDate: new FormControl('', Validators.required),
toDate: new FormControl('', Validators.required)
});
this.getRoomsFromDb();
}
createEvent(): void {
console.log(this.createForm.value)
console.log(this.createForm.value.room)
if (this.isInput(this.createForm.value.title) && this.isInput(this.createForm.value.description) && this.isInput(this.createForm.value.organiser) && this.isInput(this.createForm.value.participants) && this.isInput(this.createForm.value.room) && this.createForm.valid) {
var event: CreateEvent = {
title: this.createForm.value.title,
description: this.createForm.value.description,
organiser: this.createForm.value.organiser,
participants: this.createForm.value.participants,
room: this.createForm.value.room,
event_from: this.createForm.value.fromDate.toISOString(),
event_to: this.createForm.value.toDate.toISOString()
}
this.service.createEvent(event).subscribe({
next: data => {
console.log(data)
this.successMsg = "Event Created Successful"
},
error: error => {
console.log(error)
if (error['statusText'] == "Bad Request") {
this.successMsg = "Event Already Exist"
} else {
this.successMsg = "Event Not Created"
}
}
})
} else if (!this.isInput(this.createForm.value.title) && !this.isInput(this.createForm.value.description) && !this.isInput(this.createForm.value.organiser) && !this.isInput(this.createForm.value.participants) && !this.isInput(this.createForm.value.room)) {
this.successMsg = "Title or Description or Link Is Empty"
} else if (!this.isInput(this.createForm.value.title)) {
this.successMsg = "Title is Not Valid"
} else if (!this.isInput(this.createForm.value.description)) {
this.successMsg = "Description is Not Valid"
} else if (!this.isInput(this.createForm.value.organiser)) {
this.successMsg = "Organiser is Not Valid"
} else if (!this.isInput(this.createForm.value.participants)) {
this.successMsg = "Participants is Not Valid"
} else if (this.createForm.value.title === "") {
this.successMsg = "Title is Required"
} else if (this.createForm.value.description === "") {
this.successMsg = "Description is Required"
} else if (this.createForm.value.organiser === "") {
this.successMsg = "Organiser is Required"
} else if (this.createForm.value.participants === "") {
this.successMsg = "Participants is Required"
} else {
this.successMsg = "Form is Not Valid"
}
if(this.createForm.valid){
this.router.navigate(['/events']);
}
}
isInput(name: string): Boolean {
return (name != "" && name != null && name != undefined) ? true : false
}
}
.heading {
color: #1a4273;
text-align: center;
margin-bottom: 5%;
font-size: 2em;