Commit 9aadc9ca by Natthaphat

ปิดไม่ให้กรอก ID

parent 00d8b8af
......@@ -7,11 +7,11 @@ import swal from 'sweetalert';
import { MatPaginator, PageEvent } from "@angular/material/paginator";
import { SharedModule } from "../../../shared/shared.module";
import { UserProfileModel } from "../../models/user.model";
import { UserService } from "../../services/user.service";
import { TokenService } from "../../../shared/services/token.service";
import { FileUploadModule } from 'ng2-file-upload';
import { FileItem, FileUploader, ParsedResponseHeaders } from "ng2-file-upload";
import { environment } from "../../../../environments/environment";
import { AdminService } from "../../services/admin.service";
@Component({
selector: 'app-admin-manage',
......@@ -22,9 +22,8 @@ import { environment } from "../../../../environments/environment";
TranslateModule,
NgSelectModule,
FormsModule,
MatPaginator,
FileUploadModule
],
],
templateUrl: './admin-manage.component.html',
styleUrl: './admin-manage.component.css'
})
......@@ -59,7 +58,7 @@ export class AdminManageComponent {
}
_searchTerm = "";
constructor(private userService: UserService, public translate: TranslateService, private tokenService: TokenService) {
constructor(private adminService: AdminService, public translate: TranslateService, private tokenService: TokenService) {
this.uploadConfig()
}
......@@ -116,7 +115,7 @@ export class AdminManageComponent {
ngOnInit(): void {
this.userService.getLists().subscribe(result => {
this.adminService.getLists().subscribe(result => {
this.itemsList = result.filter(e => e.role == 99)
this.updatePagedItems()
})
......@@ -146,7 +145,7 @@ export class AdminManageComponent {
})
.then((willDelete: any) => {
if (willDelete) {
this.userService.delete(item).subscribe(result => {
this.adminService.delete(item).subscribe(result => {
swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success");
this.ngOnInit()
})
......@@ -180,14 +179,14 @@ export class AdminManageComponent {
if (willDelete) {
this.selectModel.role = 99
if (this.action == 'add') {
this.userService.save(this.selectModel).subscribe(result => {
this.adminService.save(this.selectModel).subscribe(result => {
console.log(result)
swal("Save Success!!", "บันทึกข้อมูลสมาชิก", "success");
this.ngOnInit()
this.childModal?.nativeElement.click()
})
} else if (this.action == 'edit') {
this.userService.update(this.selectModel).subscribe(result => {
this.adminService.update(this.selectModel).subscribe(result => {
console.log(result)
swal("Update Success!!", "บันทึกข้อมูลสมาชิก", "success");
this.ngOnInit()
......@@ -248,7 +247,7 @@ export class AdminManageComponent {
if (isSelected) {
const user = this.itemsList.find(user => user.memberId === memberId);
if (user) {
this.userService.delete(user).subscribe(result => {
this.adminService.delete(user).subscribe(result => {
swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success");
this.ngOnInit();
});
......@@ -284,7 +283,7 @@ export class AdminManageComponent {
const user = this.itemsList.find(user => user.memberId === memberId);
if (user) {
user.status = status
this.userService.update(user).subscribe(result => {
this.adminService.update(user).subscribe(result => {
swal("Save Success!!", "บันทึกข้อมูลสำเร็จ", "success");
this.ngOnInit();
});
......
......@@ -224,7 +224,7 @@
</div>
</div>
<div class="xl:col-span-12 col-span-12">
<div class="xl:col-span-12 col-span-12" *ngIf="modalStatus=='edit'">
<label for="deal-title" class="form-label">{{'Candidate ID' | translate}}</label>
<input type="text" class="form-control" [ngClass]="{ '!bg-input-readonly': action === 'edit' }"
id="deal-title" placeholder="" [(ngModel)]="selectModel.candidateId" [readonly]="action === 'edit'">
......@@ -356,7 +356,7 @@
data-hs-overlay="#modal-detail">
{{'Cancel' | translate}}
</button>
<button type="button" (click)="save()" class="ti-btn bg-primary text-white !font-medium"
<button type="button" *ngIf="modalStatus=='add'" (click)="save()" class="ti-btn bg-primary text-white !font-medium"
[class.ti-btn-disabled]="
!selectModel.candidateId ||
!selectModel.thFirstname ||
......
......@@ -124,9 +124,7 @@ export class UserSettingComponent {
this.userService.getListsProfile().subscribe(result => {
this.itemsList = result.map(item => new UserProfileModel(item, this.translate));
this.filterList = [...this.itemsList];
});
this.userService.getListsProfile().subscribe(email => {
this.existingEmails = email;
this.existingEmails = result;
});
}
......
import { TranslateService } from "@ngx-translate/core"
import { BaseModel } from "./base.model"
import { RoleModel } from "./role.model"
import { ProfileModel } from "./profile.model"
export interface AuthModel {
username: string
password: string
role: RoleModel
profile: ProfileModel
}
export class AuthModel extends BaseModel implements AuthModel {
username: string
password: string
role: RoleModel
profile: ProfileModel
constructor(data?: Partial<AuthModel>, translateService?: TranslateService) {
super(data, translateService)
this.username = data?.username!
this.password = data?.password!
this.role = data?.role ? new RoleModel(data.role, translateService) : data?.role!
this.profile = data?.profile ? new ProfileModel(data.profile, translateService) : data?.profile!
}
}
......
......@@ -28,7 +28,7 @@ import { RelationShipModel } from "./relationship.model";
import { ReligionModel } from "./religion.model";
import { SubDistrictModel } from "./subdistrict.model";
import { JobTypeModel } from "./job-type.model";
import { environment } from "src/environments/environment";
import { environment } from "../../../environments/environment";
export interface ProfileModel {
addressCurrent: string
......@@ -39,6 +39,7 @@ export interface ProfileModel {
buildingCurrent: string
buildingEmergency: string
buildingHome: string
candidateId: string
carEndDate: string
carLicense: number
carLicenseNumber: string
......@@ -188,6 +189,7 @@ export class ProfileModel extends BaseModel implements ProfileModel {
buildingCurrent: string
buildingEmergency: string
buildingHome: string
candidateId: string
carEndDate: string
carLicense: number
carLicenseNumber: string
......@@ -310,6 +312,7 @@ export class ProfileModel extends BaseModel implements ProfileModel {
this.buildingCurrent = checkData(data?.buildingCurrent)
this.buildingEmergency = checkData(data?.buildingEmergency)
this.buildingHome = checkData(data?.buildingHome)
this.candidateId = checkData(data?.candidateId)
this.carEndDate = checkData(data?.carEndDate)
this.carLicense = checkData(data?.carLicense)
this.carLicenseNumber = checkData(data?.carLicenseNumber)
......@@ -425,7 +428,7 @@ export class ProfileModel extends BaseModel implements ProfileModel {
}
getPicture() {
return this.picture ? (environment.url + "/files/image/" + this.picture) : null
return this.picture ? (environment.baseUrl + "/files/image/" + this.picture) : null
}
getName() {
......@@ -896,14 +899,22 @@ export class ProfileLoginModel extends BaseModel implements ProfileLoginModel {
}
getAge(){
getStatus(): string {
if (this.status == 1) {
return this.translateService.instant('Active');
} else {
return this.translateService.instant('Unactive');
}
}
getAge() {
var ageDifMs = Date.now() - new Date(this.birthday).getTime();
var ageDate = new Date(ageDifMs); // miliseconds from epoch
return Math.abs(ageDate.getUTCFullYear() - 1970);
}
getPicture() {
return this.picture ? (environment.url + "/files/image/" + this.picture) : (this.sex == 1 ? "assets/img/icon/icon_female.png" : "assets/img/icon/icon_male.png")
return this.picture ? (environment.baseUrl + "/files/image/" + this.picture) : (this.sex == 1 ? "assets/img/icon/icon_female.png" : "assets/img/icon/icon_male.png")
}
getName() {
......@@ -960,7 +971,7 @@ export class ProfileLoginModel extends BaseModel implements ProfileLoginModel {
return baseGetName(this.thFullName, this.engFullName, this.translateService.currentLang)
}
getNickName(){
getNickName() {
return baseGetName(this.thNickName, this.engNickName, this.translateService.currentLang)
}
}
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { TokenService } from '../../shared/services/token.service';
import { UserProfileModel } from '../models/user.model';
import { map, tap, switchMap, filter, reduce } from "rxjs/operators";
import { PageResponseModel, ResponseModel } from '../models/base.model';
import { forkJoin, Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class AdminService {
apiBaseUrl = "/admin";
constructor(
private http: HttpClient,
private translateService: TranslateService
) { }
getById(id: Number) {
return this.http
.get<UserProfileModel>(this.apiBaseUrl + "/" + id)
.pipe(map((e) => new UserProfileModel(e, this.translateService)));
}
getByUsername(username: string) {
return this.http
.get<UserProfileModel>(this.apiBaseUrl + "/username/" + username)
}
getLists() {
return this.http
.get<UserProfileModel[]>(this.apiBaseUrl)
.pipe(
map((e) => e.map((e) => new UserProfileModel(e, this.translateService)))
);
}
getListsProfile() {
return this.http
.get<UserProfileModel[]>(this.apiBaseUrl + '/manage-profile/lists')
// .pipe(
// map((e) => e.map((e) => new UserProfileModel(e, this.translateService)))
// );
}
getListByPageSize(body: { page: number; size: number }) {
return this.http
.get<PageResponseModel<UserProfileModel>>(this.apiBaseUrl, {
params: body,
})
.pipe(
map((page) => {
return {
...page,
content: page.content.map(
(e) => new UserProfileModel(e, this.translateService)
),
};
})
);
}
getListAllPageSize(): Observable<UserProfileModel[]> {
return this.http
.get<PageResponseModel<UserProfileModel>>(this.apiBaseUrl, {
params: { page: 0, size: 1 },
})
.pipe(
switchMap((checkData: any) => {
//console.log("checkData="+checkData)
const size = 500;
const numOfPages = checkData.totalElements / size;
const parallelList: Observable<PageResponseModel<UserProfileModel>>[] = [];
for (let page = 0; page < numOfPages; page++) {
parallelList.push(
this.getListByPageSize({
page,
size,
})
);
}
return forkJoin(parallelList).pipe(
map((response) => {
let data: UserProfileModel[] = [];
for (let i = 0; i < response.length; i++) {
data = data.concat(response[i].content);
}
return data;
})
);
})
);
}
save(body: UserProfileModel) {
return this.http.post<ResponseModel>(this.apiBaseUrl + '/manage-profile', new UserProfileModel(body));
}
update(body: UserProfileModel) {
return this.http.post<ResponseModel>(this.apiBaseUrl + "/manage-profile", new UserProfileModel(body));
}
resetPass(email: string) {
let tempBody = {
"email": email
}
return this.http.put<ResponseModel>(this.apiBaseUrl + "/send-reset-password", tempBody);
}
resetPassUser(oldPassword: string, password: string) {
let tempBody = {
"oldPassword": oldPassword,
"password": password
}
return this.http.put<ResponseModel>(this.apiBaseUrl + "/reset-password", tempBody);
}
delete(body: UserProfileModel) {
const options = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
body: new UserProfileModel(body) // ส่งข้อมูลใน body
};
return this.http.delete<ResponseModel>(this.apiBaseUrl + "/manage-profile", options);
}
}
......@@ -6,12 +6,14 @@ import { UserProfileModel } from '../models/user.model';
import { map, tap, switchMap, filter, reduce } from "rxjs/operators";
import { PageResponseModel, ResponseModel } from '../models/base.model';
import { forkJoin, Observable } from 'rxjs';
import { AuthModel } from '../models/auth.model';
@Injectable({
providedIn: 'root'
})
export class UserService {
apiBaseUrl = "/admin";
apiAuthUrl = "/auth"
constructor(
private http: HttpClient,
private translateService: TranslateService
......@@ -100,6 +102,10 @@ export class UserService {
);
}
register(authModel: AuthModel) {
return this.http.post<ResponseModel>(this.apiAuthUrl + '/register', authModel);
}
save(body: UserProfileModel) {
return this.http.post<ResponseModel>(this.apiBaseUrl + '/manage-profile', new UserProfileModel(body));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment