Fix count items when is loading
This commit is contained in:
parent
57d82596db
commit
5e510cb1df
@ -6,6 +6,7 @@ import {WordpressService} from './wordpress.service';
|
|||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import { GridComponent } from './grid/grid.component';
|
import { GridComponent } from './grid/grid.component';
|
||||||
|
import {SlicePipe } from '@angular/common';
|
||||||
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
@ -19,6 +20,7 @@ import { GridComponent } from './grid/grid.component';
|
|||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
WordpressService,
|
WordpressService,
|
||||||
|
SlicePipe,
|
||||||
],
|
],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
|
@ -2,13 +2,15 @@ import { Injectable } from '@angular/core';
|
|||||||
import { HttpClient,HttpResponse } from '@angular/common/http';
|
import { HttpClient,HttpResponse } from '@angular/common/http';
|
||||||
import { Observable,of } from 'rxjs';
|
import { Observable,of } from 'rxjs';
|
||||||
import soinumapa from "../assets/geojson/soinumapa.json";
|
import soinumapa from "../assets/geojson/soinumapa.json";
|
||||||
|
import { SlicePipe } from "@angular/common";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class GeojsonService {
|
export class GeojsonService {
|
||||||
|
|
||||||
constructor(private http: HttpClient) {
|
constructor(private http: HttpClient,
|
||||||
|
private slicePipe:SlicePipe) {
|
||||||
this.items = soinumapa.features as JSON
|
this.items = soinumapa.features as JSON
|
||||||
this.total_pages
|
this.total_pages
|
||||||
let pages = Object.keys(this.items).length/this.per_page
|
let pages = Object.keys(this.items).length/this.per_page
|
||||||
@ -25,9 +27,10 @@ export class GeojsonService {
|
|||||||
|
|
||||||
getItems(feed:any):any {
|
getItems(feed:any):any {
|
||||||
let page = feed.page
|
let page = feed.page
|
||||||
let start = (page-1)*this.per_page
|
let start:number = (page-1)*this.per_page
|
||||||
let end = (page-1)*this.per_page+this.per_page
|
let end:number = (page-1)*this.per_page+this.per_page
|
||||||
return this.items.slice( start, end)
|
return this.slicePipe.transform(this.items, start, end);
|
||||||
|
// return a.slice( start, end)
|
||||||
}
|
}
|
||||||
|
|
||||||
getCount():any {
|
getCount():any {
|
||||||
|
@ -19,11 +19,11 @@ export class GridComponent implements OnInit {
|
|||||||
posts$:Observable<any[]>;
|
posts$:Observable<any[]>;
|
||||||
items:Item[]=[];
|
items:Item[]=[];
|
||||||
feeds = [
|
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.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: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:-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:"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:"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 = [
|
// feedsCategories = [
|
||||||
// {type:"wordpress", url:"https://www.gransassolagaich.it/wp-json/wp/v2/categories",name:"Bambun",status:0},
|
// {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
|
// nextpage
|
||||||
this.feeds.map(
|
this.feeds.map(
|
||||||
(feed) => {
|
(feed) => {
|
||||||
|
if (feed.status==0) return // is loading
|
||||||
if (feed.page<=feed.total_pages) {
|
if (feed.page<=feed.total_pages) {
|
||||||
feed.page++;
|
feed.page++;
|
||||||
this.loadFeed(feed)
|
this.loadFeed(feed)
|
||||||
@ -136,11 +137,13 @@ export class GridComponent implements OnInit {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
else if (feed.type==="geojson") {
|
else if (feed.type==="geojson") {
|
||||||
|
feed.status = 0
|
||||||
let features = this.gService.getItems(feed)
|
let features = this.gService.getItems(feed)
|
||||||
feed.total_pages = this.gService.getTotalPages()
|
if (feed.total_pages==0) {
|
||||||
let numItems = this.gService.getCount()
|
feed.total_pages = this.gService.getTotalPages()
|
||||||
|
let numItems = this.gService.getCount()
|
||||||
this.countItems+=numItems
|
this.countItems+=numItems
|
||||||
feed.status = 1
|
}
|
||||||
features.map(
|
features.map(
|
||||||
(feature) => {
|
(feature) => {
|
||||||
let i = feature.properties
|
let i = feature.properties
|
||||||
@ -158,9 +161,11 @@ export class GridComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
feed.status = 1
|
||||||
}
|
}
|
||||||
/** omeka **/
|
/** omeka **/
|
||||||
else if (feed.type==="omeka") {
|
else if (feed.type==="omeka") {
|
||||||
|
feed.status = 0
|
||||||
this.oService.getItems(feed)
|
this.oService.getItems(feed)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(res)=> {
|
(res)=> {
|
||||||
|
Loading…
Reference in New Issue
Block a user