Last active
September 22, 2016 21:09
-
-
Save Spittal/2c7dd6709c46e3ee4071bb7d67a2a621 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import { ActivatedRoute } from '@angular/router'; | |
import { FormGroup, FormControl } from '@angular/forms'; | |
import { Observable } from 'rxjs'; | |
import { FlashService } from '../../core'; | |
import { AdminService } from '../admin.service'; | |
export class AdminUserIndexComponent implements OnInit { | |
private page: number; | |
private content: {}; | |
private searchInput: FormControl = new FormControl(); | |
constructor( | |
private route: ActivatedRoute, | |
private adminService: AdminService, | |
private flashService: FlashService | |
) { } | |
ngOnInit() { | |
this.route.params.subscribe(params => { | |
this.page = +params['page']; | |
this.setUpSearch(); | |
this.getAllUsers(); | |
}); | |
} | |
private getAllUsers(): void { | |
this.content = null; | |
this.adminService.getUsersList(this.page).subscribe(users => this.content = users); | |
} | |
private setUpSearch(): void { | |
this.searchInput.valueChanges | |
.debounceTime(400) | |
.distinctUntilChanged() | |
.filter(query => { | |
if (query) { | |
return true; | |
} else { | |
this.getAllUsers(); | |
return false; | |
} | |
}) | |
.switchMap(query => { | |
return this.adminService.getUsersByQuery(query); | |
}).subscribe(users => this.content = users); | |
} | |
private changePermission(payload): void { | |
this.adminService.changeUsersPermissions(payload.userId, payload.permission).subscribe( | |
message => this.flashService.success(message.success) | |
); | |
} | |
} | |
/******* | |
JS compiled out | |
******** */ | |
"use strict"; | |
var core_1 = require('@angular/core'); | |
var forms_1 = require('@angular/forms'); | |
var AdminUserIndexComponent = (function () { | |
function AdminUserIndexComponent(route, adminService, flashService) { | |
this.route = route; | |
this.adminService = adminService; | |
this.flashService = flashService; | |
this.searchInput = new forms_1.FormControl(); | |
} | |
AdminUserIndexComponent.prototype.ngOnInit = function () { | |
var _this = this; | |
this.route.params.subscribe(function (params) { | |
_this.page = +params['page']; | |
_this.setUpSearch(); | |
_this.getAllUsers(); | |
}); | |
}; | |
AdminUserIndexComponent.prototype.getAllUsers = function () { | |
var _this = this; | |
this.content = null; | |
this.adminService.getUsersList(this.page).subscribe(function (users) { return _this.content = users; }); | |
}; | |
AdminUserIndexComponent.prototype.setUpSearch = function () { | |
var _this = this; | |
this.searchInput.valueChanges | |
.debounceTime(400) | |
.distinctUntilChanged() | |
.filter(function (query) { | |
if (query) { | |
return true; | |
} | |
else { | |
_this.getAllUsers(); | |
return false; | |
} | |
}) | |
.switchMap(function (query) { | |
return _this.adminService.getUsersByQuery(query); | |
}).subscribe(function (users) { return _this.content = users; }); | |
}; | |
AdminUserIndexComponent.prototype.changePermission = function (payload) { | |
var _this = this; | |
this.adminService.changeUsersPermissions(payload.userId, payload.permission).subscribe(function (message) { return _this.flashService.success(message.success); }); | |
}; | |
return AdminUserIndexComponent; | |
}()); | |
exports.AdminUserIndexComponent = AdminUserIndexComponent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment