Skip to content

Commit

Permalink
feat(render): init maturity rating module
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed May 8, 2020
1 parent 5391949 commit 9660a5b
Show file tree
Hide file tree
Showing 11 changed files with 259 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<span>{{item.name}}</span>
<mat-slider
min="1" max="5" step="1"
*ngIf="isParent"
[(ngModel)]="item.chartValue"
(change)="updateValue($event)"
>

</mat-slider>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ComponentRatingItemComponent } from './component-rating-item.component';
import { MarkdownModule } from 'ngx-markdown';
import { LedgeRenderModule } from '../../ledge-render.module';

describe('MarkdownRatingItemComponent', () => {
let component: ComponentRatingItemComponent;
let fixture: ComponentFixture<ComponentRatingItemComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [LedgeRenderModule, MarkdownModule],
declarations: [ComponentRatingItemComponent],
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ComponentRatingItemComponent);
component = fixture.componentInstance;
component.item = {
id: '',
name: '23442'
};
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should reg touch', () => {
const mockTouch = jasmine.createSpy('touch');
component.registerOnTouched(mockTouch);
component.onTouched({});
expect(mockTouch).toHaveBeenCalled();
});

it('should reg change', () => {
const mockChange = jasmine.createSpy('change');
component.registerOnChange(mockChange);
component.onChange('a');
expect(mockChange).toHaveBeenCalled();
});

it('should change state', () => {
component.setDisabledState(true);
expect(component.disabled).toEqual(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {
Component,
EventEmitter,
forwardRef,
Input,
OnInit,
Output,
} from '@angular/core';
import { NG_VALUE_ACCESSOR } from '@angular/forms';
import { MatSliderChange } from '@angular/material/slider';
import { RatingModel } from '../model/rating.model';

@Component({
selector: 'component-rating-item',
templateUrl: './component-rating-item.component.html',
styleUrls: ['./component-rating-item.component.scss'],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => ComponentRatingItemComponent),
multi: true,
},
],
})
export class ComponentRatingItemComponent implements OnInit {
@Input() item: RatingModel;
@Input() isParent: boolean;
@Output() itemChange = new EventEmitter();

disabled = false;

onChange(_) {}

onTouched(_) {}

ngOnInit() {

}

registerOnChange(fn: any): void {
this.onChange = fn;
this.itemChange.emit = fn;
}

registerOnTouched(fn: any): void {
this.onTouched = fn;
}

setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled;
}

writeValue(obj: any): void {
if (obj !== null && obj !== undefined) {
this.item = obj;
}
}

updateValue($event: MatSliderChange) {
this.itemChange.emit(this.item);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<ul id="markdown-rating">
<li *ngFor="let task of data">
<component-rating-item
[isParent]="isParent"
[item]="task"
(itemChange)="changeForm($event, task)">
</component-rating-item>

<ol *ngIf="task.children">
<li *ngFor="let item of task.children">{{item.name}}</li>
</ol>
</li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ul {
li {
font-size: 1.2em;
}

ul {
li {
font-size: 1em;
line-height: 1.2em !important;
margin-left: 2em;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MarkdownModule } from 'ngx-markdown';

import { ComponentRatingComponent } from './component-rating.component';
import { LedgeRenderModule } from '../../ledge-render.module';

describe('MarkdownRatingComponent', () => {
let component: ComponentRatingComponent;
let fixture: ComponentFixture<ComponentRatingComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [LedgeRenderModule, MarkdownModule],
declarations: [ComponentRatingComponent],
}).compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ComponentRatingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
component.onChange('aa');
component.onTouched({});
expect(component).toBeTruthy();
});

it('should reg touch', () => {
const mockTouch = jasmine.createSpy('touch');
component.registerOnTouched(mockTouch);
component.onTouched({});
expect(mockTouch).toHaveBeenCalled();
});

it('should reg change', () => {
const mockChange = jasmine.createSpy('change');
component.registerOnChange(mockChange);
component.onChange('a');
expect(mockChange).toHaveBeenCalled();
});

it('should change state', () => {
component.setDisabledState(true);
expect(component.disabled).toEqual(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Component, forwardRef, Input, OnInit } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';

@Component({
selector: 'component-rating',
templateUrl: './component-rating.component.html',
styleUrls: ['./component-rating.component.scss'],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => ComponentRatingComponent),
multi: true,
},
],
})
export class ComponentRatingComponent implements OnInit, ControlValueAccessor {
@Input() data: any[];
@Input() isParent = false;
@Input() instanceKey: string;

disabled = false;

onChange(_) {}

onTouched(_) {}

constructor() {}

ngOnInit(): void {
}

registerOnChange(fn: any): void {
this.onChange = fn;
}

registerOnTouched(fn: any): void {
this.onTouched = fn;
}

setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled;
}

writeValue(obj: any): void {
if (obj !== null) {
this.data = obj;
}
}

changeForm($event: any, item: any) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ledge-radar [data]="data" [config]="config"></ledge-radar>
</div>

<div class="right">
<ledge-checklist [data]="data" [config]="config"></ledge-checklist>
<div class="right" *ngIf="data">
<component-rating [data]="data[0].children"></component-rating>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface RatingModel {
id: string;
name: string;
chartValue?: number;
}
4 changes: 4 additions & 0 deletions projects/ledge-render/src/lib/ledge-render.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import { LedgeSunburstComponent } from './chart/ledge-sunburst/ledge-sunburst.co
import { LedgeFishBoneComponent } from './chart/ledge-fish-bone/ledge-fish-bone.component';
import { LedgeHeatmapComponent } from './chart/ledge-heatmap/ledge-heatmap.component';
import { LedgeMaturityComponent } from './components/ledge-maturity/ledge-maturity.component';
import { ComponentRatingItemComponent } from './components/component-rating-item/component-rating-item.component';
import { ComponentRatingComponent } from './components/component-rating/component-rating.component';

const LedgeComponents = [
LedgeRenderComponent,
Expand Down Expand Up @@ -60,6 +62,8 @@ const LedgeComponents = [

ComponentTodoComponent,
ComponentChecklistComponent,
ComponentRatingItemComponent,
ComponentRatingComponent,
];

const LedgePipes = [TohtmlPipe];
Expand Down

0 comments on commit 9660a5b

Please sign in to comment.