From f93d23587762a13cb8949d33913476445f42645d Mon Sep 17 00:00:00 2001 From: Willem Dantuma Date: Mon, 5 Oct 2020 14:58:47 +0200 Subject: [PATCH] add fm-gradient component --- projects/common/src/fm/common.module.ts | 7 ++- .../src/fm/gradient/gradient.component.html | 1 + .../src/fm/gradient/gradient.component.scss | 4 ++ .../fm/gradient/gradient.component.spec.ts | 25 +++++++++ .../src/fm/gradient/gradient.component.ts | 53 +++++++++++++++++++ 5 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 projects/common/src/fm/gradient/gradient.component.html create mode 100644 projects/common/src/fm/gradient/gradient.component.scss create mode 100644 projects/common/src/fm/gradient/gradient.component.spec.ts create mode 100644 projects/common/src/fm/gradient/gradient.component.ts diff --git a/projects/common/src/fm/common.module.ts b/projects/common/src/fm/common.module.ts index cdd9728..5f25f4b 100644 --- a/projects/common/src/fm/common.module.ts +++ b/projects/common/src/fm/common.module.ts @@ -53,6 +53,7 @@ import * as commonActions from './actions/app-common.actions'; import * as commonReducers from './reducers/app-common.reducer'; import * as commonEffects from './effects/app-common.effects'; import { SecureOAuthStorage} from './shared/secureOAuthStorage'; +import { GradientComponent } from './gradient/gradient.component'; export { SafePipe, @@ -121,7 +122,8 @@ export { MenuBackgroundComponent, HasPackageDirective, HasClaimDirective, - UserMenuComponent + UserMenuComponent, + GradientComponent ], exports: [ NgbModule, @@ -141,7 +143,8 @@ export { MenuBackgroundComponent, HasPackageDirective, HasClaimDirective, - UserMenuComponent + UserMenuComponent, + GradientComponent ] }) export class AppCommonModule { diff --git a/projects/common/src/fm/gradient/gradient.component.html b/projects/common/src/fm/gradient/gradient.component.html new file mode 100644 index 0000000..dd83e53 --- /dev/null +++ b/projects/common/src/fm/gradient/gradient.component.html @@ -0,0 +1 @@ +
diff --git a/projects/common/src/fm/gradient/gradient.component.scss b/projects/common/src/fm/gradient/gradient.component.scss new file mode 100644 index 0000000..81c3c6a --- /dev/null +++ b/projects/common/src/fm/gradient/gradient.component.scss @@ -0,0 +1,4 @@ +.gradient { + height: 100%; + width: 100%; +} \ No newline at end of file diff --git a/projects/common/src/fm/gradient/gradient.component.spec.ts b/projects/common/src/fm/gradient/gradient.component.spec.ts new file mode 100644 index 0000000..63f5330 --- /dev/null +++ b/projects/common/src/fm/gradient/gradient.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { GradientComponent } from './gradient.component'; + +describe('GradientComponent', () => { + let component: GradientComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ GradientComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(GradientComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/projects/common/src/fm/gradient/gradient.component.ts b/projects/common/src/fm/gradient/gradient.component.ts new file mode 100644 index 0000000..c8bd266 --- /dev/null +++ b/projects/common/src/fm/gradient/gradient.component.ts @@ -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;i0) 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); + } + } + } +}