Skip to content

Commit

Permalink
added pagination #2
Browse files Browse the repository at this point in the history
  • Loading branch information
tmushayahama committed Mar 22, 2020
1 parent 5f81d3c commit 83b98c8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subject } from 'rxjs';
import { NoctuaFormConfigService, NoctuaUserService } from 'noctua-form-base';
import { NoctuaSearchService } from './../..//services/noctua-search.service';
import { NoctuaSearchMenuService } from '../../services/search-menu.service';

@Component({
selector: 'noc-search-history',
templateUrl: './search-history.component.html',
styleUrls: ['./search-history.component.scss']
})
export class SearchHistoryComponent implements OnInit {
export class SearchHistoryComponent implements OnInit, OnDestroy {
searchCriteria: any = {};

constructor() { }
private unsubscribeAll: Subject<any>;

ngOnInit() {
constructor(public noctuaUserService: NoctuaUserService,
public noctuaSearchMenuService: NoctuaSearchMenuService,
private noctuaSearchService: NoctuaSearchService,
public noctuaFormConfigService: NoctuaFormConfigService) {
// this.groups = this.noctuaSearchService.groups;
this.unsubscribeAll = new Subject();
}

ngOnInit(): void {
//this.searchForm = this.createSearchForm();
}

selectGroup(group) {
this.searchCriteria.group = group;
this.noctuaSearchService.search(this.searchCriteria);
}


search() {
let searchCriteria

this.noctuaSearchService.search(searchCriteria);
}

close() {
this.noctuaSearchMenuService.closeLeftDrawer();
}

ngOnDestroy(): void {
this.unsubscribeAll.next();
this.unsubscribeAll.complete();
}
}
2 changes: 1 addition & 1 deletion src/@noctua.search/models/cam-page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class Page {
size = 0;
size = 50;
total = 0;
pageNumber = 0;
}
Expand Down
10 changes: 8 additions & 2 deletions src/@noctua.search/models/search-criteria.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Cam, Contributor, Group, Organism } from 'noctua-form-base';
import { each } from 'lodash';
import { CamPage } from './cam-page';

export class SearchCriteria {
camPage: CamPage = new CamPage();
titles: any[] = [];
gps: any[] = [];
goterms: any[] = [];
Expand All @@ -17,7 +19,9 @@ export class SearchCriteria {

query() {
const self = this;
let query = ['offset=0&limit=50'];
const query = ['offset=' + (self.camPage.pageNumber * self.camPage.size).toString()];

query.push('limit=' + self.camPage.size.toString());

each(self.titles, (title) => {
query.push(`title=${title}`);
Expand Down Expand Up @@ -60,7 +64,9 @@ export class SearchCriteria {

queryEncoded() {
const self = this;
const query = ['offset=0&limit=50'];
const query = ['offset=' + (self.camPage.pageNumber * self.camPage.size).toString()];

query.push('limit=' + self.camPage.size.toString());

each(self.titles, (title) => {
query.push(`title=${encodeURIComponent(title)}`);
Expand Down
6 changes: 5 additions & 1 deletion src/@noctua.search/services/noctua-search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
Entity,
Article,
noctuaFormConfig,
// CamPage
} from 'noctua-form-base';
import { SearchCriteria } from './../models/search-criteria';
import { saveAs } from 'file-saver';
Expand Down Expand Up @@ -120,6 +119,11 @@ export class NoctuaSearchService {
this.updateSearch();
}

getPage(pageNumber: number) {
this.searchCriteria.camPage.pageNumber = pageNumber;
this.updateSearch();
}

paramsToSearch(param) {
this.searchCriteria = new SearchCriteria();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import { SparqlService } from '@noctua.sparql/services/sparql/sparql.service';

import {
NoctuaFormConfigService,
CamService
} from 'noctua-form-base';

import { Cam } from 'noctua-form-base';
import { MatPaginator } from '@angular/material';
import { CamPage } from '@noctua.search/models/cam-page';
import { NoctuaSearchMenuService } from '@noctua.search/services/search-menu.service';
Expand Down Expand Up @@ -64,9 +62,6 @@ export class CamsTableComponent implements OnInit, OnDestroy {
}

ngOnInit(): void {

console.log('pp')

this.noctuaSearchService.onCamsChanged
.pipe(takeUntil(this._unsubscribeAll))
.subscribe(cams => {
Expand All @@ -92,11 +87,14 @@ export class CamsTableComponent implements OnInit, OnDestroy {

search() {
const searchCriteria = this.searchForm.value;
console.dir(searchCriteria);
this.noctuaSearchService.search(searchCriteria);
}


setPage($event) {
if (this.camPage) {
this.noctuaSearchService.getPage($event.pageIndex);
}
}

ngOnDestroy(): void {
this._unsubscribeAll.next();
Expand Down
4 changes: 1 addition & 3 deletions src/app/main/apps/noctua-search/noctua-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { noctuaAnimations } from './../../../../@noctua/animations';
import {
Cam,
Contributor,
NoctuaUserService,
NoctuaFormConfigService,
NoctuaAnnotonFormService
NoctuaUserService
} from 'noctua-form-base';

import { FormGroup } from '@angular/forms';
Expand Down

0 comments on commit 83b98c8

Please sign in to comment.