104 lines
3.0 KiB
TypeScript
104 lines
3.0 KiB
TypeScript
import { Component, OnDestroy, OnInit, ViewEncapsulation } from '@angular/core';
|
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
|
import { Subject } from 'rxjs';
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
import { fuseAnimations } from 'src/@fuse/animations';
|
|
import { User } from 'src/modules/user/model/user.model';
|
|
import { UserService } from 'src/modules/user/service/user.service';
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
@Component({
|
|
selector: 'app-user-user-detail',
|
|
templateUrl: './user-detail.component.html',
|
|
styleUrls: ['./user-detail.component.scss'],
|
|
encapsulation: ViewEncapsulation.None,
|
|
animations: fuseAnimations
|
|
})
|
|
export class UserDetailComponent implements OnInit, OnDestroy {
|
|
user: User;
|
|
userForm: FormGroup;
|
|
|
|
// Private
|
|
private _unsubscribeAll: Subject<any>;
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param {EcommerceOrderService} userService
|
|
* @param {FormBuilder} _formBuilder
|
|
*/
|
|
constructor(
|
|
private userService: UserService,
|
|
private activatedRoute: ActivatedRoute,
|
|
private formBuilder: FormBuilder
|
|
) {
|
|
// Set the defaults
|
|
// Set the private defaults
|
|
this._unsubscribeAll = new Subject();
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
// @ Lifecycle hooks
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* On init
|
|
*/
|
|
ngOnInit(): void {
|
|
// Subscribe to update order on changes
|
|
this.activatedRoute.data.subscribe(data => {
|
|
this.user = data.user;
|
|
|
|
this.initializeForm();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* On destroy
|
|
*/
|
|
ngOnDestroy(): void {
|
|
// Unsubscribe from all subscriptions
|
|
this._unsubscribeAll.next();
|
|
this._unsubscribeAll.complete();
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
// @ Private methods
|
|
// -----------------------------------------------------------------------------------------------------
|
|
initializeForm(): void {
|
|
this.userForm = this.formBuilder.group({
|
|
username: [
|
|
{
|
|
value: this.user.username,
|
|
disabled: true
|
|
}
|
|
],
|
|
password: '',
|
|
email: this.user.email,
|
|
nickname: this.user.nickname,
|
|
phone: this.user.phone,
|
|
descriptions: this.user.descriptions
|
|
});
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------------------------------
|
|
// @ Public methods
|
|
// -----------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* Update status
|
|
*/
|
|
updateStatus(): void {
|
|
// const newStatusId = Number.parseInt(this.statusForm.get('newStatus').value);
|
|
// if (!newStatusId) {
|
|
// return;
|
|
// }
|
|
// const newStatus = this.orderStatuses.find(status => {
|
|
// return status.id === newStatusId;
|
|
// });
|
|
// newStatus['date'] = new Date().toString();
|
|
// this.order.status.unshift(newStatus);
|
|
}
|
|
}
|