Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactoring components/service for primeng #1204

Merged
merged 7 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ npm-debug.log
yarn-error.log
testem.log
/typings
.nx

# System Files
.DS_Store
Expand Down
15 changes: 13 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,19 @@
"output": "/assets/"
}
],
"styles": [],
"scripts": []
"styles": [
"node_modules/primeng/resources/themes/bootstrap4-light-blue/theme.css",
"node_modules/primeng/resources/primeng.min.css",
"node_modules/primeicons/primeicons.css",
"node_modules/primeflex/primeflex.min.css"
],
"scripts": [],
"vendorChunk": true,
"extractLicenses": false,
"buildOptimizer": false,
"sourceMap": true,
"optimization": false,
"namedChunks": true
},
"configurations": {
"production": {
Expand Down
33 changes: 22 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,11 @@
"issn": "^1.0.6",
"js-generate-password": "^0.1.9",
"lodash-es": "^4.17.21",
"luxon": "^3.4.0",
"luxon": "^3.5.0",
"marked": "^10.0.0",
"moment": "^2.30.1",
"ngx-bootstrap": "^12.0.0",
"ngx-spinner": "^16.0.0",
"ngx-toastr": "^18.0.0",
"primeflex": "^3.3.1",
"primeicons": "^6.0.1",
"primeng": "^17.14.1",
Expand Down Expand Up @@ -133,6 +132,7 @@
"karma-jasmine-html-reporter": "~2.1.0",
"karma-spec-reporter": "0.0.36",
"ng-packagr": "^17.1.1",
"primelocale": "^1.0.3",
"typescript": "~5.3.3"
},
"files": [
Expand Down
28 changes: 13 additions & 15 deletions projects/admin/src/app/acquisition/acquisition.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { FormlyModule, FORMLY_CONFIG } from '@ngx-formly/core';
import { FORMLY_CONFIG, FormlyModule } from '@ngx-formly/core';
import { FormlyPrimeNGModule } from '@ngx-formly/primeng';
import { TranslateService } from '@ngx-translate/core';
import { ApiService, CoreModule, RecordModule } from '@rero/ng-core';
import { SharedModule } from '@rero/shared';
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { PopoverModule } from 'ngx-bootstrap/popover';
import { TabsModule } from 'ngx-bootstrap/tabs';
import { PreviewEmailModule } from '../shared/preview-email/preview-email.module';
import { PrimengImportModule } from '../shared/primeng-import/primeng-import.module';
import { AcquisitionRoutingModule } from './acquisition-routing.module';
import { AcqAccountApiService } from './api/acq-account-api.service';
import { AcqOrderApiService } from './api/acq-order-api.service';
Expand All @@ -39,29 +41,26 @@ import { OrderBriefViewComponent } from './components/order/order-brief-view/ord
import { OrderDetailViewComponent } from './components/order/order-detail-view/order-detail-view.component';
import { OrderLineComponent } from './components/order/order-detail-view/order-line/order-line.component';
import { OrderLinesComponent } from './components/order/order-detail-view/order-lines/order-lines.component';
import { OrderEmailFormComponent } from './components/order/order-email-form/order-email-form.component';
import { OrderSummaryComponent } from './components/order/order-summary/order-summary.component';
import { ReceiptDetailViewComponent } from './components/receipt/receipt-detail-view/receipt-detail-view.component';
import { OrderReceipt } from './components/receipt/receipt-form/order-receipt';
import { OrderReceiptForm } from './components/receipt/receipt-form/order-receipt-form';
import { OrderReceiptViewComponent } from './components/receipt/receipt-form/order-receipt-view.component';
import { OrderSummaryComponent } from './components/order/order-summary/order-summary.component';
import { ReceiptListComponent } from './components/receipt/receipt-list/receipt-list.component';
import { ReceiptSummaryComponent } from './components/receipt/receipt-summary/receipt-summary.component';
import { registerFormlyExtension } from './formly/extension';
import { FieldDocumentBriefViewTypeComponent } from './formly/type/field-document-brief-view.type';
import { FieldRefTypeComponent } from './formly/type/field-ref.type';
import { RepeatTypeComponent } from './formly/type/repeat-section.type';
import { SelectAccountComponent } from './formly/type/select-account/select-account.component';
import { InputNoLabelWrapperComponent } from './formly/wrapper/input-no-label.wrapper';
import { AccountAvailableAmountPipe } from './pipes/account-available-amount.pipe';
import { NegativeAmountPipe } from './pipes/negative-amount.pipe';
import { ReceiptSummaryComponent } from './components/receipt/receipt-summary/receipt-summary.component';
import { ReceiptDetailViewComponent } from './components/receipt/receipt-detail-view/receipt-detail-view.component';
import { NoteBadgeColorPipe } from './pipes/note-badge-color.pipe';
import { AccountAvailableAmountPipe } from './pipes/account-available-amount.pipe';
import { ReceptionDatesPipe } from './pipes/reception-dates.pipe';
import { PreviewContentPipe } from './pipes/preview-content.pipe';
import { ReceiptLineTotalAmountPipe } from './pipes/receipt-line-total-amount.pipe';
import { PermissionsService, SharedModule } from '@rero/shared';
import { OrderEmailFormComponent } from './components/order/order-email-form/order-email-form.component';
import { PreviewEmailModule } from '../shared/preview-email/preview-email.module';
import { FormlyPrimeNGModule } from '@ngx-formly/primeng';
import { ReceptionDatesPipe } from './pipes/reception-dates.pipe';

@NgModule({
declarations: [
Expand Down Expand Up @@ -96,7 +95,6 @@ import { FormlyPrimeNGModule } from '@ngx-formly/primeng';
],
imports: [
BsDropdownModule.forRoot(),
PopoverModule.forRoot(),
CommonModule,
AcquisitionRoutingModule,
FormlyModule,
Expand All @@ -114,10 +112,10 @@ import { FormlyPrimeNGModule } from '@ngx-formly/primeng';
]
}),
RecordModule,
TabsModule,
CoreModule,
SharedModule,
PreviewEmailModule
PreviewEmailModule,
PrimengImportModule
],
providers: [
{ provide: FORMLY_CONFIG, multi: true, useFactory: registerFormlyExtension, deps: [TranslateService] },
Expand Down
30 changes: 11 additions & 19 deletions projects/admin/src/app/acquisition/api/acq-account-api.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RERO ILS UI
* Copyright (C) 2021 RERO
* Copyright (C) 2021-2024 RERO
* Copyright (C) 2021 UCLouvain
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -17,7 +17,7 @@
*/

import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { Record, RecordService } from '@rero/ng-core';
import { Error } from '@rero/ng-core/lib/error/error';
import { Observable } from 'rxjs';
Expand All @@ -29,6 +29,9 @@ import { IAcqAccount } from '../classes/account';
})
export class AcqAccountApiService {

private httpClient: HttpClient = inject(HttpClient);
private recordService: RecordService = inject(RecordService);

// SERVICES ATTRIBUTES ======================================================
/** The resource name of acquisition account */
resourceName = 'acq_accounts';
Expand Down Expand Up @@ -57,17 +60,6 @@ export class AcqAccountApiService {
remaining_balance: this.allocatedAmountDefaultData
};

// SERVICE CONSTRUCTORS =====================================================
/**
* Constructor
* @param _http: HttpClient
* @param _recordService - RecordService
*/
constructor(
private _http: HttpClient,
private _recordService: RecordService
) {}

// SERVICES FUNCTIONS =======================================================

/**
Expand All @@ -76,10 +68,10 @@ export class AcqAccountApiService {
* @returns the corresponding account
*/
getAccount(accountPid: string): Observable<IAcqAccount> {
return this._recordService
return this.recordService
.getRecords(this.resourceName, `pid:${accountPid}`, 1, 1)
.pipe(
map((result: Record) => this._recordService.totalHits(result.hits.total) === 0 ? [] : result.hits.hits),
map((result: Record) => this.recordService.totalHits(result.hits.total) === 0 ? [] : result.hits.hits),
map((hits: any[]) => hits.map((hit: any) => ({...this.accountDefaultData, ...hit.metadata}) )),
map((hits: IAcqAccount[]) => hits.find(Boolean)) // Get first element of array if exists
);
Expand All @@ -103,10 +95,10 @@ export class AcqAccountApiService {
}
const query = defaultQueryParams.join(' AND ');
options = { ...{sort: 'name'}, ...options }; // add some default params
return this._recordService
return this.recordService
.getRecords(this.resourceName, query, 1, RecordService.MAX_REST_RESULTS_SIZE, undefined, undefined, undefined, options.sort)
.pipe(
map((result: Record) => this._recordService.totalHits(result.hits.total) === 0 ? [] : result.hits.hits),
map((result: Record) => this.recordService.totalHits(result.hits.total) === 0 ? [] : result.hits.hits),
map((hits: any[]) => hits.map(hit => ({...this.accountDefaultData, ...hit.metadata}) ))
);
}
Expand All @@ -117,7 +109,7 @@ export class AcqAccountApiService {
* @return The observable on delete REST call.
*/
delete(pid: string): Observable<void | Error> {
return this._recordService.delete(this.resourceName, pid);
return this.recordService.delete(this.resourceName, pid);
}

/**
Expand All @@ -133,6 +125,6 @@ export class AcqAccountApiService {
.set('source', sourcePid)
.set('target', targetPid)
.set('amount', amount.toString());
return this._http.get<any>(apiUrl, { params });
return this.httpClient.get<any>(apiUrl, { params });
}
}
30 changes: 11 additions & 19 deletions projects/admin/src/app/acquisition/api/acq-budget-api.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* RERO ILS UI
* Copyright (C) 2021 RERO
* Copyright (C) 2021-2024 RERO
* Copyright (C) 2021 UCLouvain
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -15,43 +15,35 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { Injectable } from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { Record, RecordService } from '@rero/ng-core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { AcqAccountApiService } from './acq-account-api.service';
import { IAcqAccount } from '../classes/account';
import { AcqBudget } from '../classes/budget';
import { AcqAccountApiService } from './acq-account-api.service';

@Injectable({
providedIn: 'root'
})
export class AcqBudgetApiService {

private recordService: RecordService = inject(RecordService);
private acqAccountApiService: AcqAccountApiService = inject(AcqAccountApiService);

/** The resource name of acquisition budget */
resourceName = 'budgets';

/**
* Constructor
* @param _recordService - RecordService
* @param _acqAccountApiService - AcqAccountApiService
*/
constructor(
private _recordService: RecordService,
private _acqAccountApiService: AcqAccountApiService
) { }


/**
* Get the budget corresponding to filters.
* @param query: query to apply to find records
* @return an observable of budget
*/
getBudgets(query?: string): Observable<AcqBudget[]> {
query = query || '';
return this._recordService.getRecords(this.resourceName, query, 1, RecordService.MAX_REST_RESULTS_SIZE)
return this.recordService.getRecords(this.resourceName, query, 1, RecordService.MAX_REST_RESULTS_SIZE)
.pipe(
map((result: Record) => this._recordService.totalHits(result.hits.total) === 0 ? [] : result.hits.hits),
map((result: Record) => this.recordService.totalHits(result.hits.total) === 0 ? [] : result.hits.hits),
map((hits: any[]) => hits.map((hit: any) => new AcqBudget(hit.metadata)))
);
}
Expand All @@ -62,11 +54,11 @@ export class AcqBudgetApiService {
* @return An observable with the total amount for this budget.
*/
getBudgetTotalAmount(budgetPid: string): Observable<number> {
return this._recordService
return this.recordService
.getRecords('acq_accounts', `budget.pid:${budgetPid} AND depth:0`, 1, RecordService.MAX_REST_RESULTS_SIZE)
.pipe(
map((result: Record) => this._recordService.totalHits(result.hits.total) === 0 ? [] : result.hits.hits),
map((hits: any[]) => hits.map((hit: any) => ({...this._acqAccountApiService.accountDefaultData, ...hit.metadata}) )),
map((result: Record) => this.recordService.totalHits(result.hits.total) === 0 ? [] : result.hits.hits),
map((hits: any[]) => hits.map((hit: any) => ({...this.acqAccountApiService.accountDefaultData, ...hit.metadata}) )),
map((accounts: IAcqAccount[]) => accounts.reduce((total, acc) => total + acc.allocated_amount, 0))
);
}
Expand Down
Loading
Loading