Compare commits
No commits in common. "57e0a37c78ec10546ec476d5c3119c4fb7d126ae" and "d8730e77ad142f3e721ef966bb465bd591a0d94f" have entirely different histories.
57e0a37c78
...
d8730e77ad
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "farmmaps-lib-app",
|
||||
"version": "2.0.4",
|
||||
"version": "2.0.3",
|
||||
"scripts": {
|
||||
"ng": "ng",
|
||||
"start": "ng serve",
|
||||
|
@ -12,9 +12,6 @@ export const INITUSERSUCCESS = '[AppCommon] InitUserSuccess';
|
||||
export const INITUSERPACKAGES = '[AppCommon] InitUserPackages';
|
||||
export const INITUSERPACKAGESSUCCESS = '[AppCommon] InitUserPackagesSuccess';
|
||||
|
||||
export const INITPACKAGES = '[AppCommon] InitPackages';
|
||||
export const INITPACKAGESSUCCESS = '[AppCommon] InitPackagesSuccess';
|
||||
|
||||
export const INITUSERSETTINGSROOT = '[AppCommon] InitUserSettingsRoot';
|
||||
export const INITUSERSETTINGSROOTSUCCESS = '[AppCommon] InitUserSettingsRootSuccess';
|
||||
|
||||
@ -105,18 +102,6 @@ export class InitUserPackagesSuccess implements Action {
|
||||
constructor(public items:IItem[] ) { }
|
||||
}
|
||||
|
||||
export class InitPackages implements Action {
|
||||
readonly type = INITPACKAGES;
|
||||
|
||||
constructor() {}
|
||||
}
|
||||
|
||||
export class InitPackagesSuccess implements Action {
|
||||
readonly type = INITPACKAGESSUCCESS;
|
||||
|
||||
constructor(public items:IItem[] ) { }
|
||||
}
|
||||
|
||||
export class InitUserSettingsRoot implements Action {
|
||||
readonly type = INITUSERSETTINGSROOT;
|
||||
|
||||
@ -396,8 +381,6 @@ export type Actions = OpenModal
|
||||
| SetMenuVisible
|
||||
| InitUserPackages
|
||||
| InitUserPackagesSuccess
|
||||
| InitPackages
|
||||
| InitPackagesSuccess
|
||||
| InitUserSettingsRoot
|
||||
| InitUserSettingsRootSuccess
|
||||
| ToggleAccountMenu
|
||||
|
@ -35,7 +35,6 @@ import { PackageService } from './services/package.service';
|
||||
import { PackagePreloadStrategy } from './services/package-preload-strategy.service';
|
||||
import { SenmlService } from './services/senml-service';
|
||||
import { DeviceService } from './services/device.service';
|
||||
import { GradientService} from './services/gradient.service';
|
||||
|
||||
export {
|
||||
FolderService,
|
||||
@ -62,8 +61,7 @@ export {
|
||||
PackageService,
|
||||
SenmlService,
|
||||
PackagePreloadStrategy,
|
||||
DeviceService,
|
||||
GradientService
|
||||
DeviceService
|
||||
};
|
||||
|
||||
@NgModule({
|
||||
|
@ -32,7 +32,6 @@ import { TimespanComponent } from './components/timespan/timespan.component';
|
||||
import { TagInputComponent } from './components/tag-input/tag-input.component';
|
||||
import { MenuBackgroundComponent } from './components/menu-background/menu-background.component';
|
||||
import { HasPackageDirective} from './components/has-package/has-package.directive';
|
||||
import { PackageExistsDirective} from './components/package-exists/package-exists.directive';
|
||||
import { HasClaimDirective} from './components/has-claim/has-claim.directive';
|
||||
import { UserMenuComponent} from './components/user-menu/user-menu.component';
|
||||
import { ThumbnailComponent } from './components/thumbnail/thumbnail.component';
|
||||
@ -83,7 +82,6 @@ export {
|
||||
UserMenuComponent,
|
||||
ThumbnailComponent,
|
||||
HasPackageDirective,
|
||||
PackageExistsDirective,
|
||||
HasClaimDirective,
|
||||
Alert,
|
||||
IEventMessage,
|
||||
@ -146,7 +144,6 @@ export {
|
||||
SessionClearedComponent,
|
||||
MenuBackgroundComponent,
|
||||
HasPackageDirective,
|
||||
PackageExistsDirective,
|
||||
HasClaimDirective,
|
||||
UserMenuComponent,
|
||||
GradientComponent,
|
||||
@ -177,7 +174,6 @@ export {
|
||||
SessionClearedComponent,
|
||||
MenuBackgroundComponent,
|
||||
HasPackageDirective,
|
||||
PackageExistsDirective,
|
||||
HasClaimDirective,
|
||||
UserMenuComponent,
|
||||
GradientComponent,
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { Component, Input, OnInit ,OnChanges, SimpleChanges,ChangeDetectorRef} from '@angular/core';
|
||||
import { IItem} from '../../models/item'
|
||||
import { IGradientstop } from '../../models/gradient';
|
||||
import { GradientService } from '../../common-service.module';
|
||||
|
||||
|
||||
|
||||
@ -15,12 +14,23 @@ export class GradientComponent implements OnInit,OnChanges {
|
||||
@Input() gradientItem:IItem;
|
||||
public gradientStyle:any = {};
|
||||
|
||||
constructor(private ref: ChangeDetectorRef,private gradientService:GradientService) { }
|
||||
constructor(private ref: ChangeDetectorRef) { }
|
||||
|
||||
getGradientStyle(item:IItem):any {
|
||||
if(item.data && item.data.gradient) {
|
||||
let gradient = item.data.gradient as IGradientstop[];
|
||||
return this.gradientService.getGradientStyle(gradient);
|
||||
let gd = '{ "background": "linear-gradient(to right,';
|
||||
for(var i=0;i<gradient.length;i++) {
|
||||
let gs = gradient[i];
|
||||
if(i>0) gd+=",";
|
||||
gd += `rgba(${gs.color.red},${gs.color.green},${gs.color.blue},${gs.color.alpha/255})`;
|
||||
gd +=` ${gs.relativestop*100}%`
|
||||
}
|
||||
gradient.forEach((gs) => {
|
||||
});
|
||||
gd+=')"}';
|
||||
|
||||
return JSON.parse(gd);
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,4 +49,5 @@ export class GradientComponent implements OnInit,OnChanges {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,61 +0,0 @@
|
||||
import {AfterViewInit, Directive, Input, OnDestroy, TemplateRef, ViewContainerRef} from '@angular/core';
|
||||
import {Subscription} from 'rxjs';
|
||||
import {PackageService} from '../../services/package.service';
|
||||
import * as appCommonReducer from '../../reducers/app-common.reducer';
|
||||
import {Store} from '@ngrx/store';
|
||||
|
||||
@Directive({
|
||||
selector: '[fmPackageExists]',
|
||||
})
|
||||
export class PackageExistsDirective implements OnDestroy, AfterViewInit {
|
||||
|
||||
@Input()
|
||||
set fmPackageExists(packageIdentifier: string) {
|
||||
this.packageIdentifier = packageIdentifier;
|
||||
this.updateView();
|
||||
}
|
||||
|
||||
@Input()
|
||||
set fmPackageExistsThen(thenTemplate: TemplateRef<any>) {
|
||||
this.thenTemplate = thenTemplate;
|
||||
this.updateView();
|
||||
}
|
||||
|
||||
@Input()
|
||||
set fmPackageExistsElse(thenTemplate: TemplateRef<any>) {
|
||||
this.elseTemplate = thenTemplate;
|
||||
this.updateView();
|
||||
}
|
||||
|
||||
private packageIdentifier: string;
|
||||
private thenTemplate: TemplateRef<any>;
|
||||
private elseTemplate: TemplateRef<any>;
|
||||
private packSub: Subscription;
|
||||
|
||||
constructor(private hostTemplateRef: TemplateRef<any>, private viewContainerRef: ViewContainerRef,
|
||||
private store: Store<appCommonReducer.State>, private packageService: PackageService) {
|
||||
this.thenTemplate = hostTemplateRef;
|
||||
this.packSub = this.store.select(appCommonReducer.SelectGetPackages).subscribe((_) => {
|
||||
this.updateView();
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.updateView();
|
||||
}
|
||||
|
||||
updateView() {
|
||||
this.viewContainerRef.clear();
|
||||
if (this.packageService.packageExists(this.packageIdentifier)) {
|
||||
this.viewContainerRef.createEmbeddedView(this.thenTemplate);
|
||||
} else if (this.elseTemplate) {
|
||||
this.viewContainerRef.createEmbeddedView(this.elseTemplate);
|
||||
}
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if (this.packSub) {
|
||||
this.packSub.unsubscribe();
|
||||
}
|
||||
}
|
||||
}
|
@ -62,15 +62,6 @@ export class AppCommonEffects {
|
||||
)
|
||||
})
|
||||
));
|
||||
initPackages$ = createEffect(() => this.actions$.pipe(
|
||||
ofType(appCommonActions.INITPACKAGES),
|
||||
switchMap(() => {
|
||||
return this.itemService$.getItemList('vnd.farmmaps.itemtype.package.template').pipe(
|
||||
switchMap((items) => of(new appCommonActions.InitPackagesSuccess(items))),
|
||||
catchError(error => of(new appCommonActions.Fail(error)))
|
||||
)
|
||||
})
|
||||
));
|
||||
|
||||
userPackagesChanged$ = createEffect(() => this.actions$.pipe(
|
||||
ofType(appCommonActions.ITEMCHANGEDEVENT),
|
||||
@ -108,7 +99,7 @@ export class AppCommonEffects {
|
||||
initUserSuccess$ = createEffect(() => this.actions$.pipe(
|
||||
ofType(appCommonActions.INITUSERSUCCESS),
|
||||
switchMap(() => {
|
||||
return [new appCommonActions.InitRoot(),new appCommonActions.InitUserPackages(),new appCommonActions.InitPackages(),new appCommonActions.InitUserSettingsRoot()];
|
||||
return [new appCommonActions.InitRoot(),new appCommonActions.InitUserPackages(),new appCommonActions.InitUserSettingsRoot()];
|
||||
}
|
||||
)));
|
||||
|
||||
|
@ -9,8 +9,3 @@ export interface IPackage {
|
||||
export interface IPackages {
|
||||
[id: string]: IPackage[];
|
||||
}
|
||||
|
||||
export interface IPackageMap {
|
||||
[id: string]: IPackage;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ import { tassign } from 'tassign';
|
||||
import { IItemTypes} from '../models/item.types';
|
||||
import { IListItem } from '../models/list.item';
|
||||
import { IUser } from '../models/user';
|
||||
import { IPackage,IPackageMap,IPackages} from '../models/package';
|
||||
import { IPackage,IPackages} from '../models/package';
|
||||
import * as appCommonActions from '../actions/app-common.actions';
|
||||
import { createSelector, createFeatureSelector, ActionReducerMap } from '@ngrx/store';
|
||||
|
||||
@ -20,7 +20,6 @@ export interface State {
|
||||
routeLoading:boolean,
|
||||
menuVisible: boolean,
|
||||
userPackages: IPackages,
|
||||
packages: IPackageMap,
|
||||
userSettingsRoot: IItem,
|
||||
accountMenuVisible: boolean,
|
||||
appMenuVisible: boolean,
|
||||
@ -41,7 +40,6 @@ export const initialState: State = {
|
||||
routeLoading: false,
|
||||
menuVisible: false,
|
||||
userPackages: {},
|
||||
packages: {},
|
||||
userSettingsRoot: null,
|
||||
accountMenuVisible: false,
|
||||
appMenuVisible: false,
|
||||
@ -142,15 +140,6 @@ export function reducer(state = initialState, action: appCommonActions.Actions )
|
||||
|
||||
return tassign(state,{userPackages:packages});
|
||||
}
|
||||
case appCommonActions.INITPACKAGESSUCCESS:{
|
||||
let a = action as appCommonActions.InitPackagesSuccess;
|
||||
let packages = {}
|
||||
a.items.forEach((item) => {
|
||||
packages[item.data.id] = item.data;
|
||||
});
|
||||
|
||||
return tassign(state,{packages:packages});
|
||||
}
|
||||
case appCommonActions.INITUSERSETTINGSROOTSUCCESS:{
|
||||
let a = action as appCommonActions.InitUserSettingsRootSuccess;
|
||||
return tassign(state, { userSettingsRoot : a.item });
|
||||
@ -198,7 +187,6 @@ export const getRouteLoading = (state: State) => state.routeLoading;
|
||||
export const getMenuVisible = (state: State) => state.menuVisible;
|
||||
export const getUser = (state: State) => state.user;
|
||||
export const getUserPackages = (state: State) => state.userPackages;
|
||||
export const getPackages = (state: State) => state.packages;
|
||||
export const getUserSettingsRoot = (state: State) => state.userSettingsRoot;
|
||||
export const getAccountMenuVisible = (state: State) => state.accountMenuVisible;
|
||||
export const getAppMenuVisible = (state: State) => state.appMenuVisible;
|
||||
@ -219,7 +207,6 @@ export const selectGetRouteLoading = createSelector(selectAppCommonState, getRou
|
||||
export const SelectGetMenuVisible = createSelector(selectAppCommonState,getMenuVisible);
|
||||
export const SelectGetUser = createSelector(selectAppCommonState,getUser);
|
||||
export const SelectGetUserPackages = createSelector(selectAppCommonState,getUserPackages);
|
||||
export const SelectGetPackages = createSelector(selectAppCommonState,getPackages);
|
||||
export const SelectGetValidUserPackages = createSelector(SelectGetUserPackages, (packageMap) => {
|
||||
return getValidPackages(packageMap);
|
||||
});
|
||||
|
@ -1,25 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {IGradientstop } from '../models/gradient'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class GradientService {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
getGradientStyle(gradient:IGradientstop[],portrait:boolean = false ):any {
|
||||
let gd = '{ "background": "linear-gradient(to ' + (portrait?'bottom':'right') +',';
|
||||
for(var i=0;i<gradient.length;i++) {
|
||||
let gs = gradient[i];
|
||||
if(i>0) gd+=",";
|
||||
gd += `rgba(${gs.color.red},${gs.color.green},${gs.color.blue},${gs.color.alpha/255})`;
|
||||
gd +=` ${gs.relativestop*100}%`
|
||||
}
|
||||
gradient.forEach((gs) => {
|
||||
});
|
||||
gd+=')"}';
|
||||
|
||||
return JSON.parse(gd);
|
||||
}
|
||||
}
|
@ -7,23 +7,17 @@ import {IItem} from '../models/item';
|
||||
import {IItemTask} from '../models/itemTask';
|
||||
import {HttpClient} from '@angular/common/http';
|
||||
import {AppConfig} from '../shared/app.config';
|
||||
import {Observable,iif,of} from 'rxjs';
|
||||
import {switchMap} from 'rxjs/operators';
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
|
||||
export class PackageService {
|
||||
private userPackages: { [key: string]: IPackage } = {};
|
||||
private packages: { [key: string]: IPackage } = {};
|
||||
private packagesObservable = this.store$.select(appCommonReducer.SelectGetPackages);
|
||||
|
||||
constructor(private store$: Store<appCommonReducer.State>, public httpClient: HttpClient, public appConfig: AppConfig) {
|
||||
store$.select(appCommonReducer.SelectGetValidUserPackages).subscribe((packages) => {
|
||||
this.userPackages = packages;
|
||||
});
|
||||
this.packagesObservable.subscribe((packages) => {
|
||||
this.packages = packages;
|
||||
});
|
||||
}
|
||||
@ -33,24 +27,12 @@ export class PackageService {
|
||||
}
|
||||
|
||||
hasPackage(id: string): boolean {
|
||||
return id in this.userPackages;
|
||||
}
|
||||
|
||||
packageExists(id: string): boolean {
|
||||
return id in this.packages;
|
||||
}
|
||||
|
||||
postItemPackageTask(item: IItem, task: IItemTask): Observable<IItemTask> {
|
||||
return this.httpClient.post<IItemTask>(`${this.ApiEndpoint()}/api/v1/items/${item.code}/packagetasks`, task);
|
||||
}
|
||||
|
||||
ifPackageListExists<Type>(packageList: Array<string>, ifTrue:Observable<Type>,ifFalse:Observable<Type>):Observable<Type> {
|
||||
return this.packagesObservable.pipe(switchMap(packages =>
|
||||
iif(( )=> Object.keys(packages).some(id => packageList.includes(id)),
|
||||
ifTrue,
|
||||
ifFalse)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
export function getValidPackages(packageMap: IPackages): {[key: string]: IPackage} {
|
||||
|
@ -2,7 +2,7 @@
|
||||
<div class="row">
|
||||
<fm-gradient-select [gradientItems]="gradientItems|async" [showLabel]="false" [showAdd]="true"></fm-gradient-select>
|
||||
</div>
|
||||
<div class="row mt-3" *fmPackageExists="'vnd.farmmaps.itemtype.package.dacom'">
|
||||
<div class="row mt-3">
|
||||
<button class="btn btn-primary" (click)="onTest($event)">Test</button>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user