159 lines
5.0 KiB
TypeScript
159 lines
5.0 KiB
TypeScript
// ANGULAR
|
|
import { Injectable, LOCALE_ID, NgModule } from "@angular/core";
|
|
import { CommonModule, registerLocaleData } from "@angular/common";
|
|
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
|
|
|
|
// MATERIAL
|
|
import { MatTableModule } from "@angular/material/table";
|
|
import { MatPaginatorModule } from "@angular/material/paginator";
|
|
import { MatSortModule } from "@angular/material/sort";
|
|
import { MatProgressSpinnerModule } from "@angular/material/progress-spinner";
|
|
import { MatCardModule } from "@angular/material/card";
|
|
import { MatDatepickerModule } from "@angular/material/datepicker";
|
|
import { DateAdapter, MAT_DATE_FORMATS, MatNativeDateModule, MatRippleModule, NativeDateAdapter } from "@angular/material/core";
|
|
import { MatProgressBarModule } from "@angular/material/progress-bar";
|
|
import { MatButtonToggleModule } from "@angular/material/button-toggle";
|
|
import { MatGridListModule } from "@angular/material/grid-list";
|
|
import { MatExpansionModule } from "@angular/material/expansion";
|
|
import { MatAutocompleteModule } from "@angular/material/autocomplete";
|
|
import { MatButtonModule } from "@angular/material/button";
|
|
import { MatInputModule } from "@angular/material/input";
|
|
import { MAT_FORM_FIELD_DEFAULT_OPTIONS, MatFormFieldDefaultOptions, MatFormFieldModule } from "@angular/material/form-field";
|
|
import { MatTooltipModule } from "@angular/material/tooltip";
|
|
import { MatCheckboxModule } from "@angular/material/checkbox";
|
|
import { MatSelectModule } from "@angular/material/select";
|
|
import { MatIconModule } from "@angular/material/icon";
|
|
import { MatMenuModule } from "@angular/material/menu";
|
|
import { MatTabsModule } from "@angular/material/tabs";
|
|
import { MatRadioModule } from "@angular/material/radio";
|
|
import { MatDialogModule } from "@angular/material/dialog";
|
|
import { MatDividerModule } from "@angular/material/divider";
|
|
import { MatListModule } from "@angular/material/list";
|
|
import { MatSlideToggleModule } from "@angular/material/slide-toggle";
|
|
|
|
// Module
|
|
import { NgSelectModule } from "@ng-select/ng-select";
|
|
|
|
// UTIL
|
|
import { DateDiff, DateFormat, ToDateObjPipe } from "./utils/pipe";
|
|
import { CanDirective } from "./utils/can.directive";
|
|
import { AllowRoleDirective } from "./utils/allow-role.directives";
|
|
import { CurrencyInputMaskDirective } from "./@common/utils/CurrencyInputMask";
|
|
import { NumberOnlyDirective } from "./@common/utils/NumberOnlyDirective";
|
|
import { ThaidatePipe } from "./@common/utils/thaidate.pipe";
|
|
import localeTh from '@angular/common/locales/th';
|
|
registerLocaleData(localeTh)
|
|
@Injectable()
|
|
export class AppDateAdapter extends NativeDateAdapter {
|
|
format(date: Date, displayFormat: Object): string {
|
|
let monthNamesThai = ["ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.","ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค"];
|
|
date.setHours(7)
|
|
let day: string = date.getDate().toLocaleString()
|
|
day = +day < 10 ? '0' + day : day;
|
|
let year = date.getFullYear();
|
|
return `${day}/${monthNamesThai[date.getMonth()]}/${year + 543}`;
|
|
}
|
|
}
|
|
|
|
export const PICK_FORMATS = {
|
|
parse: {
|
|
dateInput: {
|
|
month: 'short',
|
|
year: 'numeric',
|
|
day: 'numeric'
|
|
}
|
|
},
|
|
display: {
|
|
dateInput: 'input',
|
|
monthYearLabel: { day: 'numeric', year: 'numeric', month: 'long' },
|
|
dateA11yLabel: { year: 'numeric', month: 'long', day: 'numeric' },
|
|
monthYearA11yLabel: { year: 'numeric', month: 'long' }
|
|
}
|
|
};
|
|
|
|
const MAT = [
|
|
MatAutocompleteModule,
|
|
MatButtonModule,
|
|
MatInputModule,
|
|
MatRippleModule,
|
|
MatFormFieldModule,
|
|
MatTooltipModule,
|
|
MatSelectModule,
|
|
MatCheckboxModule,
|
|
MatIconModule,
|
|
MatMenuModule,
|
|
MatTabsModule,
|
|
MatRadioModule,
|
|
MatDialogModule,
|
|
MatInputModule,
|
|
MatTableModule,
|
|
MatPaginatorModule,
|
|
MatSortModule,
|
|
MatProgressSpinnerModule,
|
|
MatCardModule,
|
|
MatDatepickerModule,
|
|
MatNativeDateModule,
|
|
MatRippleModule,
|
|
MatProgressBarModule,
|
|
MatRadioModule,
|
|
MatButtonToggleModule,
|
|
MatGridListModule,
|
|
MatExpansionModule,
|
|
MatDialogModule,
|
|
MatIconModule,
|
|
MatListModule,
|
|
MatDividerModule,
|
|
MatSlideToggleModule,
|
|
];
|
|
|
|
const appearance: MatFormFieldDefaultOptions = {
|
|
appearance: 'outline'
|
|
};
|
|
|
|
const BASE_MODULES = [
|
|
CommonModule,
|
|
FormsModule,
|
|
ReactiveFormsModule
|
|
];
|
|
|
|
const MODULES = [
|
|
MatAutocompleteModule,
|
|
NgSelectModule,
|
|
...MAT
|
|
];
|
|
|
|
|
|
const COMPONENTS = [
|
|
AllowRoleDirective,
|
|
CanDirective,
|
|
];
|
|
|
|
const PIPES = [
|
|
ToDateObjPipe,
|
|
DateFormat,
|
|
DateDiff,
|
|
CurrencyInputMaskDirective,
|
|
NumberOnlyDirective,
|
|
ThaidatePipe
|
|
];
|
|
|
|
const PROVIDERS: any = [
|
|
{
|
|
provide: MAT_FORM_FIELD_DEFAULT_OPTIONS,
|
|
useValue: appearance
|
|
},
|
|
{ provide: LOCALE_ID, useValue: 'th-TH' },
|
|
{ provide: MAT_DATE_FORMATS, useValue: PICK_FORMATS },
|
|
{ provide: DateAdapter, useClass: AppDateAdapter },
|
|
// { provide: LOCALE_ID, useValue: "en-GB" }
|
|
];
|
|
|
|
@NgModule({
|
|
imports: [...BASE_MODULES, ...MODULES],
|
|
exports: [...BASE_MODULES, ...MODULES, ...COMPONENTS, ...PIPES],
|
|
declarations: [...COMPONENTS, ...PIPES],
|
|
providers: [...PROVIDERS],
|
|
})
|
|
export class AppSharedModule {
|
|
}
|