Commit ea4c9182 by DESKTOP-E3GSHH7\myhr

เเก้ createdate lastdate

parent 36eb5823
...@@ -92,13 +92,13 @@ ...@@ -92,13 +92,13 @@
<td> <td>
<span class="badge bg-info/10 text-primary"> <span class="badge bg-info/10 text-primary">
<i class="bi bi-clock me-1"></i> <i class="bi bi-clock me-1"></i>
{{item.createdDate | date : 'medium'}} {{item.createdDate | date : 'dd/MM/yyyy HH:mm'}}
</span> </span>
</td> </td>
<td> <td>
<span class="badge bg-info/10 text-primary"> <span class="badge bg-info/10 text-primary">
<i class="bi bi-clock me-1"></i> <i class="bi bi-clock me-1"></i>
{{item.lastModifiedDate | date : 'medium'}} {{item.lastModifiedDate | date : 'dd/MM/yyyy HH:mm'}}
</span> </span>
</td> </td>
<td> <td>
...@@ -241,7 +241,7 @@ ...@@ -241,7 +241,7 @@
<div class="xl:col-span-6 col-span-12"> <div class="xl:col-span-6 col-span-12">
<label for="createdDate" class="mt-4 font-bold font-14 text-primary">{{'วันที่สร้าง' | translate}}</label> <label for="createdDate" class="mt-4 font-bold font-14 text-primary">{{'วันที่สร้าง' | translate}}</label>
<input type="datetime-local" class="form-control" id="createdDate" placeholder="" <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"> <div class="text-danger" *ngIf="!selectModel.createdDate">
{{'Please fill in information' | translate}} {{'Please fill in information' | translate}}
</div> </div>
...@@ -251,7 +251,7 @@ ...@@ -251,7 +251,7 @@
<label for="lastModifiedDate" class="mt-4 font-bold font-14 text-primary">{{'วันที่เเก้ไขล่าสุด' | <label for="lastModifiedDate" class="mt-4 font-bold font-14 text-primary">{{'วันที่เเก้ไขล่าสุด' |
translate}}</label> translate}}</label>
<input type="datetime-local" class="form-control" id="lastModifiedDate" placeholder="" <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"> <div class="text-danger" *ngIf="!selectModel.lastModifiedDate">
{{'Please fill in information' | translate}} {{'Please fill in information' | translate}}
</div> </div>
......
...@@ -96,7 +96,7 @@ export class ArticleManageComponent { ...@@ -96,7 +96,7 @@ export class ArticleManageComponent {
_searchTerm = ""; _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(); this.uploadConfig();
} }
...@@ -146,7 +146,7 @@ export class ArticleManageComponent { ...@@ -146,7 +146,7 @@ export class ArticleManageComponent {
console.log("res", res); console.log("res", res);
this.selectModel.picture = res.resultObject; this.selectModel.picture = res.resultObject;
swal(res.message, "บันทึกสำเร็จ", "success"); swal(res.message, "บันทึกสำเร็จ", "success");
console.log('After Upload, selectModel is:', this.selectModel); console.log('After Upload, selectModel is:', this.selectModel);
} else { } else {
this.uploadErrorMsg = "cannot upload file."; this.uploadErrorMsg = "cannot upload file.";
swal("Opp!!", "ไม่สามารถอัพโหลดได้", "info"); swal("Opp!!", "ไม่สามารถอัพโหลดได้", "info");
...@@ -154,16 +154,38 @@ export class ArticleManageComponent { ...@@ -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() { getArticle() {
this.articleService.getList().subscribe({ this.articleService.getList().subscribe({
next: (response: ArticleModel[]) => { next: (response: ArticleModel[]) => {
this.itemsList = response.map((x: any) => new ArticleModel(x, this.translate)); this.itemsList = response.map((x: any) => {
console.log('ข้อมูลบริษัท (itemsList)', this.itemsList); 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(); this.updatePagedItems();
}, },
error: (error) => { error: (error) => {
console.error('error cant get company', error); console.error('error cant get article', error);
swal("ข้อผิดพลาด", "ไม่สามารถดึงข้อมูลบริษัทได้", "error"); swal("ข้อผิดพลาด", "ไม่สามารถดึงข้อมูลบทความได้", "error");
} }
}); });
} }
...@@ -171,6 +193,7 @@ export class ArticleManageComponent { ...@@ -171,6 +193,7 @@ export class ArticleManageComponent {
ngOnInit(): void { ngOnInit(): void {
this.getArticle(); this.getArticle();
this.itemsList this.itemsList
this.updateMinDate();
} }
filter(v: string) { filter(v: string) {
...@@ -217,15 +240,37 @@ export class ArticleManageComponent { ...@@ -217,15 +240,37 @@ export class ArticleManageComponent {
this.selectModel.content = ""; this.selectModel.content = "";
this.selectModel.author = ""; this.selectModel.author = "";
this.selectModel.createdDate = new Date().toISOString(); 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) { view(item: ArticleModel) {
this.action = 'edit'; this.action = 'edit';
this.selectModel = new ArticleModel(item); this.selectModel = new ArticleModel(item);
console.log(this.selectModel); 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;
}
}
} }
viewArticleDetail(articleId: string) {
this.router.navigate(['/admin/sub-articles', articleId]); 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);
}
} }
save() { save() {
...@@ -244,6 +289,7 @@ export class ArticleManageComponent { ...@@ -244,6 +289,7 @@ export class ArticleManageComponent {
swal("บันทึกสำเร็จ!!", "บันทึกข้อมูลสมาชิก", "success"); swal("บันทึกสำเร็จ!!", "บันทึกข้อมูลสมาชิก", "success");
this.ngOnInit(); this.ngOnInit();
this.childModal?.nativeElement.click(); this.childModal?.nativeElement.click();
this.updateMinDate();
this.closeDialog(); this.closeDialog();
}, error => { }, error => {
console.error("เกิดข้อผิดพลาดในการบันทึก/อัปเดต:", error); console.error("เกิดข้อผิดพลาดในการบันทึก/อัปเดต:", error);
...@@ -398,4 +444,27 @@ export class ArticleManageComponent { ...@@ -398,4 +444,27 @@ export class ArticleManageComponent {
this.profileChangeInputRef.nativeElement.click(); this.profileChangeInputRef.nativeElement.click();
} }
} }
} private formatDateToISOString(date: Date): string {
\ No newline at end of file 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