add fm-gradient component
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
This commit is contained in:
parent
fe798e3f60
commit
f93d235877
@ -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 {
|
||||
|
1
projects/common/src/fm/gradient/gradient.component.html
Normal file
1
projects/common/src/fm/gradient/gradient.component.html
Normal file
@ -0,0 +1 @@
|
||||
<div class="gradient" [ngStyle]="gradientStyle"></div>
|
4
projects/common/src/fm/gradient/gradient.component.scss
Normal file
4
projects/common/src/fm/gradient/gradient.component.scss
Normal file
@ -0,0 +1,4 @@
|
||||
.gradient {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
25
projects/common/src/fm/gradient/gradient.component.spec.ts
Normal file
25
projects/common/src/fm/gradient/gradient.component.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
53
projects/common/src/fm/gradient/gradient.component.ts
Normal file
53
projects/common/src/fm/gradient/gradient.component.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user