Skip to content

Commit

Permalink
refactor: rename childrens to children
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Apr 1, 2020
1 parent 3bcf1d2 commit 6c9644b
Show file tree
Hide file tree
Showing 22 changed files with 112 additions and 57 deletions.
2 changes: 0 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { ResourcesComponent } from './presentation/resources/resources.component
import { ReporterComponent } from './presentation/reporter/reporter.component';
import { AwesomeToolComponent } from './presentation/awesome-tool/awesome-tool.component';
import { MobileComponent } from './presentation/mobile/mobile.component';
import { ToolsetComponent } from './shared/toolset/toolset.component';
import { LedgeHelperComponent } from './presentation/ledge-helper/ledge-helper.component';
import { ThinkTankComponent } from './presentation/think-tank/think-tank.component';

Expand Down Expand Up @@ -65,7 +64,6 @@ import { ThinkTankComponent } from './presentation/think-tank/think-tank.compone
DragulaModule.forRoot(),
],
providers: [Title],
exports: [],
bootstrap: [AppComponent]
})
export class AppModule { }
4 changes: 2 additions & 2 deletions src/app/presentation/maturity/maturity.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export class MaturityComponent implements OnInit {
this.indexString = '';
}

if (task.childrens) {
this.taskToMarkdownList(task.childrens, hasChildren);
if (task.children) {
this.taskToMarkdownList(task.children, hasChildren);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
(itemChange)="changeForm($event, task.item)">
</markdown-rating-item>

<p *ngIf="task.childrens">
<p *ngIf="task.children">
<markdown-rating
ngDefaultControl
[(ngModel)]="task.childrens"
[(ngModel)]="task.children"
(ngModelChange)="changeForm($event, task.item)">
</markdown-rating>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export class MarkdownTaskItemService {
return tasks;
}

if (task.childrens) {
task = this.deleteTaskByItem(task.childrens, item);
if (task.children) {
task = this.deleteTaskByItem(task.children, item);
}
}

Expand Down Expand Up @@ -80,16 +80,16 @@ export class MarkdownTaskItemService {
}
};

if (task.childrens) {
task.childrens.push(newItem);
if (task.children) {
task.children.push(newItem);
} else {
task.childrens = [newItem];
task.children = [newItem];
}
return tasks;
}

if (task.childrens) {
this.addTaskByItem(task.childrens, item, name);
if (task.children) {
this.addTaskByItem(task.children, item, name);
}
}

Expand All @@ -103,8 +103,8 @@ export class MarkdownTaskItemService {
return tasks;
}

if (task.childrens) {
this.updateTaskByItem(task.childrens, item);
if (task.children) {
this.updateTaskByItem(task.children, item);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ export class MarkdownRenderComponent implements OnInit, OnChanges, AfterViewInit
private buildListStyle(code: any) {
const toJson = LedgeMarkdownConverter.toJson(code);
const list = toJson.lists[0];
console.log(list);
let childStr = '';
childStr = this.buildListStyleChildren(list, childStr);

Expand All @@ -317,16 +316,16 @@ export class MarkdownRenderComponent implements OnInit, OnChanges, AfterViewInit

private buildListStyleChildren(list, childStr: string) {
let index = 0;
for (const children of (list.childrens as any[])) {
for (const item of (list.children as any[])) {
let subChildStr = '';
let subChildClass = '';
if (children.childrens && children.childrens.length > 0) {
subChildStr = this.buildListStyleChildren(children, subChildStr);
if (item.children && item.children.length > 0) {
subChildStr = this.buildListStyleChildren(item, subChildStr);
subChildClass = 'sub-item';
}

index++;
childStr += `<div class="list-style-item item-${index} ${subChildClass}">${children.name}${subChildStr}</div>`;
childStr += `<div class="list-style-item item-${index} ${subChildClass}">${item.name}${subChildStr}</div>`;
}

return childStr;
Expand Down Expand Up @@ -476,7 +475,7 @@ export class MarkdownRenderComponent implements OnInit, OnChanges, AfterViewInit

private toTreeData(data: any) {
if (data.length === 1) {
const childrenInfo = this.transformTreeData(data[0].childrens);
const childrenInfo = this.transformTreeData(data[0].children);
return {
name: data[0].item.text,
children: childrenInfo,
Expand All @@ -497,8 +496,8 @@ export class MarkdownRenderComponent implements OnInit, OnChanges, AfterViewInit
for (const item of data) {
const node: any = {};
node.name = item.item.text;
if (item.childrens && item.childrens.length > 0) {
node.children = this.transformTreeData(item.childrens);
if (item.children && item.children.length > 0) {
node.children = this.transformTreeData(item.children);
}
nodes.push(node);
}
Expand Down Expand Up @@ -576,8 +575,8 @@ export class MarkdownRenderComponent implements OnInit, OnChanges, AfterViewInit
let items = [];
items = MarkdownHelper.markdownToJSON(tokens, items);

const maxItem = maxBy(items, (d) => d.childrens.length);
const maxLength = maxItem.childrens.length;
const maxItem = maxBy(items, (d) => d.children.length);
const maxLength = maxItem.children.length;

let maxWidthClass = '';
const MAX_ONE_COLUMN = 10;
Expand All @@ -592,8 +591,8 @@ export class MarkdownRenderComponent implements OnInit, OnChanges, AfterViewInit
const title = items[i].item.text;
for (let j = 0; j < maxLength; j++) {
let text = '';
if (items[i].childrens[j]) {
text = items[i].childrens[j].item.text;
if (items[i].children[j]) {
text = items[i].children[j].item.text;
}
if (text !== '') {
itemsStr += `<div class="process-step-item ${maxWidthClass}">${text}</div>`;
Expand Down Expand Up @@ -649,7 +648,7 @@ export class MarkdownRenderComponent implements OnInit, OnChanges, AfterViewInit
private getDataByType(json: { tables: any[]; lists: any[]; config: any }, type: any) {
switch (type) {
case 'slider':
return json.lists[0].childrens;
return json.lists[0].children;
case 'line-chart':
return json.tables[0];
default:
Expand Down
9 changes: 9 additions & 0 deletions src/app/shared/components/model/ledge-chart.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ export interface LedgeTable {
header: any[];
cells: any[][];
}

export interface LedgeListItem {
children: LedgeListItem;
name: string;
}

export interface LedgeList {
children: LedgeListItem[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ config: {"type": "line-model"}
`;
const json = LedgeMarkdownConverter.toJson(code);
expect(json.lists.length).toEqual(1);
expect(json.lists[0].childrens.length).toEqual(3);
expect(json.lists[0].children.length).toEqual(3);
});

it('should build list with childrens', () => {
it('should build list with children', () => {
const code = `
- a
- b
`;
const json = LedgeMarkdownConverter.toJson(code);
expect(json.lists.length).toEqual(1);
expect(json.lists[0].childrens[0].childrens.length).toEqual(1);
expect(json.lists[0].children[0].children.length).toEqual(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const LedgeMarkdownConverter = {
for (const token of tokens) {
switch (token.type) {
case 'list_start': {
result += '"childrens": [';
result += '"children": [';
break;
}
case 'list_item_start': {
Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/components/model/markdown.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const MarkdownHelper = {
}
switch (token.type) {
case 'list_start': {
result += '"childrens": [';
result += '"children": [';
break;
}
case 'list_item_start': {
Expand Down Expand Up @@ -142,7 +142,7 @@ const MarkdownHelper = {
result += '}';

try {
tasks = JSON.parse(result).childrens;
tasks = JSON.parse(result).children;
} catch (e) {
tasks = originTasks;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AfterViewInit, Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
import * as echarts from 'echarts';
import { ChartData, LedgeTable, LedgeChartModel } from '../../../model/ledge-chart.model';
import { ChartData, LedgeTable, LedgeChartModel } from '../../../components/model/ledge-chart.model';
import * as d3 from 'd3';

@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>ledge-mindmap works!</p>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { LedgeMindmapComponent } from './ledge-mindmap.component';

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

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LedgeMindmapComponent ]
})
.compileComponents();
}));

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

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component, Input, OnInit } from '@angular/core';
import { LedgeTable } from '../../../components/model/ledge-chart.model';

@Component({
selector: 'ledge-mindmap',
templateUrl: './ledge-mindmap.component.html',
styleUrls: ['./ledge-mindmap.component.scss']
})
export class LedgeMindmapComponent implements OnInit {
@Input()
data: LedgeTable;

constructor() { }

ngOnInit(): void {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
</div>
</div>

<div *ngSwitchCase="'mindmap'">
<div class="charts">
<ledge-mindmap [data]="item.data"></ledge-mindmap>
</div>
</div>

<div *ngSwitchCase="'table'">
<table>
<thead>
Expand All @@ -27,10 +33,10 @@

<div *ngSwitchCase="'process-step'">
<div class="markdown-process-step">
<div class="process-step-column" *ngFor="let row of item.data.childrens">
<div class="process-step-column" *ngFor="let row of item.data.children">
<div class="process-title">{{row.name}}</div>
<div class="process-body">
<div class="process-step-item" *ngFor="let cell of row.childrens">{{cell.name}}</div>
<div class="process-step-item" *ngFor="let cell of row.children">{{cell.name}}</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { LedgeRenderComponent } from './ledge-render.component';
import { SharedModule } from '../../shared.module';
import { SharedModule } from '../shared.module';

describe('LedgeRender', () => {
let component: LedgeRenderComponent;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AfterViewInit, Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
import marked from 'marked/lib/marked';
import { LedgeChartModel } from '../model/ledge-chart.model';
import { LedgeChartModel } from '../components/model/ledge-chart.model';
import { Tokens, TokensList } from 'marked';
import LedgeMarkdownConverter from '../model/ledge-markdown-converter';
import LedgeMarkdownConverter from '../components/model/ledge-markdown-converter';

@Component({
selector: 'ledge-render',
Expand All @@ -28,7 +28,7 @@ export class LedgeRenderComponent implements OnInit, AfterViewInit, OnChanges {
}

ngOnChanges(changes: SimpleChanges): void {
const { content } = changes;
const {content} = changes;
this.content = content.currentValue;
this.renderContent(this.content);
}
Expand Down Expand Up @@ -73,24 +73,19 @@ export class LedgeRenderComponent implements OnInit, AfterViewInit, OnChanges {
switch (codeBlock.lang) {
case 'chart':
const chartData = LedgeMarkdownConverter.toJson(codeBlock.text);
this.markdownData.push({
type: 'chart',
data: chartData.tables[0]
});
this.markdownData.push({type: 'chart', data: chartData.tables[0]});
break;
case 'process-step':
const stepData = LedgeMarkdownConverter.toJson(codeBlock.text);
this.markdownData.push({
type: 'process-step',
data: stepData.lists[0]
});
this.markdownData.push({type: 'process-step', data: stepData.lists[0]});
break;
case 'process-table':
const tableData = LedgeMarkdownConverter.toJson(codeBlock.text);
this.markdownData.push({
type: 'process-table',
data: tableData.tables[0]
});
this.markdownData.push({type: 'process-table', data: tableData.tables[0]});
break;
case 'mindmap':
const mindmapData = LedgeMarkdownConverter.toJson(codeBlock.text);
this.markdownData.push({type: 'mindmap', data: mindmapData.lists[0]});
break;
default:
this.markdownData.push(token);
Expand Down
Loading

0 comments on commit 6c9644b

Please sign in to comment.