add fm-gradient component
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good

This commit is contained in:
Willem Dantuma 2020-10-05 14:58:47 +02:00
parent fe798e3f60
commit f93d235877
5 changed files with 88 additions and 2 deletions

View File

@ -53,6 +53,7 @@ import * as commonActions from './actions/app-common.actions';
import * as commonReducers from './reducers/app-common.reducer'; import * as commonReducers from './reducers/app-common.reducer';
import * as commonEffects from './effects/app-common.effects'; import * as commonEffects from './effects/app-common.effects';
import { SecureOAuthStorage} from './shared/secureOAuthStorage'; import { SecureOAuthStorage} from './shared/secureOAuthStorage';
import { GradientComponent } from './gradient/gradient.component';
export { export {
SafePipe, SafePipe,
@ -121,7 +122,8 @@ export {
MenuBackgroundComponent, MenuBackgroundComponent,
HasPackageDirective, HasPackageDirective,
HasClaimDirective, HasClaimDirective,
UserMenuComponent UserMenuComponent,
GradientComponent
], ],
exports: [ exports: [
NgbModule, NgbModule,
@ -141,7 +143,8 @@ export {
MenuBackgroundComponent, MenuBackgroundComponent,
HasPackageDirective, HasPackageDirective,
HasClaimDirective, HasClaimDirective,
UserMenuComponent UserMenuComponent,
GradientComponent
] ]
}) })
export class AppCommonModule { export class AppCommonModule {

View File

@ -0,0 +1 @@
<div class="gradient" [ngStyle]="gradientStyle"></div>

View File

@ -0,0 +1,4 @@
.gradient {
height: 100%;
width: 100%;
}

View File

@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { GradientComponent } from './gradient.component';
describe('GradientComponent', () => {
let component: GradientComponent;
let fixture: ComponentFixture<GradientComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ GradientComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(GradientComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,53 @@
import { Component, Input, OnInit } from '@angular/core';
import { IItem} from '../models/item'
interface IColor {
red: number,
green: number,
blue: number,
alpha: number,
}
interface IGradientstop {
relativestop: number,
color: IColor
}
@Component({
selector: 'fm-gradient',
templateUrl: './gradient.component.html',
styleUrls: ['./gradient.component.scss']
})
export class GradientComponent implements OnInit {
@Input() item:IItem;
public gradientStyle:any = {};
constructor() { }
getGradientStyle(item:IItem):any {
if(item.data && item.data.gradient) {
let gradient = item.data.gradient as IGradientstop[];
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);
}
}
ngOnInit(): void {
if(this.item.itemType == "vnd.farmmaps.itemtype.gradient") {
if(this.item) {
this.gradientStyle = this.getGradientStyle(this.item);
}
}
}
}