Skip to content

Commit

Permalink
budgets: add component budget and accounts
Browse files Browse the repository at this point in the history
* Adds brief and detail views for budget.
* Adds list of acquisition accounts for current library on budget detail view.
* Adds detail view for organisation.
* Adds default budget option on organisation detail view.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
Garfield-fr committed Jan 10, 2020
1 parent 83895cb commit 666c71b
Show file tree
Hide file tree
Showing 22 changed files with 770 additions and 30 deletions.
21 changes: 19 additions & 2 deletions projects/admin/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ import { RemoteAutocompleteInputTypeComponent } from './record/editor/remote-aut
import { NoCacheHeaderInterceptor } from './interceptor/no-cache-header.interceptor';
import { InterfaceInfoComponent } from './interface-info/interface-info.component';
import { DocumentEditorComponent } from './record/custom-editor/document-editor/document-editor.component';
import { BudgetsBriefViewComponent } from './record/brief-view/budgets-brief-view.component';
import { BudgetDetailViewComponent } from './record/detail-view/budget-detail-view/budget-detail-view.component';
import { AcqAccountsComponent } from './record/detail-view/budget-detail-view/acq-accounts/acq-accounts.component';
import { AcqAccountComponent } from './record/detail-view/budget-detail-view/acq-account/acq-account.component';
import { OrganisationDetailViewComponent } from './record/detail-view/organisation-detail-view/organisation-detail-view.component';
import { BudgetSelectComponent } from './record/detail-view/organisation-detail-view/budget-select/budget-select.component';
import { BudgetSelectLineComponent } from './record/detail-view/organisation-detail-view/budget-select-line/budget-select-line.component';

@NgModule({
declarations: [
Expand Down Expand Up @@ -126,7 +133,14 @@ import { DocumentEditorComponent } from './record/custom-editor/document-editor/
PatronDetailViewComponent,
InterfaceInfoComponent,
RefComponent,
RemoteAutocompleteInputTypeComponent
RemoteAutocompleteInputTypeComponent,
BudgetsBriefViewComponent,
BudgetDetailViewComponent,
AcqAccountsComponent,
AcqAccountComponent,
OrganisationDetailViewComponent,
BudgetSelectComponent,
BudgetSelectLineComponent
],
imports: [
AppRoutingModule,
Expand Down Expand Up @@ -202,7 +216,10 @@ import { DocumentEditorComponent } from './record/custom-editor/document-editor/
ItemDetailViewComponent,
PatronDetailViewComponent,
RefComponent,
RemoteAutocompleteInputTypeComponent
RemoteAutocompleteInputTypeComponent,
BudgetsBriefViewComponent,
BudgetDetailViewComponent,
OrganisationDetailViewComponent
],
bootstrap: [AppComponent]
})
Expand Down
14 changes: 12 additions & 2 deletions projects/admin/src/app/menu/menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ export class MenuComponent implements OnInit {
routerLink: '/records/persons',
iconCssClass: 'fa fa-user'
}]
}, {
name: this.translateService.instant('Acquisitions'),
iconCssClass: 'fa fa-university',
entries: [{
name: this.translateService.instant('Budgets'),
routerLink: '/records/budgets',
}]
}, {
name: this.translateService.instant('Admin & Monitoring'),
iconCssClass: 'fa fa-cogs',
Expand All @@ -189,7 +196,11 @@ export class MenuComponent implements OnInit {
routerLink: '/records/patron_types',
iconCssClass: 'fa fa-users'
}, {
name: this.translateService.instant('My Library'),
name: this.translateService.instant('My organisation'),
routerLink: `/records/organisations/detail/${this.userService.getCurrentUser().library.organisation.pid}`,
iconCssClass: 'fa fa-university'
}, {
name: this.translateService.instant('My library'),
routerLink: this.myLibraryRouterLink(),
iconCssClass: 'fa fa-university'
}, {
Expand All @@ -206,7 +217,6 @@ export class MenuComponent implements OnInit {
(element: any) => element.routerLink.indexOf('/libraries/detail') > -1
);
link.routerLink = this.myLibraryRouterLink();

});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* RERO ILS UI
* Copyright (C) 2019 RERO
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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 { Component, Input } from '@angular/core';
import { ResultItem } from '@rero/ng-core';

