Commit ea4c9182 by DESKTOP-E3GSHH7\myhr

เเก้ createdate lastdate

parent 36eb5823
......@@ -92,13 +92,13 @@
<td>
<span class="badge bg-info/10 text-primary">
<i class="bi bi-clock me-1"></i>
{{item.createdDate | date : 'medium'}}
{{item.createdDate | date : 'dd/MM/yyyy HH:mm'}}
</span>
</td>
<td>
<span class="badge bg-info/10 text-primary">
<i class="bi bi-clock me-1"></i>
{{item.lastModifiedDate | date : 'medium'}}
{{item.lastModifiedDate | date : 'dd/MM/yyyy HH:mm'}}
</span>
</td>
<td>
......@@ -241,7 +241,7 @@
<div class="xl:col-span-6 col-span-12">
<label for="createdDate" class="mt-4 font-bold font-14 text-primary">{{'วันที่สร้าง' | translate}}</label>
<input type="datetime-local" class="form-control" id="createdDate" placeholder=""
[(ngModel)]="selectModel.createdDate">
[(ngModel)]="selectModel.createdDate" (ngModelChange)="updateMinDate()">
<div class="text-danger" *ngIf="!selectModel.createdDate">
{{'Please fill in information' | translate}}
</div>
......@@ -251,7 +251,7 @@
<label for="lastModifiedDate" class="mt-4 font-bold font-14 text-primary">{{'วันที่เเก้ไขล่าสุด' |
translate}}</label>
<input type="datetime-local" class="form-control" id="lastModifiedDate" placeholder=""
[(ngModel)]="selectModel.lastModifiedDate">
[(ngModel)]="selectModel.lastModifiedDate" [min]="selectModel.createdDate">
<div class="text-danger" *ngIf="!selectModel.lastModifiedDate">
{{'Please fill in information' | translate}}
</div>
......
......@@ -96,7 +96,7 @@ export class ArticleManageComponent {
_searchTerm = "";
constructor(private articleService: ArticleService, public translate: TranslateService, private tokenService: TokenService, private router: Router,private dialog: MatDialog,) {
constructor(private articleService: ArticleService, public translate: TranslateService, private tokenService: TokenService, private router: Router, private dialog: MatDialog,) {
this.uploadConfig();
}
......@@ -154,16 +154,38 @@ export class ArticleManageComponent {
};
}
// getArticle() {
// this.articleService.getList().subscribe({
// next: (response: ArticleModel[]) => {
// this.itemsList = response.map((x: any) => new ArticleModel(x, this.translate));
// console.log('ข้อมูลบริษัท (itemsList)', this.itemsList);
// this.updatePagedItems();
// },
// error: (error) => {
// console.error('error cant get company', error);
// swal("ข้อผิดพลาด", "ไม่สามารถดึงข้อมูลบริษัทได้", "error");
// }
// });
// }
getArticle() {
this.articleService.getList().subscribe({
next: (response: ArticleModel[]) => {
this.itemsList = response.map((x: any) => new ArticleModel(x, this.translate));
console.log('ข้อมูลบริษัท (itemsList)', this.itemsList);
this.itemsList = response.map((x: any) => {
const article = new ArticleModel(x, this.translate);
if (x.createdDate) {
article.createdDate = this.formatDateToISOString(new Date(x.createdDate));
}
if (x.lastModifiedDate) {
article.lastModifiedDate = this.formatDateToISOString(new Date(x.lastModifiedDate));
}
return article;
});
console.log('ข้อมูลบทความ (itemsList)', this.itemsList);
this.updatePagedItems();
},
error: (error) => {
console.error('error cant get company', error);
swal("ข้อผิดพลาด", "ไม่สามารถดึงข้อมูลบริษัทได้", "error");
console.error('error cant get article', error);
swal("ข้อผิดพลาด", "ไม่สามารถดึงข้อมูลบทความได้", "error");
}
});
}
......@@ -171,6 +193,7 @@ export class ArticleManageComponent {
ngOnInit(): void {
this.getArticle();
this.itemsList
this.updateMinDate();
}
filter(v: string) {
......@@ -217,15 +240,37 @@ export class ArticleManageComponent {
this.selectModel.content = "";
this.selectModel.author = "";
this.selectModel.createdDate = new Date().toISOString();
const now = new Date();
this.selectModel.createdDate = this.formatDateToISOString(now);
this.selectModel.lastModifiedDate = this.formatDateToISOString(now);
}
view(item: ArticleModel) {
this.action = 'edit';
this.selectModel = new ArticleModel(item);
console.log(this.selectModel);
if (this.selectModel.createdDate) {
const createdDateObj = new Date(this.selectModel.createdDate);
this.selectModel.createdDate = this.formatDateToISOString(createdDateObj);
}
if (this.selectModel.lastModifiedDate) {
const lastModifiedDateObj = new Date(this.selectModel.lastModifiedDate);
this.selectModel.lastModifiedDate = this.formatDateToISOString(lastModifiedDateObj);
} else {
if (this.selectModel.createdDate) {
this.selectModel.lastModifiedDate = this.selectModel.createdDate;
}
}
}
private formatDatesForDatetimeLocal(articleModel: ArticleModel): void {
if (articleModel.createdDate) {
articleModel.createdDate = articleModel.createdDate.substring(0, 16);
}
if (articleModel.lastModifiedDate) {
articleModel.lastModifiedDate = articleModel.lastModifiedDate.substring(0, 16);
}
viewArticleDetail(articleId: string) {
this.router.navigate(['/admin/sub-articles', articleId]);
}
save() {
......@@ -244,6 +289,7 @@ export class ArticleManageComponent {
swal("บันทึกสำเร็จ!!", "บันทึกข้อมูลสมาชิก", "success");
this.ngOnInit();
this.childModal?.nativeElement.click();
this.updateMinDate();
this.closeDialog();
}, error => {
console.error("เกิดข้อผิดพลาดในการบันทึก/อัปเดต:", error);
......@@ -398,4 +444,27 @@ export class ArticleManageComponent {
this.profileChangeInputRef.nativeElement.click();
}
}
private formatDateToISOString(date: Date): string {
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');
return `${year}-${month}-${day}T${hours}:${minutes}`;
}
updateMinDate() {
if (this.selectModel.createdDate) {
const created = new Date(this.selectModel.createdDate);
let modified = this.selectModel.lastModifiedDate ? new Date(this.selectModel.lastModifiedDate) : null;
if (modified && modified < created) {
// เมื่อมีการปรับค่า ให้แน่ใจว่าถูกจัดรูปแบบเป็น 24 ชั่วโมง
this.selectModel.lastModifiedDate = this.formatDateToISOString(created);
} else if (!modified) {
// เมื่อมีการตั้งค่าเริ่มต้น ให้แน่ใจว่าถูกจัดรูปแบบเป็น 24 ชั่วโมง
this.selectModel.lastModifiedDate = this.formatDateToISOString(created);
}
}
}
}
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