more work on fund details dialog
authorGalen Charlton <gmc@equinoxinitiative.org>
Wed, 24 Mar 2021 19:57:55 +0000 (15:57 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 25 Mar 2021 17:56:26 +0000 (13:56 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-details-dialog.component.html
Open-ILS/src/eg2/src/app/staff/admin/acq/funds/fund-details-dialog.component.ts
Open-ILS/src/eg2/src/app/staff/admin/acq/funds/funds-manager.component.ts

index ca24322..f166e02 100644 (file)
@@ -1,3 +1,16 @@
+<eg-string #successString i18n-text text="Fund Update Succeeded"></eg-string>
+<eg-string #updateFailedString i18n-text text="Fund Update Failed"></eg-string>
+
+<ng-template #summaryField let-field="field" let-value="value">
+  <div class="col-2">
+    <label style="font-weight: bold" for="fund-{{field}}">{{idlDef.field_map[field].label}}</label>
+  </div>
+  <div class="col-2">
+    <span id="fund-{{field}}">
+      {{value}}
+    </span>
+  </div>
+</ng-template>
 <ng-template #dialogContent>
   <div class="modal-header bg-info" *ngIf="fund">
     <h3 class="modal-title" i18n>Fund Details - {{fund.name()}} ({{fund.code()}} {{fund.year()}})</h3>
       <span aria-hidden="true">&times;</span>
     </button>
   </div>
-  <div class="modal-body">
+  <div class="modal-body" *ngIf="fund">
     <ul ngbNav #fundDetailsNav="ngbNav" class="nav-tabs">
       <li ngbNavItem>
         <a ngbNavLink i18n>Summary</a>
         <ng-template ngbNavContent>
           <div class="mt-2">
-           </div>
+            <div class="row">
+              <button class="btn btn-info ml-3" (click)="openEditDialog()" i18n>Edit Fund</button>
+            </div>
+            <div class="row">
+              <ng-container *ngTemplateOutlet="summaryField;context:{value:fund.code(),field:'code'}"></ng-container>
+              <ng-container *ngTemplateOutlet="summaryField;context:{value:fund.name(),field:'name'}"></ng-container>
+            </div>
+            <div class="row">
+              <ng-container *ngTemplateOutlet="summaryField;context:{value:fund.id(),field:'id'}"></ng-container>
+              <ng-container *ngTemplateOutlet="summaryField;context:{value:fund.year(),field:'year'}"></ng-container>
+            </div>
+            <div class="row">
+              <ng-container *ngTemplateOutlet="summaryField;context:{value:fund.org().shortname(),field:'org'}"></ng-container>
+              <ng-container *ngTemplateOutlet="summaryField;context:{value:fund.currency_type().code(),field:'currency_type'}"></ng-container>
+            </div>
+            <div class="row">
+              <ng-container *ngTemplateOutlet="summaryField;context:{value:formatCurrency(fund.combined_balance()?.amount()),field:'combined_balance'}"></ng-container>
+              <ng-container *ngTemplateOutlet="summaryField;context:{value:formatCurrency(fund.allocation_total()?.amount()),field:'allocation_total'}"></ng-container>
+            </div>
+            <div class="row">
+              <ng-container *ngTemplateOutlet="summaryField;context:{value:formatCurrency(fund.spent_balance()?.amount()),field:'spent_balance'}"></ng-container>
+              <ng-container *ngTemplateOutlet="summaryField;context:{value:formatCurrency(fund.debit_total()?.amount()),field:'debit_total'}"></ng-container>
+            </div>
+            <div class="row">
+              <ng-container *ngTemplateOutlet="summaryField;context:{value:formatCurrency(fund.spent_total()?.amount()),field:'spent_total'}"></ng-container>
+              <ng-container *ngTemplateOutlet="summaryField;context:{value:formatCurrency(fund.encumbrance_total()?.amount()),field:'encumbrance_total'}"></ng-container>
+            </div>
+          </div>
         </ng-template>
       </li>
       <li ngbNavItem>
   </div>
 </ng-template>
 
+<eg-fm-record-editor #editDialog idlClass="acqf" 
+    [fieldOptions]="fieldOptions"
+    [fieldOrder]="fieldOrder"
+    [defaultNewRecord]="defaultNewRecord"
+    [preloadLinkedValues]="true"
+    [readonlyFields]="readonlyFields">
+</eg-fm-record-editor>
index a7c8b5f..c67261e 100644 (file)
@@ -1,13 +1,17 @@
 import {Component, Input, ViewChild, TemplateRef, OnInit} from '@angular/core';
 import {DialogComponent} from '@eg/share/dialog/dialog.component';
 import {IdlService, IdlObject} from '@eg/core/idl.service';
+import {FormatService} from '@eg/core/format.service';
 import {EventService} from '@eg/core/event.service';
 import {NetService} from '@eg/core/net.service';
 import {AuthService} from '@eg/core/auth.service';
 import {PcrudService} from '@eg/core/pcrud.service';
+import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
 import {GridDataSource} from '@eg/share/grid/grid';
 import {Pager} from '@eg/share/util/pager';
 import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
+import {StringComponent} from '@eg/share/string/string.component';
+import {ToastService} from '@eg/share/toast/toast.service';
 
 @Component({
   selector: 'eg-fund-details-dialog',
@@ -19,9 +23,15 @@ export class FundDetailsDialogComponent
 
     @Input() fundId: number;
     fund: IdlObject;
+    idlDef: any;
+    fieldOrder: any;
     acqfaDataSource: GridDataSource
     acqftrDataSource: GridDataSource
     acqfdebDataSource: GridDataSource
+
+    @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent;
+    @ViewChild('successString', { static: true }) successString: StringComponent;
+    @ViewChild('updateFailedString', { static: false }) updateFailedString: StringComponent;
  
     constructor(
         private idl: IdlService,
@@ -29,6 +39,8 @@ export class FundDetailsDialogComponent
         private net: NetService,
         private auth: AuthService,
         private pcrud: PcrudService,
+        private format: FormatService,
+        private toast: ToastService,
         private modal: NgbModal
     ) {
         super(modal);
@@ -36,10 +48,12 @@ export class FundDetailsDialogComponent
     
     ngOnInit() {
         this.fund = null;
-        this.onOpen$.subscribe(() => this.initRecord());
+        this.onOpen$.subscribe(() => this._initRecord());
+        this.idlDef = this.idl.classes['acqf']
+        this.fieldOrder = 'name,code,year,org,active,currency_type,balance_stop_percentage,balance_warning_percentage,propagate,rollover';
     }
 
-    private initRecord() {
+    private _initRecord() {
         this.acqfaDataSource = this._getDataSource('acqfa', 'create_time ASC');
         this.acqftrDataSource = this._getDataSource('acqftr', 'transfer_time ASC');
         this.acqfdebDataSource = this._getDataSource('acqfdeb', 'create_time ASC');
@@ -52,7 +66,9 @@ export class FundDetailsDialogComponent
                     'spent_total',
                     'encumbrance_total',
                     'debit_total',
-                    'allocation_total'
+                    'allocation_total',
+                    'org',
+                    'currency_type'
                 ]
             }
         }).subscribe(res => this.fund = res);
@@ -107,4 +123,26 @@ export class FundDetailsDialogComponent
         return gridSource;
     }
 
+    formatCurrency(value: any) {
+        return this.format.transform({
+            value: value,
+            datatype: 'money'
+        });
+    }
+
+    openEditDialog() {
+        this.editDialog.recordId = this.fundId
+        this.editDialog.mode = 'update';
+        this.editDialog.open({size: 'lg'}).subscribe(
+            result => {
+                this.successString.current()
+                    .then(str => this.toast.success(str));
+                this._initRecord();
+            },
+            error => {
+                this.updateFailedString.current()
+                    .then(str => this.toast.danger(str));
+            }
+        );
+    }
 }
index fddaca0..50cfd0b 100644 (file)
@@ -2,6 +2,7 @@ import {Component, Input, ViewChild, OnInit} from '@angular/core';
 import {Location} from '@angular/common';
 import {FormatService} from '@eg/core/format.service';
 import {GridDataSource, GridCellTextGenerator} from '@eg/share/grid/grid';
+import {GridComponent} from '@eg/share/grid/grid.component';
 import {AdminPageComponent} from '@eg/staff/share/admin-page/admin-page.component';
 import {Pager} from '@eg/share/util/pager';
 import {ActivatedRoute} from '@angular/router';
@@ -25,6 +26,7 @@ export class FundsManagerComponent extends AdminPageComponent implements OnInit
     classLabel: string;
 
     @ViewChild('fundDetailsDialog', { static: false }) fundDetailsDialog: FundDetailsDialogComponent;
+    @ViewChild('grid', { static: true }) grid: GridComponent;
 
     cellTextGenerator: GridCellTextGenerator;
 
@@ -117,6 +119,9 @@ export class FundsManagerComponent extends AdminPageComponent implements OnInit
         if (rows.length > 0) {
             this.fundDetailsDialog.fundId = rows[0].id();
             this.fundDetailsDialog.open({size: 'xl'}).subscribe(
+                result => this.grid.reload(),
+                error => this.grid.reload(),
+                () => this.grid.reload()
             );
         }
     }