AW-3441 add valid packages selector
All checks were successful
FarmMaps/FarmMapsLib/pipeline/head This commit looks good
All checks were successful
FarmMaps/FarmMapsLib/pipeline/head This commit looks good
This commit is contained in:
parent
d89670f669
commit
b7c80dfdd8
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "farmmaps-lib-app",
|
"name": "farmmaps-lib-app",
|
||||||
"version": "1.1.6",
|
"version": "1.1.7",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ng": "ng",
|
"ng": "ng",
|
||||||
"start": "ng serve",
|
"start": "ng serve",
|
||||||
|
@ -7,5 +7,5 @@ export interface IPackage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IPackages {
|
export interface IPackages {
|
||||||
[id: string]: IPackage;
|
[id: string]: IPackage[];
|
||||||
}
|
}
|
@ -131,7 +131,10 @@ export function reducer(state = initialState, action: appCommonActions.Actions )
|
|||||||
a.items.forEach((item) => {
|
a.items.forEach((item) => {
|
||||||
item.data.dataDate = item.dataDate;
|
item.data.dataDate = item.dataDate;
|
||||||
item.data.dataEndDate = item.dataEndDate;
|
item.data.dataEndDate = item.dataEndDate;
|
||||||
packages[item.data.id]=item.data;
|
if (!packages[item.data.id]) {
|
||||||
|
packages[item.data.id] = [];
|
||||||
|
}
|
||||||
|
packages[item.data.id].push(item.data);
|
||||||
});
|
});
|
||||||
|
|
||||||
return tassign(state,{userPackages:packages});
|
return tassign(state,{userPackages:packages});
|
||||||
@ -203,6 +206,23 @@ export const selectGetRouteLoading = createSelector(selectAppCommonState, getRou
|
|||||||
export const SelectGetMenuVisible = createSelector(selectAppCommonState,getMenuVisible);
|
export const SelectGetMenuVisible = createSelector(selectAppCommonState,getMenuVisible);
|
||||||
export const SelectGetUser = createSelector(selectAppCommonState,getUser);
|
export const SelectGetUser = createSelector(selectAppCommonState,getUser);
|
||||||
export const SelectGetUserPackages = createSelector(selectAppCommonState,getUserPackages);
|
export const SelectGetUserPackages = createSelector(selectAppCommonState,getUserPackages);
|
||||||
|
export const SelectGetValidUserPackages = createSelector(SelectGetUserPackages, (packageMap) => {
|
||||||
|
const nowYear = new Date(Date.now()).getUTCFullYear();
|
||||||
|
const keys = Object.keys(packageMap);
|
||||||
|
|
||||||
|
return keys.filter(k => {
|
||||||
|
const packages = packageMap[k]
|
||||||
|
.filter((p) => p.dataEndDate.getUTCFullYear() >= nowYear);
|
||||||
|
|
||||||
|
return packages.length > 0;
|
||||||
|
}).reduce((map, key) => {
|
||||||
|
const packages = packageMap[key];
|
||||||
|
return {
|
||||||
|
...map,
|
||||||
|
key: packages[0]
|
||||||
|
};
|
||||||
|
}, {});
|
||||||
|
});
|
||||||
export const SelectGetUserSettingsRoot = createSelector(selectAppCommonState,getUserSettingsRoot);
|
export const SelectGetUserSettingsRoot = createSelector(selectAppCommonState,getUserSettingsRoot);
|
||||||
export const SelectGetAccountMenuVisible = createSelector(selectAppCommonState,getAccountMenuVisible);
|
export const SelectGetAccountMenuVisible = createSelector(selectAppCommonState,getAccountMenuVisible);
|
||||||
export const SelectGetAppMenuVisible = createSelector(selectAppCommonState,getAppMenuVisible);
|
export const SelectGetAppMenuVisible = createSelector(selectAppCommonState,getAppMenuVisible);
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import { Store} from '@ngrx/store';
|
import {Store} from '@ngrx/store';
|
||||||
import * as appCommonReducer from '../reducers/app-common.reducer'
|
import * as appCommonReducer from '../reducers/app-common.reducer';
|
||||||
import { IPackages } from '../models/package';
|
import {IPackage} from '../models/package';
|
||||||
|
|
||||||
import { IItem } from '../models/item';
|
import {IItem} from '../models/item';
|
||||||
import { IItemTask } from '../models/itemTask';
|
import {IItemTask} from '../models/itemTask';
|
||||||
import { HttpClient } from "@angular/common/http";
|
import {HttpClient} from '@angular/common/http';
|
||||||
import { AppConfig } from "../shared/app.config";
|
import {AppConfig} from '../shared/app.config';
|
||||||
import { Observable } from 'rxjs';
|
import {Observable} from 'rxjs';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
|
|
||||||
export class PackageService {
|
export class PackageService {
|
||||||
private packages$:IPackages = {};
|
private packages: {[key: string]: IPackage} = {};
|
||||||
|
|
||||||
constructor(private store$: Store<appCommonReducer.State>, public httpClient: HttpClient, public appConfig: AppConfig) {
|
constructor(private store$: Store<appCommonReducer.State>, public httpClient: HttpClient, public appConfig: AppConfig) {
|
||||||
store$.select(appCommonReducer.SelectGetUserPackages).subscribe((packages) => {
|
store$.select(appCommonReducer.SelectGetValidUserPackages).subscribe((packages) => {
|
||||||
this.packages$ = packages;
|
this.packages = packages;
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ApiEndpoint() {
|
ApiEndpoint() {
|
||||||
@ -27,8 +27,8 @@ export class PackageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hasPackage(id:string):boolean {
|
hasPackage(id:string):boolean {
|
||||||
if(!this.packages$[id]) return false;
|
if(!this.packages[id]) return false;
|
||||||
return this.packages$[id].enabled ? this.packages$[id].enabled == true : true;
|
return this.packages[id].enabled ? this.packages[id].enabled === true : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
postItemPackageTask(item: IItem, task: IItemTask): Observable<IItemTask> {
|
postItemPackageTask(item: IItem, task: IItemTask): Observable<IItemTask> {
|
||||||
|
Loading…
Reference in New Issue
Block a user