This commit is contained in:
Andras Schmelczer 2019-09-16 15:18:23 +02:00
parent 97e94ec154
commit 674f07f5f1
9 changed files with 51 additions and 26 deletions

View file

@ -11,7 +11,7 @@
<div class="header"> <div class="header">
<div class="exit" (click)="modalService.cancel()"></div> <div class="exit" (click)="modalService.cancel()"></div>
<div class="block" [ngStyle]="{ 'background-color': tower.getColorOfBlock(editedValues[i]) | color }"></div> <div class="block" [ngStyle]="{ 'background-color': tower.getColorOfTag(editedValues[i].tag) | color }"></div>
<h1>View item</h1> <h1>View item</h1>
</div> </div>
@ -30,7 +30,7 @@
<textarea <textarea
[disabled]="!editMode" [disabled]="!editMode"
placeholder="Write a description here…" placeholder="{{ editMode ? 'Write a description here…' : '' }}"
[(ngModel)]="editedValues[i].description" [(ngModel)]="editedValues[i].description"
></textarea> ></textarea>
@ -45,7 +45,9 @@
</div> </div>
<div class="bottom"> <div class="bottom">
<button class="{{ editMode && i + 1 === activeChild ? '' : 'hidden' }}" (click)="submitChange()"></button> <button class="{{ editMode && i + 1 === activeChild ? '' : 'hidden' }}" (click)="submitChange()">
Save and exit
</button>
<div class="edit {{ editMode && i + 1 === activeChild ? 'active' : '' }}" (click)="editMode = !editMode"> <div class="edit {{ editMode && i + 1 === activeChild ? 'active' : '' }}" (click)="editMode = !editMode">
<img src="assets/pen.svg" alt="edit" /> <img src="assets/pen.svg" alt="edit" />
</div> </div>
@ -62,6 +64,7 @@
<div class="header"> <div class="header">
<div class="exit" (click)="modalService.cancel()"></div> <div class="exit" (click)="modalService.cancel()"></div>
<div class="block" [ngStyle]="{ 'background-color': tower.getColorOfTag(top(editedValues).tag) | color }"></div>
<h1>Create an item</h1> <h1>Create an item</h1>
</div> </div>

View file

@ -58,6 +58,10 @@
z-index: 10000; z-index: 10000;
@include card(); @include card();
@media (max-width: $mobile-width) {
opacity: 0 !important;
}
} }
&:first-child { &:first-child {
@ -65,7 +69,7 @@
} }
&.placeholder { &.placeholder {
opacity: 0; opacity: 0 !important;
width: 1000px; width: 1000px;
max-width: 1000px; max-width: 1000px;
} }

View file

