Skip to content

Commit

Permalink
title: refactoring MainTitle service as a pipe.
Browse files Browse the repository at this point in the history
Refactoring MainTitleService as a pipe. It allows to use it more easely
into components because we don't need to importt the service and create
repetitive memthod in each component to get a document main title

Co-Authored-by: Renaud Michotte <renaud.michotte@gmail.com>
  • Loading branch information
zannkukai committed Apr 15, 2020
1 parent d42a52d commit fc8c7cf
Show file tree
Hide file tree
Showing 47 changed files with 236 additions and 414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ import { TranslateModule } from '@ngx-translate/core';
import { CoreModule, RecordModule } from '@rero/ng-core';
import { CollapseModule } from 'ngx-bootstrap';
import { UserService } from '../../service/user.service';
import { SharedPipesModule } from '../../shared/shared-pipes.module';
import { ItemComponent } from '../item/item.component';
import { ItemsListComponent } from '../items-list/items-list.component';
import { CardComponent } from '../patron/card/card.component';
import { CheckinComponent } from './checkin.component';


describe('CheckoutComponent', () => {
describe('CheckinComponent', () => {
let component: CheckinComponent;
let fixture: ComponentFixture<CheckinComponent>;

Expand Down Expand Up @@ -58,7 +59,8 @@ describe('CheckoutComponent', () => {
HttpClientModule,
RouterTestingModule,
CollapseModule,
BrowserAnimationsModule
BrowserAnimationsModule,
SharedPipesModule
],
declarations: [
CardComponent,
Expand Down
4 changes: 2 additions & 2 deletions projects/admin/src/app/circulation/item/item.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<!-- TITLE -->
<div class="col-lg-4"><a
[routerLink]="['/records','documents','detail', item.document.pid]"
*ngIf="getMainTitle(item.document.title) != null">
{{ getMainTitle(item.document.title) | truncateText: 12 }}</a>
*ngIf="(item.document.title | mainTitle) != null">
{{ item.document.title | mainTitle | truncateText: 12 }}</a>
</div>
<!-- CIRCULATION INFO -->
<div class="col-lg-3">
Expand Down
19 changes: 10 additions & 9 deletions projects/admin/src/app/circulation/item/item.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ItemComponent } from './item.component';
import { TranslateModule } from '@ngx-translate/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CollapseModule } from 'ngx-bootstrap';
import { CoreModule, RecordModule } from '@rero/ng-core';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientModule } from '@angular/common/http';
import { CollapseModule } from 'ngx-bootstrap';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { LoanComponent } from '../patron/loan/loan.component';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule } from '@ngx-translate/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ItemComponent } from './item.component';
import { ItemsListComponent } from '../items-list/items-list.component';
import { LoanComponent } from '../patron/loan/loan.component';
import { SharedPipesModule } from '../../shared/shared-pipes.module';

describe('ItemComponent', () => {
let component: ItemComponent;
Expand All @@ -23,7 +23,8 @@ describe('ItemComponent', () => {
RouterTestingModule,
HttpClientModule,
CollapseModule,
BrowserAnimationsModule
BrowserAnimationsModule,
SharedPipesModule
],
declarations: [
LoanComponent,
Expand Down
12 changes: 1 addition & 11 deletions projects/admin/src/app/circulation/item/item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { RecordService } from '@rero/ng-core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { MainTitleService } from '../../service/main-title.service';
import { OrganisationService } from '../../service/organisation.service';
import { Item, ItemAction, Loan, LoanState } from '../items';
import { PatronTransactionService } from '../patron-transaction.service';
Expand Down Expand Up @@ -66,8 +65,7 @@ export class ItemComponent implements OnInit {
constructor(
private recordService: RecordService,
private organisationService: OrganisationService,
private patronTransactionService: PatronTransactionService,
private _mainTitleService: MainTitleService
private patronTransactionService: PatronTransactionService
) { }

/**
Expand Down Expand Up @@ -124,12 +122,4 @@ export class ItemComponent implements OnInit {
get organisation() {
return this.organisationService.organisation;
}

/**
* Get main title (correspondig to 'bf_Title' type, present only once in metadata)
* @param titleMetadata: title metadata
*/
getMainTitle(titleMetadata: any): string {
return this._mainTitleService.getMainTitle(titleMetadata);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ItemsListComponent } from './items-list.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CollapseModule } from 'ngx-bootstrap';
import { CoreModule, RecordModule } from '@rero/ng-core';
import { HttpClientModule } from '@angular/common/http';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule } from '@ngx-translate/core';
import { CoreModule, RecordModule } from '@rero/ng-core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ItemComponent } from '../item/item.component';
import { HttpClientModule } from '@angular/common/http';
import { CollapseModule } from 'ngx-bootstrap';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ItemsListComponent } from './items-list.component';
import { SharedPipesModule } from '../../shared/shared-pipes.module';


describe('ItemsListComponent', () => {
let component: ItemsListComponent;
Expand All @@ -39,7 +40,8 @@ describe('ItemsListComponent', () => {
RecordModule,
HttpClientModule,
CollapseModule,
BrowserAnimationsModule
BrowserAnimationsModule,
SharedPipesModule
],
declarations: [
ItemsListComponent,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,23 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule } from '@ngx-translate/core';
import { RecordModule } from '@rero/ng-core';
import { RequestedItemsListComponent } from '../requested-items-list/requested-items-list.component';
import { MainRequestComponent } from './main-request.component';
import { RequestedItemsListComponent } from '../requested-items-list/requested-items-list.component';
import { SharedPipesModule } from '../../shared/shared-pipes.module';

describe('MainRequestComponent', () => {
let component: MainRequestComponent;
let fixture: ComponentFixture<MainRequestComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [RecordModule, RouterTestingModule, HttpClientModule, TranslateModule.forRoot()],
imports: [
RecordModule,
RouterTestingModule,
HttpClientModule,
TranslateModule.forRoot(),
SharedPipesModule
],
declarations: [ MainRequestComponent, RequestedItemsListComponent ]
})
.compileComponents();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import { ItemsService } from '../items.service';

@Component({
selector: 'admin-circulation-main-request',
templateUrl: './main-request.component.html',
styleUrls: ['./main-request.component.scss']
templateUrl: './main-request.component.html'
})
export class MainRequestComponent implements OnInit {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
<i [ngClass]="{ 'fa-caret-down': !isCollapsed, 'fa-caret-right': isCollapsed }" class="fa" aria-hidden="true"></i>
</button>
<a [routerLink]="['/records','documents','detail', document.metadata.pid]"
*ngIf="getMainTitle(document.metadata.title) != null">
*ngIf="(document.metadata.title | mainTitle) != null">
<ng-container *ngIf="isCollapsed; else titleNotCollapsed">
{{ getMainTitle(document.metadata.title) | truncateText: 10 }}
{{ document.metadata.title | mainTitle | truncateText: 10 }}
</ng-container>
<ng-template #titleNotCollapsed>
{{ getMainTitle(document.metadata.title) }}
{{ document.metadata.title | mainTitle }}
</ng-template>
</a>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Component, Input, OnInit } from '@angular/core';
import { extractIdOnRef, RecordService } from '@rero/ng-core';
import { forkJoin } from 'rxjs';
import { ProvisionActivityType } from '../../../../pipe/provision-activity.pipe';
import { MainTitleService } from '../../../../service/main-title.service';
import { PatronService } from '../../../../service/patron.service';

@Component({
Expand Down Expand Up @@ -36,8 +35,7 @@ export class HistoryItemComponent implements OnInit {
*/
constructor(
private _recordService: RecordService,
private _patronService: PatronService,
private _mainTitleService: MainTitleService
private _patronService: PatronService
) { }

/**
Expand All @@ -63,14 +61,4 @@ export class HistoryItemComponent implements OnInit {
});
}
}

/**
* Get main title (corresponding to 'bf_Title' type, present only once in metadata)
* @param titleMetadata: title metadata
* @return string: the document main title, `null` if not found
*/
getMainTitle(titleMetadata: any): string {
return this._mainTitleService.getMainTitle(titleMetadata);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@

import { HttpClientModule } from '@angular/common/http';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule } from '@ngx-translate/core';
import { CoreModule, RecordModule } from '@rero/ng-core';
import { CollapseModule } from 'ngx-bootstrap';
import { ItemComponent } from '../../item/item.component';
import { ItemsListComponent } from '../../items-list/items-list.component';
import { LoanComponent } from './loan.component';
import { ItemComponent } from '../../item/item.component';
import { ItemsService } from '../../items.service';
import { ToastrService } from 'ngx-toastr';
import { CollapseModule } from 'ngx-bootstrap';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { SharedPipesModule } from '../../../shared/shared-pipes.module';
import { UserService } from '../../../service/user.service';


Expand Down Expand Up @@ -59,7 +58,8 @@ describe('LoanComponent', () => {
RouterTestingModule,
HttpClientModule,
CollapseModule,
BrowserAnimationsModule
BrowserAnimationsModule,
SharedPipesModule
],
declarations: [
LoanComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { HttpClientModule } from '@angular/common/http';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { PatronTransactionEventFormComponent } from './patron-transaction-event-form.component';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { FormlyModule } from '@ngx-formly/core';
import { CoreModule } from '@rero/ng-core';
import { TranslateModule } from '@ngx-translate/core';
import { HttpClientModule } from '@angular/common/http';
import { CoreModule } from '@rero/ng-core';
import { BsModalRef } from 'ngx-bootstrap';
import { RouterTestingModule } from '@angular/router/testing';
import { PatronTransactionEventFormComponent } from './patron-transaction-event-form.component';

describe('PatronTransactionEventFormComponent', () => {
let component: PatronTransactionEventFormComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { HttpClientModule } from '@angular/common/http';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { TranslateModule } from '@ngx-translate/core';
import { CoreModule, RecordModule } from '@rero/ng-core';
import { PatronTransactionEventComponent } from './patron-transaction-event.component';
import { HttpClientModule } from '@angular/common/http';
import { TranslateModule } from '@ngx-translate/core';

describe('PatronTransactionEventComponent', () => {
let component: PatronTransactionEventComponent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ <h6 translate>Details</h6>
<div class="col-sm-2 label-title text-right" translate>Document</div>
<div class="col-sm-10">
<a [routerLink]="['/records','documents','detail', transaction.document.pid]"
*ngIf="getMainTitle(document.metadata.title) != null">
{{ getMainTitle(document.metadata.title) | truncateText: 15 }}
*ngIf="(document.metadata.title | mainTitle) != null">
{{ document.metadata.title | mainTitle | truncateText: 15 }}
</a>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { HttpClientModule } from '@angular/common/http';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { PatronTransactionComponent } from './patron-transaction.component';
import { CoreModule, RecordModule } from '@rero/ng-core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { RouterTestingModule } from '@angular/router/testing';
import { PatronTransactionEventComponent } from '../patron-transaction-event/patron-transaction-event.component';
import { HttpClientModule } from '@angular/common/http';
import { TranslateModule } from '@ngx-translate/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { CoreModule, RecordModule } from '@rero/ng-core';
import { SharedPipesModule } from '../../../../shared/shared-pipes.module';
import { PatronTransactionEventComponent } from '../patron-transaction-event/patron-transaction-event.component';
import { PatronTransactionComponent } from './patron-transaction.component';

describe('PatronTransactionComponent', () => {
let component: PatronTransactionComponent;
Expand All @@ -20,7 +20,8 @@ describe('PatronTransactionComponent', () => {
RouterTestingModule,
HttpClientModule,
TranslateModule.forRoot(),
BrowserAnimationsModule
BrowserAnimationsModule,
SharedPipesModule
],
declarations: [
PatronTransactionComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, Input, OnInit } from '@angular/core';
import { RecordService } from '@rero/ng-core';
import { BsModalService } from 'ngx-bootstrap';
import { MainTitleService } from 'projects/admin/src/app/service/main-title.service';
import { map, mergeMap } from 'rxjs/operators';
import { OrganisationService } from '../../../../service/organisation.service';
import { Item } from '../../../items';
Expand Down Expand Up @@ -31,8 +30,7 @@ export class PatronTransactionComponent implements OnInit {
private _recordService: RecordService,
private _organisationService: OrganisationService,
private _patronTransactionService: PatronTransactionService,
private _modalService: BsModalService,
private _mainTitleService: MainTitleService
private _modalService: BsModalService
) {}

ngOnInit() {
Expand Down Expand Up @@ -110,12 +108,4 @@ export class PatronTransactionComponent implements OnInit {
};
this._modalService.show(PatronTransactionEventFormComponent, {initialState});
}

/**
* Get main title (correspondig to 'bf_Title' type, present only once in metadata)
* @param titleMetadata: title metadata
*/
getMainTitle(titleMetadata: any): string {
return this._mainTitleService.getMainTitle(titleMetadata);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { HttpClientModule } from '@angular/common/http';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { PatronTransactionsComponent } from './patron-transactions.component';
import { RouterTestingModule } from '@angular/router/testing';
import { TranslateModule } from '@ngx-translate/core';
import { PatronTransactionComponent } from './patron-transaction/patron-transaction.component';
import { CoreModule, RecordModule } from '@rero/ng-core';
import { RouterTestingModule } from '@angular/router/testing';
import { SharedPipesModule } from '../../../shared/shared-pipes.module';
import { PatronTransactionEventComponent } from './patron-transaction-event/patron-transaction-event.component';
import { HttpClientModule } from '@angular/common/http';
import { PatronTransactionComponent } from './patron-transaction/patron-transaction.component';
import { PatronTransactionsComponent } from './patron-transactions.component';

describe('PatronTransactionsComponent', () => {
let component: PatronTransactionsComponent;
Expand All @@ -19,7 +19,8 @@ describe('PatronTransactionsComponent', () => {
CoreModule,
RecordModule,
RouterTestingModule,
HttpClientModule
HttpClientModule,
SharedPipesModule
],
declarations: [
PatronTransactionsComponent,
Expand Down
Loading

0 comments on commit fc8c7cf

Please sign in to comment.