import { Component, OnInit, ViewChild } from '@angular/core'; import { UserService } from 'src/app/shared/services/user.service'; import { FeedbackPanelComponent } from 'src/app/shared/components/feedback-panel/feedback-panel.component'; import { UserFilter, User, ImportedArdaConUser } from 'tournee.businesslogic'; import { SystemAdminUserDetailComponent } from 'src/app/default-app/components/system_admin_stuff/system-admin-user-detail/system-admin-user-detail.component'; import { SystemAdminService } from 'src/app/shared/services/systemadmin.service'; @Component({ selector: 'app-system-admin-users', templateUrl: './system-admin-users.component.html', styleUrls: ['./system-admin-users.component.css'], providers: [ UserService, SystemAdminService ] }) export class SystemAdminUsersComponent implements OnInit { @ViewChild('FeedbackPanel') FeedbackPanel:FeedbackPanelComponent; @ViewChild('userDetail') UserDetail: SystemAdminUserDetailComponent; isWorking: boolean = false; Selected: User; Imported: Array = []; _expanded_section: string; Filter: UserFilter = UserFilter.create_admin(); Users: Array = []; Toggle(section) { if (this.Expanded(section)) { this._expanded_section = null; } else { this._expanded_section = section; } } ExpandCollapseText(section) { if (this.Expanded(section)) { return "Click to Collapse"; } return "Click to Expand"; } Expanded(section) { return this._expanded_section == section; } constructor(private _users: UserService, private _sysAdmin: SystemAdminService) { } ngOnInit() { } load() { if (this.isWorking) { return; } this.FeedbackPanel.reset(); this.isWorking = true; this._users.get_all_for_admin(this.Filter) .then((result) => { this.Users = result.result.map((u) => { return new User(u); }); this.isWorking = false; }) .catch((err) => { this.isWorking = false; this.FeedbackPanel.triggerError(err); }); } view_detail(user: User) { this.Selected = user; this.UserDetail.init(this.Selected); } close_detail() { this.Selected = null; setTimeout(() => { this.load(); }, 1); } onFileChange(event) { this.isWorking = true; let file = event.target.files[0]; if (!file) { this.isWorking = false; return; } const reader: FileReader = new FileReader(); reader.readAsText(file); reader.onload = () => { try { let jsonObject = JSON.parse(reader.result.toString()); let imported = jsonObject.map((i) => { return ImportedArdaConUser.import(i); }); this.Imported = imported.filter((i) => { return i.email_confirmed == true; }); } catch (error) { this.FeedbackPanel.triggerError(error); } this.isWorking = false; }; } UploadArdaConUsers() { if (this.isWorking) { return; } this.isWorking = true; this.FeedbackPanel.reset(); this._sysAdmin.importArdaConUsers(this.Imported) .then(() => { this.FeedbackPanel.triggerSuccess("ArdaCon Users Imported Successfully"); this.Imported = []; this.isWorking = false; }) .catch((err) => { this.isWorking = false; this.FeedbackPanel.triggerError(err); }); } GetUploadedArdaConUsers() { if (this.isWorking) { return; } this.isWorking = true; this.FeedbackPanel.reset(); this._sysAdmin.getUploadedArdaConUsers() .then((result) => { this.Imported = result.result.map((i) => { return new ImportedArdaConUser(i); }); this.isWorking = false; }) .catch((err) => { this.isWorking = false; this.FeedbackPanel.triggerError(err); }); } }