[update] settings menu

This commit is contained in:
2023-10-17 02:29:58 +07:00
parent 36efa12651
commit 63a58292d5
39 changed files with 1213 additions and 5 deletions

View File

@@ -0,0 +1,99 @@
<form [formGroup]="form" class="dialog-main form-dialog" autocomplete="off">
<div class="dialog-main">
<div class="dialog-header flex justify-between">
<h2>Banner</h2>
<mat-icon mat-dialog-close class="cursor-pointer">clear</mat-icon>
</div>
<div class="dialog-body">
<div class="grid grid-cols-12 gap-4 md:gap-2 ">
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">ชื่อรายการ</mat-label>
<mat-form-field class="col-span-7">
<input matInput required formControlName="name" type="text">
</mat-form-field>
<span class="col-span-1"></span>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">Link</mat-label>
<mat-form-field class="col-span-3">
<input matInput required formControlName="link" type="text">
</mat-form-field>
<span class="col-span-5"></span>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label
class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">คำอธิบาย</mat-label>
<mat-form-field class="col-span-7">
<textarea matInput formControlName="description" type="text"></textarea>
</mat-form-field>
<span class="col-span-1"></span>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label
class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">วันเริ่มต้น/สิ้นสุด</mat-label>
<mat-form-field class="col-span-2">
<input matInput formControlName="start_date" [matDatepicker]="startDate" readonly />
<mat-datepicker-toggle [for]="startDate" matSuffix></mat-datepicker-toggle>
<mat-datepicker #startDate></mat-datepicker>
</mat-form-field>
<mat-form-field class="col-span-2">
<input matInput formControlName="end_date" [matDatepicker]="endDate" readonly />
<mat-datepicker-toggle [for]="endDate" matSuffix></mat-datepicker-toggle>
<mat-datepicker #endDate></mat-datepicker>
</mat-form-field>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">แนบรูป</mat-label>
<div class="col-span-7">
<div class="list-images" style="min-height: auto !important;" *ngIf="data">
<div class=" grid grid-cols-12 gap-2 md:gap-2 items-center">
<div class="col-span-2 md:col-span-4">
<div class="flex justify-center items-center list-images-item">
<div class="list-images-action">
<i (click)="onRemoveAttachments()"class="bi bi-x-circle color-red cursor-pointer select-none"></i>
</div>
<img (click)="onAttachmentsView()" src="" alt="">
</div>
</div>
</div>
</div>
<div class="mt-4">
<input hidden type="file" accept="image/*" #uploadFile (change)="onAttachments($event)" />
<button type="button" class="btn btn-sm btn-success-o" (click)="uploadFile.click()">เพิ่มแนบไฟล์</button>
</div>
</div>
<span class="col-span-1"></span>
</div>
</div>
<div class="col-span-full">
<div class="lg:flex lg:flex-col grid grid-cols-9 gap-2">
<mat-label class="col-span-1 lg:text-left lg:self-auto text-right self-center mr-4">Open/Close</mat-label>
<mat-slide-toggle formControlName="is_use"></mat-slide-toggle>
<span class="col-span-1"></span>
</div>
</div>
</div>
</div>
<div class="dialog-footer">
<button type="submit" mat-raised-button class="btn btn-submit" (click)="save()" [disabled]="form.invalid">บันทึก</button>
<button type="button" mat-dialog-close class="btn btn-dialog-close">ยกเลิก</button>
</div>
</div>
</form>
<!-- <pre>{{form.getRawValue() | json}}</pre> -->

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { DialogComponent } from './dialog.component';
describe('DialogComponent', () => {
let component: DialogComponent;
let fixture: ComponentFixture<DialogComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ DialogComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(DialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,143 @@
import { Location } from '@angular/common';
import { ChangeDetectorRef, Component, Inject, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import { catchError, tap, throwError } from 'rxjs';
import { IDialogConfigData } from 'src/app/@common/interface/Dialog';
import { EAction, EText } from 'src/app/@config/app';
import { AppService } from 'src/app/app.service';
import { BaseForm } from 'src/app/core/base/base-form';
import { BannerService } from 'src/app/core/service/common/banner.service';
@Component({
selector: 'app-dialog',
templateUrl: './dialog.component.html',
styleUrls: ['./dialog.component.scss']
})
export class DialogComponent extends BaseForm implements OnInit {
data = false;
constructor(
public dialogRef: MatDialogRef<DialogComponent>,
@Inject(MAT_DIALOG_DATA) public dialog: IDialogConfigData,
public router: Router,
public activatedRoute: ActivatedRoute,
public fb: FormBuilder,
public location: Location,
public bannerService: BannerService,
public appService: AppService,
public cdr: ChangeDetectorRef
) {
super(router, activatedRoute, fb, location)
}
ngOnInit(): void {
if (this.dialog.action === EAction.UPDATE){
this.state = 'edit';
this.getData();
}
}
createForm(): FormGroup<any> {
return this.fb.group({
status_id: null,
created_by: null,
created_datetime: null,
updated_by: null,
updated_datetime: null,
owner_agency_uid: null,
banner_uid: null,
name: [null, Validators.required],
link: [null, Validators.required],
description: null,
start_date: [null, Validators.required],
end_date: [null, Validators.required],
file_name: null,
file_url: [null],
is_use: false
})
}
getData() {
if (!this.dialog.ids) this.appService.message(EAction.INFO, EText.NO_DATA);
this.bannerService.get(this.dialog.ids).pipe(
tap((res) => this.form.patchValue(res)),
tap(() => this.cdr.detectChanges()),
catchError((err) => {
this.appService.message(EAction.ERROR, EText.ERROR);
return throwError(() => err)
})
).subscribe()
}
save() {
const form = this.form.getRawValue();
const save$ = this.state === 'edit' ? this.bannerService.update2(form) : this.bannerService.add(form);
return save$.pipe(
tap(() => this.appService.message(EAction.SUCCESS, EText.UPDATE)),
tap(() => this.dialogRef.close('success')),
catchError((err) => {
this.appService.message(EAction.ERROR, EText.ERROR);
return throwError(() => err)
})
).subscribe()
}
// async onSubmit(form: any) {
// if (!form.valid) return false;
// const sweetalert = await lastValueFrom(this.appService.confirm(EAction.CREATE));
// if (!sweetalert.isConfirmed) return;
// this.dataForm.images = this.attachments?.[0] ? this.attachments.join(",") : null;
// this.dataForm.pageAction = 'financePaying';
// return await this.onUpdate();
// }
// async onUpdate() {
// try {
// await lastValueFrom(this.appService.post(`${this.api.quotation}/update/${this.ids}`, this.dataForm));
// await this.appService.message(EAction.SUCCESS, EText.UPDATE);
// await this.router.navigate(["/pages/finance/paying/list", this.action]);
// } catch (err) {
// this.appService.message(EAction.ERROR, EText.ERROR);
// }
// }
async onAttachments($event: any) {
const file = $event.target.files[0];
if (!file) return;
const formData = new FormData();
formData.append("ref", 'images');
formData.append("file", file);
// try {
// const res = await lastValueFrom(this.appService.post(`${API.attachments}/images`, formData));
// this.dataForm.sellerPaymentImages = res.fileName;
// this.uploadFile.nativeElement.value = null;
// this.changeDetectorRef.detectChanges();
// } catch (e) {
// this.appService.message(EText.ERROR);
// }
}
async onRemoveAttachments() {
// const sweetalert = await lastValueFrom(this.appService.confirm(EAction.DELETE));
// if (!sweetalert.isConfirmed) return;
// this.dataForm.paymentImages = null;
// this.changeDetectorRef.detectChanges();
}
async onAttachmentsView() {
// const dialogConfig = deepCopy(this.dialogConfig);
// dialogConfig.data.action = EAction.POPUP;
// dialogConfig.data.title = 'ไฟล์แนบ';
// dialogConfig.data.type = 'images';
// dialogConfig.data.images = this.dataForm.sellerPaymentImages;
// const dialogRef = this.attachmentsView.open(AttachmentsViewComponent, dialogConfig);
// const afterClosed = await lastValueFrom(dialogRef.afterClosed());
}
}

View File

@@ -0,0 +1,83 @@
<div class="card card-table">
<div class="card-filter text-right">
<div class="card-filter-section grid grid-cols-12 gap-4 md:gap-2 items-center">
<div class="col-span-4 md:col-span-6">
<mat-form-field>
<i matTextPrefix class="bi bi-search"></i>
<input matInput placeholder="ชื่อรายการ">
</mat-form-field>
</div>
<div class="col-span-8 md:col-span-6">
<button type="button" class="btn btn-create" (click)="onAdd()">
<i class="bi bi-plus"></i>
เพิ่มรายการ
</button>
</div>
</div>
</div>
<div class="card-body">
<div class="table-wrap">
<table class="table table-main" mat-table [dataSource]="bannerList" matSort>
<tr mat-header-row *matHeaderRowDef="['1','2','3','4','5','6','7','8']"></tr>
<tr mat-row *matRowDef="let row; columns: ['1','2','3','4','5','6','7','8'];"></tr>
<ng-container matColumnDef="1">
<th mat-header-cell *matHeaderCellDef class="tac" mat-sort-header>ลำดับ</th>
<td mat-cell *matCellDef="let item; let i = index" width="150" class="tac">{{getIndex(i)}}</td>
</ng-container>
<ng-container matColumnDef="2">
<th mat-header-cell *matHeaderCellDef class="tal">ชื่อรายการ</th>
<td mat-cell *matCellDef="let item" class="" style="min-width: 200px;">
{{item.name}}
</td>
</ng-container>
<ng-container matColumnDef="3">
<th mat-header-cell *matHeaderCellDef class="tal" mat-sort-header>Link</th>
<td mat-cell *matCellDef="let item" class="">{{item.link}}</td>
</ng-container>
<ng-container matColumnDef="4">
<th mat-header-cell *matHeaderCellDef class="tal" mat-sort-header>คำอธิบาย</th>
<td mat-cell *matCellDef="let item" class="">{{item.description}}</td>
</ng-container>
<ng-container matColumnDef="5">
<th mat-header-cell *matHeaderCellDef class="tal" width="150">วันเริ่มต้น</th>
<td mat-cell *matCellDef="let item" class="">{{item.start_date | date : 'dd/MM/YYYY'}}</td>
</ng-container>
<ng-container matColumnDef="6">
<th mat-header-cell *matHeaderCellDef class="tal" width="150">วันสิ้นสุด</th>
<td mat-cell *matCellDef="let item" class="">{{item.weight | date : 'dd/MM/YYYY'}}</td>
</ng-container>
<ng-container matColumnDef="7">
<th mat-header-cell *matHeaderCellDef class="tal" width="150">สถานะ</th>
<td mat-cell *matCellDef="let item" class="">{{item.is_use === true? 'Open' : 'Close'}}</td>
</ng-container>
<ng-container matColumnDef="8">
<th mat-header-cell *matHeaderCellDef class="tal" width="150">เครื่องมือ</th>
<td mat-cell *matCellDef="let item" class="">
<div class="action flex justify-center">
<div class="item">
<i class="bi bi-filetype-pdf color-main" (click)="onEdit(item.banner_uid)"></i>
</div>
<div class="item">
<i class="bi bi-trash3 color-red" (click)="onDelete(item.banner_uid)"></i>
</div>
</div>
</td>
</ng-container>
</table>
</div>
<!-- <div *ngIf="dataSourceCount === 0" class="no-data"></div> -->
<mat-paginator [pageSizeOptions]="[5,10,20]" showFirstLastButtons></mat-paginator>
</div>
</div>

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ListComponent } from './list.component';
describe('ListComponent', () => {
let component: ListComponent;
let fixture: ComponentFixture<ListComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ListComponent ]
})
.compileComponents();
fixture = TestBed.createComponent(ListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,32 @@
import { Component, EventEmitter, Input, OnChanges, Output } from '@angular/core';
import { DialogComponent } from '../dialog/dialog.component';
import { BaseList } from 'src/app/core/base/base-list';
import { EAction } from 'src/app/@config/app';
import { filter, lastValueFrom, switchMap, tap } from 'rxjs';
import { MatDialog } from '@angular/material/dialog';
@Component({
selector: 'app-list',
templateUrl: './list.component.html',
styleUrls: ['./list.component.scss']
})
export class ListComponent extends BaseList implements OnChanges {
@Input() bannerList: any = [];
@Output() add = new EventEmitter();
@Output() edit = new EventEmitter();
constructor() {
super()
}
ngOnChanges(){
this.bannerList = this.updateMatTable(this.bannerList? this.bannerList : [])
}
onAdd() {
this.add.emit()
}
onEdit(uid){
this.edit.emit(uid)
}
}