Skip to content

Commit

Permalink
feat: make styles works
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Mar 11, 2020
1 parent f559f59 commit 33091fe
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/app/features/path/path.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ <h2>Path to Production</h2>
<div class="page">
<div class="path">
<div id="pipe-header">
<div class="pipe-header" *ngFor="let pipe of pipeData;let i = index" id="{{i}}_header">
<div class="pipe-header" *ngFor="let pipe of pipeData;let i = index" id="{{i}}_header" [ngStyle]="getHeaderHeight()">
<h2>{{pipe.title}}</h2>
</div>
</div>
<div class='wrapper' id="pipe">
<div class='container' *ngFor="let pipe of pipeData;let i = index"
id="{{i}}_pipe"
[ngStyle]="{'background': pipe.backgroundColor,'color': pipe.textColor}">
[ngStyle]="getContainerStyle(pipe)">

<div class="editable" *ngFor="let item of pipe.items;let j = index" id="{{i}}_pipe_child{{j}}">
<div class="editable" [ngStyle]="getEditableStyle()" *ngFor="let item of pipe.items;let j = index" id="{{i}}_pipe_child{{j}}">
{{item}}
</div>
</div>
Expand Down
67 changes: 64 additions & 3 deletions src/app/features/path/path.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { Component, OnInit } from '@angular/core';
import {Component, OnInit} from '@angular/core';
import {StorageMap} from '@ngx-pwa/local-storage';

interface Item {
backgroundColor: string;
id: number;
title: string;
items: string[];
textColor: string;
}

@Component({
selector: 'component-path',
templateUrl: './path.component.html',
Expand Down Expand Up @@ -64,14 +72,67 @@ export class PathComponent implements OnInit {
textColor: '#ffffff'
}
];
private maxLength: number;

constructor(private storage: StorageMap) {}
constructor(private storage: StorageMap) {
}

ngOnInit(): void {

this.maxLength = this.getMaxLength(this.pipeData);
}

addColumn() {

}

getContainerStyle(pipe: Item) {
const {itemWidth, containerHeight} = this.getContainerHeightWidth();

return {
minWidth: this.maxLength * (itemWidth + 21) + 'px',
height: containerHeight,
background: pipe.backgroundColor,
color: pipe.textColor
};
}

private getContainerHeightWidth() {
const innerWidth = window.innerWidth;
let itemWidth = ((innerWidth - 200) / this.maxLength - 20);
if (itemWidth < 100) {
itemWidth = 100;
}

const itemHeightPx = itemWidth + 'px';
const containerHeight = itemWidth + 20 + 2 + 'px';
return {itemWidth, containerHeight, itemHeightPx};
}

getEditableStyle() {
const itemSize = this.getContainerHeightWidth().itemHeightPx;
return {
height: itemSize,
width: itemSize
};
}


getHeaderHeight() {
return {
height: this.getContainerHeightWidth().itemWidth + 20 + 12 + 'px'
};
}

private getMaxLength(items: Item[]) {
let maxLength = items[0].items.length;
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < items.length; i++) {
const itemLength = items[i].items.length;
if (itemLength > maxLength) {
maxLength = itemLength;
}
}

return maxLength;
}
}

0 comments on commit 33091fe

Please sign in to comment.