1
0

Fix count items when is loading

This commit is contained in:
Siroco 2019-05-14 22:51:31 +02:00
parent 57d82596db
commit 5e510cb1df
3 changed files with 20 additions and 10 deletions

View File

@ -6,6 +6,7 @@ import {WordpressService} from './wordpress.service';
import { AppComponent } from './app.component';
import { GridComponent } from './grid/grid.component';
import {SlicePipe } from '@angular/common';
@NgModule({
@ -19,6 +20,7 @@ import { GridComponent } from './grid/grid.component';
],
providers: [
WordpressService,
SlicePipe,
],
bootstrap: [AppComponent]
})

View File

@ -2,13 +2,15 @@ import { Injectable } from '@angular/core';
import { HttpClient,HttpResponse } from '@angular/common/http';
import { Observable,of } from 'rxjs';
import soinumapa from "../assets/geojson/soinumapa.json";
import { SlicePipe } from "@angular/common";
@Injectable({
providedIn: 'root'
})
export class GeojsonService {
constructor(private http: HttpClient) {
constructor(private http: HttpClient,
private slicePipe:SlicePipe) {
this.items = soinumapa.features as JSON
this.total_pages
let pages = Object.keys(this.items).length/this.per_page
@ -25,9 +27,10 @@ export class GeojsonService {
getItems(feed:any):any {
let page = feed.page
let start = (page-1)*this.per_page
let end = (page-1)*this.per_page+this.per_page
return this.items.slice( start, end)
let start:number = (page-1)*this.per_page
let end:number = (page-1)*this.per_page+this.per_page
return this.slicePipe.transform(this.items, start, end);
// return a.slice( start, end)
}
getCount():any {

View File

@ -19,11 +19,11 @@ export class GridComponent implements OnInit {
posts$:Observable<any[]>;
items:Item[]=[];
feeds = [
{type:"wordpress", categories:"https://www.gransassolagaich.it/wp-json/wp/v2/categories", url:"https://www.gransassolagaich.it/wp-json/wp/v2/posts?_embed",slug:'bambun',name:"Bambun",status:0,per_page:10,page:1,total_pages:0},
{type:"wordpress", categories:"https://www.archive.binauralmedia.org/wp-json/wp/v2/categories", url:"https://www.archive.binauralmedia.org/wp-json/wp/v2/avada_portfolio?_embed",slug:'binauralnodar',name:"Binaural",status:0,per_page:10,page:1,total_pages:0},
{type:"wordpress", categories:"https://www.gransassolagaich.it/wp-json/wp/v2/categories", url:"https://www.gransassolagaich.it/wp-json/wp/v2/posts?_embed",slug:'bambun',name:"Bambun",status:-1,per_page:10,page:1,total_pages:0},
{type:"wordpress", categories:"https://www.archive.binauralmedia.org/wp-json/wp/v2/categories", url:"https://www.archive.binauralmedia.org/wp-json/wp/v2/avada_portfolio?_embed",slug:'binauralnodar',name:"Binaural",status:-1,per_page:10,page:1,total_pages:0},
// {type:"wordpress", url:"http://backend.industriapaisaia.eus/wp-json/wp/v2/posts?_embed",name:"Local",status:0},
{type:"geojson", categories:"",url:"http://www.soinumapa.net/geojson/",name:"Audiolab",slug:"soinumapa",status:0,per_page:10,page:1,total_pages:0},
{type:"omeka", categories:"http://oralitat", url:"https://tramontana.audio-lab.org/oralitatdegasconha/",name:"Oralitat de Gasconha",slug:'oralitatgasconha',status:0,per_page:10,page:1,total_pages:0},
{type:"omeka", categories:"http://oralitat", url:"https://tramontana.audio-lab.org/oralitatdegasconha/",name:"Oralitat de Gasconha",slug:'oralitatgasconha',status:-1,per_page:10,page:1,total_pages:0},
]
// feedsCategories = [
// {type:"wordpress", url:"https://www.gransassolagaich.it/wp-json/wp/v2/categories",name:"Bambun",status:0},
@ -89,6 +89,7 @@ export class GridComponent implements OnInit {
// nextpage
this.feeds.map(
(feed) => {
if (feed.status==0) return // is loading
if (feed.page<=feed.total_pages) {
feed.page++;
this.loadFeed(feed)
@ -136,11 +137,13 @@ export class GridComponent implements OnInit {
)
}
else if (feed.type==="geojson") {
feed.status = 0
let features = this.gService.getItems(feed)
feed.total_pages = this.gService.getTotalPages()
let numItems = this.gService.getCount()
if (feed.total_pages==0) {
feed.total_pages = this.gService.getTotalPages()
let numItems = this.gService.getCount()
this.countItems+=numItems
feed.status = 1
}
features.map(
(feature) => {
let i = feature.properties
@ -158,9 +161,11 @@ export class GridComponent implements OnInit {
}
}
)
feed.status = 1
}
/** omeka **/
else if (feed.type==="omeka") {
feed.status = 0
this.oService.getItems(feed)
.subscribe(
(res)=> {