@Component({
selector: 'admin-budgets-brief-view',
template: `
<h5 class="card-title mb-0 rero-ils-person">
<a [routerLink]="[detailUrl.link]" class="pr-1">{{ record.metadata.name }}</a>
</h5>
`,
styles: []
})
export class BudgetsBriefViewComponent implements ResultItem {

@Input()
record: any;

@Input()
type: string;

@Input()
detailUrl: { link: string, external: boolean };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
RERO ILS UI
 Copyright (C) 2019 RERO

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as published by
 the Free Software Foundation, version 3 of the License.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU Affero General Public License for more details.

 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/>.
-->
<div class="row">
<div class="col-sm-7">
<h5 class="mb-0">{{ account.metadata.name }}</h5>
{{ account.metadata.description }}
</div>
<div class="col-sm-2 text-right">
{{ account.metadata.amount_allocated | currency:currencyCode:'symbol' }}
</div>
<div class="col-sm-3 text-right">
<button *ngIf="!account.permissions.cannot_update" type="button" class="btn btn-primary btn-sm"
[routerLink]="['/records', 'acq_accounts', 'edit', account.metadata.pid]">
<i class="fa fa-pencil"></i> {{ 'Edit' | translate }}
</button>

<button *ngIf="!account.permissions.cannot_delete; else notDelete" type="button" class="btn btn-primary btn-sm ml-1"
(click)="delete(account.metadata.pid)">
<i class="fa fa-trash"></i> {{ 'Delete' | translate }}
</button>
<ng-template #notDelete>
<button type="button" class="btn btn-dark btn-sm ml-1" (click)="showDeleteMessage(account)">
<i class="fa fa-trash"></i> {{ 'Delete' | translate }}
</button>
</ng-template>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* RERO ILS UI
* Copyright (C) 2019 RERO
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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 { Component, Input, Output, EventEmitter } from '@angular/core';
import { RecordUiService } from '@rero/ng-core';
import { RecordPermissionMessageService } from 'projects/admin/src/app/service/record-permission-message.service';

@Component({
selector: 'admin-acq-account',
templateUrl: './acq-account.component.html'
})
export class AcqAccountComponent {

@Input() account: any;

@Input() currencyCode: string;

@Output() deleteAcqAccount = new EventEmitter();

constructor(
private recordUiService: RecordUiService,
private recordPermissionMessage: RecordPermissionMessageService
) { }

/**
* Delete Acquisition account
* @param acqAccountPid - Acquisition account pid
*/
delete(acqAccountPid: string) {
this.recordUiService.deleteRecord('acq_accounts', acqAccountPid)
.subscribe((success: any) => {
if (success) {
this.deleteAcqAccount.emit(acqAccountPid);
}
});
}

/**
* Display message if the record cannot be deleted
* @param acqAccount - Acquisition Account record
*/
public showDeleteMessage(acqAccount: object) {
const message = this.recordPermissionMessage.generateMessage(acqAccount);
this.recordUiService.showDeleteMessage(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--
RERO ILS UI
 Copyright (C) 2019 RERO

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as published by
 the Free Software Foundation, version 3 of the License.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU Affero General Public License for more details.

 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/>.
-->
<h4 class="mt-4" translate>Acquisition accounts</h4>
<a
class="btn btn-sm btn-primary"
[routerLink]="['/', 'records', 'acq_accounts', 'new']"
[queryParams]="{ budget: budgetPid }"
>
<i class="fa fa-plus-square-o"></i> {{ 'Add' | translate }}
</a>
<ng-container *ngIf="accounts">
<ul class="list-group list-group-flush mt-3">
<li class="list-group-item" *ngFor="let account of accounts">
<admin-acq-account
[account]="account"
[currencyCode]="currencyCode"
(deleteAcqAccount)="delete($event)"
></admin-acq-account>
</li>
</ul>
</ng-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* RERO ILS UI
* Copyright (C) 2019 RERO
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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 { Component, OnInit, Input } from '@angular/core';
import { UserService } from 'projects/admin/src/app/service/user.service';
import { RecordService } from '@rero/ng-core';
import { map, mergeMap } from 'rxjs/operators';

@Component({
selector: 'admin-acq-accounts',
templateUrl: './acq-accounts.component.html'
})
export class AcqAccountsComponent implements OnInit {

@Input() budgetPid: string;

accounts: Array<any>;

currencyCode: string;

constructor(
private userService: UserService,
private recordService: RecordService
) { }

ngOnInit() {
this.loadAcqAccounts();
}

delete(acqAccountPid: string) {
this.accounts = this.accounts.filter(
acqAccount => acqAccountPid !== acqAccount.metadata.pid
);
}

private loadAcqAccounts() {
const currentLibrary = this.userService.getCurrentUser().getCurrentLibrary();
this.recordService.getRecord('libraries', currentLibrary, 1).pipe(
map(library => {
return library.metadata.organisation.pid;
}),
mergeMap(orgPid => this.recordService.getRecord('organisations', orgPid))
).subscribe(organisation => {
this.currencyCode = organisation.metadata.default_currency;
const query = `budget.pid:${this.budgetPid} AND library.pid:${currentLibrary}`;
this.recordService.getRecords(
'acq_accounts', query, 1, RecordService.MAX_REST_RESULTS_SIZE
).subscribe(result => {
if (result.hits.total > 0) {
this.accounts = result.hits.hits;
}
});
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--
RERO ILS UI
 Copyright (C) 2019 RERO

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as published by
 the Free Software Foundation, version 3 of the License.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU Affero General Public License for more details.

 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/>.
-->
<ng-container *ngIf="record$ | async as record">
<header class="row">
<h1 class="mb-1">{{ record.metadata.name }}</h1>
</header>
<section>
<admin-acq-accounts
[budgetPid]="record.metadata.pid"
></admin-acq-accounts>
</section>
</ng-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* RERO ILS UI
* Copyright (C) 2019 RERO
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* 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 { Component } from '@angular/core';
import { DetailRecord } from '@rero/ng-core/lib/record/detail/view/detail-record';
import { Observable } from 'rxjs';

@Component({
selector: 'admin-budget-detail-view',
templateUrl: './budget-detail-view.component.html'
})
export class BudgetDetailViewComponent implements DetailRecord {

record$: Observable<any>;

type: string;
}
Loading

0 comments on commit 666c71b

Please sign in to comment.