added components and directives for Bootstrap tables ordering and

filtering
This commit is contained in:
Maria Teresa Paratore 2023-10-12 17:07:48 +02:00
parent ad55f05b57
commit da9db179ff
8 changed files with 56 additions and 40 deletions

View File

@ -83,11 +83,10 @@
"@angular/platform-browser": "14.2.0", "@angular/platform-browser": "14.2.0",
"@angular/platform-browser-dynamic": "14.2.0", "@angular/platform-browser-dynamic": "14.2.0",
"@angular/router": "14.2.0", "@angular/router": "14.2.0",
"ng-bootstrap/ng-bootstrap": "15.1.1",
"@fortawesome/angular-fontawesome": "0.11.1", "@fortawesome/angular-fontawesome": "0.11.1",
"@fortawesome/fontawesome-svg-core": "6.2.0", "@fortawesome/fontawesome-svg-core": "6.2.0",
"@fortawesome/free-solid-svg-icons": "6.2.0", "@fortawesome/free-solid-svg-icons": "6.2.0",
"@ng-bootstrap/ng-bootstrap": "13.0.0", "@ng-bootstrap/ng-bootstrap": "15.1.1",
"@ngx-translate/core": "14.0.0", "@ngx-translate/core": "14.0.0",
"@ngx-translate/http-loader": "7.0.0", "@ngx-translate/http-loader": "7.0.0",
"@popperjs/core": "2.11.6", "@popperjs/core": "2.11.6",
@ -98,7 +97,8 @@
"ngx-webstorage": "10.0.1", "ngx-webstorage": "10.0.1",
"rxjs": "7.5.6", "rxjs": "7.5.6",
"tslib": "2.4.0", "tslib": "2.4.0",
"zone.js": "0.11.6" "zone.js": "0.11.6",
"typescript": "5.0.4"
}, },
"devDependencies": { "devDependencies": {
"@angular-builders/custom-webpack": "14.0.1", "@angular-builders/custom-webpack": "14.0.1",

View File

@ -25,8 +25,8 @@ import { FooterComponent } from './layouts/footer/footer.component';
import { PageRibbonComponent } from './layouts/profiles/page-ribbon.component'; import { PageRibbonComponent } from './layouts/profiles/page-ribbon.component';
import { ActiveMenuDirective } from './layouts/navbar/active-menu.directive'; import { ActiveMenuDirective } from './layouts/navbar/active-menu.directive';
import { ErrorComponent } from './layouts/error/error.component'; import { ErrorComponent } from './layouts/error/error.component';
import { TableNodesComponent } from './table-nodes/table-nodes.component';
import { SortableDirective } from './table-nodes/sortable.directive'; import { SortableDirective } from './table-nodes/sortable.directive';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
@NgModule({ @NgModule({
imports: [ imports: [
@ -40,8 +40,8 @@ import { SortableDirective } from './table-nodes/sortable.directive';
HttpClientModule, HttpClientModule,
NgxWebstorageModule.forRoot({ prefix: 'jhi', separator: '-', caseSensitive: true }), NgxWebstorageModule.forRoot({ prefix: 'jhi', separator: '-', caseSensitive: true }),
TranslationModule, TranslationModule,
TableNodesComponent, SortableDirective,
SortableDirective NgbModule
], ],
providers: [ providers: [
Title, Title,

View File

@ -36,12 +36,11 @@ function sort(hnodes: IHostingnode[], column: SortColumn, direction: string): IH
} }
} }
//matching SOLO sul campo UUID
function matches(hnode: IHostingnode, term: string, pipe: PipeTransform){ function matches(hnode: IHostingnode, term: string, pipe: PipeTransform){
// eslint-disable-next-line @typescript-eslint/no-unsafe-return // eslint-disable-next-line @typescript-eslint/no-unsafe-return
return ( return (
hnode.name.toLowerCase().includes(term.toLowerCase()) || pipe.transform(hnode.id).includes(term.toLowerCase())
pipe.transform(hnode.id).includes(term) ||
pipe.transform(hnode.status).includes(term)
); );
} }

View File

@ -14,9 +14,11 @@ import { SortDirective } from './sort/sort.directive';
import { ItemCountComponent } from './pagination/item-count.component'; import { ItemCountComponent } from './pagination/item-count.component';
import { FilterComponent } from './filter/filter.component'; import { FilterComponent } from './filter/filter.component';
import { ContextTransformPipe } from './pipe/contexttransform.pipe'; import { ContextTransformPipe } from './pipe/contexttransform.pipe';
import { NgbPagination, NgbTypeahead } from '@ng-bootstrap/ng-bootstrap';
import { SortableDirective } from 'app/table-nodes/sortable.directive';
@NgModule({ @NgModule({
imports: [SharedLibsModule], imports: [SharedLibsModule,SortableDirective],
declarations: [ declarations: [
FindLanguageFromKeyPipe, FindLanguageFromKeyPipe,
TranslateDirective, TranslateDirective,
@ -30,7 +32,8 @@ import { ContextTransformPipe } from './pipe/contexttransform.pipe';
SortDirective, SortDirective,
ItemCountComponent, ItemCountComponent,
FilterComponent, FilterComponent,
ContextTransformPipe ContextTransformPipe,
], ],
exports: [ exports: [
SharedLibsModule, SharedLibsModule,
@ -46,7 +49,10 @@ import { ContextTransformPipe } from './pipe/contexttransform.pipe';
SortDirective, SortDirective,
ItemCountComponent, ItemCountComponent,
FilterComponent, FilterComponent,
ContextTransformPipe ContextTransformPipe,
NgbPagination,
NgbTypeahead,
SortableDirective
], ],
}) })
export class SharedModule {} export class SharedModule {}

View File

@ -1,3 +1,4 @@
/* eslint-disable @angular-eslint/directive-selector */
/* eslint-disable @angular-eslint/no-host-metadata-property */ /* eslint-disable @angular-eslint/no-host-metadata-property */
import { Directive, EventEmitter, Input, Output } from '@angular/core'; import { Directive, EventEmitter, Input, Output } from '@angular/core';
import { IHostingnode } from 'app/services/i-hostinngnode'; import { IHostingnode } from 'app/services/i-hostinngnode';
@ -14,7 +15,7 @@ export interface SortEvent {
@Directive({ @Directive({
selector: '[jhiSortable]', selector: 'th[sortable]',
standalone: true, standalone: true,
host: { host: {
'[class.asc]': 'direction === "asc"', '[class.asc]': 'direction === "asc"',

View File

@ -1,10 +1,12 @@
<form>
<div class="mb-3 row"> <div class="mb-3 row">
<label for="table-complete-search" class="col-xs-3 col-sm-auto col-form-label">Full text search:</label> <label for="table-complete-search" class="col-xs-3 col-sm-auto col-form-label">Full text search:</label>
<div class="col-xs-3 col-sm-auto"> <div class="col-xs-3 col-sm-auto">
<input type="text" id="table-complete-search" <input type="text" id="table-complete-search"
[(ngModel)]="service.searchTerm"
class="form-control" class="form-control"
name="searchTerm" name="searchTerm"
[(ngModel)]="service.searchTerm"/> />
</div> </div>
<span class="col col-form-label" *ngIf="service.loading$ | async">Loading...</span> <span class="col col-form-label" *ngIf="service.loading$ | async">Loading...</span>
</div> </div>
@ -12,26 +14,22 @@
<thead> <thead>
<tr> <tr>
<th scope="col">#</th> <th scope="col">#</th>
<th scope="col" sortable="name" (sort)="onSort($event)">Country</th> <!--<th scope="col" sortable="type" (sort)="onSort($event)">Type</th>-->
<th scope="col" sortable="id" (sort)="onSort($event)">Area</th> <th scope="col" sortable="name" (sort)="onSort($event)">Name</th>
<th scope="col" sortable="status" (sort)="onSort($event)">Population</th> <th scope="col" sortable="id" (sort)="onSort($event)">Id</th>
<th scope="col" sortable="status" (sort)="onSort($event)">Population</th> <th scope="col" sortable="status" (sort)="onSort($event)">Status</th>
<th scope="col" sortable="status" (sort)="onSort($event)">Population</th> <th scope="col" sortable="lastmod" (sort)="onSort($event)">Lat Modified</th>
<th scope="col" sortable="memavailable" (sort)="onSort($event)">Available Memory</th>
<th scope="col" sortable="hdspace" (sort)="onSort($event)">HD Space</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let country of countries$ | async"> <tr *ngFor="let hnode of hnodes$ | async">
<th scope="row">{{ country.id }}</th> <th scope="row">{{ hnode.id }}</th>
<td> <td><ngb-highlight [result]="hnode.name" [term]="service.searchTerm"></ngb-highlight></td>
<img <td><ngb-highlight [result]="hnode.id" [term]="service.searchTerm"></ngb-highlight></td>
[src]="'https://upload.wikimedia.org/wikipedia/commons/' + country.flag" <td><ngb-highlight [result]="hnode.memavailable" [term]="service.searchTerm"></ngb-highlight></td>
class="me-2" <td><ngb-highlight [result]="hnode.hdspace" [term]="service.searchTerm"></ngb-highlight></td>
style="width: 20px"
/>
<ngb-highlight [result]="country.name" [term]="service.searchTerm"></ngb-highlight>
</td>
<td><ngb-highlight [result]="country.area | number" [term]="service.searchTerm"></ngb-highlight></td>
<td><ngb-highlight [result]="country.population | number" [term]="service.searchTerm"></ngb-highlight></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -1,14 +1,10 @@
import { Component, Input, OnInit, Output, QueryList, ViewChildren } from '@angular/core'; import { Component, QueryList, ViewChildren } from '@angular/core';
import { IContextNode } from 'app/services/i-context-node';
import { IHostingnode } from 'app/services/i-hostinngnode'; import { IHostingnode } from 'app/services/i-hostinngnode';
import { HnodesLoaderService } from 'app/services/hnodes-loader.service'; import { HnodesLoaderService } from 'app/services/hnodes-loader.service';
//import EventEmitter from 'events'; import { DecimalPipe, NgIf } from '@angular/common';
/////////
import { AsyncPipe, DecimalPipe, NgIf } from '@angular/common';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { SortableDirective, SortEvent } from './sortable.directive'; import { SortableDirective, SortEvent } from './sortable.directive';
import { FormsModule } from '@angular/forms';
import { NgbPaginationModule, NgbTypeaheadModule } from '@ng-bootstrap/ng-bootstrap';
/* /*
Tabella con paginazione, ordinamento e ricerca - dati presi da servizio Tabella con paginazione, ordinamento e ricerca - dati presi da servizio
*/ */
@ -18,8 +14,8 @@ Tabella con paginazione, ordinamento e ricerca - dati presi da servizio
selector: 'jhi-table-nodes', selector: 'jhi-table-nodes',
templateUrl: './table-nodes.component.html', templateUrl: './table-nodes.component.html',
styleUrls: ['./table-nodes.component.scss'], styleUrls: ['./table-nodes.component.scss'],
standalone: true,
providers: [HnodesLoaderService, DecimalPipe], providers: [HnodesLoaderService, DecimalPipe],
}) })
export class TableNodesComponent{ export class TableNodesComponent{

View File

@ -0,0 +1,16 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SharedModule } from 'app/shared/shared.module';
import { TableNodesComponent } from './table-nodes.component';
@NgModule({
declarations: [TableNodesComponent],
entryComponents: [TableNodesComponent],
imports: [
CommonModule,
SharedModule,
]
})
export class TableNodesModule { }