@ -45,6 +45,8 @@ export class BlocksComponent implements OnInit, OnDestroy {
} }
@HostListener('scroll') onScroll() { @HostListener('scroll') onScroll() {
console.log('scrolling');
this.animateScroll(); this.animateScroll();
const newToken = ++this.endOfScrollToken; const newToken = ++this.endOfScrollToken;
setTimeout(() => { setTimeout(() => {
@ -59,7 +61,9 @@ export class BlocksComponent implements OnInit, OnDestroy {
private cancelService: CancelService, private cancelService: CancelService,
private changeDetector: ChangeDetectorRef, private changeDetector: ChangeDetectorRef,
private component: ElementRef private component: ElementRef
) {} ) {
window.addEventListener('resize', this.onScroll.bind(this));
}
get blocks(): Array<Block> { get blocks(): Array<Block> {
return this.tower.blocks.filter(b => b.isDone === this.onlyDone); return this.tower.blocks.filter(b => b.isDone === this.onlyDone);
@ -107,10 +111,12 @@ export class BlocksComponent implements OnInit, OnDestroy {
} }
animate(cardStyle, maskStyle, t: number) { animate(cardStyle, maskStyle, t: number) {
t = Math.min(2, Math.max(0, t));
cardStyle.opacity = (1.33 * (1 - t / 2)).toString();
console.log(1 - t / 2);
t = Math.min(1, Math.max(0, t)); t = Math.min(1, Math.max(0, t));
cardStyle.opacity = (1 - t / 1.5).toString();
maskStyle.opacity = Math.pow(t, 0.5).toString(); maskStyle.opacity = Math.pow(t, 0.5).toString();
maskStyle.display = t <= 0.1 ? 'none' : 'block'; maskStyle.display = t <= 0.05 ? 'none' : 'block';
} }
adjustPosition() { adjustPosition() {
@ -118,13 +124,17 @@ export class BlocksComponent implements OnInit, OnDestroy {
return; return;
} }
console.log('adjusting position');
const c = this.component.nativeElement; const c = this.component.nativeElement;
const middle = const middle =
[...this.container.nativeElement.children] [...this.container.nativeElement.children]
.slice(1, -1) .slice(1, -1)
.map(element => Math.abs(element.offsetLeft - c.scrollLeft + element.clientWidth / 2 - window.innerWidth / 2)) .map(element => Math.abs(element.offsetLeft - c.scrollLeft + element.clientWidth / 2 - window.innerWidth / 2))
.map((value, index) => (Math.abs(index + 1 - this.activeChild) === 1 ? value / 1.5 : value)) .map((value, index) =>
Math.abs(index + 1 - this.activeChild) === 1 ? Math.abs(value - window.innerWidth / 4) : value
)
.reduce( .reduce(
(middleIndex, current, currentIndex, list) => (list[middleIndex] < current ? middleIndex : currentIndex), (middleIndex, current, currentIndex, list) => (list[middleIndex] < current ? middleIndex : currentIndex),
0 0
@ -136,6 +146,7 @@ export class BlocksComponent implements OnInit, OnDestroy {
scrollToChild(index: number, instantly?: boolean) { scrollToChild(index: number, instantly?: boolean) {
this.activeChild = index; this.activeChild = index;
console.log('scrolling to', index);
const element = this.container.nativeElement.children[index]; const element = this.container.nativeElement.children[index];
this.component.nativeElement.scrollTo({ this.component.nativeElement.scrollTo({
left: element.offsetLeft - (window.innerWidth / 2 - element.clientWidth / 2), left: element.offsetLeft - (window.innerWidth / 2 - element.clientWidth / 2),

View file

@ -13,18 +13,25 @@
&:hover { &:hover {
@media (min-width: $mobile-width) { @media (min-width: $mobile-width) {
div { div.container {
.container { box-shadow: $shadow;
box-shadow: $shadow;
}
} }
} }
} }
&.cdk-drag-preview { &.cdk-drag-preview {
div { div.container {
.container { @media (max-width: $mobile-width) {
box-shadow: $shadow; @keyframes shadow {
from {
box-shadow: none;
}
to {
box-shadow: $shadow;
}
}
animation: shadow $long-animation-time forwards;
} }
} }
} }
@ -87,9 +94,6 @@
transition: opacity $short-animation-time; transition: opacity $short-animation-time;
} }
.tasks-container {
}
img { img {
position: relative; position: relative;
z-index: 2; z-index: 2;

View file

@ -56,7 +56,9 @@ export class TowerComponent implements OnInit {
}); });
if ( if (
(difference.every(i => i) && this.tower.blocks.length + 1 === value.blocks.length) || (difference.every(i => i) &&
this.tower.blocks.length + 1 === value.blocks.length &&
top(value.blocks).isDone) ||
(this.tower.blocks.length === value.blocks.length && (this.tower.blocks.length === value.blocks.length &&
this.tower.blocks.filter(b => b.isDone).length + 1 === value.blocks.filter(b => b.isDone).length) this.tower.blocks.filter(b => b.isDone).length + 1 === value.blocks.filter(b => b.isDone).length)
) { ) {

View file

@ -48,8 +48,8 @@ export class Tower extends Serializable implements ITower, TowerState {
this.changeKeys({ name }); this.changeKeys({ name });
} }
getColorOfBlock(block: Block): IColor { getColorOfTag(tag: string): IColor {
return lighten((hash(block.tag) - 0.5) * 50, this.baseColor); return lighten((hash(tag) - 0.5) * 50, this.baseColor);
} }
protected onAfterClone() { protected onAfterClone() {
@ -59,7 +59,7 @@ export class Tower extends Serializable implements ITower, TowerState {
this.coloredBlocks = this.blocks.map(b => { this.coloredBlocks = this.blocks.map(b => {
const coloredBlock = b as ColoredBlock; const coloredBlock = b as ColoredBlock;
coloredBlock.color = this.getColorOfBlock(b); coloredBlock.color = this.getColorOfTag(b.tag);
return coloredBlock; return coloredBlock;
}); });

View file

@ -19,12 +19,10 @@ export class CancelService {
} }
cancelAllExcept(except: object) { cancelAllExcept(except: object) {
console.log('cancel all except', except);
this.subscribers.filter(s => s.object !== except).map(s => s.callback()); this.subscribers.filter(s => s.object !== except).map(s => s.callback());
} }
cancelAll() { cancelAll() {
console.log('cancel all');
this.subscribers.map(s => s.callback()); this.subscribers.map(s => s.callback());
} }
} }

View file

@ -1,6 +1,4 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Page } from '../model/page';
import { IPage } from '../interfaces/persistance/page';
const LOCAL_STORAGE_KEY = 'life-towers.data.v.2'; const LOCAL_STORAGE_KEY = 'life-towers.data.v.2';

View file

@ -3,6 +3,11 @@
textarea { textarea {
@include normal-text(); @include normal-text();
&:disabled {
background-color: $light-color;
}
display: block; display: block;
width: 100%; width: 100%;
height: 150px; height: 150px;