Skip to content

Commit

Permalink
release v-1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
=sathwikreddy56 committed May 22, 2021
1 parent d0b9a47 commit c1b2107
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 55 deletions.
78 changes: 64 additions & 14 deletions BackEnd/routes/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ var cities = [];
var state = [];
var facilities =[];
var state_city=[];
var filter_data = [];
console.log("Processed")
data.forEach(Element=>{
var temp = Element;
var flist = temp.facilities.split(",");
temp.facilities = flist;
mydata.push(temp);
filter_data.push(temp);
var city_name = Element.city
var state_name = Element.state

Expand All @@ -36,7 +34,7 @@ data.forEach(Element=>{
})
router.get('/render',auth,(req,res)=>{
res.json({"auth":true,
table_data:mydata,
"table_data":mydata,
"city_data":cities.sort(),
"state_data":state.sort(),
"facilities_data":facilities.sort(function(a, b){return b.length - a.length;})
Expand All @@ -50,35 +48,87 @@ router.post('/cities',auth,(req,res)=>{
})
//FILTERING
router.post('/filter',auth,(req,res)=>{
var response ={}
var table_filter_data = mydata;
var state_filter_data = state;
var city_filter_data = cities;
var facilities_filter_data = facilities;
console.log("filter data ",req.body)


if(req.body.state && req.body.state!="***"){
console.log("state filter")
var temp =[]
filter_data.forEach(ele=>{
table_filter_data.forEach(ele=>{
if(ele.state==req.body.state) temp.push(ele);
ele.facilities.forEach(facility=>{
if(!facilities_filter_data.includes(facility)&&facility!="") facilities_filter_data.push(facility)
})
})
filter_data=temp;
table_filter_data=temp;
city_filter_data = state_city[req.body.state];
response ={"filtered_table_data":table_filter_data,
"filtered_city_list":city_filter_data,
"filtered_facilities":facilities_filter_data}
}


if(req.body.city && req.body.city!="***"){
console.log("city filter")
var temp =[]
filter_data.forEach(ele=>{ if(ele.city==req.body.city) temp.push(ele); })
filter_data=temp;
table_filter_data.forEach(ele=>{
if(ele.city==req.body.city) temp.push(ele);
ele.facilities.forEach(facility=>{
if(!facilities_filter_data.includes(facility)&&facility!="") facilities_filter_data.push(facility)
})
})
table_filter_data=temp;
response ={"filtered_table_data":table_filter_data,
"filtered_facilities":facilities_filter_data}
}


if(req.body.facilities && req.body.facilities.length != 0){
console.log("facilities filter")
var temp =[]
filter_data.forEach(ele=>{
var state_temp = [];
var city_temp = []
table_filter_data.forEach(ele=>{
var flag = true;
req.body.facilities.forEach(facility=>{
if(ele.facilities.includes(facility)==false) flag = false

})
if(temp.includes(ele) ==false && flag==true ) temp.push(ele);
})
filter_data=temp;
if( flag==true ){
if(temp.includes(ele) ==false) temp.push(ele);
ele.facilities.forEach(facility=>{
if(!facilities_filter_data.includes(facility)&&facility!="") facilities_filter_data.push(facility)
})
if(!state_temp.includes(ele.state)) state_temp.push(ele.state);
if(!city_temp.includes(ele.city)) city_temp.push(ele.city);
}
})
table_filter_data=temp;
city_filter_data = city_temp;
state_filter_data = state_temp;
response ={"filtered_table_data":table_filter_data,
"filtered_facilities":facilities_filter_data,
"filtered_city_list":city_filter_data,
"filtered_state_list":state_filter_data}
}
if(req.body.search && req.body.city!=""){
console.log("search");
var temp=[]
table_filter_data.forEach(college=>{
if(college.name.includes(req.body.search)){
temp.push(college)
}
})
table_filter_data = temp
}
res.json({data:filter_data})
filter_data = mydata;
res.json({"table_data":table_filter_data,
"city_data":city_filter_data,
"state_data":state_filter_data,
"facilities_data":facilities_filter_data,})
table_filter_data = mydata;
})
module.exports = router;
2 changes: 2 additions & 0 deletions angular/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { UserNavbarComponent } from './user-side/user-navbar/user-navbar.compone
import { LoginComponent } from './auth/login/login.component';
import { SignupComponent } from './auth/signup/signup.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import {MatToolbarModule} from '@angular/material/toolbar';
import {MatMenuModule} from '@angular/material/menu';
@NgModule({
declarations: [
Expand All @@ -45,6 +46,7 @@ import {MatMenuModule} from '@angular/material/menu';
MatCardModule,
MatTableModule,
MatGridListModule,
MatToolbarModule,
MatTabsModule,
MatFormFieldModule,
MatButtonModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,29 @@
width: 100%;
height: 100%;
display: block;

background-color: #303F9F;
/* background-color: #375836; */
background-position: center;
background-repeat: no-repeat;
background-size: cover;
overflow: hidden;
}
mat-toolbar{
height: 50px;

background-color: #ffffff63;
/* background-color: #303F9F; */
}
.example-spacer {
left: 82%;
}
.mat-drawer-container{
margin-top: 3%;
margin-top: 0%;
margin-left: 3%;
margin-right: 3%;
margin-bottom: 3%;
background-color: #9da9f8;
background-color: #f8bf03;
height: 90%;
overflow: hidden;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<div class="dashboard">
<mat-toolbar>
<span>Mindler Project</span>
<span class="example-spacer"></span>
<button mat-raised-button class="btn example-spacer " (click)="logout()" color="warn">
<span>signout</span>
<mat-icon>exit_to_app</mat-icon>
</button>
</mat-toolbar>
<mat-drawer-container class="example-container">
<mat-drawer mode="side" class="" opened>
<div>
Expand All @@ -7,12 +15,9 @@
<!--SEARCH INPUT-->
<mat-form-field class="full-width">
<mat-label>Search</mat-label>
<input matInput placeholder="UserName" name="username" ngModel #username="ngModel" id="username"/>
<input matInput type="text" class="form-control" name="search" [(ngModel)]="search" (ngModelChange) = searchf()/>
</mat-form-field>
<!--<select (change)="onState($event)">
<option *ngFor="let state of statesarr" value={{state}}>{{state}}</option>
</select>-->
<!--STATE INPUT-->
<!--state INPUT-->
<mat-form-field appearance="fill">
<mat-label>STATE</mat-label>
<mat-select (selectionChange)="onState($event)">
Expand All @@ -34,7 +39,7 @@
</mat-chip-list>
</div>
</form>
<button mat-raised-button class="filter-button center" id="submitButton" color="warn" >
<button mat-raised-button class="filter-button center" (click)="reset()" id="submitButton" color="primary" >
Reset Filters
</button>
</mat-card-content>
Expand Down
100 changes: 67 additions & 33 deletions angular/src/app/user-side/user-dashboard1/user-dashboard1.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,61 @@ import { tile } from './tile';
})
export class UserDashboard1Component implements OnInit {
colleges!: tile[];
collegesf!: tile[];
dataSource =this.colleges;

statesarr !: string[] ;
citiesarr !: string[] ;
facilities !:string[];
filterFacilities !:[];

result !:string []
state :string;
city :string;
search :any;
tables = [0];
constructor(private http: HttpClient,private router: Router) {
this.state= "***";
this.city = "***";
this.result = [];
}
ngOnInit(): void {
this.get_dashboard();
}
searchf()
{
if(this.search ==""){
this.colleges = this.collegesf;
}else{
this.colleges = this.collegesf.filter(college=>{
return college.name.toLocaleLowerCase().match(this.search.toLocaleLowerCase())
})
}
}
onSearch(item:any){
this.search = item.target.value;
var token = localStorage.getItem('token')||"a"
var headers =new HttpHeaders().set('auth-token',token);
this.filter({state:this.state,city:this.city,facilities:this.result,search:this.search},headers).subscribe(info=>{
this.colleges = info.table_data;
this.statesarr = info.state_data;
this.citiesarr = info.city_data;
},(error) => { console.error('error caught in Facilities toggle : '+error.message)})
}
toggleSelection1(li : MatChipList) {
var result : string[] = [];
this.result =[]
for(const c in li.selected){
console.log(li.selected[c].value)

if(li.selected[c]){ result.push(li.selected[c].value)}
if(li.selected[c]){ if(!this.result.includes(li.selected[c])) this.result.push(li.selected[c].value)}
}
var token = localStorage.getItem('token')||"a"
var headers =new HttpHeaders().set('auth-token',token);
this.filter({state:this.state,city:this.city,facilities:result},headers).subscribe(info=>{
this.colleges = info.data;
},(error) => {
console.error('error caught in onStateChange : '+error.message)
})
this.filter({state:this.state,city:this.city,facilities:this.result},headers).subscribe(info=>{
this.colleges = info.table_data;
this.collegesf = info.table_data;
this.statesarr = info.state_data;
this.citiesarr = info.city_data;
},(error) => { console.error('error caught in Facilities toggle : '+error.message)})
}
toggleSelection(chip: MatChip,li:MatChipList) {
chip.toggleSelected();
Expand All @@ -49,34 +75,29 @@ export class UserDashboard1Component implements OnInit {
this.state = state.value;
var token = localStorage.getItem('token')||"a"
var headers =new HttpHeaders().set('auth-token',token);
console.log(state.value)
//Fetch list of cities in that state
this.state_cities(state.value,headers).subscribe(cities=>{
this.citiesarr=cities.data;
console.log(cities.data)
},(error) => {
console.error('error caught in onStateChange : '+error.message)
})
//fetch colleges filtered such that they are present only in that state
this.filter({state:this.state},headers).subscribe(info=>{
this.colleges = info.data;
},(error) => {
console.error('error caught in onStateChange : '+error.message)
})
console.log(this.state,this.city,this.result);
this.filter({state:this.state,city:this.city,facilities:this.result},headers).subscribe(info=>{
this.colleges = info.table_data;
this.collegesf = info.table_data;
this.citiesarr = info.city_data;
this.filterFacilities = info.facilities_data;
console.log(info)
},(error) => { console.error('error caught in onStateChange : '+error.message)})

}
oncity(city:any){
this.city = city.value;
var request = {"state":this.state,"city":this.city};
var request = {"state":this.state,"city":this.city,"facilities":this.result};
var token = localStorage.getItem('token')||"a"
var headers =new HttpHeaders().set('auth-token',token);
//fetch colleges filtered such that they are present only in that state
this.filter(request,headers).subscribe(info=>{
console.log("on city fetched")
console.log(info.data)
this.colleges = info.data;
},(error) => {
console.error('error caught in onStateChange : '+error.message)
})
this.colleges = info.table_data;
this.collegesf = info.table_data;
this.citiesarr = info.city_data;
this.filterFacilities = info.facilities_data;
},(error) => { console.error('error caught in onCityChange : '+error.message) })
}
get_dashboard():void{
var token = localStorage.getItem('token')||"a"
Expand All @@ -86,20 +107,33 @@ export class UserDashboard1Component implements OnInit {
console.log(h)
//Intital check for login
if(!h.auth){
this.router.navigateByUrl('/user/login');
alert("Unauthorized Access")
this.router.navigateByUrl('/user/login');
}else{
this.colleges=h.table_data;
this.colleges =h.table_data;
this.collegesf = h.table_data;
this.citiesarr = h.city_data;
this.statesarr = h.state_data;
this.facilities = h.facilities_data;
}
},(error) => {
console.error('error caught in component',error)
console.error('error caught while intializing',error)
this.router.navigateByUrl('/user/login');
alert("Unauthorized Access")
})
}

reset():void{
console.log("Hard Reset")
this.state="***"
this.city = "***"
this.ngOnInit()
}
logout():void{
console.log("logout")
localStorage.clear();
this.router.navigateByUrl('/user/login');
alert("logged out!")
}
populate_data(headers:HttpHeaders){
return this.http.get
<{"auth" :boolean,"table_data":tile[],"city_data":[],"state_data":[],"facilities_data":[]}>
Expand All @@ -109,7 +143,7 @@ export class UserDashboard1Component implements OnInit {

//fetch Filtered DATA
filter(body,headers:HttpHeaders){
return this.http.post<{"data":[]}>('http://localhost:8080/user/filter',body,{headers})
return this.http.post<{"table_data":tile[],"city_data":[],"state_data":[],"facilities_data":[]}>('http://localhost:8080/user/filter',body,{headers})
}
//fetch list of cities from the provided state
state_cities(state:string,headers:HttpHeaders){
Expand Down

0 comments on commit c1b2107

Please sign in to comment.