[update] remove unused components
This commit is contained in:
75
src/app/core/base/base-form.ts
Normal file
75
src/app/core/base/base-form.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { Location } from '@angular/common'
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { filter, tap } from 'rxjs/operators';
|
||||
import { Directive } from '@angular/core';
|
||||
@Directive()
|
||||
export class BaseForm {
|
||||
isHideForm: boolean = environment.hideForm;
|
||||
baseFormBuilder: FormBuilder
|
||||
form: FormGroup
|
||||
state: string = 'add'
|
||||
isEdit: boolean = false
|
||||
id: number
|
||||
uid: string
|
||||
uid2: string
|
||||
path: string
|
||||
constructor(
|
||||
public _router: Router,
|
||||
public _activeRouter: ActivatedRoute,
|
||||
public fb: FormBuilder,
|
||||
public location: Location
|
||||
) {
|
||||
this.baseFormBuilder = this.fb
|
||||
this.form = this.createForm()
|
||||
|
||||
this._activeRouter.params.pipe(
|
||||
tap(x => {
|
||||
if (x.hasOwnProperty('id')) {
|
||||
x.id ? this.state = 'edit' : this.state = 'add'
|
||||
x.id ? this.isEdit = true : this.isEdit = false
|
||||
}
|
||||
if (x.hasOwnProperty('uid')) {
|
||||
x.uid ? this.state = 'edit' : this.state = 'add'
|
||||
}
|
||||
}),
|
||||
tap(x => console.log(this.state)),
|
||||
tap(x => {
|
||||
this._activeRouter.url.pipe(
|
||||
tap(x => {
|
||||
if (x[0]?.path === 'approve') {
|
||||
this.state = 'approve';
|
||||
}
|
||||
}),
|
||||
tap(x => this.path = x[0]?.path),
|
||||
// tap(x => console.log(x))
|
||||
).subscribe();
|
||||
}),
|
||||
tap(x => x.id ? this.id = x.id : this.id = null),
|
||||
tap(x => x.uid ? this.uid = x.uid : this.uid = null),
|
||||
tap(x => x.uid2 ? this.uid2 = x.uid2 : this.uid2 = null)
|
||||
).subscribe();
|
||||
}
|
||||
|
||||
|
||||
back() {
|
||||
this.location.back()
|
||||
}
|
||||
|
||||
createForm(): FormGroup {
|
||||
return this.fb.group({})
|
||||
}
|
||||
|
||||
}
|
||||
export var sortByProperty = function (property) {
|
||||
return function (x, y) {
|
||||
return ((x[property] === y[property]) ? 0 : ((x[property] > y[property]) ? 1 : -1));
|
||||
};
|
||||
|
||||
};
|
||||
export var sortByPropertyplus = function (property) {
|
||||
return function (y, x) {
|
||||
return ((y[property] === x[property]) ? 0 : ((y[property] < x[property]) ? 1 : -1));
|
||||
};
|
||||
};
|
||||
75
src/app/core/base/base-list.ts
Normal file
75
src/app/core/base/base-list.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import { Observable } from 'rxjs';
|
||||
import { Directive, Output, ViewChild, EventEmitter } from '@angular/core';
|
||||
import { MatPaginator, PageEvent } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
import { MatTableDataSource } from '@angular/material/table';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { map, startWith } from 'rxjs/operators';
|
||||
|
||||
|
||||
|
||||
export interface ResultPageEvent<T> {
|
||||
results: T[];
|
||||
current_page: number;
|
||||
page_count: number;
|
||||
page_size: number;
|
||||
row_count: number;
|
||||
first_row_on_page: number;
|
||||
last_row_on_page: number;
|
||||
}
|
||||
|
||||
export interface CustomeEventPage extends PageEvent {
|
||||
queryStringPage?: string,
|
||||
paginator?: MatPaginator
|
||||
}
|
||||
|
||||
@Directive()
|
||||
export class BaseList {
|
||||
protected INT_PAGING:CustomeEventPage = {
|
||||
length: 0,
|
||||
pageIndex: 0,
|
||||
pageSize: 5,
|
||||
previousPageIndex: null,
|
||||
queryStringPage: `0/5`,
|
||||
}
|
||||
isProduction = environment.production
|
||||
@ViewChild(MatSort,{ static: true }) sort: MatSort;
|
||||
@ViewChild(MatPaginator,{ static: true }) paginator: MatPaginator;
|
||||
@Output() onPaginatorPageChange = new EventEmitter<PageEvent>()
|
||||
|
||||
protected updateMatTable(res: any){
|
||||
if(res instanceof Array){
|
||||
res = new MatTableDataSource(res)
|
||||
res.paginator = this.paginator
|
||||
res.sort = this.sort
|
||||
return res
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
protected updatePagingMatTable<T>(data: ResultPageEvent<T>){
|
||||
// let matTable = new MatTableDataSource<T>(data.results)
|
||||
|
||||
// matTable.paginator = this.paginator
|
||||
// matTable.sort = this.sort
|
||||
// return matTable
|
||||
this.paginator.length = data.row_count
|
||||
return data.results
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected getEventPage(): Observable<PageEvent> {
|
||||
return this.paginator.page.pipe(
|
||||
startWith(this.INT_PAGING),
|
||||
map( event => {
|
||||
return {
|
||||
...event,
|
||||
paginator: this.paginator,
|
||||
queryStringPage: `${event.pageIndex + 1}/${event.pageSize}`
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
93
src/app/core/base/base-service.ts
Normal file
93
src/app/core/base/base-service.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { HttpClient, HttpEventType } from '@angular/common/http';
|
||||
import { Optional } from '@angular/core';
|
||||
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, catchError } from 'rxjs/operators';
|
||||
import { environment } from 'src/environments/environment';
|
||||
|
||||
export interface IapiResponse<T>{
|
||||
apiResponse:{
|
||||
id:number,
|
||||
desc:string,
|
||||
},
|
||||
data:Array<T>
|
||||
}
|
||||
|
||||
export class BaseService {
|
||||
|
||||
protected host:string = `${environment.APIURL}`
|
||||
protected prefix:string = `${this.host}/api`
|
||||
protected fullUrl:string = ''
|
||||
|
||||
constructor(
|
||||
endpoint:string,
|
||||
protected http: HttpClient,
|
||||
) {
|
||||
this.fullUrl = this.prefix + endpoint
|
||||
}
|
||||
|
||||
uploadDocument<HttpHeaderResponse>(target: FormData){
|
||||
return this.http.post(this.fullUrl,target,{
|
||||
reportProgress: true,
|
||||
observe:'events'
|
||||
}).pipe(
|
||||
map((event: any) => {
|
||||
switch(event.type){
|
||||
case HttpEventType.UploadProgress:
|
||||
const progress = Math.round(100 * event.loaded / event.total);
|
||||
return { status: 'progress', message: `${progress}` };
|
||||
case HttpEventType.Response:
|
||||
return { status: 'success', message: event.body };
|
||||
default:
|
||||
return `Unhandled event: ${event.type}`;
|
||||
}
|
||||
}
|
||||
),
|
||||
catchError(err => {
|
||||
return of({ status: 'error', message: `${err.message}` })
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
getAll<T>(): Observable<T[]>{
|
||||
return this.http.get<T[]>(this.fullUrl)
|
||||
}
|
||||
|
||||
add<T>(data: T): Observable<T> {
|
||||
return this.http.post<T>(this.fullUrl,data)
|
||||
}
|
||||
|
||||
get<T>(id: any): Observable<T> {
|
||||
return this.http.get<T>(`${this.fullUrl}/${id}`)
|
||||
}
|
||||
|
||||
update<T>(id: number,data: T): Observable<Response>{
|
||||
return this.http.put<Response>(`${this.fullUrl}/${id}`,data)
|
||||
}
|
||||
|
||||
update2<T>(data: T): Observable<Response>{
|
||||
return this.http.put<Response>(this.fullUrl,data)
|
||||
}
|
||||
|
||||
|
||||
deleteData(id: number | string): Observable<Response> {
|
||||
return this.http.delete<Response>(`${this.fullUrl}/${id}`)
|
||||
}
|
||||
|
||||
query<T>(query: string): Observable<T> {
|
||||
return this.http.get<T>(`${this.fullUrl}/${query}`)
|
||||
}
|
||||
|
||||
queryString<T>(query: string): Observable<T>{
|
||||
return this.http.get<T>(`${this.fullUrl}?${query}`)
|
||||
}
|
||||
|
||||
addMany<T>(data: T): Observable<T> {
|
||||
return this.http.post<T>(`${this.fullUrl}/s`,data)
|
||||
}
|
||||
|
||||
updateMany<T>(data: T): Observable<Response> {
|
||||
return this.http.put<Response>(`${this.fullUrl}/s`,data)
|
||||
}
|
||||
}
|
||||
|
||||
93
src/app/core/base/base-store-service.ts
Normal file
93
src/app/core/base/base-store-service.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { HttpClient, HttpEventType } from '@angular/common/http';
|
||||
import { Optional } from '@angular/core';
|
||||
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, catchError } from 'rxjs/operators';
|
||||
import { environment } from 'src/environments/environment';
|
||||
|
||||
export interface IapiResponse<T>{
|
||||
apiResponse:{
|
||||
id:number,
|
||||
desc:string,
|
||||
},
|
||||
data:Array<T>
|
||||
}
|
||||
|
||||
export class BaseStoreService {
|
||||
|
||||
protected host:string = `${environment.storeApi}`
|
||||
protected prefix:string = `${this.host}`
|
||||
protected fullUrl:string = ''
|
||||
|
||||
constructor(
|
||||
endpoint:string,
|
||||
protected http: HttpClient,
|
||||
) {
|
||||
this.fullUrl = this.prefix + endpoint
|
||||
}
|
||||
|
||||
uploadDocument<HttpHeaderResponse>(target: FormData){
|
||||
return this.http.post(this.fullUrl,target,{
|
||||
reportProgress: true,
|
||||
observe:'events'
|
||||
}).pipe(
|
||||
map((event) => {
|
||||
switch(event.type){
|
||||
case HttpEventType.UploadProgress:
|
||||
const progress = Math.round(100 * event.loaded / event.total);
|
||||
return { status: 'progress', message: `${progress}` };
|
||||
case HttpEventType.Response:
|
||||
return { status: 'success', message: event.body };
|
||||
default:
|
||||
return `Unhandled event: ${event.type}`;
|
||||
}
|
||||
}
|
||||
),
|
||||
catchError(err => {
|
||||
return of({ status: 'error', message: `${err.message}` })
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
getAll<T>(): Observable<T[]>{
|
||||
return this.http.get<T[]>(this.fullUrl)
|
||||
}
|
||||
|
||||
add<T>(data: T): Observable<T> {
|
||||
return this.http.post<T>(this.fullUrl,data)
|
||||
}
|
||||
|
||||
get<T>(id: any): Observable<T> {
|
||||
return this.http.get<T>(`${this.fullUrl}/${id}`)
|
||||
}
|
||||
|
||||
update<T>(id: number,data: T): Observable<Response>{
|
||||
return this.http.put<Response>(`${this.fullUrl}/${id}`,data)
|
||||
}
|
||||
|
||||
update2<T>(data: T): Observable<Response>{
|
||||
return this.http.put<Response>(this.fullUrl,data)
|
||||
}
|
||||
|
||||
|
||||
deleteData(id: number | string): Observable<Response> {
|
||||
return this.http.delete<Response>(`${this.fullUrl}/${id}`)
|
||||
}
|
||||
|
||||
query<T>(query: string): Observable<T> {
|
||||
return this.http.get<T>(`${this.fullUrl}/${query}`)
|
||||
}
|
||||
|
||||
queryString<T>(query: string): Observable<T>{
|
||||
return this.http.get<T>(`${this.fullUrl}?${query}`)
|
||||
}
|
||||
|
||||
addMany<T>(data: T): Observable<T> {
|
||||
return this.http.post<T>(`${this.fullUrl}/s`,data)
|
||||
}
|
||||
|
||||
updateMany<T>(data: T): Observable<Response> {
|
||||
return this.http.put<Response>(`${this.fullUrl}/s`,data)
|
||||
}
|
||||
}
|
||||
|
||||
5
src/app/core/configs/config.ts
Normal file
5
src/app/core/configs/config.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export const configs: {
|
||||
formatDate: string
|
||||
} = {
|
||||
formatDate: 'yyyy-MM-dd'
|
||||
}
|
||||
20
src/app/core/core.module.ts
Normal file
20
src/app/core/core.module.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
|
||||
import { TokenIntercepterInterceptor } from './intercepter/token-intercepter.interceptor';
|
||||
|
||||
@NgModule({
|
||||
declarations: [],
|
||||
imports: [
|
||||
CommonModule,
|
||||
HttpClientModule,
|
||||
],
|
||||
exports: [
|
||||
CommonModule,
|
||||
HttpClientModule,
|
||||
],
|
||||
providers: [
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: TokenIntercepterInterceptor, multi: true },
|
||||
]
|
||||
})
|
||||
export class CoreModule { }
|
||||
44
src/app/core/enum/role.ts
Normal file
44
src/app/core/enum/role.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
export enum OBJECT {
|
||||
BUILDING = 'BUILDING',
|
||||
ROOM_AND_FIELD = 'ROOM_AND_FIELD',
|
||||
REQUEST_RESERVATION = 'REQUEST_RESERVATION',
|
||||
LIST_RESERVATION = 'LIST_RESERVATION',
|
||||
LIST_BLUEPRINT = 'LIST_BLUEPRINT',
|
||||
LIST_BROKEN = 'LIST_BROKEN',
|
||||
LIST_ROOM_CLOSE = 'LIST_ROOM_CLOSE',
|
||||
EMPLOYMENT_CONTACT = 'EMPLOYMENT_CONTRACT',
|
||||
MAINTENANCE_CONTRACT = 'MAINTENANCE_CONTRACT',
|
||||
RENTAL_CONTRACT = 'RENTAL_CONTRACT',
|
||||
LIST_MAINTENANCE_CONTRACT = 'LIST_MAINTENANCE_CONTRACT',
|
||||
ASSET_LIST_CONTRACT = 'ASSET_LIST_CONTRACT',
|
||||
LOG_CONTRACT = 'LOG_CONTRACT',
|
||||
CREATE_PERMISSION = 'CREATE_PERMISSION',
|
||||
SET_PERMISSION = 'SET_PERMISSION',
|
||||
ASSET_RECEIVE = 'ASSET_RECEIVE',
|
||||
INVENTORY_RECEIVE = 'INVENTORY_RECEIVE',
|
||||
LIST_INVENTORY = 'LIST_INVENTORY',
|
||||
REQUISITION = 'REQUISITION',
|
||||
REQUISITION_PLACEMENT = 'REQUISITION_PLACEMENT',
|
||||
APPROVE_REQUISITION = 'APPROVE_REQUISITION',
|
||||
RETURN_ASSET = 'RETURN_ASSET',
|
||||
STORE_ITEMS = 'STORE_ITEMS',
|
||||
WAREHOUSE = 'WAREHOUSE',
|
||||
STORE_ITEMS_CATEGORY = 'STORE_ITEMS_CATEGORY',
|
||||
STORE_ITEMS_GROUP = 'STORE_ITEMS_GROUP',
|
||||
STORE_ITEMS_TYPE = 'STORE_ITEMS_TYPE',
|
||||
STORE_ITEMS_CLASS = 'STORE_ITEMS_CLASS',
|
||||
UNITS = 'UNITS',
|
||||
UNITS_GROUP = 'UNITS_GROUP',
|
||||
REPAIR_LIST = 'REPAIR_LIST',
|
||||
REPAIR_ORDER = 'REPAIR_ORDER',
|
||||
REPAIR_RESULT = 'REPAIR_RESULT',
|
||||
REPAIR_TYPE = 'REPAIR_TYPE',
|
||||
REPAIR_DETAIL = 'REPAIR_DETAIL',
|
||||
REPAIR_ROUTE = 'REPAIR_ROUTE',
|
||||
REPAIR_URGENT = 'REPAIR_URGENT',
|
||||
BUILDING_GROUP = 'BUILDING_GROUP',
|
||||
ROOM_GROUP = 'ROOM_GROUP',
|
||||
PURPOSE = 'PURPOSE',
|
||||
SCHEDULE_TEACHING = 'SCHEDULE_TEACHING',
|
||||
PERIOD_REQUEST = 'PERIOD_REQUEST',
|
||||
}
|
||||
29
src/app/core/guards/auth.guard.ts
Normal file
29
src/app/core/guards/auth.guard.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, Router, RouterStateSnapshot } from '@angular/router';
|
||||
// import { AppService } from './app.service';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class AppGuard implements CanActivate, CanActivateChild {
|
||||
constructor(private router: Router) {
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
return this.isLogin();
|
||||
}
|
||||
|
||||
canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
return this.isLogin();
|
||||
}
|
||||
|
||||
isLogin() {
|
||||
return true;
|
||||
// const user = this.app.auth();
|
||||
// if (!user) {
|
||||
// this.router.navigate(['/auth/login']);
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { TokenIntercepterInterceptor } from './token-intercepter.interceptor';
|
||||
|
||||
describe('TokenIntercepterInterceptor', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({
|
||||
providers: [
|
||||
TokenIntercepterInterceptor
|
||||
]
|
||||
}));
|
||||
|
||||
it('should be created', () => {
|
||||
const interceptor: TokenIntercepterInterceptor = TestBed.inject(TokenIntercepterInterceptor);
|
||||
expect(interceptor).toBeTruthy();
|
||||
});
|
||||
});
|
||||
44
src/app/core/intercepter/token-intercepter.interceptor.ts
Normal file
44
src/app/core/intercepter/token-intercepter.interceptor.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { OidcAuthService } from 'src/app/core/oidc/oidc.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
HttpRequest,
|
||||
HttpHandler,
|
||||
HttpEvent,
|
||||
HttpInterceptor
|
||||
} from '@angular/common/http';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { catchError, finalize } from 'rxjs/operators';
|
||||
import { Router } from '@angular/router';
|
||||
import { NgProgress } from 'ngx-progressbar';
|
||||
import { ApplicationSecurityService } from '../service/security/application-security.service';
|
||||
|
||||
@Injectable()
|
||||
export class TokenIntercepterInterceptor implements HttpInterceptor {
|
||||
|
||||
constructor(
|
||||
private odicSV: OidcAuthService,
|
||||
private router: Router,
|
||||
private progress: NgProgress,
|
||||
private appTokenSV: ApplicationSecurityService
|
||||
) {
|
||||
}
|
||||
|
||||
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||
const isRegisterSubjectAPI = request.url.includes('rsu-reg-api')
|
||||
const customReq = request.clone({
|
||||
setHeaders:{
|
||||
Authorization: request.url.includes('app_tokens') ? `${this.odicSV.getAuthorizationHeaderValue()}` : `Bearer ${this.appTokenSV.getToken()}`
|
||||
}
|
||||
});
|
||||
this.progress.ref('progressBar').start()
|
||||
return next.handle(customReq).pipe(
|
||||
finalize(() => this.progress.ref('progressBar').complete()),
|
||||
catchError(err => {
|
||||
if (err.status == 401) {
|
||||
this.router.navigate(['./'],{ replaceUrl: true })
|
||||
}
|
||||
return throwError(err)
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
16
src/app/core/service/manage/kyc.service.ts
Normal file
16
src/app/core/service/manage/kyc.service.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BaseService } from 'src/app/core/base/base-service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class KycService extends BaseService{
|
||||
|
||||
constructor(
|
||||
public http: HttpClient
|
||||
) {
|
||||
super('/common/kyc', http)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user